Merge remote-tracking branch 'refs/remotes/origin/dev' into dev

merging into dev
This commit is contained in:
2025-02-22 15:41:54 +00:00
7 changed files with 79 additions and 11 deletions
+3 -3
View File
@@ -3,8 +3,9 @@ members = [
"lib/lib_framebuffer", "lib/lib_framebuffer",
"lib/lib_serial", "lib/lib_serial",
"lib/lib_ascii", "lib/lib_ascii",
"kernel" "kernel",
, "lib/lib_application"] "lib/lib_application",
]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
@@ -28,4 +29,3 @@ overflow-checks = false
lto = true lto = true
incremental = false incremental = false
codegen-units = 1 codegen-units = 1
+15 -1
View File
@@ -1,7 +1,8 @@
use lib_ascii::{print, println_log}; use lib_ascii::{print, println_log};
use lib_serial::serial_println; use lib_serial::serial_println;
use x86_64::instructions::port::Port; use x86_64::instructions::port::Port;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; use x86_64::registers::control::Cr2;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
use pic8259::ChainedPics; use pic8259::ChainedPics;
use spin::{Lazy, Mutex}; use spin::{Lazy, Mutex};
@@ -20,6 +21,7 @@ static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
idt.general_protection_fault idt.general_protection_fault
.set_handler_fn(general_protection_fault_handler); .set_handler_fn(general_protection_fault_handler);
idt.page_fault.set_handler_fn(page_fault_handler);
idt[InterruptIndex::Timer.as_u8()].set_handler_fn(timer_interrupt_handler); idt[InterruptIndex::Timer.as_u8()].set_handler_fn(timer_interrupt_handler);
idt[InterruptIndex::Keyboard.as_u8()].set_handler_fn(keyboard_interrupt_handler); idt[InterruptIndex::Keyboard.as_u8()].set_handler_fn(keyboard_interrupt_handler);
@@ -116,3 +118,15 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFr
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8()); .notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
} }
} }
extern "x86-interrupt" fn page_fault_handler(
stack_frame: InterruptStackFrame,
error_code: PageFaultErrorCode,
) {
serial_println!("Exception: Page Fault");
serial_println!("Accessed Address: {:?}", Cr2::read());
serial_println!("Error Code: {:?}", error_code);
serial_println!("{:#?}", stack_frame);
crate::hcf();
}
+56
View File
@@ -0,0 +1,56 @@
//! Sets up a memory map using Limine.
use limine::{
request::{HhdmRequest, KernelAddressRequest, MemoryMapRequest},
response::MemoryMapResponse,
};
use spin::Lazy;
#[used]
#[link_section = ".requests"]
static MEMORY_MAP_REQUEST: MemoryMapRequest = MemoryMapRequest::new();
#[used]
#[link_section = ".requests"]
static HIGHER_HALF_DIRECT_MAP_REQUEST: HhdmRequest = HhdmRequest::new();
/// ```rs
/// let virt_addr = phys_addr + offset;
/// let phys_addr = virt_addr - offset; // (given VA is in the HHDM). Do not use for executable code.
/// ```
pub static PHYSICAL_MEMORY_OFFSET: Lazy<u64> = Lazy::new(|| {
HIGHER_HALF_DIRECT_MAP_REQUEST
.get_response()
.unwrap()
.offset()
});
#[used]
#[link_section = ".requests"]
static KERNEL_ADDRESS_REQUEST: KernelAddressRequest = KernelAddressRequest::new();
/// Converts virtual addresses in the kernel to a physical address like this:
/// ```rs
/// let phys_addr = virt_addr - virtual_base + physical_base;
/// ```
///
/// Returns (virtual_base, physical_base)
pub static KERNEL_PHYSICAL_MEMORY_OFFSET: Lazy<(u64, u64)> = Lazy::new(|| {
let resp = KERNEL_ADDRESS_REQUEST.get_response().unwrap();
// These are base addresses, using Limine's built in page table.
(resp.virtual_base(), resp.physical_base())
});
/// Fetches the memory map from Limine.
///
/// # Panics
///
/// Panics if the memory map was not found in MEMORY_MAP_REQUEST.
pub fn get_memory_map() -> &'static MemoryMapResponse {
if let Some(memory_map) = MEMORY_MAP_REQUEST.get_response() {
return memory_map;
} else {
unreachable!("Could not fetch memory map from Limine.")
}
}
-3
View File
@@ -1,7 +1,6 @@
#![no_std] #![no_std]
#![feature(abi_x86_interrupt)] #![feature(abi_x86_interrupt)]
use arch::x86_64::interrupts;
use core::arch::asm; use core::arch::asm;
use limine::request::{RequestsEndMarker, RequestsStartMarker}; use limine::request::{RequestsEndMarker, RequestsStartMarker};
use limine::BaseRevision; use limine::BaseRevision;
@@ -11,8 +10,6 @@ pub use lib_serial::{serial_print, serial_println, serial_read};
mod arch; mod arch;
use lib_framebuffer;
/// Sets the base revision to the latest revision supported by the crate. /// Sets the base revision to the latest revision supported by the crate.
/// See specification for further info. /// See specification for further info.
/// Be sure to mark all limine requests with #[used], otherwise they may be removed by the compiler. /// Be sure to mark all limine requests with #[used], otherwise they may be removed by the compiler.
+2 -1
View File
@@ -24,7 +24,8 @@
"--no-pie", "--no-pie",
"--gc-sections", "--gc-sections",
"--build-id=none", "--build-id=none",
"-z", "max-page-size=0x1000" "-z",
"max-page-size=0x1000"
] ]
} }
} }