[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 |
---|
[234] | 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 |
---|
[220] | 38 | .globl ioc_ata_isr |
---|
[152] | 39 | .globl hal_com1_intr |
---|
[89] | 40 | .globl hal_keyboard_intr |
---|
[142] | 41 | .type hal_exception_entry, @function |
---|
[86] | 42 | .type hal_timer_intr, @function |
---|
[220] | 43 | .type ioc_ata_isr, @function |
---|
[152] | 44 | .type hal_com1_intr, @function |
---|
[89] | 45 | .type hal_keyboard_intr, @function |
---|
[25] | 46 | |
---|
[45] | 47 | /* |
---|
[308] | 48 | * Syscall. |
---|
| 49 | */ |
---|
| 50 | ASM_ENTRY(x86_syscall) |
---|
| 51 | /* for now, panic */ |
---|
| 52 | ZTRAPENTRY(T_RESERVED) |
---|
| 53 | |
---|
| 54 | ASM_ENTRY(x86_syscall32) |
---|
| 55 | /* for now, panic */ |
---|
| 56 | ZTRAPENTRY(T_RESERVED) |
---|
| 57 | |
---|
| 58 | /* |
---|
[45] | 59 | * General exceptions. |
---|
| 60 | */ |
---|
[29] | 61 | ASM_ENTRY(x86_trap00) |
---|
| 62 | ZTRAPENTRY(T_DIVIDE) |
---|
[25] | 63 | |
---|
[29] | 64 | ASM_ENTRY(x86_trap01) |
---|
| 65 | ZTRAPENTRY(T_TRCTRAP) |
---|
[25] | 66 | |
---|
[29] | 67 | ASM_ENTRY(x86_trap02) |
---|
| 68 | ZTRAPENTRY(T_NMI) |
---|
[25] | 69 | |
---|
[29] | 70 | ASM_ENTRY(x86_trap03) |
---|
| 71 | ZTRAPENTRY(T_BPTFLT) |
---|
[25] | 72 | |
---|
[29] | 73 | ASM_ENTRY(x86_trap04) |
---|
| 74 | ZTRAPENTRY(T_OFLOW) |
---|
[25] | 75 | |
---|
[29] | 76 | ASM_ENTRY(x86_trap05) |
---|
| 77 | ZTRAPENTRY(T_BOUND) |
---|
[25] | 78 | |
---|
[29] | 79 | ASM_ENTRY(x86_trap06) |
---|
| 80 | ZTRAPENTRY(T_PRIVINFLT) |
---|
[25] | 81 | |
---|
[29] | 82 | ASM_ENTRY(x86_trap07) |
---|
| 83 | ZTRAPENTRY(T_DNA) |
---|
[25] | 84 | |
---|
[29] | 85 | ASM_ENTRY(x86_trap08) |
---|
| 86 | TRAPENTRY(T_DOUBLEFLT) |
---|
[25] | 87 | |
---|
[29] | 88 | ASM_ENTRY(x86_trap09) |
---|
| 89 | ZTRAPENTRY(T_FPOPFLT) |
---|
[25] | 90 | |
---|
[29] | 91 | ASM_ENTRY(x86_trap0a) |
---|
| 92 | TRAPENTRY(T_TSSFLT) |
---|
[25] | 93 | |
---|
[29] | 94 | ASM_ENTRY(x86_trap0b) |
---|
[82] | 95 | TRAPENTRY(T_SEGNPFLT) |
---|
[25] | 96 | |
---|
[29] | 97 | ASM_ENTRY(x86_trap0c) |
---|
[82] | 98 | TRAPENTRY(T_STKFLT) |
---|
[25] | 99 | |
---|
[29] | 100 | ASM_ENTRY(x86_trap0d) |
---|
[82] | 101 | TRAPENTRY(T_PROTFLT) |
---|
[25] | 102 | |
---|
[29] | 103 | ASM_ENTRY(x86_trap0e) |
---|
| 104 | TRAPENTRY(T_PAGEFLT) |
---|
[25] | 105 | |
---|
[29] | 106 | ASM_ENTRY(x86_trap0f) |
---|
| 107 | ZTRAPENTRY(T_ASTFLT) |
---|
[25] | 108 | |
---|
[29] | 109 | ASM_ENTRY(x86_trap10) |
---|
| 110 | ZTRAPENTRY(T_ARITHTRAP) |
---|
[25] | 111 | |
---|
[29] | 112 | ASM_ENTRY(x86_trap11) |
---|
| 113 | TRAPENTRY(T_ALIGNFLT) |
---|
[25] | 114 | |
---|
[29] | 115 | ASM_ENTRY(x86_trap12) |
---|
| 116 | ZTRAPENTRY(T_MCA) |
---|
[25] | 117 | |
---|
[29] | 118 | ASM_ENTRY(x86_trap13) |
---|
| 119 | ZTRAPENTRY(T_XMM) |
---|
[25] | 120 | |
---|
[29] | 121 | ASM_ENTRY(x86_trap14) |
---|
| 122 | ASM_ENTRY(x86_trap15) |
---|
| 123 | ASM_ENTRY(x86_trap16) |
---|
| 124 | ASM_ENTRY(x86_trap17) |
---|
| 125 | ASM_ENTRY(x86_trap18) |
---|
| 126 | ASM_ENTRY(x86_trap19) |
---|
| 127 | ASM_ENTRY(x86_trap1a) |
---|
| 128 | ASM_ENTRY(x86_trap1b) |
---|
| 129 | ASM_ENTRY(x86_trap1c) |
---|
| 130 | ASM_ENTRY(x86_trap1d) |
---|
| 131 | ASM_ENTRY(x86_trap1e) |
---|
| 132 | ASM_ENTRY(x86_trap1f) |
---|
[80] | 133 | ASM_ENTRY(x86_rsvd) |
---|
[29] | 134 | /* 20 - 31 reserved for future exp */ |
---|
| 135 | ZTRAPENTRY(T_RESERVED) |
---|
[25] | 136 | |
---|
[45] | 137 | /* |
---|
[89] | 138 | * APIC interrupts. |
---|
[45] | 139 | */ |
---|
[86] | 140 | ASM_ENTRY(x86_lapic_spurious) |
---|
[45] | 141 | ZTRAPENTRY(T_ASTFLT) |
---|
| 142 | |
---|
[86] | 143 | ASM_ENTRY(x86_lapic_timer) |
---|
| 144 | pushq $0 |
---|
| 145 | pushq $T_ASTFLT |
---|
| 146 | INTR_SAVE_REGS |
---|
| 147 | |
---|
[341] | 148 | movq lapic_va(%rip),%rax |
---|
| 149 | movl $0,LAPIC_EOI(%rax) |
---|
| 150 | |
---|
[86] | 151 | movq %rsp,%rdi |
---|
| 152 | call hal_timer_intr |
---|
| 153 | |
---|
| 154 | INTR_RESTORE_REGS |
---|
| 155 | addq $16,%rsp |
---|
| 156 | iretq |
---|
| 157 | |
---|
[220] | 158 | ASM_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 | |
---|
[152] | 173 | ASM_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 | |
---|
[89] | 188 | ASM_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 | |
---|
[29] | 203 | /* |
---|
[233] | 204 | * Common entry point for exceptions. |
---|
[29] | 205 | */ |
---|
| 206 | alltraps: |
---|
[233] | 207 | INTR_SAVE_REGS |
---|
| 208 | |
---|
[29] | 209 | movq %rsp,%rdi |
---|
[142] | 210 | call hal_exception_entry |
---|
[25] | 211 | |
---|
[387] | 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 | */ |
---|
[29] | 222 | .data |
---|
| 223 | .globl x86_traps |
---|
[45] | 224 | .globl x86_intrs |
---|
[29] | 225 | .type x86_traps, @object |
---|
[45] | 226 | .type x86_intrs, @object |
---|
[25] | 227 | |
---|
[29] | 228 | .align 64 |
---|
| 229 | x86_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 | |
---|
[45] | 247 | x86_intrs: |
---|
[86] | 248 | .quad x86_lapic_spurious |
---|
| 249 | .quad x86_lapic_timer |
---|
[152] | 250 | .quad x86_ioapic_com1 |
---|
[89] | 251 | .quad x86_ioapic_keyboard |
---|
[45] | 252 | |
---|