feat(kernel): implement SMP multi-core affinity, ACPI subsystem, hardware RNG (RDRAND), and Ring 3 signal fault isolation
This commit is contained in:
@@ -497,6 +497,53 @@ static void handle_command(char *cmd) {
|
||||
} else {
|
||||
puts("[IPC-ERR] Failed to communicate with UART driver.");
|
||||
}
|
||||
} else if (strcmp(cmd, "random") == 0 || strcmp(cmd, "rng") == 0) {
|
||||
uint8_t rand_bytes[16];
|
||||
register uint64_t rax __asm__("rax") = SYS_GETRANDOM;
|
||||
register uint64_t rdi __asm__("rdi") = (uint64_t)rand_bytes;
|
||||
register uint64_t rsi __asm__("rsi") = sizeof(rand_bytes);
|
||||
__asm__ volatile("syscall" : "+r"(rax) : "r"(rdi), "r"(rsi) : "rcx", "r11", "memory");
|
||||
if ((int64_t)rax > 0) {
|
||||
printf("Hardware RNG Entropy (16 bytes): ");
|
||||
for (size_t i = 0; i < sizeof(rand_bytes); i++) {
|
||||
printf("%02x", rand_bytes[i]);
|
||||
if (i == 3 || i == 5 || i == 7 || i == 9) printf("-");
|
||||
}
|
||||
printf(" (UUID v4 format)\n");
|
||||
} else {
|
||||
puts("random: hardware RNG syscall failed");
|
||||
}
|
||||
} else if (strcmp(cmd, "acpi") == 0) {
|
||||
acpi_info_data_t acpi = {0, 0, 0, 0, 0};
|
||||
register uint64_t rax __asm__("rax") = SYS_ACPI_INFO;
|
||||
register uint64_t rdi __asm__("rdi") = (uint64_t)&acpi;
|
||||
__asm__ volatile("syscall" : "+r"(rax) : "r"(rdi) : "rcx", "r11", "memory");
|
||||
if (acpi.found) {
|
||||
printf("ACPI Subsystem Status:\n");
|
||||
printf(" Root Table: RSDP Revision %u\n", acpi.revision);
|
||||
printf(" MADT Cores: %u LAPIC CPU Core(s) enabled\n", acpi.lapic_count);
|
||||
printf(" FADT Ports: PM1a_CNT = 0x%04x, PM1b_CNT = 0x%04x\n", acpi.pm1a_cnt, acpi.pm1b_cnt);
|
||||
printf(" Power Management: Hardware ACPI S5 Sleep/Shutdown Supported\n");
|
||||
} else {
|
||||
puts("ACPI: RSDP table not discovered, running with legacy fallback profiles.");
|
||||
}
|
||||
} else if (strcmp(cmd, "smp") == 0 || strcmp(cmd, "cpu") == 0) {
|
||||
cpu_info_data_t cpu = {0, 0, {0, 0, 0, 0}};
|
||||
register uint64_t rax __asm__("rax") = SYS_CPU_INFO;
|
||||
register uint64_t rdi __asm__("rdi") = (uint64_t)&cpu;
|
||||
__asm__ volatile("syscall" : "+r"(rax) : "r"(rdi) : "rcx", "r11", "memory");
|
||||
printf("SMP Multi-Core Topology:\n");
|
||||
printf(" Online Cores: %u physical cores\n", cpu.cores_online);
|
||||
printf(" Current Core: CPU %u (Executing 'sh')\n", cpu.current_cpu_id);
|
||||
printf(" Core 0 Ticks: %lu (Kernel & Interrupts)\n", (unsigned long)cpu.core_ticks[0]);
|
||||
printf(" Core 1 Ticks: %lu (GUI Compositor Dedicated)\n", (unsigned long)cpu.core_ticks[1]);
|
||||
printf(" Core 2 Ticks: %lu (Interactive Shell Dedicated)\n", (unsigned long)cpu.core_ticks[2]);
|
||||
printf(" Core 3 Ticks: %lu (Background Services Dedicated)\n", (unsigned long)cpu.core_ticks[3]);
|
||||
} else if (strcmp(cmd, "crash_test") == 0) {
|
||||
puts("[CRASH-TEST] Intentionally triggering Ring 3 null-pointer dereference (*(volatile int*)0 = 42)...");
|
||||
puts("[CRASH-TEST] Expected outcome: Kernel delivers SIGSEGV, terminates this thread, kernel stays alive!");
|
||||
volatile int *bad_ptr = (volatile int *)0;
|
||||
*bad_ptr = 42;
|
||||
} else if (strcmp(cmd, "clear") == 0) {
|
||||
sys_log_debug("\033[2J\033[H", 7);
|
||||
} else if (strcmp(cmd, "reboot") == 0) {
|
||||
|
||||
Reference in New Issue
Block a user