interrupt.asm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. ; Defined in isr.c
  2. [extern isr_handler]
  3. ; Common ISR code
  4. isr_common_stub:
  5. ; 1. Save CPU state
  6. pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
  7. mov ax, ds ; Lower 16-bits of eax = ds.
  8. push eax ; save the data segment descriptor
  9. mov ax, 0x10 ; kernel data segment descriptor
  10. mov ds, ax
  11. mov es, ax
  12. mov fs, ax
  13. mov gs, ax
  14. ; 2. Call C handler
  15. call isr_handler
  16. ; 3. Restore state
  17. pop eax
  18. mov ds, ax
  19. mov es, ax
  20. mov fs, ax
  21. mov gs, ax
  22. popa
  23. add esp, 8 ; Cleans up the pushed error code and pushed ISR number
  24. sti
  25. iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
  26. ; We don't get information about which interrupt was caller
  27. ; when the handler is run, so we will need to have a different handler
  28. ; for every interrupt.
  29. ; Furthermore, some interrupts push an error code onto the stack but others
  30. ; don't, so we will push a dummy error code for those which don't, so that
  31. ; we have a consistent stack for all of them.
  32. ; First make the ISRs global
  33. global isr0
  34. global isr1
  35. global isr2
  36. global isr3
  37. global isr4
  38. global isr5
  39. global isr6
  40. global isr7
  41. global isr8
  42. global isr9
  43. global isr10
  44. global isr11
  45. global isr12
  46. global isr13
  47. global isr14
  48. global isr15
  49. global isr16
  50. global isr17
  51. global isr18
  52. global isr19
  53. global isr20
  54. global isr21
  55. global isr22
  56. global isr23
  57. global isr24
  58. global isr25
  59. global isr26
  60. global isr27
  61. global isr28
  62. global isr29
  63. global isr30
  64. global isr31
  65. ; 0: Divide By Zero Exception
  66. isr0:
  67. cli
  68. push byte 0
  69. push byte 0
  70. jmp isr_common_stub
  71. ; 1: Debug Exception
  72. isr1:
  73. cli
  74. push byte 0
  75. push byte 1
  76. jmp isr_common_stub
  77. ; 2: Non Maskable Interrupt Exception
  78. isr2:
  79. cli
  80. push byte 0
  81. push byte 2
  82. jmp isr_common_stub
  83. ; 3: Int 3 Exception
  84. isr3:
  85. cli
  86. push byte 0
  87. push byte 3
  88. jmp isr_common_stub
  89. ; 4: INTO Exception
  90. isr4:
  91. cli
  92. push byte 0
  93. push byte 4
  94. jmp isr_common_stub
  95. ; 5: Out of Bounds Exception
  96. isr5:
  97. cli
  98. push byte 0
  99. push byte 5
  100. jmp isr_common_stub
  101. ; 6: Invalid Opcode Exception
  102. isr6:
  103. cli
  104. push byte 0
  105. push byte 6
  106. jmp isr_common_stub
  107. ; 7: Coprocessor Not Available Exception
  108. isr7:
  109. cli
  110. push byte 0
  111. push byte 7
  112. jmp isr_common_stub
  113. ; 8: Double Fault Exception (With Error Code!)
  114. isr8:
  115. cli
  116. push byte 8
  117. jmp isr_common_stub
  118. ; 9: Coprocessor Segment Overrun Exception
  119. isr9:
  120. cli
  121. push byte 0
  122. push byte 9
  123. jmp isr_common_stub
  124. ; 10: Bad TSS Exception (With Error Code!)
  125. isr10:
  126. cli
  127. push byte 10
  128. jmp isr_common_stub
  129. ; 11: Segment Not Present Exception (With Error Code!)
  130. isr11:
  131. cli
  132. push byte 11
  133. jmp isr_common_stub
  134. ; 12: Stack Fault Exception (With Error Code!)
  135. isr12:
  136. cli
  137. push byte 12
  138. jmp isr_common_stub
  139. ; 13: General Protection Fault Exception (With Error Code!)
  140. isr13:
  141. cli
  142. push byte 13
  143. jmp isr_common_stub
  144. ; 14: Page Fault Exception (With Error Code!)
  145. isr14:
  146. cli
  147. push byte 14
  148. jmp isr_common_stub
  149. ; 15: Reserved Exception
  150. isr15:
  151. cli
  152. push byte 0
  153. push byte 15
  154. jmp isr_common_stub
  155. ; 16: Floating Point Exception
  156. isr16:
  157. cli
  158. push byte 0
  159. push byte 16
  160. jmp isr_common_stub
  161. ; 17: Alignment Check Exception
  162. isr17:
  163. cli
  164. push byte 0
  165. push byte 17
  166. jmp isr_common_stub
  167. ; 18: Machine Check Exception
  168. isr18:
  169. cli
  170. push byte 0
  171. push byte 18
  172. jmp isr_common_stub
  173. ; 19: Reserved
  174. isr19:
  175. cli
  176. push byte 0
  177. push byte 19
  178. jmp isr_common_stub
  179. ; 20: Reserved
  180. isr20:
  181. cli
  182. push byte 0
  183. push byte 20
  184. jmp isr_common_stub
  185. ; 21: Reserved
  186. isr21:
  187. cli
  188. push byte 0
  189. push byte 21
  190. jmp isr_common_stub
  191. ; 22: Reserved
  192. isr22:
  193. cli
  194. push byte 0
  195. push byte 22
  196. jmp isr_common_stub
  197. ; 23: Reserved
  198. isr23:
  199. cli
  200. push byte 0
  201. push byte 23
  202. jmp isr_common_stub
  203. ; 24: Reserved
  204. isr24:
  205. cli
  206. push byte 0
  207. push byte 24
  208. jmp isr_common_stub
  209. ; 25: Reserved
  210. isr25:
  211. cli
  212. push byte 0
  213. push byte 25
  214. jmp isr_common_stub
  215. ; 26: Reserved
  216. isr26:
  217. cli
  218. push byte 0
  219. push byte 26
  220. jmp isr_common_stub
  221. ; 27: Reserved
  222. isr27:
  223. cli
  224. push byte 0
  225. push byte 27
  226. jmp isr_common_stub
  227. ; 28: Reserved
  228. isr28:
  229. cli
  230. push byte 0
  231. push byte 28
  232. jmp isr_common_stub
  233. ; 29: Reserved
  234. isr29:
  235. cli
  236. push byte 0
  237. push byte 29
  238. jmp isr_common_stub
  239. ; 30: Reserved
  240. isr30:
  241. cli
  242. push byte 0
  243. push byte 30
  244. jmp isr_common_stub
  245. ; 31: Reserved
  246. isr31:
  247. cli
  248. push byte 0
  249. push byte 31
  250. jmp isr_common_stub