diff --git a/Cargo.lock b/Cargo.lock index bf0fefd..72d16c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 33b291e..df72a9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", ] diff --git a/libraries/able_graphics_library/src/lib.rs b/libraries/able_graphics_library/src/lib.rs index 59037de..a61cfdc 100644 --- a/libraries/able_graphics_library/src/lib.rs +++ b/libraries/able_graphics_library/src/lib.rs @@ -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(), + }; +} diff --git a/libraries/relib/readme.md b/libraries/relib/readme.md deleted file mode 100644 index 64fef33..0000000 --- a/libraries/relib/readme.md +++ /dev/null @@ -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 \ No newline at end of file diff --git a/libraries/relib/src/lib.rs b/libraries/relib/src/lib.rs deleted file mode 100644 index c02f2cc..0000000 --- a/libraries/relib/src/lib.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![no_std] - -use alloc::{ - string::{String, ToString}, - vec::Vec, -}; - -extern crate alloc; - -#[derive(Debug)] -pub struct Path { - pub path: Vec, -} - -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, - } - } -} diff --git a/libraries/relib/Cargo.toml b/libraries/std/Cargo.toml similarity index 75% rename from libraries/relib/Cargo.toml rename to libraries/std/Cargo.toml index a252ef6..d6a73f3 100644 --- a/libraries/relib/Cargo.toml +++ b/libraries/std/Cargo.toml @@ -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" } diff --git a/libraries/std/src/entry.rs b/libraries/std/src/entry.rs new file mode 100644 index 0000000..7a485ab --- /dev/null +++ b/libraries/std/src/entry.rs @@ -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(main: fn() -> T, _: isize, _: *const *const u8, _: u8) -> isize { + main(); + 0 +} diff --git a/libraries/std/src/lib.rs b/libraries/std/src/lib.rs new file mode 100644 index 0000000..cc3229a --- /dev/null +++ b/libraries/std/src/lib.rs @@ -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") _, + ); + } +} diff --git a/libraries/std/src/panic.rs b/libraries/std/src/panic.rs new file mode 100644 index 0000000..ebbb3d8 --- /dev/null +++ b/libraries/std/src/panic.rs @@ -0,0 +1,5 @@ +#[panic_handler] +fn panic_handler(pinfo: &core::panic::PanicInfo) -> ! { + print("PANIC!"); + loop {} +} diff --git a/libraries/std/src/prelude/mod.rs b/libraries/std/src/prelude/mod.rs new file mode 100644 index 0000000..77dad8e --- /dev/null +++ b/libraries/std/src/prelude/mod.rs @@ -0,0 +1 @@ +pub mod rust_2021; diff --git a/libraries/std/src/prelude/rust_2021/mod.rs b/libraries/std/src/prelude/rust_2021/mod.rs new file mode 100644 index 0000000..5d1ac95 --- /dev/null +++ b/libraries/std/src/prelude/rust_2021/mod.rs @@ -0,0 +1,7 @@ +pub use core::prelude::v1::*; + +pub use crate::print; + +pub use core::panic; + +pub use versioning; diff --git a/programs/std_test/Cargo.toml b/programs/std_test/Cargo.toml new file mode 100644 index 0000000..f3ab515 --- /dev/null +++ b/programs/std_test/Cargo.toml @@ -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" } diff --git a/programs/std_test/bare-x86_64.json b/programs/std_test/bare-x86_64.json new file mode 100644 index 0000000..346fefd --- /dev/null +++ b/programs/std_test/bare-x86_64.json @@ -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" +} \ No newline at end of file diff --git a/programs/std_test/run.sh b/programs/std_test/run.sh new file mode 100755 index 0000000..da6ea62 --- /dev/null +++ b/programs/std_test/run.sh @@ -0,0 +1,2 @@ +cargo +nightly xbuild -p std_test --target std_test/bare-x86_64.json; +../target/bare-x86_64/debug/std_test \ No newline at end of file diff --git a/programs/std_test/src/main.rs b/programs/std_test/src/main.rs new file mode 100644 index 0000000..6167b04 --- /dev/null +++ b/programs/std_test/src/main.rs @@ -0,0 +1,5 @@ +fn main() { + print("Hello, world!\n"); + + panic!("Broken"); +}