universalisos/kernel/uos_int.h
Fábio Coutada 9540b0528c feat(universalisos): PikeOS-style Phase B/C device drivers + Phase D microkernel
Phase B (Core Device Support) — all drivers verified in QEMU:
- Network: virtio-net cleanup, RTL8139, E1000, clause-22 MDIO PHY management,
  CAN bus, industrial protocols (Modbus/Profibus/EtherCAT), controller probe+dispatch
- Block storage: RAM disk backend (write->read->verify PASSED), virtio-blk transport,
  backend dispatch, real MBR+GPT partition parsers, SD/eMMC command framework
- GPIO: PL061 (verified), I2C: DesignWare (verified), SPI: PL022 (verified)

Phase C (Advanced Features):
- PCI: FULL PikeOS ARMv7 replica — transport-agnostic uos_pci_ops, config-address
  encoding, BAR sizing, capability walk, enumeration+bridge recursion, MSI/MSI-X
- USB: PikeOS-style layered stack — usb.h contract, usb_core.cpp (enumeration
  state machine), usb_ehci.cpp (EHCI transport)
- Display: FULL 1:1 PikeOS fbcon replica + copied font_8x16

Build foundation fixes:
- Freestanding aeabi_runtime.cpp (__aeabi_uidiv/__aeabi_uldivmod)
- PikeOS-style flat 4GB MMU section map + proper enable (unblocked device MMIO)
- guest.h MAX_GUEST_IMAGE_SIZE 256MB->16MB (BSS was 259MB)
- C/C++ linkage fixes, duplicate-virtio_net_init, MMIO access-size handling

Phase D (PikeOS ARMv7 Microkernel Port):
- D-1: Per-VM address spaces — cloned pgdirs, ASID-tagged TLB, 4K page walker,
  isolation PASSED (two guests, same VA->different PAs), guest fault recovery
- D-2: IRQ dispatch backbone — 1024-slot dispatch table, real GICv2 hardware
  (GICD_CTLR/GICC_CTLR/GICC_PMR/GICC_IAR/GICC_EOIR), arm_irq_handler wired
- D-3: Time subsystem — CNTVCT ns-since-boot, CNTP periodic ticker via D-2
- D-4: KDEV framework — linker-section driver registration, uos_kdev_init_all,
  name lookup
- D-5: VFP/NEON — lazy enable (undef trap->CPACR+FPEXC.EN), FPEXC=0x40000000
- D-6: SMP — per-CPU state, MPIDR, IPI/SGI framework (reschedule+TLB flush)

All uos_ naming (PikeOS p4_ convention adapted). Compiles -Werror freestanding C++17.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-09 09:10:53 +01:00

71 lines
2.2 KiB
C

/*
* Universalisos interrupt dispatch backbone (uos_int.h)
*
* Faithful adaptation of PikeOS src/int.c + kdev_int.c. A per-IRQ dispatch
* table maps interrupt IDs to handler callbacks. The low-level IRQ entry
* (arm_irq_handler in exceptions.cpp) calls uos_int_dispatch(), which reads
* the IRQ from the GIC (acknowledge), looks up the table, calls the handler,
* and EOI's the interrupt.
*
* The hardware primitives (acknowledge/eoi/mask/unmask) come from the existing
* gic.cpp; this layer adds the table + the attach/detach lifecycle.
*
* Author: PortugalFuturista Hypervisor Development Team (adapted from SYSGO PikeOS)
*/
#ifndef UOS_INT_H
#define UOS_INT_H
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
#define UOS_MAX_INTERRUPTS 1024u /* GICv2 supports 1020 + 4 special */
/* Interrupt handler callback (PikeOS P4_inthandler_t equivalent).
* cookie = user-supplied context
* intno = the interrupt ID that fired */
typedef void (*uos_int_handler_t)(void *cookie, uint32_t intno);
/* Per-IRQ info (PikeOS P4k_intinfo_t, simplified) */
typedef struct {
uos_int_handler_t handler;
void *cookie;
uint32_t usecount;
bool attached;
} uos_int_info_t;
/* The global interrupt table (one entry per IRQ). */
extern uos_int_info_t g_uos_int_table[UOS_MAX_INTERRUPTS];
/** Initialise the interrupt dispatch table. Call once at boot. */
void uos_int_module_init(void);
/** Attach a handler to IRQ `intno`. Configures + enables the IRQ at the GIC.
* Returns 0 on success, negative on error. */
int uos_int_attach(uint32_t intno, uos_int_handler_t handler, void *cookie);
/** Detach the handler from IRQ `intno`. Disables the IRQ at the GIC. */
void uos_int_detach(uint32_t intno);
/** Mask (disable) IRQ `intno` at the GIC. */
void uos_int_mask(uint32_t intno);
/** Unmask (enable) IRQ `intno` at the GIC. */
void uos_int_unmask(uint32_t intno);
/** Core dispatch: read IAR, call the registered handler (or spurious), EOI.
* Called by arm_irq_handler in exceptions.cpp. */
void uos_int_dispatch(void);
/** D-2 driver init / demonstration. */
void uos_int_driver_init(void);
void uos_int_driver_demo(void);
#ifdef __cplusplus
}
#endif
#endif /* UOS_INT_H */