]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
refactor: move kernel_va_map.h to include/arch/x86/, clean virtio_blk.c port I/O
authorTulio A M Mendes <[email protected]>
Sun, 15 Feb 2026 04:38:44 +0000 (01:38 -0300)
committerTulio A M Mendes <[email protected]>
Sun, 15 Feb 2026 04:38:44 +0000 (01:38 -0300)
- kernel_va_map.h: moved from include/ to include/arch/x86/ since it
  contains x86-specific VA layout (IOAPIC, LAPIC, ATA DMA, E1000)
- Updated all 8 include sites to use new path
- virtio_blk.c: removed duplicated port I/O inline asm, now uses
  io.h → arch/x86/io.h (outb/inb/outw/inw/outl/inl)
- Renamed outb_port/inb_port to standard outb/inb

Deep search results — agnostic areas verified clean:
- src/kernel/: no arch-specific code
- src/mm/: no arch-specific code
- src/drivers/: no arch-specific code (after virtio_blk fix)
- src/net/: no arch-specific code
- include/ (excl arch/): only dispatcher-pattern #includes remain
  (io.h, interrupts.h, arch_types.h, arch_syscall.h, spinlock.h)

include/arch/x86/kernel_va_map.h [new file with mode: 0644]
include/kernel_va_map.h [deleted file]
src/arch/x86/acpi.c
src/arch/x86/ioapic.c
src/arch/x86/lapic.c
src/drivers/e1000.c
src/drivers/vbe.c
src/drivers/virtio_blk.c
src/hal/x86/ata_dma.c
src/hal/x86/mm.c
src/kernel/vdso.c

