-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oro+oro-std+sysabi+examples: add initial ID system boilerplate
- Loading branch information
Showing
12 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "example-std-spin" | ||
description = "Example module that yields its time slice forever." | ||
version = "0.0.0" | ||
publish = false | ||
edition = "2021" | ||
|
||
build = "build.rs" | ||
|
||
[dependencies] | ||
std = { version = "0.0.0", package = "oro-std", path = "../../../oro-std" } | ||
|
||
[dependencies.oro] | ||
path = "../../../oro" | ||
features = ["runtime"] | ||
|
||
[build-dependencies.oro] | ||
path = "../../../oro" | ||
features = ["build"] | ||
default-features = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
::oro::build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![no_main] | ||
|
||
#[no_mangle] | ||
fn main() { | ||
loop { | ||
std::thread::yield_now(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#![expect(unused_imports)] | ||
use ::oro::{id::kernel::iface::THREAD_V0, key, uses}; | ||
|
||
use crate::thread::Thread; | ||
|
||
/// Gets a handle to the thread that invokes it. | ||
/// | ||
/// # Oro-specific | ||
/// This function **panics** in the rare case the thread handle cannot be retrieved. | ||
/// This is a temporary measure until the kernel implements TLS. | ||
#[must_use] | ||
pub fn current() -> Thread { | ||
// NOTE(qix-): The real `std` stores a TLS handle to the current thread, | ||
// NOTE(qix-): which is totally valid but the kernel hasn't implemented | ||
// NOTE(qix-): TLS quite yet. So we do it (slowly) here each time. | ||
uses!(THREAD_V0, key!("id")); | ||
} | ||
|
||
/// Cooperatively gives up a timeslice to the OS scheduler. | ||
/// | ||
/// This calls the underlying OS scheduler's yield primitive, signaling | ||
/// that the calling thread is willing to give up its remaining timeslice | ||
/// so that the OS may schedule other threads on the CPU. | ||
/// | ||
/// A drawback of yielding in a loop is that if the OS does not have any | ||
/// other ready threads to run on the current CPU, the thread will effectively | ||
/// busy-wait, which wastes CPU time and energy. | ||
/// | ||
/// # Oro-specific | ||
/// This function **panics** in the rare case the interface is unavailable. | ||
pub fn yield_now() { | ||
// NOTE(qix-): The real `std` stores a TLS handle to the current thread, | ||
// NOTE(qix-): which is totally valid but the kernel hasn't implemented | ||
// NOTE(qix-): TLS quite yet. So we do it (slowly) here each time. | ||
uses!(THREAD_V0, key!("id")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! Oro module metadata and ABI constants. | ||
/// ID masks for kernel interfaces. | ||
pub mod mask { | ||
/// `(id & KERNEL_ID) == 0` indicates a kernel ID. | ||
/// | ||
/// Any other ID is a non-standard, user-defined ID. | ||
pub const KERNEL_ID: u64 = 0xFFFF_FFFF_0000_0000; | ||
|
||
/// `(id & KERNEL_ID_TYPE)` extracts the kernel ID type. | ||
/// | ||
/// Note that this _does_ include the high 32-bits | ||
/// so that any erroneously operated upon user-defined | ||
/// ID will not somehow pass the check. | ||
pub const KERNEL_ID_TYPE: u64 = 0xFFFF_FFFF_FF00_0000; | ||
|
||
/// `(iface & KERNEL_ID_TYPE) == KERNEL_ID_TYPE_PRIMITIVE` indicates a primitive type. | ||
pub const KERNEL_ID_TYPE_PRIMITIVE: u64 = 0x0100_0000; | ||
|
||
/// `(iface & KERNEL_ID_TYPE) == KERNEL_ID_TYPE_IFACE` indicates a kernel interface. | ||
pub const KERNEL_ID_TYPE_IFACE: u64 = 0x0200_0000; | ||
|
||
/// `(iface & KERNEL_ID_TYPE) == KERNEL_ID_TYPE_META` indicates a module metadata structure. | ||
pub const KERNEL_ID_TYPE_META: u64 = 0x0300_0000; | ||
} | ||
|
||
/// Kernel interface IDs. | ||
pub mod iface { | ||
use crate::id::mask::KERNEL_ID_TYPE_IFACE; | ||
|
||
/// The ID of the kernel threading interface (version 0). | ||
pub const THREAD_V0: u64 = KERNEL_ID_TYPE_IFACE | 0x00_001; | ||
} | ||
|
||
/// Kernel primitive type IDs. | ||
pub mod primitive { | ||
use crate::id::mask::KERNEL_ID_TYPE_PRIMITIVE; | ||
|
||
/// The ID of the kernel `usize` primitive type. | ||
pub const U64: u64 = KERNEL_ID_TYPE_PRIMITIVE | 0x00_001; | ||
} | ||
|
||
/// Kernel metadata IDs. | ||
pub mod meta { | ||
use crate::id::mask::KERNEL_ID_TYPE_META; | ||
|
||
/// ID indicating that the following metadata indicates an interface/key usage. | ||
pub const USES: u64 = KERNEL_ID_TYPE_META | 0x00_001; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//! Macros for working with the system ABI. | ||
/// Auxiliary types used by macros exported by this crate. | ||
/// | ||
/// **Using this module directly is highly discouraged. It is not stable.** | ||
pub mod private {} | ||
|
||
/// Declares that an `(interface_id, key)` is to be used | ||
/// by the current function. | ||
#[macro_export] | ||
macro_rules! uses { | ||
($iface:expr, $key:expr) => { | ||
todo!(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters