Add the rust std as a custom sysroot

This commit is contained in:
2026-03-17 20:13:39 +01:00
parent 56a00d0403
commit f97c4b233a
37 changed files with 802 additions and 2285 deletions

View File

@@ -3,10 +3,9 @@ target = "riscv64.json"
[unstable]
json-target-spec = true
build-std = ["core", "compiler_builtins", "alloc"]
build-std-features = ["compiler-builtins-mem"]
[target.riscv64]
rustflags = [
"-C", "link-arg=-Tilm.ld",
"--sysroot", "sysroot"
]

2
.gitignore vendored
View File

@@ -7,3 +7,5 @@
disk.img
**/*.mem
mnt
sysroot/lib/rustlib/riscv64

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "library/backtrace"]
path = library/backtrace
url = https://github.com/rust-lang/backtrace-rs.git

View File

@@ -1,6 +1,7 @@
[workspace]
resolver = "3"
members = ["crates/bytes-struct","crates/io","crates/std", "crates/shared", "user/*"]
members = [ "user/*"]
exclude = ["library"]
[package]
name = "kernel-rust"

View File

@@ -1,4 +1,5 @@
#![feature(iterator_try_collect, iter_order_by)]
#![allow(unused_features)]
#![cfg_attr(any(not(feature = "std"), target_arch = "riscv64"), no_std)]
use core::cell::RefCell;

View File

@@ -7,6 +7,6 @@ edition = "2024"
proc-macro = true
[dependencies]
image = "0.25"
image = { version = "0.25", default-features = false, features = ["png"] }
syn = { version = "2", features = ["full"] }
zyn = "0.5"

View File

@@ -1,12 +0,0 @@
[package]
name = "os-std-macros"
version = "0.1.0"
edition = "2024"
[lib]
proc-macro = true
[dependencies]
proc-macro2 = "1"
quote = "1"
syn = { version = "2", features = ["full"] }

View File

@@ -1 +0,0 @@

View File

@@ -1,9 +0,0 @@
[package]
name = "std"
version = "0.1.0"
edition = "2024"
[dependencies]
os-std-macros = { path = "../os-std-macros" }
shared = { path = "../shared", features = ["user"] }
io = { path = "../io", features = ["alloc"] }

View File

@@ -1,7 +0,0 @@
//! [`CStr`], [`CString`], and related types.
pub use alloc::ffi::c_str::FromVecWithNulError;
pub use alloc::ffi::c_str::IntoStringError;
pub use alloc::ffi::c_str::{CString, NulError};
pub use core::ffi::c_str::CStr;
pub use core::ffi::c_str::FromBytesUntilNulError;
pub use core::ffi::c_str::FromBytesWithNulError;

View File

@@ -1,184 +0,0 @@
//! Utilities related to FFI bindings.
//!
//! This module provides utilities to handle data across non-Rust
//! interfaces, like other programming languages and the underlying
//! operating system. It is mainly of use for FFI (Foreign Function
//! Interface) bindings and code that needs to exchange C-like strings
//! with other languages.
//!
//! # Overview
//!
//! Rust represents owned strings with the [`String`] type, and
//! borrowed slices of strings with the [`str`] primitive. Both are
//! always in UTF-8 encoding, and may contain nul bytes in the middle,
//! i.e., if you look at the bytes that make up the string, there may
//! be a `\0` among them. Both `String` and `str` store their length
//! explicitly; there are no nul terminators at the end of strings
//! like in C.
//!
//! C strings are different from Rust strings:
//!
//! * **Encodings** - Rust strings are UTF-8, but C strings may use
//! other encodings. If you are using a string from C, you should
//! check its encoding explicitly, rather than just assuming that it
//! is UTF-8 like you can do in Rust.
//!
//! * **Character size** - C strings may use `char` or `wchar_t`-sized
//! characters; please **note** that C's `char` is different from Rust's.
//! The C standard leaves the actual sizes of those types open to
//! interpretation, but defines different APIs for strings made up of
//! each character type. Rust strings are always UTF-8, so different
//! Unicode characters will be encoded in a variable number of bytes
//! each. The Rust type [`char`] represents a '[Unicode scalar
//! value]', which is similar to, but not the same as, a '[Unicode
//! code point]'.
//!
//! * **Nul terminators and implicit string lengths** - Often, C
//! strings are nul-terminated, i.e., they have a `\0` character at the
//! end. The length of a string buffer is not stored, but has to be
//! calculated; to compute the length of a string, C code must
//! manually call a function like `strlen()` for `char`-based strings,
//! or `wcslen()` for `wchar_t`-based ones. Those functions return
//! the number of characters in the string excluding the nul
//! terminator, so the buffer length is really `len+1` characters.
//! Rust strings don't have a nul terminator; their length is always
//! stored and does not need to be calculated. While in Rust
//! accessing a string's length is an *O*(1) operation (because the
//! length is stored); in C it is an *O*(*n*) operation because the
//! length needs to be computed by scanning the string for the nul
//! terminator.
//!
//! * **Internal nul characters** - When C strings have a nul
//! terminator character, this usually means that they cannot have nul
//! characters in the middle — a nul character would essentially
//! truncate the string. Rust strings *can* have nul characters in
//! the middle, because nul does not have to mark the end of the
//! string in Rust.
//!
//! # Representations of non-Rust strings
//!
//! [`CString`] and [`CStr`] are useful when you need to transfer
//! UTF-8 strings to and from languages with a C ABI, like Python.
//!
//! * **From Rust to C:** [`CString`] represents an owned, C-friendly
//! string: it is nul-terminated, and has no internal nul characters.
//! Rust code can create a [`CString`] out of a normal string (provided
//! that the string doesn't have nul characters in the middle), and
//! then use a variety of methods to obtain a raw <code>\*mut [u8]</code> that can
//! then be passed as an argument to functions which use the C
//! conventions for strings.
//!
//! * **From C to Rust:** [`CStr`] represents a borrowed C string; it
//! is what you would use to wrap a raw <code>\*const [u8]</code> that you got from
//! a C function. A [`CStr`] is guaranteed to be a nul-terminated array
//! of bytes. Once you have a [`CStr`], you can convert it to a Rust
//! <code>&[str]</code> if it's valid UTF-8, or lossily convert it by adding
//! replacement characters.
//!
//! [`OsString`] and [`OsStr`] are useful when you need to transfer
//! strings to and from the operating system itself, or when capturing
//! the output of external commands. Conversions between [`OsString`],
//! [`OsStr`] and Rust strings work similarly to those for [`CString`]
//! and [`CStr`].
//!
//! * [`OsString`] losslessly represents an owned platform string. However, this
//! representation is not necessarily in a form native to the platform.
//! In the Rust standard library, various APIs that transfer strings to/from the operating
//! system use [`OsString`] instead of plain strings. For example,
//! [`env::var_os()`] is used to query environment variables; it
//! returns an <code>[Option]<[OsString]></code>. If the environment variable
//! exists you will get a <code>[Some]\(os_string)</code>, which you can
//! *then* try to convert to a Rust string. This yields a [`Result`], so that
//! your code can detect errors in case the environment variable did
//! not in fact contain valid Unicode data.
//!
//! * [`OsStr`] losslessly represents a borrowed reference to a platform string.
//! However, this representation is not necessarily in a form native to the platform.
//! It can be converted into a UTF-8 Rust string slice in a similar way to
//! [`OsString`].
//!
//! # Conversions
//!
//! ## On Unix
//!
//! On Unix, [`OsStr`] implements the
//! <code>std::os::unix::ffi::[OsStrExt][unix.OsStrExt]</code> trait, which
//! augments it with two methods, [`from_bytes`] and [`as_bytes`].
//! These do inexpensive conversions from and to byte slices.
//!
//! Additionally, on Unix [`OsString`] implements the
//! <code>std::os::unix::ffi::[OsStringExt][unix.OsStringExt]</code> trait,
//! which provides [`from_vec`] and [`into_vec`] methods that consume
//! their arguments, and take or produce vectors of [`u8`].
//!
//! ## On Windows
//!
//! An [`OsStr`] can be losslessly converted to a native Windows string. And
//! a native Windows string can be losslessly converted to an [`OsString`].
//!
//! On Windows, [`OsStr`] implements the
//! <code>std::os::windows::ffi::[OsStrExt][windows.OsStrExt]</code> trait,
//! which provides an [`encode_wide`] method. This provides an
//! iterator that can be [`collect`]ed into a vector of [`u16`]. After a nul
//! characters is appended, this is the same as a native Windows string.
//!
//! Additionally, on Windows [`OsString`] implements the
//! <code>std::os::windows:ffi::[OsStringExt][windows.OsStringExt]</code>
//! trait, which provides a [`from_wide`] method to convert a native Windows
//! string (without the terminating nul character) to an [`OsString`].
//!
//! ## Other platforms
//!
//! Many other platforms provide their own extension traits in a
//! `std::os::*::ffi` module.
//!
//! ## On all platforms
//!
//! On all platforms, [`OsStr`] consists of a sequence of bytes that is encoded as a superset of
//! UTF-8; see [`OsString`] for more details on its encoding on different platforms.
//!
//! For limited, inexpensive conversions from and to bytes, see [`OsStr::as_encoded_bytes`] and
//! [`OsStr::from_encoded_bytes_unchecked`].
//!
//! For basic string processing, see [`OsStr::slice_encoded_bytes`].
//!
//! [Unicode scalar value]: https://www.unicode.org/glossary/#unicode_scalar_value
//! [Unicode code point]: https://www.unicode.org/glossary/#code_point
//! [`env::set_var()`]: crate::env::set_var "env::set_var"
//! [`env::var_os()`]: crate::env::var_os "env::var_os"
//! [unix.OsStringExt]: crate::os::unix::ffi::OsStringExt "os::unix::ffi::OsStringExt"
//! [`from_vec`]: crate::os::unix::ffi::OsStringExt::from_vec "os::unix::ffi::OsStringExt::from_vec"
//! [`into_vec`]: crate::os::unix::ffi::OsStringExt::into_vec "os::unix::ffi::OsStringExt::into_vec"
//! [unix.OsStrExt]: crate::os::unix::ffi::OsStrExt "os::unix::ffi::OsStrExt"
//! [`from_bytes`]: crate::os::unix::ffi::OsStrExt::from_bytes "os::unix::ffi::OsStrExt::from_bytes"
//! [`as_bytes`]: crate::os::unix::ffi::OsStrExt::as_bytes "os::unix::ffi::OsStrExt::as_bytes"
//! [`OsStrExt`]: crate::os::unix::ffi::OsStrExt "os::unix::ffi::OsStrExt"
//! [windows.OsStrExt]: crate::os::windows::ffi::OsStrExt "os::windows::ffi::OsStrExt"
//! [`encode_wide`]: crate::os::windows::ffi::OsStrExt::encode_wide "os::windows::ffi::OsStrExt::encode_wide"
//! [`collect`]: crate::iter::Iterator::collect "iter::Iterator::collect"
//! [windows.OsStringExt]: crate::os::windows::ffi::OsStringExt "os::windows::ffi::OsStringExt"
//! [`from_wide`]: crate::os::windows::ffi::OsStringExt::from_wide "os::windows::ffi::OsStringExt::from_wide"
pub mod c_str;
pub use core::ffi::c_void;
pub use core::ffi::{VaArgSafe, VaList};
pub use core::ffi::{
c_char, c_double, c_float, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint,
c_ulong, c_ulonglong, c_ushort,
};
pub use core::ffi::{c_ptrdiff_t, c_size_t, c_ssize_t};
#[doc(inline)]
pub use self::c_str::FromBytesUntilNulError;
#[doc(inline)]
pub use self::c_str::FromBytesWithNulError;
#[doc(inline)]
pub use self::c_str::FromVecWithNulError;
#[doc(inline)]
pub use self::c_str::IntoStringError;
#[doc(inline)]
pub use self::c_str::NulError;
#[doc(inline)]
pub use self::c_str::{CStr, CString};
// #[doc(inline)]
// pub use self::os_str::{OsStr, OsString};
pub mod os_str;

File diff suppressed because it is too large Load Diff

View File

@@ -1,22 +0,0 @@
use crate::fs::File;
use io::IoBase;
pub use io::Read;
pub use io::Seek;
pub use io::SeekFrom;
pub use io::Write;
pub struct Stdin;
impl IoBase for Stdin {
type Error = ();
}
impl Read for Stdin {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
unsafe { File::from_raw_fd(0).read(buf) }
}
}
pub fn stdin() -> Stdin {
Stdin
}

View File

@@ -1,242 +0,0 @@
#![no_std]
#![allow(internal_features)]
//
// Language features:
// tidy-alphabetical-start
#![feature(alloc_error_handler)]
#![feature(allocator_internals)]
#![feature(allow_internal_unsafe)]
#![feature(allow_internal_unstable)]
#![feature(asm_experimental_arch)]
#![feature(autodiff)]
#![feature(cfg_sanitizer_cfi)]
#![feature(cfg_target_thread_local)]
#![feature(cfi_encoding)]
#![feature(const_default)]
#![feature(const_trait_impl)]
#![feature(core_float_math)]
#![feature(decl_macro)]
#![feature(deprecated_suggestion)]
#![feature(doc_cfg)]
#![feature(doc_masked)]
#![feature(doc_notable_trait)]
#![feature(dropck_eyepatch)]
#![feature(f16)]
#![feature(f128)]
#![feature(ffi_const)]
#![feature(formatting_options)]
#![feature(funnel_shifts)]
#![feature(if_let_guard)]
#![feature(intra_doc_pointers)]
#![feature(iter_advance_by)]
#![feature(iter_next_chunk)]
#![feature(lang_items)]
#![feature(link_cfg)]
#![feature(linkage)]
#![feature(macro_metavar_expr_concat)]
#![feature(maybe_uninit_fill)]
#![feature(min_specialization)]
#![feature(must_not_suspend)]
#![feature(needs_panic_runtime)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(optimize_attribute)]
#![feature(prelude_import)]
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
// #![feature(staged_api)]
#![feature(stmt_expr_attributes)]
#![feature(strict_provenance_lints)]
#![feature(thread_local)]
#![feature(try_blocks)]
#![feature(try_trait_v2)]
#![feature(type_alias_impl_trait)]
// tidy-alphabetical-end
//
// Library features (core):
// tidy-alphabetical-start
#![feature(bstr)]
#![feature(bstr_internals)]
#![feature(cast_maybe_uninit)]
#![feature(cfg_select)]
#![feature(char_internals)]
#![feature(clone_to_uninit)]
#![feature(const_convert)]
#![feature(core_intrinsics)]
#![feature(core_io_borrowed_buf)]
#![feature(drop_guard)]
#![feature(duration_constants)]
#![feature(error_generic_member_access)]
#![feature(error_iter)]
#![feature(exact_size_is_empty)]
#![feature(exclusive_wrapper)]
#![feature(extend_one)]
#![feature(float_algebraic)]
// #![feature(float_gamma)]
#![feature(float_minimum_maximum)]
#![feature(fmt_internals)]
#![feature(fn_ptr_trait)]
#![feature(generic_atomic)]
#![feature(hasher_prefixfree_extras)]
#![feature(hashmap_internals)]
#![feature(hint_must_use)]
#![feature(int_from_ascii)]
#![feature(ip)]
#![feature(maybe_uninit_array_assume_init)]
#![feature(panic_can_unwind)]
#![feature(panic_internals)]
#![feature(pin_coerce_unsized_trait)]
#![feature(pointer_is_aligned_to)]
#![feature(portable_simd)]
#![feature(ptr_as_uninit)]
#![feature(ptr_mask)]
#![feature(random)]
#![feature(slice_internals)]
#![feature(slice_ptr_get)]
#![feature(slice_range)]
#![feature(slice_split_once)]
#![feature(std_internals)]
#![feature(str_internals)]
#![feature(sync_unsafe_cell)]
#![feature(temporary_niche_types)]
#![feature(ub_checks)]
#![feature(used_with_arg)]
// tidy-alphabetical-end
//
// Library features (alloc):
// tidy-alphabetical-start
#![feature(alloc_layout_extra)]
#![feature(allocator_api)]
#![feature(clone_from_ref)]
#![feature(get_mut_unchecked)]
#![feature(map_try_insert)]
#![feature(slice_concat_trait)]
#![feature(thin_box)]
#![feature(try_reserve_kind)]
#![feature(try_with_capacity)]
#![feature(unique_rc_arc)]
#![feature(wtf8_internals)]
// tidy-alphabetical-end
//
// Library features (unwind):
// tidy-alphabetical-start
// #![feature(panic_unwind)]
// tidy-alphabetical-end
//
// Library features (std_detect):
// tidy-alphabetical-start
// #![feature(stdarch_internal)]
// tidy-alphabetical-end
//
// Only for re-exporting:
// tidy-alphabetical-start
#![feature(assert_matches)]
#![feature(async_iterator)]
#![feature(c_variadic)]
#![feature(cfg_accessible)]
#![feature(cfg_eval)]
#![feature(concat_bytes)]
#![feature(const_format_args)]
#![feature(custom_test_frameworks)]
#![feature(edition_panic)]
#![feature(format_args_nl)]
#![feature(log_syntax)]
#![feature(test)]
#![feature(trace_macros)]
// tidy-alphabetical-end
//
// Only used in tests/benchmarks:
//
// Only for const-ness:
// tidy-alphabetical-start
// #![feature(io_const_error)]
// tidy-alphabetical-end
//
#![feature(c_size_t, unsafe_binders)]
#![allow(clippy::doc_lazy_continuation, clippy::legacy_numeric_constants)]
#![allow(stable_features, incomplete_features)]
extern crate alloc;
pub use core::any;
pub use core::array;
pub use core::async_iter;
pub use core::cell;
pub use core::char;
pub use core::clone;
pub use core::cmp;
pub use core::convert;
pub use core::default;
pub use core::future;
pub use core::hint;
#[allow(deprecated, deprecated_in_future)]
pub use core::i8;
#[allow(deprecated, deprecated_in_future)]
pub use core::i16;
#[allow(deprecated, deprecated_in_future)]
pub use core::i32;
#[allow(deprecated, deprecated_in_future)]
pub use core::i64;
#[allow(deprecated, deprecated_in_future)]
pub use core::i128;
pub use core::intrinsics;
#[allow(deprecated, deprecated_in_future)]
pub use core::isize;
pub use core::iter;
pub use core::marker;
pub use core::mem;
pub use core::ops;
pub use core::option;
pub use core::pin;
pub use core::ptr;
pub use core::range;
pub use core::result;
#[allow(deprecated, deprecated_in_future)]
pub use core::u8;
#[allow(deprecated, deprecated_in_future)]
pub use core::u16;
#[allow(deprecated, deprecated_in_future)]
pub use core::u32;
#[allow(deprecated, deprecated_in_future)]
pub use core::u64;
#[allow(deprecated, deprecated_in_future)]
pub use core::u128;
pub use core::unsafe_binder;
#[allow(deprecated, deprecated_in_future)]
pub use core::usize;
pub use alloc::borrow;
pub use alloc::boxed;
pub use alloc::fmt;
pub use alloc::format;
pub use alloc::rc;
pub use alloc::slice;
pub use alloc::str;
pub use alloc::string;
pub use alloc::vec;
pub mod ffi;
pub mod io;
pub mod prelude;
pub mod process;
pub use shared::fs;
pub use shared::syscall;
#[macro_export]
macro_rules! print {
($($args:expr),*) => {
$crate::syscall::write_string_temp(&format!($($args),*))
};
}
#[macro_export]
macro_rules! println {
() => {
$crate::print!("");
// $crate::print!("\n\r");
};
($($args:expr),*) => {
$crate::print!($($args),*);
// $crate::println!();
};
}

View File

@@ -1,54 +0,0 @@
pub mod rust_2024 {
pub use crate::print;
pub use crate::println;
pub use alloc::borrow::ToOwned;
pub use alloc::format;
pub use alloc::string::String;
pub use alloc::vec;
extern crate alloc;
struct GlobalAllocator;
#[core::prelude::v1::global_allocator]
static GLOBAL_ALLOCATOR: GlobalAllocator = GlobalAllocator;
unsafe impl core::alloc::GlobalAlloc for GlobalAllocator {
unsafe fn alloc(&self, layout: core::alloc::Layout) -> *mut u8 {
crate::syscall::alloc(layout)
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: core::alloc::Layout) {
crate::syscall::dealloc(ptr, layout)
}
}
#[panic_handler]
fn panic(_panic_info: &core::panic::PanicInfo) -> ! {
// TODO print
loop {}
}
/// # Safety
/// `argc` and `argv` are passed by the kernel
#[unsafe(no_mangle)]
pub unsafe extern "C" fn _start(argc: isize, argv: *const *const u8) -> isize {
unsafe extern "Rust" {
fn main(argc: isize, argv: *const *const u8) -> isize;
}
unsafe { main(argc, argv) }
}
#[lang = "start"]
pub fn lang_start<T: crate::process::Termination + 'static>(
main: fn() -> T,
argc: isize,
argv: *const *const u8,
_sigpipe: u8,
) -> isize {
println!("{}", argc);
println!("{:?}", argv);
main().report().to_isize()
}
}

View File

@@ -1,29 +0,0 @@
pub struct ExitCode(isize);
impl ExitCode {
pub const SUCCESS: ExitCode = ExitCode(0);
pub fn to_isize(self) -> isize {
self.0
}
}
#[lang = "termination"]
pub trait Termination {
/// Is called to get the representation of the value as status code.
/// This status code is returned to the operating system.
fn report(self) -> ExitCode;
}
impl Termination for () {
#[inline]
fn report(self) -> ExitCode {
ExitCode::SUCCESS
}
}
impl Termination for isize {
#[inline]
fn report(self) -> ExitCode {
ExitCode(self)
}
}

View File

@@ -2,7 +2,6 @@ release := ""
qemu_flags := ""
cargo_flags := "" + if release != "" { "--release" } else { "" }
bin_path := if release != "" { "target/riscv64/release" } else { "target/riscv64/debug" }
rust_src := `rustc --print sysroot` / "lib/rustlib/src/rust/library/std/src"
default: run
@@ -13,25 +12,19 @@ mount_filesystem:
sync_filesystem:
sync
cp_std path:
@echo "Copying {{ path }}"
@mkdir {{ "crates/std/src" / parent_directory(path) }} -p
@cp {{ rust_src / path }} {{ "crates/std/src" / path }}
@perl -i -0777 -pe 's/^\s*#!?\[(un)?stable\(.*?\)\s*\]\n//gsm' {{ "crates/std/src" / path }}
@perl -i -0777 -pe 's/^\s*#!?\[rustc_.*?\]\n//gsm' {{ "crates/std/src" / path }}
update-std:
@cd library/std && just update-std
update_std:
@just cp_std "ffi/c_str.rs"
@just cp_std "ffi/mod.rs"
@just cp_std "ffi/os_str.rs"
build-sysroot:
@cd library/std && just build-sysroot
build_user_prog prog:
RUSTFLAGS="-C relocation-model=pic -C link-arg=-Tuser.ld -C link-arg=-pie" cargo b {{ cargo_flags }} --package {{ prog }}
RUSTFLAGS="-C relocation-model=pic -C link-arg=-pie --sysroot {{ justfile_directory() / "sysroot" }}" cargo b {{ cargo_flags }} --package {{ prog }}
riscv64-elf-strip {{ bin_path / prog }}
cp {{ bin_path / prog }} {{ "mnt/usr/bin" / prog }}
build: mount_filesystem (map_dir "user" f"just release=\"{{release}}\" cargo_flags=\"{{cargo_flags}}\" build_user_prog")
cargo b {{ cargo_flags }}
RUSTFLAGS="-Clink-arg=-Tilm.ld --sysroot {{ justfile_directory() / "sysroot" }}" cargo b {{ cargo_flags }}
just sync_filesystem
run: build (runner f"{{bin_path / "kernel-rust"}}")
@@ -66,4 +59,5 @@ runner args:
{{ qemu }} -kernel {{ args }}
clean:
cd library && just clean
cargo clean

17
library/.gitignore vendored Normal file
View File

@@ -0,0 +1,17 @@
portable-simd
core_arch
core
compiler-builtins
alloc
stdarch
unwind
std_detect
panic_abort
panic_unwind
rustc-std-workspace-alloc
rustc-std-workspace-core
rustc-std-workspace-std
windows_link
profiler_builtins
test
proc_macro

88
library/Cargo.toml Normal file
View File

@@ -0,0 +1,88 @@
cargo-features = ["profile-rustflags"]
[workspace]
resolver = "1"
members = [
"std",
# "sysroot",
# "coretests",
# "alloctests",
]
exclude = [
# stdarch has its own Cargo workspace
"stdarch",
"windows_link"
]
[profile.release.package.compiler_builtins]
# For compiler-builtins we always use a high number of codegen units.
# The goal here is to place every single intrinsic into its own object
# file to avoid symbol clashes with the system libgcc if possible. Note
# that this number doesn't actually produce this many object files, we
# just don't create more than this number of object files.
#
# It's a bit of a bummer that we have to pass this here, unfortunately.
# Ideally this would be specified through an env var to Cargo so Cargo
# knows how many CGUs are for this specific crate, but for now
# per-crate configuration isn't specifiable in the environment.
codegen-units = 10000
# These dependencies of the standard library implement symbolication for
# backtraces on most platforms. Their debuginfo causes both linking to be slower
# (more data to chew through) and binaries to be larger without really all that
# much benefit. This section turns them all to down to have no debuginfo which
# helps to improve link times a little bit.
[profile.release.package]
addr2line.debug = 0
addr2line.opt-level = "s"
adler2.debug = 0
gimli.debug = 0
gimli.opt-level = "s"
miniz_oxide.debug = 0
miniz_oxide.opt-level = "s"
# `opt-level = "s"` for `object` led to a size regression when tried previously
object.debug = 0
rustc-demangle.debug = 0
rustc-demangle.opt-level = "s"
# panic_abort must always be compiled with panic=abort, even when the rest of the
# sysroot is panic=unwind.
[profile.dev.package.panic_abort]
rustflags = ["-Cpanic=abort"]
[profile.release.package.panic_abort]
rustflags = ["-Cpanic=abort"]
# The "dist" profile is used by bootstrap for prebuilt libstd artifacts
# These settings ensure that the prebuilt artifacts support a variety of features
# in the user's profile.
[profile.dist]
inherits = "release"
codegen-units = 1
debug = 1 # "limited"
rustflags = [
# `profile.lto=off` implies `-Cembed-bitcode=no`, but unconditionally embedding
# bitcode is necessary for when users enable LTO.
# Required until Cargo can re-build the standard library based on the value
# of `profile.lto` in the user's profile.
"-Cembed-bitcode=yes",
# Enable frame pointers
"-Zunstable-options",
"-Cforce-frame-pointers=non-leaf",
]
[profile.dist.package.panic_abort]
rustflags = [
"-Cpanic=abort",
"-Cembed-bitcode=yes",
"-Zunstable-options",
"-Cforce-frame-pointers=non-leaf",
]
[patch.crates-io]
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on here
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
# rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }

1
library/backtrace Submodule

Submodule library/backtrace added at 28ec93b503

319
library/justfile Normal file
View File

@@ -0,0 +1,319 @@
SRC_DIR := "std/src"
PATCH_DIR := "std/patches"
RUST_SRC := `rustc --print sysroot` / "lib/rustlib/src/rust/library"
patch-std:
@echo "Start patching the std..."
@find {{ PATCH_DIR }} -type f | while read -r patch_file; do \
relative_path="${patch_file#{{ PATCH_DIR }}/}"; \
target_file="${relative_path%.sed}.rs"; \
if [ -f "{{ SRC_DIR }}/$target_file" ]; then \
echo " [SED] $target_file"; \
sed -i -f "$patch_file" "{{ SRC_DIR }}/$target_file"; \
else \
echo "⚠ [WARN] target doesn't exist: $target_file"; \
fi; \
done
@echo "✅ Patching done."
update-std:
@just setup-std
@just patch-std
cp_std path:
@echo "Linking {{ path }}"
@mkdir {{ "std/src" / parent_directory(path) }} -p
@ln -fs {{ RUST_SRC / "std/src" / path }} {{ "std/src" / parent_directory(path) }}
real_cp_std path:
@echo "Copying {{ path }}"
@mkdir {{ "std/src" / parent_directory(path) }} -p
@cp {{ RUST_SRC / "std/src" / path }} {{ "std/src" / path }}
setup-std:
ln -fs {{ RUST_SRC / "std_detect" }} "."
ln -fs {{ RUST_SRC / "panic_abort" }} "."
ln -fs {{ RUST_SRC / "panic_unwind" }} "."
ln -fs {{ RUST_SRC / "windows_link" }} "."
ln -fs {{ RUST_SRC / "unwind" }} "."
ln -fs {{ RUST_SRC / "alloc" }} "."
ln -fs {{ RUST_SRC / "rustc-std-workspace-alloc" }} "."
ln -fs {{ RUST_SRC / "rustc-std-workspace-core" }} "."
ln -fs {{ RUST_SRC / "rustc-std-workspace-std" }} "."
ln -fs {{ RUST_SRC / "compiler-builtins" }} "."
ln -fs {{ RUST_SRC / "core" }} "."
ln -fs {{ RUST_SRC / "stdarch" }} "."
ln -fs {{ RUST_SRC / "portable-simd" }} "."
ln -fs {{ RUST_SRC / "proc_macro" }} "."
ln -fs {{ RUST_SRC / "profiler_builtins" }} "."
ln -fs {{ RUST_SRC / "test" }} "."
@just cp_std "../build.rs"
@sed -i "59a\ || target_os == \"survos\"" std/build.rs
@just cp_std "alloc.rs"
@just cp_std "ascii.rs"
@just cp_std "backtrace.rs"
@just cp_std "bstr.rs"
@just cp_std "env.rs"
@just cp_std "error.rs"
@just cp_std "fs.rs"
@just cp_std "keyword_docs.rs"
@just cp_std "lib.rs"
@just cp_std "macros.rs"
@just cp_std "panic.rs"
@just cp_std "panicking.rs"
@just cp_std "pat.rs"
@just cp_std "path.rs"
@just cp_std "process.rs"
@just cp_std "random.rs"
@just cp_std "rt.rs"
@just cp_std "tests_helpers.rs"
@just cp_std "time.rs"
@just cp_std "backtrace"
@just cp_std "collections"
@just cp_std "ffi"
@just cp_std "fs"
@just cp_std "hash"
@just cp_std "io"
@just cp_std "net"
@just cp_std "num"
@just cp_std "os/raw/mod.rs"
@just cp_std "os/raw/tests.rs"
@just cp_std "os/mod.rs"
@just cp_std "prelude"
@just cp_std "process"
@just cp_std "sync"
@just cp_std "sys/alloc/mod.rs"
@just real_cp_std "sys/args/mod.rs"
@just cp_std "sys/args/unsupported.rs"
@just cp_std "sys/env/mod.rs"
@just cp_std "sys/env/common.rs"
@just cp_std "sys/env/unsupported.rs"
@just cp_std "sys/fd/mod.rs"
@just cp_std "sys/fs/mod.rs"
@just cp_std "sys/fs/common.rs"
@just cp_std "sys/fs/unsupported.rs"
@just cp_std "sys/helpers/mod.rs"
@just cp_std "sys/helpers/small_c_string.rs"
@just cp_std "sys/helpers/tests.rs"
@just cp_std "sys/helpers/wstr.rs"
@just cp_std "sys/io/error/generic.rs"
@just real_cp_std "sys/io/error/mod.rs"
@just cp_std "sys/io/io_slice/unsupported.rs"
@just cp_std "sys/io/is_terminal/unsupported.rs"
@just cp_std "sys/io/kernel_copy/mod.rs"
@just cp_std "sys/io/mod.rs"
@just cp_std "sys/net/connection/mod.rs"
@just cp_std "sys/net/connection/unsupported.rs"
@just cp_std "sys/net/hostname/mod.rs"
@just cp_std "sys/net/hostname/unsupported.rs"
@just cp_std "sys/net/mod.rs"
@just cp_std "sys/os_str/bytes/tests.rs"
@just cp_std "sys/os_str/bytes.rs"
@just cp_std "sys/os_str/mod.rs"
@just real_cp_std "sys/pal/mod.rs"
@just cp_std "sys/pal/unsupported/mod.rs"
@just cp_std "sys/pal/unsupported/common.rs"
@just cp_std "sys/pal/unsupported/os.rs"
@just cp_std "sys/path/mod.rs"
@just cp_std "sys/path/unix.rs"
@just cp_std "sys/personality/dwarf/eh.rs"
@just cp_std "sys/personality/dwarf/mod.rs"
@just cp_std "sys/personality/dwarf/tests.rs"
@just cp_std "sys/personality/mod.rs"
@just cp_std "sys/pipe/mod.rs"
@just cp_std "sys/pipe/unsupported.rs"
@just cp_std "sys/platform_version/mod.rs"
@just cp_std "sys/process/mod.rs"
@just cp_std "sys/process/env.rs"
@just cp_std "sys/process/unsupported.rs"
@just real_cp_std "sys/random/mod.rs"
@just cp_std "sys/random/unsupported.rs"
@just cp_std "sys/stdio/mod.rs"
@just cp_std "sys/stdio/unsupported.rs"
@just cp_std "sys/sync/condvar/mod.rs"
@just cp_std "sys/sync/condvar/no_threads.rs"
@just cp_std "sys/sync/mutex/mod.rs"
@just cp_std "sys/sync/mutex/no_threads.rs"
@just cp_std "sys/sync/once/mod.rs"
@just cp_std "sys/sync/once/no_threads.rs"
@just cp_std "sys/sync/rwlock/mod.rs"
@just cp_std "sys/sync/rwlock/no_threads.rs"
@just cp_std "sys/sync/thread_parking/mod.rs"
@just cp_std "sys/sync/thread_parking/unsupported.rs"
@just cp_std "sys/sync/mod.rs"
@just cp_std "sys/sync/once_box.rs"
@just cp_std "sys/thread/mod.rs"
@just cp_std "sys/thread/unsupported.rs"
@just real_cp_std "sys/thread_local/mod.rs"
@just cp_std "sys/thread_local/no_threads.rs"
@just cp_std "sys/thread_local/os.rs"
@just cp_std "sys/time/mod.rs"
@just cp_std "sys/time/unsupported.rs"
@just cp_std "sys/backtrace.rs"
@just cp_std "sys/cmath.rs"
@just cp_std "sys/configure_builtins.rs"
@just cp_std "sys/env_consts.rs"
@just cp_std "sys/exit.rs"
@just cp_std "sys/mod.rs"
@just cp_std "thread"
STD_FILES := "alloc.rs \
ascii.rs \
backtrace.rs \
bstr.rs \
env.rs \
error.rs \
fs.rs \
keyword_docs.rs \
lib.rs \
macros.rs \
panic.rs \
panicking.rs \
pat.rs \
path.rs \
process.rs \
random.rs \
rt.rs \
tests_helpers.rs \
time.rs \
backtrace \
collections \
ffi \
fs \
hash \
io \
net \
num \
os/raw/mod.rs \
os/raw/tests.rs \
os/mod.rs \
prelude \
process \
sync \
sys/alloc/mod.rs \
sys/args/mod.rs \
sys/args/unsupported.rs \
sys/env/mod.rs \
sys/env/common.rs \
sys/env/unsupported.rs \
sys/fd/mod.rs \
sys/fs/mod.rs \
sys/fs/common.rs \
sys/fs/unsupported.rs \
sys/helpers/mod.rs \
sys/helpers/small_c_string.rs \
sys/helpers/tests.rs \
sys/helpers/wstr.rs \
sys/io/error/generic.rs \
sys/io/error/mod.rs \
sys/io/io_slice/unsupported.rs \
sys/io/is_terminal/unsupported.rs \
sys/io/kernel_copy/mod.rs \
sys/io/mod.rs \
sys/net/connection/mod.rs \
sys/net/connection/unsupported.rs \
sys/net/hostname/mod.rs \
sys/net/hostname/unsupported.rs \
sys/net/mod.rs \
sys/os_str/bytes/tests.rs \
sys/os_str/bytes.rs \
sys/os_str/mod.rs \
sys/pal/mod.rs \
sys/pal/unsupported/mod.rs \
sys/pal/unsupported/common.rs \
sys/pal/unsupported/os.rs \
sys/path/mod.rs \
sys/path/unix.rs \
sys/personality/dwarf/eh.rs \
sys/personality/dwarf/mod.rs \
sys/personality/dwarf/tests.rs \
sys/personality/mod.rs \
sys/pipe/mod.rs \
sys/pipe/unsupported.rs \
sys/platform_version/mod.rs \
sys/process/mod.rs \
sys/process/env.rs \
sys/process/unsupported.rs \
sys/random/mod.rs \
sys/random/unsupported.rs \
sys/stdio/mod.rs \
sys/stdio/unsupported.rs \
sys/sync/condvar/mod.rs \
sys/sync/condvar/no_threads.rs \
sys/sync/mutex/mod.rs \
sys/sync/mutex/no_threads.rs \
sys/sync/once/mod.rs \
sys/sync/once/no_threads.rs \
sys/sync/rwlock/mod.rs \
sys/sync/rwlock/no_threads.rs \
sys/sync/thread_parking/mod.rs \
sys/sync/thread_parking/unsupported.rs \
sys/sync/mod.rs \
sys/sync/once_box.rs \
sys/thread/mod.rs \
sys/thread/unsupported.rs \
sys/thread_local/mod.rs \
sys/thread_local/no_threads.rs \
sys/thread_local/os.rs \
sys/time/mod.rs \
sys/time/unsupported.rs \
sys/backtrace.rs \
sys/cmath.rs \
sys/configure_builtins.rs \
sys/env_consts.rs \
sys/exit.rs \
sys/mod.rs \
thread"
build-sysroot: update-std
RUSTFLAGS="-Zforce-unstable-if-unmarked -C relocation-model=pic -C link-arg=-pie" cargo build --target ../riscv64.json
mkdir ../sysroot/lib/rustlib/riscv64/lib -p
rm ../sysroot/lib/rustlib/riscv64/lib/* -rf
cp target/riscv64/debug/deps/*.rlib ../sysroot/lib/rustlib/riscv64/lib
clean:
# cargo clean
rm ../sysroot/lib/rustlib/riscv64/lib/* -rf
for file in {{ STD_FILES }}; do \
rm -rf std/src/$file; \
done
rm -rf std/build.rs

109
library/std/.gitignore vendored Normal file
View File

@@ -0,0 +1,109 @@
build.rs
src/alloc.rs
src/ascii.rs
src/backtrace.rs
src/bstr.rs
src/env.rs
src/error.rs
src/fs.rs
src/keyword_docs.rs
src/lib.rs
src/macros.rs
src/panic.rs
src/panicking.rs
src/pat.rs
src/path.rs
src/process.rs
src/random.rs
src/rt.rs
src/tests_helpers.rs
src/time.rs
src/backtrace
src/collections
src/ffi
src/fs
src/hash
src/io
src/net
src/num
src/os/raw/mod.rs
src/os/raw/tests.rs
src/os/mod.rs
src/prelude
src/process
src/sync
src/sys/alloc/mod.rs
src/sys/args/mod.rs
src/sys/args/unsupported.rs
src/sys/env/mod.rs
src/sys/env/common.rs
src/sys/env/unsupported.rs
src/sys/fd/mod.rs
src/sys/fs/mod.rs
src/sys/fs/common.rs
src/sys/fs/unsupported.rs
src/sys/helpers/mod.rs
src/sys/helpers/small_c_string.rs
src/sys/helpers/tests.rs
src/sys/helpers/wstr.rs
src/sys/io/error/generic.rs
src/sys/io/error/mod.rs
src/sys/io/io_slice/unsupported.rs
src/sys/io/is_terminal/unsupported.rs
src/sys/io/kernel_copy/mod.rs
src/sys/io/mod.rs
src/sys/net/connection/mod.rs
src/sys/net/connection/unsupported.rs
src/sys/net/hostname/mod.rs
src/sys/net/hostname/unsupported.rs
src/sys/net/mod.rs
src/sys/os_str/bytes/tests.rs
src/sys/os_str/bytes.rs
src/sys/os_str/mod.rs
src/sys/pal/mod.rs
src/sys/pal/unsupported/mod.rs
src/sys/pal/unsupported/common.rs
src/sys/pal/unsupported/os.rs
src/sys/path/mod.rs
src/sys/path/unix.rs
src/sys/personality/dwarf/eh.rs
src/sys/personality/dwarf/mod.rs
src/sys/personality/dwarf/tests.rs
src/sys/personality/mod.rs
src/sys/pipe/mod.rs
src/sys/pipe/unsupported.rs
src/sys/platform_version/mod.rs
src/sys/process/mod.rs
src/sys/process/env.rs
src/sys/process/unsupported.rs
src/sys/random/mod.rs
src/sys/random/unsupported.rs
src/sys/stdio/mod.rs
src/sys/stdio/unsupported.rs
src/sys/sync/condvar/mod.rs
src/sys/sync/condvar/no_threads.rs
src/sys/sync/mutex/mod.rs
src/sys/sync/mutex/no_threads.rs
src/sys/sync/once/mod.rs
src/sys/sync/once/no_threads.rs
src/sys/sync/rwlock/mod.rs
src/sys/sync/rwlock/no_threads.rs
src/sys/sync/thread_parking/mod.rs
src/sys/sync/thread_parking/unsupported.rs
src/sys/sync/mod.rs
src/sys/sync/once_box.rs
src/sys/thread/mod.rs
src/sys/thread/unsupported.rs
src/sys/thread_local/mod.rs
src/sys/thread_local/no_threads.rs
src/sys/thread_local/os.rs
src/sys/time/mod.rs
src/sys/time/unsupported.rs
src/sys/backtrace.rs
src/sys/cmath.rs
src/sys/configure_builtins.rs
src/sys/env_consts.rs
src/sys/exit.rs
src/sys/mod.rs
src/thread

177
library/std/Cargo.toml Normal file
View File

@@ -0,0 +1,177 @@
cargo-features = ["public-dependency"]
[package]
name = "std"
version = "0.0.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/rust.git"
description = "The Rust Standard Library"
edition = "2024"
autobenches = false
[lib]
crate-type = ["dylib", "rlib"]
[dependencies]
alloc = { path = "../alloc", public = true }
# std no longer uses cfg-if directly, but the included copy of backtrace does.
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core", public = true }
unwind = { path = "../unwind" }
hashbrown = { version = "0.16.1", default-features = false, features = [
'rustc-dep-of-std',
] }
std_detect = { path = "../std_detect", public = true }
# Dependencies of the `backtrace` crate
rustc-demangle = { version = "0.1.27", features = ['rustc-dep-of-std'] }
[target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies]
miniz_oxide = { version = "0.8.0", optional = true, default-features = false }
addr2line = { version = "0.25.0", optional = true, default-features = false }
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2.178", default-features = false, features = [
'rustc-dep-of-std',
], public = true }
[target.'cfg(all(not(target_os = "aix"), not(all(windows, target_env = "msvc", not(target_vendor = "uwp")))))'.dependencies]
object = { version = "0.37.1", default-features = false, optional = true, features = [
'read_core',
'elf',
'macho',
'pe',
'unaligned',
'archive',
] }
[target.'cfg(target_os = "aix")'.dependencies]
object = { version = "0.37.1", default-features = false, optional = true, features = [
'read_core',
'xcoff',
'unaligned',
'archive',
] }
[target.'cfg(any(windows, target_os = "cygwin"))'.dependencies.windows-link]
path = "../windows_link"
[dev-dependencies]
rand = { version = "0.9.0", default-features = false, features = ["alloc"] }
rand_xorshift = "0.4.0"
[target.'cfg(any(all(target_family = "wasm", target_os = "unknown"), target_os = "xous", target_os = "vexos", all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
dlmalloc = { version = "0.2.10", features = ['rustc-dep-of-std'] }
[target.x86_64-fortanix-unknown-sgx.dependencies]
fortanix-sgx-abi = { version = "0.6.1", features = [
'rustc-dep-of-std',
], public = true }
[target.'cfg(target_os = "motor")'.dependencies]
moto-rt = { version = "0.16", features = ['rustc-dep-of-std'], public = true }
[target.'cfg(target_os = "hermit")'.dependencies]
hermit-abi = { version = "0.5.0", features = [
'rustc-dep-of-std',
], public = true }
[target.'cfg(all(target_os = "wasi", target_env = "p1"))'.dependencies]
wasi = { version = "0.11.0", features = [
'rustc-dep-of-std',
], default-features = false }
[target.'cfg(all(target_os = "wasi", target_env = "p2"))'.dependencies]
wasip2 = { version = '0.14.4', features = [
'rustc-dep-of-std',
], default-features = false, package = 'wasi' }
[target.'cfg(all(target_os = "wasi", target_env = "p3"))'.dependencies]
wasip2 = { version = '0.14.4', features = [
'rustc-dep-of-std',
], default-features = false, package = 'wasi' }
[target.'cfg(target_os = "uefi")'.dependencies]
r-efi = { version = "5.2.0", features = ['rustc-dep-of-std'] }
r-efi-alloc = { version = "2.0.0", features = ['rustc-dep-of-std'] }
[target.'cfg(target_os = "vexos")'.dependencies]
vex-sdk = { version = "0.27.0", features = [
'rustc-dep-of-std',
], default-features = false }
[features]
default = ["compiler-builtins-mem"]
backtrace = [
'addr2line/rustc-dep-of-std',
'object/rustc-dep-of-std',
'miniz_oxide/rustc-dep-of-std',
]
# Disable symbolization in backtraces. For use with -Zbuild-std.
# FIXME: Ideally this should be an additive backtrace-symbolization feature
backtrace-trace-only = []
panic-unwind = ["dep:panic_unwind"]
compiler-builtins-c = ["alloc/compiler-builtins-c"]
compiler-builtins-mem = ["alloc/compiler-builtins-mem"]
llvm-libunwind = ["unwind/llvm-libunwind"]
system-llvm-libunwind = ["unwind/system-llvm-libunwind"]
# Choose algorithms that are optimized for binary size instead of runtime performance
optimize_for_size = ["core/optimize_for_size", "alloc/optimize_for_size"]
# Make `RefCell` store additional debugging information, which is printed out when
# a borrow error occurs
debug_refcell = ["core/debug_refcell"]
llvm_enzyme = ["core/llvm_enzyme"]
# Enable using raw-dylib for Windows imports.
# This will eventually be the default.
windows_raw_dylib = ["windows-link/windows_raw_dylib"]
[package.metadata.fortanix-sgx]
# Maximum possible number of threads when testing
threads = 125
# Maximum heap size
heap_size = 0x8000000
[[test]]
name = "pipe-subprocess"
path = "tests/pipe_subprocess.rs"
harness = false
[[test]]
name = "sync"
path = "tests/sync/lib.rs"
[[test]]
name = "thread_local"
path = "tests/thread_local/lib.rs"
[[bench]]
name = "stdbenches"
path = "benches/lib.rs"
test = true
[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
# std use #[path] imports to portable-simd `std_float` crate
# and to the `backtrace` crate which messes-up with Cargo list
# of declared features, we therefor expect any feature cfg
'cfg(feature, values(any()))',
# Internal features aren't marked known config by default, we use these to
# gate tests.
'cfg(target_has_reliable_f16)',
'cfg(target_has_reliable_f16_math)',
'cfg(target_has_reliable_f128)',
'cfg(target_has_reliable_f128_math)',
]
# shared = { path = "../shared", features = ["user"] }
# io_crate = { package = "io", path = "../io", features = ["alloc_crate"] }

View File

@@ -0,0 +1,4 @@
# 55a \ target_os = "survos" => { \
# mod survos; \
# pub use survos::*; \
# }

View File

@@ -0,0 +1 @@
45a \ target_os = "survos",

View File

@@ -0,0 +1,6 @@
62a \ target_os = "survos" => { \
mod unsupported; \
pub use self::unsupported::*; \
mod survos; \
pub use self::survos::*; \
}

View File

@@ -0,0 +1,2 @@
108a \target_os = "survos",
124a \target_os = "survos",

View File

@@ -0,0 +1,6 @@
32a \ target_os = "survos",
129a \ target_os = "survos" => { \
// todo \
pub(crate) fn enable() {} \
}

22
library/std/riscv64.json Normal file
View File

@@ -0,0 +1,22 @@
{
"llvm-target": "riscv64",
"llvm-abiname": "lp64",
"abi": "lp64",
"data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128",
"target-endian": "little",
"target-pointer-width": 64,
"arch": "riscv64",
"os": "survos",
"vendor": "unknown",
"env": "",
"features": "+i,+m,+a,+zicsr",
"linker": "ld.lld",
"linker-flavor": "ld",
"executables": true,
"panic-strategy": "abort",
"relocation-model": "static",
"disable-redzone": true,
"emit-debug-gdb-scripts": false,
"eh-frame-header": false,
"code-model": "medium"
}

View File

@@ -0,0 +1,11 @@
/// # Safety
/// `argc` and `argv` are passed by the kernel
#[unsafe(no_mangle)]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe extern "C" fn _start(argc: isize, argv: *const *const u8) -> isize {
unsafe extern "C" {
fn main(argc: isize, argv: *const *const u8) -> isize;
}
unsafe { main(argc, argv) }
}

View File

@@ -6,7 +6,7 @@
"target-endian": "little",
"target-pointer-width": 64,
"arch": "riscv64",
"os": "none",
"os": "survos",
"vendor": "unknown",
"env": "",
"features": "+i,+m,+a,+zicsr",

View File

@@ -0,0 +1 @@
../../../../../../library

35
user.ld
View File

@@ -1,35 +0,0 @@
/*
* ld directives the for barmetal RISCV
*/
OUTPUT_ARCH(riscv)
ENTRY(_start)
MEMORY {
RAM (wxa) : ORIGIN = 0x0, LENGTH = 128M
}
SECTIONS {
. = 0x0;
.text : {
KEEP(*(.text._start))
*(.text .text.*)
} > RAM
.rodata : {
*(.rodata .rodata.*)
} > RAM
.data : {
*(.data .data.*)
} > RAM
.bss : ALIGN(8) {
__bss_start = .;
*(.bss .bss.*)
__bss_end = .;
} > RAM
_heap_start = ALIGN(8);
_heap_end = ORIGIN(RAM) + LENGTH(RAM);
}

