Last active
August 2, 2022 11:12
-
-
Save ikskuh/e6892e7ab235cbfe92121ebffef6944d to your computer and use it in GitHub Desktop.
Arm 32 Kernel Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
clear | |
zig build-exe -target arm-freestanding-eabi -mcpu baseline -T linker.ld -fsingle-threaded -fno-omit-frame-pointer -O ReleaseFast --name kernel kernel.zig | |
llvm-objdump -dt kernel | |
llvm-objcopy -O binary kernel kernel.bin | |
# cp kernel.bin disk.img | |
# fallocate -l 64M disk.img | |
dd if=/dev/zero of=disk.img bs=1M count=64 | |
dd if=kernel.bin of=disk.img conv=notrunc | |
qemu-system-arm -drive if=pflash,file=disk.img,format=raw -M virt -serial stdio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export fn _start() linksection(".text._start") callconv(.Naked) void { | |
const data = @intToPtr(*volatile u8, 0x9000000); | |
for ("Hello\r\n") |c| { | |
data.* = c; | |
} | |
while (true) {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MEMORY | |
{ | |
flash (RX) : ORIGIN = 0x00000000, LENGTH = 32M | |
dram (RWX) : ORIGIN = 0x40000000, LENGTH = 16M | |
} | |
ENTRY(_start) | |
SECTIONS { | |
. = ORIGIN(flash); | |
__kernel_flash_start = .; | |
.text : { | |
*(.text._start) | |
*(.text) | |
*(.text.*) | |
} > flash | |
.rodata : { | |
. = ALIGN(4); | |
*(.rodata) | |
*(.rodata.*) | |
} > flash | |
. = ALIGN(4); | |
__kernel_flash_end = . ; | |
.stack (NOLOAD) : { | |
. = ALIGN(4096); | |
kernel_stack_start = .; | |
. += 0x8000; | |
kernel_stack = .; | |
} > dram | |
.data : AT (__kernel_flash_end){ | |
__kernel_data_start = .; | |
*(.data) | |
*(.data.*) | |
*(.sdata) | |
*(.sdata.*) | |
. = ALIGN(4); | |
__kernel_data_end = .; | |
} > dram | |
.bss (NOLOAD) : { | |
__kernel_bss_start = .; | |
*(.bss) | |
*(.bss.*) | |
*(.sbss) | |
*(.sbss.*) | |
. = ALIGN(4); | |
__kernel_bss_end = .; | |
} > dram | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment