interrupt.s 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. .code32
  2. .text
  3. # TODO: stack alignment
  4. .globl int6
  5. .type int6 @function
  6. int6:
  7. pushal
  8. call int6_handler
  9. popal
  10. iret
  11. # TODO: stack alignment
  12. .globl int8
  13. .type int8 @function
  14. int8:
  15. nop
  16. iret
  17. # TODO: stack alignment
  18. .globl int13
  19. .type int13 @function
  20. int13:
  21. pushal
  22. call int13_handler
  23. popal
  24. # remove the 32bit error code from stack
  25. addl $4, %esp
  26. iret
  27. .globl int14
  28. .type int14 @function
  29. int14:
  30. pushal
  31. movl %cr2, %eax
  32. pushl %eax
  33. # stack alignment and push *data
  34. movl %esp, %eax
  35. subl $0x4, %esp
  36. andl $0xfffffff0, %esp
  37. movl %eax, (%esp)
  38. call int14_handler
  39. # restore stack
  40. popl %esp
  41. popl %eax
  42. popal
  43. # remove the 32bit error code from stack
  44. addl $4, %esp
  45. iret
  46. .globl irq0
  47. .type irq0 @function
  48. irq0:
  49. pushal
  50. # stack alignment and push *data
  51. movl %esp, %eax
  52. subl $0x4, %esp
  53. andl $0xfffffff0, %esp
  54. movl %eax, (%esp)
  55. call irq0_handler
  56. # restore stack
  57. popl %esp
  58. popal
  59. iret
  60. .globl irq1
  61. .type irq1 @function
  62. irq1:
  63. pushal
  64. call irq1_handler
  65. popal
  66. iret
  67. .globl irq2
  68. .type irq2 @function
  69. irq2:
  70. pushal
  71. call irq2_handler
  72. popal
  73. iret
  74. .globl irq3
  75. .type irq3 @function
  76. irq3:
  77. pushal
  78. call irq3_handler
  79. popal
  80. iret
  81. .globl irq4
  82. .type irq4 @function
  83. irq4:
  84. pushal
  85. call irq4_handler
  86. popal
  87. iret
  88. .globl irq5
  89. .type irq5 @function
  90. irq5:
  91. pushal
  92. call irq5_handler
  93. popal
  94. iret
  95. .globl irq6
  96. .type irq6 @function
  97. irq6:
  98. pushal
  99. call irq6_handler
  100. popal
  101. iret
  102. .globl irq7
  103. .type irq7 @function
  104. irq7:
  105. pushal
  106. call irq7_handler
  107. popal
  108. iret
  109. .globl irq8
  110. .type irq8 @function
  111. irq8:
  112. pushal
  113. call irq8_handler
  114. popal
  115. iret
  116. .globl irq9
  117. .type irq9 @function
  118. irq9:
  119. pushal
  120. call irq9_handler
  121. popal
  122. iret
  123. .globl irq10
  124. .type irq10 @function
  125. irq10:
  126. pushal
  127. call irq10_handler
  128. popal
  129. iret
  130. .globl irq11
  131. .type irq11 @function
  132. irq11:
  133. pushal
  134. call irq11_handler
  135. popal
  136. iret
  137. .globl irq12
  138. .type irq12 @function
  139. irq12:
  140. pushal
  141. call irq12_handler
  142. popal
  143. iret
  144. .globl irq13
  145. .type irq13 @function
  146. irq13:
  147. pushal
  148. call irq13_handler
  149. popal
  150. iret
  151. .globl irq14
  152. .type irq14 @function
  153. irq14:
  154. pushal
  155. call irq14_handler
  156. popal
  157. iret
  158. .globl irq15
  159. .type irq15 @function
  160. irq15:
  161. pushal
  162. call irq15_handler
  163. popal
  164. iret
  165. .globl syscall_stub
  166. .type syscall_stub @function
  167. syscall_stub:
  168. pushal
  169. # stack alignment and push *data
  170. movl %esp, %eax
  171. subl $0x4, %esp
  172. andl $0xfffffff0, %esp
  173. movl %eax, (%esp)
  174. call syscall_entry
  175. # restore stack
  176. popl %esp
  177. .globl _syscall_stub_fork_return
  178. .type _syscall_stub_fork_return @function
  179. _syscall_stub_fork_return:
  180. popal
  181. iret
  182. # parameters
  183. # #1: uint32_t* curr_esp
  184. # #2: uint32_t next_esp
  185. .globl asm_ctx_switch
  186. .type asm_ctx_switch @function
  187. asm_ctx_switch:
  188. movl 4(%esp), %ecx
  189. movl 8(%esp), %eax
  190. push $_ctx_switch_return
  191. push %ebx
  192. push %edi
  193. push %esi
  194. push %ebp
  195. pushfl
  196. movl %esp, (%ecx)
  197. movl %eax, %esp
  198. popfl
  199. pop %ebp
  200. pop %esi
  201. pop %edi
  202. pop %ebx
  203. ret
  204. _ctx_switch_return:
  205. ret
  206. .section .text.kinit
  207. .globl asm_load_idt
  208. .type asm_load_idt @function
  209. asm_load_idt:
  210. movl 4(%esp), %edx
  211. lidt (%edx)
  212. movl 8(%esp), %edx
  213. cmpl $0, %edx
  214. je asm_load_idt_skip
  215. sti
  216. asm_load_idt_skip:
  217. ret