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

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

enable the timer (not yet calibrated)

File size: 3.5 KB
Line 
1/*
2 * hal_kentry.S - Entry points into the kernel (traps, 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_trap_entry
37        .globl  hal_timer_intr
38        .type   hal_trap_entry, @function
39        .type   hal_timer_intr, @function
40
41        /*
42         * General exceptions.
43         */
44ASM_ENTRY(x86_trap00)
45        ZTRAPENTRY(T_DIVIDE)
46
47ASM_ENTRY(x86_trap01)
48        ZTRAPENTRY(T_TRCTRAP)
49
50ASM_ENTRY(x86_trap02)
51        ZTRAPENTRY(T_NMI)
52
53ASM_ENTRY(x86_trap03)
54        ZTRAPENTRY(T_BPTFLT)
55
56ASM_ENTRY(x86_trap04)
57        ZTRAPENTRY(T_OFLOW)
58
59ASM_ENTRY(x86_trap05)
60        ZTRAPENTRY(T_BOUND)
61
62ASM_ENTRY(x86_trap06)
63        ZTRAPENTRY(T_PRIVINFLT)
64
65ASM_ENTRY(x86_trap07)
66        ZTRAPENTRY(T_DNA)
67
68ASM_ENTRY(x86_trap08)
69        TRAPENTRY(T_DOUBLEFLT)
70
71ASM_ENTRY(x86_trap09)
72        ZTRAPENTRY(T_FPOPFLT)
73
74ASM_ENTRY(x86_trap0a)
75        TRAPENTRY(T_TSSFLT)
76
77ASM_ENTRY(x86_trap0b)
78        TRAPENTRY(T_SEGNPFLT)
79
80ASM_ENTRY(x86_trap0c)
81        TRAPENTRY(T_STKFLT)
82
83ASM_ENTRY(x86_trap0d)
84        TRAPENTRY(T_PROTFLT)
85
86ASM_ENTRY(x86_trap0e)
87        TRAPENTRY(T_PAGEFLT)
88
89ASM_ENTRY(x86_trap0f)
90        ZTRAPENTRY(T_ASTFLT)
91
92ASM_ENTRY(x86_trap10)
93        ZTRAPENTRY(T_ARITHTRAP)
94
95ASM_ENTRY(x86_trap11)
96        TRAPENTRY(T_ALIGNFLT)
97
98ASM_ENTRY(x86_trap12)
99        ZTRAPENTRY(T_MCA)
100
101ASM_ENTRY(x86_trap13)
102        ZTRAPENTRY(T_XMM)
103
104ASM_ENTRY(x86_trap14)
105ASM_ENTRY(x86_trap15)
106ASM_ENTRY(x86_trap16)
107ASM_ENTRY(x86_trap17)
108ASM_ENTRY(x86_trap18)
109ASM_ENTRY(x86_trap19)
110ASM_ENTRY(x86_trap1a)
111ASM_ENTRY(x86_trap1b)
112ASM_ENTRY(x86_trap1c)
113ASM_ENTRY(x86_trap1d)
114ASM_ENTRY(x86_trap1e)
115ASM_ENTRY(x86_trap1f)
116ASM_ENTRY(x86_rsvd)
117        /* 20 - 31 reserved for future exp */
118        ZTRAPENTRY(T_RESERVED)
119
120        /*
121         * LAPIC interrupts.
122         */
123ASM_ENTRY(x86_lapic_spurious)
124        ZTRAPENTRY(T_ASTFLT)
125
126ASM_ENTRY(x86_lapic_timer)
127        pushq   $0
128        pushq   $T_ASTFLT
129        INTR_SAVE_REGS
130
131        movq    %rsp,%rdi
132        call    hal_timer_intr
133
134        movq    lapic_va(%rip),%rax
135        movl    $0,LAPIC_EOI(%rax)
136
137        INTR_RESTORE_REGS
138        addq    $16,%rsp
139        iretq
140
141/*
142 * Arguments pushed on the stack:
143 *  tf_trapno
144 *  tf_err: Dummy inserted if not defined
145 *  tf_rip
146 *  tf_cs
147 *  tf_rflags
148 *  tf_rsp
149 *  tf_ss
150 */
151alltraps:
152        movq    %rsp,%rdi
153        call    hal_trap_entry
154        /* NOTREACHED */
155
156        .data
157        .globl  x86_traps
158        .globl  x86_intrs
159        .type   x86_traps, @object
160        .type   x86_intrs, @object
161
162        .align  64
163x86_traps:
164        .quad   x86_trap00, x86_trap01
165        .quad   x86_trap02, x86_trap03
166        .quad   x86_trap04, x86_trap05
167        .quad   x86_trap06, x86_trap07
168        .quad   x86_trap08, x86_trap09
169        .quad   x86_trap0a, x86_trap0b
170        .quad   x86_trap0c, x86_trap0d
171        .quad   x86_trap0e, x86_trap0f
172        .quad   x86_trap10, x86_trap11
173        .quad   x86_trap12, x86_trap13
174        .quad   x86_trap14, x86_trap15
175        .quad   x86_trap16, x86_trap17
176        .quad   x86_trap18, x86_trap19
177        .quad   x86_trap1a, x86_trap1b
178        .quad   x86_trap1c, x86_trap1d
179        .quad   x86_trap1e, x86_trap1f
180
181x86_intrs:
182        .quad   x86_lapic_spurious
183        .quad   x86_lapic_timer
184
Note: See TracBrowser for help on using the repository browser.