2 * Copyright (c) 2016 The FreeBSD Foundation
5 * This software was developed by Konstantin Belousov under sponsorship
6 * from the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .globl EXC\N\()_handler
70 cmpq %rsp,exc_rsp(%rip)
74 * Interrupt, not exception.
75 * First, copy the hardware interrupt frame to the previous stack.
76 * Our handler always has private IST stack.
78 movq (6*8)(%rsp),%rax /* saved %rsp value, AKA old stack */
80 movq (3*8)(%rsp),%rdx /* copy %rip to old stack */
82 movq (4*8)(%rsp),%rdx /* copy %cs */
84 movq (5*8)(%rsp),%rdx /* copy %rflags */
86 movq (6*8)(%rsp),%rdx /* copy %rsp */
88 movq (7*8)(%rsp),%rdx /* copy %ss */
92 * Now simulate invocation of the original interrupt handler
93 * with retq. We switch stacks and execute retq from the old
94 * stack since there is no free registers at the last moment.
97 leaq fw_intr_handlers(%rip),%rdx
98 movq (%rdx,%rcx,8),%rdx /* push intr handler address on old stack */
100 movq (2*8)(%rsp),%rcx /* saved %rax is put on top of old stack */
105 movq 32(%rsp),%rsp /* switch to old stack */
111 * Form the struct trapframe on our IST stack.
112 * Skip three words, which are currently busy with temporal
132 * Move %rax, %rdx, %rcx values into the final location,
133 * from the three words which were skipped above.
136 movq %rax,0x30(%rsp) /* tf_rax */
138 movq %rax,0x18(%rsp) /* tf_rcx */
140 movq %rax,0x10(%rsp) /* tf_rdx */
143 * And fill the three words themself.
146 movq %rax,0x80(%rsp) /* tf_addr */
147 movl %ecx,0x78(%rsp) /* tf_trapno */
152 movw $0,0x88(%rsp) /* tf_flags */
161 * Hang after reporting. Interrupts are already disabled.