diff --git a/include/arch/x86/kernel_va_map.h b/include/arch/x86/kernel_va_map.h
new file mode 100644 (file)
index 0000000..b5c3505
--- /dev/null
@@ -0,0 +1,64 @@
+#ifndef KERNEL_VA_MAP_H
+#define KERNEL_VA_MAP_H
+
+/*
+ * Centralized kernel virtual address map for MMIO / DMA / special regions.
+ *
+ * All fixed-VA allocations MUST be listed here to prevent collisions.
+ * The kernel image is loaded at KERNEL_VIRT_BASE (0xC0000000) and BSS
+ * can extend past 0xC0200000 with large static pools (lwIP, FAT, etc.).
+ *
+ * Layout (sorted by VA):
+ *
+ *   0xC0000000 .. ~0xC0203000  Kernel .text/.data/.bss (variable)
+ *   0xC0201000                 IOAPIC MMIO (1 page)
+ *   0xC0280000                 vDSO shared page (1 page)
+ *   0xC0300000 .. 0xC030FFFF   ACPI temp window (16 pages)
+ *   0xC0320000                 ATA DMA PRDT (1 page)
+ *   0xC0321000                 ATA DMA bounce buffer (1 page)
+ *   0xC0330000 .. 0xC034FFFF   E1000 MMIO (32 pages, 128 KB)
+ *   0xC0350000                 E1000 TX descriptor ring (1 page)
+ *   0xC0351000                 E1000 RX descriptor ring (1 page)
+ *   0xC0352000 .. 0xC0361FFF   E1000 TX buffers (16 pages)
+ *   0xC0362000 .. 0xC0371FFF   E1000 RX buffers (16 pages)
+ *   0xC0400000                 LAPIC MMIO (1 page)
+ *   0xC8000000 ..              Kernel stacks (guard + 8KB per thread)
+ *   0xD0000000 ..              Kernel heap (10 MB)
+ *   0xDC000000 ..              Initrd / generic phys mapping (up to 64 MB)
+ *   0xE0000000 ..              Framebuffer mapping (up to 16 MB)
+ */
+
+/* IOAPIC (arch/x86/ioapic.c) */
+#define KVA_IOAPIC          0xC0201000U
+
+/* vDSO shared page (kernel/vdso.c) */
+#define KVA_VDSO            0xC0280000U
+
+/* ACPI temp mapping window — 16 pages (arch/x86/acpi.c) */
+#define KVA_ACPI_TMP_BASE   0xC0300000U
+#define KVA_ACPI_TMP_PAGES  16
+
+/* ATA DMA (hal/x86/ata_dma.c) — two pages per channel (PRDT + bounce buf) */
+#define KVA_ATA_DMA_PRDT_PRI  0xC0320000U
+#define KVA_ATA_DMA_BUF_PRI   0xC0321000U
+#define KVA_ATA_DMA_PRDT_SEC  0xC0322000U
+#define KVA_ATA_DMA_BUF_SEC   0xC0323000U
+
+/* E1000 NIC (drivers/e1000.c) */
+#define KVA_E1000_MMIO      0xC0330000U
+#define KVA_E1000_MMIO_PAGES 32
+#define KVA_E1000_TX_DESC   0xC0350000U
+#define KVA_E1000_RX_DESC   0xC0351000U
+#define KVA_E1000_TX_BUF    0xC0352000U
+#define KVA_E1000_RX_BUF    0xC0362000U
+
+/* LAPIC (arch/x86/lapic.c) */
+#define KVA_LAPIC           0xC0400000U
+
+/* Initrd / generic physical range mapping (hal/x86/mm.c) */
+#define KVA_PHYS_MAP        0xDC000000U
+
+/* Framebuffer (drivers/vbe.c) — up to 16 MB for large resolutions */
+#define KVA_FRAMEBUFFER     0xE0000000U
+
+#endif
diff --git a/include/kernel_va_map.h b/include/kernel_va_map.h
deleted file mode 100644 (file)
index b5c3505..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef KERNEL_VA_MAP_H
-#define KERNEL_VA_MAP_H
-
-/*
- * Centralized kernel virtual address map for MMIO / DMA / special regions.
- *
- * All fixed-VA allocations MUST be listed here to prevent collisions.
- * The kernel image is loaded at KERNEL_VIRT_BASE (0xC0000000) and BSS
- * can extend past 0xC0200000 with large static pools (lwIP, FAT, etc.).
- *
- * Layout (sorted by VA):
- *
- *   0xC0000000 .. ~0xC0203000  Kernel .text/.data/.bss (variable)
- *   0xC0201000                 IOAPIC MMIO (1 page)
- *   0xC0280000                 vDSO shared page (1 page)
- *   0xC0300000 .. 0xC030FFFF   ACPI temp window (16 pages)
- *   0xC0320000                 ATA DMA PRDT (1 page)
- *   0xC0321000                 ATA DMA bounce buffer (1 page)
- *   0xC0330000 .. 0xC034FFFF   E1000 MMIO (32 pages, 128 KB)
- *   0xC0350000                 E1000 TX descriptor ring (1 page)
- *   0xC0351000                 E1000 RX descriptor ring (1 page)
- *   0xC0352000 .. 0xC0361FFF   E1000 TX buffers (16 pages)
- *   0xC0362000 .. 0xC0371FFF   E1000 RX buffers (16 pages)
- *   0xC0400000                 LAPIC MMIO (1 page)
- *   0xC8000000 ..              Kernel stacks (guard + 8KB per thread)
- *   0xD0000000 ..              Kernel heap (10 MB)
- *   0xDC000000 ..              Initrd / generic phys mapping (up to 64 MB)
- *   0xE0000000 ..              Framebuffer mapping (up to 16 MB)
- */
-
-/* IOAPIC (arch/x86/ioapic.c) */
-#define KVA_IOAPIC          0xC0201000U
-
-/* vDSO shared page (kernel/vdso.c) */
-#define KVA_VDSO            0xC0280000U
-
-/* ACPI temp mapping window — 16 pages (arch/x86/acpi.c) */
-#define KVA_ACPI_TMP_BASE   0xC0300000U
-#define KVA_ACPI_TMP_PAGES  16
-
-/* ATA DMA (hal/x86/ata_dma.c) — two pages per channel (PRDT + bounce buf) */
-#define KVA_ATA_DMA_PRDT_PRI  0xC0320000U
-#define KVA_ATA_DMA_BUF_PRI   0xC0321000U
-#define KVA_ATA_DMA_PRDT_SEC  0xC0322000U
-#define KVA_ATA_DMA_BUF_SEC   0xC0323000U
-
-/* E1000 NIC (drivers/e1000.c) */
-#define KVA_E1000_MMIO      0xC0330000U
-#define KVA_E1000_MMIO_PAGES 32
-#define KVA_E1000_TX_DESC   0xC0350000U
-#define KVA_E1000_RX_DESC   0xC0351000U
-#define KVA_E1000_TX_BUF    0xC0352000U
-#define KVA_E1000_RX_BUF    0xC0362000U
-
-/* LAPIC (arch/x86/lapic.c) */
-#define KVA_LAPIC           0xC0400000U
-
-/* Initrd / generic physical range mapping (hal/x86/mm.c) */
-#define KVA_PHYS_MAP        0xDC000000U
-
-/* Framebuffer (drivers/vbe.c) — up to 16 MB for large resolutions */
-#define KVA_FRAMEBUFFER     0xE0000000U
-
-#endif
index eef6da61fe19b2293a15f56f11ab45e54aada043..2762f904b20247361af3c261071abc42a234fade 100644 (file)
@@ -12,7 +12,7 @@ static int g_acpi_valid = 0;
 /* The first 16MB is identity-mapped during early boot (boot.S maps 0-16MB).
  * For addresses < 16MB we can use phys + 0xC0000000.
  * For addresses >= 16MB we must temporarily map them via VMM. */
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
 
 #define KERNEL_VIRT_BASE 0xC0000000U
 #define IDENTITY_LIMIT   0x01000000U  /* 16MB */
