diff --git a/bios_hello_world_c/README.adoc b/bios_hello_world_c/README.adoc new file mode 100644 index 0000000..df06e16 --- /dev/null +++ b/bios_hello_world_c/README.adoc @@ -0,0 +1,3 @@ +TODO not working. + +A single stage educational minimal C BIOS hello world example for: https://stackoverflow.com/questions/22054578/how-to-run-a-program-without-an-operating-system/32483545#32483545 diff --git a/bios_hello_world_c/build.sh b/bios_hello_world_c/build.sh new file mode 100755 index 0000000..4f1b7b6 --- /dev/null +++ b/bios_hello_world_c/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -eux +as -ggdb3 -o entry.o entry.S +gcc -c -ggdb3 -nostartfiles -nostdlib -o main.o main.c +ld -o main.elf -T linker.ld entry.o main.o +ld --oformat binary -o main.img -T linker.ld entry.o main.o +qemu-system-x86_64 -hda main.img diff --git a/bios_hello_world_c/entry.S b/bios_hello_world_c/entry.S new file mode 100644 index 0000000..f3eed8a --- /dev/null +++ b/bios_hello_world_c/entry.S @@ -0,0 +1,6 @@ +.text +.global mystart +mystart: + mov %rsp, __stack_top + call main + jmp . diff --git a/bios_hello_world_c/linker.ld b/bios_hello_world_c/linker.ld new file mode 100644 index 0000000..a5ac46a --- /dev/null +++ b/bios_hello_world_c/linker.ld @@ -0,0 +1,17 @@ +ENTRY(mystart) +SECTIONS +{ + .text : { + entry.o(.text) + *(.text) + *(.rodata) + *(.data) + /**(.eh_frame)*/ + . = 0x1FE; + SHORT(0xAA55) + } + /* Reserve 16 MiB of stack. */ + __stack_bottom = .; + . = . + 0x1000000; + __stack_top = .; +} diff --git a/bios_hello_world_c/main.c b/bios_hello_world_c/main.c new file mode 100644 index 0000000..e846e18 --- /dev/null +++ b/bios_hello_world_c/main.c @@ -0,0 +1,3 @@ +void main(void) { + while (1); +}