Skip to content

Commit 5e24e84

Browse files
author
Dan Cross
committed
node: per-node/CPU segments
Signed-off-by: Dan Cross <[email protected]>
1 parent 6cf5d47 commit 5e24e84

File tree

19 files changed

+442
-69
lines changed

19 files changed

+442
-69
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ members = [
1212
"hypatia",
1313
"memory",
1414
"monitor",
15+
"node",
1516
"scheduler",
1617
"supervisor",
1718
"system",

global/src/main.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,9 @@
1313

1414
mod x86_64;
1515

16-
use arch::Page4K;
17-
18-
/// Returns a static reference to the global zero page.
19-
pub fn zero_page() -> &'static Page4K {
20-
const ZERO_PAGE: Page4K = Page4K::new();
21-
&ZERO_PAGE
22-
}
23-
2416
/// Initialize the system.
2517
#[unsafe(no_mangle)]
2618
pub extern "C" fn init() {
27-
zero_page();
2819
uart::panic_println!("Hello from global");
2920
}
3021

node/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2021 The Hypatia Authors
2+
# All rights reserved
3+
#
4+
# Use of this source code is governed by an MIT-style
5+
# license that can be found in the LICENSE file or at
6+
# https://opensource.org/licenses/MIT.
7+
8+
[package]
9+
name = "node"
10+
version = "0.1.0"
11+
edition = "2024"
12+
13+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
14+
15+
[dependencies]
16+
arch = { package = "x86_64", path = "../x86_64" }
17+
hypatia = { path = "../hypatia" }
18+
uart = { path = "../uart" }

node/build.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2023 The Hypatia Authors
2+
// All rights reserved
3+
//
4+
// Use of this source code is governed by an MIT-style
5+
// license that can be found in the LICENSE file or at
6+
// https://opensource.org/licenses/MIT.
7+
8+
use std::env;
9+
10+
fn main() {
11+
let target = env::var("TARGET").unwrap();
12+
if target.as_str() == "x86_64-unknown-none-elf" {
13+
println!("cargo:rustc-link-arg-bins=-Tnode/src/link.ld")
14+
}
15+
}

node/src/link.ld

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2023 The Hypatia Authors
3+
* All rights reserved
4+
*
5+
* Use of this source code is governed by an MIT-style
6+
* license that can be found in the LICENSE file or at
7+
* https://opensource.org/licenses/MIT.
8+
*/
9+
10+
ENTRY(init)
11+
12+
SECTIONS {
13+
. = 0xFFFFFB4000000000;
14+
15+
.xferv . :
16+
{
17+
KEEP(*(.xferv*))
18+
}
19+
. = ALIGN(4096);
20+
21+
.text . :
22+
{
23+
*(.text*)
24+
}
25+
. = ALIGN(4096);
26+
PROVIDE(etext = .);
27+
28+
.rodata . :
29+
{
30+
*(.rodata*)
31+
}
32+
. = ALIGN(4096);
33+
PROVIDE(erodata = .);
34+
35+
.got . :
36+
{
37+
*(.got*)
38+
}
39+
. = ALIGN(4096);
40+
41+
.data . :
42+
{
43+
*(.data*)
44+
}
45+
. = ALIGN(4096);
46+
PROVIDE(edata = .);
47+
48+
.bss . :
49+
{
50+
*(.bss*)
51+
*(COMMON)
52+
}
53+
. = ALIGN(4096);
54+
55+
PROVIDE(end = .);
56+
}

node/src/main.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2023 The Hypatia Authors
2+
// All rights reserved
3+
//
4+
// Use of this source code is governed by an MIT-style
5+
// license that can be found in the LICENSE file or at
6+
// https://opensource.org/licenses/MIT.
7+
8+
#![feature(sync_unsafe_cell)]
9+
#![cfg_attr(not(test), no_main)]
10+
#![cfg_attr(not(test), no_std)]
11+
#![forbid(absolute_paths_not_starting_with_crate)]
12+
#![forbid(elided_lifetimes_in_paths)]
13+
#![forbid(unsafe_op_in_unsafe_fn)]
14+
15+
use arch::Page4K;
16+
17+
mod x86_64;
18+
19+
/// Returns a static reference to the global zero page.
20+
pub fn zero_page() -> &'static Page4K {
21+
const ZERO_PAGE: Page4K = Page4K::new();
22+
&ZERO_PAGE
23+
}
24+
25+
/// Initialize the system.
26+
#[unsafe(no_mangle)]
27+
pub extern "C" fn init() {
28+
x86_64::init();
29+
}
30+
31+
hypatia::runtime!();

node/src/x86_64/gdt.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2023 The Hypatia Authors
2+
// All rights reserved
3+
//
4+
// Use of this source code is governed by an MIT-style
5+
// license that can be found in the LICENSE file or at
6+
// https://opensource.org/licenses/MIT.
7+
8+
use arch::{Page, V4KA, VPageAddr, gdt};
9+
use core::sync::atomic::{AtomicBool, Ordering};
10+
11+
#[unsafe(link_section = ".gdt")]
12+
static mut GDT: gdt::GDT = gdt::GDT::empty();
13+
static INITED: AtomicBool = AtomicBool::new(false);
14+
15+
pub(crate) fn map() {
16+
let zeros = crate::zero_page();
17+
let va = V4KA::new((&raw const GDT).addr());
18+
const R: bool = true;
19+
const NW: bool = false;
20+
const NX: bool = false;
21+
for k in 1..16 {
22+
let zva = V4KA::new(va.addr() + k * 4096);
23+
arch::vm::map_leaf(zeros.frame(), zva, R, NW, NX).expect("mapped zero page in GDT");
24+
}
25+
}
26+
27+
pub(crate) fn init(task_state: &arch::tss::TSS) {
28+
if !INITED.swap(true, Ordering::AcqRel) {
29+
let gdtp = &raw mut GDT;
30+
let gdt = unsafe { &mut *gdtp };
31+
gdt.init(task_state);
32+
unsafe {
33+
arch::gdt::load(gdt);
34+
}
35+
}
36+
}

node/src/x86_64/idt.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2023 The Hypatia Authors
2+
// All rights reserved
3+
//
4+
// Use of this source code is governed by an MIT-style
5+
// license that can be found in the LICENSE file or at
6+
// https://opensource.org/licenses/MIT.
7+
8+
use core::cell::SyncUnsafeCell;
9+
use core::sync::atomic::{AtomicBool, Ordering};
10+
11+
static IDT: SyncUnsafeCell<arch::idt::IDT> = SyncUnsafeCell::new(arch::idt::IDT::empty());
12+
static INITED: AtomicBool = AtomicBool::new(false);
13+
14+
pub(crate) fn init() {
15+
if INITED.swap(true, Ordering::AcqRel) {
16+
panic!("double init node IDT");
17+
}
18+
let idt = unsafe { &mut *IDT.get() };
19+
idt.init(arch::trap::stubs());
20+
unsafe {
21+
arch::idt::load(idt);
22+
}
23+
}

node/src/x86_64/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2023 The Hypatia Authors
2+
// All rights reserved
3+
//
4+
// Use of this source code is governed by an MIT-style
5+
// license that can be found in the LICENSE file or at
6+
// https://opensource.org/licenses/MIT.
7+
8+
pub(crate) mod gdt;
9+
pub(crate) mod idt;
10+
pub(crate) mod tss;
11+
mod xferv;
12+
13+
pub(crate) fn init() {
14+
idt::init();
15+
gdt::map();
16+
let tss = tss::init();
17+
gdt::init(tss);
18+
}

0 commit comments

Comments
 (0)