Skip to content
This repository was archived by the owner on Dec 31, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
05de70f
Doing paging...
viktorpopp Nov 12, 2025
26bc1b4
Kinda working
viktorpopp Nov 12, 2025
c1cea98
Almost finished paging
viktorpopp Nov 12, 2025
e1ed82c
Finished page table creation
viktorpopp Nov 12, 2025
1e39394
Finished paging
viktorpopp Nov 12, 2025
3073eb8
Fixed PMM
viktorpopp Nov 13, 2025
41fc11e
General improvements
viktorpopp Nov 13, 2025
34a2243
VMM in progress...
viktorpopp Nov 16, 2025
23c6147
Finished VMM context initialization
viktorpopp Nov 17, 2025
e5a783e
Added testing data structures
viktorpopp Nov 18, 2025
f8bc4f3
Testing works (kinda)
viktorpopp Nov 18, 2025
f6d94c9
Added VSCode setings
viktorpopp Nov 18, 2025
81d1da4
Improved testing
viktorpopp Nov 18, 2025
f800e70
Improved testing further
viktorpopp Nov 18, 2025
a6deca8
Why wont QEMU exit :sob:
viktorpopp Nov 18, 2025
19c520a
Finished minimal testing framework
viktorpopp Nov 18, 2025
78f5f27
Removed reduntant test macro
viktorpopp Nov 18, 2025
e79b494
Added assertion macros
viktorpopp Nov 19, 2025
caa0ae2
Added CI workflow
viktorpopp Nov 19, 2025
07aa621
Little fix
viktorpopp Nov 19, 2025
c87f1b8
Added "Generate Configuration" step
viktorpopp Nov 19, 2025
d2d32d9
Added more deps
viktorpopp Nov 19, 2025
1645400
Made the `test` rule depend on `ovmf`
viktorpopp Nov 19, 2025
e620dae
Improved build system interface
viktorpopp Nov 21, 2025
29b2d42
Improved `defconfig` thingy
viktorpopp Nov 22, 2025
8e2de9d
Fixed CI config gen
viktorpopp Nov 22, 2025
a7ae029
Merge branch 'nightly' into dev
viktorpopp Nov 22, 2025
9e56e2a
A bit of docs :)
viktorpopp Nov 25, 2025
d0da406
A bunch of more docs :smile:
viktorpopp Nov 25, 2025
566ea58
Added vscode stuff
viktorpopp Nov 25, 2025
b2a2729
Removed some stuff
viktorpopp Nov 27, 2025
7b89757
Removed vscode run target.
viktorpopp Nov 27, 2025
af3ec5d
Finished debugging
viktorpopp Nov 27, 2025
827a1ed
Removed unused include
viktorpopp Nov 28, 2025
c674271
temp commit (I will be installing Linux on my main pc :shipit:)
viktorpopp Dec 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
Add: [-DUNIT_TEST_ENABLED]
27 changes: 27 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Makefile CI

