| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- /* arch/x86/kernel/arch_int.c
- *
- * This file is part of evx.
- *
- * evx is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * evx is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with evx. If not, see <https://www.gnu.org/licenses/>
- */
- #include <kernel/init.h>
- #include <kernel/module.h>
- #include <kernel/mm.h>
- #include <kernel/kernel.h>
- #include <kernel/kmlog.h>
- #include <arch/archinfo.h>
- #include <arch/mm.h>
- #include <arch/int.h>
- #include <arch/string.h>
- #include <sys/types.h>
- #include <config.h>
- /* head$(BITS).S */
- /* extern struct idt_entry *idt; things interesting.
- * a struct idt_entry *idt, and that is a pointer. idt, is
- * the address.
- *
- * a struct idt_entry idt[], and that is an array. */
- extern struct idt_entry idt[256];
- extern void ret_intr(void);
- int do_trap(int nr);
- static int set_gate(struct idt_entry *, void (*) (void), int attr);
- #define set_int_gate(nr, handler) set_gate(idt + nr, handler, 0x8e)
- #define set_trap_gate(nr, handler) set_gate(idt + nr, handler, 0x8f)
- #define set_sys_gate(nr, handler) set_gate(idt + nr, handler, 0xef)
- #if CONFIG_64BIT
- /* errcodes later */
- #define build_trap_entry(nr) \
- void trap_##nr##_entry(void); \
- __asm__ ( \
- ".globl trap_"#nr"_entry\n\t" \
- "trap_"#nr"_entry:\n\t" \
- IRQ_SAVE_REGS \
- "movq $"#nr", %rdi\n\t" \
- "pushq ret_intr(%rip)\n\t" \
- "jmp do_trap\n\t" \
- );
- #else
- #define build_trap_entry(nr) \
- void trap_##nr##_entry(void); \
- __asm__ ( \
- ".globl trap_"#nr"_entry\n\t" \
- "trap_"#nr"_entry:\n\t" \
- "pushl $"#nr"\n\t" \
- "call do_trap\n\t" \
- "addl $4, %esp\n\t" \
- "jmp ret_intr\n\t" \
- );
- #endif
- #include "__build_traps_generated.c"
- /* set the handlers for traps, 0 - 31 */
- int __init arch_traps_init(void) {
- #include "__arch_traps_generated.c"
- return 0;
- }
- const static char *trap_msg[32] = {
- "division by zero",
- "debug trap",
- "NMI",
- "breakpoint",
- "overflow",
- "bound",
- "invalid op-code",
- "device not avaliable",
- "double fault",
- "coprocessor segment overrun",
- "invalid tss",
- "segment not present",
- "stack-segment fault",
- "general protection",
- "page fault",
- "reserved",
- "x87 floating-point exception",
- "alignment check",
- "machine check",
- "simd floating-point exception",
- "virtualization exception",
- "control protection exception",
- "reserved",
- "hypervisor injection exception",
- "vmm communication exception",
- "security exception",
- "reserved"
- };
- int do_trap(int nr) {
- kmlog("Oops! trap %d: %s\n", nr, trap_msg[nr]);
- for (;;)
- ;
- return 0;
- }
- static int set_gate(struct idt_entry *entry, void (* handler) (void), int attr) {
- /* no ist support in long-mode, well, that's not so useful */
- __archptr_t p = (__archptr_t) handler;
- entry->off_0 = p & 0xffffu;
- entry->seg = 8;
- #if CONFIG_64BIT
- entry->ist =
- #else
- entry->resv =
- #endif
- 0;
- entry->attr = attr;
- entry->off_1 = (p >> 16u) & 0xffffu;
- #if CONFIG_64BIT
- entry->off_2 = p >> 32u;
- entry->zero = 0;
- #endif
- return 0;
- }
- arch_init(arch_traps_init);
|