feat(kernel): implement SMP multi-core affinity, ACPI subsystem, hardware RNG (RDRAND), and Ring 3 signal fault isolation
This commit is contained in:
+35
-3
@@ -184,13 +184,15 @@ pub struct ExceptionFrame {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn raw_exception_handler(frame: *const ExceptionFrame) {
|
||||
pub extern "C" fn raw_exception_handler(frame: *mut ExceptionFrame) {
|
||||
unsafe {
|
||||
let v = (*frame).vector;
|
||||
let ec = (*frame).error_code;
|
||||
let rip = (*frame).rip;
|
||||
let cs = (*frame).cs;
|
||||
let rflags = (*frame).rflags;
|
||||
let is_user = (cs & 3) == 3;
|
||||
|
||||
let names = [
|
||||
"#DE", "#DB", "NMI", "#BP", "#OF", "#BR", "#UD", "#NM",
|
||||
"#DF", "CSO", "#TS", "#NP", "#SS", "#GP", "#PF", "RES",
|
||||
@@ -198,7 +200,37 @@ pub extern "C" fn raw_exception_handler(frame: *const ExceptionFrame) {
|
||||
"??" , "??" , "??" , "??" , "??" , "??" , "#SX", "??" ,
|
||||
];
|
||||
let name = if v < 32 { names[v as usize] } else { "IRQ" };
|
||||
kprintln!("\n[EXCEPTION] Vec={} ({}) ErrCode={:#x} RIP={:#018x} CS={:#x} RFLAGS={:#x}",
|
||||
|
||||
if is_user {
|
||||
let sched = &mut *core::ptr::addr_of_mut!(SCHEDULER);
|
||||
let cur_tid = sched.current_tid;
|
||||
let cur_name = sched.threads[cur_tid].name;
|
||||
|
||||
let (sig_num, sig_name) = match v {
|
||||
0 | 4 | 5 => (8, "SIGFPE"), // Divide by zero or overflow
|
||||
6 => (4, "SIGILL"), // Invalid opcode
|
||||
11 | 12 | 13 | 14 => (11, "SIGSEGV"), // Page fault or General protection
|
||||
_ => (7, "SIGBUS"),
|
||||
};
|
||||
|
||||
kprintln!("\n[SIGNAL] Process [TID {}] '{}' crashed with Signal {} ({}) at RIP={:#018x} ErrCode={:#x}",
|
||||
cur_tid, cur_name, sig_num, sig_name, rip, ec);
|
||||
|
||||
if v == 14 {
|
||||
let cr2: u64;
|
||||
core::arch::asm!("mov {}, cr2", out(reg) cr2, options(nostack, preserves_flags));
|
||||
kprintln!(" [SIGNAL] Faulting memory address (CR2): {:#018x}", cr2);
|
||||
}
|
||||
|
||||
// Terminate only the crashed Ring 3 process
|
||||
sched.threads[cur_tid].state = crate::sched::thread::ThreadState::Dead;
|
||||
|
||||
// Switch CPU to the next ready process so the OS and desktop stay alive!
|
||||
sched.schedule();
|
||||
return;
|
||||
}
|
||||
|
||||
kprintln!("\n[EXCEPTION] Kernel Panic! Vec={} ({}) ErrCode={:#x} RIP={:#018x} CS={:#x} RFLAGS={:#x}",
|
||||
v, name, ec, rip, cs, rflags);
|
||||
if v == 14 {
|
||||
let cr2: u64;
|
||||
@@ -206,7 +238,7 @@ pub extern "C" fn raw_exception_handler(frame: *const ExceptionFrame) {
|
||||
kprintln!(" #PF CR2 (faulting address): {:#018x}", cr2);
|
||||
}
|
||||
if v < 32 {
|
||||
kprintln!(" [HALT] Unrecoverable exception - CPU halted.");
|
||||
kprintln!(" [HALT] Unrecoverable kernel exception - CPU halted.");
|
||||
loop { core::arch::asm!("cli; hlt", options(nostack, preserves_flags)); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user