source: trunk/hal/x86_64/core/hal_kentry.S @ 145

Last change on this file since 145 was 145, checked in by max@…, 7 years ago

style

File size: 4.7 KB
Line 
1/*
2 * hal_kentry.S - Entry points into the kernel (exceptions/interrupts/syscalls)
3 *
4 * Copyright (c) 2017 Maxime Villard
5 *
6 * This file is part of ALMOS-MKH.
7 *
8 * ALMOS-MKH is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.0 of the License.
11 *
12 * ALMOS-MKH is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#define x86_ASM
23#include <hal_boot.h>
24#include <hal_kentry.h>
25#include <hal_apic.h>
26
27#define TRAPENTRY(a)    \
28        pushq   $(a);   \
29        jmp     alltraps;
30
31#define ZTRAPENTRY(a) \
32        pushq   $0; \
33        TRAPENTRY(a)
34
35        .text
36        .globl  hal_exception_entry
37        .globl  hal_timer_intr
38        .globl  hal_keyboard_intr
39        .type   hal_exception_entry, @function
40        .type   hal_timer_intr, @function
41        .type   hal_keyboard_intr, @function
42
43        /*
44         * General exceptions.
45         */
46ASM_ENTRY(x86_trap00)
47        ZTRAPENTRY(T_DIVIDE)
48
49ASM_ENTRY(x86_trap01)
50        ZTRAPENTRY(T_TRCTRAP)
51
52ASM_ENTRY(x86_trap02)
53        ZTRAPENTRY(T_NMI)
54
55ASM_ENTRY(x86_trap03)
56        ZTRAPENTRY(T_BPTFLT)
57
58ASM_ENTRY(x86_trap04)
59        ZTRAPENTRY(T_OFLOW)
60
61ASM_ENTRY(x86_trap05)
62        ZTRAPENTRY(T_BOUND)
63
64ASM_ENTRY(x86_trap06)
65        ZTRAPENTRY(T_PRIVINFLT)
66
67ASM_ENTRY(x86_trap07)
68        ZTRAPENTRY(T_DNA)
69
70ASM_ENTRY(x86_trap08)
71        TRAPENTRY(T_DOUBLEFLT)
72
73ASM_ENTRY(x86_trap09)
74        ZTRAPENTRY(T_FPOPFLT)
75
76ASM_ENTRY(x86_trap0a)
77        TRAPENTRY(T_TSSFLT)
78
79ASM_ENTRY(x86_trap0b)
80        TRAPENTRY(T_SEGNPFLT)
81
82ASM_ENTRY(x86_trap0c)
83        TRAPENTRY(T_STKFLT)
84
85ASM_ENTRY(x86_trap0d)
86        TRAPENTRY(T_PROTFLT)
87
88ASM_ENTRY(x86_trap0e)
89        TRAPENTRY(T_PAGEFLT)
90
91ASM_ENTRY(x86_trap0f)
92        ZTRAPENTRY(T_ASTFLT)
93
94ASM_ENTRY(x86_trap10)
95        ZTRAPENTRY(T_ARITHTRAP)
96
97ASM_ENTRY(x86_trap11)
98        TRAPENTRY(T_ALIGNFLT)
99
100ASM_ENTRY(x86_trap12)
101        ZTRAPENTRY(T_MCA)
102
103ASM_ENTRY(x86_trap13)
104        ZTRAPENTRY(T_XMM)
105
106ASM_ENTRY(x86_trap14)
107ASM_ENTRY(x86_trap15)
108ASM_ENTRY(x86_trap16)
109ASM_ENTRY(x86_trap17)
110ASM_ENTRY(x86_trap18)
111ASM_ENTRY(x86_trap19)
112ASM_ENTRY(x86_trap1a)
113ASM_ENTRY(x86_trap1b)
114ASM_ENTRY(x86_trap1c)
115ASM_ENTRY(x86_trap1d)
116ASM_ENTRY(x86_trap1e)
117ASM_ENTRY(x86_trap1f)
118ASM_ENTRY(x86_rsvd)
119        /* 20 - 31 reserved for future exp */
120        ZTRAPENTRY(T_RESERVED)
121
122        /*
123         * APIC interrupts.
124         */
125ASM_ENTRY(x86_lapic_spurious)
126        ZTRAPENTRY(T_ASTFLT)
127
128ASM_ENTRY(x86_lapic_timer)
129        pushq   $0
130        pushq   $T_ASTFLT
131        INTR_SAVE_REGS
132
133        movq    %rsp,%rdi
134        call    hal_timer_intr
135
136        movq    lapic_va(%rip),%rax
137        movl    $0,LAPIC_EOI(%rax)
138
139        INTR_RESTORE_REGS
140        addq    $16,%rsp
141        iretq
142
143ASM_ENTRY(x86_ioapic_keyboard)
144        pushq   $0
145        pushq   $T_ASTFLT
146        INTR_SAVE_REGS
147
148        movq    %rsp,%rdi
149        call    hal_keyboard_intr
150
151        movq    lapic_va(%rip),%rax
152        movl    $0,LAPIC_EOI(%rax)
153
154        INTR_RESTORE_REGS
155        addq    $16,%rsp
156        iretq
157
158        /*
159         * The XCU interrupt entries.
160         */
161
162#define XCU_WTI_ENTRY(n)                \
163ASM_ENTRY(x86_xcu_wti_ ## n)            \
164        pushq   $0              ;       \
165        pushq   $T_ASTFLT       ;       \
166        INTR_SAVE_REGS          ;       \
167                                ;       \
168        movq    $(APIC_FAKE_STATUS_WTI|n),CPUVAR(APIC_FAKE_STATUS);     \
169        call    hal_do_interrupt;       \
170                                ;       \
171        INTR_RESTORE_REGS       ;       \
172        addq    $16,%rsp        ;       \
173        iretq
174
175#define XCU_HWI_ENTRY(n)                \
176ASM_ENTRY(x86_xcu_hwi_ ## n)            \
177        pushq   $0              ;       \
178        pushq   $T_ASTFLT       ;       \
179        INTR_SAVE_REGS          ;       \
180                                ;       \
181        movq    $(APIC_FAKE_STATUS_HWI|n),CPUVAR(APIC_FAKE_STATUS);     \
182        call    hal_do_interrupt;       \
183                                ;       \
184        INTR_RESTORE_REGS       ;       \
185        addq    $16,%rsp        ;       \
186        iretq
187
188#define XCU_PTI_ENTRY(n)                \
189ASM_ENTRY(x86_xcu_pti_ ## n)            \
190        pushq   $0              ;       \
191        pushq   $T_ASTFLT       ;       \
192        INTR_SAVE_REGS          ;       \
193                                ;       \
194        movq    $(APIC_FAKE_STATUS_PTI|n),CPUVAR(APIC_FAKE_STATUS);     \
195        call    hal_do_interrupt;       \
196                                ;       \
197        INTR_RESTORE_REGS       ;       \
198        addq    $16,%rsp        ;       \
199        iretq
200
201XCU_WTI_ENTRY(0)
202XCU_HWI_ENTRY(0)
203XCU_PTI_ENTRY(0)
204
205/*
206 * Arguments pushed on the stack:
207 *  tf_trapno
208 *  tf_err: Dummy inserted if not defined
209 *  tf_rip
210 *  tf_cs
211 *  tf_rflags
212 *  tf_rsp
213 *  tf_ss
214 */
215alltraps:
216        movq    %rsp,%rdi
217        call    hal_exception_entry
218        /* NOTREACHED */
219
220        .data
221        .globl  x86_traps
222        .globl  x86_intrs
223        .type   x86_traps, @object
224        .type   x86_intrs, @object
225
226        .align  64
227x86_traps:
228        .quad   x86_trap00, x86_trap01
229        .quad   x86_trap02, x86_trap03
230        .quad   x86_trap04, x86_trap05
231        .quad   x86_trap06, x86_trap07
232        .quad   x86_trap08, x86_trap09
233        .quad   x86_trap0a, x86_trap0b
234        .quad   x86_trap0c, x86_trap0d
235        .quad   x86_trap0e, x86_trap0f
236        .quad   x86_trap10, x86_trap11
237        .quad   x86_trap12, x86_trap13
238        .quad   x86_trap14, x86_trap15
239        .quad   x86_trap16, x86_trap17
240        .quad   x86_trap18, x86_trap19
241        .quad   x86_trap1a, x86_trap1b
242        .quad   x86_trap1c, x86_trap1d
243        .quad   x86_trap1e, x86_trap1f
244
245x86_intrs:
246        .quad   x86_lapic_spurious
247        .quad   x86_xcu_wti_0
248        .quad   x86_xcu_hwi_0
249        .quad   x86_xcu_pti_0
250
251        .quad   x86_lapic_timer
252        .quad   x86_ioapic_keyboard
253
Note: See TracBrowser for help on using the repository browser.