2 * Copyright ( c ) 1989 , 1990 William F . Jolitz.

3 * Copyright ( c ) 1990 The Regents of the University of California.

4 * All rights reserved.

5 * Copyright ( c ) 2014-2018 The FreeBSD Foundation

6 * All rights reserved.

8 * Portions of this software were developed by

9 * Konstantin Belousov < kib @ FreeBSD.org > under sponsorship from

10 * the FreeBSD Foundation.

12 * Redistribution and use in source and binary forms , with or without

13 * modification , are permitted provided that the following conditions

14 * are met :

15 * 1 . Redistributions of source code must retain the above copyright

16 * notice , this list of conditions and the following disclaimer.

17 * 2 . Redistributions in binary form must reproduce the above copyright

18 * notice , this list of conditions and the following disclaimer in the

19 * documentation and / or other materials provided with the distribution.

20 * 4 . Neither the name of the University nor the names of its contributors

21 * may be used to endorse or promote products derived from this software

22 * without specific prior written permission.

24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS '' AND

25 * ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE

26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE

27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE

28 * FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL

29 * DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS

30 * OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION )

31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT

32 * LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY

33 * OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF

34 * SUCH DAMAGE.

36 * from : vector.s , 386 BSD 0.1 unknown origin

37 * $ FreeBSD $

41 * Interrupt entry points for external interrupts triggered by I / O APICs

42 * as well as IPI handlers.

53 #ifdef SMP

54 #define LK lock ;

56 #define LK

61 /* End Of Interrupt to APIC */

63 cmpl $ 0 , x2apic_mode

64 jne 1 f

65 movq lapic_map , %rax

66 movl $0,LA_EOI(% rax )

67 ret

68 1 :

69 movl $ MSR_APIC_EOI , %ecx

70 xorl % eax , %eax

71 xorl % edx , %edx

72 wrmsr

73 ret

76 * I/O Interrupt Entry Point. Rather than having one entry point for

77 * each interrupt source, we use one entry point for each 32-bit word

78 * in the ISR. The handler determines the highest bit set in the ISR,

79 * translates that into a vector, and passes the vector to the

84 FAKE_MCOUNT(TF_RIP(% rsp ))

85 cmpl $ 0 , x2apic_mode

86 je 1 f

87 movl $ ( MSR_APIC_ISR0 + \index ), %ecx

88 rdmsr

89 jmp 2f

91 movq lapic_map, % rdx /* pointer to local APIC */

92 movl LA_ISR + 16 * ( \index )( %rdx), % eax /* load ISR */

93 2 :

94 bsrl %eax, % eax /* index of highest set bit in ISR */

95 jz 3 f

96 addl $ ( 32 * \index ), %eax

97 movq % rsp , %rsi

98 movl % eax , %edi /* pass the IRQ */

99 call lapic_handle_intr

101 MEXITCOUNT

102 jmp doreti

106 * Handle "spurious INTerrupts".

108 * This is different than the "spurious INTerrupt" generated by an

109 * 8259 PIC for missing INTs. See the APIC documentation for details.

110 * This routine should NOT do an 'EOI' cycle.

115 /* No EOI cycle used here */

116 jmp doreti_iret

127 * Local APIC periodic timer handler.

129 INTR_HANDLER timerint

130 FAKE_MCOUNT(TF_RIP(% rsp ))

131 movq %rsp, % rdi

132 call lapic_handle_timer

133 MEXITCOUNT

134 jmp doreti

137 * Local APIC CMCI handler.

139 INTR_HANDLER cmcint

141 call lapic_handle_cmc

142 MEXITCOUNT

143 jmp doreti

146 * Local APIC error interrupt handler.

148 INTR_HANDLER errorint

149 FAKE_MCOUNT(TF_RIP(% rsp ))

150 call lapic_handle_error

151 MEXITCOUNT

152 jmp doreti

154 #ifdef XENHVM

156 * Xen event channel upcall interrupt handler.

157 * Only used when the hypervisor supports direct vector callbacks.

161 movq % rsp , %rdi

162 call xen_intr_handle_upcall

163 MEXITCOUNT

164 jmp doreti

167 #ifdef SMP

169 * Global address space TLB shootdown.

175 call as_lapic_eoi

176 jmp ld_regs

179 INTR_HANDLER invltlb

180 call invltlb_handler

181 jmp invltlb_ret

184 call invltlb_pcid_handler

185 jmp invltlb_ret

188 call invltlb_invpcid_handler

189 jmp invltlb_ret

192 call invltlb_invpcid_pti_handler

193 jmp invltlb_ret

196 * Single page TLB shootdown

198 INTR_HANDLER invlpg

199 call invlpg_handler

200 jmp invltlb_ret

203 call invlpg_invpcid_handler

204 jmp invltlb_ret

207 call invlpg_pcid_handler

208 jmp invltlb_ret

211 * Page range TLB shootdown.

213 INTR_HANDLER invlrng

214 call invlrng_handler

215 jmp invltlb_ret

218 call invlrng_invpcid_handler

219 jmp invltlb_ret

222 call invlrng_pcid_handler

223 jmp invltlb_ret

226 * Invalidate cache.

228 INTR_HANDLER invlcache

229 call invlcache_handler

230 jmp invltlb_ret

233 * Handler for IPIs sent via the per-cpu IPI bitmap.

236 call as_lapic_eoi

237 FAKE_MCOUNT(TF_RIP(% rsp ))

238 call ipi_bitmap_handler

239 MEXITCOUNT

240 jmp doreti

243 * Executed by a CPU when it receives an IPI_STOP from another CPU.

245 INTR_HANDLER cpustop

246 call as_lapic_eoi

247 call cpustop_handler

248 jmp doreti

251 * Executed by a CPU when it receives an IPI_SUSPEND from another CPU.

253 INTR_HANDLER cpususpend

254 call cpususpend_handler

255 call as_lapic_eoi

256 jmp doreti

259 * Executed by a CPU when it receives a RENDEZVOUS IPI from another CPU.

261 * - Calls the generic rendezvous action function.

263 INTR_HANDLER rendezvous

265 movl PCPU ( CPUID ), %eax

266 movq ipi_rendezvous_counts(,% rax , 8 ), %rax

267 incq (% rax )

269 call smp_rendezvous_action

270 call as_lapic_eoi

271 jmp doreti

274 * IPI handler whose purpose is to interrupt the CPU with minimum overhead.

275 * This is used by bhyve to force a host cpu executing in guest context to

276 * trap into the hypervisor.

278 * This handler is different from other IPI handlers in the following aspects :

280 * 1 . It doesn 't push a trapframe on the stack.

282 * This implies that a DDB backtrace involving ' justreturn ' will skip the

283 * function that was interrupted by this handler.

285 * 2. It doesn' t 'swapgs' when userspace is interrupted.

287 * The 'justreturn' handler does not access any pcpu data so it is not an

288 * issue. Moreover the 'justreturn' handler can only be interrupted by an NMI

289 * whose handler already doesn ' t trust GS.base when kernel code is interrupted.

293 IDTVEC ( justreturn )

294 pushq %rax

295 pushq % rcx

296 pushq %rdx

297 call as_lapic_eoi

298 popq % rdx

299 popq %rcx

300 popq % rax

301 jmp doreti_iret

303 INTR_HANDLER justreturn1

304 call as_lapic_eoi

305 jmp doreti