From: hackbard Date: Fri, 31 Aug 2007 08:06:14 +0000 (+0200) Subject: added initial linker script and tartup asm code X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21b21d3d5c7feb1ece4c8ea3d495e03c502450ea;p=my-code%2Farm.git added initial linker script and tartup asm code --- diff --git a/betty/Makefile b/betty/Makefile index b5b6a5f..dfd3fee 100644 --- a/betty/Makefile +++ b/betty/Makefile @@ -5,12 +5,18 @@ CFLAGS = -Wall # cross build ARCH = arm-elf CROSS_CC = $(ARCH)-gcc +CROSS_AS = $(ARCH)-as +CROSS_LD = $(ARCH)-ld CROSS_OBJCOPY = $(ARCH)-objcopy -CROSS_CFLAGS = -Wall -Os -mcpu=arm7tdmi-s -nostartfiles -nostdlib +CROSS_OPTS = -mcpu=arm7tdmi-s +CROSS_CFLAGS = $(CROSS_OPTS) -Wall -Os +CROSS_ASLAGS = $(CROSS_OPTS) --gstabs +CROSS_RAM_LDFLAGS = -Tlpc2220_ram.ld -nostartfiles -nostdlib +CROSS_ROM_LDFLAGS = -Tlpc2220_rom.ld -nostartfiles -nostdlib # build objects HOST_TARGET = lpcload fwdump -CROSS_TARGET = fwbc.hex fwflash.hex +CROSS_TARGET = fwbc.hex fwflash.hex fwflash.elf # debug: .elf for objdump # all projects all: $(HOST_TARGET) $(CROSS_TARGET) @@ -18,22 +24,27 @@ all: $(HOST_TARGET) $(CROSS_TARGET) # arm code arm: arm_clean $(CROSS_TARGET) -# fwbc -fwbc: - $(CROSS_CC) $(CROSS_CFLAGS) -c fwbc.c -o fwbc +# .o out of .c +%.o: %.c + $(CROSS_CC) -c $(CROSS_CFLAGS) -o $@ $< -fwbc.hex: fwbc - $(CROSS_OBJCOPY) -O ihex fwbc fwbc.hex +# .o out of .s +%.o: %.s + $(CROSS_AS) $(CROSS_ASLAGS) -o $@ $< -# fwflash -fwflash: - $(CROSS_CC) $(CROSS_CFLAGS) -c fwflash.c -o fwflash +# .elf out of .o +%.elf: %.o startup.o + $(CROSS_LD) $(CROSS_RAM_LDFLAGS) startup.o -o $@ $< -fwflash.hex: fwflash - $(CROSS_OBJCOPY) -O ihex fwflash fwflash.hex +# .hex out of .elf +%.hex: %.elf + $(CROSS_OBJCOPY) -O ihex $< $@ +# host clean clean: rm -f lpcload fwdump +# arm clean arm_clean: - rm -f $(CROSS_TARGET) fwbc fwflash + rm -vf *.o *.hex *.elf + diff --git a/betty/lpc2220_ram.ld b/betty/lpc2220_ram.ld new file mode 100644 index 0000000..c6fd14d --- /dev/null +++ b/betty/lpc2220_ram.ld @@ -0,0 +1,29 @@ +/* + * lpc2220_ram.ld - linker script for the lpc2220 device (->ram) + * + * author: hackbard@hackdaworld.org + * + */ + +SECTIONS { + . = 0x40000200; + .text . : { + startup.o(.text) /* startup code */ + *(.text) /* all remaining code */ + *(.glue_7) /* glue code */ + *(.glue_7t) /* glue code */ + } + + . = ALIGN(4); + + .rodata : { *(.rodata) } /* read only data */ + + . = ALIGN(4); + + .data : { *(.data) } /* initialized data */ + + . = ALIGN(4); + + .bss : { *(.bss) } /* uninitialized data */ +} + diff --git a/betty/lpc2220_rom.ld b/betty/lpc2220_rom.ld new file mode 100644 index 0000000..11fa38d --- /dev/null +++ b/betty/lpc2220_rom.ld @@ -0,0 +1,43 @@ +/* + * lpc2220_rom.ld - linker script for the lpc2220 device (->rom) + * + * author: hackbard@hackdaworld.org + * + */ + +/* memory definitions */ + +MEMORY { + FLASH_BANK0 (rx) : ORIGIN=0x80000000, LENGTH=0x00100000 + FLASH_BANK2 (rx) : ORIGIN=0x82000000, LENGTH=0x00100000 + RAM (rw) : ORIGIN=0x40000000, LENGTH=0x00010000 +} + +/* section definitions */ + +SECTIONS { + + /* startup and user code (.text) */ + .text : { + startup.o(.text) // startup code + *(.text) // our code + *(.glue_7) // glue code + *(.glue_7t) // glue code + } > FLASH_BANK0 + + . = ALIGN(4) + + /* read only data */ + .rodata : { *(.rodata) } > FLASH_BANK0 + + . = ALIGN(4) + + /* initialized data */ + .data : { *(.data) } > RAM + + . = ALIGN(4); + + /* uninitialized data */ + .bss : { *(.bss) } > RAM +} + diff --git a/betty/startup.s b/betty/startup.s new file mode 100644 index 0000000..bc4ff41 --- /dev/null +++ b/betty/startup.s @@ -0,0 +1,47 @@ +# +# startup.s - starup code for the lpc2220 +# +# author: hackbard@hackdaworld.org +# + +# +# some definitions +# + +# sram + +.equ sram_size, (64*1024) +.equ sram_addr, 0x40000000 +.equ sram_top, (sram_addr+sram_size-4) + +# stack + +.equ stack_size, (2*1024) +.equ stack_top, sram_top +.equ stack_limit, (sram_top-stack_size) + +# +# the startup code +# + +.text +.arm + + # init stack pointer + + ldr r0, =sram_top + mov sp, r0 + ldr r0, =stack_limit + mov sl, r0 + + # jump to c code + + adr lr, loop_forever + mov r0, #0 + mov r1, #0 + ldr r2, =main + bx r2 + +loop_forever: + b loop_forever +