]> 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..6477d17
--- /dev/null
@@ -0,0 +1,45 @@
+// 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 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..be42540
--- /dev/null
@@ -0,0 +1,45 @@
+// 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 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..70013af
--- /dev/null
@@ -0,0 +1,89 @@
+// 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 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 16c1e87bf77dc26888b2b8541ed100ed7323de95..9466e20032d5391da8872fa474db31a5234f985e 100644 (file)
 
 #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 */
+#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 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 3665f7a199110c4a0dcf6cdd53664cddf7e74b94..c120a439ca8549163446a8e009ed6aafd2e0911a 100644 (file)
 
 #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;
 }
 
@@ -48,15 +33,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 cd6b00e5e813f2d9fa579d7fb216c68e310bd6a9..c3c2cf58a1dc8138dd3b0776d8f7a5013edcebb9 100644 (file)
 
 #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 */