我的启动代码是这样的 vector.s ; ;System informition ;Flash: 1M x 16bit ;SDRAM: 1M x 4bank x 16bit
ModeMask EQU 0x1F SVC32Mode EQU 0x13 IRQ32Mode EQU 0x12 FIQ32Mode EQU 0x11 User32Mode EQU 0x10 Abort32Mode EQU 0x17 Undef32Mode EQU 0x1B IRQ_BIT EQU 0x80 FIQ_BIT EQU 0x40
;RomBaseAddr EQU 0 ; RamBaseAddr EQU 0x100 ;Sdram at 16M RamLoaderAddr EQU 0x100 ;@22M ;RamEndAddr EQU &200
GBLS MainEntry MainEntry SETS "main" IMPORT $MainEntry
;//********************************************************** ;//检查是否使用tasm.exe进行编译 GBLL THUMBCODE [ {CONFIG} = 16 THUMBCODE SETL {TRUE} CODE32 | THUMBCODE SETL {FALSE} ]
[ THUMBCODE CODE32 ;for start-up code for Thumb mode ] ;****************************************************** AREA SelfBoot, CODE, READONLY IMPORT UDF_INS_VECTOR IMPORT SWI_SVC_VECTOR IMPORT INS_ABT_VECTOR IMPORT DAT_ABT_VECTOR IMPORT IRQ_SVC_VECTOR IMPORT FIQ_SVC_VECTOR ENTRY IF :DEF: |ads$version| ELSE EXPORT __main __main ENDIF ResetEntry b SYS_RST_HANDLER b UDF_INS_HANDLER b SWI_SVC_HANDLER b INS_ABT_HANDLER b DAT_ABT_HANDLER b . b IRQ_SVC_HANDLER b FIQ_SVC_HANDLER
;****************************************************** MACRO $Label HANDLER $Vector $Label sub lr, lr, #4 stmfd sp!, {r0-r3, lr} ldr r0, =$Vector ldr pc, [r0] ldmfd sp!, {r0-r3, pc}^ MEND UDF_INS_HANDLER stmfd sp!, {r0-r3, lr} ldr r0, =UDF_INS_VECTOR mov lr, pc ldr pc, [r0] ldmfd sp!, {r0-r3, pc}^ SWI_SVC_HANDLER stmfd sp!, {r0-r3, lr} ldr r0, =SWI_SVC_VECTOR mov lr, pc ldr pc, [r0] ldmfd sp!, {r0-r3, pc}^ INS_ABT_HANDLER sub lr, lr, #4 stmfd sp!, {r0-r3, lr} ldr r0, =INS_ABT_VECTOR mov lr, pc ldr pc, [r0] ldmfd sp!, {r0-r3, pc}^ DAT_ABT_HANDLER sub lr, lr, #4 stmfd sp!, {r0-r3, lr} ldr r0, =DAT_ABT_VECTOR mov lr, pc ldr pc, [r0] ldmfd sp!, {r0-r3, pc}^ IRQ_SVC_HANDLER sub lr, lr, #4 stmfd sp!, {r0-r12, lr} mrs r0, spsr stmfd sp!, {r0} ldr r0, =IRQ_SVC_VECTOR ldr pc, [r0] FIQ_SVC_HANDLER sub lr, lr, #4 stmfd sp!, {r0-r12, lr} mrs r0, spsr stmfd sp!, {r0} ldr r0, =IRQ_SVC_VECTOR ldr pc, [r0] ;//**********************Copy Code********************************* SYS_RST_HANDLER mrs r0, cpsr ;enter svc mode and disable irq,fiq bic r0, r0, #ModeMask orr r0, r0, #(SVC32Mode :OR: IRQ_BIT :OR: FIQ_BIT) msr cpsr_c, r0 IMPORT InitSystem ;//init system bl InitSystem adr r0, ResetEntry ;Get start address 0 mov r3, #(RamLoaderAddr<<16) ;Destination address(sdram) 0x160 @22M ldr r1, BaseOfROM ;RO Section ldr r2, TopOfROM add r1, r1, r3 ;RamBaseAddr+BaseOfROM = R1 addr offset add r2, r2, r3 ;RamBaseAddr+TopOfROM = R2 0 ldmia r0!, {r4-r11} ;Copy code to Sdram stmia r1!, {r4-r11} cmp r1, r2 ;size == RO size,r1==TopofRO bcc %B0 sub r1, r1, r2 ;r1 - r2 = 0x4 sub r0, r0, r1 ;r0 == BaseOfBSS ldr r1, BaseOfBSS ldr r2, BaseOfZero add r1, r1, r3 ;RAMbase+ add r2, r2, r3 1 ;copy RW sec cmp r1, r2 ldrcc r4, [r0], #4 strcc r4, [r1], #4 bcc %B1 mov r0, #0 ldr r2, EndOfBSS add r2, r2, r3 3 ;copy ZI cmp r1, r2 strcc r0, [r1], #4 bcc %B3 IMPORT RemapMemory adr r0, ResetEntry ;Copy code to befor BaseOfROM ldr r1, =RemapMemory ;why reload again? ldr r2, BaseOfROM sub r2, r1, r2 add r0, r0, r2 add r1, r2, r3 mov r2, #32 0 ldr r3, [r0], #4 str r3, [r1], #4 subs r2, r2, #1 bne %B0 ldr lr, GotoMain ;load main addr b RemapMemory
GotoMain DCD $MainEntry
;***********************************************
IMPORT |Image$$RO$$Base| ; ROM code start IMPORT |Image$$RO$$Limit| ; RAM data starts after ROM program IMPORT |Image$$RW$$Base| ; Pre-initialised variables IMPORT |Image$$ZI$$Base| ; uninitialised variables IMPORT |Image$$ZI$$Limit| ; End of variable RAM space
BaseOfROM DCD |Image$$RO$$Base| TopOfROM DCD |Image$$RO$$Limit| BaseOfBSS DCD |Image$$RW$$Base| BaseOfZero DCD |Image$$ZI$$Base| EndOfBSS DCD |Image$$ZI$$Limit| ;//*********************************************** ;//此处添加Image 搬移代码 two param Image dst Addr TIP_SIZE EQU 256 IMPORT ResetMemSet EXPORT trans_to_boot trans_to_boot ;BootLoader Image R0 = biosbase 0x10000 ; R1 = bios load 0x1000 mov lr, r1 ; a2 = r1 ldr r1, =ResetMemSet ;载入函数地址 ldr r2, BaseOfROM ;载入RO地址 sub r2, r1, r2 ;函数地址-RO地址 add r0, r0, r2 ;a1 = r0 mov r2, #TIP_SIZE 0 ldr r3, [r1], #4 ;//将ResetMemSet函数搬移到之前执行 猜想为了主程序初始化,清除主程序运行之前的寄存器配置 str r3, [r0], #4 subs r2, r2, #1 bne %B0 sub r0, r0, #TIP_SIZE*4 ;//先执行一段初始化代码 mov pc, r0 ;//jump to 0x10000
;*********************************************** END |