x86: refactor traps, add register dump support
parent
3e43ec5491
commit
d69fd0d2aa
@ -1,175 +0,0 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <arch/interrupt.h>
|
||||
|
||||
#include <asm/common.h>
|
||||
|
||||
.text
|
||||
|
||||
/*
|
||||
* low level entry points, this is what gets put into the IDT
|
||||
*/
|
||||
|
||||
ASM_ENTRY(_x86_isr_divide_error)
|
||||
cld
|
||||
call x86_isr_divide_error
|
||||
iret
|
||||
ASM_END(_x86_isr_divide_error)
|
||||
|
||||
ASM_ENTRY(_x86_isr_debug_exception)
|
||||
cld
|
||||
call x86_isr_debug_exception
|
||||
iret
|
||||
ASM_END(_x86_isr_debug_exception)
|
||||
|
||||
ASM_ENTRY(_x86_isr_nmi)
|
||||
cld
|
||||
call x86_isr_nmi
|
||||
iret
|
||||
ASM_END(_x86_isr_nmi)
|
||||
|
||||
ASM_ENTRY(_x86_isr_breakpoint)
|
||||
cld
|
||||
call x86_isr_breakpoint
|
||||
iret
|
||||
ASM_END(_x86_isr_breakpoint)
|
||||
|
||||
ASM_ENTRY(_x86_isr_overflow)
|
||||
cld
|
||||
call x86_isr_overflow
|
||||
iret
|
||||
ASM_END(_x86_isr_overflow)
|
||||
|
||||
ASM_ENTRY(_x86_isr_bound_range_exceeded)
|
||||
cld
|
||||
call x86_isr_bound_range_exceeded
|
||||
iret
|
||||
ASM_END(_x86_isr_bound_range_exceeded)
|
||||
|
||||
ASM_ENTRY(_x86_isr_invalid_opcode)
|
||||
cld
|
||||
call x86_isr_invalid_opcode
|
||||
iret
|
||||
ASM_END(_x86_isr_invalid_opcode)
|
||||
|
||||
ASM_ENTRY(_x86_isr_device_not_available)
|
||||
cld
|
||||
call x86_isr_device_not_available
|
||||
iret
|
||||
ASM_END(_x86_isr_device_not_available)
|
||||
|
||||
ASM_ENTRY(_x86_isr_double_fault)
|
||||
cld
|
||||
call x86_isr_double_fault
|
||||
add $4, %esp
|
||||
iret
|
||||
ASM_END(_x86_isr_double_fault)
|
||||
|
||||
ASM_ENTRY(_x86_isr_invalid_tss)
|
||||
cld
|
||||
call x86_isr_invalid_tss
|
||||
add $4, %esp
|
||||
iret
|
||||
ASM_END(_x86_isr_invalid_tss)
|
||||
|
||||
ASM_ENTRY(_x86_isr_segment_not_present)
|
||||
cld
|
||||
call x86_isr_segment_not_present
|
||||
add $4, %esp
|
||||
iret
|
||||
ASM_END(_x86_isr_segment_not_present)
|
||||
|
||||
ASM_ENTRY(_x86_isr_stack_segment_fault)
|
||||
cld
|
||||
call x86_isr_stack_segment_fault
|
||||
add $4, %esp
|
||||
iret
|
||||
ASM_END(_x86_isr_stack_segment_fault)
|
||||
|
||||
ASM_ENTRY(_x86_isr_general_protection)
|
||||
cld
|
||||
call x86_isr_general_protection
|
||||
add $4, %esp
|
||||
iret
|
||||
ASM_END(_x86_isr_general_protection)
|
||||
|
||||
ASM_ENTRY(_x86_isr_page_fault)
|
||||
cld
|
||||
call x86_isr_page_fault
|
||||
add $4, %esp
|
||||
iret
|
||||
ASM_END(_x86_isr_page_fault)
|
||||
|
||||
ASM_ENTRY(_x86_isr_x87_fpu_error)
|
||||
cld
|
||||
call x86_isr_x87_fpu_error
|
||||
iret
|
||||
ASM_END(_x86_isr_fpu_error)
|
||||
|
||||
ASM_ENTRY(_x86_isr_alignment_check)
|
||||
cld
|
||||
call x86_isr_alignment_check
|
||||
add $4, %esp
|
||||
iret
|
||||
ASM_END(_x86_isr_alignment_check)
|
||||
|
||||
ASM_ENTRY(_x86_isr_machine_check)
|
||||
cld
|
||||
call x86_isr_machine_check
|
||||
iret
|
||||
ASM_END(_x86_isr_machine_check)
|
||||
|
||||
ASM_ENTRY(_x86_isr_simd_floating_point_exception)
|
||||
cld
|
||||
call x86_isr_simd_floating_point_exception
|
||||
iret
|
||||
ASM_END(_x86_isr_simd_floating_point_exception)
|
||||
|
||||
ASM_ENTRY(_x86_isr_virtualization_exception)
|
||||
cld
|
||||
call x86_isr_virtualization_exception
|
||||
iret
|
||||
ASM_END(_x86_isr_virtualization_exception)
|
||||
|
||||
ASM_ENTRY(_x86_isr_control_protection_exception)
|
||||
cld
|
||||
call x86_isr_control_protection_exception
|
||||
add $4, %esp
|
||||
iret
|
||||
ASM_END(_x86_isr_control_protection_exception)
|
||||
|
||||
/* trap.c */
|
||||
.extern x86_isr_divide_error
|
||||
.extern x86_isr_debug_exception
|
||||
.extern x86_isr_nmi
|
||||
.extern x86_isr_breakpoint
|
||||
.extern x86_isr_overflow
|
||||
.extern x86_isr_bound_range_exceeded
|
||||
.extern x86_isr_invalid_opcode
|
||||
.extern x86_isr_device_not_available
|
||||
.extern x86_isr_double_fault
|
||||
.extern x86_isr_invalid_tss
|
||||
.extern x86_isr_segment_not_present
|
||||
.extern x86_isr_stack_segment_fault
|
||||
.extern x86_isr_general_protection
|
||||
.extern x86_isr_page_fault
|
||||
.extern x86_isr_x87_fpu_error
|
||||
.extern x86_isr_alignment_check
|
||||
.extern x86_isr_machine_check
|
||||
.extern x86_isr_simd_floating_point_exception
|
||||
.extern x86_isr_virtualization_exception
|
||||
.extern x86_isr_control_protection_exception
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
@ -0,0 +1,102 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <arch/interrupt.h>
|
||||
|
||||
#include <asm/common.h>
|
||||
|
||||
.text
|
||||
|
||||
/*
|
||||
* Low level trap entry points, this is what gets put into the IDT.
|
||||
*
|
||||
* Hardware automatically pushes EFLAGS, CS, EIP, and (optionally) an error
|
||||
* code to the stack. The rest is pushed by software using the pushal
|
||||
* instruction. I wanted to use the same context save struct for both kinds
|
||||
* of exceptions (the ones that push an error code and the ones that don't),
|
||||
* so the pointer to the hardware context save is also pushed to the stack and
|
||||
* included in struct x86_trap_frame.
|
||||
*/
|
||||
|
||||
.macro gen_isr_noerror name
|
||||
.extern x86_isr_\name
|
||||
ASM_ENTRY(_x86_isr_\name )
|
||||
cld
|
||||
pushal
|
||||
mov %esp, %eax
|
||||
add $32, %eax
|
||||
push %eax
|
||||
call x86_isr_\name
|
||||
add $4, %esp
|
||||
popal
|
||||
iretl
|
||||
ASM_END(_x86_isr_\name )
|
||||
.endm
|
||||
|
||||
/*
|
||||
* So, instead of just adding a dedicated register for exception status, the
|
||||
* Intel people apparently thought it was better to have the CPU push an error
|
||||
* code to the stack. This is technically not too bad of an idea because the
|
||||
* x86 ABI says all parameters are passed through the stack, so you could write
|
||||
* exception handlers in C! Too bad the CPU (1) doesn't save scratch registers
|
||||
* eax, ecx and edx automatically, (2) only some of the exceptions push this
|
||||
* error code?? and (3) you have to pop the error code manually??????
|
||||
*/
|
||||
.macro gen_isr_error name
|
||||
.extern x86_isr_\name
|
||||
ASM_ENTRY(_x86_isr_\name )
|
||||
cld
|
||||
pushal
|
||||
mov %esp, %eax
|
||||
add $36, %eax
|
||||
push %eax /* struct x86_trap_frame::hw_frame */
|
||||
/*
|
||||
* pushal pushes 8 registers = 32 bytes to the stack, plus 4 bytes
|
||||
* for the pointer to struct x86_hw_frame, so the error code pushed
|
||||
* by hardware is 36 bytes into %esp now
|
||||
*/
|
||||
mov 36(%esp), %ebx
|
||||
mov %esp, %eax
|
||||
push %ebx
|
||||
push %eax
|
||||
call x86_isr_\name /* x86_isr_<name>(%esp, error_code); */
|
||||
add $8, %esp
|
||||
popal
|
||||
add $4, %esp /* "pop" the hardware error code from the stack */
|
||||
iretl
|
||||
ASM_END(_x86_isr_\name )
|
||||
.endm
|
||||
|
||||
gen_isr_noerror divide_error
|
||||
gen_isr_noerror debug_exception
|
||||
gen_isr_noerror nmi
|
||||
gen_isr_noerror breakpoint
|
||||
gen_isr_noerror overflow
|
||||
gen_isr_noerror bound_range_exceeded
|
||||
gen_isr_noerror invalid_opcode
|
||||
gen_isr_noerror device_not_available
|
||||
gen_isr_error double_fault
|
||||
gen_isr_error invalid_tss
|
||||
gen_isr_error segment_not_present
|
||||
gen_isr_error stack_segment_fault
|
||||
gen_isr_error general_protection
|
||||
gen_isr_error page_fault
|
||||
gen_isr_noerror x87_fpu_error
|
||||
gen_isr_error alignment_check
|
||||
gen_isr_noerror machine_check
|
||||
gen_isr_noerror simd_floating_point_exception
|
||||
gen_isr_noerror virtualization_exception
|
||||
gen_isr_error control_protection_exception
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
Loading…
Reference in New Issue