Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Implemented Comprehensive Exception Handling in OS Kernel #30

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ charlotte_core-x86_64-debug.iso: build-x86_64-debug
rm -rf iso_root

run-x86_64-debug: ovmf-x86_64 charlotte_core-x86_64-debug.iso
qemu-system-x86_64 -enable-kvm -M q35 -cpu host -m 12G -bios ovmf-x86_64/OVMF.fd -cdrom charlotte_core-x86_64-debug.iso -boot d
qemu-system-x86_64 -enable-kvm -M q35 -cpu host -m 2G -bios ovmf-x86_64/OVMF.fd -cdrom charlotte_core-x86_64-debug.iso -boot d

run-x86_64-log: ovmf-x86_64 charlotte_core-x86_64-debug.iso
qemu-system-x86_64 -enable-kvm -M q35 -cpu host -m 12G -bios ovmf-x86_64/OVMF.fd -cdrom charlotte_core-x86_64-debug.iso -boot d serial file:log_x86_64.txt
Expand Down Expand Up @@ -158,4 +158,4 @@ clean:
rm -f log_x86_64.txt

distclean: clean
rm -rf limine
rm -rf limine
185 changes: 184 additions & 1 deletion charlotte_core/src/arch/x86_64/exceptions/exceptions.asm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ extern ih_divide_by_zero
extern ih_double_fault
extern ih_general_protection_fault
extern ih_page_fault
extern ih_segment_not_present
extern ih_debug
extern ih_non_maskable_interrupt
extern ih_breakpoint
extern ih_overflow
extern ih_bound_range_exceeded
extern ih_invalid_opcode
extern ih_device_not_available
extern ih_invalid_tss
extern ih_stack_segment_fault
extern ih_reserved
extern ih_x87_floating_point
extern ih_alignment_check
extern ih_machine_check
extern ih_simd_floating_point
extern ih_virtualization
extern ih_control_protection
extern ih_hypervisor_injection
extern ih_vmm_communication
extern ih_security_exception

;The actual ISRs
global isr_divide_by_zero
Expand Down Expand Up @@ -77,4 +97,167 @@ isr_page_fault:
pop rdi ;pop the error code
call ih_page_fault
call restore_regs
iretq
iretq

global isr_segment_not_present
isr_segment_not_present:
call save_regs
pop rdi ; Pop the error code into RDI for the handler
call ih_segment_not_present
push rdi ; Push the error code back onto the stack for restoring context
call restore_regs
add rsp, 8 ; Clean up the error code from the stack
iretq

global isr_debug
isr_debug:
call save_regs
call ih_debug
call restore_regs
iretq

global isr_non_maskable_interrupt
isr_non_maskable_interrupt:
call save_regs
call ih_non_maskable_interrupt
call restore_regs
iretq

global isr_breakpoint
isr_breakpoint:
call save_regs
call ih_breakpoint
call restore_regs
iretq


global isr_overflow
isr_overflow:
call save_regs
call ih_overflow
call restore_regs
iretq

global isr_bound_range_exceeded
isr_bound_range_exceeded:
call save_regs
call ih_bound_range_exceeded
call restore_regs
iretq

global isr_invalid_opcode
isr_invalid_opcode:
call save_regs
call ih_invalid_opcode
call restore_regs
iretq

global isr_device_not_available
isr_device_not_available:
call save_regs
call ih_device_not_available
call restore_regs
iretq

global isr_invalid_tss
isr_invalid_tss:
call save_regs
pop rdi
call ih_invalid_tss
push rdi
call restore_regs
add rsp, 8
iretq

global isr_stack_segment_fault
isr_stack_segment_fault:
call save_regs
pop rdi
call ih_stack_segment_fault
push rdi
call restore_regs
add rsp, 8
iretq

global isr_reserved
isr_reserved:
call save_regs
; No error code to pop for this vector, as it's not used
call ih_reserved
call restore_regs
iretq

global isr_x87_floating_point
isr_x87_floating_point:
call save_regs
call ih_x87_floating_point
call restore_regs
iretq

global isr_alignment_check
isr_alignment_check:
call save_regs
pop rdi
call ih_alignment_check
push rdi
call restore_regs
add rsp, 8
iretq

global isr_machine_check
isr_machine_check:
; Registers are not saved since this exception is an abort
; Unlike Double Fault, Machine Check does not push an error code
call ih_machine_check
hlt ; Halt the core since machine checks indicate severe hardware issues

global isr_simd_floating_point
isr_simd_floating_point:
call save_regs
call ih_simd_floating_point
call restore_regs
iretq

global isr_virtualization
isr_virtualization:
call save_regs
call ih_virtualization
call restore_regs
iretq

global isr_control_protection
isr_control_protection:
call save_regs
pop rdi
call ih_control_protection
push rdi
call restore_regs
add rsp, 8
iretq

global isr_hypervisor_injection
isr_hypervisor_injection:
call save_regs
call ih_hypervisor_injection
call restore_regs
iretq

global isr_vmm_communication
isr_vmm_communication:
call save_regs
pop rdi ; Pop the error code into RDI for the handler
call ih_vmm_communication
push rdi ; Push the error code back onto the stack for correct stack alignment
call restore_regs
add rsp, 8 ; Clean up the error code from the stack
iretq

global isr_security_exception
isr_security_exception:
call save_regs
pop rdi ; Pop the error code into RDI for the handler
call ih_security_exception
push rdi ; Push the error code back onto the stack for correct stack alignment
call restore_regs
add rsp, 8 ; Clean up the error code from the stack
iretq
Loading