forked from AbleOS/ableos_userland
work on custom STD
This commit is contained in:
parent
3ff38b9e60
commit
bd4241209a
18
Cargo.lock
generated
18
Cargo.lock
generated
|
@ -276,10 +276,6 @@ version = "0.6.28"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
||||
|
||||
[[package]]
|
||||
name = "relib"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "ron"
|
||||
version = "0.7.1"
|
||||
|
@ -319,6 +315,20 @@ dependencies = [
|
|||
"versioning",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "std"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"versioning",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "std_test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.105"
|
||||
|
|
|
@ -11,13 +11,14 @@ members = [
|
|||
|
||||
"drivers/keyboards/ps2_keyboard",
|
||||
"drivers/mice/ps2_mouse",
|
||||
|
||||
"libraries/able_graphics_library",
|
||||
"libraries/clparse",
|
||||
"libraries/cryptography",
|
||||
"libraries/locale-maxima",
|
||||
"libraries/messaging",
|
||||
"libraries/process",
|
||||
"libraries/relib",
|
||||
"libraries/std",
|
||||
"libraries/table",
|
||||
"libraries/tar",
|
||||
"libraries/time",
|
||||
|
@ -30,4 +31,7 @@ members = [
|
|||
"programs/table_view",
|
||||
"programs/undelete",
|
||||
"programs/wat2wasm",
|
||||
|
||||
|
||||
"programs/std_test",
|
||||
]
|
||||
|
|
|
@ -33,6 +33,15 @@ pub struct GraphicsSettings {
|
|||
}
|
||||
|
||||
impl GraphicsSettings {
|
||||
/// Create a new instance of graphics settings to be used by the window state
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
mode: GraphicsMode::RawPixels,
|
||||
cursor: Cursor {
|
||||
cursor_state: CursorStates::Default,
|
||||
},
|
||||
}
|
||||
}
|
||||
pub fn get_mode(&self) -> GraphicsMode {
|
||||
self.mode
|
||||
}
|
||||
|
@ -41,3 +50,17 @@ impl GraphicsSettings {
|
|||
self.cursor.cursor_state = c_state;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Window {
|
||||
x: i64,
|
||||
y: i64,
|
||||
graphics_settings: GraphicsSettings,
|
||||
}
|
||||
// Make a new window by calling the windowing manager
|
||||
pub fn create_window(x: i64, y: i64) -> Window {
|
||||
return Window {
|
||||
x,
|
||||
y,
|
||||
graphics_settings: GraphicsSettings::new(),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
An attempt at implimenting a standard library for ableOS
|
||||
Will reexport and break apart into submodules you can directly include to reduce bloat
|
|
@ -1,27 +0,0 @@
|
|||
#![no_std]
|
||||
|
||||
use alloc::{
|
||||
string::{String, ToString},
|
||||
vec::Vec,
|
||||
};
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Path {
|
||||
pub path: Vec<String>,
|
||||
}
|
||||
|
||||
impl Path {
|
||||
pub fn new(path: String) -> Self {
|
||||
let mut path_vec_string = Vec::new();
|
||||
|
||||
for part in path.split(&['\\', '/'][..]) {
|
||||
path_vec_string.push(part.to_string());
|
||||
}
|
||||
|
||||
Path {
|
||||
path: path_vec_string,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
[package]
|
||||
name = "relib"
|
||||
name = "std"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
versioning = { path = "../versioning" }
|
25
libraries/std/src/entry.rs
Normal file
25
libraries/std/src/entry.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use core::arch::asm;
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn _start() -> ! {
|
||||
extern "C" {
|
||||
fn main(argc: isize, argv: *const *const u8) -> isize;
|
||||
}
|
||||
|
||||
// TODO: grab and pass arguments to main
|
||||
|
||||
main(0, core::ptr::null());
|
||||
|
||||
asm!(
|
||||
"syscall",
|
||||
in("rax") 60,
|
||||
in("rdi") 0,
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
#[lang = "start"]
|
||||
fn lang_start<T>(main: fn() -> T, _: isize, _: *const *const u8, _: u8) -> isize {
|
||||
main();
|
||||
0
|
||||
}
|
33
libraries/std/src/lib.rs
Normal file
33
libraries/std/src/lib.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
#![feature(lang_items, prelude_import)]
|
||||
#![feature(panic_info_message)]
|
||||
#![no_std]
|
||||
|
||||
mod entry;
|
||||
pub mod panic;
|
||||
|
||||
use core::arch::asm;
|
||||
|
||||
#[prelude_import]
|
||||
pub use prelude::rust_2021::*;
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
use versioning::Version;
|
||||
|
||||
pub const VERSION: Version = Version::new(0, 1, 0);
|
||||
|
||||
// extern crate alloc;
|
||||
|
||||
pub fn print(s: &str) {
|
||||
unsafe {
|
||||
asm!(
|
||||
"syscall",
|
||||
in("rax") 1,
|
||||
in("rdi") 1,
|
||||
in("rsi") s.as_ptr(),
|
||||
in("rdx") s.len(),
|
||||
out("rcx") _,
|
||||
out("r11") _,
|
||||
);
|
||||
}
|
||||
}
|
5
libraries/std/src/panic.rs
Normal file
5
libraries/std/src/panic.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
#[panic_handler]
|
||||
fn panic_handler(pinfo: &core::panic::PanicInfo) -> ! {
|
||||
print("PANIC!");
|
||||
loop {}
|
||||
}
|
1
libraries/std/src/prelude/mod.rs
Normal file
1
libraries/std/src/prelude/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod rust_2021;
|
7
libraries/std/src/prelude/rust_2021/mod.rs
Normal file
7
libraries/std/src/prelude/rust_2021/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
pub use core::prelude::v1::*;
|
||||
|
||||
pub use crate::print;
|
||||
|
||||
pub use core::panic;
|
||||
|
||||
pub use versioning;
|
9
programs/std_test/Cargo.toml
Normal file
9
programs/std_test/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "std_test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
std = { path = "../../libraries/std" }
|
15
programs/std_test/bare-x86_64.json
Normal file
15
programs/std_test/bare-x86_64.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"llvm-target": "x86_64-unknown-none",
|
||||
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
|
||||
"arch": "x86_64",
|
||||
"target-endian": "little",
|
||||
"target-pointer-width": "64",
|
||||
"target-c-int-width": "32",
|
||||
"os": "none",
|
||||
"executables": true,
|
||||
"linker-flavor": "ld.lld",
|
||||
"linker": "rust-lld",
|
||||
"panic-strategy": "abort",
|
||||
"disable-redzone": true,
|
||||
"features": "-mmx,-sse,+soft-float"
|
||||
}
|
2
programs/std_test/run.sh
Executable file
2
programs/std_test/run.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
cargo +nightly xbuild -p std_test --target std_test/bare-x86_64.json;
|
||||
../target/bare-x86_64/debug/std_test
|
5
programs/std_test/src/main.rs
Normal file
5
programs/std_test/src/main.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
fn main() {
|
||||
print("Hello, world!\n");
|
||||
|
||||
panic!("Broken");
|
||||
}
|
Loading…
Reference in a new issue