Debugging triple fault
Some checks failed
Continuous Integration / Check (push) Failing after 50s
Continuous Integration / Clippy (push) Failing after 49s

This commit is contained in:
August 2026-07-03 03:09:37 +00:00
parent 1c4245e38a
commit df5208827c
Signed by: shibedrill
SSH Key Fingerprint: SHA256:M0m3JW1s38BgO2t0fG146Yxd9OJ2IOqkvCAsuRHQ6Pw
6 changed files with 54 additions and 19 deletions

Binary file not shown.

View File

@ -160,7 +160,7 @@ args = ["-display", "none", "-drive", "file=build/gila.iso,format=raw,index=0,me
[tasks.debug_run] [tasks.debug_run]
dependencies = ["iso"] dependencies = ["iso"]
command = "${QEMUCOMMAND}" command = "${QEMUCOMMAND}"
args = ["-s", "-S", "-display", "none", "-drive", "file=build/gila.iso,format=raw,index=0,media=disk", "-serial", "stdio"] args = ["-s", "-S", "-display", "none", "-drive", "file=build/gila.iso,format=raw,index=0,media=disk", "-no-reboot", "-no-shutdown", "-serial", "stdio", "-d", "int"]
[tasks.debug_view] [tasks.debug_view]
dependencies = ["iso"] dependencies = ["iso"]

View File

@ -12,21 +12,21 @@ comment: The Gila microkernel.
kernel_path: boot():/boot/${ARCH}/kernel kernel_path: boot():/boot/${ARCH}/kernel
cmdline: -loglevel=Trace -logdev=display,serial cmdline: -loglevel=Trace -logdev=display,serial
module_path: boot():/boot/${ARCH}/userboot.bin module_path: boot():/boot/${ARCH}/userboot.bin
kaslr: yes kaslr: no
randomize_hhdm_base: yes randomize_hhdm_base: no
//Info //Info
protocol: limine protocol: limine
kernel_path: boot():/boot/${ARCH}/kernel kernel_path: boot():/boot/${ARCH}/kernel
cmdline: -loglevel=Info -logdev=display,serial cmdline: -loglevel=Info -logdev=display,serial
module_path: boot():/boot/${ARCH}/userboot.bin module_path: boot():/boot/${ARCH}/userboot.bin
kaslr: yes kaslr: no
randomize_hhdm_base: yes randomize_hhdm_base: no
//Warn //Warn
protocol: limine protocol: limine
kernel_path: boot():/boot/${ARCH}/kernel kernel_path: boot():/boot/${ARCH}/kernel
cmdline: -loglevel=Warning -logdev=display,serial cmdline: -loglevel=Warning -logdev=display,serial
module_path: boot():/boot/${ARCH}/userboot.bin module_path: boot():/boot/${ARCH}/userboot.bin
kaslr: yes kaslr: no
randomize_hhdm_base: yes randomize_hhdm_base: no

View File

@ -2,7 +2,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
use core::arch::asm; use core::arch::asm;
use intbits::Bits; use intbits::Bits;
pub fn nop() { pub fn nop() {
@ -20,3 +19,23 @@ pub fn long_mode() -> bool {
} }
output.bit(29) output.bit(29)
} }
pub fn ltr(selector: u16) {
unsafe {
asm!(
"ltr ax",
in("ax") selector
)
}
}
pub fn str() -> u16 {
let result: u16;
unsafe {
asm!(
"str ax",
out("ax") result,
)
}
result
}

View File

