timer.S 2.5 KB

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