From: hackbard Date: Fri, 14 Sep 2007 22:22:31 +0000 (+0200) Subject: enhanced linker script and startup X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26b834d1801d8453bb25b6b427a6b6c3b131cf57;p=my-code%2Farm.git enhanced linker script and startup --- diff --git a/betty/Makefile b/betty/Makefile index f6d465f..28184c3 100644 --- a/betty/Makefile +++ b/betty/Makefile @@ -20,7 +20,7 @@ CROSS_TARGET = fwbc.hex fwflash.hex betty.hex # betty deps BETTY_DEPS = system.o uart.o buttons.o spi.o display.o flash.o functions.o -#BETTY_DEPS += pffs.o +BETTY_DEPS += interrupts.o #pffs.o # all projects all: $(HOST_TARGET) $(CROSS_TARGET) @@ -48,8 +48,8 @@ arm: arm_clean $(CROSS_TARGET) $(CROSS_AS) $(CROSS_ASLAGS) -o $@ $< # .elf out of .o -%.elf: %.o startup.o - $(CROSS_LD) $(CROSS_RAM_LDFLAGS) startup.o -o $@ $< +%.elf: %.o startup.o interrupts.o + $(CROSS_LD) $(CROSS_RAM_LDFLAGS) startup.o interrupts.o -o $@ $< # betty is special ;) betty.elf: betty.o startup.o $(BETTY_DEPS) diff --git a/betty/lpc2220_ram.ld b/betty/lpc2220_ram.ld index c6fd14d..7356893 100644 --- a/betty/lpc2220_ram.ld +++ b/betty/lpc2220_ram.ld @@ -20,7 +20,14 @@ SECTIONS { . = ALIGN(4); - .data : { *(.data) } /* initialized data */ + /* define end of text symbol */ + _etext = .; + + .data : { /* initialized data */ + _data = .; + *(.data) + _edata = .; + } . = ALIGN(4); diff --git a/betty/lpc2220_rom.ld b/betty/lpc2220_rom.ld index ab48644..92a99a0 100644 --- a/betty/lpc2220_rom.ld +++ b/betty/lpc2220_rom.ld @@ -32,12 +32,27 @@ SECTIONS { . = ALIGN(4); + /* define text end symbol */ + _etext = .; + PROVIDE(etext = .); + /* initialized data */ - .data : { *(.data) } > RAM AT FLASH_BANK0 + .data : { + _data = .; + *(.data) + } > RAM AT > FLASH_BANK0 . = ALIGN(4); + /* define data end symbol */ + _edata = .; + PROVIDE(edata = .); + /* uninitialized data */ - .bss : { *(.bss) } > RAM AT FLASH_BANK0 + .bss (NOLOAD) : { *(.bss) } > RAM + + /* define bss end symbol */ + _bss_end = .; + PROVIDE(bss_end = .); } diff --git a/betty/startup.s b/betty/startup.s index bc4ff41..af87f6e 100644 --- a/betty/startup.s +++ b/betty/startup.s @@ -16,10 +16,31 @@ # stack -.equ stack_size, (2*1024) +.equ stack_size, (4*1024) .equ stack_top, sram_top .equ stack_limit, (sram_top-stack_size) +.equ stack_size_fiq, 64 +.equ stack_size_irq, 256 +.equ stack_size_supervisor, 64 +.equ stack_size_abort, 64 +.equ stack_size_undefined, 64 +.equ stack_size_system, 1024 + +# arm modes - control bits of the program status register +# ref: chapter 2.8, arm7tdmi-s technical reference manual + +.equ mode_user, 0x10 +.equ mode_fiq, 0x11 +.equ mode_irq, 0x12 +.equ mode_supervisor, 0x13 +.equ mode_abort, 0x17 +.equ mode_undefined, 0x1b +.equ mode_system, 0x1f + +.equ fiq_disable, 0x40 +.equ irq_disable, 0x80 + # # the startup code # @@ -27,13 +48,72 @@ .text .arm - # init stack pointer + # exception handling must go to the very beginning + + b handler_reset + b handler_undef_instruction + b handler_soft_ir + b handler_prefetch_abort + b handler_data_abort + nop + b handler_irq + b handler_fiq + + handler_undef_instruction: .word interrupt_handler_undef_instruction + handler_soft_ir: .word interrupt_handler_soft_ir + handler_prefetch_abort: .word interrupt_handler_prefetch_abort + handler_data_abort: .word interrupt_handler_data_abort + handler_irq: .word interrupt_handler_irq + handler_fiq: .word interrupt_handler_fiq + + # reset handling goes here + +handler_reset: + + # init stack pointer for each mode + set stack limit ldr r0, =sram_top + + msr cpsr_c, #mode_undefined|irq_disable|fiq_disable mov sp, r0 + sub r0, r0, #stack_size_undefined + + msr cpsr_c, #mode_abort|irq_disable|fiq_disable + mov sp, r0 + sub r0, r0, #stack_size_abort + + msr cpsr_c, #mode_fiq|irq_disable|fiq_disable + mov sp, r0 + sub r0, r0, #stack_size_fiq + + msr cpsr_c, #mode_irq|irq_disable|fiq_disable + mov sp, r0 + sub r0, r0, #stack_size_irq + + msr cpsr_c, #mode_supervisor|irq_disable|fiq_disable + mov sp, r0 + sub r0, r0, #stack_size_supervisor + + msr cpsr_c, #mode_system|irq_disable|fiq_disable + mov sp, r0 + sub r0, r0, #stack_size_system + ldr r0, =stack_limit mov sl, r0 + # copy data section + + ldr r1, =_etext + ldr r2, =_data + ldr r3, =_edata + +copy_data_loop: + + cmp r2, r3 + ldrlo r0, [r1], #4 + strlo r0, [r2], #4 + blo copy_data_loop + # jump to c code adr lr, loop_forever