-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oro+examples: add initial noop example, along with build infra
- Loading branch information
Showing
13 changed files
with
279 additions
and
2 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,9 @@ members = [ | |
"oro-sync", | ||
"oro-sysabi", | ||
"oro", | ||
|
||
# Examples | ||
"examples/noop", | ||
] | ||
|
||
[workspace.dependencies] | ||
|
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,17 @@ | ||
[package] | ||
name = "exmod-noop" | ||
description = "Example module that spins endlessly" | ||
version = "0.0.0" | ||
publish = false | ||
edition = "2021" | ||
|
||
build = "build.rs" | ||
|
||
[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,12 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
#[allow(unused_imports)] | ||
use oro; | ||
|
||
#[no_mangle] | ||
fn main() { | ||
loop { | ||
::core::hint::spin_loop(); | ||
} | ||
} |
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,42 @@ | ||
OUTPUT_FORMAT(elf64-aarch64) | ||
OUTPUT_ARCH(aarch64) | ||
|
||
ENTRY(_oro_start) | ||
|
||
PHDRS { | ||
text PT_LOAD FLAGS((1 << 0) | (1 << 2)); /* rx */ | ||
rodata PT_LOAD FLAGS((1 << 2) ); /* r */ | ||
data PT_LOAD FLAGS((1 << 1) | (1 << 2)); /* rw */ | ||
} | ||
|
||
SECTIONS { | ||
. = 0x3000000000; | ||
|
||
.text : { | ||
*(.text .text.*) | ||
} :text | ||
|
||
. = ALIGN(4096); | ||
|
||
.rodata : { | ||
*(.rodata .rodata.*) | ||
} :rodata | ||
|
||
. = ALIGN(4096); | ||
|
||
.data : { | ||
*(.data .data.*) | ||
} :data | ||
|
||
. = ALIGN(4096); | ||
|
||
.bss : { | ||
*(COMMON) | ||
*(.bss .bss.*) /* MUST be last allocated to :data */ | ||
} :data | ||
|
||
/DISCARD/ : { | ||
*(.eh_frame) | ||
*(.note .note.*) | ||
} | ||
} |
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,56 @@ | ||
//! Houses the build configurator for Oro modules. | ||
//! | ||
//! # Usage | ||
//! In the module crate's `build.rs` script, call the `build` function to configure the linker to | ||
//! generate a valid Oro module that can be loaded by the Oro kernel. | ||
//! | ||
//! ```no_run | ||
//! fn main() { | ||
//! ::oro::build(); | ||
//! } | ||
//! ``` | ||
use std::path::PathBuf; | ||
|
||
/// To be called by the module crate's `build.rs` script. | ||
/// | ||
/// This function configures the linker to generate a valid | ||
/// Oro module that can be loaded by the Oro kernel. | ||
pub fn build() { | ||
let target = std::env::var("TARGET").unwrap(); | ||
|
||
match target.as_str() { | ||
"aarch64-unknown-none" => { | ||
let linker_script = PathBuf::from(file!()) | ||
.parent() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.join("aarch64.ld"); | ||
|
||
println!("cargo:rustc-link-arg=-static"); | ||
println!("cargo:rustc-link-arg=--relax"); | ||
println!("cargo:rustc-link-arg=-T"); | ||
println!("cargo:rustc-link-arg={}", linker_script.display()); | ||
} | ||
"x86_64-unknown-none" => { | ||
let linker_script = PathBuf::from(file!()) | ||
.parent() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.join("x86_64.ld"); | ||
|
||
println!("cargo:rustc-link-arg=-static"); | ||
println!("cargo:rustc-link-arg=--relax"); | ||
println!("cargo:rustc-link-arg=-T"); | ||
println!("cargo:rustc-link-arg={}", linker_script.display()); | ||
} | ||
_ => { | ||
panic!( | ||
"unsupported target when building Oro module: {target}; run with \ | ||
`--target=<arch>-unknown-none` instead" | ||
); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,44 @@ | ||
//! # Oro Module High Level API and Build Tooling | ||
#![no_std] | ||
//! | ||
//! # Usage | ||
//! Declare the `oro` crate as a dependency in your `Cargo.toml` file. | ||
//! You must also specify that you want Cargo to use a `build.rs` script. | ||
//! | ||
//! ```toml | ||
//! [package] | ||
//! build = "build.rs" | ||
//! | ||
//! [dependencies] | ||
//! oro = { version = "<version>", features = ["runtime"] } | ||
//! | ||
//! [build-dependencies] | ||
//! oro = { version = "<version>", features = ["build"] } | ||
//! ``` | ||
//! | ||
//! The `oro` crate *must* be `use`d by the module, even if no APIs are | ||
//! called, in order to properly link the panic handler, etc. | ||
//! | ||
//! ```no_run | ||
//! #[allow(unused_imports)] | ||
//! use oro; | ||
//! ``` | ||
//! | ||
//! Finally, in your `build.rs`, call the `build` function to configure the linker to | ||
//! generate a valid Oro module that can be loaded by the Oro kernel. | ||
//! | ||
//! ```no_run | ||
//! fn main() { | ||
//! ::oro::build(); | ||
//! } | ||
//! ``` | ||
#![cfg_attr(not(feature = "build"), no_std)] | ||
|
||
#[cfg(feature = "build")] | ||
mod build; | ||
#[cfg(feature = "build")] | ||
pub use build::*; | ||
|
||
#[cfg(not(feature = "build"))] | ||
mod runtime; | ||
#[cfg(not(feature = "build"))] | ||
pub use runtime::*; |
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,28 @@ | ||
//! High-level runtime support for Oro modules. | ||
#[cfg(feature = "panic_handler")] | ||
#[panic_handler] | ||
#[doc(hidden)] | ||
fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
// TODO(qix-): Implement panic handler | ||
loop { | ||
core::hint::spin_loop(); | ||
} | ||
} | ||
|
||
extern "C" { | ||
fn main(); | ||
} | ||
|
||
#[doc(hidden)] | ||
#[no_mangle] | ||
pub extern "C" fn _oro_start() -> ! { | ||
unsafe { | ||
main(); | ||
} | ||
|
||
// TODO(qix-): Implement exit routine | ||
loop { | ||
core::hint::spin_loop(); | ||
} | ||
} |
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,42 @@ | ||
OUTPUT_FORMAT(elf64-x86-64) | ||
OUTPUT_ARCH(i386:x86-64) | ||
|
||
ENTRY(_oro_start) | ||
|
||
PHDRS { | ||
text PT_LOAD FLAGS((1 << 0) | (1 << 2)); /* rx */ | ||
rodata PT_LOAD FLAGS((1 << 2) ); /* r */ | ||
data PT_LOAD FLAGS((1 << 1) | (1 << 2)); /* rw */ | ||
} | ||
|
||
SECTIONS { | ||
. = 0x3000000000; | ||
|
||
.text : { | ||
*(.text .text.*) | ||
} :text | ||
|
||
. = ALIGN(4096); | ||
|
||
.rodata : { | ||
*(.rodata .rodata.*) | ||
} :rodata | ||
|
||
. = ALIGN(4096); | ||
|
||
.data : { | ||
*(.data .data.*) | ||
} :data | ||
|
||
. = ALIGN(4096); | ||
|
||
.bss : { | ||
*(COMMON) | ||
*(.bss .bss.*) /* MUST be last allocated to :data */ | ||
} :data | ||
|
||
/DISCARD/ : { | ||
*(.eh_frame) | ||
*(.note .note.*) | ||
} | ||
} |