Skip to content

Commit 71d802c

Browse files
authored
[docs][libcpu][arm][cortex-a] update comment for start_gcc.S #11089
1 parent ec0c2bb commit 71d802c

File tree

1 file changed

+58
-39
lines changed

1 file changed

+58
-39
lines changed

libcpu/arm/cortex-a/start_gcc.S

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,24 @@
2727
.equ I_Bit, 0x80 /* when I bit is set, IRQ is disabled */
2828
.equ F_Bit, 0x40 /* when F bit is set, FIQ is disabled */
2929

30-
/*Load the physical address of a symbol into a register.
31-
Through pv_off calculates the offset of the physical address */
30+
/**
31+
* @brief Get the physical address of the symbol
32+
*
33+
* @param reg is the register to store the physical address
34+
* @param symbol is symbol name
35+
* @param _pvoff is the offset between the physical address and the virtual address
36+
*/
3237
.macro get_phy, reg, symbol, _pvoff
3338
ldr \reg, =\symbol
3439
add \reg, \_pvoff
3540
.endm
36-
/*Calculate the offset between the physical address and the virtual address of the "_reset".*/
41+
42+
/**
43+
* @brief Calculate the offset between the physical address and the virtual address of the "_reset"
44+
*
45+
* @param tmp is the register which will be used to store the virtual address of the "_reset"
46+
* @param out is the register which will be used to store the pv_off (paddr - vaddr)
47+
*/
3748
.macro get_pvoff, tmp, out
3849
ldr \tmp, =_reset
3950
adr \out, _reset
@@ -68,20 +79,20 @@ init_cpu_stack_early:
6879

6980
#ifdef RT_USING_FPU
7081
mov r4, #0xfffffff
71-
mcr p15, 0, r4, c1, c0, 2
82+
mcr p15, 0, r4, c1, c0, 2 /* CPACR */
7283
#endif
7384

7485
mov pc, lr
7586

7687
init_kernel_bss:
7788

7889
/* enable I cache + branch prediction */
79-
mrc p15, 0, r0, c1, c0, 0
80-
orr r0, r0, #(1<<12)
81-
orr r0, r0, #(1<<11)
90+
mrc p15, 0, r0, c1, c0, 0 /* SCTLR */
91+
orr r0, r0, #(1<<12) /* I=1 */
92+
orr r0, r0, #(1<<11) /* Z=1 */
8293
mcr p15, 0, r0, c1, c0, 0
8394

84-
mov r0,#0 /* get a zero */
95+
mov r0,#0
8596
get_phy r1, __bss_start, pv_off
8697
get_phy r2, __bss_end, pv_off
8798

@@ -123,7 +134,7 @@ continue_exit:
123134
#endif
124135
#ifdef SOC_BCM283x
125136
/* Suspend the other cpu cores */
126-
mrc p15, 0, r0, c0, c0, 5
137+
mrc p15, 0, r0, c0, c0, 5 /* MPIDR */
127138
ands r0, #3
128139
bne _halt
129140

@@ -162,17 +173,18 @@ continue_exit:
162173
163174
#endif
164175

165-
/* invalid tlb before enable mmu */
166-
mrc p15, 0, r0, c1, c0, 0
167-
bic r0, #1
176+
/* disable MMU */
177+
mrc p15, 0, r0, c1, c0, 0 /* SCTLR */
178+
bic r0, #1 /* M=0 */
168179
mcr p15, 0, r0, c1, c0, 0
169180
dsb
170181
isb
171182

183+
/* invalidate TLB, I-cache and branch predictor */
172184
mov r0, #0
173-
mcr p15, 0, r0, c8, c7, 0
174-
mcr p15, 0, r0, c7, c5, 0 /* iciallu */
175-
mcr p15, 0, r0, c7, c5, 6 /* bpiall */
185+
mcr p15, 0, r0, c8, c7, 0 /* ITLBIALL */
186+
mcr p15, 0, r0, c7, c5, 0 /* ICIALLU */
187+
mcr p15, 0, r0, c7, c5, 6 /* BPIALL */
176188
dsb
177189
isb
178190

@@ -218,13 +230,14 @@ enable_mmu_page_table_early:
218230
get_phy r0, init_mtbl, pv_off
219231
mcr p15, #0, r0, c2, c0, #0
220232
dmb
221-
222-
ldr r0,=#0x55555555
223-
mcr p15, #0, r0, c3, c0, #0
233+
234+
/* set all domains with client mode */
235+
ldr r0,=#0x55555555 /* client */
236+
mcr p15, #0, r0, c3, c0, #0 /* DACR */
224237