View File

@@ -4,4 +4,6 @@ version = "0.1.0"
edition = "2024"
[dependencies]
std = { path = "../../crates/std" }
# std = { path = "../../crates/std" }
# shared = { path = "../../crates/shared", features = ["user"] }
# core = { path = "../../crates/std/crates/core" }

View File

@@ -1,6 +1,9 @@
fn main() -> isize {
fn main() {
let a = std::env::args();
for a in a {
println!("Argument: {}", a);
}
println!(
"Hello from PIC program loaded dynamically with custom std and a better justfile, and syscalls ! "
);
0
}

View File

@@ -4,4 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
std = { path = "../../crates/std" }
# std = { path = "../../crates/std" }
shared = { path = "../../crates/shared", features = ["user"] }
io = { path = "../../crates/io" }
bffs = { path = "../../crates/bffs" }

View File

@@ -1,23 +1,24 @@
#![allow(unused)]
use std::{
io::{Read, Write, stdin},
syscall,
};
use io::{Read, Write};
use std::io::{Stdin, stdin};
use shared::syscall;
fn main() {
// let mut input = String::new();
let mut input = String::new();
input.push('a');
// let mut file = syscall::open("/dev/fb0");
// syscall::seek(&mut file, SeekFrom::End(-3));
// syscall::write(&mut file, &[255; 6400 * 50]);
// syscall::sleep(Duration::from_secs_f64(2.0));
syscall::close(0);
let mut tty = syscall::open("/dev/tty0");
tty.write(input.as_bytes()).unwrap();
syscall::spawn("/usr/bin/shell");
loop {
let mut test = [0; 2];
let len = stdin().read(&mut test).unwrap();
tty.write_all(str::from_utf8(&test[..len as usize]).unwrap().as_bytes())
let len = tty.read(&mut test).unwrap();
tty.write(str::from_utf8(&test[..len as usize]).unwrap().as_bytes())
.unwrap();
}
}