aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-09-07 10:48:33 +0200
committerBad Diode <bd@badd10de.dev>2021-09-07 10:48:33 +0200
commit4b86e6272166236c9283004f6a060d5174165796 (patch)
tree67521dabe329b256c27761fa2a93a837b8e3fec4
downloaduxnrpi-4b86e6272166236c9283004f6a060d5174165796.tar.gz
uxnrpi-4b86e6272166236c9283004f6a060d5174165796.zip
Initial commit: bootstrap
-rw-r--r--Makefile47
-rw-r--r--src/linker.ld34
-rw-r--r--src/main.c3
-rw-r--r--src/start.s11
4 files changed, 95 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..475c160
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,47 @@
1.POSIX:
2.SUFFIXES:
3.PHONY: clean run
4
5# Compiler.
6AS := arm-none-eabi-as
7CC := arm-none-eabi-gcc
8OBJCOPY := arm-none-eabi-objcopy
9
10# Paths.
11SRC_DIR := src
12BUILD_DIR := build
13
14# Output files.
15ELF := $(BUILD_DIR)/kernel7.elf
16IMG := $(BUILD_DIR)/kernel7.img
17
18# Bootstrapping files.
19OBJ_START = $(BUILD_DIR)/start.o
20OBJ_MAIN = $(BUILD_DIR)/main.o
21SRC_LINK = $(SRC_DIR)/linker.ld
22
23CFLAGS := -Wall -ffreestanding -O2 -nostdlib -lgcc -mgeneral-regs-only
24AFLAGS :=
25
26default: $(IMG)
27
28$(BUILD_DIR)/%.o: $(SRC_DIR)/%.s
29 $(AS) $(AFLAGS) -o $@ -c $<
30
31$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
32 $(CC) $(CFLAGS) -o $@ -c $<
33
34$(IMG): $(BUILD_DIR) $(ELF)
35 $(OBJCOPY) $(ELF) -O binary $(IMG)
36
37$(ELF): $(OBJ_START) $(OBJ_MAIN)
38 $(CC) $(CFLAGS) -T $(SRC_LINK) -o $(ELF) $(OBJ_START) $(OBJ_MAIN)
39
40clean:
41 rm -rf $(BUILD_DIR)
42
43$(BUILD_DIR):
44 mkdir -p $(BUILD_DIR)
45
46run: $(IMG)
47 qemu-system-aarch64 -M raspi3 -kernel $(IMG) -d in_asm -serial null -serial stdio
diff --git a/src/linker.ld b/src/linker.ld
new file mode 100644
index 0000000..f3482e9
--- /dev/null
+++ b/src/linker.ld
@@ -0,0 +1,34 @@
1ENTRY(_start)
2
3SECTIONS
4{
5 . = 0x8000;
6 __start = .;
7 .text :
8 {
9 KEEP(*(.text.boot))
10 *(.text)
11 }
12 . = ALIGN(4096);
13 .rodata :
14 {
15 *(.rodata)
16 }
17 . = ALIGN(4096);
18 .data :
19 {
20 *(.data)
21 }
22 . = ALIGN(4096);
23 __bss_start = .;
24 .bss :
25 {
26 bss = .;
27 *(.bss)
28 }
29 . = ALIGN(4096);
30 __bss_end = .;
31 __bss_size = __bss_end - __bss_start;
32 __end = .;
33}
34
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..1ce2dd1
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,3 @@
1void main(void) {
2 while(1);
3}
diff --git a/src/start.s b/src/start.s
new file mode 100644
index 0000000..0fd2a5f
--- /dev/null
+++ b/src/start.s
@@ -0,0 +1,11 @@
1.section ".text.boot"
2
3.global _start
4
5_start:
6 ldr r3, =main
7 blx r3
8
9halt:
10 wfe
11 b halt