[25] | 1 | /* |
---|
[145] | 2 | * hal_kentry.S - Entry points into the kernel (exceptions/interrupts/syscalls) |
---|
| 3 | * |
---|
[29] | 4 | * Copyright (c) 2017 Maxime Villard |
---|
[145] | 5 | * |
---|
[25] | 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 |
---|
[29] | 18 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
---|
[25] | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 20 | */ |
---|
| 21 | |
---|
[29] | 22 | #define x86_ASM |
---|
| 23 | #include <hal_boot.h> |
---|
| 24 | #include <hal_kentry.h> |
---|
[86] | 25 | #include <hal_apic.h> |
---|
[25] | 26 | |
---|
[29] | 27 | #define TRAPENTRY(a) \ |
---|
[86] | 28 | pushq $(a); \ |
---|
| 29 | jmp alltraps; |
---|
[25] | 30 | |
---|
[29] | 31 | #define ZTRAPENTRY(a) \ |
---|
[86] | 32 | pushq $0; \ |
---|
[29] | 33 | TRAPENTRY(a) |
---|
[25] | 34 | |
---|
[29] | 35 | .text |
---|
[142] | 36 | .globl hal_exception_entry |
---|
[86] | 37 | .globl hal_timer_intr |
---|
[89] | 38 | .globl hal_keyboard_intr |
---|
[142] | 39 | .type hal_exception_entry, @function |
---|
[86] | 40 | .type hal_timer_intr, @function |
---|
[89] | 41 | .type hal_keyboard_intr, @function |
---|
[25] | 42 | |
---|
[45] | 43 | /* |
---|
| 44 | * General exceptions. |
---|
| 45 | */ |
---|
[29] | 46 | ASM_ENTRY(x86_trap00) |
---|
| 47 | ZTRAPENTRY(T_DIVIDE) |
---|
[25] | 48 | |
---|
[29] | 49 | ASM_ENTRY(x86_trap01) |
---|
| 50 | ZTRAPENTRY(T_TRCTRAP) |
---|
[25] | 51 | |
---|
[29] | 52 | ASM_ENTRY(x86_trap02) |
---|
| 53 | ZTRAPENTRY(T_NMI) |
---|
[25] | 54 | |
---|
[29] | 55 | ASM_ENTRY(x86_trap03) |
---|
| 56 | ZTRAPENTRY(T_BPTFLT) |
---|
[25] | 57 | |
---|
[29] | 58 | ASM_ENTRY(x86_trap04) |
---|
| 59 | ZTRAPENTRY(T_OFLOW) |
---|
[25] | 60 | |
---|
[29] | 61 | ASM_ENTRY(x86_trap05) |
---|
| 62 | ZTRAPENTRY(T_BOUND) |
---|
[25] | 63 | |
---|
[29] | 64 | ASM_ENTRY(x86_trap06) |
---|
| 65 | ZTRAPENTRY(T_PRIVINFLT) |
---|
[25] | 66 | |
---|
[29] | 67 | ASM_ENTRY(x86_trap07) |
---|
| 68 | ZTRAPENTRY(T_DNA) |
---|
[25] | 69 | |
---|
[29] | 70 | ASM_ENTRY(x86_trap08) |
---|
| 71 | TRAPENTRY(T_DOUBLEFLT) |
---|
[25] | 72 | |
---|
[29] | 73 | ASM_ENTRY(x86_trap09) |
---|
| 74 | ZTRAPENTRY(T_FPOPFLT) |
---|
[25] | 75 | |
---|
[29] | 76 | ASM_ENTRY(x86_trap0a) |
---|
| 77 | TRAPENTRY(T_TSSFLT) |
---|
[25] | 78 | |
---|
[29] | 79 | ASM_ENTRY(x86_trap0b) |
---|
[82] | 80 | TRAPENTRY(T_SEGNPFLT) |
---|
[25] | 81 | |
---|
[29] | 82 | ASM_ENTRY(x86_trap0c) |
---|
[82] | 83 | TRAPENTRY(T_STKFLT) |
---|
[25] | 84 | |
---|
[29] | 85 | ASM_ENTRY(x86_trap0d) |
---|
[82] | 86 | TRAPENTRY(T_PROTFLT) |
---|
[25] | 87 | |
---|
[29] | 88 | ASM_ENTRY(x86_trap0e) |
---|
| 89 | TRAPENTRY(T_PAGEFLT) |
---|
[25] | 90 | |
---|
[29] | 91 | ASM_ENTRY(x86_trap0f) |
---|
| 92 | ZTRAPENTRY(T_ASTFLT) |
---|
[25] | 93 | |
---|
[29] | 94 | ASM_ENTRY(x86_trap10) |
---|
| 95 | ZTRAPENTRY(T_ARITHTRAP) |
---|
[25] | 96 | |
---|
[29] | 97 | ASM_ENTRY(x86_trap11) |
---|
| 98 | TRAPENTRY(T_ALIGNFLT) |
---|
[25] | 99 | |
---|
[29] | 100 | ASM_ENTRY(x86_trap12) |
---|
| 101 | ZTRAPENTRY(T_MCA) |
---|
[25] | 102 | |
---|
[29] | 103 | ASM_ENTRY(x86_trap13) |
---|
| 104 | ZTRAPENTRY(T_XMM) |
---|
[25] | 105 | |
---|
[29] | 106 | ASM_ENTRY(x86_trap14) |
---|
| 107 | ASM_ENTRY(x86_trap15) |
---|
| 108 | ASM_ENTRY(x86_trap16) |
---|
| 109 | ASM_ENTRY(x86_trap17) |
---|
| 110 | ASM_ENTRY(x86_trap18) |
---|
| 111 | ASM_ENTRY(x86_trap19) |
---|
| 112 | ASM_ENTRY(x86_trap1a) |
---|
| 113 | ASM_ENTRY(x86_trap1b) |
---|
| 114 | ASM_ENTRY(x86_trap1c) |
---|
| 115 | ASM_ENTRY(x86_trap1d) |
---|
| 116 | ASM_ENTRY(x86_trap1e) |
---|
| 117 | ASM_ENTRY(x86_trap1f) |
---|
[80] | 118 | ASM_ENTRY(x86_rsvd) |
---|
[29] | 119 | /* 20 - 31 reserved for future exp */ |
---|
| 120 | ZTRAPENTRY(T_RESERVED) |
---|
[25] | 121 | |
---|
[45] | 122 | /* |
---|
[89] | 123 | * APIC interrupts. |
---|
[45] | 124 | */ |
---|
[86] | 125 | ASM_ENTRY(x86_lapic_spurious) |
---|
[45] | 126 | ZTRAPENTRY(T_ASTFLT) |
---|
| 127 | |
---|
[86] | 128 | ASM_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 | |
---|
[89] | 143 | ASM_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 | |
---|
[138] | 158 | /* |
---|
| 159 | * The XCU interrupt entries. |
---|
| 160 | */ |
---|
| 161 | |
---|
| 162 | #define XCU_WTI_ENTRY(n) \ |
---|
| 163 | ASM_ENTRY(x86_xcu_wti_ ## n) \ |
---|
| 164 | pushq $0 ; \ |
---|
| 165 | pushq $T_ASTFLT ; \ |
---|
| 166 | INTR_SAVE_REGS ; \ |
---|
| 167 | ; \ |
---|
| 168 | call hal_do_interrupt; \ |
---|
| 169 | ; \ |
---|
| 170 | INTR_RESTORE_REGS ; \ |
---|
| 171 | addq $16,%rsp ; \ |
---|
| 172 | iretq |
---|
| 173 | |
---|
| 174 | #define XCU_HWI_ENTRY(n) \ |
---|
| 175 | ASM_ENTRY(x86_xcu_hwi_ ## n) \ |
---|
| 176 | pushq $0 ; \ |
---|
| 177 | pushq $T_ASTFLT ; \ |
---|
| 178 | INTR_SAVE_REGS ; \ |
---|
| 179 | ; \ |
---|
| 180 | call hal_do_interrupt; \ |
---|
| 181 | ; \ |
---|
| 182 | INTR_RESTORE_REGS ; \ |
---|
| 183 | addq $16,%rsp ; \ |
---|
| 184 | iretq |
---|
| 185 | |
---|
| 186 | #define XCU_PTI_ENTRY(n) \ |
---|
| 187 | ASM_ENTRY(x86_xcu_pti_ ## n) \ |
---|
| 188 | pushq $0 ; \ |
---|
| 189 | pushq $T_ASTFLT ; \ |
---|
| 190 | INTR_SAVE_REGS ; \ |
---|
| 191 | ; \ |
---|
| 192 | call hal_do_interrupt; \ |
---|
| 193 | ; \ |
---|
| 194 | INTR_RESTORE_REGS ; \ |
---|
| 195 | addq $16,%rsp ; \ |
---|
| 196 | iretq |
---|
| 197 | |
---|
| 198 | XCU_WTI_ENTRY(0) |
---|
| 199 | XCU_HWI_ENTRY(0) |
---|
| 200 | XCU_PTI_ENTRY(0) |
---|
| 201 | |
---|
[29] | 202 | /* |
---|
| 203 | * Arguments pushed on the stack: |
---|
| 204 | * tf_trapno |
---|
| 205 | * tf_err: Dummy inserted if not defined |
---|
| 206 | * tf_rip |
---|
| 207 | * tf_cs |
---|
| 208 | * tf_rflags |
---|
| 209 | * tf_rsp |
---|
| 210 | * tf_ss |
---|
| 211 | */ |
---|
| 212 | alltraps: |
---|
| 213 | movq %rsp,%rdi |
---|
[142] | 214 | call hal_exception_entry |
---|
[29] | 215 | /* NOTREACHED */ |
---|
[25] | 216 | |
---|
[29] | 217 | .data |
---|
| 218 | .globl x86_traps |
---|
[45] | 219 | .globl x86_intrs |
---|
[29] | 220 | .type x86_traps, @object |
---|
[45] | 221 | .type x86_intrs, @object |
---|
[25] | 222 | |
---|
[29] | 223 | .align 64 |
---|
| 224 | x86_traps: |
---|
| 225 | .quad x86_trap00, x86_trap01 |
---|
| 226 | .quad x86_trap02, x86_trap03 |
---|
| 227 | .quad x86_trap04, x86_trap05 |
---|
| 228 | .quad x86_trap06, x86_trap07 |
---|
| 229 | .quad x86_trap08, x86_trap09 |
---|
| 230 | .quad x86_trap0a, x86_trap0b |
---|
| 231 | .quad x86_trap0c, x86_trap0d |
---|
| 232 | .quad x86_trap0e, x86_trap0f |
---|
| 233 | .quad x86_trap10, x86_trap11 |
---|
| 234 | .quad x86_trap12, x86_trap13 |
---|
| 235 | .quad x86_trap14, x86_trap15 |
---|
| 236 | .quad x86_trap16, x86_trap17 |
---|
| 237 | .quad x86_trap18, x86_trap19 |
---|
| 238 | .quad x86_trap1a, x86_trap1b |
---|
| 239 | .quad x86_trap1c, x86_trap1d |
---|
| 240 | .quad x86_trap1e, x86_trap1f |
---|
| 241 | |
---|
[45] | 242 | x86_intrs: |
---|
[86] | 243 | .quad x86_lapic_spurious |
---|
[138] | 244 | .quad x86_xcu_wti_0 |
---|
| 245 | .quad x86_xcu_hwi_0 |
---|
| 246 | .quad x86_xcu_pti_0 |
---|
| 247 | |
---|
[86] | 248 | .quad x86_lapic_timer |
---|
[89] | 249 | .quad x86_ioapic_keyboard |
---|
[45] | 250 | |
---|