Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. void isr_handler(int_reg_t *r) {
  2.     interrupt_lock();
  3.  
  4.     /* If the int number is in range */
  5.     if (r->int_num < IDT_ENTRIES) {
  6.         if (r->int_num < 32) {
  7.             /* Exception */
  8.             uint64_t cr2;
  9.             asm volatile("movq %%cr2, %0;" : "=r"(cr2));
  10.             /* Ensure the display is not locked when we crash */
  11.             unlock(&base_tty.tty_lock);
  12.             unlock(&vesa_lock);
  13.             clear_buffer();
  14.             tty_seek(0, 0, &base_tty);
  15.             sprintf("\nException!");
  16.             sprintf("\nRAX: %lx RBX: %lx RCX: %lx \nRDX: %lx RBP: %lx RDI: %lx \nRSI: %lx R08: %lx R09: %lx \nR10: %lx R11: %lx R12: %lx \nR13: %lx R14: %lx R15: %lx \nRSP: %lx ERR: %lx INT: %lx \nRIP: %lx CR2: %lx", r->rax, r->rbx, r->rcx, r->rdx, r->rbp, r->rdi, r->rsi, r->r8, r->r9, r->r10, r->r11, r->r12, r->r13, r->r14, r->r15, r->rsp, r->int_err, r->int_num, r->rip, cr2);
  17.             while (1) { asm volatile("hlt"); }
  18.         }
  19.         /* If the entry is present */
  20.         if (handlers[r->int_num]) {
  21.             /* Call the handler */
  22.             handlers[r->int_num](r);
  23.         }
  24.     } else {
  25.         uint64_t cr2;
  26.         asm volatile("movq %%cr2, %0;" : "=r"(cr2));
  27.         sprintf("\nBad int no %lu", r->int_num);
  28.         sprintf("\nRAX: %lx RBX: %lx RCX: %lx \nRDX: %lx RBP: %lx RDI: %lx \nRSI: %lx R08: %lx R09: %lx \nR10: %lx R11: %lx R12: %lx \nR13: %lx R14: %lx R15: %lx \nRSP: %lx ERR: %lx INT: %lx \nRIP: %lx CR2: %lx", r->rax, r->rbx, r->rcx, r->rdx, r->rbp, r->rdi, r->rsi, r->r8, r->r9, r->r10, r->r11, r->r12, r->r13, r->r14, r->r15, r->rsp, r->int_err, r->int_num, r->rip, cr2);
  29.         while (1) { asm volatile("hlt"); }
  30.     }
  31.  
  32.     interrupt_unlock();
  33.  
  34.     // If we make it here, send an EOI to our LAPIC
  35.     write_lapic(0xB0, 0);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement