SHARE
TWEET

am i dum?

a guest Dec 14th, 2019 172 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void swap_values(registers_t *r) {
  2.     regs = &runningTask->regs; // Get registers
  3.     /* Set old registers */
  4.     regs->eflags = r->eflags;
  5.     regs->eax = r->eax;
  6.     regs->ebx = r->ebx;
  7.     regs->ecx = r->ecx;
  8.     regs->edx = r->edx;
  9.     regs->edi = r->edi;
  10.     regs->esi = r->esi;
  11.     regs->eip = r->eip;
  12.     regs->esp = r->esp;
  13.     regs->ebp = r->ebp;
  14.     // Select new running task
  15.     runningTask = runningTask->next;
  16.     while (runningTask->state != RUNNING) {
  17.         runningTask = runningTask->next;
  18.     }
  19.  
  20.     // Set values for context switch
  21.     regs = &runningTask->regs;
  22.     r->eflags = regs->eflags;
  23.     r->eflags = r->eflags | 0x200;
  24.     r->eax = regs->eax;
  25.     r->ebx = regs->ebx;
  26.     r->ecx = regs->ecx;
  27.     r->edx = regs->edx;
  28.     r->edi = regs->edi;
  29.     r->esi = regs->esi;
  30.     r->eip = regs->eip;
  31.     r->useresp = regs->esp;
  32.     r->esp = regs->esp;
  33.     r->ebp = regs->ebp;
  34.     sprint("\nDone switching\n");
  35.     sprint_uint(r->esp);
  36.     sprint("\n");
  37.     sprint_uint(r->eip);
  38. }
  39.  
  40.  
  41. irq_common_stub:
  42.     pushad
  43.     mov ax, ds
  44.     push eax
  45.     mov eax, dr6
  46.     push eax
  47.     mov eax, esp                 ; At this point ESP is a pointer to where DS (and the rest
  48.                              ; of the interrupt handler state resides)
  49.                              ; Push ESP as 1st parameter as it's a
  50.                              ; pointer to a registers_t
  51.     call irq_handler
  52.     mov ebx, [switch_task]
  53.     cmp ebx, 1
  54.     jne testLabel
  55.     mov ebx, 0
  56.     mov [switch_task], ebx
  57.     mov eax, esp ; Safety, irq_handler probably changed eax
  58.     call swap_values ; Change context stored on stack
  59. testLabel:
  60.     add esp, 8 ; DR6 and ss
  61.     popad
  62.     add esp, 8 ; IRQ code and error code
  63.     sti ; Set interrupt flag
  64.     iret ; Ret
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top