我用的ADS1.2+ H-JTAG调试的LPC2364,AXD仿真的时候, Vectors LDR PC, Reset_Addr ;0 LDR PC, Undef_Addr ;4 LDR PC, SWI_Addr ;8 LDR PC, PAbt_Addr ;c LDR PC, DAbt_Addr ;10 NOP ;14 Reserved Vector
从Vectors行开始单步执行,LDR PC, Reset_Addr 执行之后不是跳转,而是顺序执行LDR PC, Undef_Addr,后面也全部相同,从Regisers窗口观察Current里的pc值,和指令相对应,00>04>08>0c。之前还有遇到就是进入main()后,一部分函数执行完毕后,继续执行剩下的函数,结果到函数返回的‘}’后,有时候跳到数据或指令异常,或跳到main()后紧跟的那个'{'行首,感觉很怪异,想不出什么解决办法,感觉和启动代码,或者scatter文件相关。 启动代码: PRESERVE8 ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
Mode_USR EQU 0x10 Mode_FIQ EQU 0x11 Mode_IRQ EQU 0x12 Mode_SVC EQU 0x13 Mode_ABT EQU 0x17 Mode_UND EQU 0x1B Mode_SYS EQU 0x1F
I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled
;// <h> Stack Configuration (Stack Sizes in Bytes) ;// <o0> Undefined Mode <0x0-0xFFFFFFFF:8> ;// <o1> Supervisor Mode <0x0-0xFFFFFFFF:8> ;// <o2> Abort Mode <0x0-0xFFFFFFFF:8> ;// <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8> ;// <o4> Interrupt Mode <0x0-0xFFFFFFFF:8> ;// <o5> User/System Mode <0x0-0xFFFFFFFF:8> ;// </h>
;定义堆栈的大小,最终工作在系统模式,栈名StackUsr,只给了起始位置,未指定大小 SVC_STACK_LEGTH EQU 0 ;单位为字 FIQ_STACK_LEGTH EQU 0 IRQ_STACK_LEGTH EQU 512 ABT_STACK_LEGTH EQU 0 UND_STACK_LEGTH EQU 0
;USR_STACK_LEGTH EQU 1024 ;设定用户模式栈
Heap_Size EQU 1024
IMPORT __use_no_semihosting_swi IMPORT __use_two_region_memory
IMPORT TargetResetInit IMPORT FIQ_Exception IMPORT __main ;The emported labels ;给外部使用的标号在这声明 ; EXPORT bottom_of_heap EXPORT bottom_of_Stacks ; EXPORT top_of_heap EXPORT StackUsr EXPORT Reset_Handler EXPORT __user_initial_stackheap ; Area Definition and Entry Point ; Startup Code must be linked first at Address at which it expects to run.
CODE32 AREA RESET, CODE, READONLY ENTRY
; Exception Vectors ; Mapped to Address 0. ; Absolute addressing mode must be used. ; Dummy Handlers are implemented as infinite loops which can be modified.
Vectors LDR PC, Reset_Addr ;0 LDR PC, Undef_Addr ;4 LDR PC, SWI_Addr ;8 LDR PC, PAbt_Addr ;c LDR PC, DAbt_Addr ;10 NOP ;14 Reserved Vector ;LDR PC, IRQ_Addr LDR PC, [PC, #-0x0120] ;18 Vector from VicVectAddr LDR PC, FIQ_Addr ;1c
Reset_Addr DCD Reset_Handler ;20 Undef_Addr DCD Undef_Handler ;24 SWI_Addr DCD SWI_Handler ;28 PAbt_Addr DCD PAbt_Handler ;2c DAbt_Addr DCD DAbt_Handler ;20 DCD 0xB9206E28 ;34 Reserved Address IRQ_Addr DCD IRQ_Handler ;38 FIQ_Addr DCD FIQ_Handler ;3c
Undef_Handler B Undef_Handler ;40 SWI_Handler B SWI_Handler ;44 PAbt_Handler B PAbt_Handler ;48 DAbt_Handler B DAbt_Handler ;4c IRQ_Handler B IRQ_Handler ;40 FIQ_Handler B FIQ_Handler ;44 Reset_Handler ; Enter Undefined Instruction Mode and set its Stack Pointer MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit LDR SP, StackUnd
; Enter Abort Mode and set its Stack Pointer MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit LDR SP, StackAbt
; Enter FIQ Mode and set its Stack Pointer MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit LDR SP, StackFiq
; Enter IRQ Mode and set its Stack Pointer MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit LDR SP, StackIrq
; Enter Supervisor Mode and set its Stack Pointer MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit LDR SP, StackSvc
; Enter Sys Mode and set its Stack Pointer ; MSR CPSR_c, #Mode_SYS:OR:I_Bit:OR:F_Bit ; LDR SP, StackSys
; Enter User Mode and set its Stack Pointer ; MSR CPSR_c, #Mode_USR MSR CPSR_c, #Mode_SYS:OR:F_Bit LDR SP, =StackUsr BL TargetResetInit ; Enter the C code LDR R0, =__main BX R0 ; B __main
;// <h> Heap Configuration ;// <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF> ;// </h>
; User Initial Stack & Heap ; AREA |.text|, CODE, READONLY __user_initial_stackheap LDR R0,=bottom_of_heap ;heap基地址 LDR r1,=StackUsr ;栈基地址 LDR r2,=top_of_heap ;heap长度限制值 LDR r3,=bottom_of_Stacks ;栈长度限制值 MOV pc,lr StackSvc DCD SvcStackSpace + (SVC_STACK_LEGTH - 1)* 4 StackIrq DCD IrqStackSpace + (IRQ_STACK_LEGTH - 1)* 4 StackFiq DCD FiqStackSpace + (FIQ_STACK_LEGTH - 1)* 4 StackAbt DCD AbtStackSpace + (ABT_STACK_LEGTH - 1)* 4 StackUnd DCD UndStackSpace + (UND_STACK_LEGTH - 1)* 4
IF :DEF: EN_CRP IF . >= 0x1fc INFO 1,"\nThe data at 0x000001fc must be 0x87654321.\nPlease delete some source before this line." ENDIF CrpData WHILE . < 0x1fc NOP WEND CrpData1 DCD 0x87654321 ;/*When the Data is 为0x87654321,user code be protected. 当此数为0x87654321时,用户程序被保护 */ ENDIF ;/* 分配堆栈空间 */ AREA MyStacks, DATA, NOINIT, ALIGN=2 SvcStackSpace SPACE SVC_STACK_LEGTH * 4 ;Stack spaces for Administration Mode 管理模式堆栈空间 IrqStackSpace SPACE IRQ_STACK_LEGTH * 4 ;Stack spaces for Interrupt ReQuest Mode 中断模式堆栈空间 FiqStackSpace SPACE FIQ_STACK_LEGTH * 4 ;Stack spaces for Fast Interrupt reQuest Mode 快速中断模式堆栈空间 AbtStackSpace SPACE ABT_STACK_LEGTH * 4 ;Stack spaces for Suspend Mode 中止义模式堆栈空间 UndStackSpace SPACE UND_STACK_LEGTH * 4 ;Stack spaces for Undefined Mode 未定义模式堆栈
AREA Heap, DATA, NOINIT, ALIGN=3 bottom_of_heap SPACE 1
AREA StackBottom, DATA, NOINIT, ALIGN=3 bottom_of_Stacks SPACE 1
AREA HeapTop, DATA, NOINIT, ALIGN=3 top_of_heap SPACE 1
AREA Stacks, DATA, NOINIT, ALIGN=3 StackUsr SPACE 1
END
scatter文件: ROM_LOAD 0x0 { ROM_EXEC 0x0 { Startup_a.o (RESET, +First) * (+RO) }
ERAM 0x40000000 UNINIT { * (+RW,+ZI) } MYSTACKS +0 UNINIT { Startup_a.o (MyStacks) }
HEAP +0 UNINIT { Startup_a.o (Heap) } HEAP_BOTTOM +256 UNINIT { Startup_a.o (HeapTop) } USERSTACKS +0 UNINIT { Startup_a.o (StackBottom) } STACKS_BOTTOM 0x40002000 UNINIT ;//LPC2364 { Startup_a.o (Stacks) } }
启动代码和scatter文件都是仿照ZLG2200模板写的。
|
|