x86_64 icon indicating copy to clipboard operation
x86_64 copied to clipboard

const fn gdt creation

Open tepperson2 opened this issue 3 years ago • 4 comments

I would like the ability to create a GlobalDescriptorTable with a const fn. I am writing a kernel and need to ensure that no 64-bit code runs before I jump to long mode because the kernel is started in 32-bit mode. I want to define the gdt structure with rust.

tepperson2 avatar Feb 28 '23 14:02 tepperson2

I just noticed the "const_fn" feature, but I would like to do this on stable rust.

tepperson2 avatar Feb 28 '23 14:02 tepperson2

The const_fn feature is using the compiler's unstable const_mut_refs feature, which is hopefully stabilized soon. See https://github.com/rust-lang/rust/issues/57349 for the current state. Unfortunately, we don't have any other way to create a GDT in a const environment at the moment. If you have an idea how we could implement it, please let us know!

phil-opp avatar Mar 01 '23 10:03 phil-opp

I added a pull request https://github.com/rust-osdev/x86_64/pull/406

tepperson2 avatar Mar 03 '23 17:03 tepperson2

Note that you can also use GlobalDescriptorTable::from_raw_slice if you want something that works on the current version of stable Rust.

josephlr avatar Mar 03 '23 21:03 josephlr