]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
include: move x86-specific headers under include/arch/x86 and add shims
authorTulio A M Mendes <[email protected]>
Thu, 5 Feb 2026 20:47:39 +0000 (17:47 -0300)
committerTulio A M Mendes <[email protected]>
Thu, 5 Feb 2026 20:47:39 +0000 (17:47 -0300)
include/arch/x86/idt.h [new file with mode: 0644]
include/arch/x86/io.h [new file with mode: 0644]
include/arch/x86/multiboot2.h [new file with mode: 0644]
include/idt.h
include/io.h
include/multiboot2.h

diff --git a/include/arch/x86/idt.h b/include/arch/x86/idt.h
new file mode 100644 (file)
index 0000000..3319dee
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef ARCH_X86_IDT_H
+#define ARCH_X86_IDT_H
+
+#include <stdint.h>
+
+/* IDT Entry (Gate Descriptor) */
+struct idt_entry {
+    uint16_t base_lo;   // Lower 16 bits of handler address
+    uint16_t sel;       // Kernel segment selector
+    uint8_t  always0;   // This must always be zero
+    uint8_t  flags;     // Type and attributes
+    uint16_t base_hi;   // Upper 16 bits of handler address
+} __attribute__((packed));
+
+/* IDT Pointer (Loaded into IDTR) */
+struct idt_ptr {
+    uint16_t limit;
+    uint32_t base;
+} __attribute__((packed));
+
+/* Registers saved by our assembly ISR stub */
+struct registers {
+    uint32_t ds;                                     // Data segment selector
+    uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha
+    uint32_t int_no, err_code;                       // Interrupt number and error code
+    uint32_t eip, cs, eflags, useresp, ss;           // Pushed by the processor automatically
+};
+
+// Initialize IDT and PIC
+void idt_init(void);
+
+// Register a custom handler for a specific interrupt
+typedef void (*isr_handler_t)(struct registers*);
+void register_interrupt_handler(uint8_t n, isr_handler_t handler);
+
+#endif
diff --git a/include/arch/x86/io.h b/include/arch/x86/io.h
new file mode 100644 (file)
index 0000000..2e89507
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef ARCH_X86_IO_H
+#define ARCH_X86_IO_H
+
+#include <stdint.h>
+
+static inline void outb(uint16_t port, uint8_t val) {
+    __asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port));
+}
+
+static inline void outw(uint16_t port, uint16_t val) {
+    __asm__ volatile ("outw %0, %1" : : "a"(val), "Nd"(port));
+}
+
+static inline void outl(uint16_t port, uint32_t val) {
+    __asm__ volatile ("outl %0, %1" : : "a"(val), "Nd"(port));
+}
+
+static inline uint8_t inb(uint16_t port) {
+    uint8_t ret;
+    __asm__ volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
+    return ret;
+}
+
+static inline uint16_t inw(uint16_t port) {
+    uint16_t ret;
+    __asm__ volatile ("inw %1, %0" : "=a"(ret) : "Nd"(port));
+    return ret;
+}
+
+static inline uint32_t inl(uint16_t port) {
+    uint32_t ret;
+    __asm__ volatile ("inl %1, %0" : "=a"(ret) : "Nd"(port));
+    return ret;
+}
+
+#endif
diff --git a/include/arch/x86/multiboot2.h b/include/arch/x86/multiboot2.h
new file mode 100644 (file)
index 0000000..c412097
--- /dev/null
@@ -0,0 +1,80 @@
+#ifndef ARCH_X86_MULTIBOOT2_H
+#define ARCH_X86_MULTIBOOT2_H
+
+#include <stdint.h>
+
+/*  How many bytes from the start of the file we search for the header. */
+#define MULTIBOOT_SEARCH                        32768
+#define MULTIBOOT_HEADER_ALIGN                  8
+
+/*  The magic field should contain this. */
+#define MULTIBOOT2_HEADER_MAGIC                 0xe85250d6
+
+/*  This should be in %eax. */
+#define MULTIBOOT2_BOOTLOADER_MAGIC             0x36d76289
+
+/*  Alignment of multiboot modules. */
+#define MULTIBOOT_MOD_ALIGN                     0x00001000
+
+/*  Alignment of the multiboot info structure. */
+#define MULTIBOOT_INFO_ALIGN                    0x00000008
+
+/* Tags found in the Multiboot2 information structure */
+#define MULTIBOOT_TAG_TYPE_END                  0
+#define MULTIBOOT_TAG_TYPE_CMDLINE              1
+#define MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME     2
+#define MULTIBOOT_TAG_TYPE_MODULE               3
+#define MULTIBOOT_TAG_TYPE_BASIC_MEMINFO        4
+#define MULTIBOOT_TAG_TYPE_BOOTDEV              5
+#define MULTIBOOT_TAG_TYPE_MMAP                 6
+#define MULTIBOOT_TAG_TYPE_VBE                  7
+#define MULTIBOOT_TAG_TYPE_FRAMEBUFFER          8
+
+struct multiboot_tag {
+    uint32_t type;
+    uint32_t size;
+};
+
+struct multiboot_tag_string {
+    uint32_t type;
+    uint32_t size;
+    char string[0];
+};
+
+struct multiboot_tag_basic_meminfo {
+    uint32_t type;
+    uint32_t size;
+    uint32_t mem_lower;
+    uint32_t mem_upper;
+};
+
+struct multiboot_tag_mmap {
+    uint32_t type;
+    uint32_t size;
+    uint32_t entry_size;
+    uint32_t entry_version;
+    struct multiboot_mmap_entry entries[0];
+};
+
+struct multiboot_tag_module {
+    uint32_t type;
+    uint32_t size;
+    uint32_t mod_start;
+    uint32_t mod_end;
+    char string[0];
+};
+
+struct multiboot_mmap_entry {
+    uint64_t addr;
+    uint64_t len;
+    uint32_t type;
+    uint32_t zero;
+};
+
+#define MULTIBOOT_MEMORY_AVAILABLE              1
+#define MULTIBOOT_MEMORY_RESERVED               2
+#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE       3
+#define MULTIBOOT_MEMORY_NVS                    4
+#define MULTIBOOT_MEMORY_BADRAM                 5
+
+#endif
index 3ae501d8a986d787c9a4ec8b509c9e43646d5525..2897e402013c8fedb5cda79981b7bae60e1de82f 100644 (file)
@@ -3,34 +3,25 @@
 
 #include <stdint.h>
 
