From ff0bd96abd34b7383f74d0609b41e81f333b85cf Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Mon, 18 Mar 2024 14:26:00 +0100 Subject: [PATCH] Improve readability --- src/arch/x86/gdt.rs | 10 ++++++---- src/arch/x86_64/gdt.rs | 10 +++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/arch/x86/gdt.rs b/src/arch/x86/gdt.rs index 62680c11cf..bd5cf3aec5 100644 --- a/src/arch/x86/gdt.rs +++ b/src/arch/x86/gdt.rs @@ -120,6 +120,8 @@ const BASE_GDT: [GdtEntry; 9] = [ GdtEntry::new(0, 0, GDT_A_PRESENT | GDT_A_RING_3 | GDT_A_TSS_AVAIL, 0), ]; +const IOBITMAP_SIZE: usize = 8192; + #[repr(C, align(4096))] pub struct ProcessorControlRegion { pub self_ref: usize, @@ -127,8 +129,8 @@ pub struct ProcessorControlRegion { pub gdt: [GdtEntry; 9], percpu: crate::percpu::PercpuBlock, pub tss: TssWrapper, - pub pio_bitmap: [u8; 8192], - pub all_ones: u8, + pub _pio_bitmap: [u8; IOBITMAP_SIZE], + pub _all_ones: u8, } // NOTE: Despite not using #[repr(packed)], we do know that while there may be some padding @@ -193,12 +195,12 @@ pub unsafe fn init_paging(stack_offset: usize, cpu_id: LogicalCpuId) { }; { - pcr.all_ones = 0xFF; + pcr._all_ones = 0xFF; pcr.tss.0.iobp_offset = 0xFFFF; let tss = &pcr.tss.0 as *const _ as usize as u32; pcr.gdt[GDT_TSS].set_offset(tss); - pcr.gdt[GDT_TSS].set_limit(mem::size_of::() as u32 + 8192); + pcr.gdt[GDT_TSS].set_limit(mem::size_of::() as u32 + IOBITMAP_SIZE); } // Load the new GDT, which is correctly located in thread local storage. diff --git a/src/arch/x86_64/gdt.rs b/src/arch/x86_64/gdt.rs index cc8c6f8fa5..d52f469255 100644 --- a/src/arch/x86_64/gdt.rs +++ b/src/arch/x86_64/gdt.rs @@ -121,8 +121,12 @@ pub struct ProcessorControlRegion { pub gdt: [GdtEntry; 8], pub percpu: PercpuBlock, pub tss: TaskStateSegment, - pub iobitmap: [u8; IOBITMAP_SIZE as usize], - pub all_ones: u8, + + // These two fields are read by the CPU, but not currently modified by the kernel. Instead, the + // kernel sets the `iomap_base` field in the TSS, to either point to this bitmap, or outside + // the TSS, in which case userspace is not granted port IO access. + pub _iobitmap: [u8; IOBITMAP_SIZE as usize], + pub _all_ones: u8, } const _: () = { @@ -213,7 +217,7 @@ pub unsafe fn init_paging(stack_offset: usize, cpu_id: LogicalCpuId) { { pcr.tss.iomap_base = 0xFFFF; - pcr.all_ones = 0xFF; + pcr._all_ones = 0xFF; let tss = &mut pcr.tss as *mut TaskStateSegment as usize as u64; let tss_lo = (tss & 0xFFFF_FFFF) as u32;