Skip to content

Commit 23d32d0

Browse files
committed
gdt: Add definitions for 32-bit GDT
Our 32-bit GDT just has 1 code and 1 data segment descriptor. They are both flat (spanning the entire 4G address space) and are placed in normal static memory (for now). Signed-off-by: Joe Richey <[email protected]>
1 parent f7f5c6d commit 23d32d0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/gdt.rs

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ bitflags::bitflags! {
2626
const COMMON = Self::ACCESSED.bits | Self::USER_SEGMENT.bits | Self::PRESENT.bits;
2727
// BIT32 must be 0, all other bits (not yet mentioned) are ignored.
2828
const CODE64 = Self::COMMON.bits | Self::EXECUTABLE.bits | Self::BIT64.bits;
29+
30+
// All 32-bit segments have base = 0, limit = 4G = (0xF_FFFF + 1)*4K
31+
const MAX_LIMIT = Self::LIMIT_0_15.bits | Self::LIMIT_16_19.bits | Self::GRANULARITY.bits;
32+
const COMMON32 = Self::COMMON.bits | Self::MAX_LIMIT.bits | Self::BIT32.bits;
33+
// We set READABLE because the ROM code reads data via cs.
34+
const CODE32 = Self::COMMON32.bits | Self::READABLE.bits | Self::EXECUTABLE.bits;
35+
// We set WRITABLE so the ROM code can write ROM data into RAM.
36+
const DATA32 = Self::COMMON32.bits | Self::WRITABLE.bits;
2937
}
3038
}
3139

@@ -51,3 +59,7 @@ impl Pointer {
5159
#[no_mangle]
5260
static GDT64_PTR: Pointer = Pointer::new(&GDT64);
5361
static GDT64: [Descriptor; 2] = [Descriptor::empty(), Descriptor::CODE64];
62+
63+
#[no_mangle]
64+
static GDT32_PTR: Pointer = Pointer::new(&GDT32);
65+
static GDT32: [Descriptor; 3] = [Descriptor::empty(), Descriptor::CODE32, Descriptor::DATA32];

0 commit comments

Comments
 (0)