diff --git a/.cargo/config.toml b/.cargo/config.toml index c51c6dbc..af47a1c8 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -7,7 +7,7 @@ limine-x86_64 = "build --target oro-arch-x86_64/x86_64-unknown-oro.json --featur limine-aarch64 = "build --target oro-arch-aarch64/aarch64-unknown-oro.json --features oro-debug/pl011 --bin oro-limine-aarch64 -Zunstable-options -Zbuild-std=core,compiler_builtins,alloc -Zbuild-std-features=compiler-builtins-mem" -oro-clippy = "clippy --target ./oro-arch-x86_64/x86_64-unknown-oro.json --target oro-arch-aarch64/aarch64-unknown-oro.json -p oro-boot-protocol -p oro-mem -p oro-debug -p oro-elf -p oro-kernel -p oro-macro -p oro-macro-proc -p oro-sync -p oro-id -p oro-sysabi -p oro -Zunstable-options -Zbuild-std=core,compiler_builtins,alloc -Zbuild-std-features=compiler-builtins-mem" +oro-clippy = "clippy --target ./oro-arch-x86_64/x86_64-unknown-oro.json --target oro-arch-aarch64/aarch64-unknown-oro.json -p oro-boot-protocol -p oro-mem -p oro-debug -p oro-elf -p oro-kernel -p oro-macro -p oro-macro-proc -p oro-sync -p oro-id -p oro-sysabi -p oro -p oro-std -Zunstable-options -Zbuild-std=core,compiler_builtins,alloc -Zbuild-std-features=compiler-builtins-mem" oro-clippy-x86_64 = "clippy --target ./oro-arch-x86_64/x86_64-unknown-oro.json --features oro-debug/uart16550 --bin oro-kernel-x86_64 --bin oro-limine-x86_64 -Zunstable-options -Zbuild-std=core,compiler_builtins,alloc -Zbuild-std-features=compiler-builtins-mem" @@ -21,4 +21,4 @@ oro-ra-x86_64 = "check --quiet --message-format=json --keep-going --target ./oro oro-ra-aarch64 = "check --quiet --message-format=json --keep-going --target ./oro-arch-aarch64/aarch64-unknown-oro.json --bin oro-kernel-aarch64 --bin oro-limine-aarch64 -Zunstable-options -Zbuild-std=core,compiler_builtins,alloc -Zbuild-std-features=compiler-builtins-mem" -oro-examples = "build --target=x86_64-unknown-none --target=aarch64-unknown-none -p exmod-noop -p exmod-spin" +oro-examples = "build --target=x86_64-unknown-none --target=aarch64-unknown-none -p example-noop -p example-spin -p example-std-noop" diff --git a/Cargo.lock b/Cargo.lock index 43e0a7bc..cab0f386 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,19 +105,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] -name = "exmod-noop" +name = "example-noop" version = "0.0.0" dependencies = [ "oro", ] [[package]] -name = "exmod-spin" +name = "example-spin" version = "0.0.0" dependencies = [ "oro", ] +[[package]] +name = "example-std-noop" +version = "0.0.0" +dependencies = [ + "oro", + "oro-std", +] + [[package]] name = "glob" version = "0.3.1" @@ -382,6 +390,13 @@ dependencies = [ "oro-sync", ] +[[package]] +name = "oro-std" +version = "0.0.0" +dependencies = [ + "oro", +] + [[package]] name = "oro-sync" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index e93375b0..dd44e322 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,11 +29,13 @@ members = [ "oro-id", "oro-sync", "oro-sysabi", + "oro-std", "oro", # Examples - "examples/noop", - "examples/spin", + "examples/no-std/noop", + "examples/no-std/spin", + "examples/std/noop", ] [workspace.dependencies] @@ -57,7 +59,6 @@ oro-dbgutil.path = "oro-dbgutil" oro-id.path = "oro-id" oro-sync.path = "oro-sync" oro-sysabi.path = "oro-sysabi" -oro.path = "oro" limine = "0.2.0" uart_16550 = "0.3.0" diff --git a/examples/noop/Cargo.toml b/examples/no-std/noop/Cargo.toml similarity index 79% rename from examples/noop/Cargo.toml rename to examples/no-std/noop/Cargo.toml index a0e384ff..7ca076a9 100644 --- a/examples/noop/Cargo.toml +++ b/examples/no-std/noop/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "exmod-noop" +name = "example-noop" description = "Example module that exits immediately." version = "0.0.0" publish = false @@ -8,10 +8,10 @@ edition = "2021" build = "build.rs" [dependencies.oro] -path = "../../oro" +path = "../../../oro" features = ["runtime"] [build-dependencies.oro] -path = "../../oro" +path = "../../../oro" features = ["build"] default-features = false diff --git a/examples/noop/build.rs b/examples/no-std/noop/build.rs similarity index 100% rename from examples/noop/build.rs rename to examples/no-std/noop/build.rs diff --git a/examples/noop/src/main.rs b/examples/no-std/noop/src/main.rs similarity index 100% rename from examples/noop/src/main.rs rename to examples/no-std/noop/src/main.rs diff --git a/examples/spin/Cargo.toml b/examples/no-std/spin/Cargo.toml similarity index 78% rename from examples/spin/Cargo.toml rename to examples/no-std/spin/Cargo.toml index 5fb5d0a4..f409a77f 100644 --- a/examples/spin/Cargo.toml +++ b/examples/no-std/spin/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "exmod-spin" +name = "example-spin" description = "Example module that spins endlessly" version = "0.0.0" publish = false @@ -8,10 +8,10 @@ edition = "2021" build = "build.rs" [dependencies.oro] -path = "../../oro" +path = "../../../oro" features = ["runtime"] [build-dependencies.oro] -path = "../../oro" +path = "../../../oro" features = ["build"] default-features = false diff --git a/examples/spin/build.rs b/examples/no-std/spin/build.rs similarity index 100% rename from examples/spin/build.rs rename to examples/no-std/spin/build.rs diff --git a/examples/spin/src/main.rs b/examples/no-std/spin/src/main.rs similarity index 100% rename from examples/spin/src/main.rs rename to examples/no-std/spin/src/main.rs diff --git a/examples/std/noop/Cargo.toml b/examples/std/noop/Cargo.toml new file mode 100644 index 00000000..20b41a68 --- /dev/null +++ b/examples/std/noop/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "example-std-noop" +description = "Example module that exits immediately." +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 diff --git a/examples/std/noop/build.rs b/examples/std/noop/build.rs new file mode 100644 index 00000000..c43c5af7 --- /dev/null +++ b/examples/std/noop/build.rs @@ -0,0 +1,3 @@ +fn main() { + ::oro::build(); +} diff --git a/examples/std/noop/src/main.rs b/examples/std/noop/src/main.rs new file mode 100644 index 00000000..a9bf4386 --- /dev/null +++ b/examples/std/noop/src/main.rs @@ -0,0 +1,6 @@ +#![no_main] + +#[no_mangle] +fn main() { + // Left intentionally blank +} diff --git a/oro-std/Cargo.toml b/oro-std/Cargo.toml new file mode 100644 index 00000000..2d7fef11 --- /dev/null +++ b/oro-std/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "oro-std" +version.workspace = true +description = "Interim Rust standard library shims for the Oro operating system" +publish = false +edition = "2021" +authors = [ + "Josh Junon (https//github.com/qix-)" +] +homepage = "https://oro.sh" +repository = "https://github.com/oro-os/kernel" +license = "MIT OR Apache-2.0" + +[lib] +doctest = false + +[lints] +workspace = true + +[features] +default = [] +oro = [] + +# NOTE(qix-): This crate MUST NOT have any workspace (only) dependencies +# NOTE(qix-): as it is published publicly. +[dependencies] +oro = { version = "0.0.0", path = "../oro" } diff --git a/oro-std/LICENSE.apache-2.0 b/oro-std/LICENSE.apache-2.0 new file mode 100644 index 00000000..1b5ec8b7 --- /dev/null +++ b/oro-std/LICENSE.apache-2.0 @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/oro-std/LICENSE.mit b/oro-std/LICENSE.mit new file mode 100644 index 00000000..d230fe79 --- /dev/null +++ b/oro-std/LICENSE.mit @@ -0,0 +1,19 @@ +Copyright 2024 Joshua Lee Junon + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the “Software”), +to deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH +THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/oro-std/README.md b/oro-std/README.md new file mode 100644 index 00000000..2d06630b --- /dev/null +++ b/oro-std/README.md @@ -0,0 +1,64 @@ +# Rust `std` interim implementation for Oro modules + +This crate aims to shim, **in part**, the Rust `std` crate for Oro modules. + +> [!WARNING] +> There are **many, many** types, constants, and methods missing from this crate. +> This is **not** intended to be a full replacement for the Rust `std` crate, and +> is **purely an interim solution** until the time when such functionality is added +> to the upstream `std` crate (if ever). +> +> **Missing functionality is not considered a bug.** However, _incorrect_ functionality +> or additional methods (not including extension traits in the more Oro-specific `oro` +> crate, if any) **are** considered bugs and should be reported as such. + +## Usage +For updated usage information, please refer to the [crate documentation](https://docs.rs/oro-std). + +Add the following to your `Cargo.toml`: + +```toml +[dependencies] +std = { git = "https://github.com/oro-os/kernel.git", package = "oro-std" } +``` + +**Note that the use of `std = { package = "oro-std" }` is _NOT_ a guarantee that normal `std`-based +Rust code will compile.** + +If you would also like to use the packaged `oro` crate, you can add it as a feature: + +```toml +[dependencies] +std = { version = "...", package = "oro-std", features = ["oro"] } +``` + +```rust +use std::os::oro; // requires the "oro" feature +``` + +> [!WARNING] +> The `std::os::oro` module is **highly unstable**; there is **no guarantee** +> that its API will remain the same indefinitely, and will almost definitely +> require recompilation of any code that uses it in the future. **Use at your own risk.** + +## Why not just patch `std`? +It'd require a change to the Rust compiler's target definitions themselves, +which is more work than providing a stripped down interim subset of `std` features. +The way the `oro` crate is able to build modules without much additional work for +module writers has limitations regarding build flags and target settings (namely +that a `--target path/to.json` cannot be passed), which would be required to _correctly_ +patch `std` as it contains a lot of `#[cfg(target_os = "...")]` directives. + +Instead, the goal of this crate is to provide a future-proof way to write Oro modules _now_ +with the intention of fully deprecating its use in the future. + +Further, not all Oro kernel functionality has been developed yet nor is set in stone, +so doing it this way allows parts of `std` to be introduced piecemeal as the project +progresses in its early stages. + +## License +This crate is Copyright © 2024 by Joshua Lee Junon and is released under either +the [MIT](LICENSE.mit) **or** the [Apache 2.0](LICENSE.apache-2.0) license, at the +user's discretion. + +Part of the [Oro Operating System](https://github.com/oro-os) project. diff --git a/oro-std/aarch64.ld b/oro-std/aarch64.ld new file mode 100644 index 00000000..e087427f --- /dev/null +++ b/oro-std/aarch64.ld @@ -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 { + . = 0x30000000000; + + .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.*) + } +} diff --git a/oro-std/src/lib.rs b/oro-std/src/lib.rs new file mode 100644 index 00000000..baa66389 --- /dev/null +++ b/oro-std/src/lib.rs @@ -0,0 +1,36 @@ +//! # Oro Interim `std` Library +//! +//! > **NOTE:** This crate is intended to be used as a temporary stand-in for the Rust standard library +//! > when targeting the Oro kernel. It is not intended to be a full replacement for the Rust standard +//! > library, and is definitely missing a _lot_ of functionality. +//! > +//! > Any functionality that *is* implemented should match the behavior of the Rust standard library +//! > exactly. Any deviations or _additional_ functionality not present in mainline `std` +//! > should be considered a bug and reported. +//! +//! ## Usage +//! Declare the `std` crate as a dependency in your `Cargo.toml` file, mapping it to `oro-std`: +//! +//! ```toml +//! [dependencies] +//! std = { git = "https://github.com/oro-os/kernel.git", package = "oro-std" } +//! ``` +//! +//! ## OS-Specific `std::os::oro` Module +//! By default, the `std::os::oro` module is **not** enabled. To enable it, you must include the +//! `oro` feature in your `Cargo.toml`: +//! +//! ```toml +//! [dependencies] +//! std = { git = "https://github.com/oro-os/kernel.git", package = "oro-std", features = ["oro"] } +//! ``` +//! +//! Note that `std::os::oro` is just a re-export of the `oro` crate. If you wish to write +//! less-fragile code for the future, you may choose to depend on `oro` directly. +#![no_std] + +#[expect(unused_imports)] +use ::oro; + +pub mod os; +pub mod prelude; diff --git a/oro-std/src/os.rs b/oro-std/src/os.rs new file mode 100644 index 00000000..ebe5a281 --- /dev/null +++ b/oro-std/src/os.rs @@ -0,0 +1,4 @@ +//! OS-specific funtionality. + +#[cfg(feature = "oro")] +pub use ::oro; diff --git a/oro-std/src/prelude.rs b/oro-std/src/prelude.rs new file mode 100644 index 00000000..75cc7e32 --- /dev/null +++ b/oro-std/src/prelude.rs @@ -0,0 +1,5 @@ +//! Prelude types and other functionality; intended to be included via `use oro_std::prelude::*`. +//! +//! Automatically included in the root module of every crate if using `std = { package = "oro-std" }`. + +pub use core::prelude::*;