This commit is contained in:
nub31
2025-12-28 00:48:12 +01:00
commit 932ec395c5
7 changed files with 149 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.build

9
LICENSE Normal file
View File

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

35
README.md Normal file
View File

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

44
makefile Normal file
View File

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

24
src/boot.asm Normal file
View File

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

6
src/grub.cfg Normal file
View File

@@ -0,0 +1,6 @@
menuentry "nub-os" {
multiboot2 /boot/nub-os
}
set default="nub-os"
set timeout=0

30
src/linker.ld Normal file
View File

@@ -0,0 +1,30 @@
ENTRY(entry)
SECTIONS
{
. = 2M;
.text :
{
*(.multiboot)
*(.text)
}
.rodata :
{
*(.rodata)
}
.data :
{
*(.data)
}
.bss :
{
*(COMMON)
*(.bss)
}
kernel_end = .;
}