interrupt.asm 6.0 KB

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