on:
push:
branches: ["nightly", "dev", "beta", "stable"]
pull_request:
branches: ["nightly", "dev", "beta", "stable"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: "recursive"

- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang nasm make xorriso git curl qemu-system-x86

- name: Generate Configuration
run: make defconfig

- name: Test Kernel
run: make test
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/kernel/bin/kernel",
"cwd": "${workspaceFolder}",

"MIMode": "gdb",
"setupCommands": [
{
"description": "Load Kernel ELF Symbols",
"text": "symbol-file ${workspaceFolder}/kernel/bin/kernel",
"ignoreFailures": false
},
{
"description": "Use Intel syntax",
"text": "set disassembly-flavor intel",
"ignoreFailures": false
},
{
"description": "Use hexadecimal values",
"text": "set output-radix 16",
"ignoreFailures": false
},
{
"description": "Remote QEMU target",
"text": "target remote localhost:1234",
"ignoreFailures": false
}
]
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Kernel",
"type": "shell",
"command": "make",
"args": ["all"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
8 changes: 8 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
mainmenu "Zeronix Kernel"

menu "Debugging"

config PAGING_DEBUG
bool "Enable Paging Debugging"
default n

endmenu # Debugging
34 changes: 31 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include tools/utils.mk

$(call USER_VARIABLE, KARCH, x86_64)
$(call USER_VARIABLE, QEMUFLAGS, -m 128M -M smm=off -serial stdio -d int -D qemu.log -no-reboot -no-shutdown)
$(call USER_VARIABLE, TEST_QEMUFLAGS, -m 128M -M smm=off -d int -D qemu.log -no-reboot)

override OUTPUT := zeronix.iso

Expand All @@ -17,7 +18,7 @@ override XORRISO_FLAGS += \
all: disk

kernel:
$(MAKE) -C kernel
$(MAKE) -C kernel $(KERNEL_TARGET)

bootloader:
$(MAKE) -C limine
Expand Down Expand Up @@ -45,6 +46,32 @@ run: ovmf disk
-cdrom $(OUTPUT) \
$(QEMUFLAGS)

test: KERNEL_TARGET=test
test: ovmf disk
qemu-system-$(KARCH) \
-M q35 \
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-$(KARCH).fd,readonly=on \
-drive if=pflash,unit=1,format=raw,file=ovmf/ovmf-vars-$(KARCH).fd \
-cdrom $(OUTPUT) \
-nographic \
$(TEST_QEMUFLAGS) \
-device isa-debug-exit,iobase=0xf4,iosize=0x04 \
|| [ $$? -eq 33 ]

debug: KERNEL_TARGET=debug
debug: ovmf disk
qemu-system-$(KARCH) \
-M q35 \
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-$(KARCH).fd,readonly=on \
-drive if=pflash,unit=1,format=raw,file=ovmf/ovmf-vars-$(KARCH).fd \
-cdrom $(OUTPUT) \
$(QEMUFLAGS) \
-s -S

defconfig:
cp ./kernel/cfgs/$(KARCH)/default_config .config
./tools/kconfig.sh

menuconfig:
kconfig-mconf Kconfig
./tools/kconfig.sh
Expand All @@ -59,12 +86,13 @@ clean:
rm -rf $(OUTPUT) qemu.log

distclean: clean
rm -rf limine/ compile_commands.json ovmf/
$(MAKE) -C kernel distclean
rm -rf limine/ compile_commands.json ovmf/ .config

ovmf/ovmf-code-$(KARCH).fd:
mkdir -p ovmf
curl -Lo $@ https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-code-$(KARCH).fd

ovmf/ovmf-vars-$(KARCH).fd:
mkdir -p ovmf
curl -Lo $@ https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-vars-$(KARCH).fd
curl -Lo $@ https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-vars-$(KARCH).fd
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ cd zeronix
git submodule update --init
```

### Generating a Configuration

```sh
make defconfig
```

### Building the ISO

```sh
Expand Down
17 changes: 15 additions & 2 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ override KCFLAGS += \
-mno-sse2 \
-fno-omit-frame-pointer \
-mno-red-zone \
-O3 \
-mcmodel=kernel

ifneq ($(filter debug,$(MAKECMDGOALS)),)
override KCFLAGS += -O0
else
override KCFLAGS += -O3
endif

override KCPPFLAGS += \
-I src \
-I libs/flanterm/src \
Expand Down Expand Up @@ -62,6 +67,11 @@ override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))

all: bin/$(OUTPUT)

test: override KCPPFLAGS += -DUNIT_TEST_ENABLED
test: clean bin/$(OUTPUT)

debug: all

bin/$(OUTPUT): linker.lds $(OBJ)
mkdir -p "$$(dirname $@)"
$(KLD) $(OBJ) $(KLDFLAGS) -o $@
Expand All @@ -82,4 +92,7 @@ obj/%.asm.o: src/%.asm
nasm $(KNASMFLAGS) $< -o $@

clean:
rm -rf bin/ obj/
rm -rf bin/ obj/

