timer.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* IRQ stubs: save state, call C handler, restore, iret.
  2. PIT stub (pit_irq_stub) lives in switch.S for context switching. */
  3. .code32
  4. .text
  5. .include "irqret.inc"
  6. .extern lapic_eoi
  7. .globl kbd_irq_stub
  8. kbd_irq_stub:
  9. pusha
  10. /* Reload the kernel data segment: this IRQ can fire while a ring-3
  11. * process runs, in which case DS is null (IRET reset it). */
  12. movw $0x10, %ax
  13. movw %ax, %ds
  14. movw %ax, %es
  15. movw %ax, %fs
  16. movw $0x28, %ax
  17. movw %ax, %gs
  18. call kbd_irq
  19. call lapic_eoi
  20. IRQ_RETURN_DS 36
  21. popa
  22. iret
  23. .globl mouse_irq_stub
  24. mouse_irq_stub:
  25. pusha
  26. movw $0x10, %ax
  27. movw %ax, %ds
  28. movw %ax, %es
  29. movw %ax, %fs
  30. movw $0x28, %ax
  31. movw %ax, %gs
  32. call mouse_irq
  33. call lapic_eoi
  34. IRQ_RETURN_DS 36
  35. popa
  36. iret
  37. .globl fdc_irq_stub
  38. fdc_irq_stub:
  39. pusha
  40. movw $0x10, %ax
  41. movw %ax, %ds
  42. movw %ax, %es
  43. movw %ax, %fs
  44. movw $0x28, %ax
  45. movw %ax, %gs
  46. call fdc_irq
  47. call lapic_eoi
  48. IRQ_RETURN_DS 36
  49. popa
  50. iret
  51. /* Default IRQ handler: send both EOIs and return. Catches spurious and
  52. unexpected hardware interrupts that would otherwise triple-fault. */
  53. .globl default_irq_stub
  54. default_irq_stub:
  55. pusha
  56. movw $0x10, %ax
  57. movw %ax, %ds
  58. movw %ax, %es
  59. movw %ax, %fs
  60. movw $0x28, %ax
  61. movw %ax, %gs
  62. call lapic_eoi
  63. movb $0x20, %al
  64. outb %al, $0x20
  65. IRQ_RETURN_DS 36
  66. popa
  67. iret
  68. /* CPU exception stubs (vectors 0-31). The handler never returns; it gets a
  69. * pointer to a struct exc_state (panic.h): the saved GPRs plus the CPU's
  70. * exception frame (vector, error code, EIP, CS, EFLAGS, [user ESP, SS]). */
  71. .macro exc_no_err vec
  72. exc_stub_\vec:
  73. pushl $0 /* the CPU pushes no error code: supply a zero */
  74. pushl $\vec
  75. jmp exc_common
  76. .endm
  77. .macro exc_err vec
  78. exc_stub_\vec:
  79. pushl $\vec /* the CPU's error code is already on the stack */
  80. jmp exc_common
  81. .endm
  82. exc_no_err 0
  83. exc_no_err 1
  84. exc_no_err 2
  85. exc_no_err 3
  86. exc_no_err 4
  87. exc_no_err 5
  88. exc_no_err 6
  89. exc_no_err 7
  90. exc_err 8
  91. exc_no_err 9
  92. exc_err 10
  93. exc_err 11
  94. exc_err 12
  95. exc_err 13
  96. exc_err 14
  97. exc_no_err 15
  98. exc_no_err 16
  99. exc_err 17
  100. exc_no_err 18
  101. exc_no_err 19
  102. exc_no_err 20
  103. exc_no_err 21
  104. exc_no_err 22
  105. exc_no_err 23
  106. exc_no_err 24
  107. exc_no_err 25
  108. exc_no_err 26
  109. exc_no_err 27
  110. exc_no_err 28
  111. exc_no_err 29
  112. exc_no_err 30
  113. exc_no_err 31
  114. exc_common:
  115. /* Load the kernel data segment: exceptions only switch CS, and DS may be
  116. * null (IRET reset it to null when returning to ring-3), which would make
  117. * the C handler's string/data accesses fault. */
  118. pushl %eax
  119. movw $0x10, %ax
  120. movw %ax, %ds
  121. movw %ax, %es
  122. movw %ax, %fs
  123. movw $0x28, %ax
  124. movw %ax, %gs
  125. popl %eax
  126. /* Layout at %esp must match struct exc_state (panic.h). */
  127. pusha /* GPRs exactly as they were at the fault */
  128. movl %esp, %eax
  129. pushl %eax /* exc_handler(struct exc_state *st) */
  130. call exc_handler
  131. cli
  132. 1: hlt
  133. jmp 1b
  134. /* Lookup table so C can iterate over the 32 stubs. */
  135. .section .rodata
  136. .globl exc_stub_table
  137. exc_stub_table:
  138. .long exc_stub_0, exc_stub_1, exc_stub_2, exc_stub_3
  139. .long exc_stub_4, exc_stub_5, exc_stub_6, exc_stub_7
  140. .long exc_stub_8, exc_stub_9, exc_stub_10, exc_stub_11
  141. .long exc_stub_12, exc_stub_13, exc_stub_14, exc_stub_15
  142. .long exc_stub_16, exc_stub_17, exc_stub_18, exc_stub_19
  143. .long exc_stub_20, exc_stub_21, exc_stub_22, exc_stub_23
  144. .long exc_stub_24, exc_stub_25, exc_stub_26, exc_stub_27
  145. .long exc_stub_28, exc_stub_29, exc_stub_30, exc_stub_31