From 8466e9b4d2fbca85d53d8dadc87914b4766c43de Mon Sep 17 00:00:00 2001 From: wires Date: Wed, 19 Mar 2025 17:09:41 -0400 Subject: initial commit --- src/Link.ld | 35 +++++++++++++++++++++++++++++++++++ src/main.zig | 3 +++ src/startup.s | 28 ++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/Link.ld create mode 100644 src/main.zig create mode 100644 src/startup.s (limited to 'src') diff --git a/src/Link.ld b/src/Link.ld new file mode 100644 index 0000000..aec6d6a --- /dev/null +++ b/src/Link.ld @@ -0,0 +1,35 @@ +ENTRY(_start) +OUTPUT_FORMAT("elf64-littleaarch64") + +SECTIONS { + __kernel_load_address = 0x80000; + __stack_base = __kernel_load_address; + + . = __kernel_load_address; + + .init : { + KEEP(*(.init)) + } + + .text : { + *(.text) + *(.text.*) + *(.gnu.linkonce.t*) + } + + . = ALIGN(CONSTANT(MAXPAGESIZE)); + __bss_start = .; + .bss (NOLOAD) : { + *(.bss*) + *(.gnu.linkonce.b*) + *(COMMON) + } + __bss_end = .; + __bss_size = (__bss_end - __bss_start) / 8; + + . = ALIGN(CONSTANT(COMMONPAGESIZE)); + .rodata : { *(.rodata*) *(.gnu.linkonce.d*) } + + . = ALIGN(CONSTANT(COMMONPAGESIZE)); + .data : { *(.data*) *(.gnu.linkonce.d*) } +} diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..602f270 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,3 @@ +export fn main() callconv(.C) void { + while (true) {} +} diff --git a/src/startup.s b/src/startup.s new file mode 100644 index 0000000..e0c6385 --- /dev/null +++ b/src/startup.s @@ -0,0 +1,28 @@ +.section ".init" +.global _start + +_start: + mrs x1, MPIDR_EL1 + and x1, x1, 0b11 + + cbz x1, init +halt: + wfe + b halt + +init: + adr x1, __stack_base + mov sp, x1 + + adr x1, __bss_start + adr x2, __bss_size + cbz x2, exec_kernel + +clear_bss: + str xzr, [x1], 8 + sub x2, x2, 1 + cbnz w2, clear_bss + +exec_kernel: + bl main + b halt -- cgit 1.4.1