distclean:
rm -rf libs/ src/gen/autoconf.h
1 change: 1 addition & 0 deletions kernel/cfgs/x86_64/default_config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# CONFIG_PAGING_DEBUG is not set
17 changes: 17 additions & 0 deletions kernel/linker.lds
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,30 @@ PHDRS
SECTIONS
{
. = 0xffffffff80000000;
__kernel_start = .;

.limine_requests : {
__limine_requests_start = .;
KEEP(*(.limine_requests_start))
KEEP(*(.limine_requests))
KEEP(*(.limine_requests_end))
__limine_requests_end = .;
} :limine_requests

. = ALIGN(CONSTANT(MAXPAGESIZE));

.text : {
__kernel_text_start = .;
*(.text .text.*)
__kernel_text_end = .;
} :text

. = ALIGN(CONSTANT(MAXPAGESIZE));

.rodata : {
__kernel_rodata_start = .;
*(.rodata .rodata.*)
__kernel_rodata_end = .;
} :rodata

.note.gnu.build-id : {
Expand All @@ -38,16 +45,26 @@ SECTIONS
. = ALIGN(CONSTANT(MAXPAGESIZE));

.data : {
__kernel_data_start = .;
*(.data .data.*)
__kernel_data_end = .;
} :data

.bss : {
*(.bss .bss.*)
*(COMMON)
} :data

.testcases : {
__start_testcases = .;
KEEP(*(.testcases))
__end_testcases = .;
}

/DISCARD/ : {
*(.eh_frame*)
*(.note .note.*)
}

__kernel_end = .;
}
3 changes: 3 additions & 0 deletions kernel/src/arch/amd64/exceptions/exceptions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

/**
* @brief Registers the exception handlers.
*/
void amd64_exceptions_init();

void amd64_paging_fault_handler(void *context);
3 changes: 3 additions & 0 deletions kernel/src/arch/amd64/gdt/gdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
#define GDT_CODE_SEGMENT 0x8
#define GDT_DATA_SEGMENT 0x10

/**
* @brief Loads the Global Descriptor Table.
*/
void amd64_gdt_init();
28 changes: 28 additions & 0 deletions kernel/src/arch/amd64/idt/idt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,36 @@

#define IDT_MAX_DESCRIPTORS 256

/**
* @brief Loads the Interrupt Descriptor Table.
*
* Sets all vectors to point to their corresponding entry in the ISR stub table and loads the IDT.
*/
void amd64_idt_init();

/**
* @brief Sets an entry in the IDT.
*
* @param index The index of the entry.
* @param base The base pointer of the function.
* @param selector The selector thats used.
* @param flags Raw IDT entry flags.
*
* @note Do not call this directly for registering handlers. Instead use
* `amd64_isr_register_handler`.
*/
void amd64_idt_set_gate(uint8_t index, void *base, uint16_t selector, uint8_t flags);

/**
* @brief Enables an interrupt gate.
*
* @param interrupt The index of the entry to enable.
*/
void amd64_idt_gate_enable(int interrupt);

/**
* @brief Disables an interrupt gate.
*
* @param interrupt The index of the entry to disable.
*/
void amd64_idt_gate_disable(int interrupt);
16 changes: 16 additions & 0 deletions kernel/src/arch/amd64/isr/isr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

extern void *amd64_isr_stub_table[];

/**
* @brief Interrupt Stack Frame.
*/
typedef struct
{
// Pushed by `isr_commom`
Expand Down Expand Up @@ -35,7 +38,20 @@ typedef struct

} __attribute__((packed)) amd64_interrupt_frame_t;

/**
* @brief Interrupt Service Routine Handler Function
*/
typedef void (*amd64_isr_handler_fn)(void *ctx);

/**
* @brief Enables all IDT gates/entries.
*/
void amd64_isr_init();

/**
* @brief Registers an ISR Handler
*
* @param interrupt The IDT/ISR index to register.
* @param handler The function that gets registered.
*/
void amd64_isr_register_handler(int interrupt, amd64_isr_handler_fn handler);
9 changes: 9 additions & 0 deletions kernel/src/arch/amd64/paging/paging.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
global get_pml4
get_pml4:
mov rax, cr3
ret

global load_pml4
load_pml4:
mov cr3, rdi
ret
Loading
Loading