timer.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 %ax, %gs
  16. call kbd_irq
  17. IRQ_RETURN_DS 36
  18. popa
  19. iret
  20. .globl fdc_irq_stub
  21. fdc_irq_stub:
  22. pusha
  23. movw $0x10, %ax
  24. movw %ax, %ds
  25. movw %ax, %es
  26. movw %ax, %fs
  27. movw %ax, %gs
  28. call fdc_irq
  29. IRQ_RETURN_DS 36
  30. popa
  31. iret
  32. /* Default IRQ handler: send EOI and return. Catches spurious and
  33. unexpected hardware interrupts that would otherwise triple-fault. */
  34. .globl default_irq_stub
  35. default_irq_stub:
  36. pushl %eax
  37. movb $0x20, %al
  38. outb %al, $0x20
  39. popl %eax
  40. iret
  41. /* CPU exception stubs (vectors 0-31). The handler never returns,
  42. so we don't need to preserve the full frame for iret. */
  43. .macro exc_no_err vec
  44. exc_stub_\vec:
  45. pushl $\vec
  46. jmp exc_common
  47. .endm
  48. .macro exc_err vec
  49. exc_stub_\vec:
  50. addl $4, %esp
  51. pushl $\vec
  52. jmp exc_common
  53. .endm
  54. exc_no_err 0
  55. exc_no_err 1
  56. exc_no_err 2
  57. exc_no_err 3
  58. exc_no_err 4
  59. exc_no_err 5
  60. exc_no_err 6
  61. exc_no_err 7
  62. exc_err 8
  63. exc_no_err 9
  64. exc_err 10
  65. exc_err 11
  66. exc_err 12
  67. exc_err 13
  68. exc_err 14
  69. exc_no_err 15
  70. exc_no_err 16
  71. exc_err 17
  72. exc_no_err 18
  73. exc_no_err 19
  74. exc_no_err 20
  75. exc_no_err 21
  76. exc_no_err 22
  77. exc_no_err 23
  78. exc_no_err 24
  79. exc_no_err 25
  80. exc_no_err 26
  81. exc_no_err 27
  82. exc_no_err 28
  83. exc_no_err 29
  84. exc_no_err 30
  85. exc_no_err 31
  86. exc_common:
  87. /* Load the kernel data segment: exceptions only switch CS, and DS may be
  88. * null (IRET reset it to null when returning to ring-3), which would make
  89. * the C handler's string/data accesses fault. */
  90. pushl %eax
  91. movw $0x10, %ax
  92. movw %ax, %ds
  93. movw %ax, %es
  94. movw %ax, %fs
  95. movw %ax, %gs
  96. popl %eax
  97. pushl 8(%esp) /* CS -> 3rd arg */
  98. pushl 4(%esp) /* vector -> 2nd arg */
  99. pushl 12(%esp) /* faulting EIP -> 1st arg */
  100. call exc_handler /* exc_handler(eip, vector, cs) */
  101. addl $12, %esp
  102. cli
  103. 1: hlt
  104. jmp 1b
  105. /* Lookup table so C can iterate over the 32 stubs. */
  106. .section .rodata
  107. .globl exc_stub_table
  108. exc_stub_table:
  109. .long exc_stub_0, exc_stub_1, exc_stub_2, exc_stub_3
  110. .long exc_stub_4, exc_stub_5, exc_stub_6, exc_stub_7
  111. .long exc_stub_8, exc_stub_9, exc_stub_10, exc_stub_11
  112. .long exc_stub_12, exc_stub_13, exc_stub_14, exc_stub_15
  113. .long exc_stub_16, exc_stub_17, exc_stub_18, exc_stub_19
  114. .long exc_stub_20, exc_stub_21, exc_stub_22, exc_stub_23
  115. .long exc_stub_24, exc_stub_25, exc_stub_26, exc_stub_27
  116. .long exc_stub_28, exc_stub_29, exc_stub_30, exc_stub_31