Skip to content

Commit 31e9d98

Browse files
author
Dan Cross
committed
WIP: Laying the groundwork for per-node/CPU segments
Signed-off-by: Dan Cross <[email protected]>
1 parent 2ff007b commit 31e9d98

File tree

6 files changed

+183
-53
lines changed

6 files changed

+183
-53
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

theon/src/main.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
//! execution. Theon will locate them, and load them into
4646
//! physical memory.
4747
//!
48-
//! Each binary is allocated a 16MiB region of physical RAM for
49-
//! its various pages; these regions begin at 64MiB and are
50-
//! aligned on 32MiB boundaries, giving us room for loading new
51-
//! images into the second 16MiBs of each binary's region for
48+
//! Each binary is allocated an 8MiB region of physical RAM for
49+
//! its various pages; these regions begin at 16MiB and are
50+
//! aligned on 16MiB boundaries, giving us room for loading new
51+
//! images into the second 8MiBs of each binary's region for
5252
//! hitless update.
5353
//!
5454
//! Binaries represent either tasks or segments; see HDP 0002
@@ -104,13 +104,13 @@ enum BinaryType {
104104
/// or a task).
105105
type BinaryMeta = (&'static str, HPA, BinaryType);
106106

107-
/// Binaries are loaded in 16MiB regions of physical memory
108-
/// that are aligned on 32MiB boundaries, starting at 64MiB.
107+
/// Binaries are loaded in 8MiB regions of physical memory
108+
/// that are aligned on 16MiB boundaries, starting at 16MiB.
109109
const fn load_addr(offset: usize) -> HPA {
110-
let addr = (64 + offset * 32) * MIB;
110+
let addr = (16 + offset * 16) * MIB;
111111
HPA::new(addr as u64)
112112
}
113-
const BINARY_IMAGE_MEMORY_SIZE: usize = 16 * MIB;
113+
const BINARY_IMAGE_MEMORY_SIZE: usize = 8 * MIB;
114114

115115
/// A table description all the binaries that are loaded by
116116
/// theon, where to load them in physical memory, and their
@@ -157,10 +157,12 @@ pub extern "C" fn main(mbinfo_phys: u64) -> ! {
157157
let archive = goblin::archive::Archive::parse(bins.bytes).expect("cannot parse bin.a");
158158
uart::panic_println!("Binary archive: {:#x?}", archive);
159159
clear_binary_load_region();
160+
let mut roots = alloc::vec::Vec::with_capacity(BINARY_TABLE.len());
160161
for &(name, addr, typ) in BINARY_TABLE {
161162
let bytes = archive.extract(name, bins.bytes).expect("cannot extract elf");
162163
let region_end = addr.offset(BINARY_IMAGE_MEMORY_SIZE);
163-
load(name, typ, bytes, addr..region_end).expect("loaded binary");
164+
let root = load(name, typ, bytes, addr..region_end).expect("loaded binary");
165+
roots.push((name, root));
164166
}
165167
unsafe { core::arch::asm!("int3") };
166168
// Start other CPUs.

x86_64/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ bitflags = "*"
1717
bit_field = "*"
1818
bitstruct = "*"
1919
seq-macro = "*"
20+
static_assertions = "*"
2021
x86 = "*"
2122
zerocopy = "*"

x86_64/src/gdt.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
use crate::segment;
1313
use crate::tss::TSS;
1414
use core::arch::asm;
15+
use static_assertions::const_assert_eq;
1516

1617
/// Support the x86_64 64-bit Global Descriptor Table.
1718
///
1819
/// We waste a few bytes per CPU by allocating a 4KiB page for
1920
/// the GDT, then we map that at the known GDT location in the
20-
/// per-CPU virtual memory segment, but we pad that out to 64KiB
21+
/// per-node virtual memory segment. We pad that out to 64KiB
2122
/// by mapping the zero page repeatedly beyond the end of the
2223
/// GDT proper.
2324
///
@@ -34,7 +35,9 @@ pub struct GDT {
3435
_usertext: segment::Descriptor,
3536
_unused: segment::Descriptor, // For alignment.
3637
task: segment::TaskStateDescriptor,
38+
_empty: [u64; 512 - 8],
3739
}
40+
const_assert_eq!(core::mem::size_of::<GDT>(), 4096);
3841

3942
impl GDT {
4043
pub const fn empty() -> GDT {
@@ -46,6 +49,7 @@ impl GDT {
4649
_usertext: segment::Descriptor::empty(),
4750
_unused: segment::Descriptor::empty(),
4851
task: segment::TaskStateDescriptor::empty(),
52+
_empty: [0; 512 - 8],
4953
}
5054
}
5155

@@ -71,12 +75,11 @@ impl GDT {
7175
/// descriptor.
7276
///
7377
/// # Safety
74-
///
7578
/// Called on a valid GDT.
7679
unsafe fn lgdt(&self) {
7780
let ptr: *const Self = self;
7881
let base = u64::try_from(ptr.addr()).unwrap();
79-
const LIMIT: u16 = core::mem::size_of::<GDT>() as u16 - 1;
82+
const LIMIT: u16 = 65535;
8083
unsafe {
8184
asm!(r#"
8285
subq $16, %rsp;

x86_64/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub trait Page {
117117

118118
fn frame(&self) -> Self::FrameType {
119119
let addr = self.vaddr().addr();
120-
let pfa = vm::translate(addr);
120+
let pfa = vm::translate(addr).expect("Page is mapped");
121121
Self::FrameType::new(pfa)
122122
}
123123
}

0 commit comments

Comments
 (0)