]> 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 a168bf0218bbd1816caeb73f630561035c61e2d2..8992a3fb973b74b54299c465f10b6aa69ad48fc6 100644 (file)
@@ -12,7 +12,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 cc6c01f..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-// SPDX-License-Identifier: BSD-3-Clause
-/*
- * Copyright (c) 2018, Tulio A M Mendes <[email protected]>
- * All rights reserved.
- * See LICENSE for details.
- *
- * Source: https://github.com/tadryanom/AdrOS
- */
-
-#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 9466e20..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-// SPDX-License-Identifier: BSD-3-Clause
-/*
- * Copyright (c) 2018, Tulio A M Mendes <[email protected]>
- * All rights reserved.
- * See LICENSE for details.
- *
- * Source: https://github.com/tadryanom/AdrOS
- */
-
-#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..5fea130
--- /dev/null
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2018, Tulio A M Mendes <[email protected]>
+ * All rights reserved.
+ * See LICENSE for details.
+ *
+ * Source: https://github.com/tadryanom/AdrOS
+ */
+
+#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 87f9151f3cdd52f3fd5e53345143403da70c7b55..a09099db7cd9f7efe78be1c93eeb0278716c5ffe 100644 (file)
@@ -11,7 +11,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 f827559cae79ecaf1f28a9f0595b7471025c706a..98cf4406c4c79eb78305b43a6e77406dcbdca25c 100644 (file)
@@ -11,8 +11,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 16bf5a6503f45309e4efd8d7ead50000d84298b8..9bcc5f21fd5339a09d63f1fa75524c678c80e963 100644 (file)
@@ -7,7 +7,7 @@
  * Source: https://github.com/tadryanom/AdrOS
  */
 
-#include "gdt.h"
+#include "arch/x86/gdt.h"
 
 #include "uart_console.h"
  #include "utils.h"
index dc683dbc5417f75b39160714c942032c7b46d131..d60800507fd1c75b6852dc31a3765469d4cfdfbe 100644 (file)
@@ -7,7 +7,7 @@
  * Source: https://github.com/tadryanom/AdrOS
  */
 
-#include "idt.h"
+#include "arch/x86/idt.h"
 #include "io.h"
 #include "uart_console.h"
 #include "process.h"
index 216bb9c3ff37a8f95ec0d943a5541f2ac0028a92..614ec34d40169681bebc429fdfd29efa9a0650cc 100644 (file)
@@ -15,7 +15,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 289a442be2e4c87fdbfa779d1b4d180baf38e1d3..9bda83f71009f1d5a677bec311c12085fdf61961 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "hal/cpu.h"
 
-#include "gdt.h"
+#include "arch/x86/gdt.h"
 
 #if defined(__i386__) || defined(__x86_64__)
 
index dfc689066076c35a1ab01639f1cf2495860a990b..e9415e1a193b724ac819b225ad169bf4eee67987 100644 (file)
@@ -10,7 +10,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 7b47f394cceca726122f0d803928ce3c41008b4e..9ff64d95ac3643cbb18108757f8e5e0d4f65da15 100644 (file)
@@ -10,7 +10,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 813d632d9fb7de69305bb8d66552497eb83160ac..b09a92e41aefa0ef26f54f803b4fd69065b8f503 100644 (file)
@@ -14,8 +14,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 08680b28a6a064b2538bb463900ec3a65b108dd6..fcc5199e95cea9175b4f3edcd19fe4a9f05e5a46 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include "syscall.h"
-#include "idt.h"
+#include "interrupts.h"
 #include "fs.h"
 #include "process.h"
 #include "spinlock.h"
index cfeb3856e6a0e11ac79ec23357c600e66e4d356a..ce7b190222e2ed1a3c82f01ed5b7f13ac8cd5051 100644 (file)
@@ -10,7 +10,7 @@
 #include "uaccess.h"
 
 #include "errno.h"
-#include "idt.h"
+#include "interrupts.h"
 
 #include <stdint.h>