MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / isr_handler

Function isr_handler

Kernel/src/arch/x86_64/idt.cpp:268–321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266
267extern "C"
268 void isr_handler(int int_num, regs64_t* regs, int err_code) {
269 errCode = err_code;
270 if (interrupt_handlers[int_num].handler != 0) {
271 interrupt_handlers[int_num].handler(interrupt_handlers[int_num].data, regs);
272 } else if(int_num == 0x69){
273 Log::Warning("\r\nEarly syscall");
274 } else if(!(regs->ss & 0x3)){ // Check the CPL of the segment, caused by kernel?
275 // Kernel Panic so tell other processors to stop executing
276 APIC::Local::SendIPI(0, ICR_DSH_OTHER /* Send to all other processors except us */, ICR_MESSAGE_TYPE_FIXED, IPI_HALT);
277
278 Log::Error("Fatal Kernel Exception: ");
279 Log::Info(int_num);
280 Log::Info("RIP: ");
281 Log::Info(regs->rip);
282 Log::Info("Error Code: ");
283 Log::Info(err_code);
284 Log::Info("Register Dump: a: ");
285 Log::Write(regs->rax);
286 Log::Write(", b:");
287 Log::Write(regs->rbx);
288 Log::Write(", c:");
289 Log::Write(regs->rcx);
290 Log::Write(", d:");
291 Log::Write(regs->rdx);
292 Log::Write(", S:");
293 Log::Write(regs->rsi);
294 Log::Write(", D:");
295 Log::Write(regs->rdi);
296 Log::Write(", sp:");
297 Log::Write(regs->rsp);
298 Log::Write(", bp:");
299 Log::Write(regs->rbp);
300
301 Log::Info("Stack Trace:");
302 PrintStackTrace(regs->rbp);
303
304 char temp[16];
305 char temp2[16];
306 char temp3[16];
307 const char* reasons[]{"Generic Exception","RIP: ", itoa(regs->rip, temp, 16),"Exception: ",itoa(int_num, temp2, 16), "Process:", itoa(Scheduler::GetCurrentProcess() ? (Scheduler::GetCurrentProcess()->pid) : 0,temp3,10)};;
308 KernelPanic(reasons, 7);
309 for (;;);
310 } else {
311 Log::Warning("Process %s crashed, PID: ", Scheduler::GetCurrentProcess()->name);
312 Log::Write(Scheduler::GetCurrentProcess()->pid);
313 Log::Write(", RIP: ");
314 Log::Write(regs->rip);
315 Log::Write(", Exception: ");
316 Log::Write(int_num);
317 Log::Info("Stack trace:");
318 UserPrintStackTrace(regs->rbp, Scheduler::GetCurrentProcess()->addressSpace);
319 Scheduler::EndProcess(Scheduler::GetCurrentProcess());
320 }
321 }
322
323 extern "C"
324 void irq_handler(int int_num, regs64_t* regs) {

Callers

nothing calls this directly

Calls 11

WarningFunction · 0.85
SendIPIFunction · 0.85
ErrorFunction · 0.85
InfoFunction · 0.85
PrintStackTraceFunction · 0.85
GetCurrentProcessFunction · 0.85
KernelPanicFunction · 0.85
UserPrintStackTraceFunction · 0.85
EndProcessFunction · 0.85
WriteFunction · 0.70
itoaFunction · 0.50

Tested by

no test coverage detected