diff options
author | Ingo Albrecht <prom@berlin.ccc.de> | 2010-04-18 08:08:43 +0200 |
---|---|---|
committer | Ingo Albrecht <prom@berlin.ccc.de> | 2010-07-20 14:41:19 +0200 |
commit | 02d57bfcf9a68439bacd5aa9b16e76c859f0959f (patch) | |
tree | 6682e5cecf4074fc1c326650b6fa6dbecc3cf711 /src/target/firmware/board | |
parent | e4ad7b6827acb7529e5a0116ea01126c629d4ede (diff) |
firmware: modularized startup code
Diffstat (limited to 'src/target/firmware/board')
-rw-r--r-- | src/target/firmware/board/compal/macros.S (renamed from src/target/firmware/board/compal/start.S) | 70 | ||||
-rw-r--r-- | src/target/firmware/board/compal/ram.lds | 29 | ||||
-rw-r--r-- | src/target/firmware/board/compal/start.ram.S | 26 | ||||
-rw-r--r-- | src/target/firmware/board/compal/start.rom.S | 29 | ||||
-rw-r--r-- | src/target/firmware/board/compal_e88/loader.lds | 26 |
5 files changed, 134 insertions, 46 deletions
diff --git a/src/target/firmware/board/compal/start.S b/src/target/firmware/board/compal/macros.S index dcbe1e8f..559246d2 100644 --- a/src/target/firmware/board/compal/start.S +++ b/src/target/firmware/board/compal/macros.S @@ -1,4 +1,24 @@ +.macro clear_bss + mov r0, #0 + ldr r1, =__bss_start + ldr r2, =__bss_end +2: cmp r1, r2 + strlo r0, [r1], #4 + blo 2b +.endm + +.macro copy_data + ldr r0, =__data_start + ldr r1, =_data_start + ldr r2, =__data_end +copy: + ldrb r4, [r0], #1 + strb r4, [r1], #1 + cmp r0, r2 + bne copy +.endm + .EQU ARM_MODE_FIQ, 0x11 .EQU ARM_MODE_IRQ, 0x12 .EQU ARM_MODE_SVC, 0x13 @@ -9,21 +29,8 @@ #define TOP_OF_RAM 0x083fff0 #define FIQ_STACK_SIZE 1024 #define IRQ_STACK_SIZE 1024 - -.section .text.start - -.globl _start -_start: - /* clear bss section */ - .global __bss_start - .global __bss_end - mov r0, #0 - ldr r1, =__bss_start - ldr r2, =__bss_end -2: cmp r1, r2 - strlo r0, [r1], #4 - blo 2b - + +.macro init_stacks /* initialize stacks, starting at TOP_OF_RAM */ ldr r0, =TOP_OF_RAM @@ -40,35 +47,12 @@ _start: /* initialize supervisor stack */ msr CPSR_c, #ARM_MODE_SVC | I_BIT | F_BIT mov r13, r0 +.endm - /* set backlight to moderate level */ - bl pwl_init - mov r0, #50 - bl pwl_set_level - - /* test uart output */ - @ldr r0, =string - @bl puts_asm - - /* dump some memory */ - @ldr r0, =0xfffef000 - @bl memdump - @ldr r0, =0xfffffe00 - @bl memdump - +.macro call_ctors /* call constructor functions */ - ldr r0, _ctor_list - ldr r1, _ctor_end + ldr r0, =_ctor_start + ldr r1, =_ctor_end bl do_global_ctors - - /* jump to main */ - ldr pc, _jump_main - - /* endless loop at end of program */ -_end: b _end - b _start - -_jump_main: .word main -_ctor_list: .word __CTOR_LIST__ -_ctor_end: .word __CTOR_END__ +.endm diff --git a/src/target/firmware/board/compal/ram.lds b/src/target/firmware/board/compal/ram.lds index d6df49a9..aa71d3a0 100644 --- a/src/target/firmware/board/compal/ram.lds +++ b/src/target/firmware/board/compal/ram.lds @@ -54,9 +54,6 @@ SECTIONS /* constructors and destructors */ . = ALIGN(4); __CTOR_LIST__ = .; - LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) - KEEP(*(SORT(.ctors))) - LONG(0) /* end of list */ __CTOR_END__ = .; __DTOR_LIST__ = .; LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) @@ -67,6 +64,32 @@ SECTIONS PROVIDE(_text_start = LOADADDR(.text)); PROVIDE(_text_end = LOADADDR(.text) + SIZEOF(.text)); + /* constructor pointers */ + . = ALIGN(4); + .ctors : { + /* ctor count */ + LONG(SIZEOF(.ctors) / 4 - 2) + /* ctor pointers */ + KEEP(*(SORT(.ctors))) + /* end of list */ + LONG(0) + } + PROVIDE(_ctor_start = LOADADDR(.ctors)); + PROVIDE(_ctor_end = LOADADDR(.ctors) + SIZEOF(.ctors)); + + /* destructor pointers */ + . = ALIGN(4); + .dtors : { + /* dtor count */ + LONG(SIZEOF(.dtors) / 4 - 2) + /* dtor pointers */ + KEEP(*(SORT(.dtors))) + /* end of list */ + LONG(0) + } + PROVIDE(_dtor_start = LOADADDR(.dtors)); + PROVIDE(_dtor_end = LOADADDR(.dtors) + SIZEOF(.dtors)); + /* read-only data */ . = ALIGN(4); .rodata : { diff --git a/src/target/firmware/board/compal/start.ram.S b/src/target/firmware/board/compal/start.ram.S new file mode 100644 index 00000000..c8f242c0 --- /dev/null +++ b/src/target/firmware/board/compal/start.ram.S @@ -0,0 +1,26 @@ + +.section .text.start + +#include "macros.S" + +.globl _start +_start: + /* clear bss section */ + clear_bss + + /* initialize all stacks */ + init_stacks + + /* call constructors */ + call_ctors + + /* jump to main */ + ldr pc, _jump_main + + /* endless loop at end of program */ +_loop: + b _loop + b _start + +_jump_main: + .word main diff --git a/src/target/firmware/board/compal/start.rom.S b/src/target/firmware/board/compal/start.rom.S new file mode 100644 index 00000000..36f33336 --- /dev/null +++ b/src/target/firmware/board/compal/start.rom.S @@ -0,0 +1,29 @@ + +.section .text.start + +#include "macros.S" + +.globl _start +_start: + /* clear bss section */ + clear_bss + + /* copy data to ram */ + copy_data + + /* initialize all stacks */ + init_stacks + + /* call constructors */ + call_ctors + + /* jump to main */ + ldr pc, _jump_main + + /* endless loop at end of program */ +_loop: + b _loop + b _start + +_jump_main: + .word main diff --git a/src/target/firmware/board/compal_e88/loader.lds b/src/target/firmware/board/compal_e88/loader.lds index 3d821ae8..2a7c0600 100644 --- a/src/target/firmware/board/compal_e88/loader.lds +++ b/src/target/firmware/board/compal_e88/loader.lds @@ -61,6 +61,32 @@ SECTIONS PROVIDE(_text_start = ADDR(.text)); PROVIDE(_text_end = ADDR(.text) + SIZEOF(.text)); + /* constructor pointers */ + . = ALIGN(4); + .ctors : { + /* ctor count */ + LONG(SIZEOF(.ctors) / 4 - 2) + /* ctor pointers */ + KEEP(*(SORT(.ctors))) + /* end of list */ + LONG(0) + } + PROVIDE(_ctor_start = LOADADDR(.ctors)); + PROVIDE(_ctor_end = LOADADDR(.ctors) + SIZEOF(.ctors)); + + /* destructor pointers */ + . = ALIGN(4); + .dtors : { + /* dtor count */ + LONG(SIZEOF(.dtors) / 4 - 2) + /* dtor pointers */ + KEEP(*(SORT(.dtors))) + /* end of list */ + LONG(0) + } + PROVIDE(_dtor_start = LOADADDR(.dtors)); + PROVIDE(_dtor_end = LOADADDR(.dtors) + SIZEOF(.dtors)); + /* read-only data */ .rodata : { *(.rodata*) |