-/* IDT Entry (Gate Descriptor) */
-struct idt_entry {
-    uint16_t base_lo;   // Lower 16 bits of handler address
-    uint16_t sel;       // Kernel segment selector
-    uint8_t  always0;   // This must always be zero
-    uint8_t  flags;     // Type and attributes
-    uint16_t base_hi;   // Upper 16 bits of handler address
-} __attribute__((packed));
+#if defined(__i386__) || defined(__x86_64__)
+#include "arch/x86/idt.h"
+#else
 
-/* IDT Pointer (Loaded into IDTR) */
-struct idt_ptr {
-    uint16_t limit;
-    uint32_t base;
-} __attribute__((packed));
-
-/* Registers saved by our assembly ISR stub */
+/* Non-x86: provide a minimal compatibility surface.
+   Interrupt controller specifics live in arch code. */
 struct registers {
-    uint32_t ds;                                     // Data segment selector
-    uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha
-    uint32_t int_no, err_code;                       // Interrupt number and error code
-    uint32_t eip, cs, eflags, useresp, ss;           // Pushed by the processor automatically
+    uint32_t int_no;
+    uint32_t err_code;
 };
 
-// Initialize IDT and PIC
-void idt_init(void);
-
-// Register a custom handler for a specific interrupt
 typedef void (*isr_handler_t)(struct registers*);
-void register_interrupt_handler(uint8_t n, isr_handler_t handler);
+
+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
index f44840ea0e1cf625e31fe0b9767d9cdbe3e228e2..b059bb82aa08aad5703eaa44f8d20866a85df751 100644 (file)
@@ -3,34 +3,19 @@
 
 #include <stdint.h>
 
-/* x86 I/O Port Wrappers */
-#if defined(__i386__) || defined(__x86_64__)
-
-static inline void outb(uint16_t port, uint8_t val) {
-    __asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port));
-}
-
-static inline uint8_t inb(uint16_t port) {
-    uint8_t ret;
-    __asm__ volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
-    return ret;
-}
-
+/* Generic MMIO helpers (ARM/RISC-V/MIPS and also usable on x86) */
 static inline void mmio_write8(uintptr_t addr, uint8_t val) {
     volatile uint8_t* ptr = (uint8_t*)addr;
     *ptr = val;
 }
 
