summaryrefslogtreecommitdiff
path: root/firmware/src/start/Cstartup.S
diff options
context:
space:
mode:
authorlaforge <laforge@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2006-09-13 16:02:52 +0000
committerlaforge <laforge@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2006-09-13 16:02:52 +0000
commita97e460bea62375c9c870fb3e3650fbff20c5ad1 (patch)
tree64c0de524a604015a367aa979c777325765fbfa3 /firmware/src/start/Cstartup.S
parent8bd3d51b23e328e91c209dbebe8cfe002b0b0042 (diff)
Completely separate DFU from application program, we now have a real bootloader.
DFU occupies 0x00100000 - 0x00100fff in flash, application starts at 0x00101000. DFU also occupies the first couple of bytes in SRAM, application starts at 0x00200024. In order to produce a samba-flashable image, first build dfu.bin by typing 'make -f Makefule.dfu', succeeded by 'make TARGET=... DEBUG=... BOARD=...' and then concatenating the two files together, e.g. cat dfu.bin main_reqa.bin > flash.bin. Actual flashing via DFU is still not operational, but will be implemented next git-svn-id: https://svn.openpcd.org:2342/trunk@194 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
Diffstat (limited to 'firmware/src/start/Cstartup.S')
-rw-r--r--firmware/src/start/Cstartup.S348
1 files changed, 173 insertions, 175 deletions
diff --git a/firmware/src/start/Cstartup.S b/firmware/src/start/Cstartup.S
index e91fd86..e7d5714 100644
--- a/firmware/src/start/Cstartup.S
+++ b/firmware/src/start/Cstartup.S
@@ -76,165 +76,22 @@
.text
.arm
.section .vectram, "ax"
-resetvecR: B resetvecR
-undefvecR: B undefvecR
-swivecR: B swivecR
-pabtvecR: B pabtvecR
-dabtvecR: B dabtvecR
-rsvdvecR: B rsvdvecR
-irqvecR: B IRQ_Handler_EntryR
-fiqvecR:
-FIQ_Handler_EntryR:
-
-/*- Switch in SVC/User Mode to allow User Stack access for C code */
-/* because the FIQ is not yet acknowledged*/
-
-/*- Save and r0 in FIQ_Register */
- mov r9,r0
- ldr r0 , [r8, #AIC_FVR]
- msr CPSR_c,#I_BIT | F_BIT | ARM_MODE_SVC
-
-/*- Save scratch/used registers and LR in User Stack */
- stmfd sp!, { r1-r3, r12, lr}
-
-/*- Branch to the routine pointed by the AIC_FVR */
- mov r14, pc
- bx r0
-
-/*- Restore scratch/used registers and LR from User Stack */
- ldmia sp!, { r1-r3, r12, lr}
-
-/*- Leave Interrupts disabled and switch back in FIQ mode */
- msr CPSR_c, #I_BIT | F_BIT | ARM_MODE_FIQ
-
-/*- Restore the R0 ARM_MODE_SVC register */
- mov r0,r9
-
-/*- Restore the Program Counter using the LR_fiq directly in the PC */
- subs pc,lr,#4
-
- .global IRQ_Handler_EntryR
- .func IRQ_Handler_EntryR
-
-IRQ_Handler_EntryR:
-
-/*- Manage Exception Entry */
-/*- Adjust and save LR_irq in IRQ stack */
- sub lr, lr, #4
- stmfd sp!, {lr}
-
-/*- Save SPSR need to be saved for nested interrupt */
- mrs r14, SPSR
- stmfd sp!, {r14}
-
-/*- Save and r0 in IRQ stack */
- stmfd sp!, {r0}
-
-/*- Write in the IVR to support Protect Mode */
-/*- No effect in Normal Mode */
-/*- De-assert the NIRQ and clear the source in Protect Mode */
- ldr r14, =AT91C_BASE_AIC
- ldr r0 , [r14, #AIC_IVR]
- str r14, [r14, #AIC_IVR]
-
-/*- Enable Interrupt and Switch in Supervisor Mode */
- msr CPSR_c, #ARM_MODE_SVC
-
-/*- Save scratch/used registers and LR in User Stack */
- stmfd sp!, { r1-r3, r12, r14}
-
-/*- Branch to the routine pointed by the AIC_IVR */
- mov r14, pc
- bx r0
-/*- Restore scratch/used registers and LR from User Stack*/
- ldmia sp!, { r1-r3, r12, r14}
-
-/*- Disable Interrupt and switch back in IRQ mode */
- msr CPSR_c, #I_BIT | ARM_MODE_IRQ
-
-/*- Mark the End of Interrupt on the AIC */
- ldr r14, =AT91C_BASE_AIC
- str r14, [r14, #AIC_EOICR]
-
-/*- Restore SPSR_irq and r0 from IRQ stack */
- ldmia sp!, {r0}
-
-/*- Restore SPSR_irq and r0 from IRQ stack */
- ldmia sp!, {r14}
- msr SPSR_cxsf, r14
-
-/*- Restore adjusted LR_irq from IRQ stack directly in the PC */
- ldmia sp!, {pc}^
-
- .size IRQ_Handler_EntryR, . - IRQ_Handler_EntryR
- .endfunc
-
- .global remap
- .func remap
-_remap:
-# led1on
-# Remap RAM to 0x00000000 for DFU
+ .global _remap_call_dfu
+ .func _remap_call_dfu
+_remap_call_dfu:
+ led1on
+ /* Remap RAM to 0x00000000 for DFU */
ldr r1, =AT91C_BASE_AIC
mov r2, #0x01
str r2, [r1, #AIC_MCR_RCR]
+
+ ldr r4, =dfu_main
+ bx r4
- /* prepare c function call to main */
- mov r0, #0 /* argc = 0 */
- ldr lr,=exit
- ldr r10,=main
-
-#ifdef CONFIG_DFU_SWITCH
- /* check whether bootloader button is pressed */
- ldr r1, =AT91C_PMC_PCER
- mov r2, #(1 << AT91C_ID_PIOA)
- str r2, [r1]
-
- ldr r1, =AT91C_BASE_PIOA
- ldr r2, [r1, #PIOA_PDSR]
- tst r2, #PIO_BOOTLDR
- ldrne r10,=dfu_main
-#endif
-
- bx r10
- .size remap, . - remap
+ .size _remap_call_dfu, . - _remap_call_dfu
.endfunc
-/* "exit" dummy added by mthomas to avoid sbrk write read etc. needed
- by the newlib default "exit" */
- .global exit
- .func exit
-exit:
- b .
- .size exit, . - exit
- .endfunc
-
-/*---------------------------------------------------------------
-//* ?EXEPTION_VECTOR
-//* This module is only linked if needed for closing files.
-//*---------------------------------------------------------------*/
- .global AT91F_Default_FIQ_handler
- .func AT91F_Default_FIQ_handler
-AT91F_Default_FIQ_handler:
- b AT91F_Default_FIQ_handler
- .size AT91F_Default_FIQ_handler, . - AT91F_Default_FIQ_handler
- .endfunc
-
- .global AT91F_Default_IRQ_handler
- .func AT91F_Default_IRQ_handler
-AT91F_Default_IRQ_handler:
- b AT91F_Default_IRQ_handler
- .size AT91F_Default_IRQ_handler, . - AT91F_Default_IRQ_handler
- .endfunc
-
- .global AT91F_Spurious_handler
- .func AT91F_Spurious_handler
-AT91F_Spurious_handler:
- b AT91F_Spurious_handler
- .size AT91F_Spurious_handler, . - AT91F_Spurious_handler
- .endfunc
-
-
#;------------------------------------------------------------------------------
#;- Section Definition
@@ -255,9 +112,6 @@ Top_Stack:
* .text is used instead of .section .text so it works with arm-aout too. */
.section .reset
.text
- .global _startup
- .func _startup
-_startup:
reset:
/*------------------------------------------------------------------------------
//*- Exception vectors
@@ -277,17 +131,108 @@ swivec:
pabtvec:
B pabtvec /* 0x0C Prefetch Abort */
dabtvec:
- B dabtvec /* 0x10 Data Abort */
+ b dabtvec /* 0x10 Data Abort */
rsvdvec:
- B rsvdvec /* 0x14 reserved */
+ b rsvdvec /* 0x14 reserved */
irqvec:
- B irqvec /* 0x18 IRQ */
-fiqvec:
- B fiqvec /* 0x1c FIQ */
+ b IRQ_Handler_Entry /* 0x18 IRQ */
+fiqvec:
+ b FIQ_Handler_Entry
+ /* 0x1c FIQ */
+dfu_state_dummy:
+ .word 0
+
+FIQ_Handler_Entry:
+
+/*- Switch in SVC/User Mode to allow User Stack access for C code */
+/* because the FIQ is not yet acknowledged*/
+
+/*- Save and r0 in FIQ_Register */
+ mov r9, r0
+ ldr r0, [r8, #AIC_FVR]
+ msr CPSR_c, #I_BIT | F_BIT | ARM_MODE_SVC
+
+ /*- Save scratch/used registers and LR in User Stack */
+ stmfd sp!, { r1-r3, r12, lr}
+
+ /*- Branch to the routine pointed by the AIC_FVR */
+ mov r14, pc
+ bx r0
+
+ /*- Restore scratch/used registers and LR from User Stack */
+ ldmia sp!, { r1-r3, r12, lr}
+
+ /*- Leave Interrupts disabled and switch back in FIQ mode */
+ msr CPSR_c, #I_BIT | F_BIT | ARM_MODE_FIQ
+
+ /*- Restore the R0 ARM_MODE_SVC register */
+ mov r0,r9
+
+ /*- Restore the Program Counter using the LR_fiq directly in the PC */
+ subs pc, lr, #4
+
+ .global IRQ_Handler_Entry
+ .func IRQ_Handler_Entry
+
+IRQ_Handler_Entry:
+
+ /*- Manage Exception Entry */
+ /*- Adjust and save LR_irq in IRQ stack */
+ sub lr, lr, #4
+ stmfd sp!, {lr}
+
+ /*- Save SPSR need to be saved for nested interrupt */
+ mrs r14, SPSR
+ stmfd sp!, {r14}
+
+ /*- Save and r0 in IRQ stack */
+ stmfd sp!, {r0}
+
+ /*- Write in the IVR to support Protect Mode */
+ /*- No effect in Normal Mode */
+ /*- De-assert the NIRQ and clear the source in Protect Mode */
+ ldr r14, =AT91C_BASE_AIC
+ ldr r0 , [r14, #AIC_IVR]
+ str r14, [r14, #AIC_IVR]
+
+ /*- Enable Interrupt and Switch in Supervisor Mode */
+ msr CPSR_c, #ARM_MODE_SVC
+
+ /*- Save scratch/used registers and LR in User Stack */
+ stmfd sp!, { r1-r3, r12, r14}
+
+ /*- Branch to the routine pointed by the AIC_IVR */
+ mov r14, pc
+ bx r0
+
+ /*- Restore scratch/used registers and LR from User Stack*/
+ ldmia sp!, { r1-r3, r12, r14}
+
+ /*- Disable Interrupt and switch back in IRQ mode */
+ msr CPSR_c, #I_BIT | ARM_MODE_IRQ
+
+ /*- Mark the End of Interrupt on the AIC */
+ ldr r14, =AT91C_BASE_AIC
+ str r14, [r14, #AIC_EOICR]
+
+ /*- Restore SPSR_irq and r0 from IRQ stack */
+ ldmia sp!, {r0}
+
+ /*- Restore SPSR_irq and r0 from IRQ stack */
+ ldmia sp!, {r14}
+ msr SPSR_cxsf, r14
+
+ /*- Restore adjusted LR_irq from IRQ stack directly in the PC */
+ ldmia sp!, {pc}^
+
+ .size IRQ_Handler_Entry, . - IRQ_Handler_Entry
+ .endfunc
.align 0
.RAM_TOP:
.word Top_Stack
+ .global _startup
+ .func _startup
InitReset:
/*------------------------------------------------------------------------------
/*- Low level Init (PMC, AIC, ? ....) by C function AT91F_LowLevelInit
@@ -348,16 +293,7 @@ InitReset:
msr CPSR_c, #ARM_MODE_SVC
mov r13, r0 /* Init stack Sup */
-/*- Relocate DFU .data section (Copy from ROM to RAM)*/
- ldr r1, =_etext_dfu
- ldr r2, =_data_dfu
- ldr r3, =_edata_dfu
-LoopRelDFU: cmp r2, r3
- ldrlo r0, [r1], #4
- strlo r0, [r2], #4
- blo LoopRelDFU
-
-# Relocate .data section (Copy from ROM to RAM)
+# Relocate DFU .data section (Copy from ROM to RAM)
LDR R1, =_etext
LDR R2, =_data
LDR R3, =_edata
@@ -366,7 +302,7 @@ LoopRel: CMP R2, R3
STRLO R0, [R2], #4
BLO LoopRel
-# Clear .bss section (Zero init)
+# Clear DFU .bss section (Zero init)
MOV R0, #0
LDR R1, =__bss_start__
LDR R2, =__bss_end__
@@ -374,13 +310,75 @@ LoopZI: CMP R1, R2
STRLO R0, [R1], #4
BLO LoopZI
- led1on
+ /* prepare c function call to main */
+ mov r0, #0 /* argc = 0 */
+ ldr lr, =exit
+ ldr r10, =0x00101000
- ldr r0, =_remap
- bx r0
+#ifdef CONFIG_DFU_SWITCH
+ /* check whether bootloader button is pressed */
+ ldr r1, =AT91C_PMC_PCER
+ mov r2, #(1 << AT91C_ID_PIOA)
+ str r2, [r1]
+ ldr r1, =AT91C_BASE_PIOA
+ ldr r2, [r1, #PIOA_PDSR]
+ tst r2, #PIO_BOOTLDR
+ bne _reloc_dfu_text
+#endif
+
+ bx r10
+
+_reloc_dfu_text:
+
+ ldr r1, =0x00100000
+ ldr r2, =0x00200000
+ ldr r3, =_etext
+ add r3, r3, r2
+loop_rel_t: cmp r2, r3
+ ldrlo r4, [r1], #4
+ strlo r4, [r2], #4
+ blo loop_rel_t
+ ldr r4, =_remap_call_dfu
+ bx r4
+
.size _startup, . - _startup
.endfunc
-
+
+/* "exit" dummy to avoid sbrk write read etc. needed by the newlib default "exit" */
+ .global exit
+ .func exit
+exit:
+ b .
+ .size exit, . - exit
+ .endfunc
+
+/*---------------------------------------------------------------
+//* ?EXEPTION_VECTOR
+//* This module is only linked if needed for closing files.
+//*---------------------------------------------------------------*/
+ .global AT91F_Default_FIQ_handler
+ .func AT91F_Default_FIQ_handler
+AT91F_Default_FIQ_handler:
+ b AT91F_Default_FIQ_handler
+ .size AT91F_Default_FIQ_handler, . - AT91F_Default_FIQ_handler
+ .endfunc
+
+ .global AT91F_Default_IRQ_handler
+ .func AT91F_Default_IRQ_handler
+AT91F_Default_IRQ_handler:
+ b AT91F_Default_IRQ_handler
+ .size AT91F_Default_IRQ_handler, . - AT91F_Default_IRQ_handler
+ .endfunc
+
+ .global AT91F_Spurious_handler
+ .func AT91F_Spurious_handler
+AT91F_Spurious_handler:
+ b AT91F_Spurious_handler
+ .size AT91F_Spurious_handler, . - AT91F_Spurious_handler
+ .endfunc
+
+
+
.end
personal git repositories of Harald Welte. Your mileage may vary