]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
refactor: move gdt.h/idt.h out of generic include/ into arch-specific paths
authorTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 04:27:48 +0000 (01:27 -0300)
committerTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 04:27:48 +0000 (01:27 -0300)
gdt.h and idt.h are x86-only concepts (Global Descriptor Table,
Interrupt Descriptor Table) that do not exist on ARM/RISC-V/MIPS.
They should not live in the generic include/ directory.

Changes:
- Delete include/gdt.h wrapper; all 3 consumers (arch/x86/ and
  hal/x86/) now include arch/x86/gdt.h directly.
- Delete include/idt.h wrapper; create include/interrupts.h as
  the generic abstraction (provides struct registers + isr_handler_t
  with arch-specific dispatch).
- Generic kernel code (syscall.c, uaccess.c, process.h) now
  includes interrupts.h instead of idt.h.
- x86-only code (idt.c, timer HAL, keyboard HAL, usermode, etc.)
  now includes arch/x86/idt.h directly.
- Remove unused idt.h and io.h includes from kernel/main.c.

Passes: make, cppcheck, QEMU smoke test.

15 files changed:
include/arch/x86/usermode.h
include/gdt.h [deleted file]
include/idt.h [deleted file]
include/interrupts.h [new file with mode: 0644]
include/process.h
src/arch/x86/arch_early_setup.c
src/arch/x86/gdt.c
src/arch/x86/idt.c
src/arch/x86/usermode.c
src/hal/x86/cpu.c
src/hal/x86/keyboard.c
src/hal/x86/timer.c
src/kernel/main.c
src/kernel/syscall.c
src/kernel/uaccess.c

index 0f1b015bdbc949b1ff01f20c184581266ab70690..df82642600859833c47fba1f91472bb48630465e 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <stdint.h>
 
-#include "idt.h"
+#include "arch/x86/idt.h"
 
 #if defined(__i386__)
 __attribute__((noreturn)) void x86_enter_usermode(uintptr_t user_eip, uintptr_t user_esp);
diff --git a/include/gdt.h b/include/gdt.h
deleted file mode 100644 (file)
index b2b7537..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef GDT_H
-#define GDT_H
-
-#if defined(__i386__) || defined(__x86_64__)
-#include "arch/x86/gdt.h"
-#else
-
-#include <stdint.h>
-#include <stddef.h>
-
-static inline void gdt_init(void) { }
-static inline void tss_set_kernel_stack(uintptr_t esp0) { (void)esp0; }
-
-#endif
-
-#endif
diff --git a/include/idt.h b/include/idt.h
deleted file mode 100644 (file)
index 2897e40..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef IDT_H
-#define IDT_H
-
-#include <stdint.h>
-
-#if defined(__i386__) || defined(__x86_64__)
-#include "arch/x86/idt.h"
-#else
-
-/* Non-x86: provide a minimal compatibility surface.
-   Interrupt controller specifics live in arch code. */
-struct registers {
-    uint32_t int_no;
-    uint32_t err_code;
-};
-
-typedef void (*isr_handler_t)(struct registers*);
-
-static inline void idt_init(void) { }
-static inline void register_interrupt_handler(uint8_t n, isr_handler_t handler) {
-    (void)n;
-    (void)handler;
-}
-
-#endif
-
-#endif
diff --git a/include/interrupts.h b/include/interrupts.h
new file mode 100644 (file)
index 0000000..c3f0b1c
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef INTERRUPTS_H
+#define INTERRUPTS_H
+
+#include <stdint.h>
+
+#if defined(__i386__) || defined(__x86_64__)
+#include "arch/x86/idt.h"
+#else
+
+/* Non-x86: provide a minimal compatibility surface.
+   Interrupt controller specifics live in arch code. */
+struct registers {
+    uint32_t int_no;
+    uint32_t err_code;
+};
+
+typedef void (*isr_handler_t)(struct registers*);
+
+static inline void idt_init(void) { }
+static inline void register_interrupt_handler(uint8_t n, isr_handler_t handler) {
+    (void)n;
+    (void)handler;
+}
+
+#endif
+
+#endif /* INTERRUPTS_H */
index ba51960e54de842757e7dd0df2e3543ae87abb75..324dad2c0bd355512c5de4a7369b0a759b4e95b2 100644 (file)
@@ -2,7 +2,7 @@
 #define PROCESS_H
 
 #include <stdint.h>
