feat: frame allocation

This commit is contained in:
Zoe
2026-08-19 09:58:43 -05:00
parent 2a1bf17d8b
commit 35d18495ec
7 changed files with 498 additions and 104 deletions
+1
View File
@@ -50,6 +50,7 @@ pub(super) const KERNEL_DATA_SELECTOR: u16 = 2 * 8;
pub(super) const TSS_SELECTOR: u16 = 3 * 8;
#[repr(align(16))]
#[allow(dead_code)] // field 0 is read, rust just cant tell
struct ExceptionStack([u8; DOUBLE_FAULT_STACK_SIZE]);
static mut GDT: Gdt = Gdt::new();
+5 -14
View File
@@ -19,22 +19,10 @@ macro_rules! fatal_with_error_code {
};
}
extern "x86-interrupt" fn debug_handler(frame: InterruptStackFrame) {
fatal_exception("DEBUG EXCEPTION", &frame, None);
}
extern "x86-interrupt" fn non_maskable_interrupt_handler(frame: InterruptStackFrame) {
fatal_exception("NON-MASKABLE INTERRUPT", &frame, None);
}
extern "x86-interrupt" fn breakpoint_handler(frame: InterruptStackFrame) {
report_exception("BREAKPOINT", &frame, None);
}
extern "x86-interrupt" fn double_fault_handler(frame: InterruptStackFrame, error_code: u64) {
fatal_exception("DOUBLE FAULT", &frame, Some(error_code));
}
extern "x86-interrupt" fn page_fault_handler(frame: InterruptStackFrame, error_code: u64) {
report_exception("PAGE FAULT", &frame, Some(error_code));
println!("Faulting address: {:#X}", read_cr2());
@@ -43,12 +31,15 @@ extern "x86-interrupt" fn page_fault_handler(frame: InterruptStackFrame, error_c
}
fatal_without_error_code!(divide_error_handler, "DIVIDE ERROR");
fatal_without_error_code!(debug_handler, "DEBUG EXCEPTION");
fatal_without_error_code!(non_maskable_interrupt_handler, "NON-MASKABLE INTERRUPT");
fatal_without_error_code!(invalid_opcode_handler, "INVALID OPCODE");
fatal_without_error_code!(device_not_available_handler, "DEVICE NOT AVAILABLE");
fatal_without_error_code!(x87_floating_point_handler, "X87 FLOATING-POINT EXCEPTION");
fatal_without_error_code!(machine_check_handler, "MACHINE CHECK");
fatal_without_error_code!(simd_floating_point_handler, "SIMD FLOATING-POINT EXCEPTION");
fatal_with_error_code!(double_fault_handler, "DOUBLE FAULT");
fatal_with_error_code!(invalid_tss_handler, "INVALID TSS");
fatal_with_error_code!(segment_not_present_handler, "SEGMENT NOT PRESENT");
fatal_with_error_code!(stack_segment_fault_handler, "STACK-SEGMENT FAULT");
@@ -134,10 +125,10 @@ fn report_exception(name: &'static str, frame: &InterruptStackFrame, error_code:
"kernel"
}
);
println!("RIP: {:#X}", frame.instruction_pointer.as_u64());
println!("RIP: {:#X}", frame.instruction_pointer.as_usize());
println!("CS: {:#X}", frame.code_segment);
println!("FLAGS: {:#X}", frame.cpu_flags);
println!("RSP: {:#X}", frame.stack_pointer.as_u64());
println!("RSP: {:#X}", frame.stack_pointer.as_usize());
println!("SS: {:#X}", frame.stack_segment);
if let Some(error_code) = error_code {
+72 -72
View File
@@ -14,46 +14,46 @@ pub unsafe fn read_u8(port: u16) -> u8 {
value
}
#[inline(always)]
pub unsafe fn read_u8_slice(port: u16, slice: &mut [u8]) {
unsafe {
asm!(
"rep insb",
in("dx") port,
inout("rdi") slice.as_mut_ptr() => _,
inout("rcx") slice.len() => _,
options(nostack, preserves_flags),
);
}
}
// #[inline(always)]
// pub unsafe fn read_u8_slice(port: u16, slice: &mut [u8]) {
// unsafe {
// asm!(
// "rep insb",
// in("dx") port,
// inout("rdi") slice.as_mut_ptr() => _,
// inout("rcx") slice.len() => _,
// options(nostack, preserves_flags),
// );
// }
// }
#[inline(always)]
pub unsafe fn read_u16(port: u16) -> u16 {
let value: u16;
unsafe {
asm!(
"in ax, dx",
in("dx") port,
out("ax") value,
options(nomem, nostack, preserves_flags),
);
}
value
}
// #[inline(always)]
// pub unsafe fn read_u16(port: u16) -> u16 {
// let value: u16;
// unsafe {
// asm!(
// "in ax, dx",
// in("dx") port,
// out("ax") value,
// options(nomem, nostack, preserves_flags),
// );
// }
// value
// }
#[inline(always)]
pub unsafe fn read_u32(port: u16) -> u32 {
let value: u32;
unsafe {
asm!(
"in eax, dx",
in("dx") port,
out("eax") value,
options(nomem, nostack, preserves_flags),
);
}
value
}
// #[inline(always)]
// pub unsafe fn read_u32(port: u16) -> u32 {
// let value: u32;
// unsafe {
// asm!(
// "in eax, dx",
// in("dx") port,
// out("eax") value,
// options(nomem, nostack, preserves_flags),
// );
// }
// value
// }
#[inline(always)]
pub unsafe fn write_u8(port: u16, value: u8) {
@@ -67,39 +67,39 @@ pub unsafe fn write_u8(port: u16, value: u8) {
}
}
#[inline(always)]
pub unsafe fn write_u8_slice(port: u16, slice: &[u8]) {
unsafe {
asm!(
"rep outsb",
in("dx") port,
inout("rsi") slice.as_ptr() => _,
inout("rcx") slice.len() => _,
options(nostack, preserves_flags),
);
}
}
// #[inline(always)]
// pub unsafe fn write_u8_slice(port: u16, slice: &[u8]) {
// unsafe {
// asm!(
// "rep outsb",
// in("dx") port,
// inout("rsi") slice.as_ptr() => _,
// inout("rcx") slice.len() => _,
// options(nostack, preserves_flags),
// );
// }
// }
#[inline(always)]
pub unsafe fn write_u16(port: u16, value: u16) {
unsafe {
asm!(
"out dx, ax",
in("dx") port,
in("ax") value,
options(nomem, nostack, preserves_flags),
);
}
}
// #[inline(always)]
// pub unsafe fn write_u16(port: u16, value: u16) {
// unsafe {
// asm!(
// "out dx, ax",
// in("dx") port,
// in("ax") value,
// options(nomem, nostack, preserves_flags),
// );
// }
// }
#[inline(always)]
pub unsafe fn write_u32(port: u16, value: u32) {
unsafe {
asm!(
"out dx, eax",
in("dx") port,
in("eax") value,
options(nomem, nostack, preserves_flags),
);
}
}
// #[inline(always)]
// pub unsafe fn write_u32(port: u16, value: u32) {
// unsafe {
// asm!(
// "out dx, eax",
// in("dx") port,
// in("eax") value,
// options(nomem, nostack, preserves_flags),
// );
// }
// }