Compare commits

..

3 Commits

Author SHA1 Message Date
2e626a33d1
Mess with Userboot loading
Some checks failed
Continuous Integration / Check (push) Failing after 1m1s
Continuous Integration / Clippy (push) Failing after 59s
2026-11-10 04:41:08 +00:00
5e0075abc2
Fix docs wording 2026-11-10 03:38:42 +00:00
27e643426a
Clippy, format, docs 2026-11-10 03:35:41 +00:00
5 changed files with 58 additions and 11 deletions

View File

@ -51,4 +51,39 @@ different protection mechanism for userspace capabilities.
Lastly, I want to figure out a way to make the kernel's capability Lastly, I want to figure out a way to make the kernel's capability
representation a little more... *robust*, I guess. More idiomatic Rust. Using representation a little more... *robust*, I guess. More idiomatic Rust. Using
raw pointers everywhere feels sloppy. Maybe this is a good application of raw pointers everywhere feels sloppy. Maybe this is a good application of
`PhantomData<T>`? `PhantomData<T>`?
## 2026-11-09: Capability management refinement
I decided to use `Pin<&mut Capability>` for the derivation tree pointers. This
makes a lot of sense, considering the capabilities aren't supposed to move
around in memory.
For capabilities representing memory ranges, we can use a "buddy" system:
52 bits of a 64-bit pointer are used to refer to the base address of the range.
6 of the remaining 12 bits can be used to represent the number of pages in the
range. If we call this 6-bit value n, then the number of pages represented by
the capability can be defined as 2^n. Access rights can be encoded in the final
6 bits. We can represent any number of pages using binary partitioning, which
results in multiple range capabilities of unique page counts that are powers of
two.
For page type capabilities, we can do something similar, except we use all 12
low bits for access rights. Keeping all capability types the same size allows
for convenient storage of capabilities in an array, as enum variants with
associated types. Boom!!!
Userboot will regrettably need to be moved to a different crate altogether, so
it might be wise to turn this repo back into a workspace. This is because the
same `build.rs` file gets used for both Userboot and the kernel, which causes
Userboot to be linked as a static, non-relocatable executable, to be loaded at
`0xffffffff80000000`. We cannot remap this address range, because it belongs to
the kernel, which must be loaded at all times to allow for interrupt handling.
There are a few ways I could fix this:
- Compile and link Userboot as a relocatable ELF, which necessitates adding an
ELF parser+loader to the kernel. I dislike this option.
- Compile and link Userboot with a different load address, which I can remap
via paging. By compiling the binary with a load address of `0x1000`, it would
be possible to map it to a clean address space that does not collide with the
kernel. Loading at `0x0` is impossible due to nullptr detection.

View File

@ -24,6 +24,6 @@ pub fn amd_v_supported() -> bool {
#[allow(dead_code)] #[allow(dead_code)]
pub fn enable_svm() { pub fn enable_svm() {
let mut efer: u64 = x86_64::registers::model_specific::Efer::read().bits(); let mut efer: u64 = x86_64::registers::model_specific::Efer::read().bits();
intbits::Bits::set_bit(&mut efer, 12,true); intbits::Bits::set_bit(&mut efer, 12, true);
unsafe { x86_64::registers::model_specific::Efer::write(EferFlags::from_bits_retain(efer)) }; unsafe { x86_64::registers::model_specific::Efer::write(EferFlags::from_bits_retain(efer)) };
} }

View File

@ -40,3 +40,11 @@ pub fn str() -> u16 {
} }
result result
} }
pub fn halt() {
unsafe {
asm!(
"hlt"
)
}
}

View File

@ -4,11 +4,11 @@
use core::arch::asm; use core::arch::asm;
use core::ptr::{addr_of, addr_of_mut}; use core::ptr::{addr_of, addr_of_mut};
use intbits::Bits;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use x86_64::structures::gdt; use x86_64::structures::gdt;
use x86_64::structures::gdt::*; use x86_64::structures::gdt::*;
use x86_64::structures::tss::TaskStateSegment; use x86_64::structures::tss::TaskStateSegment;
use intbits::Bits;
use crate::log::*; use crate::log::*;
use crate::memory::alloc::format; use crate::memory::alloc::format;
@ -23,12 +23,15 @@ trait ModifyFlags {
impl ModifyFlags for Descriptor { impl ModifyFlags for Descriptor {
fn set_flags(self, flags: DescriptorFlags) -> Descriptor { fn set_flags(self, flags: DescriptorFlags) -> Descriptor {
match self { match self {
Descriptor::UserSegment(a) => { Descriptor::UserSegment(a) => Descriptor::UserSegment(intbits::Bits::with_bits(
Descriptor::UserSegment(intbits::Bits::with_bits(a, 52..=55, intbits::Bits::bits(flags.bits(), 0..=3))) a,
} 52..=55,
Descriptor::SystemSegment(a, b) => { intbits::Bits::bits(flags.bits(), 0..=3),
Descriptor::SystemSegment(intbits::Bits::with_bits(a, 52..=55, intbits::Bits::bits(flags.bits(), 0..=3)), b) )),
} Descriptor::SystemSegment(a, b) => Descriptor::SystemSegment(
intbits::Bits::with_bits(a, 52..=55, intbits::Bits::bits(flags.bits(), 0..=3)),
b,
),
} }
} }
} }

View File

@ -23,8 +23,8 @@ use log::*;
use memory::alloc::format; use memory::alloc::format;
use params::*; use params::*;
use x86_64::VirtAddr;
use crate::boot::modules::MODULE_RESPONSE; use crate::boot::modules::MODULE_RESPONSE;
use x86_64::VirtAddr;
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
unsafe extern "C" fn main() -> ! { unsafe extern "C" fn main() -> ! {
@ -61,10 +61,11 @@ unsafe extern "C" fn main() -> ! {
{ {
let ub = modules_list.modules()[0]; let ub = modules_list.modules()[0];
log_info!("Found userboot: {} {}", ub.path(), ub.cmdline()); log_info!("Found userboot: {} {}", ub.path(), ub.cmdline());
// TODO: remap userboot as user pages // TODO: remap userboot as user pages, map writable memory to stack
let start_addr = VirtAddr::from_ptr(ub.data() as *const [u8]); let start_addr = VirtAddr::from_ptr(ub.data() as *const [u8]);
log_trace!("Userboot start address: 0x{:x}", start_addr); log_trace!("Userboot start address: 0x{:x}", start_addr);
//arch::asm::halt(); // Uncomment this to examine behavior prior to usermode jump
arch::startup::jump_to_usermode(VirtAddr::new(0xffffffff80000000), start_addr) arch::startup::jump_to_usermode(VirtAddr::new(0xffffffff80000000), start_addr)
} else { } else {
panic!("Userboot not found, cannot boot!"); panic!("Userboot not found, cannot boot!");