[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 |
---|
[152] | 38 | .globl hal_com1_intr |
---|
[89] | 39 | .globl hal_keyboard_intr |
---|
[142] | 40 | .type hal_exception_entry, @function |
---|
[86] | 41 | .type hal_timer_intr, @function |
---|
[152] | 42 | .type hal_com1_intr, @function |
---|
[89] | 43 | .type hal_keyboard_intr, @function |
---|
[25] | 44 | |
---|
[45] | 45 | /* |
---|
| 46 | * General exceptions. |
---|
| 47 | */ |
---|
[29] | 48 | ASM_ENTRY(x86_trap00) |
---|
| 49 | ZTRAPENTRY(T_DIVIDE) |
---|
[25] | 50 | |
---|
[29] | 51 | ASM_ENTRY(x86_trap01) |
---|
| 52 | ZTRAPENTRY(T_TRCTRAP) |
---|
[25] | 53 | |
---|
[29] | 54 | ASM_ENTRY(x86_trap02) |
---|
| 55 | ZTRAPENTRY(T_NMI) |
---|
[25] | 56 | |
---|
[29] | 57 | ASM_ENTRY(x86_trap03) |
---|
| 58 | ZTRAPENTRY(T_BPTFLT) |
---|
[25] | 59 | |
---|
[29] | 60 | ASM_ENTRY(x86_trap04) |
---|
| 61 | ZTRAPENTRY(T_OFLOW) |
---|
[25] | 62 | |
---|
[29] | 63 | ASM_ENTRY(x86_trap05) |
---|
| 64 | ZTRAPENTRY(T_BOUND) |
---|
[25] | 65 | |
---|
[29] | 66 | ASM_ENTRY(x86_trap06) |
---|
| 67 | ZTRAPENTRY(T_PRIVINFLT) |
---|
[25] | 68 | |
---|
[29] | 69 | ASM_ENTRY(x86_trap07) |
---|
| 70 | ZTRAPENTRY(T_DNA) |
---|
[25] | 71 | |
---|
[29] | 72 | ASM_ENTRY(x86_trap08) |
---|
| 73 | TRAPENTRY(T_DOUBLEFLT) |
---|
[25] | 74 | |
---|
[29] | 75 | ASM_ENTRY(x86_trap09) |
---|
| 76 | ZTRAPENTRY(T_FPOPFLT) |
---|
[25] | 77 | |
---|
[29] | 78 | ASM_ENTRY(x86_trap0a) |
---|
| 79 | TRAPENTRY(T_TSSFLT) |
---|
[25] | 80 | |
---|
[29] | 81 | ASM_ENTRY(x86_trap0b) |
---|
[82] | 82 | TRAPENTRY(T_SEGNPFLT) |
---|
[25] | 83 | |
---|
[29] | 84 | ASM_ENTRY(x86_trap0c) |
---|
[82] | 85 | TRAPENTRY(T_STKFLT) |
---|
[25] | 86 | |
---|
[29] | 87 | ASM_ENTRY(x86_trap0d) |
---|
[82] | 88 | TRAPENTRY(T_PROTFLT) |
---|
[25] | 89 | |
---|
[29] | 90 | ASM_ENTRY(x86_trap0e) |
---|
| 91 | TRAPENTRY(T_PAGEFLT) |
---|
[25] | 92 | |
---|
[29] | 93 | ASM_ENTRY(x86_trap0f) |
---|
| 94 | ZTRAPENTRY(T_ASTFLT) |
---|
[25] | 95 | |
---|
[29] | 96 | ASM_ENTRY(x86_trap10) |
---|
| 97 | ZTRAPENTRY(T_ARITHTRAP) |
---|
[25] | 98 | |
---|
[29] | 99 | ASM_ENTRY(x86_trap11) |
---|
| 100 | TRAPENTRY(T_ALIGNFLT) |
---|
[25] | 101 | |
---|
[29] | 102 | ASM_ENTRY(x86_trap12) |
---|
| 103 | ZTRAPENTRY(T_MCA) |
---|
[25] | 104 | |
---|
[29] | 105 | ASM_ENTRY(x86_trap13) |
---|
| 106 | ZTRAPENTRY(T_XMM) |
---|
[25] | 107 | |
---|
[29] | 108 | ASM_ENTRY(x86_trap14) |
---|
| 109 | ASM_ENTRY(x86_trap15) |
---|
| 110 | ASM_ENTRY(x86_trap16) |
---|
| 111 | ASM_ENTRY(x86_trap17) |
---|
| 112 | ASM_ENTRY(x86_trap18) |
---|
| 113 | ASM_ENTRY(x86_trap19) |
---|
| 114 | ASM_ENTRY(x86_trap1a) |
---|
| 115 | ASM_ENTRY(x86_trap1b) |
---|
| 116 | ASM_ENTRY(x86_trap1c) |
---|
| 117 | ASM_ENTRY(x86_trap1d) |
---|
| 118 | ASM_ENTRY(x86_trap1e) |
---|
| 119 | ASM_ENTRY(x86_trap1f) |
---|
[80] | 120 | ASM_ENTRY(x86_rsvd) |
---|
[29] | 121 | /* 20 - 31 reserved for future exp */ |
---|
| 122 | ZTRAPENTRY(T_RESERVED) |
---|
[25] | 123 | |
---|
[45] | 124 | /* |
---|
[89] | 125 | * APIC interrupts. |
---|
[45] | 126 | */ |
---|
[86] | 127 | ASM_ENTRY(x86_lapic_spurious) |
---|
[45] | 128 | ZTRAPENTRY(T_ASTFLT) |
---|
| 129 | |
---|
[86] | 130 | ASM_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 | |
---|
[152] | 145 | ASM_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 | |
---|
[89] | 160 | ASM_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 | |
---|
[138] | 175 | /* |
---|
| 176 | * The XCU interrupt entries. |
---|
| 177 | */ |
---|
| 178 | |
---|
| 179 | #define XCU_WTI_ENTRY(n) \ |
---|
| 180 | ASM_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) \ |
---|
| 192 | ASM_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) \ |
---|
| 204 | ASM_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 | |
---|
| 215 | XCU_WTI_ENTRY(0) |
---|
| 216 | XCU_HWI_ENTRY(0) |
---|
| 217 | XCU_PTI_ENTRY(0) |
---|
| 218 | |
---|
[29] | 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 | */ |
---|
| 229 | alltraps: |
---|
| 230 | movq %rsp,%rdi |
---|
[142] | 231 | call hal_exception_entry |
---|
[29] | 232 | /* NOTREACHED */ |
---|
[25] | 233 | |
---|
[29] | 234 | .data |
---|
| 235 | .globl x86_traps |
---|
[45] | 236 | .globl x86_intrs |
---|
[29] | 237 | .type x86_traps, @object |
---|
[45] | 238 | .type x86_intrs, @object |
---|
[25] | 239 | |
---|
[29] | 240 | .align 64 |
---|
| 241 | x86_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 | |
---|
[45] | 259 | x86_intrs: |
---|
[86] | 260 | .quad x86_lapic_spurious |
---|
[138] | 261 | .quad x86_xcu_wti_0 |
---|
| 262 | .quad x86_xcu_hwi_0 |
---|
| 263 | .quad x86_xcu_pti_0 |
---|
| 264 | |
---|
[86] | 265 | .quad x86_lapic_timer |
---|
[152] | 266 | .quad x86_ioapic_com1 |
---|
[89] | 267 | .quad x86_ioapic_keyboard |
---|
[45] | 268 | |
---|