1
0

interrupt.asm 6.0 KB

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