From: John Tsiombikas Date: Sun, 21 Oct 2018 22:48:25 +0000 (+0300) Subject: initial commit X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=rpikern;a=commitdiff_plain;h=e3851fa5fc01560a8ab799046b7cf0d2f35f18e8 initial commit --- e3851fa5fc01560a8ab799046b7cf0d2f35f18e8 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..db8b393 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.o +*.d +*.swp +*.bin +*.elf +link.map diff --git a/Makefile b/Makefile new file mode 100644 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 index 0000000..074a182 --- /dev/null +++ b/rpikern.ld @@ -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 index 0000000..ec157f6 --- /dev/null +++ b/src/startup.s @@ -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