start.s 文件中汇编代码的注解(RTEMS)
作者:zhousm 2016年01月01日
处理器:S3C2440 ARM9
操作系统:RTEMS-4.10.2
源文件路径:rtems-4.10.2/c/src/lib/libbsp/arm/gp32/start/start.S
当处理器跳转到指定的地址开始执行时,即从该文件开始执行:
1 /* Some standard definitions...*/ 2 .equ PSR_MODE_USR, 0x10 3 .equ PSR_MODE_FIQ, 0x11 4 .equ PSR_MODE_IRQ, 0x12 5 .equ PSR_MODE_SVC, 0x13 6 .equ PSR_MODE_ABT, 0x17 7 .equ PSR_MODE_UNDEF, 0x1B 8 .equ PSR_MODE_SYS, 0x1F 9 10 .equ PSR_I, 0x80 /* 当 I=1 时,禁止 IRQ 中断 */ 11 .equ PSR_F, 0x40 /* 当 F=1 时,禁止 FIQ 中断 */ 12 .equ PSR_T, 0x20 13 14 .text 15 .globl _start 16 _start: 17 b _start2 /* 此为第一条被执行的指令,跳转到 _start2 地址处开始执行,即第52行 */ 18 19 @--------------------------------------------------------------------------------- 20 @ AXF addresses 21 @--------------------------------------------------------------------------------- 22 .word _axf_text_start /* _axf_text_start = 0x30000100 */ 23 .word _axf_ro_end /* */ 24 .word _axf_data_start /* .data start */ 25 .word _axf_bss_end /* .data end */ 26 _bss_start: 27 .word _axf_bss_start /* .bss start */ 28 _bss_end: 29 .word _axf_bss_end /* .bss end */ 30 /* 这些符号都定义在 linkcmds 文件中了 */ 31 @--------------------------------------------------------------------------------- 32 @ GamePark magic sequence 33 @--------------------------------------------------------------------------------- 34 .word 0x44450011 35 .word 0x44450011 36 .word 0x01234567 37 .word 0x12345678 38 .word 0x23456789 39 .word 0x34567890 40 .word 0x45678901 41 .word 0x56789012 42 .word 0x23456789 43 .word 0x34567890 44 .word 0x45678901 45 .word 0x56789012 46 .word 0x23456789 47 .word 0x34567890 48 .word 0x45678901 49 .word 0x56789012 50 51 @--------------------------------------------------------------------------------- 52 _start2: 53 @--------------------------------------------------------------------------------- 54 55 /* 56 * I'll just set the CPSR for SVC mode, interrupts 57 * off, and ARM instructions. 58 */ 59 mov r0, #(PSR_MODE_SVC | PSR_I | PSR_F) /* 0x13 + 0x80 + 0x40 = 0xD3, 设置为 SVC 模式 */ 60 msr cpsr, r0 61 62 /* Enter IRQ mode and set up the IRQ stack pointer */ 63 mov r0, #(PSR_MODE_IRQ | PSR_I | PSR_F) /* 0x12 + 0x80 + 0x40 = 0xD2, 设置为 IRQ 中断模式,用于初始化 IRQ 堆栈 */ 64 msr cpsr, r0 65 ldr r1, =_irq_stack_size 66 ldr sp, =_irq_stack 67 add sp, sp, r1 /* sp = 0x30023400 + 0x00001000; 4kByte */ 68 69 /* Enter FIQ mode and set up the FIQ stack pointer */ 70 mov r0, #(PSR_MODE_FIQ | PSR_I | PSR_F) /* 0x11 + 0x80 + 0x40 = 0xD1, 设置为 FIQ 中断模式,用于初始化 FIQ 堆栈 */ 71 msr cpsr, r0 72 ldr r1, =_fiq_stack_size 73 ldr sp, =_fiq_stack 74 add sp, sp, r1 /* sp = 0x30024400 + 0x00000400; 1kByte */ 75 76 /* Enter ABT mode and set up the ABT stack pointer */ 77 mov r0, #(PSR_MODE_ABT | PSR_I | PSR_F) /* 0x17 + 0x80 + 0x40 = 0xD7,设置为 ABT 模式,用于初始化 Abort 堆栈 */ 78 msr cpsr, r0 79 ldr r1, =_abt_stack_size 80 ldr sp, =_abt_stack 81 add sp, sp, r1 /* sp = 0x30023300 + 0x00000100; 256Byte */ 82 83 /* Set up the SVC stack pointer last and stay in SVC mode */ 84 mov r0, #(PSR_MODE_SVC | PSR_I | PSR_F) /* 0x13 + 0x80 + 0x40 = 0xD3,回到 SVC 模式,用于初始化 SVC 堆栈 */ 85 msr cpsr, r0 86 ldr r1, =_svc_stack_size 87 ldr sp, =_svc_stack 88 add sp, sp, r1 89 sub sp, sp, #0x64 /* sp = 0x30024800 + 0x00001000 - 0x64 */ 90 91 /* clear .bss segment */ 92 clear_bss: /* 此段代码由本人(zhousm)添加,用于初始化 _bss 段内存 */ 93 ldr r0, _bss_start 94 ldr r1, _bss_end 95 mov r2, #0 96 clear_loop: 97 str r2, [r0] 98 add r0, #4 99 cmp r0, r1 100 ble clear_loop 101 102 /* disable mmu, I and D caches*/ 103 disable_mmu: 104 nop 105 nop 106 mrc p15, 0, r0, c1, c0, 0 /* r0 <- c1 */ 107 bic r0, r0, #0x01 /* disable MMU */ 108 bic r0, r0, #0x04 /* disable D-cache */ 109 bic r0, r0, #0x01000 /* disable I-cache */ 110 mcr p15, 0, r0, c1, c0, 0 /* c1 <- r0 */ 111 nop 112 nop 113 114 /* clean data cache */ 115 mov r1, #0x00 116 Loop1: 117 mov r2, #0x00 118 Loop2: /* c7 - [31:26] - [7:5] */ 119 mov r3, r2, lsl#26 /* r3 <- (r2 << 26), c7-[31:26] */ 120 orr r3, r3, r1, lsl#5 /* r3 <- (r3 | (r1<<5)), c7-[7:5] */ 121 mcr p15, 0, r3, c7, c14, 2 /* c7 <- r3 */ 122 add r2, r2, #0x01 123 cmp r2, #64 124 bne Loop2 125 add r1, r1, #0x01 126 cmp r1, #8 127 bne Loop1 /* Loop: 8*64 times */ 128 129 /* 130 * Initialize the MMU. After we return, the MMU is enabled, 131 * and memory may be remapped. I hope we don't remap this 132 * memory away. 133 */ 134 ldr r0, =mem_map 135 bl mmu_init 136 137 /* 138 * Initialize the exception vectors. This includes the 139 * exceptions vectors (0x00000000-0x0000001c), and the 140 * pointers to the exception handlers (0x00000020-0x0000003c). 141 */ 142 mov r0, #0 /* 此段代码将 vector_block 向量表搬移到 0 地址 */ 143 adr r1, vector_block 144 ldmia r1!, {r2-r9} 145 stmia r0!, {r2-r9} 146 ldmia r1!, {r2-r9} 147 stmia r0!, {r2-r9} 148 149 /* Now we are prepared to start the BSP's C code */ 150 mov r0, #0 151 bl boot_card /* 跳转到 boot_card() 函数处执行 */ 152 153 /* 154 * Theoretically, we could return to what started us up, 155 * but we'd have to have saved the registers and stacks. 156 * Instead, we'll just reset. 157 */ 158 bl bsp_reset 159 160 /* We shouldn't get here. If we do, hang */ 161 _hang: 162 b _hang 163 164 165 /* 166 * This is the exception vector table and the pointers to 167 * the functions that handle the exceptions. It's a total 168 * of 16 words (64 bytes) 169 */ 170 vector_block: /* 中断向量表 */ 171 ldr pc, Reset_Handler 172 ldr pc, Undefined_Handler 173 ldr pc, SWI_Handler 174 ldr pc, Prefetch_Handler 175 ldr pc, Abort_Handler 176 nop 177 ldr pc, IRQ_Handler 178 ldr pc, FIQ_Handler 179 180 Reset_Handler: b bsp_reset /* 跳转到 bsp_reset() 函数去执行复位操作 */ 181 Undefined_Handler: b Undefined_Handler /* 跳转到自己,无限循环,后续程序将会覆盖这部分向量 */ 182 SWI_Handler: b SWI_Handler /* 跳转到自己,无限循环 */ 183 Prefetch_Handler: b Prefetch_Handler /* 跳转到自己,无限循环 */ 184 Abort_Handler: b Abort_Handler /* 跳转到自己,无限循环 */ 185 nop 186 IRQ_Handler: b IRQ_Handler /* 跳转到自己,无限循环 */ 187 FIQ_Handler: b FIQ_Handler /* 跳转到自己,无限循环 */ 188 189 .globl Reset_Handler 190 .globl Undefined_Handler 191 .globl SWI_Handler 192 .globl Prefetch_Handler 193 .globl Abort_Handler 194 .globl IRQ_Handler 195 .globl FIQ_Handler