Core exception handling w or wo err code
This commit is contained in:
parent
75dbbdb53b
commit
3fb667d62e
@ -22,36 +22,108 @@
|
|||||||
.type exception_wrapper_\id,@function
|
.type exception_wrapper_\id,@function
|
||||||
/* INTERRUPT FRAME START */
|
/* INTERRUPT FRAME START */
|
||||||
/* ALREADY PUSHED TO US BY THE PROCESSOR UPON ENTRY TO THIS INTERRUPT */
|
/* ALREADY PUSHED TO US BY THE PROCESSOR UPON ENTRY TO THIS INTERRUPT */
|
||||||
/* uint32_t ip */
|
|
||||||
/* uint32_t cs; */
|
|
||||||
/* uint32_t flags */
|
/* uint32_t flags */
|
||||||
|
/* uint32_t cs; */
|
||||||
|
/* uint32_t ip */
|
||||||
/* Pushes the other reg to save same and look like a struct cpu_state*/
|
/* Pushes the other reg to save same and look like a struct cpu_state*/
|
||||||
/* Fake error code */
|
/* Fake error code */
|
||||||
pushl $0
|
pushl $0
|
||||||
|
|
||||||
/* Backup the actual context */
|
/* Backup the actual context */
|
||||||
pushl %ebp
|
pushl %ebp
|
||||||
movl %esp, %ebp
|
movl %esp, %ebp
|
||||||
|
|
||||||
pushl %eax
|
pushl %eax
|
||||||
pushl %ecx
|
pushl %ecx
|
||||||
pushl %edx
|
pushl %edx
|
||||||
pushl %ebx
|
pushl %ebx
|
||||||
pushl %esi
|
pushl %esi
|
||||||
pushl %edi
|
pushl %edi
|
||||||
subl $2,%esp
|
subl $2,%esp
|
||||||
pushw %ss
|
pushw %ss
|
||||||
pushw %ds
|
pushw %ds
|
||||||
pushw %es
|
pushw %es
|
||||||
pushw %fs
|
pushw %fs
|
||||||
pushw %gs
|
pushw %gs
|
||||||
|
|
||||||
/* Set correct kernel segment descriptors' value */
|
/* Set correct kernel segment descriptors' value */
|
||||||
movw $BUILD_SEGMENT_REG_VALUE(0, 0, SEG_KDATA), %di
|
movw $BUILD_SEGMENT_REG_VALUE(0, 0, SEG_KDATA), %di
|
||||||
pushw %di ; popw %ds
|
pushw %di ; popw %ds
|
||||||
pushw %di ; popw %es
|
pushw %di ; popw %es
|
||||||
pushw %di ; popw %fs
|
pushw %di ; popw %fs
|
||||||
pushw %di ; popw %gs
|
pushw %di ; popw %gs
|
||||||
|
|
||||||
|
push %esp
|
||||||
|
pushl $\id
|
||||||
|
call exception_handler_wrap
|
||||||
|
addl $8, %esp
|
||||||
|
|
||||||
|
/* Reconfigure the MMU if needed */
|
||||||
|
pushl %esp /* cpu_ctxt */
|
||||||
|
call thread_prepare_exception_switch_back
|
||||||
|
addl $4, %esp /* Unallocate the stack */
|
||||||
|
|
||||||
|
/* Prepare kernel TSS in case we are switching to a
|
||||||
|
user thread: we make sure that we will come back
|
||||||
|
into the kernel at a correct stack location */
|
||||||
|
pushl %esp /* Pass the location of the context we are
|
||||||
|
restoring to the function */
|
||||||
|
call cpu_context_update_kernel_tss
|
||||||
|
addl $4, %esp
|
||||||
|
|
||||||
|
/* Restore the context */
|
||||||
|
popw %gs
|
||||||
|
popw %fs
|
||||||
|
popw %es
|
||||||
|
popw %ds
|
||||||
|
popw %ss
|
||||||
|
addl $2,%esp
|
||||||
|
popl %edi
|
||||||
|
popl %esi
|
||||||
|
popl %ebx
|
||||||
|
popl %edx
|
||||||
|
popl %ecx
|
||||||
|
popl %eax
|
||||||
|
popl %ebp
|
||||||
|
/* Remove fake error code */
|
||||||
|
addl $4, %esp
|
||||||
|
|
||||||
|
iret
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro exception_mac_with_errcode id
|
||||||
|
exception_wrapper_\id:
|
||||||
|
.type exception_wrapper_\id,@function
|
||||||
|
/* INTERRUPT FRAME START */
|
||||||
|
/* ALREADY PUSHED TO US BY THE PROCESSOR UPON ENTRY TO THIS INTERRUPT */
|
||||||
|
/* uint32_t flags */
|
||||||
|
/* uint32_t cs; */
|
||||||
|
/* uint32_t ip */
|
||||||
|
/* Pushes the other reg to save same and look like a struct cpu_state*/
|
||||||
|
|
||||||
|
/* Backup the actual context */
|
||||||
|
pushl %ebp
|
||||||
|
movl %esp, %ebp
|
||||||
|
|
||||||
|
pushl %eax
|
||||||
|
pushl %ecx
|
||||||
|
pushl %edx
|
||||||
|
pushl %ebx
|
||||||
|
pushl %esi
|
||||||
|
pushl %edi
|
||||||
|
subl $2,%esp
|
||||||
|
pushw %ss
|
||||||
|
pushw %ds
|
||||||
|
pushw %es
|
||||||
|
pushw %fs
|
||||||
|
pushw %gs
|
||||||
|
|
||||||
|
/* Set correct kernel segment descriptors' value */
|
||||||
|
movw $BUILD_SEGMENT_REG_VALUE(0, 0, SEG_KDATA), %di
|
||||||
|
pushw %di ; popw %ds
|
||||||
|
pushw %di ; popw %es
|
||||||
|
pushw %di ; popw %fs
|
||||||
|
pushw %di ; popw %gs
|
||||||
|
|
||||||
push %esp
|
push %esp
|
||||||
pushl $\id
|
pushl $\id
|
||||||
@ -72,30 +144,32 @@
|
|||||||
addl $4, %esp
|
addl $4, %esp
|
||||||
|
|
||||||
/* Restore the context */
|
/* Restore the context */
|
||||||
popw %gs
|
popw %gs
|
||||||
popw %fs
|
popw %fs
|
||||||
popw %es
|
popw %es
|
||||||
popw %ds
|
popw %ds
|
||||||
popw %ss
|
popw %ss
|
||||||
addl $2,%esp
|
addl $2,%esp
|
||||||
popl %edi
|
popl %edi
|
||||||
popl %esi
|
popl %esi
|
||||||
popl %ebx
|
popl %ebx
|
||||||
popl %edx
|
popl %edx
|
||||||
popl %ecx
|
popl %ecx
|
||||||
popl %eax
|
popl %eax
|
||||||
popl %ebp
|
popl %ebp
|
||||||
/* Remove fake error code */
|
/* Remove fake error code */
|
||||||
addl $4, %esp
|
addl $4, %esp
|
||||||
|
|
||||||
iret
|
iret
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
|
/*List of exception w or w/o err codehttps://wiki.osdev.org/Exceptions*/
|
||||||
|
.irp exception_id, 8, 10, 11, 12, 13, 14, 17, 30
|
||||||
|
exception_mac_with_errcode exception_id
|
||||||
|
.endr
|
||||||
|
|
||||||
.set i, 0
|
.irp exception_id, 0, 1, 2, 3, 4, 5, 6, 7, 9, 15, 16, 18, 19, 20 21, 22, 23, 24, 25, 26, 27, 28, 29, 31
|
||||||
.rept 0x20
|
exception_mac exception_id
|
||||||
exception_mac %i
|
|
||||||
.set i, i+1
|
|
||||||
.endr
|
.endr
|
||||||
|
|
||||||
.macro ref_exception_wrapper id
|
.macro ref_exception_wrapper id
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
add-symbol-file kernel.sym
|
add-symbol-file kernel.sym
|
||||||
source custom_gdb_extension.py
|
source custom_gdb_extension.py
|
||||||
|
#For ASM sources
|
||||||
|
directory arch/x86/:core
|
||||||
target remote | qemu-system-i386 -S -gdb stdio -kernel kernel -m 16M
|
target remote | qemu-system-i386 -S -gdb stdio -kernel kernel -m 16M
|
||||||
|
Loading…
Reference in New Issue
Block a user