Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"hypatia",
"memory",
"monitor",
"node",
"scheduler",
"supervisor",
"system",
Expand Down
1 change: 1 addition & 0 deletions global/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ edition = "2024"
[dependencies]
arch = { package = "x86_64", path = "../x86_64" }
hypatia = { path = "../hypatia" }
uart = { path = "../uart" }
10 changes: 9 additions & 1 deletion global/src/link.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Hypatia Authors
* Copyright 2023 The Hypatia Authors
* All rights reserved
*
* Use of this source code is governed by an MIT-style
Expand All @@ -9,9 +9,17 @@

ENTRY(init)

EXTERN(xferv);

SECTIONS {
. = 0xFFFFFC0000000000;

.xferv . :
{
KEEP(*(.xferv*))
}
. = ALIGN(4096);

.text . :
{
*(.text*)
Expand Down
12 changes: 3 additions & 9 deletions global/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Hypatia Authors
// Copyright 2023 The Hypatia Authors
// All rights reserved
//
// Use of this source code is governed by an MIT-style
Expand All @@ -11,18 +11,12 @@
#![forbid(elided_lifetimes_in_paths)]
#![forbid(unsafe_op_in_unsafe_fn)]

use arch::Page4K;

/// Returns a static reference to the global zero page.
pub fn zero_page() -> &'static Page4K {
const ZERO_PAGE: Page4K = Page4K::new();
&ZERO_PAGE
}
mod x86_64;

/// Initialize the system.
#[unsafe(no_mangle)]
pub extern "C" fn init() {
zero_page();
uart::panic_println!("Hello from global");
}

hypatia::runtime!();
8 changes: 8 additions & 0 deletions global/src/x86_64/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2023 The Hypatia Authors
// All rights reserved
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

mod xferv;
Empty file added global/src/x86_64/swtch.rs
Empty file.
29 changes: 29 additions & 0 deletions global/src/x86_64/xferv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2023 The Hypatia Authors
// All rights reserved
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

use core::arch::naked_asm;

#[unsafe(export_name = "xferv")]
#[unsafe(link_section = ".xferv")]
#[unsafe(naked)]
unsafe extern "C" fn xferv() {
naked_asm!(r#"
.balign 8; jmp {hi};
.balign 8; jmp {bye};
"#,
hi = sym hi,
bye = sym bye,
options(att_syntax));
}

extern "C" fn hi() {
uart::panic_println!("Hi!");
}

extern "C" fn bye() {
uart::panic_println!("Bye!");
}
18 changes: 18 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2021 The Hypatia Authors
# All rights reserved
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

[package]
name = "node"
version = "0.1.0"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
arch = { package = "x86_64", path = "../x86_64" }
hypatia = { path = "../hypatia" }
uart = { path = "../uart" }
15 changes: 15 additions & 0 deletions node/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2023 The Hypatia Authors
// All rights reserved
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

use std::env;

fn main() {
let target = env::var("TARGET").unwrap();
if target.as_str() == "x86_64-unknown-none-elf" {
println!("cargo:rustc-link-arg-bins=-Tnode/src/link.ld")
}
}
56 changes: 56 additions & 0 deletions node/src/link.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2023 The Hypatia Authors
* All rights reserved
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/

ENTRY(init)

SECTIONS {
. = 0xFFFFFB4000000000;

.xferv . :
{
KEEP(*(.xferv*))
}
. = ALIGN(4096);

.text . :
{
*(.text*)
}
. = ALIGN(4096);
PROVIDE(etext = .);

.rodata . :
{
*(.rodata*)
}
. = ALIGN(4096);
PROVIDE(erodata = .);

.got . :
{
*(.got*)
}
. = ALIGN(4096);

.data . :
{
*(.data*)
}
. = ALIGN(4096);
PROVIDE(edata = .);

.bss . :
{
*(.bss*)
*(COMMON)
}
. = ALIGN(4096);

PROVIDE(end = .);
}
31 changes: 31 additions & 0 deletions node/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2023 The Hypatia Authors
// All rights reserved
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

#![feature(sync_unsafe_cell)]
#![cfg_attr(not(test), no_main)]
#![cfg_attr(not(test), no_std)]
#![forbid(absolute_paths_not_starting_with_crate)]
#![forbid(elided_lifetimes_in_paths)]
#![forbid(unsafe_op_in_unsafe_fn)]

use arch::Page4K;

mod x86_64;

/// Returns a static reference to the global zero page.
pub fn zero_page() -> &'static Page4K {
const ZERO_PAGE: Page4K = Page4K::new();
&ZERO_PAGE
}

/// Initialize the system.
#[unsafe(no_mangle)]
pub extern "C" fn init() {
x86_64::init();
}

hypatia::runtime!();
36 changes: 36 additions & 0 deletions node/src/x86_64/gdt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2023 The Hypatia Authors
// All rights reserved
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

use arch::{Page, V4KA, VPageAddr, gdt};
use core::sync::atomic::{AtomicBool, Ordering};

#[unsafe(link_section = ".gdt")]
static mut GDT: gdt::GDT = gdt::GDT::empty();
static INITED: AtomicBool = AtomicBool::new(false);

pub(crate) fn map() {
let zeros = crate::zero_page();
let va = V4KA::new((&raw const GDT).addr());
const R: bool = true;
const NW: bool = false;
const NX: bool = false;
for k in 1..16 {
let zva = V4KA::new(va.addr() + k * 4096);
arch::vm::map_leaf(zeros.frame(), zva, R, NW, NX).expect("mapped zero page in GDT");
}
}

pub(crate) fn init(task_state: &arch::tss::TSS) {
if !INITED.swap(true, Ordering::AcqRel) {
let gdtp = &raw mut GDT;
let gdt = unsafe { &mut *gdtp };
gdt.init(task_state);
unsafe {
arch::gdt::load(gdt);
}
}
}
23 changes: 23 additions & 0 deletions node/src/x86_64/idt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2023 The Hypatia Authors
// All rights reserved
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

use core::cell::SyncUnsafeCell;
use core::sync::atomic::{AtomicBool, Ordering};

static IDT: SyncUnsafeCell<arch::idt::IDT> = SyncUnsafeCell::new(arch::idt::IDT::empty());
static INITED: AtomicBool = AtomicBool::new(false);

pub(crate) fn init() {
if INITED.swap(true, Ordering::AcqRel) {
panic!("double init node IDT");
}
let idt = unsafe { &mut *IDT.get() };
idt.init(arch::trap::stubs());
unsafe {
arch::idt::load(idt);
}
}
18 changes: 18 additions & 0 deletions node/src/x86_64/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2023 The Hypatia Authors
// All rights reserved
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

pub(crate) mod gdt;
pub(crate) mod idt;
pub(crate) mod tss;
mod xferv;

pub(crate) fn init() {
idt::init();
gdt::map();
let tss = tss::init();
gdt::init(tss);
}
14 changes: 14 additions & 0 deletions node/src/x86_64/tss.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2023 The Hypatia Authors
// All rights reserved
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

use core::cell::SyncUnsafeCell;

static TSS: SyncUnsafeCell<arch::tss::TSS> = SyncUnsafeCell::new(arch::tss::TSS::empty());

pub(crate) fn init() -> &'static arch::tss::TSS {
unsafe { &*TSS.get() }
}
29 changes: 29 additions & 0 deletions node/src/x86_64/xferv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2023 The Hypatia Authors
// All rights reserved
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

use core::arch::naked_asm;

#[unsafe(export_name = "xferv")]
#[unsafe(link_section = ".xferv")]
#[unsafe(naked)]
pub unsafe extern "C" fn xferv() {
naked_asm!(r#"
.balign 8; jmp {hi};
.balign 8; jmp {bye};
"#,
hi = sym hi,
bye = sym bye,
options(att_syntax));
}

pub extern "C" fn hi() {
uart::panic_println!("Hi!");
}

pub extern "C" fn bye() {
uart::panic_println!("Bye!");
}
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
edition = "2021"
edition = "2024"
use_small_heuristics = "Max"
newline_style = "Unix"
Loading