timer.S 3.0 KB

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