Compare commits
3 Commits
117b799bbe
...
c6ea6e46cc
Author | SHA1 | Date | |
---|---|---|---|
c6ea6e46cc | |||
e124f3c2c6 | |||
8c30acfc5b |
@ -72,7 +72,7 @@ args = ["-rf", "build/initramfs", "build/initramfs.tar.lzma"]
|
||||
|
||||
[tasks.lib]
|
||||
condition = { files_modified = { input = ["src/lib/**/*.rs"], output = ["${ARTIFACTDIR}/libgila.rlib"] }, fail_message = "(inputs unchanged)" }
|
||||
dependencies = ["prepare"]
|
||||
dependencies = []
|
||||
command = "cargo"
|
||||
args = ["build", "--profile", "${PROFILE}", "--lib"]
|
||||
|
||||
@ -170,4 +170,4 @@ command = "gdb"
|
||||
args = ["${ARTIFACTDIR}/kernel", "--eval-command=target remote localhost:1234"]
|
||||
|
||||
[tasks.debug]
|
||||
run_task = { name = ["debug-run", "debug-view"], fork = true, parallel = true }
|
||||
run_task = { name = ["debug-run", "debug-view"], fork = true, parallel = true }
|
||||
|
@ -4,40 +4,39 @@
|
||||
use lazy_static::lazy_static;
|
||||
use x86_64::structures::idt::*;
|
||||
|
||||
use crate::format;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref IDT: InterruptDescriptorTable = {
|
||||
let mut idt = InterruptDescriptorTable::new();
|
||||
let idt = InterruptDescriptorTable::new();
|
||||
// TODO: Re-implement this once the x86-interrupt ABI is fixed.
|
||||
//idt.double_fault.set_handler_fn(double_fault);
|
||||
idt.page_fault.set_handler_fn(page_fault);
|
||||
// Alternatively: Write our own interrupt handler wrappers.
|
||||
idt
|
||||
};
|
||||
}
|
||||
|
||||
//extern "x86-interrupt" fn double_fault(info: InterruptStackFrame, _: u64) -> ! {
|
||||
// crate::interrupt::double_fault(&format!("{info:#?}"));
|
||||
//}
|
||||
// For all these handlers, they will be called from a purely naked ASM
|
||||
// function. That function will first push all registers to the stack.
|
||||
// It is the responsibility of these functions to recover this info.
|
||||
|
||||
// Recoverable exception: Occurs on division failure.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn x86_divide_error() {
|
||||
|
||||
#[allow(dead_code)]
|
||||
extern "x86-interrupt" fn page_fault(info: InterruptStackFrame, errcode: PageFaultErrorCode) {
|
||||
if errcode.contains(PageFaultErrorCode::USER_MODE) {
|
||||
// Fault occurred in usermode. Non fatal.
|
||||
todo!()
|
||||
} else {
|
||||
// Fault occurred in kernel mode. This is possibly fatal.
|
||||
// This is recoverable if we simply hit an unavailable page,
|
||||
// but unrecoverable if we hit a nonexistent or invalid page.
|
||||
if errcode.contains(PageFaultErrorCode::PROTECTION_VIOLATION)
|
||||
| errcode.contains(PageFaultErrorCode::MALFORMED_TABLE)
|
||||
{
|
||||
let addr = unsafe {
|
||||
let a: usize;
|
||||
core::arch::asm! {"mov {}, cr2", out(reg) a};
|
||||
a
|
||||
};
|
||||
crate::interrupt::page_fault(addr, &format!("{info:#?}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recoverable exception: Occurs on failure in BOUND instruction.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn x86_bound_range() {
|
||||
|
||||
}
|
||||
|
||||
// Recoverable exception: Invalid opcode.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn x86_invalid_opcode() {
|
||||
|
||||
}
|
||||
|
||||
// Recoverable exception: FPU not available or enabled.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn x86_device_unavailable() {
|
||||
|
||||
}
|
@ -1,11 +1,16 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn double_fault(info: &str) -> ! {
|
||||
panic!("Double fault: {}", info);
|
||||
use core::str;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn double_fault(info: *const u8, info_len: usize) -> ! {
|
||||
let info_slice = unsafe {&str::from_raw_parts(info, info_len)};
|
||||
panic!("Double fault: {}", info_slice);
|
||||
}
|
||||
|
||||
pub fn page_fault(addr: usize, info: &str) -> ! {
|
||||
panic!("Page fault at 0x{:X}: {}", addr, info);
|
||||
}
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn page_fault(addr: usize, info: *const u8, info_len: usize) -> ! {
|
||||
let info_slice = unsafe { &str::from_raw_parts(info, info_len) };
|
||||
panic!("Page fault at 0x{:X}: {}", addr, info_slice);
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(allocator_api)]
|
||||
#![feature(abi_x86_interrupt)]
|
||||
#![feature(str_from_raw_parts)]
|
||||
|
||||
mod arch;
|
||||
mod boot;
|
||||
|
Loading…
Reference in New Issue
Block a user