timer.S 3.2 KB

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