initial commit

This commit is contained in:
2025-03-21 19:55:17 -07:00
commit 92049a5736
15 changed files with 96 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

18
build.sh Executable file
View File

@@ -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

BIN
entry.o Normal file

Binary file not shown.

7
entry.s Normal file
View File

@@ -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

BIN
iso/.DS_Store vendored Normal file

Binary file not shown.

BIN
iso/boot/.DS_Store vendored Normal file

Binary file not shown.

5
iso/boot/grub/grub.cfg Normal file
View File

@@ -0,0 +1,5 @@
set timeout=5
menuentry "My OS" {
multiboot /boot/os.elf
boot
}

BIN
iso/boot/os.elf Executable file

Binary file not shown.

11
kernel.c Normal file
View File

@@ -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.
}
}

BIN
kernel.o Normal file

Binary file not shown.

24
linker.ld Normal file
View File

@@ -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
}

14
make Normal file
View File

@@ -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

17
multiboot.h Normal file
View File

@@ -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

BIN
os.elf Executable file

Binary file not shown.

BIN
os.iso Executable file

Binary file not shown.