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

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

Handle the return from exception.

File size: 4.5 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  ioc_ata_isr
39        .globl  hal_com1_intr
40        .globl  hal_keyboard_intr
41        .type   hal_exception_entry, @function
42        .type   hal_timer_intr, @function
43        .type   ioc_ata_isr, @function
44        .type   hal_com1_intr, @function
45        .type   hal_keyboard_intr, @function
46
47        /*
48         * Syscall.
49         */
50ASM_ENTRY(x86_syscall)
51        /* for now, panic */
52        ZTRAPENTRY(T_RESERVED)
53
54ASM_ENTRY(x86_syscall32)
55        /* for now, panic */
56        ZTRAPENTRY(T_RESERVED)
57
58        /*
59         * General exceptions.
60         */
61ASM_ENTRY(x86_trap00)
62        ZTRAPENTRY(T_DIVIDE)
63
64ASM_ENTRY(x86_trap01)
65        ZTRAPENTRY(T_TRCTRAP)
66
67ASM_ENTRY(x86_trap02)
68        ZTRAPENTRY(T_NMI)
69
70ASM_ENTRY(x86_trap03)
71        ZTRAPENTRY(T_BPTFLT)
72
73ASM_ENTRY(x86_trap04)
74        ZTRAPENTRY(T_OFLOW)
75
76ASM_ENTRY(x86_trap05)
77        ZTRAPENTRY(T_BOUND)
78
79ASM_ENTRY(x86_trap06)
80        ZTRAPENTRY(T_PRIVINFLT)
81
82ASM_ENTRY(x86_trap07)
83        ZTRAPENTRY(T_DNA)
84
85ASM_ENTRY(x86_trap08)
86        TRAPENTRY(T_DOUBLEFLT)
87
88ASM_ENTRY(x86_trap09)
89        ZTRAPENTRY(T_FPOPFLT)
90
91ASM_ENTRY(x86_trap0a)
92        TRAPENTRY(T_TSSFLT)
93
94ASM_ENTRY(x86_trap0b)
95        TRAPENTRY(T_SEGNPFLT)
96
97ASM_ENTRY(x86_trap0c)
98        TRAPENTRY(T_STKFLT)
99
100ASM_ENTRY(x86_trap0d)
101        TRAPENTRY(T_PROTFLT)
102
103ASM_ENTRY(x86_trap0e)
104        TRAPENTRY(T_PAGEFLT)
105
106ASM_ENTRY(x86_trap0f)
107        ZTRAPENTRY(T_ASTFLT)
108
109ASM_ENTRY(x86_trap10)
110        ZTRAPENTRY(T_ARITHTRAP)
111
112ASM_ENTRY(x86_trap11)
113        TRAPENTRY(T_ALIGNFLT)
114
115ASM_ENTRY(x86_trap12)
116        ZTRAPENTRY(T_MCA)
117
118ASM_ENTRY(x86_trap13)
119        ZTRAPENTRY(T_XMM)
120
121ASM_ENTRY(x86_trap14)
122ASM_ENTRY(x86_trap15)
123ASM_ENTRY(x86_trap16)
124ASM_ENTRY(x86_trap17)
125ASM_ENTRY(x86_trap18)
126ASM_ENTRY(x86_trap19)
127ASM_ENTRY(x86_trap1a)
128ASM_ENTRY(x86_trap1b)
129ASM_ENTRY(x86_trap1c)
130ASM_ENTRY(x86_trap1d)
131ASM_ENTRY(x86_trap1e)
132ASM_ENTRY(x86_trap1f)
133ASM_ENTRY(x86_rsvd)
134        /* 20 - 31 reserved for future exp */
135        ZTRAPENTRY(T_RESERVED)
136
137        /*
138         * APIC interrupts.
139         */
140ASM_ENTRY(x86_lapic_spurious)
141        ZTRAPENTRY(T_ASTFLT)
142
143ASM_ENTRY(x86_lapic_timer)
144        pushq   $0
145        pushq   $T_ASTFLT
146        INTR_SAVE_REGS
147
148        movq    lapic_va(%rip),%rax
149        movl    $0,LAPIC_EOI(%rax)
150
151        movq    %rsp,%rdi
152        call    hal_timer_intr
153
154        INTR_RESTORE_REGS
155        addq    $16,%rsp
156        iretq
157
158ASM_ENTRY(x86_ioapic_ata0)
159        pushq   $0
160        pushq   $T_ASTFLT
161        INTR_SAVE_REGS
162
163        movq    %rsp,%rdi
164        call    ioc_ata_isr
165
166        movq    lapic_va(%rip),%rax
167        movl    $0,LAPIC_EOI(%rax)
168
169        INTR_RESTORE_REGS
170        addq    $16,%rsp
171        iretq
172
173ASM_ENTRY(x86_ioapic_com1)
174        pushq   $0
175        pushq   $T_ASTFLT
176        INTR_SAVE_REGS
177
178        movq    %rsp,%rdi
179        call    hal_com1_intr
180
181        movq    lapic_va(%rip),%rax
182        movl    $0,LAPIC_EOI(%rax)
183
184        INTR_RESTORE_REGS
185        addq    $16,%rsp
186        iretq
187
188ASM_ENTRY(x86_ioapic_keyboard)
189        pushq   $0
190        pushq   $T_ASTFLT
191        INTR_SAVE_REGS
192
193        movq    %rsp,%rdi
194        call    hal_keyboard_intr
195
196        movq    lapic_va(%rip),%rax
197        movl    $0,LAPIC_EOI(%rax)
198
199        INTR_RESTORE_REGS
200        addq    $16,%rsp
201        iretq
202
203/*
204 * Common entry point for exceptions.
205 */
206alltraps:
207        INTR_SAVE_REGS
208
209        movq    %rsp,%rdi
210        call    hal_exception_entry
211
212        movq    lapic_va(%rip),%rax
213        movl    $0,LAPIC_EOI(%rax)
214
215        INTR_RESTORE_REGS
216        addq    $16,%rsp
217        iretq
218
219/*
220 * Variables.
221 */
222        .data
223        .globl  x86_traps
224        .globl  x86_intrs
225        .type   x86_traps, @object
226        .type   x86_intrs, @object
227
228        .align  64
229x86_traps:
230        .quad   x86_trap00, x86_trap01
231        .quad   x86_trap02, x86_trap03
232        .quad   x86_trap04, x86_trap05
233        .quad   x86_trap06, x86_trap07
234        .quad   x86_trap08, x86_trap09
235        .quad   x86_trap0a, x86_trap0b
236        .quad   x86_trap0c, x86_trap0d
237        .quad   x86_trap0e, x86_trap0f
238        .quad   x86_trap10, x86_trap11
239        .quad   x86_trap12, x86_trap13
240        .quad   x86_trap14, x86_trap15
241        .quad   x86_trap16, x86_trap17
242        .quad   x86_trap18, x86_trap19
243        .quad   x86_trap1a, x86_trap1b
244        .quad   x86_trap1c, x86_trap1d
245        .quad   x86_trap1e, x86_trap1f
246
247x86_intrs:
248        .quad   x86_lapic_spurious
249        .quad   x86_lapic_timer
250        .quad   x86_ioapic_com1
251        .quad   x86_ioapic_keyboard
252
Note: See TracBrowser for help on using the repository browser.