|
楼主 |
发表于 2008-7-8 13:27:04
|
显示全部楼层
最后,附上启动文件cstartup.s,移植版本参考官方的an1014中的realview部分
那个全局变量不清零的bug我查了很多文档才理清,主要在跳转到main函数那块
;------------------------------------------------------------------------------
;;#------------------------------------------------------------------------------
INCLUDE AT91SAM7X256.inc
RamEnd EQU 0x00210000
;;#------------------------------------------------------------------------------
;;#- Area Definition
;;#------------------------------------------------------------------------------
;;#---------------------------------------------------------------
;;# ?RESET
;;# Reset Vector.
;;# Normally, segment INTVEC is linked at address 0.
;;# For debugging purposes, INTVEC may be placed at other
;;# addresses.
;;# A debugger that honors the entry point will start the
;;# program in a normal way even if INTVEC is not at address 0.
;;#-------------------------------------------------------------
;; IMPORT OS_CPU_IRQ_ISR
IMPORT OS_CPU_ARM_ExceptResetHndlr ;复位中断程序
IMPORT OS_CPU_ARM_ExceptUndefInstrHndlr ;未知指令
IMPORT OS_CPU_ARM_ExceptSwiHndlr ;软中断
IMPORT OS_CPU_ARM_ExceptPrefetchAbortHndlr ;取指异常
IMPORT OS_CPU_ARM_ExceptDataAbortHndlr
IMPORT OS_CPU_ARM_ExceptAddrAbortHndlr
IMPORT OS_CPU_ARM_ExceptIrqHndlr
IMPORT OS_CPU_ARM_ExceptFiqHndlr
;;// IMPORT OS_CPU_FIQ_ISR
;.text
;;# PROGRAM ?RESET
;;# RSEG INTRAMSTART_REMAP
;;# RSEG INTRAMEND_REMAP
;;# RSEG ICODE:CODE:ROOT(2)
; CODE 32 /*; Always ARM mode after reset*/
;;# org 0
AREA reset, CODE, READONLY
;ENTRY
;EXPORT entry
ENTRY
EXPORT entry
entry
;;#------------------------------------------------------------------------------
;;#- Exception vectors
;;#--------------------
;;#- These vectors can be read at address 0 or at RAM address
;;#- They ABSOLUTELY requires to be in relative addresssing mode in order to
;;#- guarantee a valid jump. For the moment, all are just looping.
;;#- If an exception occurs before remap, this would result in an infinite loop.
;;#- To ensure if a exeption occurs before start application to infinite loop.
;;#------------------------------------------------------------------------------
re_set
B InitReset ;/* 0x00 Reset handler*/
undefvec
ldr pc,=OS_CPU_ARM_ExceptUndefInstrHndlr ;/* 0x04 Undefined Instruction */
swivec
ldr pc,=OS_CPU_ARM_ExceptSwiHndlr ;/* 0x08 Software Interrupt*/
pabtvec
ldr pc,=OS_CPU_ARM_ExceptPrefetchAbortHndlr ;/* 0x0C Prefetch Abort*/
dabtvec
ldr pc,=OS_CPU_ARM_ExceptDataAbortHndlr ;/* 0x10 Data Abort*/
rsvdvec
B rsvdvec ;/* 0x14 reserved*/
irqvec
;ldr pc, [pc,#-0xF20] ; IRQ : read the AIC
ldr pc,=OS_CPU_ARM_ExceptIrqHndlr
fiqvec ldr pc,=OS_CPU_ARM_ExceptFiqHndlr ;/* 0x1c FIQ*/
;;#------------------------------------------------------------------------------
;;#- Function : FIQ_Handler_Entry
;;#- Treatments : FIQ Controller Interrupt Handler.
;;#- Called Functions : AIC_FVR[interrupt]
;;#------------------------------------------------------------------------------
InitReset
;#------------------------------------------------------------------------------
;#- configure the reset mode register . user reset enable
;#------------------------------------------------------------------------------
ldr r0,=0xFFFFFD08
ldr r1,=0xa5000001
str r1,[r0]
;#------------------------------------------------------------------------------
;#- Low level Init (PMC, AIC, ? ....) by C function AT91F_LowLevelInit
;#------------------------------------------------------------------------------
IMPORT AT91F_LowLevelInit
;#define __iramend SFB(INTRAMEND_REMAP)
;#- minumum C initialization
;#- call AT91F_LowLevelInit( void)
ldr r13,=RamEnd ; temporary stack in internal RAM*/
;#--Call Low level init function in ABSOLUTE through the Interworking
ldr r0,=AT91F_LowLevelInit
mov lr, pc
bx r0
;# REMAP memory 0x200000 -> 0x0
; Copy Exception Vectors to Internal RAM
; RAM_BASE EQU 0x200000
; ADR R8, re_set ; Source
; LDR R9, =RAM_BASE ; Destination
; LDMIA R8!, {R0-R7} ; Load Vectors
; STMIA R9!, {R0-R7} ; Store Vectors
; LDMIA R8!, {R0-R7} ; Load Handler Addresses
; STMIA R9!, {R0-R7} ; Store Handler Addresses
; ENDIF
; Remap on-chip RAM to address 0
;MC_BASE EQU 0xFFFFFF00 ; MC Base Address
;MC_RCR EQU 0x00 ; MC_RCR Offset
; IF :DEF:REMAP
; LDR R0, =MC_BASE
; MOV R1, #1
; STR R1, [R0, #MC_RCR] ; Remap
; ENDIF
;#------------------------------------------------------------------------------
;#- Stack Sizes Definition
;#------------------------
;#- Interrupt Stack requires 2 words x 8 priority level x 4 bytes when using
;#- the vectoring. This assume that the IRQ management.
;#- The Interrupt Stack must be adjusted depending on the interrupt handlers.
;#- Fast Interrupt not requires stack If in your application it required you must
;#- be definehere.
;#- The System stack size is not defined and is limited by the free internal
;#- SRAM.
;#------------------------------------------------------------------------------
;#------------------------------------------------------------------------------
;#- Top of Stack Definition
;#-------------------------
;#- Interrupt and Supervisor Stack are located at the top of internal memory in
;#- order to speed the exception handling context saving and restoring.
;#- ARM_MODE_SVC (Application, C) Stack is located at the top of the external memory.
;#------------------------------------------------------------------------------
IRQ_STACK_SIZE equ (3*8*4)
;2 words per interrupt priority level
ARM_MODE_USER EQU 0x10
ARM_MODE_FIQ EQU 0x11
ARM_MODE_IRQ EQU 0x12
ARM_MODE_SVC EQU 0x13
ARM_MODE_ABORT EQU 0x17
ARM_MODE_UNDEF EQU 0x1B
ARM_MODE_SYS EQU 0x1F
I_BIT equ 0x80
F_BIT equ 0x40
;#------------------------------------------------------------------------------
;#- Setup the stack for each mode
;#-------------------------------
ldr r0, =RamEnd
;#- Set up Fast Interrupt Mode and set FIQ Mode Stack
msr CPSR_c, #ARM_MODE_FIQ | I_BIT | F_BIT
;#- Init the FIQ register
ldr r8, =AT91C_BASE_AIC
;#- Set up Interrupt Mode and set IRQ Mode Stack
msr CPSR_c, #ARM_MODE_IRQ | I_BIT | F_BIT
mov r13, r0 ; Init stack IRQ*/
sub r0, r0, #IRQ_STACK_SIZE
;#- Enable interrupt & Set up Supervisor Mode and set Supervisor Mode Stack
msr CPSR_c, #ARM_MODE_SVC
mov r13, r0
;#------------------------------------------------------------------------------
;#- Initialise C variables
;#------------------------
;#- Following labels are automatically generated by the linker.
;#- RO: Read-only = the code
;#- RW: Read Write = the data pre-initialized and zero-initialized.
;#- ZI: Zero-Initialized.
;#- Pre-initialization values are located after the code area in the image.
;#- Zero-initialized datas are mapped after the pre-initialized.
;#- Note on the Data position :
;#- If using the ARMSDT, when no -rw-base option is used for the linker, the
;#- data area is mapped after the code. You can map the data either in internal
;#- SRAM ( -rw-base=0x40 or 0x34) or in external SRAM ( -rw-base=0x2000000 ).
;#- Note also that to improve the code density, the pre_initialized data must
;#- be limited to a minimum.
;#------------------------------------------------------------------------------
IMPORT __main
ldr r0, =__main
mov lr, pc
bx r0
;#------------------------------------------------------------------------------
;#- Loop for ever
;#---------------
;#- End of application. Normally, never occur.
;#- Could jump on Software Reset ( B 0x0 ).
;#------------------------------------------------------------------------------
End
b End
;#---------------------------------------------------------------
;# ?EXEPTION_VECTOR
;# This module is only linked if needed for closing files.
;#其余中断处理
;#---------------------------------------------------------------
global AT91F_Default_FIQ_handler
global AT91F_Default_IRQ_handler
global AT91F_Spurious_handler
;CODE 32 /*; Always ARM mode after exeption*/
AT91F_Default_FIQ_handler
b AT91F_Default_FIQ_handler
AT91F_Default_IRQ_handler
b AT91F_Default_IRQ_handler
AT91F_Spurious_handler
b AT91F_Spurious_handler
;# ENDMOD
END |
|