make system_config

This commit is contained in:
Able 2023-04-30 06:52:42 -05:00
parent 18b18a67ad
commit ecb1c2a3cc
14 changed files with 455 additions and 90 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target
/disk

81
Cargo.lock generated
View file

@ -59,6 +59,12 @@ dependencies = [
"std",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "axel2wat"
version = "0.1.0"
@ -171,6 +177,16 @@ dependencies = [
"ahash 0.8.2",
]
[[package]]
name = "indexmap"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown 0.12.3",
]
[[package]]
name = "libc"
version = "0.2.138"
@ -225,6 +241,12 @@ dependencies = [
"syn",
]
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "messaging"
version = "0.1.0"
@ -341,6 +363,15 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_spanned"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
dependencies = [
"serde",
]
[[package]]
name = "shell"
version = "0.1.0"
@ -375,6 +406,13 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "system_config"
version = "0.1.0"
dependencies = [
"toml 0.7.3",
]
[[package]]
name = "table"
version = "0.1.0"
@ -438,6 +476,40 @@ dependencies = [
"serde",
]
[[package]]
name = "toml"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b403acf6f2bb0859c93c7f0d967cb4a75a7ac552100f9322faf64dc047669b21"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.19.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]]
name = "trash_manifest"
version = "0.1.0"
@ -505,6 +577,15 @@ dependencies = [
"logos",
]
[[package]]
name = "winnow"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5617da7e1f97bf363947d767b91aaf3c2bbc19db7fda9c65af1278713d58e0a2"
dependencies = [
"memchr",
]
[[package]]
name = "xml"
version = "0.1.0"

View file

