Advertisement
Guest User

Kinda working now

a guest
Dec 7th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. switchTask:
  2.     cli #Clear interrupt flag, to prevent an interrupt from firing while task is switching
  3.     mov 4(%esp), %eax # Move the top of the struct to eax
  4.     mov 4(%eax), %ebx # EBX
  5.     mov 8(%eax), %ecx # ECX
  6.     mov 12(%eax), %edx # EDX
  7.     mov 16(%eax), %esi # ESI
  8.     mov 20(%eax), %edi # EDI
  9.     mov 24(%eax), %esp # ESP
  10.     push %eax # Save eax
  11.     mov 32(%eax), %eax # Move EIP to EAX
  12.     xchg (%esp), %eax # Move the new EIP value into esp, and eax is returned to its previous state
  13.     mov 36(%eax), %ebp # EFLAGS
  14.     push %ebp # Push the flags(stored in ebp)
  15.     popf # Pop the value we just pushed into the flags register, restores interrupt flag, because each process is started with the interrupt flag on, and disabling it would kill the task system (secret info dont tell processes)
  16.     mov 28(%eax), %ebp # EBP
  17.     mov (%eax), %eax # Put EAX back
  18.     push %eax
  19.     mov $102, %ax
  20.     mov %ax, (0xb8000) # put f at screen
  21.     mov %ax, (0xb8002) # put f at screen
  22.     mov %ax, (0xb8004) # put f at screen
  23.     pop %eax
  24.     sti
  25.     ret # Return to the EIP in stack
  26.  
  27. irq_common_stub:
  28.     pushad
  29.     mov ax, ds
  30.     push eax
  31.     mov ax, 0x10 ;0x10
  32.     mov ds, ax
  33.     mov es, ax
  34.     mov fs, ax
  35.     mov gs, ax
  36.     mov eax, dr6
  37.     push eax
  38.     push esp                 ; At this point ESP is a pointer to where DS (and the rest
  39.                              ; of the interrupt handler state resides)
  40.                              ; Push ESP as 1st parameter as it's a
  41.                              ; pointer to a registers_t  
  42.     call irq_handler
  43.     mov eax, [switch_task]
  44.     cmp eax, 1
  45.     je changeTasks
  46.     add esp, 8                 ; Remove the saved ESP on the stack. Efficient to just pop it
  47.                              ; into any register. You could have done: add esp, 4 as well
  48.     pop ebx
  49.     mov ds, bx
  50.     mov es, bx
  51.     mov fs, bx
  52.     mov gs, bx
  53.     popad
  54.     add esp, 8
  55.     sti
  56.     iret
  57.  
  58. changeTasks:
  59.     mov eax, 1234567
  60.     push eax
  61.     mov eax, 0
  62.     mov [switch_task], eax
  63.     call store_global ; Set a global variable with C
  64.     add esp, 72 ; "Pop" 18 values off the stack
  65.     jmp irq_schedule ; Switch task
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement