Skip to content

Commit 2bcce3a

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

File tree

15 files changed

+414
-53
lines changed

15 files changed

+414
-53
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",

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 = "2021"
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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(naked_functions)]
9+
#![feature(strict_provenance)]
10+
#![cfg_attr(not(test), no_main)]
11+
#![cfg_attr(not(test), no_std)]
12+
#![forbid(absolute_paths_not_starting_with_crate)]
13+
#![forbid(elided_lifetimes_in_paths)]
14+
#![forbid(unsafe_op_in_unsafe_fn)]
15+
16+
use arch::Page4K;
17+
18+
mod x86_64;
19+
20+
/// Returns a static reference to the global zero page.
21+
pub fn zero_page() -> &'static Page4K {
22+
const ZERO_PAGE: Page4K = Page4K::new();
23+
&ZERO_PAGE
24+
}
25+
26+
/// Initialize the system.
27+
#[no_mangle]
28+
pub extern "C" fn init(allocator: &dyn FnMut() -> Result<arch::Page4K, ()>) {
29+
x86_64::init();
30+
}
31+
32+
hypatia::runtime!();

node/src/x86_64/gdt.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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::{gdt, Page, VPageAddr, V4KA};
9+
use core::sync::atomic::{AtomicBool, Ordering};
10+
11+
#[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(unsafe { (&GDT as *const gdt::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+
unsafe {
30+
GDT.init(task_state);
31+
arch::gdt::load(&mut GDT);
32+
}
33+
}
34+
}

node/src/x86_64/idt.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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::idt;
9+
use core::sync::atomic::{AtomicBool, Ordering};
10+
11+
static mut IDT: idt::IDT = idt::IDT::empty();
12+
static INITED: AtomicBool = AtomicBool::new(false);
13+
14+
pub(crate) fn init() {
15+
if !INITED.swap(true, Ordering::AcqRel) {
16+
unsafe {
17+
IDT.init(arch::trap::stubs());
18+
}
19+
}
20+
}

node/src/x86_64/mod.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+
pub(crate) mod gdt;
9+
pub(crate) mod idt;
10+
mod xferv;
11+
12+
pub(crate) fn init() {
13+
idt::init();
14+
gdt::map();
15+
}

node/src/x86_64/xferv.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+
use core::arch::asm;
9+
10+
#[export_name = "xferv"]
11+
#[link_section = ".xferv"]
12+
#[naked]
13+
pub unsafe extern "C" fn xferv() {
14+
unsafe {
15+
asm!(r#"
16+
.balign 8; jmp {hi};
17+
.balign 8; jmp {bye};
18+
"#,
19+
hi = sym hi,
20+
bye = sym bye,
21+
options(att_syntax, noreturn));
22+
}
23+
}
24+
25+
pub extern "C" fn hi() {
26+
uart::panic_println!("Hi!");
27+
}
28+
29+
pub extern "C" fn bye() {
30+
uart::panic_println!("Bye!");
31+
}

0 commit comments

Comments
 (0)