|
1 | | -.set INTERRUPT_HANDLER_SIZE, 16 |
2 | | -.set GS_RSP0, 0 |
3 | | -.set GS_RSP3, 8 |
| 1 | +// Offsets in CpuLocalHead. |
| 2 | +.set GS_RSP0, 0 |
| 3 | +.set GS_RSP3, 8 |
4 | 4 |
|
5 | 5 | .global syscall_entry |
6 | 6 | syscall_entry: |
@@ -78,115 +78,6 @@ syscall_entry: |
78 | 78 | swapgs |
79 | 79 | sysretq |
80 | 80 |
|
81 | | -// |
82 | | -// Interrupt/exception handlers |
83 | | -// |
84 | | -.align INTERRUPT_HANDLER_SIZE |
85 | | -.global interrupt_handlers |
86 | | -interrupt_handlers: |
87 | | -.set i, 0 |
88 | | -.rept 256 |
89 | | -.set handler_start, . |
90 | | -// Exceptions with error code. |
91 | | -.if i == 8 || 10 <= i && i <= 14 || i == 17 |
92 | | - .align INTERRUPT_HANDLER_SIZE |
93 | | - cli |
94 | | - push i |
95 | | - jmp interrupt_common |
96 | | - .align INTERRUPT_HANDLER_SIZE |
97 | | -// Interrupts and exceptions without error code. |
98 | | -.else |
99 | | - .align INTERRUPT_HANDLER_SIZE |
100 | | - cli |
101 | | - push 0 // Dummy value as error code. |
102 | | - push i |
103 | | - jmp interrupt_common |
104 | | - .align INTERRUPT_HANDLER_SIZE |
105 | | -.endif |
106 | | - |
107 | | -// Increment the counter. |
108 | | -.set i, i + 1 |
109 | | -.endr |
110 | | - |
111 | | -.extern x64_handle_interrupt |
112 | | -interrupt_common: |
113 | | - // |
114 | | - // The current stack frame: |
115 | | - // |
116 | | - // +--------------------+ |
117 | | - // 48 | SS | |
118 | | - // +--------------------+ |
119 | | - // 40 | RSP | |
120 | | - // +--------------------+ |
121 | | - // 32 | RFLAGS | |
122 | | - // +--------------------+ |
123 | | - // 24 | CS | |
124 | | - // +--------------------+ |
125 | | - // 16 | RIP | |
126 | | - // +--------------------+ |
127 | | - // 8 | Error code | |
128 | | - // +--------------------+ |
129 | | - // 0 | IRQ Number | <- RSP |
130 | | - // +--------------------+ |
131 | | - // |
132 | | - |
133 | | - // Check CS register in the IRET frame to determine if the interrupt has |
134 | | - // occurred in user mode. |
135 | | - test qword ptr [rsp + 24], 3 |
136 | | - jz 1f |
137 | | - swapgs |
138 | | -1: |
139 | | - // Save RDI and set the IRQ number to RDI at once. |
140 | | - xchg rdi, [rsp] |
141 | | - |
142 | | - // Save registers except RDI (we have already saved it above). |
143 | | - push r15 |
144 | | - push r14 |
145 | | - push r13 |
146 | | - push r12 |
147 | | - push r11 |
148 | | - push r10 |
149 | | - push r9 |
150 | | - push r8 |
151 | | - push rbp |
152 | | - push rsi |
153 | | - push rdx |
154 | | - push rcx |
155 | | - push rbx |
156 | | - push rax |
157 | | - |
158 | | - mov rsi, rsp |
159 | | - call x64_handle_interrupt |
160 | | - |
161 | | - pop rax |
162 | | - pop rbx |
163 | | - pop rcx |
164 | | - pop rdx |
165 | | - pop rsi |
166 | | - pop rbp |
167 | | - pop r8 |
168 | | - pop r9 |
169 | | - pop r10 |
170 | | - pop r11 |
171 | | - pop r12 |
172 | | - pop r13 |
173 | | - pop r14 |
174 | | - pop r15 |
175 | | - pop rdi |
176 | | - |
177 | | - // Skip error code. |
178 | | - add rsp, 8 |
179 | | - |
180 | | - // Check CS register in the IRET frame to determine whether the exception |
181 | | - // occur in the userspace. If so, do SWAPGS. |
182 | | - test qword ptr [rsp + 8], 3 |
183 | | - jz 1f |
184 | | - |
185 | | - cli |
186 | | - swapgs |
187 | | -1: |
188 | | - iretq |
189 | | - |
190 | 81 | .global kthread_entry |
191 | 82 | kthread_entry: |
192 | 83 | sti |
|
0 commit comments