Compare commits

..

No commits in common. "df5208827c73cd33f43d99376fd155e611ab99e8" and "58d684564fd16aff1d2ba0e5fef6e36d7b27116d" have entirely different histories.

10 changed files with 1775 additions and 56 deletions

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
/target /target
/build /build
.idea .idea
/log

BIN
.tlb.txt.kate-swp Normal file

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", "-no-reboot", "-no-shutdown", "-serial", "stdio", "-d", "int"] args = ["-s", "-S", "-display", "none", "-drive", "file=build/gila.iso,format=raw,index=0,media=disk", "-serial", "stdio"]
[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: no kaslr: yes
randomize_hhdm_base: no randomize_hhdm_base: yes
//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: no kaslr: yes
randomize_hhdm_base: no randomize_hhdm_base: yes
//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: no kaslr: yes
randomize_hhdm_base: no randomize_hhdm_base: yes

46
log.txt Normal file
View File

@ -0,0 +1,46 @@
check_exception old: 0xffffffff new 0xe // Page Fault
0: v=0e e=0015 i=0 cpl=3 IP=001b:ffffffff800175b0 pc=ffffffff800175b0 SP=0023:ffffffff8f000000 CR2=ffffffff800175b0 // Correct address
RAX=0000000000000200 RBX=0000000000000000 RCX=ffffffff800175b0 RDX=ffffffff8f000000
RSI=000000000000001b RDI=ffffffff8f000023 RBP=0000000000000000 RSP=ffffffff8f000000
R8 =ffffffff8f000000 R9 =ffffffff800175b0 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=ffffffff800175b0 RFL=00000202 [-------] CPL=3 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00001300
CS =001b 0000000000000000 ffffffff 00affb00 DPL=3 CS64 [-RA]
SS =0023 0000000000000000 ffffffff 00aff300 DPL=3 DS [-WA]
DS =0000 0000000000000000 00000000 00001300
FS =0000 0000000000000000 00000000 00001300
GS =0000 0000000000000000 00000000 00001300
LDT=0000 0000000000000000 00000000 00008200 DPL=0 LDT
TR =0038 0000000000000000 00000000 00008900 DPL=0 TSS64-avl
GDT= ffffffff80044498 00000037
IDT= ffffffff800433d0 00000fff
CR0=80010011 CR2=ffffffff800175b0 CR3=0000000007d9e000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000000 CCD=ffff800007dad588 CCO=EFLAGS
EFER=0000000000000d00
check_exception old: 0xe new 0xd // General Protection Fault
1: v=08 e=0000 i=0 cpl=3 IP=001b:ffffffff800175b0 pc=ffffffff800175b0 SP=0023:ffffffff8f000000 env->regs[R_EAX]=0000000000000200
RAX=0000000000000200 RBX=0000000000000000 RCX=ffffffff800175b0 RDX=ffffffff8f000000
RSI=000000000000001b RDI=ffffffff8f000023 RBP=0000000000000000 RSP=ffffffff8f000000
R8 =ffffffff8f000000 R9 =ffffffff800175b0 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=ffffffff800175b0 RFL=00000202 [-------] CPL=3 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00001300
CS =001b 0000000000000000 ffffffff 00affb00 DPL=3 CS64 [-RA]
SS =0023 0000000000000000 ffffffff 00aff300 DPL=3 DS [-WA]
DS =0000 0000000000000000 00000000 00001300
FS =0000 0000000000000000 00000000 00001300
GS =0000 0000000000000000 00000000 00001300
LDT=0000 0000000000000000 00000000 00008200 DPL=0 LDT
TR =0038 0000000000000000 00000000 00008900 DPL=0 TSS64-avl
GDT= ffffffff80044498 00000037
IDT= ffffffff800433d0 00000fff
CR0=80010011 CR2=ffffffff800175b0 CR3=0000000007d9e000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000000 CCD=ffff800007dad588 CCO=EFLAGS
EFER=0000000000000d00
check_exception old: 0x8 new 0xd // Second General Protection Fault
// Instead of calling the GPF handler again it's just a triple fault

1709
log1.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
// 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() {
@ -19,23 +20,3 @@ 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,21 +33,6 @@ 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,
@ -58,10 +43,8 @@ pub struct Selectors {
pub gdt: GlobalDescriptorTable<48>, pub gdt: GlobalDescriptorTable<48>,
} }
pub const TSS: TaskStateSegment = TaskStateSegment::new();
lazy_static! { lazy_static! {
#[derive(Debug)] pub static ref TSS: TaskStateSegment = TaskStateSegment::new();
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
@ -158,7 +141,7 @@ pub fn dump_gdt() {
} }
#[derive(Debug)] #[derive(Debug)]
pub enum SegmentType { enum SegmentType {
Null, Null,
Code, Code,
Data, Data,

View File

@ -42,10 +42,15 @@ use x86_64::{
use crate::{ use crate::{
arch::{ arch::{
asm::{self, ltr, str}, x86_64::{ asm,
cpuid::{CPUID, virt_supported}, gdt::{SELECTORS, SegmentType, TSS, dump_gdt}, interrupts::get_lapic_addr, x86_64::{
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! {
@ -243,7 +248,6 @@ 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,
@ -251,15 +255,12 @@ 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(0xffffffff80000000), VirtAddr::new(0xffffffff8f000000),
SELECTORS.sel_user_stack, SELECTORS.sel_user_stack,
) )
.iretq(); .iretq();

0
tlb.txt Normal file
View File