From: Robin Krens Date: Fri, 5 Jul 2019 09:09:55 +0000 (+0800) Subject: first commit, basic setup and makefile X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=fe0e1e676b1d1a3f151dbe8cdf7a54ec78e1723f;p=cortex-from-scratch first commit, basic setup and makefile --- fe0e1e676b1d1a3f151dbe8cdf7a54ec78e1723f diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cc01e47 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +CC=$(TOOLROOT)/arm-none-eabi-gcc +LD=arm-none-eabi-ld +AR=$(TOOLROOT)/arm-none-eabi-ar +AS=arm-none-eabi-as +MKIMG=arm-none-eabi-objcopy + +LDFLAGS+= -mthumb -mcpu=cortex-m3 +CFLAGS+= -mcpu=cortex-m3 -mthumb + +as: + $(AS) $(CFLAGS) -o start.o start.asm + +all: + $(AS) $(CFLAGS) -o start.o start.asm + $(LD) -T link.ld -o start.out start.o + $(MKIMG) -Obinary start.out kernel.bin + +run: + qemu-system-arm -monitor stdio -M lm3s6965evb -kernel kernel.bin + +examine: + arm-none-eabi-objdump -S start.out + +%.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + $(CC) -MM $(CFLAGS) $< > $*.d + +%.o: %.s + $(CC) -c $(CFLAGS) $< -o $@ + + + + diff --git a/link.ld b/link.ld new file mode 100644 index 0000000..00ce90e --- /dev/null +++ b/link.ld @@ -0,0 +1,21 @@ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 512K + SRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K +} + +ENTRY(_start) + +SECTIONS +{ + .text : ALIGN(4) + { + /* (.vector_table */ + *(.text) + + } > FLASH + .data : + { + *(.data) + } > SRAM +} diff --git a/start.asm b/start.asm new file mode 100644 index 0000000..8991594 --- /dev/null +++ b/start.asm @@ -0,0 +1,22 @@ + .equ STACK_TOP, 0x20000800 + .text + .global _start + .code 16 + .syntax unified +_start: + .word STACK_TOP, start + .type start, function + +/* Start of main program */ +start: + movs r0, #10 + movs r1, #5 +loop: + adds r1, r0 + subs r0, #1 + bne loop +/* Result is now in R1 */ +deadloop: + b deadloop + .end +