work on custom STD

This commit is contained in:
Able 2023-03-09 06:36:35 -06:00
parent 3ff38b9e60
commit bd4241209a
15 changed files with 146 additions and 35 deletions

18
Cargo.lock generated
View file

@ -276,10 +276,6 @@ version = "0.6.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
[[package]]
name = "relib"
version = "0.1.0"
[[package]] [[package]]
name = "ron" name = "ron"
version = "0.7.1" version = "0.7.1"
@ -319,6 +315,20 @@ dependencies = [
"versioning", "versioning",
] ]
[[package]]
name = "std"
version = "0.1.0"
dependencies = [
"versioning",
]
[[package]]
name = "std_test"
version = "0.1.0"
dependencies = [
"std",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.105" version = "1.0.105"

View file

@ -11,13 +11,14 @@ members = [
"drivers/keyboards/ps2_keyboard", "drivers/keyboards/ps2_keyboard",
"drivers/mice/ps2_mouse", "drivers/mice/ps2_mouse",
"libraries/able_graphics_library", "libraries/able_graphics_library",
"libraries/clparse", "libraries/clparse",
"libraries/cryptography", "libraries/cryptography",
"libraries/locale-maxima", "libraries/locale-maxima",
"libraries/messaging", "libraries/messaging",
"libraries/process", "libraries/process",
"libraries/relib", "libraries/std",
"libraries/table", "libraries/table",
"libraries/tar", "libraries/tar",
"libraries/time", "libraries/time",
@ -30,4 +31,7 @@ members = [
"programs/table_view", "programs/table_view",
"programs/undelete", "programs/undelete",
"programs/wat2wasm", "programs/wat2wasm",
"programs/std_test",
] ]

View file

@ -33,6 +33,15 @@ pub struct GraphicsSettings {
} }
impl 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 { pub fn get_mode(&self) -> GraphicsMode {
self.mode self.mode
} }
@ -41,3 +50,17 @@ impl GraphicsSettings {
self.cursor.cursor_state = c_state; 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(),
};
}

View file

@ -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

View file

@ -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,
}
}
}

View file

@ -1,8 +1,9 @@
[package] [package]
name = "relib" name = "std"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
versioning = { path = "../versioning" }

View 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
View 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") _,
);
}
}

View file

@ -0,0 +1,5 @@
#[panic_handler]
fn panic_handler(pinfo: &core::panic::PanicInfo) -> ! {
print("PANIC!");
loop {}
}

View file

@ -0,0 +1 @@
pub mod rust_2021;

View file

@ -0,0 +1,7 @@
pub use core::prelude::v1::*;
pub use crate::print;
pub use core::panic;
pub use versioning;

View 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" }

View 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
View 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

View file

@ -0,0 +1,5 @@
fn main() {
print("Hello, world!\n");
panic!("Broken");
}