feat(kernel): implement SMP multi-core affinity, ACPI subsystem, hardware RNG (RDRAND), and Ring 3 signal fault isolation
This commit is contained in:
@@ -399,6 +399,60 @@ static void execute_console_command(const char *raw_cmd) {
|
||||
} else {
|
||||
lv_textarea_add_text(g_txt_term_output, "[dmesg] No new kernel log messages.\n");
|
||||
}
|
||||
} else if (strcmp(raw_cmd, "random") == 0 || strcmp(raw_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) {
|
||||
snprintf(buf, sizeof(buf), "Hardware RNG (16 bytes): %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
|
||||
rand_bytes[0], rand_bytes[1], rand_bytes[2], rand_bytes[3],
|
||||
rand_bytes[4], rand_bytes[5], rand_bytes[6], rand_bytes[7],
|
||||
rand_bytes[8], rand_bytes[9], rand_bytes[10], rand_bytes[11],
|
||||
rand_bytes[12], rand_bytes[13], rand_bytes[14], rand_bytes[15]);
|
||||
lv_textarea_add_text(g_txt_term_output, buf);
|
||||
} else {
|
||||
lv_textarea_add_text(g_txt_term_output, "random: RNG syscall failed\n");
|
||||
}
|
||||
} else if (strcmp(raw_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) {
|
||||
snprintf(buf, sizeof(buf),
|
||||
"ACPI Subsystem:\n"
|
||||
" RSDP: Revision %u\n"
|
||||
" MADT: %u CPU Cores enabled\n"
|
||||
" FADT: PM1a=0x%04x, PM1b=0x%04x\n"
|
||||
" Power: Hardware S5 Shutdown & Reset Active\n",
|
||||
acpi.revision, acpi.lapic_count, acpi.pm1a_cnt, acpi.pm1b_cnt);
|
||||
lv_textarea_add_text(g_txt_term_output, buf);
|
||||
} else {
|
||||
lv_textarea_add_text(g_txt_term_output, "ACPI: RSDP table not found.\n");
|
||||
}
|
||||
} else if (strcmp(raw_cmd, "smp") == 0 || strcmp(raw_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");
|
||||
snprintf(buf, sizeof(buf),
|
||||
"SMP Multi-Core Topology:\n"
|
||||
" Cores Online: %u physical cores\n"
|
||||
" Current CPU: CPU %u (Executing GUI)\n"
|
||||
" Core 0 Ticks: %lu (Kernel & Interrupts)\n"
|
||||
" Core 1 Ticks: %lu (Dedicated GUI Compositor)\n"
|
||||
" Core 2 Ticks: %lu (Dedicated Interactive Shell)\n"
|
||||
" Core 3 Ticks: %lu (Dedicated Background Services)\n",
|
||||
cpu.cores_online, cpu.current_cpu_id,
|
||||
(unsigned long)cpu.core_ticks[0], (unsigned long)cpu.core_ticks[1],
|
||||
(unsigned long)cpu.core_ticks[2], (unsigned long)cpu.core_ticks[3]);
|
||||
lv_textarea_add_text(g_txt_term_output, buf);
|
||||
} else if (strcmp(raw_cmd, "crash_test") == 0) {
|
||||
lv_textarea_add_text(g_txt_term_output, "[CRASH-TEST] Triggering Ring 3 null-pointer fault (*(int*)0 = 42)...\n");
|
||||
volatile int *p = (volatile int *)0;
|
||||
*p = 42;
|
||||
} else if (strcmp(raw_cmd, "reboot") == 0) {
|
||||
lv_textarea_add_text(g_txt_term_output, "Rebooting system...\n");
|
||||
register uint64_t rax __asm__("rax") = SYS_REBOOT;
|
||||
|
||||
@@ -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