index 5f8173bc004d95c9db7a0e964a89c48d3269a000..5db30fbee0e643534987cd49ed39dc38e08179bc 100644 (file)
@@ -1,6 +1,6 @@
 #include "arch/x86/ioapic.h"
 #include "arch/x86/lapic.h"
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
 #include "vmm.h"
 #include "console.h"
 #include "utils.h"
index 2d6a0d8567d404c56e35457cd5cc043745a0ce30..c26e134d082aa7beee8eb41d89183326da1f781d 100644 (file)
@@ -1,5 +1,5 @@
 #include "arch/x86/lapic.h"
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
 #include "hal/cpu_features.h"
 #include "vmm.h"
 #include "io.h"
index 2665771f7e61126b5c481b83cc687d75053daa1a..9e1f65d08c5bdb4f79265aa92da873ccd28d0274 100644 (file)
@@ -1,6 +1,6 @@
 #include "e1000.h"
 #include "hal/driver.h"
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
 #include "pci.h"
 #include "vmm.h"
 #include "pmm.h"
index 55cace12a8ca14d67ba5c6e4293f50b50162122c..adf998540bb457720b65a9be485e978127a92568 100644 (file)
@@ -6,7 +6,7 @@
 #include "uaccess.h"
 #include "console.h"
 #include "utils.h"
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
 
 #include <stddef.h>
 
index fd15c985b65acf0ae3247837c34d3ca78ab1b01b..f96233a21f6f11fb8ed4b76fd3d7088b41366e6e 100644 (file)
@@ -18,6 +18,7 @@
 #include "vmm.h"
 #include "interrupts.h"
 #include "hal/driver.h"
+#include "io.h"
 
 #include <stddef.h>
 
@@ -99,32 +100,6 @@ static uint8_t vblk_status_byte __attribute__((aligned(4)));
 
 static spinlock_t vblk_lock = {0};
 
