From: Tulio A M Mendes Date: Tue, 10 Feb 2026 04:27:48 +0000 (-0300) Subject: refactor: move gdt.h/idt.h out of generic include/ into arch-specific paths X-Git-Url: https://projects.tadryanom.me/?a=commitdiff_plain;h=3f80c5b1360a9baa32ecbcb4c514fa8c62ca3a8e;p=AdrOS.git refactor: move gdt.h/idt.h out of generic include/ into arch-specific paths 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. --- diff --git a/include/arch/x86/usermode.h b/include/arch/x86/usermode.h index a168bf02..8992a3fb 100644 --- a/include/arch/x86/usermode.h +++ b/include/arch/x86/usermode.h @@ -12,7 +12,7 @@ #include -#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 index cc6c01fa..00000000 --- a/include/gdt.h +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* - * Copyright (c) 2018, Tulio A M Mendes - * 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 -#include - -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 index 9466e200..00000000 --- a/include/idt.h +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* - * Copyright (c) 2018, Tulio A M Mendes - * All rights reserved. - * See LICENSE for details. - * - * Source: https://github.com/tadryanom/AdrOS - */ - -#ifndef IDT_H -#define IDT_H - -#include - -#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 index 00000000..5fea1303 --- /dev/null +++ b/include/interrupts.h @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2018, Tulio A M Mendes + * All rights reserved. + * See LICENSE for details. + * + * Source: https://github.com/tadryanom/AdrOS + */ + +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +#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 */ diff --git a/include/process.h b/include/process.h index 87f9151f..a09099db 100644 --- a/include/process.h +++ b/include/process.h @@ -11,7 +11,7 @@ #define PROCESS_H #include -#include "idt.h" // For struct registers +#include "interrupts.h" // For struct registers #include "fs.h" #include "signal.h" diff --git a/src/arch/x86/arch_early_setup.c b/src/arch/x86/arch_early_setup.c index f827559c..98cf4406 100644 --- a/src/arch/x86/arch_early_setup.c +++ b/src/arch/x86/arch_early_setup.c @@ -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" diff --git a/src/arch/x86/gdt.c b/src/arch/x86/gdt.c index 16bf5a65..9bcc5f21 100644 --- a/src/arch/x86/gdt.c +++ b/src/arch/x86/gdt.c @@ -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" diff --git a/src/arch/x86/idt.c b/src/arch/x86/idt.c index dc683dbc..d6080050 100644 --- a/src/arch/x86/idt.c +++ b/src/arch/x86/idt.c @@ -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" diff --git a/src/arch/x86/usermode.c b/src/arch/x86/usermode.c index 216bb9c3..614ec34d 100644 --- a/src/arch/x86/usermode.c +++ b/src/arch/x86/usermode.c @@ -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__) diff --git a/src/hal/x86/cpu.c b/src/hal/x86/cpu.c index 289a442b..9bda83f7 100644 --- a/src/hal/x86/cpu.c +++ b/src/hal/x86/cpu.c @@ -9,7 +9,7 @@ #include "hal/cpu.h" -#include "gdt.h" +#include "arch/x86/gdt.h" #if defined(__i386__) || defined(__x86_64__) diff --git a/src/hal/x86/keyboard.c b/src/hal/x86/keyboard.c index dfc68906..e9415e1a 100644 --- a/src/hal/x86/keyboard.c +++ b/src/hal/x86/keyboard.c @@ -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; diff --git a/src/hal/x86/timer.c b/src/hal/x86/timer.c index 7b47f394..9ff64d95 100644 --- a/src/hal/x86/timer.c +++ b/src/hal/x86/timer.c @@ -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; diff --git a/src/kernel/main.c b/src/kernel/main.c index 813d632d..b09a92e4 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -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" diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index 08680b28..fcc5199e 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -8,7 +8,7 @@ */ #include "syscall.h" -#include "idt.h" +#include "interrupts.h" #include "fs.h" #include "process.h" #include "spinlock.h" diff --git a/src/kernel/uaccess.c b/src/kernel/uaccess.c index cfeb3856..ce7b1902 100644 --- a/src/kernel/uaccess.c +++ b/src/kernel/uaccess.c @@ -10,7 +10,7 @@ #include "uaccess.h" #include "errno.h" -#include "idt.h" +#include "interrupts.h" #include