timer.S 2.9 KB

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