-#include "idt.h" // For struct registers
+#include "interrupts.h" // For struct registers
 #include "fs.h"
 #include "signal.h"
 
index 5760bbd1479bc431cb76d3ef2efd55d46677be36..346b981aa186aee681257583ae83872987417582 100644 (file)
@@ -2,8 +2,8 @@
 
 #include "kernel/boot_info.h"
 
-#include "gdt.h"
-#include "idt.h"
+#include "arch/x86/gdt.h"
+#include "arch/x86/idt.h"
 #include "uart_console.h"
 
 #include "multiboot2.h"
index a4fe0f4f5c42324efce259d5ae948e082e4b4a17..2712d7517f9740d68a0234f01669bafe88218579 100644 (file)
@@ -1,4 +1,4 @@
-#include "gdt.h"
+#include "arch/x86/gdt.h"
 
 #include "uart_console.h"
  #include "utils.h"
index 4e39b4ba75ee92a345dca19f0e91bdfeda49331f..2ef9b86e4db0fd0f863bad40c53ee2d8d8c7433b 100644 (file)
@@ -1,4 +1,4 @@
-#include "idt.h"
+#include "arch/x86/idt.h"
 #include "io.h"
 #include "uart_console.h"
 #include "process.h"
index d80e18e5756d67f5944bfbd0f6474f9ca9201ed8..3f3e36fd07a0b0ade45600e59206f62944f7d45e 100644 (file)
@@ -6,7 +6,7 @@
 #include "uart_console.h"
 #include "utils.h"
  #include "arch/x86/usermode.h"
-#include "idt.h"
+#include "arch/x86/idt.h"
 
 #if defined(__i386__)
 
index 1ebd6ef2eed164f25ff43e876498b3db52868eb9..36252d8c4f22724e89bef7feb62481c7d7b8f16c 100644 (file)
@@ -1,6 +1,6 @@
 #include "hal/cpu.h"
 
-#include "gdt.h"
+#include "arch/x86/gdt.h"
 
 #if defined(__i386__) || defined(__x86_64__)
 
index aefa2ce5eba1bc83aa0051a06ef04377e38d7268..9f39e2e24251044a5688e4db3718463aab5cff80 100644 (file)
@@ -1,7 +1,7 @@
 #include "hal/keyboard.h"
 
 #if defined(__i386__)
-#include "idt.h"
+#include "arch/x86/idt.h"
 #include "io.h"
 
 static hal_keyboard_char_cb_t g_cb = 0;
index 710abb9cbf76b334c62e2f9a9a6cdf79dd8b12c4..4825fb072617785ed49d533bb5a3ed8badc7dc5f 100644 (file)
@@ -1,7 +1,7 @@
 #include "hal/timer.h"
 
 #if defined(__i386__)
-#include "idt.h"
+#include "arch/x86/idt.h"
 #include "io.h"
 
 static hal_timer_tick_cb_t g_tick_cb = 0;
index a89b5606365d513ef893bd72997a507e7511e7fd..cdbf1055b579845a66586d38ed18ec318588f70c 100644 (file)
@@ -5,8 +5,6 @@
 #include "uart_console.h"
 #include "pmm.h"
 #include "vmm.h"
-#include "idt.h"
-#include "io.h"
 #include "process.h"
 #include "keyboard.h"
 #include "shell.h"
index 75cd5092bdbe12fee6d5fa103d65c3be249c1483..447f6f0f27294ccd966f4f1d1bc764a79d2cfc8f 100644 (file)
@@ -1,5 +1,5 @@
 #include "syscall.h"
-#include "idt.h"
+#include "interrupts.h"
 #include "fs.h"
 #include "process.h"
 #include "spinlock.h"
index 9ec48dba5b5d6b7bbd919a8a3aced5d5b81791f7..b47e57ddd603aa11fb545294caebe8dea7698010 100644 (file)
@@ -1,7 +1,7 @@
 #include "uaccess.h"
 
 #include "errno.h"
-#include "idt.h"
+#include "interrupts.h"
 
 #include <stdint.h>