initial commit
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 21 Oct 2018 22:48:25 +0000 (01:48 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 21 Oct 2018 22:48:25 +0000 (01:48 +0300)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
rpikern.ld [new file with mode: 0644]
src/startup.s [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..db8b393
--- /dev/null
@@ -0,0 +1,6 @@
+*.o
+*.d
+*.swp
+*.bin
+*.elf
+link.map
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..739bfdd
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,53 @@
+csrc = $(wildcard src/*.c) $(wildcard src/libc/*.c)
+ssrc = $(wildcard src/*.s) $(wildcard src/libc/*.s)
+Ssrc = $(wildcard src/*.S) $(wildcard src/libc/*.S)
+obj = $(csrc:.c=.o) $(ssrc:.s=.o) $(Ssrc:.S=.o)
+dep = $(csrc:.c=.d)
+elf = rpikern.elf
+bin = rpikern.bin
+
+ifneq ($(shell uname -m | sed 's/^arm.*/arm/'), arm)
+       toolprefix = arm-linux-gnueabihf-
+       CPP = $(toolprefix)cpp
+       CC = $(toolprefix)gcc
+       AS = $(toolprefix)as
+       LD = $(toolprefix)ld
+       OBJCOPY = $(toolprefix)objcopy
+endif
+
+warn = -pedantic -Wall
+dbg = -g
+inc = -Isrc/libc
+gccopt = -fpic -ffreestanding -nostdinc
+arch = -mcpu=arm1176jzf-s
+
+CFLAGS = $(arch) $(warn) $(opt) $(dbg) $(gccopt) $(inc) $(def)
+ASFLAGS = $(arch) $(dbg) $(inc)
+LDFLAGS = -nostdlib -T rpikern.ld -print-gc-sections
+
+QEMU_FLAGS = -m 256 -M raspi2 -serial stdio
+
+
+$(bin): $(elf)
+       $(OBJCOPY) -O binary $< $@
+
+$(elf): $(obj)
+       $(LD) -o $@ $(obj) -Map link.map $(LDFLAGS)
+
+-include $(dep)
+
+%.d: %.c
+       @echo 'gen dep $@ ...'
+       @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
+
+.PHONY: clean
+clean:
+       rm -f $(obj) $(bin) $(elf) link.map
+
+.PHONY: cleandep
+cleandep:
+       rm -f $(dep)
+
+.PHONY: debug
+debug: $(elf)
+       qemu-system-arm $(QEMU_FLAGS) -kernel $(elf)
diff --git a/rpikern.ld b/rpikern.ld
new file mode 100644 (file)
index 0000000..074a182
--- /dev/null
@@ -0,0 +1,20 @@
+SECTIONS {
+       . = 0x00008000;
+       _kern_start = .;
+
+       .startup : { KEEP(* (.startup)) }
+       .text : { * (.text); }
+       .rotdata : { * (.rodata); }
+       .data : { * (.data); }
+
+       .bss ALIGN(4): {
+               _bss_start = .;
+               * (.bss);
+               . = ALIGN(4);
+               _bss_end = .;
+       }
+       _bss_size = SIZEOF(.bss);
+
+       _kern_size = . - _kern_start;
+       _mem_start = .;
+}
diff --git a/src/startup.s b/src/startup.s
new file mode 100644 (file)
index 0000000..ec157f6
--- /dev/null
@@ -0,0 +1,8 @@
+       .section .startup
+       @ clear bss
+       ldr r0, =_bss_start
+       ldr r1, =_bss_size
+       mov r2, #0
+0:     str r2, [r0], #4
+       subs r1, #4
+       bne 0b