Guest User

interupts

a guest
Jan 22nd, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.34 KB | None | 0 0
  1. ;
  2. ; interrupt.s -- Contains interrupt service routine wrappers.
  3. ;                Based on Bran's kernel development tutorials.
  4. ;                Rewritten for JamesM's kernel development tutorials.
  5.  
  6. ; This macro creates a stub for an ISR which does NOT pass it's own
  7. ; error code (adds a dummy errcode byte).
  8. %macro ISR_NOERRCODE 1
  9.  global isr%1
  10.  isr%1:
  11.    cli                         ; Disable interrupts firstly.
  12.    push byte 0                 ; Push a dummy error code.
  13.    push byte %1                ; Push the interrupt number.
  14.    jmp isr_common_stub         ; Go to our common handler code.
  15. %endmacro
  16.  
  17. ; This macro creates a stub for an ISR which passes it's own
  18. ; error code.
  19. %macro ISR_ERRCODE 1
  20.   global isr%1
  21.   isr%1:
  22.     cli                         ; Disable interrupts.
  23.     push byte %1                ; Push the interrupt number
  24.     jmp isr_common_stub
  25. %endmacro
  26.  
  27. ISR_NOERRCODE 0
  28. ISR_NOERRCODE 1
  29. ISR_NOERRCODE 2
  30. ISR_NOERRCODE 3
  31. ISR_NOERRCODE 4
  32. ISR_NOERRCODE 5
  33. ISR_NOERRCODE 6
  34. ISR_NOERRCODE 7
  35. ISR_ERRCODE   8
  36. ISR_NOERRCODE 9
  37. ISR_ERRCODE   10
  38. ISR_ERRCODE   11
  39. ISR_ERRCODE   12
  40. ISR_ERRCODE   13
  41. ISR_ERRCODE   14
  42. ISR_NOERRCODE 15
  43. ISR_NOERRCODE 16
  44. ISR_NOERRCODE 17
  45. ISR_NOERRCODE 18
  46. ISR_NOERRCODE 19
  47. ISR_NOERRCODE 20
  48. ISR_NOERRCODE 21
  49. ISR_NOERRCODE 22
  50. ISR_NOERRCODE 23
  51. ISR_NOERRCODE 24
  52. ISR_NOERRCODE 25
  53. ISR_NOERRCODE 26
  54. ISR_NOERRCODE 27
  55. ISR_NOERRCODE 28
  56. ISR_NOERRCODE 29
  57. ISR_NOERRCODE 30
  58. ISR_NOERRCODE 31
  59.  
  60. ; In isr.c
  61. extern isr_handler
  62.  
  63. ; This is our common ISR stub. It saves the processor state, sets
  64. ; up for kernel mode segments, calls the C-level fault handler,
  65. ; and finally restores the stack frame.
  66. isr_common_stub:
  67.     pusha                    ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
  68.  
  69.     mov ax, ds               ; Lower 16-bits of eax = ds.
  70.     push eax                 ; save the data segment descriptor
  71.  
  72.     mov ax, 0x10  ; load the kernel data segment descriptor
  73.     mov ds, ax
  74.     mov es, ax
  75.     mov fs, ax
  76.     mov gs, ax
  77.  
  78.     call isr_handler
  79.  
  80.     pop ebx        ; reload the original data segment descriptor
  81.     mov ds, bx
  82.     mov es, bx
  83.     mov fs, bx
  84.     mov gs, bx
  85.  
  86.     popa                     ; Pops edi,esi,ebp...
  87.     add esp, 8     ; Cleans up the pushed error code and pushed ISR number
  88.     sti
  89.     iret           ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
Advertisement
Add Comment
Please, Sign In to add comment