-static inline uint8_t mmio_read8(uintptr_t addr) {
-    volatile uint8_t* ptr = (uint8_t*)addr;
-    return *ptr;
+static inline void mmio_write16(uintptr_t addr, uint16_t val) {
+    volatile uint16_t* ptr = (uint16_t*)addr;
+    *ptr = val;
 }
 
-#else
-
-/* MMIO for ARM/RISC-V */
-static inline void mmio_write8(uintptr_t addr, uint8_t val) {
-    volatile uint8_t* ptr = (uint8_t*)addr;
+static inline void mmio_write32(uintptr_t addr, uint32_t val) {
+    volatile uint32_t* ptr = (uint32_t*)addr;
     *ptr = val;
 }
 
@@ -39,15 +24,19 @@ static inline uint8_t mmio_read8(uintptr_t addr) {
     return *ptr;
 }
 
-/* Fallback for port I/O on architectures that don't have it (mapped to MMIO or no-op) */
-static inline void outb(uint16_t port, uint8_t val) {
-    (void)port; (void)val; // No-op
+static inline uint16_t mmio_read16(uintptr_t addr) {
+    volatile uint16_t* ptr = (uint16_t*)addr;
+    return *ptr;
 }
 
-static inline uint8_t inb(uint16_t port) {
-    (void)port; return 0;
+static inline uint32_t mmio_read32(uintptr_t addr) {
+    volatile uint32_t* ptr = (uint32_t*)addr;
+    return *ptr;
 }
 
+/* x86 port I/O lives under include/arch/x86/io.h */
+#if defined(__i386__) || defined(__x86_64__)
+#include "arch/x86/io.h"
 #endif
 
 #endif
index c28535e1a54376f327dff206b13b65df72fe9247..4162c4048c84d2846bf4b674e353564148728e7e 100644 (file)
@@ -3,78 +3,7 @@
 
 #include <stdint.h>
 
-/*  How many bytes from the start of the file we search for the header. */
-#define MULTIBOOT_SEARCH                        32768
-#define MULTIBOOT_HEADER_ALIGN                  8
-
-/*  The magic field should contain this. */
-#define MULTIBOOT2_HEADER_MAGIC                 0xe85250d6
-
-/*  This should be in %eax. */
-#define MULTIBOOT2_BOOTLOADER_MAGIC             0x36d76289
-
-/*  Alignment of multiboot modules. */
-#define MULTIBOOT_MOD_ALIGN                     0x00001000
-
-/*  Alignment of the multiboot info structure. */
-#define MULTIBOOT_INFO_ALIGN                    0x00000008
-
-/* Tags found in the Multiboot2 information structure */
-#define MULTIBOOT_TAG_TYPE_END                  0
-#define MULTIBOOT_TAG_TYPE_CMDLINE              1
-#define MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME     2
-#define MULTIBOOT_TAG_TYPE_MODULE               3
-#define MULTIBOOT_TAG_TYPE_BASIC_MEMINFO        4
-#define MULTIBOOT_TAG_TYPE_BOOTDEV              5
-#define MULTIBOOT_TAG_TYPE_MMAP                 6
-#define MULTIBOOT_TAG_TYPE_VBE                  7
-#define MULTIBOOT_TAG_TYPE_FRAMEBUFFER          8
-
-struct multiboot_tag {
-    uint32_t type;
-    uint32_t size;
-};
-
-struct multiboot_tag_string {
-    uint32_t type;
-    uint32_t size;
-    char string[0];
-};
-
-struct multiboot_tag_basic_meminfo {
-    uint32_t type;
-    uint32_t size;
-    uint32_t mem_lower;
-    uint32_t mem_upper;
-};
-
-struct multiboot_tag_mmap {
-    uint32_t type;
-    uint32_t size;
-    uint32_t entry_size;
-    uint32_t entry_version;
-    struct multiboot_mmap_entry entries[0];
-};
-
-struct multiboot_tag_module {
-    uint32_t type;
-    uint32_t size;
-    uint32_t mod_start;
-    uint32_t mod_end;
-    char string[0];
-};
-
-struct multiboot_mmap_entry {
-    uint64_t addr;
-    uint64_t len;
-    uint32_t type;
-    uint32_t zero;
-};
-
-#define MULTIBOOT_MEMORY_AVAILABLE              1
-#define MULTIBOOT_MEMORY_RESERVED               2
-#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE       3
-#define MULTIBOOT_MEMORY_NVS                    4
-#define MULTIBOOT_MEMORY_BADRAM                 5
-
+#if defined(__i386__) || defined(__x86_64__)
+#include "arch/x86/multiboot2.h"
+#endif
 #endif /* MULTIBOOT2_H */