3.BootLoader第一阶段
根本的硬件初始化作业包含:
·屏蔽一切的中止;
·设置CPU的速度和时钟频率;
·RAM初始化;
·初始化LED
ARM的中止向量表设置在0地址开端的8个字空间中,如下表:
每逢其间的某个反常发生后行将PC值置到相应的中止向量处,每个中止向量处放置一个跳转指令到相应的中止服务程序去进行处理,中止向量表的程序如下:
@ 0x00: Reset b Reset @ 0x04: Undefined instruction exception UndefEntryPoint: b HandleUndef @ 0x08: Software interrupt exception SWIEntryPoint: b HandleSWI @ 0x0c: Prefetch Abort (Instruction Fetch Memory Abort) PrefetchAbortEnteryPoint: b HandlePrefetchAbort @ 0x10: Data Access Memory Abort DataAbortEntryPoint: b HandleDataAbort @ 0x14: Not used NotUsedEntryPoint: b HandleNotUsed @ 0x18: IRQ(Interrupt Request) exception IRQEntryPoint: b HandleIRQ @ 0x1c: FIQ(Fast Interrupt Request) exception FIQEntryPoint: b HandleFIQ |
复位时封闭看门狗定时器、屏蔽一切中止:
Reset: @ disable watch dog timer mov r1, #0x53000000 mov r2, #0x0 str r2, [r1] @ disable all interrupts mov r1, #INT_CTL_BASE mov r2, #0xffffffff str r2, [r1, #oINTMSK] ldr r2, =0x7ff str r2, [r1, #oINTSUBMSK] |
设置体系时钟:
@init clk @ 1:2:4 mov r1, #CLK_CTL_BASE mov r2, #0x3 str r2, [r1, #oCLKDIVN] mrc p15, 0, r1, c1, c0, 0 @ read ctrl register orr r1, r1, #0xc0000000 @ Asynchronous mcr p15, 0, r1, c1, c0, 0 @ write ctrl register @ now, CPU clock is 200 Mhz mov r1, #CLK_CTL_BASE ldr r2, mpll_200mhz str r2, [r1, #oMPLLCON] |
点亮一切的用户LED:
@ All LED on mov r1, #GPIO_CTL_BASE add r1, r1, #oGPIO_F ldr r2,=0x55aa str r2, [r1, #oGPIO_CON] mov r2, #0xff str r2, [r1, #oGPIO_UP] mov r2, #0x00 str r2, [r1, #oGPIO_DAT] |
设置(初始化)内存映射:
ENTRY(memsetup) @ initialise the static memory @ set memory control registers mov pc, lr |
设置(初始化)UART:
@ set GPIO for UART mov r1, #GPIO_CTL_BASE add r1, r1, #oGPIO_H ldr r2, gpio_con_uart str r2, [r1, #oGPIO_CON] ldr r2, gpio_up_uart str r2, [r1, #oGPIO_UP] bl InitUART @ Initialize UART #if 0 1: ldr r3, [r1, #oUTRSTAT] mov r2, #0 1: ldr r3, [r1, #oUTRSTAT] mov pc, lr |
此外,vivi还供给了几个汇编情况下经过串口打印字符的函数PrintChar、PrintWord和PrintHexWord:
@ PrintChar : prints the character in R0 @ r0 contains the character @ r1 contains base of serial port @ writes ro with XXX, modifies r0,r1,r2 @ TODO : write ro with XXX reg to error handling PrintChar: TXBusy: ldr r2, [r1, #oUTRSTAT] and r2, r2, #UTRSTAT_TX_EMPTY tst r2, #UTRSTAT_TX_EMPTY beq TXBusy str r0, [r1, #oUTXHL] mov pc, lr @ PrintWord : prints the 4 characters in R0 mov r0, r3, LSR #8 /* shift word right 8 bits */ mov r0, r3, LSR #16 /* shift word right 16 bits */ mov r0, r3, LSR #24 /* shift word right 24 bits */ mov r0, #\r mov r0, #\n mov pc, r4 @ PrintHexWord : prints the 4 bytes in R0 as 8 hex ascii characters mov r0, #\r mov r0, #\n mov pc, r4 |