summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-10-05 08:56:38 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-10-05 08:58:29 -0700
commit4d21315f667c03eaf44a580c3435f73853b53dbf (patch)
tree881a6caabe9f289a7bc6e8ad9fd67279f4d09eba
downloadmacaroni-4d21315f667c03eaf44a580c3435f73853b53dbf.tar.gz
macaroni-4d21315f667c03eaf44a580c3435f73853b53dbf.zip
Init
-rw-r--r--.gitignore7
-rw-r--r--Makefile37
-rw-r--r--build/.gitkeep0
-rw-r--r--linker.ld9
-rw-r--r--src/boot.asm31
-rw-r--r--src/kernel.c36
6 files changed, 120 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..44984ee
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+/limine-binary
+/limine-binary.tar.gz
+/edk2-ovmf-bins
+/edk2-ovmf-bins.tar.gz
+/iso_root
+*.iso
+*.hdd
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9779670
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,37 @@
+.DEFAULT_GOAL := macaroni.iso
+
+LIMINE_SHARE = /opt/homebrew/share/limine/
+
+BUILD_OUT = build
+ASM = nasm
+ASM_FLAGS = -felf32
+CFLAG = -std=c11 -ffreestanding -O0 -Wall -Wextra
+CC = i686-elf-gcc
+BINFLAG = -T linker.ld -ffreestanding -O0 -nostdlib -lgcc
+
+boot.o: src/boot.asm
+ ${ASM} ${ASM_FLAGS} src/boot.asm -o ${BUILD_OUT}/boot.o
+
+kernel.o: src/kernel.c
+ ${CC} -c src/kernel.c -o ${BUILD_OUT}/kernel.o ${CFLAG}
+
+macaroni.bin: boot.o kernel.o
+ ${CC} -o ${BUILD_OUT}/macaroni.bin ${BINFLAG} ${BUILD_OUT}/*.o
+
+macaroni.iso: macaroni.bin
+ mkdir -p ${BUILD_OUT}/iso
+ cp ${BUILD_OUT}/macaroni.bin ${BUILD_OUT}/iso/macaroni.bin
+ printf "timeout: 0\n/macaroni\n protocol: multiboot1\n kernel_path: boot():/macaroni.bin\n" > ${BUILD_OUT}/iso/limine.conf
+ cp ${LIMINE_SHARE}/limine-bios-cd.bin ${LIMINE_SHARE}/limine-bios.sys ${LIMINE_SHARE}/limine-uefi-cd.bin ${BUILD_OUT}/iso/
+ xorriso -as mkisofs -R -r -J -b limine-bios-cd.bin -no-emul-boot -boot-load-size 4 -boot-info-table \
+ --efi-boot limine-uefi-cd.bin -efi-boot-part --efi-boot-image --protective-msdos-label \
+ ${BUILD_OUT}/iso -o ${BUILD_OUT}/macaroni.iso
+ limine bios-install ${BUILD_OUT}/macaroni.iso
+
+.PHONY: demo
+demo: macaroni.iso
+ qemu-system-x86_64 -cdrom ${BUILD_OUT}/macaroni.iso
+
+.PHONY: clean
+clean:
+ rm -rf ${BUILD_OUT}/**
diff --git a/build/.gitkeep b/build/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/build/.gitkeep
diff --git a/linker.ld b/linker.ld
new file mode 100644
index 0000000..29da3f9
--- /dev/null
+++ b/linker.ld
@@ -0,0 +1,9 @@
+ENTRY(_start)
+SECTIONS
+{
+ . = 2M;
+ .text BLOCK(4K) : ALIGN(4K) { *(.multiboot_header) *(.text) }
+ .rodata BLOCK(4K) : ALIGN(4K) { *(.rodata) }
+ .data BLOCK(4K) : ALIGN(4K) { *(.data) }
+ .bss BLOCK(4K) : ALIGN(4K) { *(COMMON) *(.bss) }
+}
diff --git a/src/boot.asm b/src/boot.asm
new file mode 100644
index 0000000..cbf57d6
--- /dev/null
+++ b/src/boot.asm
@@ -0,0 +1,31 @@
+;> The Multiboot header must be contained completely within the first 8192 bytes of the OS
+;> image, and must be longword (32-bit) aligned.
+MULTIBOOT_ALIGN_TO_PAGE: equ 1 << 0
+MULTIBOOT_MEMORY_DESCRIBE: equ 1 << 2
+MULTIBOOT_MAGIC: equ 0x1BADB002
+MULTIBOOT_FLAGS: equ (MULTIBOOT_ALIGN_TO_PAGE | MULTIBOOT_MEMORY_DESCRIBE)
+MULTIBOOT_CHECKSUM: equ -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS)
+section .multiboot_header
+align 4
+ dd MULTIBOOT_MAGIC
+ dd MULTIBOOT_FLAGS
+ dd MULTIBOOT_CHECKSUM
+
+STACK_SIZE: equ (1 << 14)
+section .bss
+align 16
+stack_bottom:
+ resb STACK_SIZE
+stack_top:
+
+section .text
+global _start:function (_start.end - _start)
+_start:
+ mov esp, stack_top
+ extern cmain
+ call cmain
+ cli
+
+jmp $
+
+.end:
diff --git a/src/kernel.c b/src/kernel.c
new file mode 100644
index 0000000..1459f73
--- /dev/null
+++ b/src/kernel.c
@@ -0,0 +1,36 @@
+#include <stddef.h>
+#include <stdint.h>
+
+#define WIDTH 80
+#define HEIGHT 25
+
+#define BLACK 0
+#define BLUE 1
+#define GREEN 2
+#define RED 4
+#define MAGENTA 13
+#define WHITE 15
+
+int strlen(char* s) {
+ int n = 0;
+ char* s_ptr = s;
+ while (*(s_ptr++)) {
+ n++;
+ }
+ return n;
+}
+
+void cmain(void) {
+ uint16_t* vgamem = (uint16_t*) 0xB8000;
+ uint16_t vgacolors[6] = {WHITE | RED << 4, WHITE | GREEN << 4, WHITE | BLUE << 4, BLACK | RED << 4, BLACK | GREEN << 4, BLACK | BLUE << 4};
+ char* s = "Hello world!";
+ int i,j,k;
+ for (k = 0; k >= 0; ++k) {
+ k = (k % 5);
+ j = 0;
+ while (j < 100000000) { j++; } // Since we don't have an interrupt descriptor table we can't use the PIC; this emulates "sleeping"
+ for (i = 0; i < WIDTH*HEIGHT; i++) {
+ vgamem[i] = s[i % strlen(s)] | vgacolors[(i+k) % 6] << 8;
+ }
+ }
+} \ No newline at end of file