commit 932ec395c500f3a9c163e490585017617df578a2 Author: nub31 Date: Sun Dec 28 00:48:12 2025 +0100 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b7f1399 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.build \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b50f201 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2026 nub31 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5e60065 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Nub OS + +## Dependencies + +### Building the kernel + +- `grub` +- `mtools` +- `make` +- `x86_64-elf-gcc` +- `x86_64-elf-ld` +- `nasm` + +## Building + +### Disk image + +```sh +make iso +``` + +## Running + +After building the iso, run the following: + +```sh +qemu-system-x86_64 -cdrom .build/nub-os.iso +``` + +## Debugging + +```sh +qemu-system-x86_64 -s -S -cdrom .build/nub-os.iso +gdb -tui .build/kernel/kernel -ex "target remote localhost:1234" +``` diff --git a/makefile b/makefile new file mode 100644 index 0000000..482a282 --- /dev/null +++ b/makefile @@ -0,0 +1,44 @@ +CC = x86_64-elf-gcc +LD = x86_64-elf-ld +AS = nasm + +# Modify these settings here for defines and debug info +# CFLAGS = -g -D DEBUG +# LDFLAGS = -g +# ASFLAGS = -g -F dwarf + +# Do not modify +CFLAGS += -m64 -ffreestanding -nostdinc -nostdlib -Wall -Wextra -Wshadow -std=c23 +LDFLAGS += +ASFLAGS += -f elf64 + +SRC_C := $(shell find src -name '*.c') +SRC_ASM := $(shell find src -name '*.asm') + +OBJS := $(patsubst src/%.c, .build/%.o, $(SRC_C)) $(patsubst src/%.asm, .build/%.o, $(SRC_ASM)) + +iso: .build/nub-os.iso + @echo "ISO created at '.build/nub-os.iso'" + +run: .build/nub-os.iso + qemu-system-x86_64 -cdrom .build/nub-os.iso + +clean: + @rm -r .build 2>/dev/null || true + +.build/nub-os.iso: .build/nub-os src/grub.cfg + mkdir -p .build/grub/boot/grub + cp src/grub.cfg .build/grub/boot/grub + cp .build/nub-os .build/grub/boot/ + grub-mkrescue -o .build/nub-os.iso .build/grub/ + +.build/nub-os: $(OBJS) + $(LD) $(LDFLAGS) -T src/linker.ld -o $@ $^ + +.build/%.o: src/%.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -c -o $@ $< + +.build/%.o: src/%.asm + @mkdir -p $(dir $@) + $(AS) $(ASFLAGS) -o $@ $< \ No newline at end of file diff --git a/src/boot.asm b/src/boot.asm new file mode 100644 index 0000000..5ffd136 --- /dev/null +++ b/src/boot.asm @@ -0,0 +1,24 @@ +global entry + +%define MAGIC 0xe85250d6 +%define ARCH 0x0 +%define LENGTH (header.end - header.start) + +section .multiboot +align 8 +header: + .start: + dd MAGIC + dd ARCH + dd LENGTH + dd -(MAGIC + ARCH + LENGTH) + ; end tag + dw 0 + dw 0 + dd 8 + .end: + +section .text +bits 32 +entry: + jmp $ \ No newline at end of file diff --git a/src/grub.cfg b/src/grub.cfg new file mode 100644 index 0000000..eb30cc1 --- /dev/null +++ b/src/grub.cfg @@ -0,0 +1,6 @@ +menuentry "nub-os" { + multiboot2 /boot/nub-os +} + +set default="nub-os" +set timeout=0 diff --git a/src/linker.ld b/src/linker.ld new file mode 100644 index 0000000..df1f061 --- /dev/null +++ b/src/linker.ld @@ -0,0 +1,30 @@ +ENTRY(entry) + +SECTIONS +{ + . = 2M; + + .text : + { + *(.multiboot) + *(.text) + } + + .rodata : + { + *(.rodata) + } + + .data : + { + *(.data) + } + + .bss : + { + *(COMMON) + *(.bss) + } + + kernel_end = .; +} \ No newline at end of file