225238
/* disable ttbr1 */
226-
mov r0, #(1 << 5) /* PD1=1 */
227-
mcr p15, 0, r0, c2, c0, 2 /* ttbcr */
239+
mov r0, #(1 << 5) /* PD1=1 */
240+
mcr p15, 0, r0, c2, c0, 2 /* TTBCR */
228241

229242
230243
/* init stack for cpu mod */
@@ -253,16 +266,17 @@ enable_mmu_page_table_early:
253266
sub sp, r1, cpu_id, asl #ARM_CPU_STACK_SIZE_OFFSET
254267

255268

256-
/* invalid tlb before enable mmu */
269+
/* invalidate TLB, I-cache and branch predictor */
257270
mov r0, #0
258-
mcr p15, 0, r0, c8, c7, 0
259-
mcr p15, 0, r0, c7, c5, 0 /* iciallu */
260-
mcr p15, 0, r0, c7, c5, 6 /* bpiall */
261-
262-
mrc p15, 0, r0, c1, c0, 0
263-
bic r0, r0, #0x7 /* clear bit1~3 */
264-
orr r0, #((1 << 12) | (1 << 11)) /* instruction cache, branch prediction */
265-
orr r0, #((1 << 2) | (1 << 0)) /* data cache, mmu enable */
271+
mcr p15, 0, r0, c8, c7, 0 /* ITLBIALL */
272+
mcr p15, 0, r0, c7, c5, 0 /* ICIALLU */
273+
mcr p15, 0, r0, c7, c5, 6 /* BPIALL */
274+
275+
/* enable I cache + branch prediction, enable MMU */
276+
mrc p15, 0, r0, c1, c0, 0 /* SCTLR */
277+
bic r0, r0, #0x7 /* C=0, A=0, M=0 */
278+
orr r0, #((1 << 12) | (1 << 11)) /* I=1, Z=1 */
279+
orr r0, #((1 << 2) | (1 << 0)) /* C=1, M=1 */
266280
mcr p15, 0, r0, c1, c0, 0
267281
dsb
268282
isb
@@ -278,13 +292,13 @@ master_core_startup :
278292

279293
.global rt_hw_mmu_tbl_get
280294
rt_hw_mmu_tbl_get:
281-
mrc p15, 0, r0, c2, c0, 0 /* ttbr0 */
282-
bic r0, #0x18
295+
mrc p15, 0, r0, c2, c0, 0 /* TTBR0 */
296+
bic r0, #0x18 /* RGN=0 */
283297
mov pc, lr
284298

285299
.weak rt_hw_cpu_id_early
286300
rt_hw_cpu_id_early:
287-
mrc p15, 0, r0, c0, c0, 5
301+
mrc p15, 0, r0, c0, c0, 5 /* MPIDR */
288302
and r0, r0, #0xf
289303
mov pc, lr
290304

@@ -635,15 +649,20 @@ START_POINT_END(_thread_start)
635649
init_mtbl:
636650
.space (4*4096) /* The L1 translation table therefore contains 4096 32-bit (word-sized) entries. */
637651

652+
/*
653+
* void rt_hw_mmu_switch(rt_uint32_t* mmutable_p);
654+
* r0 --> mmutable_p (mmu table address)
655+
*/
638656
.global rt_hw_mmu_switch
639657
rt_hw_mmu_switch:
640-
orr r0, #0x18
641-
mcr p15, 0, r0, c2, c0, 0 // ttbr0
642-
//invalid tlb
658+
orr r0, #0x18 /* RGN=0b11 (Outer WB-WA) */
659+
mcr p15, 0, r0, c2, c0, 0 /* TTBR0 */
660+
661+
/* invalidate TLB, I-cache and branch predictor */
643662
mov r0, #0
644-
mcr p15, 0, r0, c8, c7, 0
645-
mcr p15, 0, r0, c7, c5, 0 //iciallu
646-
mcr p15, 0, r0, c7, c5, 6 //bpiall
663+
mcr p15, 0, r0, c8, c7, 0 /* ITLBIALL */
664+
mcr p15, 0, r0, c7, c5, 0 /* ICIALLU */
665+
mcr p15, 0, r0, c7, c5, 6 /* BPIALL */
647666

648667
dsb
649668
isb
@@ -653,7 +672,7 @@ rt_hw_mmu_switch:
653672
.global rt_hw_set_process_id
654673
rt_hw_set_process_id:
655674
LSL r0, r0, #8
656-
MCR p15, 0, r0, c13, c0, 1
675+
MCR p15, 0, r0, c13, c0, 1 /* CONTEXTIDR */
657676
mov pc, lr
658677

659678

0 commit comments

Comments
 (0)