I am using AT91RM9200 and I u-boot to boot up the processor. I wanted to
write programs for my processor, So I took the example program from
C:\WinARM\examples\at91sam7s64_Hello\ and modified the linker script.
Regarding the start up file, I wanted to know if I really need to
initialise the peripherals again, I think the U-Boot has already done
that for me. What changes do I really need in the startup_SAM7S.s file.
Since both are ARM processor based, I assume that the start files should
not be changed. Still can anyone provide me a basic example startup file
( GNU ) for my board. This is what I did, can anyone tell me if the
changes are correct ? I am using RAM-RUN so I also removed the portion
of #ifdef ( ROM-RUN ). Also, my linker script has got only i change i.e
origin for my SDRAM
/***********************************************************************
/
/*
*/
/* startup_SAM7S.S: Startup file for Atmel AT91SAM7S device series
*/
/*
*/
/***********************************************************************
/
/* ported to arm-elf-gcc / WinARM by Martin Thomas, KL, .de
*/
/* <eversmith@heizung-thomas.de>
*/
/* modifications Copyright Martin Thomas 2005
*/
// *** Startup Code (executed after Reset) ***
.equ Mode_USR, 0x10
.equ Mode_FIQ, 0x11
.equ Mode_IRQ, 0x12
.equ Mode_SVC, 0x13
.equ Mode_ABT, 0x17
.equ Mode_UND, 0x1B
.equ Mode_SYS, 0x1F
.equ I_Bit, 0x80 /* when I bit is set, IRQ is
disabled */
.equ F_Bit, 0x40 /* when F bit is set, FIQ is
disabled */
// Internal Memory Base Addresses
.equ FLASH_BASE, 0x10000000 // my change
.equ RAM_BASE, 0x20000000 // my change
.equ Top_Stack, 0x20040000 // my change
.equ UND_Stack_Size, 0x00000004
.equ SVC_Stack_Size, 0x00000100
.equ ABT_Stack_Size, 0x00000004
.equ FIQ_Stack_Size, 0x00000004
.equ IRQ_Stack_Size, 0x00000100
.equ USR_Stack_Size, 0x00000400
/*
Exception Vectors
- for ROM_RUN: placed in 0x00000000
- for RAM_RUN: placed at 0x00200000 (on AT91SAM7S64)
-> will be used during startup before remapping with target ROM_RUN
-> will be used "always" in code without remapping or with target
RAM_RUN
Mapped to Address relative address 0 of .text
Absolute addressing mode must be used.
Dummy Handlers are implemented as infinite loops which can be modified.
*/
.text
.arm
.section .vectrom, "ax"
Vectors: LDR PC,Reset_Addr
LDR PC,Undef_Addr
LDR PC,SWI_Addr
LDR PC,PAbt_Addr
LDR PC,DAbt_Addr
NOP /* Reserved Vector */
// LDR PC,IRQ_Addr
LDR PC,[PC,#-0xF20] /* Vector From AIC_IVR */
// LDR PC,FIQ_Addr
LDR PC,[PC,#-0xF20] /* Vector From AIC_FVR */
Reset_Addr: .word Reset_Handler
Undef_Addr: .word Undef_Handler
SWI_Addr: .word SWI_Handler
PAbt_Addr: .word PAbt_Handler
DAbt_Addr: .word DAbt_Handler
.word 0 /* Reserved Address */
IRQ_Addr: .word IRQ_Handler
FIQ_Addr: .word FIQ_Handler
Undef_Handler: B Undef_Handler
SWI_Handler: B SWI_Handler
PAbt_Handler: B PAbt_Handler
DAbt_Handler: B DAbt_Handler
IRQ_Handler: B IRQ_Handler
FIQ_Handler: B FIQ_Handler
// Starupt Code must be linked first at Address at which it expects to
run.
.text
.arm
.section .init, "ax"
.global _startup
.func _startup
_startup:
// Reset Handler
LDR pc, =Reset_Handler
Reset_Handler:
// Setup Stack for each mode
LDR R0, =Top_Stack
// Enter Undefined Instruction Mode and set its Stack Pointer
MSR CPSR_c, #Mode_UND|I_Bit|F_Bit
MOV SP, R0
SUB R0, R0, #UND_Stack_Size
// Enter Abort Mode and set its Stack Pointer
MSR CPSR_c, #Mode_ABT|I_Bit|F_Bit
MOV SP, R0
SUB R0, R0, #ABT_Stack_Size
// Enter FIQ Mode and set its Stack Pointer
MSR CPSR_c, #Mode_FIQ|I_Bit|F_Bit
MOV SP, R0
SUB R0, R0, #FIQ_Stack_Size
// Enter IRQ Mode and set its Stack Pointer
MSR CPSR_c, #Mode_IRQ|I_Bit|F_Bit
MOV SP, R0
SUB R0, R0, #IRQ_Stack_Size
// Enter Supervisor Mode and set its Stack Pointer
MSR CPSR_c, #Mode_SVC|I_Bit|F_Bit
MOV SP, R0
SUB R0, R0, #SVC_Stack_Size
// Enter User Mode and set its Stack Pointer
MSR CPSR_c, #Mode_USR
MOV SP, R0
// Setup a default Stack Limit (when compiled with "-mapcs-stack-check")
SUB SL, SP, #USR_Stack_Size
// Clear .bss section (Zero init)
MOV R0, #0
LDR R1, =__bss_start__
LDR R2, =__bss_end__
LoopZI: CMP R1, R2
STRLO R0, [R1], #4
BLO LoopZI
#if defined(VECTORS_IN_RAM) || defined(RAM_RUN)
/*
*** Remap ***
ROM_RUN: exception vectors for RAM have been already copied
to 0x00200000 by the .data copy-loop
RAM_RUN: exception vectors are already placed at 0x0020000 by
linker settings
*/
.equ MC_BASE,0xFFFFFF00 /* MC Base Address */
.equ MC_RCR, 0x00 /* MC_RCR Offset */
LDR R0, =MC_BASE
MOV R1, #1
STR R1, [R0, #MC_RCR] // Remap
#endif /* VECTORS_IN_RAM || RAM_RUN */
// Enter the C code
mov r0,#0 // no arguments (argc = 0)
mov r1,r0
mov r2,r0
mov fp,r0 // null frame pointer
mov r7,r0 // null frame pointer for thumb
ldr r10,=main
adr lr, __main_exit
bx r10 // enter main()
__main_exit: B __main_exit
.size _startup, . - _startup
.endfunc
.end