diff options
author | Bad Diode <bd@badd10de.dev> | 2021-09-07 10:48:33 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-09-07 10:48:33 +0200 |
commit | 4b86e6272166236c9283004f6a060d5174165796 (patch) | |
tree | 67521dabe329b256c27761fa2a93a837b8e3fec4 | |
download | uxnrpi-4b86e6272166236c9283004f6a060d5174165796.tar.gz uxnrpi-4b86e6272166236c9283004f6a060d5174165796.zip |
Initial commit: bootstrap
-rw-r--r-- | Makefile | 47 | ||||
-rw-r--r-- | src/linker.ld | 34 | ||||
-rw-r--r-- | src/main.c | 3 | ||||
-rw-r--r-- | src/start.s | 11 |
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. | ||
6 | AS := arm-none-eabi-as | ||
7 | CC := arm-none-eabi-gcc | ||
8 | OBJCOPY := arm-none-eabi-objcopy | ||
9 | |||
10 | # Paths. | ||
11 | SRC_DIR := src | ||
12 | BUILD_DIR := build | ||
13 | |||
14 | # Output files. | ||
15 | ELF := $(BUILD_DIR)/kernel7.elf | ||
16 | IMG := $(BUILD_DIR)/kernel7.img | ||
17 | |||
18 | # Bootstrapping files. | ||
19 | OBJ_START = $(BUILD_DIR)/start.o | ||
20 | OBJ_MAIN = $(BUILD_DIR)/main.o | ||
21 | SRC_LINK = $(SRC_DIR)/linker.ld | ||
22 | |||
23 | CFLAGS := -Wall -ffreestanding -O2 -nostdlib -lgcc -mgeneral-regs-only | ||
24 | AFLAGS := | ||
25 | |||
26 | default: $(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 | |||
40 | clean: | ||
41 | rm -rf $(BUILD_DIR) | ||
42 | |||
43 | $(BUILD_DIR): | ||
44 | mkdir -p $(BUILD_DIR) | ||
45 | |||
46 | run: $(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 @@ | |||
1 | ENTRY(_start) | ||
2 | |||
3 | SECTIONS | ||
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 @@ | |||
1 | void 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 | |||
9 | halt: | ||
10 | wfe | ||
11 | b halt | ||