/x86/isr_wrap.s

https://gitlab.com/bluehole/myos-32bit · Assembly · 505 lines · 364 code · 40 blank · 101 comment · 0 complexity · 1c97efb7ec8aec1f925ea52fdbeceac1 MD5 · raw file

  1. ;//////////////////////////////////////////////////////////
  2. ;// This file is a part of Nanos Copyright (C) 2008, 2009//
  3. ;// ashok.s.das@gmail.com //
  4. ;//////////////////////////////////////////////////////////
  5. ;// isr wrapper //
  6. ;// //
  7. ;//////////////////////////////////////////////////////////
  8. ;Stolen from Bran's tutorial
  9. ; we will add our Interrupt
  10. ; Service Routines (ISRs) right here!
  11. segment .text
  12. global _isr0
  13. global _isr1
  14. global _isr2
  15. global _isr3
  16. global _isr4
  17. global _isr5
  18. global _isr6
  19. global _isr7
  20. global _isr8
  21. global _isr9
  22. global _isr10
  23. global _isr11
  24. global _isr12
  25. global _isr13
  26. global _isr14
  27. global _isr15
  28. global _isr16
  29. global _isr17
  30. global _isr18
  31. global _isr19
  32. global _isr20
  33. global _isr21
  34. global _isr22
  35. global _isr23
  36. global _isr24
  37. global _isr25
  38. global _isr26
  39. global _isr27
  40. global _isr28
  41. global _isr29
  42. global _isr30
  43. global _isr31
  44. global _irq0 ;IRQ 0
  45. global _irq1
  46. global _irq2
  47. global _irq3
  48. global _irq4
  49. global _irq5
  50. global _irq6
  51. global _irq7
  52. global _irq8
  53. global _irq9
  54. global _irq10
  55. global _irq11
  56. global _irq12
  57. global _irq13
  58. global _irq14
  59. global _irq15 ;IRQ 15
  60. global read_eip ; I could not find a better place to put
  61. ; this so put it here
  62. extern _irq_handler ; C code
  63. ; 0: Divide By Zero Exception
  64. _isr0:
  65. cli
  66. push byte 0 ; A normal ISR stub that pops a dummy error code to keep
  67. ;a uniform stack frame
  68. push byte 0
  69. jmp isr_common_stub
  70. ; 1: Debug Exception
  71. _isr1:
  72. cli
  73. push byte 0
  74. push byte 1
  75. jmp isr_common_stub
  76. ;2 : NMI
  77. _isr2:
  78. cli
  79. push byte 0
  80. push byte 2
  81. jmp isr_common_stub
  82. ;3 Breakpoint
  83. _isr3:
  84. cli
  85. push byte 0
  86. push byte 3
  87. jmp isr_common_stub
  88. ;4 Into detected overflow
  89. _isr4:
  90. cli
  91. push byte 0
  92. push byte 4
  93. jmp isr_common_stub
  94. ;5 Out Of Bound
  95. _isr5:
  96. cli
  97. push byte 0
  98. push byte 5
  99. jmp isr_common_stub
  100. ;6 Invalid Opcode
  101. _isr6:
  102. cli
  103. push byte 0
  104. push byte 6
  105. jmp isr_common_stub
  106. ;7 No Co_processor
  107. _isr7:
  108. cli
  109. push byte 0
  110. push byte 7
  111. jmp isr_common_stub
  112. ; 8: Double Fault Exception (With Error Code!)
  113. _isr8:
  114. cli
  115. push byte 8 ; Note that we DON'T push a value on the stack in this one!
  116. ; It pushes one already!Use this type of stub for exceptions
  117. ; that pop error codes!
  118. jmp isr_common_stub
  119. ;9: co-processor segment overrun
  120. _isr9:
  121. cli
  122. push byte 0
  123. push byte 9
  124. jmp isr_common_stub
  125. ;10 Bad TSS
  126. _isr10:
  127. cli
  128. push byte 10; Note that we DON'T push a value on the stack in this one!
  129. ; It pushes one already!Use this type of stub for exceptions
  130. ; that pop error codes!
  131. jmp isr_common_stub
  132. ;11 Segment Not Present
  133. _isr11:
  134. cli
  135. push byte 11; Note that we DON'T push a value on the stack in this one!
  136. ; It pushes one already!Use this type of stub for exceptions
  137. ; that pop error codes!
  138. jmp isr_common_stub
  139. ;12 Stack fault
  140. _isr12:
  141. cli
  142. push byte 12; Note that we DON'T push a value on the stack in this one!
  143. ; It pushes one already!Use this type of stub for exceptions
  144. ; that pop error codes!
  145. jmp isr_common_stub
  146. ;13 GPF
  147. _isr13:
  148. cli
  149. push byte 13; Note that we DON'T push a value on the stack in this one!
  150. ; It pushes one already!Use this type of stub for exceptions
  151. ; that pop error codes!
  152. jmp isr_common_stub
  153. ;14 Page Fault
  154. _isr14:
  155. cli
  156. push byte 14; Note that we DON'T push a value on the stack in this one!
  157. ; It pushes one already!Use this type of stub for exceptions
  158. ; that pop error codes!
  159. jmp isr_common_stub
  160. ;15 Unknown Exception
  161. _isr15:
  162. cli
  163. push byte 0
  164. push byte 15
  165. jmp isr_common_stub
  166. ;16 Co-Processor Fault
  167. _isr16:
  168. cli
  169. push byte 0
  170. push byte 16
  171. jmp isr_common_stub
  172. ;17 Allignment Check Exception
  173. _isr17:
  174. cli
  175. push byte 0
  176. push byte 17
  177. jmp isr_common_stub
  178. ;18 Machine Check Exception
  179. _isr18:
  180. cli
  181. push byte 0
  182. push byte 18
  183. jmp isr_common_stub
  184. ;19 reserved
  185. _isr19:
  186. cli
  187. push byte 0
  188. push byte 19
  189. jmp isr_common_stub
  190. ;20 reserved
  191. _isr20:
  192. cli
  193. push byte 0
  194. push byte 20
  195. jmp isr_common_stub
  196. ;21 reserved
  197. _isr21:
  198. cli
  199. push byte 0
  200. push byte 21
  201. jmp isr_common_stub
  202. ;22 reserved
  203. _isr22:
  204. cli
  205. push byte 0
  206. push byte 22
  207. jmp isr_common_stub
  208. ;23 reserved
  209. _isr23:
  210. cli
  211. push byte 0
  212. push byte 23
  213. jmp isr_common_stub
  214. ;24 reserved
  215. _isr24:
  216. cli
  217. push byte 0
  218. push byte 24
  219. jmp isr_common_stub
  220. ;25 reserved
  221. _isr25:
  222. cli
  223. push byte 0
  224. push byte 25
  225. jmp isr_common_stub
  226. ;26 reserved
  227. _isr26:
  228. cli
  229. push byte 0
  230. push byte 26
  231. jmp isr_common_stub
  232. ;27 reserved
  233. _isr27:
  234. cli
  235. push byte 0
  236. push byte 27
  237. jmp isr_common_stub
  238. ;28 reserved
  239. _isr28:
  240. cli
  241. push byte 0
  242. push byte 28
  243. jmp isr_common_stub
  244. ;29 reserved
  245. _isr29:
  246. cli
  247. push byte 0
  248. push byte 29
  249. jmp isr_common_stub
  250. ;30 reserved
  251. _isr30:
  252. cli
  253. push byte 0
  254. push byte 30
  255. jmp isr_common_stub
  256. ;31 reserved
  257. _isr31:
  258. cli
  259. push byte 0
  260. push byte 31
  261. jmp isr_common_stub
  262. ;============================IRQs====================
  263. ; 32: IRQ0
  264. extern task_switch
  265. extern end_irq
  266. _irq0:
  267. cli
  268. push byte 0 ; Note that these don't push an error code on the stack:
  269. ; We need to push a dummy error code
  270. push byte 32
  271. ; jmp irq_common_stub
  272. pusha
  273. push ds
  274. push es
  275. push fs
  276. push gs
  277. mov ax, 0x10
  278. mov ds, ax
  279. mov es, ax
  280. mov fs, ax
  281. mov gs, ax
  282. mov eax, esp ; save esp in eax
  283. push eax ; push it on the stack so that we will get the whole stack
  284. ; inside the irq handler
  285. mov eax, _irq_handler ;; call the irq_handler C function
  286. call eax ; the call will not change the eip
  287. pop eax ; here recall the esp as it was before the call
  288. ; irq_handler
  289. mov esp,eax
  290. mov eax,esp
  291. push eax
  292. call task_switch
  293. mov esp,eax
  294. pop gs
  295. pop fs
  296. pop es
  297. pop ds
  298. popa
  299. add esp, 8
  300. sti
  301. iret
  302. ; 33: IRQ1
  303. _irq1:
  304. cli
  305. push byte 0 ; Note that these don't push an error code on the stack:
  306. ; We need to push a dummy error code
  307. push byte 33
  308. jmp irq_common_stub
  309. ; 34: IRQ2
  310. _irq2:
  311. cli
  312. push byte 0 ; Note that these don't push an error code on the stack:
  313. ; We need to push a dummy error code
  314. push byte 34
  315. jmp irq_common_stub
  316. ; 35: IRQ3
  317. _irq3:
  318. cli
  319. push byte 0 ; Note that these don't push an error code on the stack:
  320. ; We need to push a dummy error code
  321. push byte 35
  322. jmp irq_common_stub
  323. ; 36: IRQ4
  324. _irq4:
  325. cli
  326. push byte 0 ; Note that these don't push an error code on the stack:
  327. ; We need to push a dummy error code
  328. push byte 36
  329. jmp irq_common_stub
  330. ; 37: IRQ5
  331. _irq5:
  332. cli
  333. push byte 0 ; Note that these don't push an error code on the stack:
  334. ; We need to push a dummy error code
  335. push byte 37
  336. jmp irq_common_stub
  337. ; 38: IRQ6
  338. _irq6:
  339. cli
  340. push byte 0 ; Note that these don't push an error code on the stack:
  341. ; We need to push a dummy error code
  342. push byte 38
  343. jmp irq_common_stub
  344. ; 39: IRQ7
  345. _irq7:
  346. cli
  347. push byte 0 ; Note that these don't push an error code on the stack:
  348. ; We need to push a dummy error code
  349. push byte 39
  350. jmp irq_common_stub
  351. ; 40: IRQ8
  352. _irq8:
  353. cli
  354. push byte 0 ; Note that these don't push an error code on the stack:
  355. ; We need to push a dummy error code
  356. push byte 40
  357. jmp irq_common_stub
  358. ; 41: IRQ9
  359. _irq9:
  360. cli
  361. push byte 0 ; Note that these don't push an error code on the stack:
  362. ; We need to push a dummy error code
  363. push byte 41
  364. jmp irq_common_stub
  365. ; 42: IRQ10
  366. _irq10:
  367. cli
  368. push byte 0 ; Note that these don't push an error code on the stack:
  369. ; We need to push a dummy error code
  370. push byte 42
  371. jmp irq_common_stub
  372. ; 43: IRQ11
  373. _irq11:
  374. cli
  375. push byte 0 ; Note that these don't push an error code on the stack:
  376. ; We need to push a dummy error code
  377. push byte 43
  378. jmp irq_common_stub
  379. ; 44: IRQ12
  380. _irq12:
  381. cli
  382. push byte 0 ; Note that these don't push an error code on the stack:
  383. ; We need to push a dummy error code
  384. push byte 44
  385. jmp irq_common_stub
  386. ; 45: IRQ13
  387. _irq13:
  388. cli
  389. push byte 0 ; Note that these don't push an error code on the stack:
  390. ; We need to push a dummy error code
  391. push byte 45
  392. jmp irq_common_stub
  393. ; 46: IRQ14
  394. _irq14:
  395. cli
  396. push byte 0 ; Note that these don't push an error code on the stack:
  397. ; We need to push a dummy error code
  398. push byte 46
  399. jmp irq_common_stub
  400. ; 47: IRQ15
  401. _irq15:
  402. cli
  403. push byte 0 ; Note that these don't push an error code on the stack:
  404. ; We need to push a dummy error code
  405. push byte 47
  406. jmp irq_common_stub
  407. ; This is a stub that we have created for IRQ based ISRs. This calls
  408. ; '_irq_handler' in our C code. We need to create this in an 'irq.c'
  409. irq_common_stub:
  410. pusha
  411. push ds
  412. push es
  413. push fs
  414. push gs
  415. mov ax, 0x10
  416. mov ds, ax
  417. mov es, ax
  418. mov fs, ax
  419. mov gs, ax
  420. mov eax, esp ; save esp in eax
  421. push eax ; push it on the stack so that we will get the whole stack
  422. ; inside the irq handler
  423. mov eax, _irq_handler ;; call the irq_handler C function
  424. call eax ; the call will not change the eip
  425. pop eax ; here recall the esp as it was before the call
  426. ; irq_handler
  427. pop gs
  428. pop fs
  429. pop es
  430. pop ds
  431. popa
  432. add esp, 8
  433. iret
  434. ; We call a C function in here. We need to let the assembler know
  435. ; that '_fault_handler' exists in another file
  436. extern _fault_handler
  437. ; This is our common ISR stub. It saves the processor state, sets
  438. ; up for kernel mode segments, calls the C-level fault handler,
  439. ; and finally restores the stack frame.
  440. isr_common_stub:
  441. pusha
  442. push ds
  443. push es
  444. push fs
  445. push gs
  446. mov ax, 0x10 ; Load the Kernel Data Segment descriptor!
  447. mov ds, ax
  448. mov es, ax
  449. mov fs, ax
  450. mov gs, ax
  451. mov eax, esp ; Push us the stack
  452. push eax
  453. mov eax, _fault_handler
  454. call eax ; A special call, preserves the 'eip' register
  455. pop eax
  456. pop gs
  457. pop fs
  458. pop es
  459. pop ds
  460. popa
  461. add esp, 8 ; Cleans up the pushed error code and pushed ISR number
  462. iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP!
  463. read_eip:
  464. pop eax
  465. jmp eax