Writing an x86 kernel in C: How to start making my IRQ, PIC, IDT handling mechanics?

I'm building a x86 hobby operating system from scratch. The early boot stage successfully transitions from assembly into a pure C entry point inside init/main.c.

I am currently trying to write my interrupt subsystem (irq.c) to handle hardware lines like the keyboard and timer, but right now it's just a placeholder stub. Here is my current layout: irq.c:

#include "irq.h"


/* TODO: implement real IDT/PIC setup */
void idt_init(void) {}
void pic_init(void) {}
void irq_register(int irq, void (*handler)(void)) {
    (void)irq;
    (void)handler;
}

irq.h:

#ifndef NOVIUM_IRQ_H
#define NOVIUM_IRQ_H


#include <novium/types.h>


void idt_init(void);
void pic_init(void);
void irq_register(int irq, void (*handler)(void));


#endif
reddit.com
u/devcurrent0x — 12 hours ago
▲ 3 r/osdev

Novium OS — A from-scratch 32-bit x86 hobby Operating System (Custom bootloader and kernel)

Hey everyone,

I wanted to share a milestone on a hobby operating system I’m building from scratch called Novium OS, featuring a custom bootloader.

I just got my multi-stage boot chain (boot.S -> setup.S -> bootstrap.S) completely stable. It successfully handles raw hardware initialization, sets up a temporary GDT, and handles the cr0 register transition cleanly into 32-bit protected mode before jumping into the kernel entry point. I also wrapped up a basic VGA text driver with hardware cursor syncing so I can verify output, and got "Hello World" printing to the screen.

The layout is inspired by a super stripped-down Linux kernel (arch/, drivers/, kernel/).

Next i have to write irq.c and interrupt.c, and writing the low-level assembly ISR stubs. I need to build the macro wrappers to handle interrupts with and without error codes, save the CPU state with pusha, remap the 8259 PIC master/slave vectors, and execute the final iret. I'm fully braced for plenty of debugging via QEMU logs to catch silent triple faults.

The codebase uses AT&T syntax for the GNU Assembler (gas). If anyone wants to take a look at the boot sequence, folder layout, or offer any early feedback on how I structured the assembly stages, the repository is right here:

https://github.com/alexdev8930/NoviumOS

(Note: Later architecture features like filesystems and IPC currently contain stubs because the core kernel is still being built out. The actual working code files are located in arch/ and drivers/, though a few placeholders are still mixed in there.)

If you like the project, please drop a star on GitHub! It really encourages me to keep extending on my project.

reddit.com
u/devcurrent0x — 15 hours ago
▲ 17 r/Assembly_language+1 crossposts

Novium OS — A from-scratch 32-bit x86 hobby Operating System (Custom assembly bootloader)

Hey everyone,

I wanted to share a milestone on a hobby operating system I’m building from scratch called Novium OS featuring a custom bootloader.

I just got my multi-stage boot chain (boot.S -> setup.S -> bootstrap.S) completely stable. It successfully handles the raw hardware initialization, sets up a temporary GDT, and handles the cr0 register transition cleanly into 32-bit protected mode before jumping into the kernel entry point. I also wrapped up a basic VGA text driver with hardware cursor syncing so I can verify output, and got "Hello World" printing to the screen.

The layout is inspired by a super stripped-down Linux (arch/, drivers/, kernel/).

Next up is tackling irq.c and interrupt.c and writing the low-level assembly ISR stubs. I need to build the macro wrappers to handle interrupts with and without error codes, save the CPU state with pusha, remap the 8259 PIC master/slave vectors, and execute the final iret. I'm fully braced for plenty of debugging via QEMU logs to catch silent triple faults.

The codebase uses AT&T syntax for the GNU Assembler (gas). If anyone wants to take a look at the boot sequence, folder layout, or offer any early feedback on how I structured the assembly stages, the repository is right here:
https://github.com/alexdev8930/NoviumOS

u/devcurrent0x — 1 day ago