├── .gitlab ├── .gitlab-ci.yml └── CODEOWNERS ├── LICENSE ├── Makefile ├── Makefile.conf.example ├── README.md ├── cmd └── digest.cpp ├── doc └── specification.pdf ├── inc ├── aarch64 │ ├── abi.hpp │ ├── acpi_arch.hpp │ ├── acpi_fixed.hpp │ ├── acpi_table_gtdt.hpp │ ├── acpi_table_iort.hpp │ ├── arch.hpp │ ├── barrier.hpp │ ├── board.hpp │ ├── board_acpi.hpp │ ├── board_allwinner_a64.hpp │ ├── board_amlogic_g12b.hpp │ ├── board_amlogic_sm1.hpp │ ├── board_broadcom_bcm2711.hpp │ ├── board_hisilicon_hi3660.hpp │ ├── board_nvidia_tegrax1.hpp │ ├── board_nvidia_tegrax2.hpp │ ├── board_nvidia_xavier.hpp │ ├── board_nxp_imx8m.hpp │ ├── board_qemu.hpp │ ├── board_qualcomm_sdm670.hpp │ ├── board_renesas_rcar3.hpp │ ├── board_rockchip_rk3399.hpp │ ├── board_ti_am62x.hpp │ ├── board_ti_j721e.hpp │ ├── board_xilinx_zynq_cg.hpp │ ├── board_xilinx_zynq_u96.hpp │ ├── board_xilinx_zynq_zcu102.hpp │ ├── cache.hpp │ ├── coherency.hpp │ ├── console_uart_cdns.hpp │ ├── console_uart_imx.hpp │ ├── console_uart_meson.hpp │ ├── console_uart_mini.hpp │ ├── console_uart_ns16550.hpp │ ├── console_uart_pl011.hpp │ ├── console_uart_scif.hpp │ ├── coresight.hpp │ ├── cos.hpp │ ├── counter.hpp │ ├── cpu.hpp │ ├── ec_arch.hpp │ ├── entry.hpp │ ├── event.hpp │ ├── extern.hpp │ ├── fdt.hpp │ ├── fpu.hpp │ ├── gicc.hpp │ ├── gicd.hpp │ ├── gich.hpp │ ├── gicr.hpp │ ├── gits.hpp │ ├── hip_arch.hpp │ ├── integrity.hpp │ ├── interrupt.hpp │ ├── intid.hpp │ ├── lowlevel.hpp │ ├── memattr.hpp │ ├── memory.hpp │ ├── mtd_arch.hpp │ ├── patch_arch.hpp │ ├── psci.hpp │ ├── ptab_dpt.hpp │ ├── ptab_hpt.hpp │ ├── ptab_npt.hpp │ ├── ptab_pte.hpp │ ├── ptab_tmp.hpp │ ├── regs.hpp │ ├── smc.hpp │ ├── smmu.hpp │ ├── smmu_v2.hpp │ ├── smmu_v3.hpp │ ├── space_dma.hpp │ ├── space_gst.hpp │ ├── space_hst.hpp │ ├── space_msr.hpp │ ├── space_pio.hpp │ ├── spinlock.hpp │ ├── syscall_tmp.hpp │ ├── sysreg.hpp │ ├── timer.hpp │ ├── utcb_arch.hpp │ ├── vmcb.hpp │ └── vmid.hpp ├── acpi.hpp ├── acpi_gas.hpp ├── acpi_table.hpp ├── acpi_table_dbg2.hpp ├── acpi_table_facs.hpp ├── acpi_table_fadt.hpp ├── acpi_table_hest.hpp ├── acpi_table_madt.hpp ├── acpi_table_mcfg.hpp ├── acpi_table_rsdp.hpp ├── acpi_table_spcr.hpp ├── acpi_table_srat.hpp ├── acpi_table_tpm2.hpp ├── acpi_table_xsdt.hpp ├── assert.hpp ├── atomic.hpp ├── bitmap.hpp ├── bits.hpp ├── buddy.hpp ├── capability.hpp ├── checksum.hpp ├── cmdline.hpp ├── compiler.hpp ├── console.hpp ├── console_mbuf.hpp ├── console_uart.hpp ├── debug.hpp ├── ec.hpp ├── elf.hpp ├── endian.hpp ├── hash.hpp ├── hazard.hpp ├── hip.hpp ├── initprio.hpp ├── kmem.hpp ├── kobject.hpp ├── list.hpp ├── lock_guard.hpp ├── macros.hpp ├── mmio.hpp ├── mtd.hpp ├── multiboot.hpp ├── paging.hpp ├── patch.hpp ├── pci.hpp ├── pd.hpp ├── pt.hpp ├── ptab.hpp ├── queue.hpp ├── rcu.hpp ├── refcnt.hpp ├── sc.hpp ├── scheduler.hpp ├── sdid.hpp ├── signature.hpp ├── slab.hpp ├── sm.hpp ├── space.hpp ├── space_mem.hpp ├── space_obj.hpp ├── status.hpp ├── stc.hpp ├── std.hpp ├── stdio.hpp ├── string.hpp ├── syscall.hpp ├── timeout.hpp ├── timeout_budget.hpp ├── timeout_hypercall.hpp ├── types.hpp ├── uefi.hpp ├── utcb.hpp ├── util.hpp ├── uuid.hpp ├── wait.hpp └── x86_64 │ ├── abi.hpp │ ├── acm.hpp │ ├── acpi_arch.hpp │ ├── acpi_fixed.hpp │ ├── acpi_table_dmar.hpp │ ├── acpi_table_hpet.hpp │ ├── acpi_table_lpit.hpp │ ├── arch.hpp │ ├── barrier.hpp │ ├── bitmap_msr.hpp │ ├── bitmap_pio.hpp │ ├── cache.hpp │ ├── cache_guard.hpp │ ├── cet.hpp │ ├── config.hpp │ ├── console_uart_apb.hpp │ ├── console_uart_hsu.hpp │ ├── console_uart_ns16550.hpp │ ├── console_uart_sio.hpp │ ├── console_uart_sol.hpp │ ├── cos.hpp │ ├── counter.hpp │ ├── cpu.hpp │ ├── cpuset.hpp │ ├── cr.hpp │ ├── descriptor.hpp │ ├── drng.hpp │ ├── ec_arch.hpp │ ├── entry.hpp │ ├── event.hpp │ ├── extern.hpp │ ├── fpu.hpp │ ├── gdt.hpp │ ├── hip_arch.hpp │ ├── hpet.hpp │ ├── idt.hpp │ ├── integrity.hpp │ ├── interrupt.hpp │ ├── intid.hpp │ ├── io.hpp │ ├── ioapic.hpp │ ├── lapic.hpp │ ├── lowlevel.hpp │ ├── mca.hpp │ ├── memattr.hpp │ ├── memory.hpp │ ├── msr.hpp │ ├── mtd_arch.hpp │ ├── mtrr.hpp │ ├── nmi.hpp │ ├── patch_arch.hpp │ ├── pci_arch.hpp │ ├── pcid.hpp │ ├── pconfig.hpp │ ├── pic.hpp │ ├── ptab_dpt.hpp │ ├── ptab_ept.hpp │ ├── ptab_hpt.hpp │ ├── ptab_pte.hpp │ ├── ptab_tmp.hpp │ ├── regs.hpp │ ├── selectors.hpp │ ├── sgx.hpp │ ├── smmu.hpp │ ├── smx.hpp │ ├── space_dma.hpp │ ├── space_gst.hpp │ ├── space_hst.hpp │ ├── space_msr.hpp │ ├── space_pio.hpp │ ├── spinlock.hpp │ ├── svm.hpp │ ├── syscall_tmp.hpp │ ├── tcg.hpp │ ├── timer.hpp │ ├── tlb.hpp │ ├── tpm.hpp │ ├── tpm_alg.hpp │ ├── tpm_log.hpp │ ├── tss.hpp │ ├── txt.hpp │ ├── utcb_arch.hpp │ ├── vectors.hpp │ ├── vmx.hpp │ └── vpid.hpp └── src ├── aarch64 ├── acpi_table_fadt.cpp ├── acpi_table_gtdt.cpp ├── acpi_table_hest.cpp ├── acpi_table_iort.cpp ├── acpi_table_madt.cpp ├── acpi_table_srat.cpp ├── bootstrap.cpp ├── console_uart_cdns.cpp ├── console_uart_imx.cpp ├── console_uart_meson.cpp ├── console_uart_mini.cpp ├── console_uart_ns16550.cpp ├── console_uart_pl011.cpp ├── console_uart_scif.cpp ├── counter.cpp ├── cpu.cpp ├── ec_arch.cpp ├── ec_exc.cpp ├── entry.S ├── fdt.cpp ├── fpu.cpp ├── gicc.cpp ├── gicd.cpp ├── gich.cpp ├── gicr.cpp ├── gits.cpp ├── hip_arch.cpp ├── init.cpp ├── interrupt.cpp ├── psci.cpp ├── ptab_hpt.cpp ├── ptab_npt.cpp ├── smmu.cpp ├── smmu_v2.cpp ├── smmu_v3.cpp ├── space_hst.cpp ├── start.S ├── timer.cpp ├── utcb_arch.cpp └── vmcb.cpp ├── acpi.cpp ├── acpi_table.cpp ├── acpi_table_dbg2.cpp ├── acpi_table_facs.cpp ├── acpi_table_mcfg.cpp ├── acpi_table_spcr.cpp ├── acpi_table_tpm2.cpp ├── acpi_table_xsdt.cpp ├── buddy.cpp ├── cache.cpp ├── cmdline.cpp ├── console.cpp ├── console_mbuf.cpp ├── ec.cpp ├── head_mbi.S ├── hip.cpp ├── hypervisor.ld ├── integrity.cpp ├── pci.cpp ├── pd.cpp ├── pt.cpp ├── ptab.cpp ├── rcu.cpp ├── sc.cpp ├── scheduler.cpp ├── slab.cpp ├── sm.cpp ├── space_mem.cpp ├── space_obj.cpp ├── string.cpp ├── syscall.cpp ├── timeout.cpp ├── timeout_budget.cpp ├── timeout_hypercall.cpp ├── uefi.cpp └── x86_64 ├── acpi_table_dmar.cpp ├── acpi_table_fadt.cpp ├── acpi_table_hest.cpp ├── acpi_table_hpet.cpp ├── acpi_table_lpit.cpp ├── acpi_table_madt.cpp ├── acpi_table_srat.cpp ├── bootstrap.cpp ├── console_uart_apb.cpp ├── console_uart_hsu.cpp ├── console_uart_sio.cpp ├── console_uart_sol.cpp ├── cos.cpp ├── counter.cpp ├── cpu.cpp ├── ec_arch.cpp ├── ec_exc.cpp ├── ec_svm.cpp ├── ec_vmx.cpp ├── entry.S ├── fpu.cpp ├── gdt.cpp ├── head_mle.S ├── hip_arch.cpp ├── hpet.cpp ├── idt.cpp ├── init.cpp ├── interrupt.cpp ├── ioapic.cpp ├── lapic.cpp ├── mca.cpp ├── patch.cpp ├── ptab_hpt.cpp ├── regs.cpp ├── sgx.cpp ├── smmu.cpp ├── space_dma.cpp ├── space_hst.cpp ├── space_msr.cpp ├── space_pio.cpp ├── start.S ├── svm.cpp ├── tlb.cpp ├── tpm.cpp ├── tpm_log.cpp ├── tss.cpp ├── txt.cpp ├── utcb_arch.cpp ├── vmx.cpp └── vpid.cpp /.gitlab/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Rules defined later take precedence over rules defined earlier 2 | 3 | # Default 4 | * udo@hypervisor.org 5 | -------------------------------------------------------------------------------- /doc/specification.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udosteinberg/NOVA/d7a5368861102d2b6c6056e952838e372bef948e/doc/specification.pdf -------------------------------------------------------------------------------- /inc/aarch64/abi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Application Binary Interface: Architecture-Specific (Arm) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "regs.hpp" 21 | 22 | class Sys_abi 23 | { 24 | private: 25 | Sys_regs &s; 26 | 27 | public: 28 | Sys_abi (Sys_regs &r) : s { r } {} 29 | 30 | auto &p0() const { return s.gpr[0]; } 31 | auto &p1() const { return s.gpr[1]; } 32 | auto &p2() const { return s.gpr[2]; } 33 | auto const &p3() const { return s.gpr[3]; } 34 | auto const &p4() const { return s.gpr[4]; } 35 | 36 | ALWAYS_INLINE uint8_t flags() const { return p0() >> 4 & BIT_RANGE (3, 0); } 37 | }; 38 | -------------------------------------------------------------------------------- /inc/aarch64/acpi_table_gtdt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "acpi_table.hpp" 21 | 22 | /* 23 | * 5.2.24: Generic Timer Description Table (GTDT) 24 | */ 25 | class Acpi_table_gtdt final 26 | { 27 | private: 28 | Acpi_table table; // 0 5.0+ 29 | Unaligned_le ctrl_base; // 36 5.0+ 30 | Unaligned_le flags; // 44 5.0+ 31 | Unaligned_le el1_s_gsi, el1_s_flg; // 48 5.0+ 32 | Unaligned_le el1_p_gsi, el1_p_flg; // 56 5.0+ 33 | Unaligned_le el1_v_gsi, el1_v_flg; // 64 5.0+ 34 | Unaligned_le el2_p_gsi, el2_p_flg; // 72 5.0+ 35 | Unaligned_le read_base; // 80 5.1+ 36 | Unaligned_le plt_cnt; // 88 5.1+ 37 | Unaligned_le plt_off; // 92 5.1+ 38 | Unaligned_le el2_v_gsi, el2_v_flg; // 96 6.3+ 39 | 40 | public: 41 | void parse() const; 42 | }; 43 | 44 | static_assert (__is_standard_layout (Acpi_table_gtdt) && alignof (Acpi_table_gtdt) == 1 && sizeof (Acpi_table_gtdt) == 104); 45 | -------------------------------------------------------------------------------- /inc/aarch64/board_acpi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Any ACPI-Based Board 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #ifndef __ASSEMBLER__ 21 | 22 | #include "debug.hpp" 23 | 24 | struct Board 25 | { 26 | static constexpr uint64_t spin_addr { 0 }; 27 | static constexpr struct Cpu { uint64_t id; } cpu[1] { { 0 } }; 28 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0, 0 }, { 0, 0 } }; 29 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }; 30 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_NONE, 0, 0 }; 31 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 32 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /inc/aarch64/board_allwinner_a64.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Allwinner A64 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x40000000 // 0x40000000 - 0xffffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[4] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0x01c81000, 0x1000 }, { 0, 0 }, { 0x01c82000, 0x2000 }, { 0x01c84000, 0x2000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_NS16550_DBGP, 0x01c28000, 0 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_amlogic_g12b.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Amlogic G12B (S922X/A311D) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x0 // 0x0 - 0xf4ffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[6] { { 0x0 }, { 0x1 }, { 0x100 }, { 0x101 }, { 0x102 }, { 0x103 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0xffc01000, 0x1000 }, { 0, 0 }, { 0xffc02000, 0x2000 }, { 0xffc04000, 0x2000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_MESON, 0xff803000, 24'000'000 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_amlogic_sm1.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Amlogic SM1 (S905D3/S905X3/S905Y3) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x0 // 0x0 - 0xf57fffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[4] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0xffc01000, 0x1000 }, { 0, 0 }, { 0xffc02000, 0x2000 }, { 0xffc04000, 0x2000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_MESON, 0xff803000, 24'000'000 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_broadcom_bcm2711.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Broadcom BCM2711 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x0 // 0x0 - 0xfc000000 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0xd8 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[4] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0xff841000, 0x1000 }, { 0, 0 }, { 0xff842000, 0x2000 }, { 0xff844000, 0x2000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_BCM2835, 0xfe215000, 500'000'000 }; 33 | // static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_PL011, 0xfe201000, 48'000'000 }; 34 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 35 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /inc/aarch64/board_hisilicon_hi3660.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: HiSilicon Hi3660 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x0 // 0x0 - 0xdfffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[8] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 }, { 0x100 }, { 0x101 }, { 0x102 }, { 0x103 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0xe82b1000, 0x1000 }, { 0, 0 }, { 0xe82b2000, 0x2000 }, { 0xe82b4000, 0x2000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_PL011, 0xfff32000, 0 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_nvidia_tegrax1.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: NVIDIA Tegra X1 (Erista) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x80000000 // 0x80000000 - 0xffffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[4] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0x50041000, 0x1000 }, { 0, 0 }, { 0x50042000, 0x2000 }, { 0x50044000, 0x2000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_NS16550_DBGP, 0x70006000, 408'000'000 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_nvidia_tegrax2.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: NVIDIA Tegra X2 (Parker) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x80000000 // 0x80000000 - 0x3ffffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[6] { { 0x0 }, { 0x1 }, { 0x100 }, { 0x101 }, { 0x102 }, { 0x103 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0x03881000, 0x1000 }, { 0, 0 }, { 0x03882000, 0x2000 }, { 0x03884000, 0x2000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_NS16550_DBGP, 0x03100000, 0 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[2], ctx[2]; } smmu_v2[1] 34 | { 35 | { 0x12000000, { { 0xaa, 0x4 }, { 0xab, 0x4 } }, { { 0xaa, 0x4 }, { 0xab, 0x4 } } }, // SMMU0 36 | }; 37 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /inc/aarch64/board_nxp_imx8m.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: NXP i.MX 8M 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x40000000 // 0x40000000 - 0x13fffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[4] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0x38800000, 0x10000 }, { 0x38880000, 0x80000 }, { 0, 0 }, { 0, 0 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_IMX, 0x30860000, 25'000'000 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_qemu.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: QEMU Virtual Board 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x40000000 // 0x40000000 - ... 21 | #define RAM_SIZE 0x10000000 // 256MB 22 | 23 | #ifndef __ASSEMBLER__ 24 | 25 | #include "debug.hpp" 26 | 27 | struct Board 28 | { 29 | static constexpr uint64_t spin_addr { 0 }; 30 | static constexpr struct Cpu { uint64_t id; } cpu[4] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 } }; 31 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x4 }, { 0xb, 0x4 } }; 32 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0x8000000, 0x10000 }, { 0x80a0000, 0xf60000 }, { 0x8010000, 0x10000 }, { 0x8030000, 0x10000 } }; 33 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_PL011, 0x9000000, 24'000'000 }; 34 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 35 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /inc/aarch64/board_renesas_rcar3.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Renesas R-Car 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x40000000 // 0x40000000 - 0xbfffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[6] { { 0x0 }, { 0x1 }, { 0x101 }, { 0x102 }, { 0x103 }, { 0x104 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0xf1010000, 0x1000 }, { 0, 0 }, { 0xf1020000, 0x20000 }, { 0xf1040000, 0x20000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_SCIF, 0xe6e88000, 0 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_rockchip_rk3399.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Rockchip RK3399 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x0 // 0x0 - 0xf7ffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[6] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 }, { 0x100 }, { 0x101 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0xfee00000, 0x10000 }, { 0xfef00000, 0xc0000 }, { 0, 0 }, { 0, 0 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_NS16550_DBGP, 0xff1a0000, 0 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_ti_am62x.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Texas Instruments Sitara AM62x 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x80000000 // 0x80000000 - 0xffffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[4] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0x1800000, 0x10000 }, { 0x1880000, 0x80000 }, { 0, 0 }, { 0, 0 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_NS16550_DBGP, 0x2800000, 48'000'000 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_ti_j721e.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Texas Instruments Jacinto J721E (DRA829/TDA4VM) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x80000000 // 0x80000000 - 0xffffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | #include "intid.hpp" 26 | 27 | struct Board 28 | { 29 | static constexpr uint64_t spin_addr { 0 }; 30 | static constexpr struct Cpu { uint64_t id; } cpu[2] { { 0x0 }, { 0x1 } }; 31 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 32 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0x1800000, 0x10000 }, { 0x1900000, 0x100000 }, { 0, 0 }, { 0, 0 } }; 33 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_NS16550_DBGP, 0x2800000, 48'000'000 }; 34 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] {}; 35 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] { 0x36600000, Intid::from_spi (0x304), Intid::from_spi (0x300), 0, 0 }; 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /inc/aarch64/board_xilinx_zynq_cg.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Xilinx Zynq Ultrascale+ MPSoC ZCU102 (ZUxCG) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x0 // 0x0 - 0x7fffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[2] { { 0x0 }, { 0x1 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0xf9010000, 0x10000 }, { 0, 0 }, { 0xf9020000, 0x20000 }, { 0xf9040000, 0x20000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_CDNS, 0xff000000, 100'000'000 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] { { 0xfd800000, { { 0x9b, 0x4 } }, { { 0x9b, 0x4 } } } }; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_xilinx_zynq_u96.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Xilinx Zynq Ultrascale+ MPSoC Ultra96 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x0 // 0x0 - 0x7fffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[4] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0xf9010000, 0x10000 }, { 0, 0 }, { 0xf9020000, 0x20000 }, { 0xf9040000, 0x20000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_CDNS, 0xff010000, 100'000'000 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] { { 0xfd800000, { { 0x9b, 0x4 } }, { { 0x9b, 0x4 } } } }; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/board_xilinx_zynq_zcu102.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Board-Specific Configuration: Xilinx Zynq Ultrascale+ MPSoC ZCU102 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define RAM_BASE 0x0 // 0x0 - 0x7fffffff 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include "debug.hpp" 25 | 26 | struct Board 27 | { 28 | static constexpr uint64_t spin_addr { 0 }; 29 | static constexpr struct Cpu { uint64_t id; } cpu[4] { { 0x0 }, { 0x1 }, { 0x2 }, { 0x3 } }; 30 | static constexpr struct Tmr { unsigned ppi, flg; } tmr[2] { { 0xa, 0x8 }, { 0xb, 0x8 } }; 31 | static constexpr struct Gic { uint64_t mmio, size; } gic[4] { { 0xf9010000, 0x10000 }, { 0, 0 }, { 0xf9020000, 0x20000 }, { 0xf9040000, 0x20000 } }; 32 | static constexpr struct Uart { Debug::Subtype type; uint64_t mmio; unsigned clock; } uart { Debug::Subtype::SERIAL_CDNS, 0xff000000, 100'000'000 }; 33 | static constexpr struct Smmu_v2 { uint64_t mmio; struct { unsigned spi, flg; } glb[1], ctx[1]; } smmu_v2[1] { { 0xfd800000, { { 0x9b, 0x4 } }, { { 0x9b, 0x4 } } } }; 34 | static constexpr struct Smmu_v3 { uint64_t mmio; unsigned evt; unsigned glb; unsigned cmd; unsigned pri; } smmu_v3[1] {}; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inc/aarch64/coherency.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Coherency Support 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "barrier.hpp" 21 | #include "cache.hpp" 22 | 23 | class Coherency final 24 | { 25 | public: 26 | static void observe (void const *ptr, size_t size, bool coherent) 27 | { 28 | // A DSB ISHST is sufficient if memory is coherent 29 | if (coherent) [[likely]] 30 | return Barrier::wsb (Barrier::Domain::ISH); 31 | 32 | // Use 32 as conservative default because per-CPU line size is not yet available during init 33 | Cache::data_clean (ptr, size, 32); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /inc/aarch64/coresight.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CoreSight Architecture 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "std.hpp" 21 | #include "types.hpp" 22 | 23 | class Coresight 24 | { 25 | protected: 26 | enum class Component : unsigned 27 | { 28 | CIDR3 = 4, // Component Identification Register 3 29 | CIDR2 = 8, // Component Identification Register 2 30 | CIDR1 = 12, // Component Identification Register 1 31 | CIDR0 = 16, // Component Identification Register 0 32 | PIDR3 = 20, // Peripheral Identification Register 3 33 | PIDR2 = 24, // Peripheral Identification Register 2 34 | PIDR1 = 28, // Peripheral Identification Register 1 35 | PIDR0 = 32, // Peripheral Identification Register 0 36 | }; 37 | 38 | static auto read (Component r, uintptr_t addr) { return *reinterpret_cast(addr - std::to_underlying (r)); } 39 | }; 40 | -------------------------------------------------------------------------------- /inc/aarch64/cos.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Class Of Service (COS) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "status.hpp" 21 | #include "types.hpp" 22 | 23 | class Cos final 24 | { 25 | public: 26 | /* 27 | * Determine if a class of service is valid 28 | * 29 | * @param cos Class of service 30 | * @return True if valid, false otherwise 31 | */ 32 | static bool valid_cos (cos_t cos) { return !cos; } 33 | 34 | /* 35 | * Change the currently active class of service 36 | */ 37 | static void make_current (cos_t) {} 38 | 39 | static auto cfg_qos (uint8_t) { return Status::BAD_FTR; } 40 | static auto cfg_l3_mask (uint16_t, uint32_t) { return Status::BAD_FTR; } 41 | static auto cfg_l2_mask (uint16_t, uint32_t) { return Status::BAD_FTR; } 42 | static auto cfg_mb_thrt (uint16_t, uint16_t) { return Status::BAD_FTR; } 43 | }; 44 | -------------------------------------------------------------------------------- /inc/aarch64/counter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Event Counters 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "atomic.hpp" 21 | #include "intid.hpp" 22 | #include "kmem.hpp" 23 | #include "types.hpp" 24 | 25 | class Counter final 26 | { 27 | private: 28 | Atomic val { 0 }; 29 | 30 | public: 31 | static Counter req[Intid::NUM_SGI] CPULOCAL; 32 | static Counter loc[Intid::NUM_PPI] CPULOCAL; 33 | static Counter schedule CPULOCAL; 34 | static Counter helping CPULOCAL; 35 | 36 | ALWAYS_INLINE 37 | inline void inc() 38 | { 39 | val = val + 1; 40 | } 41 | 42 | ALWAYS_INLINE 43 | inline unsigned get (cpu_t cpu) const 44 | { 45 | return *Kmem::loc_to_glb (cpu, &val); 46 | } 47 | }; 48 | -------------------------------------------------------------------------------- /inc/aarch64/event.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Event Selectors 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | class Event final 21 | { 22 | public: 23 | enum Selector 24 | { 25 | NONE = -1, 26 | STARTUP = 0, 27 | RECALL = 1, 28 | VTIMER = 2, 29 | }; 30 | 31 | static constexpr auto hst_arch { 64 }; 32 | static constexpr auto gst_arch { 64 }; 33 | 34 | static constexpr auto hst_max { 1 + RECALL }; 35 | static constexpr auto gst_max { 1 + VTIMER }; 36 | }; 37 | -------------------------------------------------------------------------------- /inc/aarch64/extern.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * External Symbols 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "types.hpp" 21 | 22 | extern char __init_psci, __init_spin; 23 | extern char GIT_VER, NOVA_HPAS, KMEM_HVAS, KMEM_HVAF, PTAB_HVAS, DSTK_TOP; 24 | extern void (*CTORS_S[])(), (*CTORS_E[])(), (*CTORS_C[])(), (*CTORS_L[])(); 25 | -------------------------------------------------------------------------------- /inc/aarch64/hip_arch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hypervisor Information Page (HIP): Architecture-Specific Part (Arm) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "macros.hpp" 21 | #include "types.hpp" 22 | 23 | class Hip_arch final 24 | { 25 | private: 26 | uint16_t num_smg; 27 | uint16_t num_ctx; 28 | 29 | public: 30 | enum class Feature : uint64_t 31 | { 32 | SMMU = BIT (0), 33 | }; 34 | 35 | void build(); 36 | }; 37 | -------------------------------------------------------------------------------- /inc/aarch64/integrity.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Integrity Measurement 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "hash.hpp" 21 | 22 | class Integrity final 23 | { 24 | private: 25 | static bool extend (unsigned, Hash_sha1_160 const &, Hash_sha2_256 const &, Hash_sha2_384 const &, Hash_sha2_512 const &) { return false; } 26 | 27 | public: 28 | static inline constinit uint64_t root_phys { 0 }, root_size { 0 }; 29 | 30 | static bool measure(); 31 | }; 32 | -------------------------------------------------------------------------------- /inc/aarch64/lowlevel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Low-Level Functions 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "compiler.hpp" 21 | 22 | static inline void pause() 23 | { 24 | asm volatile ("yield" : : : "memory"); 25 | } 26 | 27 | [[noreturn]] static inline void shutdown() 28 | { 29 | for (;;) 30 | asm volatile ("wfi" : : : "memory"); 31 | } 32 | -------------------------------------------------------------------------------- /inc/aarch64/patch_arch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Instruction Patching: Architecture-Specific Part (Arm) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define NOP_LEN 4 21 | #define NOP_OPC 0xd503201f 22 | -------------------------------------------------------------------------------- /inc/aarch64/ptab_pte.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Page Table Entry (Arm) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "barrier.hpp" 21 | #include "ptab.hpp" 22 | 23 | template class Pte : public Ptab::Entry 24 | { 25 | using E = typename Ptab::Entry; 26 | 27 | public: 28 | auto type (unsigned l) const { return E::val ? l == T::lev() || (l && (E::val & T::ATTR_nL)) ? E::Type::PTAB : E::Type::LEAF : E::Type::HOLE; } 29 | 30 | static void publish() { Barrier::wsb (Barrier::Domain::ISH); } 31 | 32 | // Physical address size 33 | static constexpr auto pas (unsigned e) 34 | { 35 | static constexpr unsigned encoding[8] { 32, 36, 40, 42, 44, 48, 52, 56 }; 36 | return encoding[BIT_RANGE (2, 0) & e]; 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /inc/aarch64/ptab_tmp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Page Table Templates 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "ptab_dpt.hpp" 21 | #include "ptab_hpt.hpp" 22 | #include "ptab_npt.hpp" 23 | 24 | template class Ptab; 25 | template class Ptab; 26 | template class Ptab; 27 | -------------------------------------------------------------------------------- /inc/aarch64/space_msr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MSR Space 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "space.hpp" 21 | 22 | class Space_msr final : public Space 23 | { 24 | public: 25 | static constexpr uint8_t mco { 0 }; 26 | static constexpr uint8_t sbw { 0 }; 27 | 28 | [[nodiscard]] auto delegate (Space_msr const *, unsigned long, unsigned long, unsigned, unsigned) { return Status::BAD_FTR; } 29 | 30 | [[nodiscard]] static Space_msr *create (Status &s, Slab_cache &, Pd *) 31 | { 32 | s = Status::BAD_FTR; 33 | 34 | return nullptr; 35 | } 36 | 37 | void destroy() {} 38 | }; 39 | -------------------------------------------------------------------------------- /inc/aarch64/space_pio.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * PIO Space 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "space.hpp" 21 | 22 | class Space_pio final : public Space 23 | { 24 | public: 25 | static constexpr uint8_t mco { 0 }; 26 | static constexpr uint8_t sbw { 0 }; 27 | 28 | [[nodiscard]] auto delegate (Space_pio const *, unsigned long, unsigned long, unsigned, unsigned) { return Status::BAD_FTR; } 29 | 30 | [[nodiscard]] static Space_pio *create (Status &s, Slab_cache &, Pd *, bool) 31 | { 32 | s = Status::BAD_FTR; 33 | 34 | return nullptr; 35 | } 36 | 37 | void destroy() {} 38 | }; 39 | -------------------------------------------------------------------------------- /inc/aarch64/syscall_tmp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * System-Call Interface 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | template void Ec::send_msg (Ec *); 21 | template void Ec::send_msg (Ec *); 22 | -------------------------------------------------------------------------------- /inc/aarch64/sysreg.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * System Register Access 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "compiler.hpp" 21 | #include "types.hpp" 22 | 23 | #define RDSYS(T, R, E) \ 24 | static inline auto get_##R() \ 25 | { \ 26 | T v; \ 27 | asm volatile ("mrs %x0, " EXPAND (E) : "=r" (v)); \ 28 | return v; \ 29 | } 30 | 31 | #define WRSYS(T, R, E) \ 32 | static inline void set_##R (T v) \ 33 | { \ 34 | asm volatile ("msr " EXPAND (E) ", %x0" : : "rZ" (v)); \ 35 | } 36 | 37 | #define SYSREG32_RO(R, E) RDSYS (uint32_t, R, E) 38 | #define SYSREG32_WO(R, E) WRSYS (uint32_t, R, E) 39 | #define SYSREG32_RW(R, E) SYSREG32_RO (R, E) SYSREG32_WO (R, E) 40 | 41 | #define SYSREG64_RO(R, E) RDSYS (uint64_t, R, E) 42 | #define SYSREG64_WO(R, E) WRSYS (uint64_t, R, E) 43 | #define SYSREG64_RW(R, E) SYSREG64_RO (R, E) SYSREG64_WO (R, E) 44 | -------------------------------------------------------------------------------- /inc/aarch64/vmid.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Virtual-Machine Identifier (VMID) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "atomic.hpp" 21 | #include "macros.hpp" 22 | #include "types.hpp" 23 | 24 | class Vmid final 25 | { 26 | private: 27 | uint16_t const val; 28 | 29 | static inline constinit Atomic allocator { 0 }; 30 | 31 | // FIXME: Handle overflow 32 | static auto alloc() 33 | { 34 | return allocator++; 35 | } 36 | 37 | public: 38 | Vmid() : val { alloc() } {} 39 | 40 | operator auto() const { return val & BIT_RANGE (7, 0); } 41 | }; 42 | -------------------------------------------------------------------------------- /inc/acpi_table_spcr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "acpi_table.hpp" 21 | 22 | /* 23 | * Serial Port Console Redirection Table (SPCR) 24 | */ 25 | class Acpi_table_spcr final 26 | { 27 | private: 28 | Acpi_table table; // 0 29 | Unaligned_le subtype; // 36 30 | Unaligned_le reserved; // 38 31 | Acpi_gas regs; // 40 32 | Unaligned_le intr_type, irq, gsi[4]; // 52 33 | Unaligned_le baud, parity, stop, flow, term, lang; // 58 34 | Unaligned_le did, vid; // 64 35 | Unaligned_le bus, dev, fun, flags[4], seg, res[4]; // 68 36 | 37 | public: 38 | void parse() const; 39 | }; 40 | 41 | static_assert (__is_standard_layout (Acpi_table_spcr) && alignof (Acpi_table_spcr) == 1 && sizeof (Acpi_table_spcr) == 80); 42 | -------------------------------------------------------------------------------- /inc/acpi_table_tpm2.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "acpi_table.hpp" 21 | 22 | /* 23 | * TCG Hardware Interface Description Table for TPM 2.0 (TPM2) 24 | */ 25 | class Acpi_table_tpm2 final 26 | { 27 | private: 28 | Acpi_table table; // 0 29 | Unaligned_le platform; // 36 30 | Unaligned_le reserved; // 38 31 | Unaligned_le tpm_base; // 40 32 | Unaligned_le start_method; // 48 33 | Unaligned_le start_params; // 52 34 | 35 | public: 36 | void parse() const; 37 | }; 38 | 39 | static_assert (__is_standard_layout (Acpi_table_tpm2) && alignof (Acpi_table_tpm2) == 1 && sizeof (Acpi_table_tpm2) == 56); 40 | -------------------------------------------------------------------------------- /inc/acpi_table_xsdt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "acpi_table.hpp" 25 | 26 | /* 27 | * 5.2.7: Root System Description Table (RSDT) 28 | * 5.2.8: Extended System Description Table (XSDT) 29 | */ 30 | class Acpi_table_xsdt final 31 | { 32 | private: 33 | Acpi_table table; 34 | 35 | public: 36 | void parse() const; 37 | }; 38 | 39 | static_assert (__is_standard_layout (Acpi_table_xsdt) && alignof (Acpi_table_xsdt) == 1 && sizeof (Acpi_table_xsdt) == 36); 40 | -------------------------------------------------------------------------------- /inc/assert.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Assertions 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2014 Udo Steinberg, FireEye, Inc. 9 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 10 | * 11 | * This file is part of the NOVA microhypervisor. 12 | * 13 | * NOVA is free software: you can redistribute it and/or modify it 14 | * under the terms of the GNU General Public License version 2 as 15 | * published by the Free Software Foundation. 16 | * 17 | * NOVA is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License version 2 for more details. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "stdio.hpp" 26 | 27 | #ifdef DEBUG 28 | #define assert(X) do { \ 29 | if (!(X)) [[unlikely]] \ 30 | panic ("Assertion \"%s\" in %s at %s:%d", #X, __PRETTY_FUNCTION__, __FILE__, __LINE__); \ 31 | } while (0) 32 | #else 33 | #define assert(X) do { (void) sizeof (X); } while (0) 34 | #endif 35 | -------------------------------------------------------------------------------- /inc/bitmap.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Atomic Bitmap 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "atomic.hpp" 21 | #include "bits.hpp" 22 | 23 | /* 24 | * Atomic Bitmap of B Bits initialized with I 25 | */ 26 | template class Bitmap final 27 | { 28 | private: 29 | static constexpr auto cnt { type_bits() }; 30 | static constexpr auto idx (size_t s) { return s / cnt; } 31 | static constexpr auto msk (size_t s) { return BITN (s % cnt); } 32 | 33 | struct { Atomic val { I ? ~uintptr_t { 0 } : 0 }; } bitmap[aligned_up (cnt, B) / cnt]; 34 | 35 | public: 36 | ALWAYS_INLINE inline void clr (size_t s) { bitmap[idx (s)].val &= ~msk (s); } 37 | ALWAYS_INLINE inline void set (size_t s) { bitmap[idx (s)].val |= msk (s); } 38 | ALWAYS_INLINE inline bool tst (size_t s) const { return bitmap[idx (s)].val & msk (s); } 39 | 40 | ALWAYS_INLINE inline void cfg (size_t s, bool b) { b ? set (s) : clr (s); } 41 | }; 42 | 43 | // Sanity checks 44 | static_assert (sizeof (Bitmap<1 + sizeof (uintptr_t) * 0>) == sizeof (uintptr_t) * 1); 45 | static_assert (sizeof (Bitmap<1 + sizeof (uintptr_t) * 8>) == sizeof (uintptr_t) * 2); 46 | static_assert (sizeof (Bitmap<1 + sizeof (uintptr_t) * 16>) == sizeof (uintptr_t) * 3); 47 | -------------------------------------------------------------------------------- /inc/checksum.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Checksum Functions 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | class Checksum 21 | { 22 | public: 23 | /* 24 | * Compute additive checksum 25 | * 26 | * @param ptr Pointer to array of T values 27 | * @param n Number of T values to checksum 28 | * @return Sum of T values, trimmed to T 29 | */ 30 | template static auto additive (T const *ptr, unsigned n) 31 | { 32 | T val { 0 }; 33 | 34 | while (n--) 35 | val += *ptr++; 36 | 37 | return val; 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /inc/console_mbuf.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Memory-Buffer Console 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "atomic.hpp" 21 | #include "buddy.hpp" 22 | #include "console.hpp" 23 | #include "kmem.hpp" 24 | 25 | class Sm; 26 | 27 | class Console_mbuf_mmio final 28 | { 29 | public: 30 | Atomic r_idx { 0 }; 31 | Atomic w_idx { 0 }; 32 | 33 | static constexpr unsigned ord { 0 }; 34 | static constexpr unsigned size { BIT (PAGE_BITS + ord) }; 35 | static constexpr unsigned entries { size - sizeof (r_idx) - sizeof (w_idx) }; 36 | 37 | Atomic buffer[entries]; 38 | 39 | [[nodiscard]] static void *operator new (size_t) noexcept 40 | { 41 | return Buddy::alloc (ord, Buddy::Fill::BITS0); 42 | } 43 | }; 44 | 45 | class Console_mbuf final : private Console 46 | { 47 | private: 48 | Sm *sm { nullptr }; 49 | 50 | [[nodiscard]] bool outc (char) const override final; 51 | 52 | Console_mbuf(); 53 | 54 | public: 55 | Console_mbuf_mmio *const regs; 56 | 57 | static Console_mbuf singleton; 58 | 59 | static auto addr() { return Kmem::ptr_to_phys (singleton.regs); } 60 | static auto size() { return singleton.regs->size; } 61 | }; 62 | -------------------------------------------------------------------------------- /inc/hazard.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hazard 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "atomic.hpp" 25 | #include "macros.hpp" 26 | 27 | class Hazard final 28 | { 29 | private: 30 | using hazard_t = unsigned; 31 | 32 | Atomic val; 33 | 34 | public: 35 | enum 36 | { 37 | SCHED = BIT (0), 38 | SLEEP = BIT (1), 39 | RCU = BIT (2), 40 | TR = BIT (15), // x86 only 41 | FPU = BIT (16), 42 | TSC = BIT (29), // x86 only 43 | RECALL = BIT (30), 44 | ILLEGAL = BIT (31), 45 | }; 46 | 47 | inline Hazard (hazard_t h) : val (h) {} 48 | 49 | inline operator hazard_t() const { return val; } 50 | 51 | inline void set (hazard_t h) { val |= h; } 52 | inline void clr (hazard_t h) { val &= ~h; } 53 | inline auto tas (hazard_t h) { return val.test_and_set (h); } 54 | }; 55 | -------------------------------------------------------------------------------- /inc/initprio.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Static Initialization Priorities 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | // Lower numbers indicate a higher priority 25 | #define AFTER(X) ((X) + 1) 26 | 27 | #define PRIO_LIMIT 100 28 | #define PRIO_PTAB AFTER (PRIO_LIMIT) 29 | #define PRIO_SLAB AFTER (PRIO_PTAB) 30 | #define PRIO_SPACE_OBJ AFTER (PRIO_SLAB) 31 | #define PRIO_SPACE_MEM AFTER (PRIO_SPACE_OBJ) 32 | #define PRIO_SPACE_PIO AFTER (PRIO_SPACE_OBJ) 33 | #define PRIO_SPACE_MSR AFTER (PRIO_SPACE_OBJ) 34 | #define PRIO_CONSOLE 65533 35 | #define PRIO_LOCAL 65534 36 | -------------------------------------------------------------------------------- /inc/kmem.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Kernel Memory Management 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "compiler.hpp" 25 | #include "memory.hpp" 26 | #include "types.hpp" 27 | 28 | class Kmem final 29 | { 30 | private: 31 | static inline constinit uintptr_t offset asm ("__kmem_offset") { 0 }; 32 | 33 | static auto phys_to_virt (uintptr_t p) { return p + offset; } 34 | static auto virt_to_phys (uintptr_t v) { return v - offset; } 35 | 36 | public: 37 | static auto sym_to_virt (void const *p) { return reinterpret_cast(p) + OFFSET; } 38 | static auto sym_to_phys (void const *p) { return virt_to_phys (sym_to_virt (p)); } 39 | static auto ptr_to_phys (void const *p) { return virt_to_phys (reinterpret_cast(p)); } 40 | static auto phys_to_ptr (uintptr_t p) { return reinterpret_cast(phys_to_virt (p)); } 41 | 42 | // Convert CPULOCAL pointer to global alias pointer 43 | template NONNULL static auto loc_to_glb (cpu_t cpu, T *p) 44 | { 45 | return reinterpret_cast(reinterpret_cast(p) - MMAP_CPU_DATA + MMAP_GLB_CPUS + cpu * PAGE_SIZE (0)); 46 | } 47 | }; 48 | -------------------------------------------------------------------------------- /inc/list.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Linked List 3 | * 4 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #pragma once 20 | 21 | template class List 22 | { 23 | protected: 24 | T *next { nullptr }; 25 | 26 | void insert (T *&list) 27 | { 28 | auto ptr { &list }; 29 | 30 | while (*ptr) 31 | ptr = &(*ptr)->next; 32 | 33 | *ptr = static_cast(this); 34 | } 35 | 36 | void remove (T *&list) 37 | { 38 | auto ptr { &list }; 39 | 40 | while (*ptr != this) 41 | ptr = &(*ptr)->next; 42 | 43 | *ptr = next; 44 | next = nullptr; 45 | } 46 | 47 | public: 48 | List (T *&list) 49 | { 50 | insert (list); 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /inc/lock_guard.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Lock Guard 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 8 | * 9 | * This file is part of the NOVA microhypervisor. 10 | * 11 | * NOVA is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License version 2 as 13 | * published by the Free Software Foundation. 14 | * 15 | * NOVA is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License version 2 for more details. 19 | */ 20 | 21 | #pragma once 22 | 23 | template class Lock_guard final 24 | { 25 | private: 26 | T &lock; 27 | 28 | public: 29 | Lock_guard (T &l) : lock { l } { lock.lock(); } 30 | 31 | ~Lock_guard() { lock.unlock(); } 32 | 33 | Lock_guard (Lock_guard const &) = delete; 34 | Lock_guard& operator= (Lock_guard const &) = delete; 35 | }; 36 | -------------------------------------------------------------------------------- /inc/macros.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Generic Macros 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #ifdef __ASSEMBLER__ 21 | #define SFX_U(X) X 22 | #define SFX_UL(X) X 23 | #define SFX_ULL(X) X 24 | #else 25 | #define SFX_U(X) X ## U 26 | #define SFX_UL(X) X ## UL 27 | #define SFX_ULL(X) X ## ULL 28 | #endif 29 | 30 | #define VAL_SHIFT(V,S) (SFX_U (V) << (S)) 31 | #define VALN_SHIFT(V,S) (SFX_UL (V) << (S)) 32 | #define VAL64_SHIFT(V,S) (SFX_ULL (V) << (S)) 33 | 34 | #define BIT_RANGE(H,L) (VAL_SHIFT (2, H) - VAL_SHIFT (1, L)) 35 | #define BITN_RANGE(H,L) (VALN_SHIFT (2, H) - VALN_SHIFT (1, L)) 36 | #define BIT64_RANGE(H,L) (VAL64_SHIFT (2, H) - VAL64_SHIFT (1, L)) 37 | 38 | #define BIT(B) VAL_SHIFT (1, B) 39 | #define BITN(B) VALN_SHIFT (1, B) 40 | #define BIT64(B) VAL64_SHIFT (1, B) 41 | -------------------------------------------------------------------------------- /inc/mtd.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Message Transfer Descriptor (MTD): Architecture-Independent Part 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 8 | * 9 | * This file is part of the NOVA microhypervisor. 10 | * 11 | * NOVA is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License version 2 as 13 | * published by the Free Software Foundation. 14 | * 15 | * NOVA is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License version 2 for more details. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "memory.hpp" 24 | #include "types.hpp" 25 | 26 | class Mtd 27 | { 28 | protected: 29 | uint32_t const mtd; 30 | 31 | explicit Mtd (uint32_t v) : mtd { v } {} 32 | 33 | public: 34 | operator auto() const { return mtd; } 35 | }; 36 | 37 | class Mtd_user final : public Mtd 38 | { 39 | public: 40 | static constexpr auto items { PAGE_SIZE (0) / sizeof (uintptr_t) }; 41 | 42 | auto count() const { return mtd % items + 1; } 43 | 44 | explicit Mtd_user (uint32_t v) : Mtd { v } {} 45 | }; 46 | -------------------------------------------------------------------------------- /inc/paging.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Paging Permissions 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "macros.hpp" 21 | 22 | class Paging final 23 | { 24 | public: 25 | enum Permissions 26 | { 27 | NONE = 0, // No Permissions 28 | R = BIT (0), // Read 29 | W = BIT (1), // Write 30 | XU = BIT (2), // Execute (User) 31 | XS = BIT (3), // Execute (Supervisor) 32 | API = XS | XU | W | R, 33 | U = BIT (12), // User Accessible 34 | K = BIT (13), // Kernel Memory 35 | G = BIT (14), // Global 36 | SS = BIT (15), // Shadow Stack 37 | }; 38 | }; 39 | -------------------------------------------------------------------------------- /inc/sdid.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SMMU Domain Identifier (SDID) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "atomic.hpp" 21 | #include "types.hpp" 22 | 23 | class Sdid final 24 | { 25 | private: 26 | uint8_t const val; 27 | 28 | static inline constinit Atomic allocator { 0 }; 29 | 30 | // FIXME: Handle overflow 31 | static inline auto alloc() { return allocator++; } 32 | 33 | public: 34 | inline Sdid() : val { alloc() } {} 35 | 36 | inline operator auto() const { return val; } 37 | }; 38 | -------------------------------------------------------------------------------- /inc/signature.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Signature Functions 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "types.hpp" 21 | 22 | class Signature 23 | { 24 | public: 25 | /* 26 | * Convert 4-character ASCII string to uint32_t (little-endian) 27 | * 28 | * @param s String of length >= 4 29 | * @return uint32_t representation of the string 30 | */ 31 | static constexpr auto u32 (char const *s) 32 | { 33 | return static_cast(s[3]) << 24 | static_cast(s[2]) << 16 | 34 | static_cast(s[1]) << 8 | static_cast(s[0]); 35 | } 36 | 37 | /* 38 | * Convert 8-character ASCII string to uint64_t (little-endian) 39 | * 40 | * @param s String of length >= 8 41 | * @return uint64_t representation of the string 42 | */ 43 | static constexpr auto u64 (char const *s) 44 | { 45 | return static_cast(s[7]) << 56 | static_cast(s[6]) << 48 | 46 | static_cast(s[5]) << 40 | static_cast(s[4]) << 32 | 47 | static_cast(s[3]) << 24 | static_cast(s[2]) << 16 | 48 | static_cast(s[1]) << 8 | static_cast(s[0]); 49 | } 50 | }; 51 | -------------------------------------------------------------------------------- /inc/slab.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Slab Allocator 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "initprio.hpp" 25 | #include "spinlock.hpp" 26 | 27 | class Slab_cache final 28 | { 29 | private: 30 | struct Slab; 31 | 32 | uint16_t const bsz; // Buffer size 33 | uint16_t const bps; // Buffers per Slab 34 | Slab * curr { nullptr }; // Current (Partial) Slab 35 | Slab * head { nullptr }; // Head of Slab List 36 | Spinlock lock; // Allocator Spinlock 37 | 38 | public: 39 | [[nodiscard]] void *alloc(); 40 | 41 | void free (void *); 42 | 43 | Slab_cache (size_t, size_t); 44 | }; 45 | -------------------------------------------------------------------------------- /inc/space.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Space 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "pd.hpp" 25 | 26 | class Space : public Kobject 27 | { 28 | private: 29 | Refptr const pd; 30 | 31 | protected: 32 | Space (Kobject::Subtype s) : Kobject { Kobject::Type::PD, s }, pd { nullptr } {} 33 | 34 | Space (Kobject::Subtype s, Refptr &p) : Kobject { Kobject::Type::PD, s }, pd { std::move (p) } {} 35 | 36 | public: 37 | Pd *get_pd() const { return pd; } 38 | }; 39 | -------------------------------------------------------------------------------- /inc/space_mem.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Memory Space 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "bits.hpp" 25 | #include "memattr.hpp" 26 | #include "memory.hpp" 27 | #include "paging.hpp" 28 | #include "space.hpp" 29 | 30 | template class Space_mem : public Space 31 | { 32 | protected: 33 | Space_mem (Kobject::Subtype s) : Space { s } {} 34 | 35 | Space_mem (Kobject::Subtype s, Refptr &p) : Space { s, p } {} 36 | 37 | static void access_ctrl (T &mem, uint64_t phys, size_t size, Paging::Permissions perm, Memattr attr) 38 | { 39 | for (unsigned o; size; size -= BITN (o), phys += BITN (o)) 40 | mem.update (phys, phys, (o = aligned_order (size, phys)) - PAGE_BITS, perm, attr); 41 | } 42 | 43 | public: 44 | [[nodiscard]] Status delegate (Space_hst const *, unsigned long, unsigned long, unsigned, unsigned, Memattr); 45 | }; 46 | -------------------------------------------------------------------------------- /inc/status.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hypercall Status Codes 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | enum class Status : unsigned 25 | { 26 | SUCCESS, 27 | TIMEOUT, 28 | ABORTED, 29 | OVRFLOW, 30 | BAD_HYP, 31 | BAD_CAP, 32 | BAD_PAR, 33 | BAD_FTR, 34 | BAD_CPU, 35 | BAD_DEV, 36 | MEM_OBJ, 37 | MEM_CAP, 38 | }; 39 | -------------------------------------------------------------------------------- /inc/timeout.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Timeout 3 | * 4 | * Copyright (C) 2014 Udo Steinberg, FireEye, Inc. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "compiler.hpp" 22 | #include "types.hpp" 23 | 24 | class Timeout 25 | { 26 | private: 27 | uint64_t time { 0 }; 28 | Timeout * prev { nullptr }; 29 | Timeout * next { nullptr }; 30 | 31 | static inline constinit Timeout *list CPULOCAL { nullptr }; 32 | 33 | virtual void trigger() = 0; 34 | 35 | public: 36 | // Enforce a constructor for CPU-local timeouts 37 | Timeout() {} 38 | 39 | void enqueue (uint64_t); 40 | uint64_t dequeue(); 41 | 42 | static void check(); 43 | static void sync(); 44 | 45 | static uint64_t idle(); 46 | }; 47 | -------------------------------------------------------------------------------- /inc/timeout_budget.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Budget Timeout 3 | * 4 | * Copyright (C) 2014 Udo Steinberg, FireEye, Inc. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "timeout.hpp" 22 | 23 | class Timeout_budget final : public Timeout 24 | { 25 | private: 26 | void trigger() override; 27 | 28 | public: 29 | static Timeout_budget timeout CPULOCAL; 30 | }; 31 | -------------------------------------------------------------------------------- /inc/timeout_hypercall.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hypercall Timeout 3 | * 4 | * Copyright (C) 2014 Udo Steinberg, FireEye, Inc. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "timeout.hpp" 22 | 23 | class Ec; 24 | class Sm; 25 | 26 | class Timeout_hypercall final : public Timeout 27 | { 28 | private: 29 | Ec * const ec { nullptr }; 30 | Sm * sm { nullptr }; 31 | 32 | void trigger() override; 33 | 34 | public: 35 | Timeout_hypercall (Ec *e) : ec (e) {} 36 | 37 | void enqueue (uint64_t t, Sm *s) { sm = s; Timeout::enqueue (t); } 38 | }; 39 | -------------------------------------------------------------------------------- /inc/types.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Type Definitions 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 8 | * 9 | * This file is part of the NOVA microhypervisor. 10 | * 11 | * NOVA is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License version 2 as 13 | * published by the Free Software Foundation. 14 | * 15 | * NOVA is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License version 2 for more details. 19 | */ 20 | 21 | #pragma once 22 | 23 | // Signed Integer Types 24 | using int32_t = __INT32_TYPE__; 25 | using int64_t = __INT64_TYPE__; 26 | 27 | // Unsigned Integer Types 28 | using uint8_t = __UINT8_TYPE__; 29 | using uint16_t = __UINT16_TYPE__; 30 | using uint32_t = __UINT32_TYPE__; 31 | using uint64_t = __UINT64_TYPE__; 32 | using uint128_t = __uint128_t; 33 | 34 | // Pointer Types 35 | using uintptr_t = __UINTPTR_TYPE__; 36 | 37 | // Size Types 38 | using size_t = __SIZE_TYPE__; 39 | 40 | // NOVA Types 41 | using apic_t = uint32_t; 42 | using iid_t = uint32_t; 43 | using pci_t = uint32_t; 44 | using cos_t = uint16_t; 45 | using cpu_t = uint16_t; 46 | using gsi_t = uint16_t; 47 | using port_t = uint16_t; 48 | -------------------------------------------------------------------------------- /inc/util.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Utility Functions 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 8 | * 9 | * This file is part of the NOVA microhypervisor. 10 | * 11 | * NOVA is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License version 2 as 13 | * published by the Free Software Foundation. 14 | * 15 | * NOVA is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License version 2 for more details. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "compiler.hpp" 24 | #include "types.hpp" 25 | 26 | template static constexpr auto min (T v1, T v2) 27 | { 28 | return v1 < v2 ? v1 : v2; 29 | } 30 | 31 | template static constexpr auto max (T v1, T v2) 32 | { 33 | return v1 > v2 ? v1 : v2; 34 | } 35 | 36 | template static constexpr auto gcd (T v1, T v2) 37 | { 38 | while (v2) { 39 | T r { v1 % v2 }; 40 | v1 = v2; 41 | v2 = r; 42 | } 43 | 44 | return v1; 45 | } 46 | 47 | template static constexpr bool match_list (T const list[], T id) 48 | { 49 | for (auto ptr { list }; *ptr; ptr++) 50 | if (*ptr == id) 51 | return true; 52 | 53 | return false; 54 | } 55 | 56 | /* 57 | * Turns p into an "exposed" pointer. As a result, the standard allows 58 | * integers to be converted to pointers of the same provenance as p. 59 | */ 60 | template constexpr T *expose (T *p) noexcept 61 | { 62 | [[maybe_unused]] auto x { reinterpret_cast(p) }; 63 | return p; 64 | } 65 | -------------------------------------------------------------------------------- /inc/uuid.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Universally Unique Identifier (UUID) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "types.hpp" 21 | 22 | class Uuid final 23 | { 24 | private: 25 | uint64_t const uuid[2]; 26 | 27 | public: 28 | constexpr bool operator== (Uuid const &x) const 29 | { 30 | return uuid[0] == x.uuid[0] && uuid[1] == x.uuid[1]; 31 | } 32 | 33 | constexpr Uuid (uint32_t l, uint16_t m, uint16_t h, uint8_t const (&n)[8]) : uuid { uint64_t { h } << 48 | uint64_t { m } << 32 | l, uint64_t { n[7] } << 56 | uint64_t { n[6] } << 48 | uint64_t { n[5] } << 40 | uint64_t { n[4] } << 32 | uint32_t { n[3] } << 24 | uint32_t { n[2] } << 16 | uint16_t { n[1] } << 8 | n[0] } {} 34 | }; 35 | 36 | static_assert (__is_standard_layout (Uuid) && sizeof (Uuid) == 16); 37 | -------------------------------------------------------------------------------- /inc/wait.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Completion Wait 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "lowlevel.hpp" 21 | #include "timer.hpp" 22 | 23 | class Wait final 24 | { 25 | public: 26 | static auto until (uint32_t ms, auto const &func) 27 | { 28 | for (uint64_t const t { Stc::ms_to_ticks (ms) }, b { Timer::time() }; !func(); pause()) 29 | if (Timer::time() - b > t) [[unlikely]] 30 | return false; 31 | 32 | return true; 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /inc/x86_64/abi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Application Binary Interface: Architecture-Specific (x86) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "regs.hpp" 21 | 22 | class Sys_abi 23 | { 24 | private: 25 | Sys_regs &s; 26 | 27 | public: 28 | Sys_abi (Sys_regs &r) : s { r } {} 29 | 30 | auto &p0() const { return s.rdi; } 31 | auto &p1() const { return s.rsi; } 32 | auto &p2() const { return s.rdx; } 33 | auto const &p3() const { return s.rax; } 34 | auto const &p4() const { return s.r8; } 35 | 36 | ALWAYS_INLINE uint8_t flags() const { return p0() >> 4 & BIT_RANGE (3, 0); } 37 | }; 38 | -------------------------------------------------------------------------------- /inc/x86_64/acpi_table_hpet.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "acpi_table.hpp" 22 | 23 | /* 24 | * HPET Description Table (HPET) 25 | */ 26 | class Acpi_table_hpet final 27 | { 28 | private: 29 | Acpi_table table; // 0 30 | Unaligned_le cap; // 36 31 | Acpi_gas regs; // 40 32 | Unaligned_le uid; // 52 33 | Unaligned_le tick; // 53 34 | Unaligned_le attr; // 55 35 | 36 | public: 37 | void parse() const; 38 | }; 39 | 40 | static_assert (__is_standard_layout (Acpi_table_hpet) && alignof (Acpi_table_hpet) == 1 && sizeof (Acpi_table_hpet) == 56); 41 | -------------------------------------------------------------------------------- /inc/x86_64/bitmap_pio.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * PIO Bitmap 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "bitmap.hpp" 25 | #include "buddy.hpp" 26 | 27 | class Bitmap_pio final 28 | { 29 | public: 30 | static constexpr auto bits { BIT (16) }; 31 | 32 | static bool valid (size_t s) { return s < bits; } 33 | 34 | void clr (size_t s) { pio.clr (s); } 35 | void set (size_t s) { pio.set (s); } 36 | bool tst (size_t s) const { return pio.tst (s); } 37 | 38 | /* 39 | * Allocate PIO bitmap 40 | * 41 | * @return Pointer to the PIO bitmap (success) or nullptr (failure) 42 | */ 43 | [[nodiscard]] static void *operator new (size_t) noexcept { return Buddy::alloc (1); } 44 | 45 | /* 46 | * Deallocate PIO bitmap 47 | * 48 | * @param ptr Pointer to the PIO bitmap or nullptr 49 | */ 50 | static void operator delete (void *ptr) { Buddy::free (ptr); } 51 | 52 | private: 53 | Bitmap pio; 54 | }; 55 | 56 | // Sanity checks 57 | static_assert (sizeof (Bitmap_pio) == PAGE_SIZE (0) << 1); 58 | -------------------------------------------------------------------------------- /inc/x86_64/cache_guard.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Cache Guard 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "arch.hpp" 21 | #include "cache.hpp" 22 | #include "cr.hpp" 23 | 24 | class Cache_guard final 25 | { 26 | private: 27 | uintptr_t const cr0; 28 | 29 | public: 30 | Cache_guard() : cr0 { Cr::get_cr0() } 31 | { 32 | Cr::set_cr0 (cr0 | CR0_CD); // No-fill cache mode 33 | Cache::data_clean(); 34 | } 35 | 36 | ~Cache_guard() 37 | { 38 | Cache::data_clean(); 39 | Cr::set_cr0 (cr0); // Normal cache mode 40 | } 41 | 42 | Cache_guard (Cache_guard const &) = delete; 43 | Cache_guard& operator= (Cache_guard const &) = delete; 44 | }; 45 | -------------------------------------------------------------------------------- /inc/x86_64/cet.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Control-Flow Enforcement Technology (CET) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "compiler.hpp" 21 | #include "extern.hpp" 22 | #include "patch.hpp" 23 | #include "types.hpp" 24 | 25 | class Cet final 26 | { 27 | public: 28 | /* 29 | * Deactivate supervisor shadow stack by marking the token as not busy 30 | */ 31 | ALWAYS_INLINE 32 | static inline void sss_deactivate() 33 | { 34 | #if defined(__CET__) && (__CET__ & 2) 35 | #define ASM_CET_1 clrssbsy %0; 36 | asm volatile (EXPAND (PATCH (ASM_CET_1,,PATCH_CET_SSS)) : : "m" (DSHD_TOP)); 37 | #endif 38 | } 39 | 40 | /* 41 | * Unwind supervisor shadow stack up to the token 42 | */ 43 | ALWAYS_INLINE 44 | static inline void sss_unwind() 45 | { 46 | #if defined(__CET__) && (__CET__ & 2) 47 | uintptr_t ssp; 48 | #define ASM_CET_2 rdsspq %0; sub %0, %1; shr $3, %1; incsspq %1; 49 | asm volatile (EXPAND (PATCH (ASM_CET_2,,PATCH_CET_SSS)) : "=&r" (ssp) : "r" (&DSHD_TOP)); 50 | #endif 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /inc/x86_64/config.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Configuration 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #define NUM_CPU 256 25 | #define NUM_EXC 32 26 | #define NUM_VEC 256 27 | #define NUM_VMI 256 28 | -------------------------------------------------------------------------------- /inc/x86_64/console_uart_hsu.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: High-Speed UART (HSU) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "console_uart_ns16550.hpp" 21 | 22 | class Console_uart_hsu final : private Console_uart_ns16550 23 | { 24 | private: 25 | static Console_uart_hsu uart[]; 26 | 27 | static Regs probe (pci_t); 28 | 29 | protected: 30 | explicit Console_uart_hsu (pci_t pci) : Console_uart_ns16550 { probe (pci), 1'843'200 } {} 31 | }; 32 | -------------------------------------------------------------------------------- /inc/x86_64/console_uart_sio.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: Super I/O (SIO) UART 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "console_uart_ns16550.hpp" 21 | 22 | class Console_uart_sio final : private Console_uart_ns16550 23 | { 24 | private: 25 | static Console_uart_sio uart[]; 26 | 27 | static constexpr port_t pio[8] { 0x3f8, 0x2f8, 0x220, 0x228, 0x238, 0x2e8, 0x338, 0x3e8 }; 28 | 29 | // Work around broken firmware that decodes ComA and ComB to the same port 30 | static inline constinit Atomic decode {}; 31 | 32 | static int probe_isa (unsigned); 33 | static int probe_lpc (unsigned); 34 | 35 | static Regs probe (unsigned); 36 | 37 | protected: 38 | explicit Console_uart_sio (unsigned n) : Console_uart_ns16550 { probe (n), 1'843'200 } {} 39 | }; 40 | -------------------------------------------------------------------------------- /inc/x86_64/console_uart_sol.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: Serial-Over-LAN (SOL) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "console_uart_ns16550.hpp" 21 | 22 | class Console_uart_sol final : private Console_uart_ns16550 23 | { 24 | private: 25 | static Console_uart_sol uart[]; 26 | 27 | static Regs probe (pci_t); 28 | 29 | protected: 30 | explicit Console_uart_sol (pci_t pci) : Console_uart_ns16550 { probe (pci), 0 } {} 31 | }; 32 | -------------------------------------------------------------------------------- /inc/x86_64/counter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Event Counters 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "atomic.hpp" 25 | #include "kmem.hpp" 26 | #include "vectors.hpp" 27 | 28 | class Counter final 29 | { 30 | private: 31 | Atomic val { 0 }; 32 | 33 | public: 34 | static Counter req[NUM_IPI] CPULOCAL; 35 | static Counter loc[NUM_LVT] CPULOCAL; 36 | static Counter schedule CPULOCAL; 37 | static Counter helping CPULOCAL; 38 | 39 | ALWAYS_INLINE 40 | inline void inc() 41 | { 42 | val = val + 1; 43 | } 44 | 45 | ALWAYS_INLINE 46 | inline unsigned get (cpu_t cpu) const 47 | { 48 | return *Kmem::loc_to_glb (cpu, &val); 49 | } 50 | }; 51 | -------------------------------------------------------------------------------- /inc/x86_64/event.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Event Selectors 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | class Event final 21 | { 22 | public: 23 | enum Selector 24 | { 25 | NONE = -1, 26 | STARTUP = 0, 27 | RECALL = 1, 28 | }; 29 | 30 | static constexpr auto hst_arch { 32 }; 31 | static constexpr auto gst_arch { 256 }; 32 | 33 | static constexpr auto hst_max { 1 + RECALL }; 34 | static constexpr auto gst_max { 1 + RECALL }; 35 | }; 36 | -------------------------------------------------------------------------------- /inc/x86_64/extern.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * External Symbols 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "types.hpp" 25 | 26 | extern char GIT_VER, NOVA_HPAS, KMEM_HVAS, KMEM_HVAF, PTAB_HVAS, DSTK_TOP, DSHD_TOP, HASH_HEAD, MLE_TL, MLE_L2, __head_mle; 27 | extern void (*CTORS_S[])(), (*CTORS_E[])(), (*CTORS_C[])(), (*CTORS_L[])(); 28 | 29 | extern char entry_sys; 30 | extern char entry_vmx; 31 | extern uintptr_t handlers[]; 32 | -------------------------------------------------------------------------------- /inc/x86_64/gdt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Global Descriptor Table (GDT) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "descriptor.hpp" 25 | #include "selectors.hpp" 26 | 27 | class Gdt final 28 | { 29 | private: 30 | Descriptor_gdt_seg null; // 0x0 31 | Descriptor_gdt_seg kern_code; // 0x8 32 | Descriptor_gdt_seg kern_data; // 0x10 33 | Descriptor_gdt_seg user_data; // 0x18 34 | Descriptor_gdt_seg user_code; // 0x20 35 | Descriptor_gdt_seg unused; // 0x28 36 | Descriptor_gdt_sys tss_run; // 0x30 37 | 38 | public: 39 | static Gdt gdt CPULOCAL; 40 | 41 | static void build(); 42 | 43 | static void load() 44 | { 45 | Pseudo_descriptor const d { &gdt, sizeof (gdt) }; 46 | asm volatile ("lgdt %0" : : "m" (d)); 47 | } 48 | 49 | static void unbusy_tss() 50 | { 51 | gdt.tss_run.val[1] &= ~BIT (9); 52 | } 53 | }; 54 | 55 | static_assert (__is_standard_layout (Gdt) && sizeof (Gdt) == SEL_MAX); 56 | -------------------------------------------------------------------------------- /inc/x86_64/hip_arch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hypervisor Information Page (HIP): Architecture-Specific Part (x86) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "macros.hpp" 21 | #include "types.hpp" 22 | 23 | class Hip_arch final 24 | { 25 | private: 26 | uint64_t elog_phys; 27 | uint32_t elog_size; 28 | uint32_t elog_offs; 29 | 30 | public: 31 | enum class Feature : uint64_t 32 | { 33 | SMMU = BIT (0), 34 | VMX = BIT (1), 35 | SVM = BIT (2), 36 | }; 37 | 38 | void build(); 39 | }; 40 | 41 | static_assert (__is_standard_layout (Hip_arch) && sizeof (Hip_arch) == 16); 42 | -------------------------------------------------------------------------------- /inc/x86_64/hpet.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * High Precision Event Timer (HPET) 3 | * 4 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "list.hpp" 22 | #include "slab.hpp" 23 | 24 | class Hpet final : public List 25 | { 26 | private: 27 | uint8_t const id; // Enumeration ID 28 | pci_t pci { 0 }; // PCI S:B:D:F 29 | 30 | static Slab_cache cache; // HPET Slab Cache 31 | static inline constinit Hpet *list { nullptr }; // HPET List 32 | 33 | public: 34 | explicit Hpet (uint8_t i) : List { list }, id { i } {} 35 | 36 | static bool claim_dev (pci_t p, uint8_t i) 37 | { 38 | for (auto l { list }; l; l = l->next) 39 | if (l->pci == 0 && l->id == i) { 40 | l->pci = p; 41 | return true; 42 | } 43 | 44 | return false; 45 | } 46 | 47 | [[nodiscard]] static void *operator new (size_t) noexcept 48 | { 49 | return cache.alloc(); 50 | } 51 | }; 52 | -------------------------------------------------------------------------------- /inc/x86_64/idt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Interrupt Descriptor Table (IDT) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "descriptor.hpp" 25 | #include "vectors.hpp" 26 | 27 | class Idt final 28 | { 29 | public: 30 | static inline constinit ALIGNED(8) Descriptor_idt idt[NUM_VEC]; 31 | 32 | static void build(); 33 | 34 | static void load() 35 | { 36 | Pseudo_descriptor const d { idt, sizeof (idt) }; 37 | asm volatile ("lidt %0" : : "m" (d)); 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /inc/x86_64/integrity.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Integrity Measurement 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "tpm.hpp" 21 | #include "tpm_log.hpp" 22 | #include "txt.hpp" 23 | 24 | class Integrity final 25 | { 26 | private: 27 | static bool extend (unsigned pcr, Hash_sha1_160 const &sha1_160, Hash_sha2_256 const &sha2_256, Hash_sha2_384 const &sha2_384, Hash_sha2_512 const &sha2_512) 28 | { 29 | return Txt::launched && Tpm::extend (pcr, sha1_160, sha2_256, sha2_384, sha2_512) && Tpm_log::extend (pcr, sha1_160, sha2_256, sha2_384, sha2_512); 30 | } 31 | 32 | public: 33 | static inline constinit uint64_t root_phys { 0 }, root_size { 0 }; 34 | 35 | static bool measure(); 36 | }; 37 | -------------------------------------------------------------------------------- /inc/x86_64/intid.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Interrupt Identifier 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "types.hpp" 21 | 22 | class Intid 23 | { 24 | public: 25 | static constexpr auto to_seg (iid_t i) { return static_cast(i >> 16); } 26 | static constexpr auto to_gsi (iid_t i) { return static_cast(i); } 27 | }; 28 | -------------------------------------------------------------------------------- /inc/x86_64/io.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * I/O Ports 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 8 | * 9 | * This file is part of the NOVA microhypervisor. 10 | * 11 | * NOVA is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License version 2 as 13 | * published by the Free Software Foundation. 14 | * 15 | * NOVA is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License version 2 for more details. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "types.hpp" 24 | 25 | class Io final 26 | { 27 | public: 28 | template static auto in (port_t p) 29 | { 30 | T v; 31 | asm volatile ("in %w1, %0" : "=a" (v) : "Nd" (p)); 32 | return v; 33 | } 34 | 35 | template static void out (port_t p, T v) 36 | { 37 | asm volatile ("out %0, %w1" : : "a" (v), "Nd" (p)); 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /inc/x86_64/lowlevel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Low-Level Functions 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "compiler.hpp" 25 | 26 | static inline void pause() 27 | { 28 | __builtin_ia32_pause(); 29 | } 30 | 31 | [[noreturn]] static inline void shutdown() 32 | { 33 | for (;;) 34 | asm volatile ("cli; hlt"); 35 | } 36 | -------------------------------------------------------------------------------- /inc/x86_64/mca.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Machine-Check Architecture (MCA) 3 | * 4 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "compiler.hpp" 22 | #include "types.hpp" 23 | 24 | class Mca final 25 | { 26 | private: 27 | static inline constinit uint8_t banks CPULOCAL { 0 }; 28 | 29 | public: 30 | static void init(); 31 | static void handler(); 32 | }; 33 | -------------------------------------------------------------------------------- /inc/x86_64/mtrr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Memory Type Range Registers (MTRR) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "macros.hpp" 25 | #include "msr.hpp" 26 | 27 | class Mtrr final 28 | { 29 | public: 30 | static auto get_vcnt() { return static_cast(Msr::read (Msr::Reg64::IA32_MTRR_CAP) & BIT_RANGE (7, 0)); } 31 | 32 | static auto get_base (unsigned n) { return Msr::read (Msr::Arr64::IA32_MTRR_PHYS_BASE, 2, n); } 33 | static auto get_mask (unsigned n) { return Msr::read (Msr::Arr64::IA32_MTRR_PHYS_MASK, 2, n); } 34 | 35 | static void set_base (unsigned n, uint64_t v) { Msr::write (Msr::Arr64::IA32_MTRR_PHYS_BASE, 2, n, v); } 36 | static void set_mask (unsigned n, uint64_t v) { Msr::write (Msr::Arr64::IA32_MTRR_PHYS_MASK, 2, n, v); } 37 | 38 | static bool validate (unsigned n, uint64_t m) 39 | { 40 | for (unsigned i { 0 }; i < n; i++) 41 | if (get_mask (i) & m) 42 | return false; 43 | 44 | return true; 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /inc/x86_64/nmi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Non-Maskable Interrupt Handling 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | class Nmi final 21 | { 22 | public: 23 | static void handler() {} 24 | }; 25 | -------------------------------------------------------------------------------- /inc/x86_64/patch_arch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Instruction Patching: Architecture-Specific Part (x86) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #define NOP_LEN 1 21 | #define NOP_OPC 0x90 22 | 23 | #define PATCH_XSAVES 0 24 | #define PATCH_CET_IBT 1 25 | #define PATCH_CET_SSS 2 26 | -------------------------------------------------------------------------------- /inc/x86_64/pcid.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Process Context Identifier (PCID) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "atomic.hpp" 21 | #include "macros.hpp" 22 | #include "types.hpp" 23 | 24 | class Pcid final 25 | { 26 | private: 27 | uint16_t const val; 28 | 29 | static inline constinit Atomic allocator { 0 }; 30 | 31 | // FIXME: Handle overflow 32 | static auto alloc() 33 | { 34 | return allocator++; 35 | } 36 | 37 | public: 38 | Pcid() : val { alloc() } {} 39 | 40 | operator auto() const { return val & BIT_RANGE (11, 0); } 41 | }; 42 | -------------------------------------------------------------------------------- /inc/x86_64/pic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 8259A Programmable Interrupt Controller (PIC) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "io.hpp" 25 | #include "macros.hpp" 26 | #include "types.hpp" 27 | #include "vectors.hpp" 28 | 29 | class Pic final 30 | { 31 | friend class Acpi_table_madt; 32 | 33 | private: 34 | static inline constinit bool exists { false }; 35 | 36 | public: 37 | static void init() 38 | { 39 | if (!exists) 40 | return; 41 | 42 | Io::out(0x20, BIT (4) | BIT (0)); // ICW1: ICW4 needed 43 | Io::out(0x21, VEC_GSI); // ICW2: Interrupt vector base 44 | Io::out(0x21, BIT (2)); // ICW3: Slave on pin 2 45 | Io::out(0x21, BIT (0)); // ICW4: 8086 mode 46 | Io::out(0x21, BIT_RANGE (7, 0)); // OCW1: Mask everything 47 | } 48 | }; 49 | -------------------------------------------------------------------------------- /inc/x86_64/ptab_pte.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Page Table Entry (x86) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "ptab.hpp" 25 | 26 | template class Pte : public Ptab::Entry 27 | { 28 | using E = typename Ptab::Entry; 29 | 30 | public: 31 | auto type (unsigned l) const { return E::val ? l && !(E::val & T::ATTR_S) ? E::Type::PTAB : E::Type::LEAF : E::Type::HOLE; } 32 | 33 | static void publish() {} 34 | }; 35 | -------------------------------------------------------------------------------- /inc/x86_64/ptab_tmp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Page Table Templates 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "ptab_dpt.hpp" 21 | #include "ptab_ept.hpp" 22 | #include "ptab_hpt.hpp" 23 | 24 | template class Ptab; 25 | template class Ptab; 26 | template class Ptab; 27 | -------------------------------------------------------------------------------- /inc/x86_64/selectors.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Segment Selectors 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #define SEL_KERN_CODE 0x8 // IA32_STAR[47:32] + 0 25 | #define SEL_KERN_DATA 0x10 // IA32_STAR[47:32] + 8 26 | #define SEL_USER_DATA 0x1b // IA32_STAR[63:48] + 8 27 | #define SEL_USER_CODE 0x23 // IA32_STAR[63:48] + 16 28 | #define SEL_TSS_RUN 0x30 29 | #define SEL_MAX 0x40 30 | -------------------------------------------------------------------------------- /inc/x86_64/syscall_tmp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * System-Call Interface 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | template void Ec::send_msg (Ec *); 21 | template void Ec::send_msg (Ec *); 22 | template void Ec::send_msg (Ec *); 23 | -------------------------------------------------------------------------------- /inc/x86_64/timer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer: Architecture-Specific (x86) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "lapic.hpp" 21 | #include "stc.hpp" 22 | #include "timeout.hpp" 23 | 24 | class Timer final : private Stc 25 | { 26 | public: 27 | static auto time() 28 | { 29 | return Lapic::time(); 30 | } 31 | 32 | static void set_dln (uint64_t ticks) 33 | { 34 | Lapic::set_timer (ticks); 35 | } 36 | 37 | static void stop() {} 38 | 39 | static void set_time (uint64_t t) 40 | { 41 | Msr::write (Msr::Reg64::IA32_TSC, t); 42 | 43 | Timeout::sync(); 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /inc/x86_64/tlb.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Translation Lookaside Buffer (TLB) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | class Space; 25 | 26 | class Tlb final 27 | { 28 | public: 29 | static void shootdown (Space *); 30 | }; 31 | -------------------------------------------------------------------------------- /inc/x86_64/tss.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Task State Segment (TSS) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "compiler.hpp" 25 | #include "gdt.hpp" 26 | 27 | class Tss final 28 | { 29 | public: 30 | Unaligned_le res0; // 0 31 | Unaligned_le rsp[3]; // 4 32 | Unaligned_le ist[8]; // 28 33 | Unaligned_le res1; // 92 34 | Unaligned_le res2; // 100 35 | Unaligned_le iobm; // 102 36 | 37 | static Tss run asm ("tss_run") CPULOCAL; 38 | 39 | static void build(); 40 | 41 | static void load() 42 | { 43 | Gdt::unbusy_tss(); 44 | asm volatile ("ltr %w0" : : "rm" (SEL_TSS_RUN)); 45 | } 46 | }; 47 | 48 | static_assert (__is_standard_layout (Tss) && alignof (Tss) == 1 && sizeof (Tss) == 104); 49 | -------------------------------------------------------------------------------- /inc/x86_64/vectors.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Interrupt Vectors 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "config.hpp" 25 | 26 | #define NUM_FLT 1 27 | #define NUM_IPI 2 28 | #define NUM_LVT 5 29 | #define NUM_GSI (NUM_VEC - NUM_EXC - NUM_FLT - NUM_IPI - NUM_LVT) 30 | 31 | #define VEC_GSI NUM_EXC 32 | #define VEC_LVT (VEC_GSI + NUM_GSI) 33 | #define VEC_IPI (VEC_LVT + NUM_LVT) 34 | #define VEC_FLT (VEC_IPI + NUM_IPI) 35 | -------------------------------------------------------------------------------- /inc/x86_64/vpid.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Virtual Processor Identifier (VPID) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 8 | * 9 | * This file is part of the NOVA microhypervisor. 10 | * 11 | * NOVA is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License version 2 as 13 | * published by the Free Software Foundation. 14 | * 15 | * NOVA is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License version 2 for more details. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "atomic.hpp" 24 | #include "kmem.hpp" 25 | 26 | class Invvpid final 27 | { 28 | private: 29 | uint64_t const vpid; 30 | uint64_t const addr; 31 | 32 | public: 33 | enum Type 34 | { 35 | ADR = 0, // Individual address 36 | SGL = 1, // Single context 37 | ALL = 2, // All contexts 38 | SRG = 3, // Single context retaining globals 39 | }; 40 | 41 | Invvpid (uint16_t v, uint64_t a) : vpid { v }, addr { a } {} 42 | }; 43 | 44 | class Vpid final 45 | { 46 | private: 47 | static Atomic allocator CPULOCAL; 48 | 49 | public: 50 | // FIXME: Handle overflow 51 | static auto alloc (cpu_t cpu) 52 | { 53 | return ++*Kmem::loc_to_glb (cpu, &allocator); 54 | } 55 | 56 | static void invalidate (Invvpid::Type t, uint16_t vpid, uint64_t addr = 0) 57 | { 58 | Invvpid const v { vpid, addr }; 59 | asm volatile ("invvpid %0, %1" : : "m" (v), "r" (static_cast(t)) : "cc"); 60 | } 61 | }; 62 | -------------------------------------------------------------------------------- /src/aarch64/acpi_table_fadt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "acpi.hpp" 23 | #include "stdio.hpp" 24 | 25 | void Acpi_table_fadt::parse() const 26 | { 27 | Acpi::facs = facs64 ? facs64 : facs32; 28 | Acpi::fflg = fflg; 29 | 30 | trace (TRACE_FIRM, "ACPI: Version %u.%u Profile %u Features %#x Boot %#x", uint8_t { table.revision }, minor_version & BIT_RANGE (3, 0), uint8_t { pm_profile }, uint32_t { fflg }, uint16_t { bflg_arm }); 31 | 32 | if (bflg_arm & BIT (0)) 33 | Psci::init(); 34 | } 35 | -------------------------------------------------------------------------------- /src/aarch64/acpi_table_gtdt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi_table_gtdt.hpp" 19 | #include "intid.hpp" 20 | #include "timer.hpp" 21 | 22 | void Acpi_table_gtdt::parse() const 23 | { 24 | // Set timer PPI 25 | Timer::ppi_el2_p = Intid::to_ppi (el2_p_gsi); 26 | Timer::ppi_el1_v = Intid::to_ppi (el1_v_gsi); 27 | 28 | // Set timer trigger 29 | Timer::lvl_el2_p = !(el2_p_flg & BIT (0)); 30 | Timer::lvl_el1_v = !(el1_v_flg & BIT (0)); 31 | } 32 | -------------------------------------------------------------------------------- /src/aarch64/acpi_table_hest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi_table_hest.hpp" 19 | 20 | void Acpi_table_hest::parse() const {} 21 | -------------------------------------------------------------------------------- /src/aarch64/acpi_table_iort.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi_table_iort.hpp" 19 | #include "smmu_v3.hpp" 20 | 21 | void Acpi_table_iort::Node_smmu_v2::parse() const 22 | { 23 | } 24 | 25 | void Acpi_table_iort::Node_smmu_v3::parse() const 26 | { 27 | auto const smmu { Smmu_v3::setup (base, { intid_evt, intid_pri, intid_glb, intid_cmd }) }; 28 | 29 | if (!smmu) [[unlikely]] 30 | panic ("SMMU allocation failed"); 31 | } 32 | 33 | void Acpi_table_iort::parse() const 34 | { 35 | for (auto ptr { reinterpret_cast(this) + node_ofs }; ptr < reinterpret_cast(this) + table.header.length; ) { 36 | 37 | auto const n { reinterpret_cast(ptr) }; 38 | 39 | trace (TRACE_FIRM | TRACE_PARSE, "IORT: Node Type %u", std::to_underlying (n->type())); 40 | 41 | switch (n->type()) { 42 | case Node::Type::SMMU_V2: static_cast(n)->parse(); break; 43 | case Node::Type::SMMU_V3: static_cast(n)->parse(); break; 44 | default: break; 45 | } 46 | 47 | ptr += n->len; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/aarch64/acpi_table_srat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi_table_srat.hpp" 19 | #include "stdio.hpp" 20 | 21 | void Acpi_table_srat::Affinity_memory::parse() const 22 | { 23 | // Skip disabled entries 24 | if (!(flags & BIT (0))) [[unlikely]] 25 | return; 26 | 27 | trace (TRACE_FIRM, "SRAT: %#018lx-%018lx Dom %u", uint64_t { base }, base + size, uint32_t { pxd }); 28 | } 29 | 30 | void Acpi_table_srat::parse() const 31 | { 32 | for (auto ptr { reinterpret_cast(this + 1) }; ptr < reinterpret_cast(this) + table.header.length; ) { 33 | 34 | auto const a { reinterpret_cast(ptr) }; 35 | 36 | switch (a->type()) { 37 | case Affinity::Type::MEMORY: static_cast(a)->parse(); break; 38 | default: break; 39 | } 40 | 41 | ptr += a->length; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/aarch64/bootstrap.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Bootstrap Code 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi.hpp" 19 | #include "compiler.hpp" 20 | #include "cpu.hpp" 21 | #include "ec.hpp" 22 | #include "smmu.hpp" 23 | 24 | extern "C" [[noreturn]] 25 | void bootstrap (cpu_t c, unsigned e) 26 | { 27 | Cpu::init (c, e); 28 | 29 | // Before cores leave the barrier into userland, the SMMU must be active 30 | if (Cpu::bsp) 31 | if (!Smmu::initialize()) [[unlikely]] 32 | panic ("SMMU initialization failed"); 33 | 34 | // Before cores leave the barrier into userland, the idle EC must exist 35 | if (!Acpi::resume) 36 | Ec::create_idle(); 37 | 38 | // Barrier: wait for all CPUs to arrive here 39 | for (Cpu::online++; Cpu::online != Cpu::count; pause()) ; 40 | 41 | if (!Acpi::resume) 42 | if (Cpu::bsp) 43 | Ec::create_root(); 44 | 45 | Scheduler::schedule(); 46 | } 47 | -------------------------------------------------------------------------------- /src/aarch64/console_uart_cdns.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: Cadence (CDNS) UART 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "console_uart_cdns.hpp" 19 | 20 | INIT_PRIORITY (PRIO_CONSOLE) Console_uart_cdns Console_uart_cdns::singleton { (Board::uart.type == Debug::Subtype::SERIAL_CDNS) * Board::uart.mmio, Board::uart.clock }; 21 | -------------------------------------------------------------------------------- /src/aarch64/console_uart_imx.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: i.MX UART 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "console_uart_imx.hpp" 19 | 20 | INIT_PRIORITY (PRIO_CONSOLE) Console_uart_imx Console_uart_imx::singleton { (Board::uart.type == Debug::Subtype::SERIAL_IMX) * Board::uart.mmio, Board::uart.clock }; 21 | -------------------------------------------------------------------------------- /src/aarch64/console_uart_meson.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: Meson UART 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "console_uart_meson.hpp" 19 | 20 | INIT_PRIORITY (PRIO_CONSOLE) Console_uart_meson Console_uart_meson::singleton { (Board::uart.type == Debug::Subtype::SERIAL_MESON) * Board::uart.mmio, Board::uart.clock }; 21 | -------------------------------------------------------------------------------- /src/aarch64/console_uart_mini.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: Mini UART 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "console_uart_mini.hpp" 19 | 20 | INIT_PRIORITY (PRIO_CONSOLE) Console_uart_mini Console_uart_mini::singleton { (Board::uart.type == Debug::Subtype::SERIAL_BCM2835) * Board::uart.mmio, Board::uart.clock }; 21 | -------------------------------------------------------------------------------- /src/aarch64/console_uart_ns16550.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: NS16550 UART 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "console_uart_ns16550.hpp" 19 | 20 | INIT_PRIORITY (PRIO_CONSOLE) Console_uart_ns16550 Console_uart_ns16550::singleton { (Board::uart.type == Debug::Subtype::SERIAL_NS16550_DBGP) * Board::uart.mmio, Board::uart.clock }; 21 | -------------------------------------------------------------------------------- /src/aarch64/console_uart_pl011.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: PrimeCell UART (PL011) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "console_uart_pl011.hpp" 19 | 20 | INIT_PRIORITY (PRIO_CONSOLE) Console_uart_pl011 Console_uart_pl011::singleton { (Board::uart.type == Debug::Subtype::SERIAL_PL011) * Board::uart.mmio, Board::uart.clock }; 21 | -------------------------------------------------------------------------------- /src/aarch64/console_uart_scif.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: Serial Communication Interface with FIFO (SCIF) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "console_uart_scif.hpp" 19 | 20 | INIT_PRIORITY (PRIO_CONSOLE) Console_uart_scif Console_uart_scif::singleton { (Board::uart.type == Debug::Subtype::SERIAL_SCIF) * Board::uart.mmio, Board::uart.clock }; 21 | -------------------------------------------------------------------------------- /src/aarch64/counter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Event Counters 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "counter.hpp" 19 | 20 | Counter Counter::req[Intid::NUM_SGI]; 21 | Counter Counter::loc[Intid::NUM_PPI]; 22 | Counter Counter::schedule; 23 | Counter Counter::helping; 24 | -------------------------------------------------------------------------------- /src/aarch64/fpu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Floating Point Unit (FPU) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "ec.hpp" 19 | #include "fpu.hpp" 20 | 21 | void Fpu::fini() 22 | { 23 | Ec::switch_fpu (nullptr); 24 | } 25 | -------------------------------------------------------------------------------- /src/aarch64/hip_arch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hypervisor Information Page (HIP): Architecture-Specific Part (Arm) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "hip_arch.hpp" 19 | #include "smmu.hpp" 20 | 21 | void Hip_arch::build() 22 | { 23 | num_smg = Smmu::avail_smg(); 24 | num_ctx = Smmu::avail_ctx(); 25 | 26 | trace (TRACE_ROOT, "INFO: SMG#: %5u", num_smg); 27 | trace (TRACE_ROOT, "INFO: CTX#: %5u", num_ctx); 28 | } 29 | -------------------------------------------------------------------------------- /src/aarch64/init.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Initialization Code 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi.hpp" 19 | #include "cmdline.hpp" 20 | #include "console.hpp" 21 | #include "cpu.hpp" 22 | #include "extern.hpp" 23 | #include "fdt.hpp" 24 | #include "patch.hpp" 25 | #include "smmu.hpp" 26 | 27 | extern "C" uintptr_t kern_ptab_setup (cpu_t cpu) 28 | { 29 | return Cpu::remote_ptab (cpu); 30 | } 31 | 32 | extern "C" void preinit() 33 | { 34 | if (!Acpi::resume) 35 | Cmdline::init(); 36 | } 37 | 38 | extern "C" unsigned init() 39 | { 40 | if (Acpi::resume) { 41 | 42 | // Restart all cores 43 | for (cpu_t c { 0 }; c < Cpu::count; c++) 44 | Psci::boot_cpu (c, Cpu::remote_mpidr (c)); 45 | 46 | } else { 47 | 48 | Buddy::init(); 49 | 50 | for (auto func { CTORS_S }; func != CTORS_E; (*func++)()) ; 51 | 52 | for (auto func { CTORS_C }; func != CTORS_S; (*func++)()) ; 53 | 54 | // Now we're ready to talk to the world 55 | Console::print ("\nNOVA Microhypervisor #%07lx-%#x (%s): %s %s [%s]\n", reinterpret_cast(&GIT_VER), Patch::applied, ARCH, __DATE__, __TIME__, COMPILER_STRING); 56 | } 57 | 58 | Acpi::init() || Fdt::init(); 59 | 60 | Smmu::setup(); 61 | 62 | return Cpu::boot_cpu; 63 | } 64 | -------------------------------------------------------------------------------- /src/aarch64/ptab_npt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Nested Page Table (NPT) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "cpu.hpp" 19 | #include "ptab_npt.hpp" 20 | 21 | uint64_t Nptp::current; 22 | 23 | void Nptp::init() 24 | { 25 | // Reset at resume time to match vttbr 26 | current = 0; 27 | 28 | // OAS > 5 requires FEAT_LPA2 29 | auto const oas { min (Cpu::feature (Cpu::Mem_feature::PARANGE), uint8_t { 5 }) }; 30 | 31 | // IPA must not be larger than OAS supported by the CPU 32 | if (Npt::ibits > Npt::pas (oas)) [[unlikely]] 33 | panic ("Configured address-space size is too large"); 34 | 35 | asm volatile ("msr vtcr_el2, %x0; isb" : : "r" (VTCR_RES1 | oas << 16 | TCR_TG0_4K | TCR_SH0_INNER | TCR_ORGN0_WB_RW | TCR_IRGN0_WB_RW | (Npt::lev() - 2) << 6 | (64 - Npt::ibits)) : "memory"); 36 | } 37 | -------------------------------------------------------------------------------- /src/aarch64/smmu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * System Memory Management Unit 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "smmu.hpp" 19 | #include "smmu_v2.hpp" 20 | #include "smmu_v3.hpp" 21 | 22 | void Smmu::setup() 23 | { 24 | // SMMU already enumerated by firmware 25 | if (list) [[likely]] 26 | return; 27 | 28 | // SMMUv2 enumeration based on board 29 | for (unsigned i { 0 }; i < sizeof (Board::smmu_v2) / sizeof (*Board::smmu_v2); i++) 30 | if (Board::smmu_v2[i].mmio) 31 | new Smmu_v2 (Board::smmu_v2[i]); 32 | 33 | // SMMUv3 enumeration based on board 34 | for (unsigned i { 0 }; i < sizeof (Board::smmu_v3) / sizeof (*Board::smmu_v3); i++) 35 | if (Board::smmu_v3[i].mmio) 36 | (void) Smmu_v3::setup (Board::smmu_v3[i].mmio, { Board::smmu_v3[i].evt, Board::smmu_v3[i].pri, Board::smmu_v3[i].glb, Board::smmu_v3[i].cmd }); 37 | } 38 | -------------------------------------------------------------------------------- /src/aarch64/space_hst.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Host Memory Space 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "extern.hpp" 19 | #include "multiboot.hpp" 20 | #include "space_hst.hpp" 21 | #include "space_obj.hpp" 22 | 23 | INIT_PRIORITY (PRIO_SPACE_MEM) ALIGNED (Kobject::alignment) Space_hst Space_hst::nova; 24 | 25 | /* 26 | * Constructor (NOVA HST Space) 27 | */ 28 | Space_hst::Space_hst() : Space_mem { Kobject::Subtype::HST } 29 | { 30 | Space_obj::nova.insert (Space_obj::Selector::NOVA_HST, Capability { this, std::to_underlying (Capability::Perm_sp::TAKE) }); 31 | 32 | // Highest mappable PA 33 | constexpr uintptr_t max_addr { selectors << PAGE_BITS }; 34 | 35 | // Compute image addresses within mappable PA bounds 36 | auto const s { min (max_addr, Kmem::sym_to_phys (&NOVA_HPAS)) }; 37 | auto const e { min (max_addr, Multiboot::ea) }; 38 | 39 | access_ctrl (0, s, Paging::Permissions (Paging::U | Paging::API)); 40 | access_ctrl (e, max_addr - e, Paging::Permissions (Paging::U | Paging::API)); 41 | } 42 | -------------------------------------------------------------------------------- /src/aarch64/timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Generic Timer 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi.hpp" 19 | #include "interrupt.hpp" 20 | #include "stdio.hpp" 21 | #include "timeout.hpp" 22 | #include "timer.hpp" 23 | 24 | void Timer::init() 25 | { 26 | if (Cpu::bsp) { 27 | 28 | // Adjust system time 29 | if (Acpi::resume) 30 | offs = pct() - Acpi::resume; 31 | 32 | // Determine frequency of the system counter 33 | else 34 | asm volatile ("mrs %x0, cntfrq_el0" : "=r" (freq)); 35 | } 36 | 37 | if (!Acpi::resume) 38 | trace (TRACE_TIMR, "TIMR: EL2p:%u%c EL1v:%u%c %lu Hz", ppi_el2_p, lvl_el2_p ? 'L' : 'E', ppi_el1_v, lvl_el1_v ? 'L' : 'E', freq); 39 | 40 | // Configure EL1v timer interrupt 41 | Interrupt::configure (Intid::from_ppi (ppi_el1_v), lvl_el1_v, false, false); 42 | 43 | // Configure EL2p timer interrupt 44 | Interrupt::configure (Intid::from_ppi (ppi_el2_p), lvl_el2_p, false, false); 45 | 46 | // Enable EL2p timer 47 | asm volatile ("msr cnthp_ctl_el2, %x0" : : "rZ" (BIT64 (0))); 48 | 49 | // Start timeout infrastructure 50 | Timeout::sync(); 51 | } 52 | -------------------------------------------------------------------------------- /src/acpi_table_dbg2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi_table_dbg2.hpp" 19 | #include "stdio.hpp" 20 | 21 | void Acpi_table_dbg2::parse() const 22 | { 23 | for (auto ptr { reinterpret_cast(this) + info_off }; ptr < reinterpret_cast(this) + table.header.length; ) { 24 | 25 | auto const i { reinterpret_cast(ptr) }; 26 | auto const r { reinterpret_cast(ptr + i->regs_off) }; 27 | 28 | trace (TRACE_FIRM, "DBG2: Console %04x:%04x (%u:%#lx:%u:%u)", uint16_t { i->type }, uint16_t { i->subtype }, std::to_underlying (r->asid), uint64_t { r->addr }, uint8_t { r->bits }, uint8_t { r->accs }); 29 | 30 | Console::bind (Debug::Type { uint16_t { i->type } }, Debug::Subtype { uint16_t { i->subtype } }, *r); 31 | 32 | ptr += i->length; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/acpi_table_facs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi_table_facs.hpp" 19 | #include "stdio.hpp" 20 | 21 | void Acpi_table_facs::parse() const 22 | { 23 | if (header.length < sizeof (*this)) [[unlikely]] 24 | return; 25 | 26 | trace (TRACE_FIRM, "FACS: Hardware %#x Flags %#x Wake %#x/%#lx", uint32_t { hardware }, uint32_t { flags }, uint32_t { wake32 }, uint64_t { wake64 }); 27 | } 28 | -------------------------------------------------------------------------------- /src/acpi_table_mcfg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "acpi_table_mcfg.hpp" 23 | #include "pci.hpp" 24 | #include "stdio.hpp" 25 | #include "string.hpp" 26 | 27 | void Acpi_table_mcfg::Segment::parse (char const (&oem)[6], char const (&tbl)[8]) const 28 | { 29 | auto unusable { false }; 30 | 31 | // Ignore segments with broken ECAM 32 | for (unsigned i { 0 }; i < sizeof (quirk) / sizeof (*quirk); i++) 33 | if (!strncmp (quirk[i].oem, oem, sizeof (oem)) && !strncmp (quirk[i].tbl, tbl, sizeof (tbl)) && quirk[i].seg & BIT64 (seg)) 34 | unusable = true; 35 | 36 | if (unusable || !Pci::init_seg (phys_base, seg, sbn, ebn)) [[unlikely]] 37 | trace (TRACE_FIRM, "WARN: PCI Segment %#x unusable", uint16_t { seg }); 38 | } 39 | 40 | void Acpi_table_mcfg::parse() const 41 | { 42 | for (auto ptr { reinterpret_cast(this + 1) }; ptr < reinterpret_cast(this) + table.header.length; ptr += sizeof (Segment)) 43 | reinterpret_cast(ptr)->parse (table.oem_id, table.oem_table_id); 44 | } 45 | -------------------------------------------------------------------------------- /src/acpi_table_spcr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi_table_spcr.hpp" 19 | #include "stdio.hpp" 20 | 21 | void Acpi_table_spcr::parse() const 22 | { 23 | trace (TRACE_FIRM, "SPCR: Console %04x:%04x (%u:%#lx:%u:%u)", std::to_underlying (Debug::Type::SERIAL), uint16_t { subtype }, std::to_underlying (regs.asid), uint64_t { regs.addr }, uint8_t { regs.bits }, uint8_t { regs.accs }); 24 | 25 | Console::bind (Debug::Type::SERIAL, Debug::Subtype { uint16_t { subtype } }, regs); 26 | } 27 | -------------------------------------------------------------------------------- /src/acpi_table_tpm2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "acpi_table_tpm2.hpp" 19 | #include "stdio.hpp" 20 | 21 | void Acpi_table_tpm2::parse() const 22 | { 23 | trace (TRACE_FIRM, "TPM2: TPM at %#lx (%u)", uint64_t { tpm_base }, uint32_t { start_method }); 24 | } 25 | -------------------------------------------------------------------------------- /src/acpi_table_xsdt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "acpi_table_xsdt.hpp" 23 | 24 | void Acpi_table_xsdt::parse() const 25 | { 26 | size_t const s { table.header.signature == Signature::u32 ("XSDT") ? sizeof (uint64_t) : sizeof (uint32_t) }; 27 | 28 | for (auto ptr { reinterpret_cast(this + 1) }; ptr < reinterpret_cast(this) + table.header.length; ptr += s) 29 | Acpi_table::consume (s == sizeof (uint64_t) ? *reinterpret_cast const *>(ptr) : *reinterpret_cast const *>(ptr)); 30 | } 31 | -------------------------------------------------------------------------------- /src/cache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Cache Maintenance 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "cache.hpp" 19 | 20 | unsigned Cache::dcache_line_size { 0 }; 21 | unsigned Cache::icache_line_size { 0 }; 22 | -------------------------------------------------------------------------------- /src/cmdline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Command Line Parser 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2014 Udo Steinberg, FireEye, Inc. 9 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 10 | * 11 | * This file is part of the NOVA microhypervisor. 12 | * 13 | * NOVA is free software: you can redistribute it and/or modify it 14 | * under the terms of the GNU General Public License version 2 as 15 | * published by the Free Software Foundation. 16 | * 17 | * NOVA is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License version 2 for more details. 21 | */ 22 | 23 | #include "cmdline.hpp" 24 | #include "multiboot.hpp" 25 | #include "ptab_hpt.hpp" 26 | #include "string.hpp" 27 | 28 | size_t Cmdline::arg_len (char const *&line) 29 | { 30 | for (; *line == ' '; line++) ; 31 | 32 | char const *p; 33 | 34 | for (p = line; *p && *p != ' '; p++) ; 35 | 36 | return static_cast(p - line); 37 | } 38 | 39 | void Cmdline::parse (char const *line) 40 | { 41 | for (size_t len; (len = arg_len (line)); line += len) 42 | for (unsigned i { 0 }; i < sizeof (options) / sizeof (*options); i++) 43 | if (!strncmp (options[i].str, line, len)) 44 | options[i].var = true; 45 | } 46 | 47 | void Cmdline::init() 48 | { 49 | if (Multiboot::cl) 50 | parse (static_cast(Hptp::map (MMAP_GLB_MAP0, Multiboot::cl))); 51 | } 52 | -------------------------------------------------------------------------------- /src/head_mbi.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Multiboot Headers 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "macros.hpp" 23 | #include "multiboot.hpp" 24 | 25 | .section .head 26 | .balign 8 27 | 28 | .Lmb2: .long MULTIBOOT_V2_HEADER 29 | .long 0 30 | .long .Lmb1 - .Lmb2 31 | .long -(.Lmb1 - .Lmb2) - MULTIBOOT_V2_HEADER 32 | .quad 0x0000000800000006 33 | .quad 0x0000000800000007 34 | .quad 0x000000180000000a 35 | .quad 0xffffffff00200000 36 | .quad 0x0000000200200000 37 | .quad 0x0000000800000000 38 | 39 | .Lmb1: .long MULTIBOOT_V1_HEADER 40 | .long BIT (0) 41 | .long -BIT (0) - MULTIBOOT_V1_HEADER 42 | -------------------------------------------------------------------------------- /src/integrity.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Integrity Measurement 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "integrity.hpp" 19 | #include "ptab_hpt.hpp" 20 | 21 | bool Integrity::measure() 22 | { 23 | constexpr auto chunk_size { Hpt::page_size (Hpt::bpl) }; 24 | 25 | Hash_sha1_160 sha1_160; 26 | Hash_sha2_256 sha2_256; 27 | Hash_sha2_384 sha2_384; 28 | Hash_sha2_512 sha2_512; 29 | 30 | // Even for size 0 the loop must execute once to yield a valid digest 31 | for (uint64_t p { root_phys }, s { root_size };; p += chunk_size) { 32 | 33 | auto const ptr { static_cast(Hptp::map (MMAP_GLB_MAP0, p)) }; 34 | auto const len { min (s, chunk_size) }; 35 | s -= len; 36 | 37 | sha1_160.update (ptr, len, s); 38 | sha2_256.update (ptr, len, s); 39 | sha2_384.update (ptr, len, s); 40 | sha2_512.update (ptr, len, s); 41 | 42 | if (!s) 43 | break; 44 | } 45 | 46 | return extend (19, sha1_160, sha2_256, sha2_384, sha2_512); 47 | } 48 | -------------------------------------------------------------------------------- /src/pt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Portal (PT) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "ec.hpp" 23 | #include "pt.hpp" 24 | #include "stdio.hpp" 25 | 26 | INIT_PRIORITY (PRIO_SLAB) Slab_cache Pt::cache { sizeof (Pt), Kobject::alignment }; 27 | 28 | Pt::Pt (Refptr &e, uintptr_t i) : Kobject { Kobject::Type::PT }, ec { std::move (e) }, ip { i } 29 | { 30 | trace (TRACE_CREATE, "PT:%p created (EC:%p IP:%#lx)", static_cast(this), static_cast(ec), ip); 31 | } 32 | -------------------------------------------------------------------------------- /src/sc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Scheduling Context (SC) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2014 Udo Steinberg, FireEye, Inc. 9 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 10 | * 11 | * This file is part of the NOVA microhypervisor. 12 | * 13 | * NOVA is free software: you can redistribute it and/or modify it 14 | * under the terms of the GNU General Public License version 2 as 15 | * published by the Free Software Foundation. 16 | * 17 | * NOVA is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License version 2 for more details. 21 | */ 22 | 23 | #include "ec.hpp" 24 | #include "stc.hpp" 25 | #include "stdio.hpp" 26 | 27 | INIT_PRIORITY (PRIO_SLAB) Slab_cache Sc::cache { sizeof (Sc), Kobject::alignment }; 28 | 29 | Sc::Sc (Refptr &e, cpu_t n, uint16_t b, uint8_t p, cos_t c) : Kobject { Kobject::Type::SC }, ec { std::move (e) }, budget { Stc::ms_to_ticks (b) }, cpu { n }, cos { c }, prio { p } 30 | { 31 | trace (TRACE_CREATE, "SC:%p created (EC:%p CPU:%u Budget:%ums Prio:%u COS:%u)", static_cast(this), static_cast(ec), cpu, b, p, c); 32 | } 33 | -------------------------------------------------------------------------------- /src/sm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Semaphore (SM) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "sm.hpp" 23 | #include "stdio.hpp" 24 | 25 | INIT_PRIORITY (PRIO_SLAB) Slab_cache Sm::cache { sizeof (Sm), Kobject::alignment }; 26 | 27 | Sm::Sm (uintptr_t v, void *p) : Kobject { Kobject::Type::SM, p ? Kobject::Subtype::SM_INT : Kobject::Subtype::SM_REG }, cnt { p ? 0 : v }, ptr { p }, iid { static_cast(p ? v : 0) } 28 | { 29 | trace (TRACE_CREATE, "SM:%p created (%s:%#lx)", static_cast(this), p ? "GSI" : "CNT", v); 30 | } 31 | -------------------------------------------------------------------------------- /src/string.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * String Functions 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #define inline 20 | #include "string.hpp" 21 | -------------------------------------------------------------------------------- /src/timeout_budget.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Budget Timeout 3 | * 4 | * Copyright (C) 2014 Udo Steinberg, FireEye, Inc. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #include "cpu.hpp" 20 | #include "hazard.hpp" 21 | #include "initprio.hpp" 22 | #include "rcu.hpp" 23 | #include "timeout_budget.hpp" 24 | 25 | INIT_PRIORITY (PRIO_LOCAL) Timeout_budget Timeout_budget::timeout; 26 | 27 | void Timeout_budget::trigger() 28 | { 29 | Cpu::hazard |= Hazard::SCHED; 30 | 31 | Rcu::check(); 32 | } 33 | -------------------------------------------------------------------------------- /src/timeout_hypercall.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hypercall Timeout 3 | * 4 | * Copyright (C) 2014 Udo Steinberg, FireEye, Inc. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #include "sm.hpp" 20 | #include "timeout_hypercall.hpp" 21 | 22 | void Timeout_hypercall::trigger() 23 | { 24 | sm->timeout (ec); 25 | } 26 | -------------------------------------------------------------------------------- /src/x86_64/acpi_table_hpet.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #include "acpi_table_hpet.hpp" 20 | #include "hpet.hpp" 21 | #include "stdio.hpp" 22 | 23 | void Acpi_table_hpet::parse() const 24 | { 25 | if (regs.asid != Acpi_gas::Asid::MEM) [[unlikely]] 26 | return; 27 | 28 | auto const hpet { new Hpet { uid } }; 29 | if (!hpet) [[unlikely]] 30 | panic ("HPET allocation failed"); 31 | 32 | trace (TRACE_FIRM, "HPET: %#010lx", uint64_t { regs.addr }); 33 | } 34 | -------------------------------------------------------------------------------- /src/x86_64/acpi_table_lpit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Configuration and Power Interface (ACPI) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 8 | * 9 | * This file is part of the NOVA microhypervisor. 10 | * 11 | * NOVA is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License version 2 as 13 | * published by the Free Software Foundation. 14 | * 15 | * NOVA is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License version 2 for more details. 19 | */ 20 | 21 | #include "acpi_table_lpit.hpp" 22 | #include "stdio.hpp" 23 | 24 | void Acpi_table_lpit::Descriptor_native::parse() const 25 | { 26 | if (flags & BIT (0)) 27 | return; 28 | 29 | trace (TRACE_FIRM | TRACE_PARSE, "LPIT: Trigger:%#x/%#lx+%u/%u Counter:%#x/%#lx+%u/%u Residency:%uus Latency:%uus", 30 | static_cast(trigger.asid), uint64_t { trigger.addr }, uint8_t { trigger.offs }, uint8_t { trigger.bits }, 31 | static_cast(counter.asid), uint64_t { counter.addr }, uint8_t { counter.offs }, uint8_t { counter.bits }, 32 | uint32_t { min_residency }, uint32_t { max_latency }); 33 | } 34 | 35 | void Acpi_table_lpit::parse() const 36 | { 37 | for (auto ptr { reinterpret_cast(this + 1) }; ptr < reinterpret_cast(this) + table.header.length; ) { 38 | 39 | auto const d { reinterpret_cast(ptr) }; 40 | 41 | switch (d->type()) { 42 | case Descriptor::Type::NATIVE: static_cast(d)->parse(); break; 43 | default: break; 44 | } 45 | 46 | ptr += d->length; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/x86_64/bootstrap.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Bootstrap Code 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "acpi.hpp" 23 | #include "compiler.hpp" 24 | #include "ec.hpp" 25 | #include "timer.hpp" 26 | 27 | extern "C" [[noreturn]] void bootstrap() 28 | { 29 | Cpu::init(); 30 | 31 | // Before cores leave the barrier into userland, the idle EC must exist 32 | if (!Acpi::resume) 33 | Ec::create_idle(); 34 | 35 | // Barrier: wait for all CPUs to arrive here 36 | for (Cpu::online++; Cpu::online != Cpu::count; pause()) ; 37 | 38 | if (Acpi::resume) 39 | Timer::set_time (Acpi::resume); 40 | 41 | else if (Cpu::bsp) 42 | Ec::create_root(); 43 | 44 | if (Cpu::bsp) 45 | Acpi::wake_restore(); 46 | 47 | Scheduler::schedule(); 48 | } 49 | -------------------------------------------------------------------------------- /src/x86_64/console_uart_apb.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: Advanced Peripheral Bus (APB) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "console_uart_apb.hpp" 19 | 20 | INIT_PRIORITY (PRIO_CONSOLE) Console_uart_apb Console_uart_apb::uart[] { Console_uart_apb { pci0, did0 }, 21 | Console_uart_apb { pci1, did1 }, 22 | Console_uart_apb { pci2, did2 } }; 23 | 24 | Console_uart_apb::Regs Console_uart_apb::probe (pci_t const pci[], uint16_t const did[]) 25 | { 26 | Regs regs; 27 | 28 | for (auto ptr { pci }; *ptr; ptr++) { 29 | 30 | auto const didvid { Pci_arch::read (*ptr, Pci::Cfg::Reg32::DID_VID) }; 31 | 32 | if (static_cast(didvid) == 0x8086 && match_list (did, static_cast(didvid >> 16))) { 33 | 34 | regs.mem = static_cast(Pci_arch::read (*ptr, Pci::Cfg::Reg32::BAR_1)) << 32 | (Pci_arch::read (*ptr, Pci::Cfg::Reg32::BAR_0) & BIT_RANGE (31, 12)); 35 | regs.shl = 2; 36 | 37 | Pci_arch::rd_wr (*ptr, Pci::Cfg::Reg16::CMD, !!regs.mem * BIT (1)); 38 | 39 | break; 40 | } 41 | } 42 | 43 | return regs; 44 | } 45 | -------------------------------------------------------------------------------- /src/x86_64/console_uart_hsu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: High-Speed UART (HSU) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "console_uart_hsu.hpp" 19 | #include "pci_arch.hpp" 20 | 21 | INIT_PRIORITY (PRIO_CONSOLE) Console_uart_hsu Console_uart_hsu::uart[] { Console_uart_hsu { Pci::pci (0, 26, 0) }, 22 | Console_uart_hsu { Pci::pci (0, 26, 1) }, 23 | Console_uart_hsu { Pci::pci (0, 26, 2) } }; 24 | 25 | Console_uart_hsu::Regs Console_uart_hsu::probe (pci_t pci) 26 | { 27 | Regs regs; 28 | 29 | // Probe for Intel 16550-Compatible Serial Controller 30 | if (static_cast(Pci_arch::read (pci, Pci::Cfg::Reg32::DID_VID)) == 0x8086 && Pci_arch::read (pci, Pci::Cfg::Reg32::CCP_RID) >> 8 == 0x70002) { 31 | 32 | regs.mem = Pci_arch::read (pci, Pci::Cfg::Reg32::BAR_1) & BIT_RANGE (31, 8); 33 | regs.pio = Pci_arch::read (pci, Pci::Cfg::Reg32::BAR_0) & BIT_RANGE (15, 3); 34 | 35 | Pci_arch::rd_wr (pci, Pci::Cfg::Reg16::CMD, !!regs.mem * BIT (1) | !!regs.pio * BIT (0)); 36 | } 37 | 38 | return regs; 39 | } 40 | -------------------------------------------------------------------------------- /src/x86_64/console_uart_sol.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Console: Serial-Over-LAN (SOL) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "console_uart_sol.hpp" 19 | #include "pci_arch.hpp" 20 | 21 | INIT_PRIORITY (PRIO_CONSOLE) Console_uart_sol Console_uart_sol::uart[] { Console_uart_sol { Pci::pci (0, 22, 3) } }; 22 | 23 | Console_uart_sol::Regs Console_uart_sol::probe (pci_t pci) 24 | { 25 | Regs regs; 26 | 27 | // Probe for Intel 16550-Compatible Serial Controller 28 | if (static_cast(Pci_arch::read (pci, Pci::Cfg::Reg32::DID_VID)) == 0x8086 && Pci_arch::read (pci, Pci::Cfg::Reg32::CCP_RID) >> 8 == 0x70002) { 29 | 30 | regs.mem = Pci_arch::read (pci, Pci::Cfg::Reg32::BAR_1) & BIT_RANGE (31, 12); 31 | regs.pio = Pci_arch::read (pci, Pci::Cfg::Reg32::BAR_0) & BIT_RANGE (15, 3); 32 | 33 | Pci_arch::rd_wr (pci, Pci::Cfg::Reg16::CMD, !!regs.mem * BIT (1) | !!regs.pio * BIT (0)); 34 | } 35 | 36 | return regs; 37 | } 38 | -------------------------------------------------------------------------------- /src/x86_64/counter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Event Counters 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "counter.hpp" 23 | 24 | Counter Counter::req[NUM_IPI]; 25 | Counter Counter::loc[NUM_LVT]; 26 | Counter Counter::schedule; 27 | Counter Counter::helping; 28 | -------------------------------------------------------------------------------- /src/x86_64/gdt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Global Descriptor Table (GDT) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "gdt.hpp" 23 | #include "memory.hpp" 24 | #include "tss.hpp" 25 | 26 | ALIGNED(8) Gdt Gdt::gdt; 27 | 28 | void Gdt::build() 29 | { 30 | gdt.kern_code = Descriptor_gdt_seg { Descriptor_gdt_seg::Type::CODE_XRA, 0 }; 31 | gdt.kern_data = Descriptor_gdt_seg { Descriptor_gdt_seg::Type::DATA_RWA, 0 }; 32 | gdt.user_data = Descriptor_gdt_seg { Descriptor_gdt_seg::Type::DATA_RWA, 3 }; 33 | gdt.user_code = Descriptor_gdt_seg { Descriptor_gdt_seg::Type::CODE_XRA, 3 }; 34 | 35 | gdt.tss_run = Descriptor_gdt_sys { Descriptor_gdt_sys::Type::SYS_TSS, reinterpret_cast(&Tss::run), static_cast(MMAP_SPC_PIO_E - reinterpret_cast(&Tss::run)) }; 36 | } 37 | -------------------------------------------------------------------------------- /src/x86_64/head_mle.S: -------------------------------------------------------------------------------- 1 | /* 2 | * MLE Header 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "macros.hpp" 19 | 20 | .global __head_mle 21 | 22 | .section .head 23 | .balign 8 24 | 25 | __head_mle: .octa 0x42b651cba2555c0f74a7476f9082ac5a // 0 UUID 26 | .long .Lhead_mle - __head_mle // 16 Length 27 | .long 0x20003 // 20 Version 28 | .long HASH_INIT // 24 ILP Entry 29 | .long 0 // 28 First Page 30 | .long 0 // 32 MLE Start 31 | .long HASH_SIZE // 36 MLE End 32 | .long BIT_RANGE (10, 0) // 40 MLE Caps 33 | .long 0 // 44 Cmd Start 34 | .long 0 // 48 Cmd End 35 | .Lhead_mle: 36 | -------------------------------------------------------------------------------- /src/x86_64/hip_arch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hypervisor Information Page (HIP): Architecture-Specific Part (x86) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "hip_arch.hpp" 19 | #include "tpm_log.hpp" 20 | 21 | void Hip_arch::build() 22 | { 23 | elog_phys = Tpm_log::phys; 24 | elog_size = Tpm_log::size; 25 | elog_offs = Tpm_log::offs; 26 | } 27 | -------------------------------------------------------------------------------- /src/x86_64/hpet.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * High Precision Event Timer (HPET) 3 | * 4 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 5 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 6 | * 7 | * This file is part of the NOVA microhypervisor. 8 | * 9 | * NOVA is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation. 12 | * 13 | * NOVA is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License version 2 for more details. 17 | */ 18 | 19 | #include "hpet.hpp" 20 | 21 | INIT_PRIORITY (PRIO_SLAB) Slab_cache Hpet::cache { sizeof (Hpet), alignof (Hpet) }; 22 | -------------------------------------------------------------------------------- /src/x86_64/idt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Interrupt Descriptor Table (IDT) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "arch.hpp" 23 | #include "extern.hpp" 24 | #include "idt.hpp" 25 | #include "selectors.hpp" 26 | 27 | void Idt::build() 28 | { 29 | uintptr_t *ptr { handlers }; 30 | 31 | for (unsigned vector { 0 }; vector < sizeof (idt) / sizeof (*idt); vector++, ptr++) 32 | idt[vector] = Descriptor_idt { *ptr & IDT_USER ? 3U : 0U, *ptr & IDT_IST1 ? 1U : 0U, SEL_KERN_CODE, *ptr & ~IDT_MASK }; 33 | } 34 | -------------------------------------------------------------------------------- /src/x86_64/ioapic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * I/O Advanced Programmable Interrupt Controller (IOAPIC) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "ioapic.hpp" 23 | #include "space_hst.hpp" 24 | #include "stdio.hpp" 25 | 26 | INIT_PRIORITY (PRIO_SLAB) Slab_cache Ioapic::cache { sizeof (Ioapic), alignof (Ioapic) }; 27 | 28 | void Ioapic::init() 29 | { 30 | trace (TRACE_INTR, "APIC: I/O:%#04x VER:%#x GSI:%#04x-%#04x (%04x:%02x:%02x.%x)", id, ver(), gsi_base, gsi_last, Pci::seg (pci), Pci::bus (pci), Pci::dev (pci), Pci::fun (pci)); 31 | 32 | // Mask all entries 33 | for (auto i { gsi_base }; i <= gsi_last; i++) 34 | set_cfg (i); 35 | } 36 | -------------------------------------------------------------------------------- /src/x86_64/sgx.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Software Guard Extensions (SGX) 3 | * 4 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 5 | * 6 | * This file is part of the NOVA microhypervisor. 7 | * 8 | * NOVA is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2 as 10 | * published by the Free Software Foundation. 11 | * 12 | * NOVA is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License version 2 for more details. 16 | */ 17 | 18 | #include "cpu.hpp" 19 | #include "sgx.hpp" 20 | #include "stdio.hpp" 21 | 22 | Sgx::State Sgx::current, Sgx::initial; 23 | uint32_t Sgx::features { 0 }; 24 | bool Sgx::writable { false }; 25 | 26 | void Sgx::init() 27 | { 28 | // Abort if SGX is not supported 29 | if (!Cpu::feature (Cpu::Feature::SGX)) [[unlikely]] 30 | return; 31 | 32 | auto const ctrl { Msr::read (Msr::Reg64::IA32_FEATURE_CONTROL) }; 33 | 34 | // Abort if firmware has opted out of SGX 35 | if ((ctrl & ctrl_sgx) != ctrl_sgx) [[unlikely]] 36 | return; 37 | 38 | trace (TRACE_CPU, "ENCL: Features:%#x%s%s%s", features, Cpu::feature (Cpu::Feature::SGX_LC) ? " FLC" : "", feature (Feature::SGX2) ? " SGX2" : "", feature (Feature::SGX1) ? " SGX1" : ""); 39 | 40 | // Abort if SGX1 functions are not available 41 | if (!feature (Feature::SGX1)) [[unlikely]] 42 | return; 43 | 44 | // Check if SGX launch control is available 45 | if (Cpu::feature (Cpu::Feature::SGX_LC)) [[likely]] { 46 | 47 | // Obtain initial state 48 | State::init(); 49 | 50 | // IA32_SGXLEPUBKEYHASH is writable if firmware has enabled FLC 51 | writable = (ctrl & ctrl_flc) == ctrl_flc; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/x86_64/space_dma.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DMA Memory Space 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "space_dma.hpp" 23 | 24 | INIT_PRIORITY (PRIO_SPACE_MEM) ALIGNED (Kobject::alignment) Space_dma Space_dma::nova; 25 | -------------------------------------------------------------------------------- /src/x86_64/svm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Secure Virtual Machine (SVM) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2014 Udo Steinberg, FireEye, Inc. 9 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 10 | * 11 | * This file is part of the NOVA microhypervisor. 12 | * 13 | * NOVA is free software: you can redistribute it and/or modify it 14 | * under the terms of the GNU General Public License version 2 as 15 | * published by the Free Software Foundation. 16 | * 17 | * NOVA is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License version 2 for more details. 21 | */ 22 | 23 | #include "arch.hpp" 24 | #include "cmdline.hpp" 25 | #include "cpu.hpp" 26 | #include "hip.hpp" 27 | #include "msr.hpp" 28 | #include "stdio.hpp" 29 | #include "svm.hpp" 30 | 31 | uint64_t Vmcb::root; 32 | unsigned Vmcb::asid_ctr; 33 | uint32_t Vmcb::svm_version; 34 | uint32_t Vmcb::svm_feature; 35 | 36 | Vmcb::Vmcb (uintptr_t bmp, uintptr_t nptp) : base_io (bmp), asid (++asid_ctr), int_control (1ul << 24), npt_cr3 (nptp), efer (EFER_SVME), g_pat (0x7040600070406ull) 37 | { 38 | base_msr = Kmem::ptr_to_phys (Buddy::alloc (1, Buddy::Fill::BITS1)); 39 | assert (base_msr); 40 | } 41 | 42 | void Vmcb::init() 43 | { 44 | if (!Cpu::feature (Cpu::Feature::SVM)) 45 | return; 46 | 47 | Msr::write (Msr::Reg64::IA32_EFER, Msr::read (Msr::Reg64::IA32_EFER) | EFER_SVME); 48 | Msr::write (Msr::Reg64::AMD_SVM_HSAVE_PA, root = Kmem::ptr_to_phys (new Vmcb)); 49 | 50 | trace (TRACE_VIRT, "VIRT: SVM:%#x NPT:%u", svm_version, has_npt()); 51 | 52 | Hip::set_feature (Hip_arch::Feature::SVM); 53 | } 54 | -------------------------------------------------------------------------------- /src/x86_64/tlb.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Translation Lookaside Buffer (TLB) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "counter.hpp" 23 | #include "ec.hpp" 24 | #include "interrupt.hpp" 25 | #include "space_gst.hpp" 26 | #include "space_hst.hpp" 27 | #include "stc.hpp" 28 | #include "stdio.hpp" 29 | #include "tlb.hpp" 30 | #include "wait.hpp" 31 | 32 | void Tlb::shootdown (Space *s) 33 | { 34 | Cpu::preemption_enable(); 35 | 36 | for (cpu_t cpu { 0 }; cpu < Cpu::count; cpu++) { 37 | 38 | auto const ec { Ec::remote_current (cpu) }; 39 | 40 | if (ec->regs.get_hst() != s && ec->regs.get_gst() != s) 41 | continue; 42 | 43 | if (Cpu::id == cpu) { 44 | Cpu::hazard |= Hazard::SCHED; 45 | continue; 46 | } 47 | 48 | auto const c { Counter::req[Interrupt::Request::RKE].get (cpu) }; 49 | 50 | Interrupt::send_cpu (Interrupt::Request::RKE, cpu); 51 | 52 | Wait::until (1, [&] { return Counter::req[Interrupt::Request::RKE].get (cpu) != c; }); 53 | } 54 | 55 | Cpu::preemption_disable(); 56 | } 57 | -------------------------------------------------------------------------------- /src/x86_64/tss.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Task State Segment (TSS) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2012-2013 Udo Steinberg, Intel Corporation. 8 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 9 | * 10 | * This file is part of the NOVA microhypervisor. 11 | * 12 | * NOVA is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2 as 14 | * published by the Free Software Foundation. 15 | * 16 | * NOVA is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License version 2 for more details. 20 | */ 21 | 22 | #include "memory.hpp" 23 | #include "tss.hpp" 24 | 25 | ALIGNED(8) Tss Tss::run; 26 | 27 | void Tss::build() 28 | { 29 | run.ist[1] = MMAP_CPU_ISTT; 30 | run.iobm = static_cast(MMAP_SPC_PIO - reinterpret_cast(&run)); 31 | } 32 | -------------------------------------------------------------------------------- /src/x86_64/vpid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Virtual Processor Identifier (VPID) 3 | * 4 | * Copyright (C) 2009-2011 Udo Steinberg 5 | * Economic rights: Technische Universitaet Dresden (Germany) 6 | * 7 | * Copyright (C) 2019-2025 Udo Steinberg, BlueRock Security, Inc. 8 | * 9 | * This file is part of the NOVA microhypervisor. 10 | * 11 | * NOVA is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License version 2 as 13 | * published by the Free Software Foundation. 14 | * 15 | * NOVA is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License version 2 for more details. 19 | */ 20 | 21 | #include "vpid.hpp" 22 | 23 | Atomic Vpid::allocator { 0 }; 24 | --------------------------------------------------------------------------------