@ -40,6 +40,7 @@ members = [
"programs/table_view",
"programs/undelete",
"programs/wasm_syscall_test",
"programs/system_config",
"programs/wat2wasm",
"programs/xml_tests",

View file

@ -1,3 +1,49 @@
pub enum BufferUsage {
Vertex,
}
use alloc::vec::Vec;
use super::error::GPUError;
pub type VertexBuffer = Vec<u8>;
#[repr(C)]
pub struct XYZ {
x: f64,
y: f64,
z: f64,
}
#[repr(C)]
pub struct XYZW {
x: f64,
y: f64,
z: f64,
w: f64,
}
pub struct GraphicsEngine {
vertex_buffer_attributes_editable: bool,
vertex_buffer: VertexBuffer,
vertex_size: usize,
}
impl GraphicsEngine {
pub fn new() -> Self {
Self {
vertex_buffer_attributes_editable: true,
vertex_buffer: Vec::new(),
vertex_size: 0,
}
}
pub fn append_vertex(&mut self, mut vertex: Vec<u8>) -> Result<(), GPUError> {
if self.vertex_buffer_attributes_editable {
return Err(GPUError::EngineNotInitialized);
}
if !vertex.len() == self.vertex_size {
return Err(GPUError::ImproperVertexSize);
}
self.vertex_buffer.append(&mut vertex);
Ok(())
}
}

View file

@ -1,40 +0,0 @@
use super::{
color::Color3,
framebuffer::FrameBuffer,
types::{BufferID, Position2},
vertex::Vertex,
};
pub enum DrawCommand {
/// Copy one framebuffer onto another
UpdateFrame(UpdateFrameData),
Clear(Color3),
ClearBuffer(BufferID),
AppendVertex(BufferID, Vertex),
}
/// Offset framebuffer two by offset and place it onto framebuffer one
pub struct UpdateFrameData {
pub offset: Position2,
pub framebuffer_1: FrameBuffer,
pub framebuffer_2: FrameBuffer,
}
impl UpdateFrameData {
/// Run a few checks to make sure this is a sane action
pub fn sanity_check(&self) -> bool {
let size_check;
let mut x_offscreen = false;
let mut y_offscreen = false;
size_check = self.framebuffer_1.check_size(&self.framebuffer_2);
if self.offset.inner[0] > self.framebuffer_1.width as f32 {
x_offscreen = true
}
if self.offset.inner[1] > self.framebuffer_1.height as f32 {
y_offscreen = true
}
size_check && x_offscreen && y_offscreen
}
}

View file

@ -0,0 +1,4 @@
pub enum GPUError {
ImproperVertexSize = 10,
EngineNotInitialized = 100,
}

View file

@ -1,7 +1,5 @@
pub mod buffer;
pub mod color;
pub mod commands;
pub mod display;
pub mod error;
pub mod framebuffer;
pub mod types;
pub mod vertex;

View file

@ -1,12 +0,0 @@
pub type BufferID = u16;
pub struct Float3Array {
pub inner: [f32; 3],
}
pub struct Float2Array {
pub inner: [f32; 2],
}
pub type Position3 = Float3Array;
pub type Position2 = Float2Array;

View file

@ -1,18 +0,0 @@
use alloc::vec::Vec;
use super::{
color::Color3,
types::{Float2Array, Float3Array, Position3},
};
pub struct Vertex {
pub position: Position3,
pub normal: Float3Array,
pub color: Color3,
pub tex_coords: Float2Array,
}
pub struct VertexBuffer {
pub vertex_buffer: Vec<Vertex>,
}

View file

@ -1 +1,5 @@
function "local" "abcd"(i32, i32, i32) -> i64;
set_memory 0 "abcdefghijklmnopqrstuvwxyz";
set_memory 26 "hi";
set_memory 123 "hello";
function "local" "abcd"(i32, i32, i32) -> i64;

View file

@ -56,28 +56,37 @@ impl Function {
fn main() -> std::io::Result<()> {
use crate::ATypes::*;
if false {
let fil = include_str!("../assets/basic.axel");
// println!("{}", fil);
let fil = include_str!("../assets/basic.axel");
// println!("{}", fil);
let fun = Function::new(
"host".to_string(),
"name".to_string(),
vec![Num32],
vec![Num32],
);
let fun = Function::new(
"host".to_string(),
"name".to_string(),
vec![Num32],
vec![Num32],
);
let axel_out = format!("(module\n{}\n)", fun);
let axel_out = format!("(module\n{}\n)", fun);
let path = "main.wat";
let mut output = File::create(path).unwrap();
write!(output, "{}", axel_out)?;
let path = "main.wat";
let mut output = File::create(path).unwrap();
write!(output, "{}", axel_out)?;
let output = Command::new("wat2wasm")
.arg("main.wat")
.output()
.expect("Failed to execute command");
}
let output = Command::new("wat2wasm")
.arg("main.wat")
.output()
.expect("Failed to execute command");
//
//
Ok(())
}
use std::io::Write;
pub enum Tokens {
// set memory [0-9]+ "[a-zA-Z]+"
SetMemory(u64, String),
}

View file

@ -0,0 +1,9 @@
[package]
name = "system_config"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
toml = "0.7.3"

View file

@ -0,0 +1,56 @@
[boot]
[boot.limine]
default_entry = 1
timeout = 0
verbose = true
interface_resolution = "1024x768x24"
# Terminal related settings
term_wallpaper = "boot:///background.bmp"
term_background = "008080"
[boot.limine.ableos]
comment = "Default AbleOS boot entry."
protocol = "limine"
kernel_path = "boot:///kernel"
kernel_cmdline = "baka=true foobles=true"
resolution = "1024x768x24"
[repositories]
core = "https://git.ablecorp.us/AbleOS/core"
userspace = "https://git.ablecorp.us/AbleOS/ableos_userland"
[packages]
[packages.list_files]
version = "0.1.1"
hash = ""
repo = "userspace"
authors = []
[packages.list_files.configuration]
[users]
[users.able]
home = "/home/able/"
password_hash = "abc123"
[users.able.repositories]
able_repo = "https://git.ablecorp.us/able/ableos_packages"
[users.able.packages]
[users.able.packages.ablecraft]
version = "0.1.1"
hash = ""
repo = "able_repo"
[users.able.packages.ablecraft.configuration]
[users.able.packages.list_files.configuration]
use_color = true
[users.able.packages.list_files.permissions]
file_paths = ["/"]
[users.chad]
home = "/chad/"
password_hash = "abc123"
[users.chad.repositories]
[users.chad.packages]

View file

@ -0,0 +1,226 @@
use std::{
env,
error::Error,
fmt::format,
fs::{self, File},
io::{Read, Write},
path,
};
use toml::Table;
use toml::{self, Value};
fn main() -> Result<(), Box<dyn Error>> {
let mut args: Vec<String> = env::args().collect();
args.remove(0);
let file_path = &args[0];
println!("{}", file_path);
let mut file = File::open(file_path).expect("Unable to open the file");
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Unable to read the file");
let value = contents.parse::<Table>().unwrap();
fs::remove_dir_all("disk")?;
fs::create_dir("disk")?;
// HANDLE repolist
{
let repolist = value.get("repositories").unwrap();
let ret = make_repolist("repolist.toml".to_string(), repolist);
println!("making repolist {:?}", ret);
}
// HANDLE boot
{
let boot = value.get("boot").unwrap();
let boot_table = boot.as_table().unwrap();
if boot_table.contains_key("limine") {
let limine = boot_table.get("limine").unwrap();
let ret = make_limine_cfg(limine);
println!("limine return {:?}", ret);
}
// println!("{:#?}", boot);
}
// HANDLE users
{
let mut passhash_list: Vec<(String, String)> = vec![];
let users = value.get("users").unwrap();
// println!("{:?}", users.as_table().unwrap().keys());
let users_table = users.as_table().unwrap();
for user in users_table.keys() {
let ut = users_table.get(user).unwrap();
let home_path = ut.get("home").unwrap();
let pass_hash = ut.get("password_hash").unwrap();
passhash_list.push((user.to_string(), pass_hash.to_string()));
let ret = make_user(home_path.to_string());
println!("making user return {:?}", ret);
// Handle homepath generation of USER
{
let mut hp = home_path.clone().to_string();
hp.remove(0);
hp.remove(0);
hp.remove(hp.len() - 1);
hp.remove(hp.len() - 1);
for package in ut.get("packages").unwrap().as_table().unwrap().keys() {
let pack_folder: String = format!("disk/{}/{}", hp, package);
let pack_config: String = format!("disk/{}/{}/config.toml", hp, package);
fs::create_dir(pack_folder)?;
let mut file = File::create(pack_config)?;
// repo_list_str.as_bytes()
let abc = ut
.get("packages")
.unwrap()
.get(package)
.unwrap()
.get("configuration")
.unwrap();
let mut abc = abc.to_string();
if abc.len() > 2 {
abc.remove(0);
abc.remove(0);
abc.remove(abc.len() - 1);
abc.remove(abc.len() - 1);
}
if abc.len() == 2 {
abc.remove(0);
abc.remove(0);
}
file.write_all(abc.as_bytes())?;
}
}
{
let repolist = ut.get("repositories").unwrap();
let mut hp = home_path.clone().to_string();
hp.remove(0);
hp.remove(0);
hp.remove(hp.len() - 1);
hp.remove(hp.len() - 1);
let user_path_repolist = format!("{}/repolist.toml", hp.to_string());
println!("{}", user_path_repolist);
let ret = make_repolist(user_path_repolist, repolist);
println!("making repolist {:?}", ret);
}
}
let ret = generate_password_hashlist(passhash_list);
println!("making password hashlist {:?}", ret);
}
// let mut file = File::create("disk/foo.txt")?;
// file.write_all(b"Hello, world!")?;
Ok(())
}
pub fn make_limine_cfg(limine: &Value) -> std::io::Result<()> {
let mut limine_str = String::new();
// raw_limine
{
let mut lc = limine.clone();
let boot_entries = lc.as_table_mut().unwrap();
let default_entry = boot_entries.get("default_entry").unwrap();
let timeout = boot_entries.get("timeout").unwrap();
let interface_resolution = boot_entries.get("interface_resolution").unwrap();
let verbose = boot_entries.get("verbose").unwrap();
let term_wallpaper = boot_entries.get("term_wallpaper").unwrap();
let vb_post = match verbose.as_bool().unwrap() {
true => "yes",
false => "no",
};
let term_background = boot_entries
.get("term_backdrop")
.unwrap_or(&Value::Integer(0));
let base = format!(
"DEFAULT_ENTRY={}
TIMEOUT={}
VERBOSE={}
INTERFACE_RESOLUTION={}
# Terminal related settings
TERM_WALLPAPER={}
TERM_BACKDROP={}
",
default_entry, timeout, vb_post, interface_resolution, term_wallpaper, term_background
);
limine_str.push_str(&base);
}
// HANDLE boot_entries
{
let mut lc = limine.clone();
let boot_entries = lc.as_table_mut().unwrap();
let mut real_boot_entries = boot_entries.clone();
for (key, value) in boot_entries.into_iter() {
if !value.is_table() {
real_boot_entries.remove(key);
}
}
for (name, value) in real_boot_entries {
let comment = value.get("comment").unwrap();
let protocol = value.get("protocol").unwrap();
let resolution = value.get("resolution").unwrap();
let kernel_path = value.get("kernel_path").unwrap();
let kernel_cmdline = value.get("kernel_cmdline").unwrap();
let entry = format!(
"
:{}
COMMENT={}
PROTOCOL={}
RESOLUTION={}
KERNEL_PATH={}
KERNEL_CMDLINE={}
",
name, comment, protocol, resolution, kernel_path, kernel_cmdline,
);
limine_str.push_str(&entry);
}
}
let mut file = File::create("disk/limine.cfg")?;
file.write_all(limine_str.as_bytes())?;
Ok(())
}
pub fn make_user(mut home_path: String) -> std::io::Result<()> {
home_path.remove(0);
home_path.remove(home_path.len() - 1);
let path = format!("disk/{}", home_path);
fs::create_dir_all(path)?;
Ok(())
}
pub fn make_repolist(path: String, repolist: &Value) -> std::io::Result<()> {
let path = format!("disk/{}", path);
let mut file = File::create(path)?;
let mut repo_list_str = String::new();
for (repo_name, repo_url) in repolist.as_table().unwrap() {
let entry = format!("{} = {}\n", repo_name, repo_url);
repo_list_str.push_str(&entry);
}
file.write_all(repo_list_str.as_bytes())?;
Ok(())
}
pub fn generate_password_hashlist(passhash_list: Vec<(String, String)>) -> std::io::Result<()> {
let mut file = File::create("disk/passwords.toml")?;
let mut file_cont = String::new();
for (user, hash) in passhash_list {
let ret = format!("{}={}\n", user, hash);
file_cont.push_str(&ret);
}
file.write_all(file_cont.as_bytes())?;
Ok(())
}