mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
feat: Add certs, init, io_uring, security, usr, virt subsystems, Nano editor & full LazyBox suite
This commit is contained in:
1 parent
ae5f4a96c4
commit
5662be29f5
27 files changed
+1870
-333
No files matched your search
@@ -0,0 +1,64 @@
|
||||
#include <virt/virt.h>
|
||||
#include <virt/virtio.h>
|
||||
#include <arch/x86_64/cpuid.h>
|
||||
#include <lib/string.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
static hypervisor_info_t host_hypervisor;
|
||||
|
||||
void virt_init(void) {
|
||||
memset(&host_hypervisor, 0, sizeof(host_hypervisor));
|
||||
|
||||
// Check CPUID hypervisor feature bit (ECX bit 31 on leaf 1)
|
||||
uint32_t eax, ebx, ecx, edx;
|
||||
cpuid(1, &eax, &ebx, &ecx, &edx);
|
||||
|
||||
if (ecx & (1U << 31)) {
|
||||
// Hypervisor present, query leaf 0x40000000
|
||||
cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
|
||||
char sig[13];
|
||||
memcpy(sig, &ebx, 4);
|
||||
memcpy(sig + 4, &ecx, 4);
|
||||
memcpy(sig + 8, &edx, 4);
|
||||
sig[12] = '\0';
|
||||
|
||||
strncpy(host_hypervisor.signature, sig, sizeof(host_hypervisor.signature) - 1);
|
||||
|
||||
if (strcmp(sig, "KVMKVMKVM\0\0\0") == 0 || strstr(sig, "KVM") != NULL) {
|
||||
host_hypervisor.type = HYPERVISOR_KVM;
|
||||
strcpy(host_hypervisor.name, "Linux KVM / QEMU");
|
||||
} else if (strcmp(sig, "TCGTCGTCGTCG") == 0) {
|
||||
host_hypervisor.type = HYPERVISOR_QEMU;
|
||||
strcpy(host_hypervisor.name, "QEMU TCG Engine");
|
||||
} else if (strcmp(sig, "VMwareVMware") == 0) {
|
||||
host_hypervisor.type = HYPERVISOR_VMWARE;
|
||||
strcpy(host_hypervisor.name, "VMware ESXi / Workstation");
|
||||
} else if (strcmp(sig, "VBoxVBoxVBox") == 0) {
|
||||
host_hypervisor.type = HYPERVISOR_VBOX;
|
||||
strcpy(host_hypervisor.name, "Oracle VirtualBox");
|
||||
} else if (strcmp(sig, "Microsoft Hv") == 0) {
|
||||
host_hypervisor.type = HYPERVISOR_HYPERV;
|
||||
strcpy(host_hypervisor.name, "Microsoft Hyper-V");
|
||||
} else {
|
||||
host_hypervisor.type = HYPERVISOR_UNKNOWN;
|
||||
strcpy(host_hypervisor.name, "Generic Hypervisor");
|
||||
}
|
||||
|
||||
printk(KERN_INFO "VIRT: Detected Hypervisor: %s (Signature: '%s')\n",
|
||||
host_hypervisor.name, host_hypervisor.signature);
|
||||
} else {
|
||||
host_hypervisor.type = HYPERVISOR_NONE;
|
||||
strcpy(host_hypervisor.name, "Bare Metal x86_64 Machine");
|
||||
printk(KERN_INFO "VIRT: Running on physical Bare Metal x86_64 hardware\n");
|
||||
}
|
||||
|
||||
virtio_init();
|
||||
}
|
||||
|
||||
const hypervisor_info_t* virt_get_hypervisor_info(void) {
|
||||
return &host_hypervisor;
|
||||
}
|
||||
|
||||
bool virt_is_virtualized(void) {
|
||||
return host_hypervisor.type != HYPERVISOR_NONE;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <virt/virtio.h>
|
||||
#include <lib/string.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
#define MAX_VIRTIO_DEVS 8
|
||||
|
||||
static virtio_device_t virtio_devices[MAX_VIRTIO_DEVS];
|
||||
static size_t virtio_count = 0;
|
||||
|
||||
void virtio_init(void) {
|
||||
memset(virtio_devices, 0, sizeof(virtio_devices));
|
||||
virtio_count = 0;
|
||||
printk(KERN_INFO "VIRTIO: Subsystem initialized (Ready for VirtIO devices)\n");
|
||||
}
|
||||
|
||||
int virtio_register_device(uint16_t dev_id, uint32_t io_base, uint8_t irq) {
|
||||
if (virtio_count >= MAX_VIRTIO_DEVS) return -1;
|
||||
|
||||
virtio_device_t* dev = &virtio_devices[virtio_count];
|
||||
dev->device_id = dev_id;
|
||||
dev->io_base = io_base;
|
||||
dev->irq = irq;
|
||||
dev->status = 1; // Acknowledge
|
||||
dev->active = true;
|
||||
|
||||
switch (dev_id) {
|
||||
case VIRTIO_ID_NET: strcpy(dev->name, "VirtIO Net Device"); break;
|
||||
case VIRTIO_ID_BLOCK: strcpy(dev->name, "VirtIO Block Storage"); break;
|
||||
case VIRTIO_ID_CONSOLE: strcpy(dev->name, "VirtIO Console"); break;
|
||||
case VIRTIO_ID_ENTROPY: strcpy(dev->name, "VirtIO RNG Entropy"); break;
|
||||
case VIRTIO_ID_BALLOON: strcpy(dev->name, "VirtIO Memory Balloon"); break;
|
||||
case VIRTIO_ID_GPU: strcpy(dev->name, "VirtIO 2D/3D GPU"); break;
|
||||
default: strcpy(dev->name, "VirtIO Unknown Device"); break;
|
||||
}
|
||||
|
||||
printk(KERN_INFO "VIRTIO: Registered %s at IO 0x%x (IRQ %d)\n", dev->name, io_base, irq);
|
||||
virtio_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t virtio_get_device_count(void) {
|
||||
return virtio_count;
|
||||
}
|
||||
|
||||
const virtio_device_t* virtio_get_device(size_t index) {
|
||||
if (index >= virtio_count) return NULL;
|
||||
return &virtio_devices[index];
|
||||
}
|
||||
Reference in new issue
Block a user