interrupt.asm 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. ; Defined in isr.c
  2. [extern isr_handler]
  3. [extern irq_handler]
  4. ; Common ISR code
  5. isr_common_stub:
  6. ; 1. Save CPU state
  7. pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
  8. mov ax, ds ; Lower 16-bits of eax = ds.
  9. push eax ; save the data segment descriptor
  10. mov ax, 0x10 ; kernel data segment descriptor
  11. mov ds, ax
  12. mov es, ax
  13. mov fs, ax
  14. mov gs, ax
  15. push esp ; registers_t *r
  16. ; 2. Call C handler
  17. cld ; C code following the sysV ABI requires DF to be clear on function entry
  18. call isr_handler
  19. ; 3. Restore state
  20. pop eax
  21. pop eax
  22. mov ds, ax
  23. mov es, ax
  24. mov fs, ax
  25. mov gs, ax
  26. popa
  27. add esp, 8 ; Cleans up the pushed error code and pushed ISR number
  28. iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
  29. ; Common IRQ code. Identical to ISR code except for the 'call'
  30. ; and the 'pop ebx'
  31. irq_common_stub:
  32. pusha
  33. mov ax, ds
  34. push eax
  35. mov ax, 0x10
  36. mov ds, ax
  37. mov es, ax
  38. mov fs, ax
  39. mov gs, ax
  40. push esp
  41. cld
  42. call irq_handler ; Different than the ISR code
  43. pop ebx ; Different than the ISR code
  44. pop ebx
  45. mov ds, bx
  46. mov es, bx
  47. mov fs, bx
  48. mov gs, bx
  49. popa
  50. add esp, 8
  51. iret
  52. ; We don't get information about which interrupt was caller
  53. ; when the handler is run, so we will need to have a different handler
  54. ; for every interrupt.
  55. ; Furthermore, some interrupts push an error code onto the stack but others
  56. ; don't, so we will push a dummy error code for those which don't, so that
  57. ; we have a consistent stack for all of them.
  58. ; First make the ISRs global
  59. global isr0
  60. global isr1
  61. global isr2
  62. global isr3
  63. global isr4
  64. global isr5
  65. global isr6
  66. global isr7
  67. global isr8
  68. global isr9
  69. global isr10
  70. global isr11
  71. global isr12
  72. global isr13
  73. global isr14
  74. global isr15
  75. global isr16
  76. global isr17
  77. global isr18
  78. global isr19
  79. global isr20
  80. global isr21
  81. global isr22
  82. global isr23
  83. global isr24
  84. global isr25
  85. global isr26
  86. global isr27
  87. global isr28
  88. global isr29
  89. global isr30
  90. global isr31
  91. ; IRQs
  92. global irq0
  93. global irq1
  94. global irq2
  95. global irq3
  96. global irq4
  97. global irq5
  98. global irq6
  99. global irq7
  100. global irq8
  101. global irq9
  102. global irq10
  103. global irq11
  104. global irq12
  105. global irq13
  106. global irq14
  107. global irq15
  108. ; 0: Divide By Zero Exception
  109. isr0:
  110. push byte 0
  111. push byte 0
  112. jmp isr_common_stub
  113. ; 1: Debug Exception
  114. isr1:
  115. push byte 0
  116. push byte 1
  117. jmp isr_common_stub
  118. ; 2: Non Maskable Interrupt Exception
  119. isr2:
  120. push byte 0
  121. push byte 2
  122. jmp isr_common_stub
  123. ; 3: Int 3 Exception
  124. isr3:
  125. push byte 0
  126. push byte 3
  127. jmp isr_common_stub
  128. ; 4: INTO Exception
  129. isr4:
  130. push byte 0
  131. push byte 4
  132. jmp isr_common_stub
  133. ; 5: Out of Bounds Exception
  134. isr5:
  135. push byte 0
  136. push byte 5
  137. jmp isr_common_stub
  138. ; 6: Invalid Opcode Exception
  139. isr6:
  140. push byte 0
  141. push byte 6
  142. jmp isr_common_stub
  143. ; 7: Coprocessor Not Available Exception
  144. isr7:
  145. push byte 0
  146. push byte 7
  147. jmp isr_common_stub
  148. ; 8: Double Fault Exception (With Error Code!)
  149. isr8:
  150. push byte 8
  151. jmp isr_common_stub
  152. ; 9: Coprocessor Segment Overrun Exception
  153. isr9:
  154. push byte 0
  155. push byte 9
  156. jmp isr_common_stub
  157. ; 10: Bad TSS Exception (With Error Code!)
  158. isr10:
  159. push byte 10
  160. jmp isr_common_stub
  161. ; 11: Segment Not Present Exception (With Error Code!)
  162. isr11:
  163. push byte 11
  164. jmp isr_common_stub
  165. ; 12: Stack Fault Exception (With Error Code!)
  166. isr12:
  167. push byte 12
  168. jmp isr_common_stub
  169. ; 13: General Protection Fault Exception (With Error Code!)
  170. isr13:
  171. push byte 13
  172. jmp isr_common_stub
  173. ; 14: Page Fault Exception (With Error Code!)
  174. isr14:
  175. push byte 14
  176. jmp isr_common_stub
  177. ; 15: Reserved Exception
  178. isr15:
  179. push byte 0
  180. push byte 15
  181. jmp isr_common_stub
  182. ; 16: Floating Point Exception
  183. isr16:
  184. push byte 0
  185. push byte 16
  186. jmp isr_common_stub
  187. ; 17: Alignment Check Exception
  188. isr17:
  189. push byte 0
  190. push byte 17
  191. jmp isr_common_stub
  192. ; 18: Machine Check Exception
  193. isr18:
  194. push byte 0
  195. push byte 18
  196. jmp isr_common_stub
  197. ; 19: Reserved
  198. isr19:
  199. push byte 0
  200. push byte 19
  201. jmp isr_common_stub
  202. ; 20: Reserved
  203. isr20:
  204. push byte 0
  205. push byte 20
  206. jmp isr_common_stub
  207. ; 21: Reserved
  208. isr21:
  209. push byte 0
  210. push byte 21
  211. jmp isr_common_stub
  212. ; 22: Reserved
  213. isr22:
  214. push byte 0
  215. push byte 22
  216. jmp isr_common_stub
  217. ; 23: Reserved
  218. isr23:
  219. push byte 0
  220. push byte 23
  221. jmp isr_common_stub
  222. ; 24: Reserved
  223. isr24:
  224. push byte 0
  225. push byte 24
  226. jmp isr_common_stub
  227. ; 25: Reserved
  228. isr25:
  229. push byte 0
  230. push byte 25
  231. jmp isr_common_stub
  232. ; 26: Reserved
  233. isr26:
  234. push byte 0
  235. push byte 26
  236. jmp isr_common_stub
  237. ; 27: Reserved
  238. isr27:
  239. push byte 0
  240. push byte 27
  241. jmp isr_common_stub
  242. ; 28: Reserved
  243. isr28:
  244. push byte 0
  245. push byte 28
  246. jmp isr_common_stub
  247. ; 29: Reserved
  248. isr29:
  249. push byte 0
  250. push byte 29
  251. jmp isr_common_stub
  252. ; 30: Reserved
  253. isr30:
  254. push byte 0
  255. push byte 30
  256. jmp isr_common_stub
  257. ; 31: Reserved
  258. isr31:
  259. push byte 0
  260. push byte 31
  261. jmp isr_common_stub
  262. ; IRQ handlers
  263. irq0:
  264. push byte 0
  265. push byte 32
  266. jmp irq_common_stub
  267. irq1:
  268. push byte 1
  269. push byte 33
  270. jmp irq_common_stub
  271. irq2:
  272. push byte 2
  273. push byte 34
  274. jmp irq_common_stub
  275. irq3:
  276. push byte 3
  277. push byte 35
  278. jmp irq_common_stub
  279. irq4:
  280. push byte 4
  281. push byte 36
  282. jmp irq_common_stub
  283. irq5:
  284. push byte 5
  285. push byte 37
  286. jmp irq_common_stub
  287. irq6:
  288. push byte 6
  289. push byte 38
  290. jmp irq_common_stub
  291. irq7:
  292. push byte 7
  293. push byte 39
  294. jmp irq_common_stub
  295. irq8:
  296. push byte 8
  297. push byte 40
  298. jmp irq_common_stub
  299. irq9:
  300. push byte 9
  301. push byte 41
  302. jmp irq_common_stub
  303. irq10:
  304. push byte 10
  305. push byte 42
  306. jmp irq_common_stub
  307. irq11:
  308. push byte 11
  309. push byte 43
  310. jmp irq_common_stub
  311. irq12:
  312. push byte 12
  313. push byte 44
  314. jmp irq_common_stub
  315. irq13:
  316. push byte 13
  317. push byte 45
  318. jmp irq_common_stub
  319. irq14:
  320. push byte 14
  321. push byte 46
  322. jmp irq_common_stub
  323. irq15:
  324. push byte 15
  325. push byte 47
  326. jmp irq_common_stub