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

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

add a basic RS232 COM1 implementation

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