@ -33,6 +33,21 @@ impl ModifyFlags for Descriptor {
} }
} }
trait ModifyAccess {
fn set_access(self, access: u8) -> Self;
}
impl ModifyAccess for Descriptor {
fn set_access(self, access: u8) -> Self {
match self {
Descriptor::UserSegment(_) => todo!(),
Descriptor::SystemSegment(a, b) => {
Descriptor::SystemSegment(a.with_bits(40..=47, access.bits(0..=7).into()), b)
},
}
}
}
pub struct Selectors { pub struct Selectors {
pub sel_kernel_code: SegmentSelector, pub sel_kernel_code: SegmentSelector,
pub sel_kernel_stack: SegmentSelector, pub sel_kernel_stack: SegmentSelector,
@ -43,8 +58,10 @@ pub struct Selectors {
pub gdt: GlobalDescriptorTable<48>, pub gdt: GlobalDescriptorTable<48>,
} }
pub const TSS: TaskStateSegment = TaskStateSegment::new();
lazy_static! { lazy_static! {
pub static ref TSS: TaskStateSegment = TaskStateSegment::new(); #[derive(Debug)]
pub static ref SELECTORS: Selectors = { pub static ref SELECTORS: Selectors = {
let mut gdt = GlobalDescriptorTable::empty(); let mut gdt = GlobalDescriptorTable::empty();
// DO NOT REORDER // DO NOT REORDER
@ -141,7 +158,7 @@ pub fn dump_gdt() {
} }
#[derive(Debug)] #[derive(Debug)]
enum SegmentType { pub enum SegmentType {
Null, Null,
Code, Code,
Data, Data,

View File

@ -42,15 +42,10 @@ use x86_64::{
use crate::{ use crate::{
arch::{ arch::{
asm, asm::{self, ltr, str}, x86_64::{
x86_64::{ cpuid::{CPUID, virt_supported}, gdt::{SELECTORS, SegmentType, TSS, dump_gdt}, interrupts::get_lapic_addr,
cpuid::{CPUID, virt_supported},
gdt::{SELECTORS, dump_gdt},
interrupts::get_lapic_addr,
}, },
}, }, boot::modules::MODULE_RESPONSE, memory::paging::{self, active_root_table, map_page, phys_to_virt},
boot::modules::MODULE_RESPONSE,
memory::paging::{self, active_root_table, map_page, phys_to_virt},
}; };
lazy_static! { lazy_static! {
@ -248,6 +243,7 @@ unsafe extern "C" fn main() -> ! {
log_trace!("GDT_SELECTOR_USER_DATA: {}", SELECTORS.sel_user_stack.0); log_trace!("GDT_SELECTOR_USER_DATA: {}", SELECTORS.sel_user_stack.0);
log_trace!("GDT_SELECTOR_KERNEL_CODE: {}", SELECTORS.sel_kernel_code.0); log_trace!("GDT_SELECTOR_KERNEL_CODE: {}", SELECTORS.sel_kernel_code.0);
log_trace!("GDT_SELECTOR_KERNEL_DATA: {}", SELECTORS.sel_kernel_stack.0); log_trace!("GDT_SELECTOR_KERNEL_DATA: {}", SELECTORS.sel_kernel_stack.0);
log_trace!("GDT_SELECTOR_TSS: {}", SELECTORS.sel_tss.0);
x86_64::registers::model_specific::Star::write( x86_64::registers::model_specific::Star::write(
SELECTORS.sel_user_code, SELECTORS.sel_user_code,
SELECTORS.sel_user_stack, SELECTORS.sel_user_stack,
@ -255,12 +251,15 @@ unsafe extern "C" fn main() -> ! {
SELECTORS.sel_kernel_stack, SELECTORS.sel_kernel_stack,
) )
.expect("fuck"); .expect("fuck");
log_trace!("STR before loading new TSS: {}", str());
ltr(SELECTORS.sel_tss.0);
log_trace!("STR after loading new TSS: {}", str());
unsafe { unsafe {
InterruptStackFrameValue::new( InterruptStackFrameValue::new(
VirtAddr::from_ptr(usermode_fn as *const fn()), VirtAddr::from_ptr(usermode_fn as *const fn()),
SELECTORS.sel_user_code, SELECTORS.sel_user_code,
RFlags::INTERRUPT_FLAG, RFlags::INTERRUPT_FLAG,
VirtAddr::new(0xffffffff8f000000), VirtAddr::new(0xffffffff80000000),
SELECTORS.sel_user_stack, SELECTORS.sel_user_stack,
) )
.iretq(); .iretq();