-/* ---- Port I/O helpers ---- */
-static inline void outl(uint16_t port, uint32_t val) {
-    __asm__ volatile("outl %0, %w1" :: "a"(val), "Nd"(port));
-}
-static inline uint32_t inl(uint16_t port) {
-    uint32_t val;
-    __asm__ volatile("inl %w1, %0" : "=a"(val) : "Nd"(port));
-    return val;
-}
-static inline void outw(uint16_t port, uint16_t val) {
-    __asm__ volatile("outw %0, %w1" :: "a"(val), "Nd"(port));
-}
-static inline uint16_t inw(uint16_t port) {
-    uint16_t val;
-    __asm__ volatile("inw %w1, %0" : "=a"(val) : "Nd"(port));
-    return val;
-}
-static inline void outb_port(uint16_t port, uint8_t val) {
-    __asm__ volatile("outb %0, %w1" :: "a"(val), "Nd"(port));
-}
-static inline uint8_t inb_port(uint16_t port) {
-    uint8_t val;
-    __asm__ volatile("inb %w1, %0" : "=a"(val) : "Nd"(port));
-    return val;
-}
-
 /* ---- Vring size calculation (legacy) ---- */
 static uint32_t vring_size(uint32_t num) {
     /* desc table + avail ring (aligned to page) + used ring */
@@ -156,11 +131,11 @@ int virtio_blk_init(void) {
     pci_config_write(dev->bus, dev->slot, dev->func, 0x04, cmd);
 
     /* Reset device */
-    outb_port(vblk_iobase + VIRTIO_PCI_STATUS, 0);
+    outb(vblk_iobase + VIRTIO_PCI_STATUS, 0);
 
     /* Acknowledge */
-    outb_port(vblk_iobase + VIRTIO_PCI_STATUS, VIRTIO_STATUS_ACK);
-    outb_port(vblk_iobase + VIRTIO_PCI_STATUS,
+    outb(vblk_iobase + VIRTIO_PCI_STATUS, VIRTIO_STATUS_ACK);
+    outb(vblk_iobase + VIRTIO_PCI_STATUS,
               VIRTIO_STATUS_ACK | VIRTIO_STATUS_DRIVER);
 
     /* Read host features, accept none for simplicity */
@@ -177,7 +152,7 @@ int virtio_blk_init(void) {
     vblk_queue_size = inw(vblk_iobase + VIRTIO_PCI_QUEUE_SIZE);
     if (vblk_queue_size == 0) {
         kprintf("[VIRTIO-BLK] Queue size is 0.\n");
-        outb_port(vblk_iobase + VIRTIO_PCI_STATUS, VIRTIO_STATUS_FAILED);
+        outb(vblk_iobase + VIRTIO_PCI_STATUS, VIRTIO_STATUS_FAILED);
         return -1;
     }
 
@@ -191,7 +166,7 @@ int virtio_blk_init(void) {
         void* frame = pmm_alloc_page();
         if (!frame) {
             kprintf("[VIRTIO-BLK] Failed to alloc vring page.\n");
-            outb_port(vblk_iobase + VIRTIO_PCI_STATUS, VIRTIO_STATUS_FAILED);
+            outb(vblk_iobase + VIRTIO_PCI_STATUS, VIRTIO_STATUS_FAILED);
             return -1;
         }
         vmm_map_page((uint64_t)(uintptr_t)frame,
@@ -214,7 +189,7 @@ int virtio_blk_init(void) {
     outl(vblk_iobase + VIRTIO_PCI_QUEUE_PFN, vring_phys / 4096U);
 
     /* Mark driver ready */
-    outb_port(vblk_iobase + VIRTIO_PCI_STATUS,
+    outb(vblk_iobase + VIRTIO_PCI_STATUS,
               VIRTIO_STATUS_ACK | VIRTIO_STATUS_DRIVER | VIRTIO_STATUS_DRIVER_OK);
 
     vblk_ready = 1;
@@ -284,7 +259,7 @@ static int vblk_do_request(uint32_t type, uint64_t sector,
     vblk_last_used_idx++;
 
     /* Read ISR to clear interrupt */
-    (void)inb_port(vblk_iobase + VIRTIO_PCI_ISR);
+    (void)inb(vblk_iobase + VIRTIO_PCI_ISR);
 
     int ret = (vblk_status_byte == 0) ? 0 : -1;
     spin_unlock_irqrestore(&vblk_lock, fl);
index e69048b2ce3567858071f465cdcf01dd7ad097ae..8989af7c44199ef149bcff4c96bbeb6515819b66 100644 (file)
@@ -1,5 +1,5 @@
 #include "ata_dma.h"
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
 #include "pci.h"
 #include "io.h"
 #include "pmm.h"
index c927adc605d1334d1b776c0a8ec893da00a2813a..a8532993de458a49c14001f56204838371b37d08 100644 (file)
@@ -1,7 +1,7 @@
 #include "hal/mm.h"
 
 #include "vmm.h"
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
 
 #include <stddef.h>
 
index ed09350beae5f425f0f4ad8ff648edb52db49559..c4cde81b574697fa42f82b9c98ea3d2343f079f5 100644 (file)
@@ -1,5 +1,5 @@
 #include "vdso.h"
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
 #include "pmm.h"
 #include "vmm.h"
 #include "utils.h"