--- /dev/null
+#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
+++ /dev/null
-#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
/* 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 */
#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"
#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"
#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"
#include "uaccess.h"
#include "console.h"
#include "utils.h"
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
#include <stddef.h>
#include "vmm.h"
#include "interrupts.h"
#include "hal/driver.h"
+#include "io.h"
#include <stddef.h>
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 */
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 */
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;
}
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,
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;
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);
#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"
#include "hal/mm.h"
#include "vmm.h"
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
#include <stddef.h>
#include "vdso.h"
-#include "kernel_va_map.h"
+#include "arch/x86/kernel_va_map.h"
#include "pmm.h"
#include "vmm.h"
#include "utils.h"