commit 92049a573650256bd927bf25aa2e2faef0075a35 Author: brandon Date: Fri Mar 21 19:55:17 2025 -0700 initial commit diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..18a387b Binary files /dev/null and b/.DS_Store differ diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..082f95a --- /dev/null +++ b/build.sh @@ -0,0 +1,18 @@ +x86_64-elf-as -o entry.o entry.s +echo "Successfully compiled entry" +x86_64-elf-gcc -ffreestanding -c -o kernel.o kernel.c -std=gnu11 -Wall -Wextra +echo "Succesfully compiled kernel" +x86_64-elf-gcc -ffreestanding -nostdlib -T linker.ld -o os.elf entry.o kernel.o +echo "Successfully compiled elf with linker" +echo "Connecting to spyro for remote compile..." +scp -r iso next@spyro.corp.bbrunson.com:~/OS/ +echo "Successfully transferred elf to spyro" +echo "Compiling ISO with GRUB..." +ssh next@spyro.corp.bbrunson.com 'grub-mkrescue -o ~/OS/os.iso ~/OS/iso' +echo "Successfully compiled OS" +echo "Transferring compiled ISO..." +scp -r next@spyro.corp.bbrunson.com:~/OS/os.iso . +echo "Successfully tranferred compiled ISO" +echo "= Compilation complete =" +echo "Booting ISO via QEMU..." +qemu-system-x86_64 -cdrom os.iso \ No newline at end of file diff --git a/entry.o b/entry.o new file mode 100644 index 0000000..010cdf9 Binary files /dev/null and b/entry.o differ diff --git a/entry.s b/entry.s new file mode 100644 index 0000000..0553e48 --- /dev/null +++ b/entry.s @@ -0,0 +1,7 @@ + .section .text + .globl _start # Declare _start as global + .extern kmain # Declare the external C function + +_start: + call kmain # Call the C kernel entry point + hlt # Halt if kmain returns diff --git a/iso/.DS_Store b/iso/.DS_Store new file mode 100644 index 0000000..9da35ae Binary files /dev/null and b/iso/.DS_Store differ diff --git a/iso/boot/.DS_Store b/iso/boot/.DS_Store new file mode 100644 index 0000000..11cb6f8 Binary files /dev/null and b/iso/boot/.DS_Store differ diff --git a/iso/boot/grub/grub.cfg b/iso/boot/grub/grub.cfg new file mode 100644 index 0000000..431c209 --- /dev/null +++ b/iso/boot/grub/grub.cfg @@ -0,0 +1,5 @@ +set timeout=5 +menuentry "My OS" { + multiboot /boot/os.elf + boot +} \ No newline at end of file diff --git a/iso/boot/os.elf b/iso/boot/os.elf new file mode 100755 index 0000000..04a010c Binary files /dev/null and b/iso/boot/os.elf differ diff --git a/kernel.c b/kernel.c new file mode 100644 index 0000000..a16b7ea --- /dev/null +++ b/kernel.c @@ -0,0 +1,11 @@ +/* kernel.c */ +#include "multiboot.h" + +// Define the kernel entry point. It must be declared extern "C" if you use C++. +void kmain(void) { + // Your kernel initialization and code here. + // For example, a simple infinite loop. + while (1) { + // Optionally, add code to print something to the screen. + } +} diff --git a/kernel.o b/kernel.o new file mode 100644 index 0000000..b46ac2b Binary files /dev/null and b/kernel.o differ diff --git a/linker.ld b/linker.ld new file mode 100644 index 0000000..b3f5ddb --- /dev/null +++ b/linker.ld @@ -0,0 +1,24 @@ +ENTRY(_start) +PHDRS { + header PT_LOAD FILEHDR PHDRS ALIGN(4) + kernel PT_LOAD FLAGS(5) +} + +SECTIONS +{ + /* Place the multiboot header at file offset 0 */ + . = 0; + .multiboot : { + KEEP(*(.multiboot)) + } AT(0) : header + + /* Place the remaining kernel sections starting at 1MB */ + . = 0x100000; + .text : { + *(.text*) + } : kernel + + .rodata : { *(.rodata*) } : kernel + .data : { *(.data*) } : kernel + .bss : { *(.bss*) } : kernel +} \ No newline at end of file diff --git a/make b/make new file mode 100644 index 0000000..49896bb --- /dev/null +++ b/make @@ -0,0 +1,14 @@ +CC=x86_64-elf-gcc +CFLAGS=-ffreestanding -O2 -Wall -Wextra +LDFLAGS=-T linker.ld + +all: os.bin + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +os.bin: boot.o kernel.o + $(CC) $(LDFLAGS) $^ -o $@ + +clean: + rm -f *.o os.bin \ No newline at end of file diff --git a/multiboot.h b/multiboot.h new file mode 100644 index 0000000..7493e8c --- /dev/null +++ b/multiboot.h @@ -0,0 +1,17 @@ +/* multiboot.h */ +#ifndef MULTIBOOT_H +#define MULTIBOOT_H + +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 +#define MULTIBOOT_HEADER_FLAGS 0x00010003 // Set flags as needed +#define MULTIBOOT_HEADER_CHECKSUM -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) + +// Place the multiboot header in a dedicated section so that the bootloader can find it. +__attribute__((section(".multiboot"))) +const unsigned int multiboot_header[3] = { + MULTIBOOT_HEADER_MAGIC, + MULTIBOOT_HEADER_FLAGS, + MULTIBOOT_HEADER_CHECKSUM +}; + +#endif // MULTIBOOT_H \ No newline at end of file diff --git a/os.elf b/os.elf new file mode 100755 index 0000000..53d378c Binary files /dev/null and b/os.elf differ diff --git a/os.iso b/os.iso new file mode 100755 index 0000000..e185ee1 Binary files /dev/null and b/os.iso differ