summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaindropsSys <raindrops@equestria.dev>2023-12-02 16:02:58 +0100
committerRaindropsSys <raindrops@equestria.dev>2023-12-02 16:02:58 +0100
commitd5aa820492349ee62eac26f0408ea09e13709386 (patch)
treefdce32edb936a138e9ae2736c1ed2f6f98e8f399
parentac3c8079a1205ed8bc3e6b1f1bad2e575c444ebb (diff)
downloadcometos-d5aa820492349ee62eac26f0408ea09e13709386.tar.gz
cometos-d5aa820492349ee62eac26f0408ea09e13709386.tar.bz2
cometos-d5aa820492349ee62eac26f0408ea09e13709386.zip
Updated 24 files, added 17 files and renamed 2 files (automated)
-rw-r--r--.DS_Storebin10244 -> 10244 bytes
-rw-r--r--.cargo/config.toml2
-rw-r--r--.idea/cutieos.iml2
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml3
-rw-r--r--commands/.DS_Storebin0 -> 6148 bytes
-rw-r--r--commands/Cargo.toml3
-rw-r--r--commands/src/append.rs22
-rw-r--r--commands/src/appendln.rs22
-rw-r--r--commands/src/cat.rs30
-rw-r--r--commands/src/cd.rs66
-rw-r--r--commands/src/clear.rs6
-rw-r--r--commands/src/debug.rs13
-rw-r--r--commands/src/lib.rs49
-rw-r--r--commands/src/ls.rs14
-rw-r--r--commands/src/mkdir.rs19
-rw-r--r--commands/src/parser.rs102
-rw-r--r--commands/src/path.rs14
-rw-r--r--commands/src/pwd.rs3
-rw-r--r--commands/src/reboot.rs3
-rw-r--r--commands/src/rm.rs23
-rw-r--r--commands/src/rmdir.rs31
-rw-r--r--commands/src/shutdown.rs3
-rw-r--r--commands/src/touch.rs32
-rw-r--r--commands/src/ver.rs32
-rw-r--r--esp/.DS_Storebin10244 -> 10244 bytes
-rw-r--r--esp/CutieOS/test.txt1
-rw-r--r--esp/efi/.DS_Storebin8196 -> 8196 bytes
-rwxr-xr-xesp/efi/boot/bootaa64.efibin0 -> 295936 bytes
-rwxr-xr-xesp/efi/boot/bootx64.efibin222720 -> 336384 bytes
-rw-r--r--firmware/AAVMF_CODE.fdbin0 -> 67108864 bytes
-rw-r--r--firmware/AAVMF_VARS.fdbin0 -> 67108864 bytes
-rw-r--r--firmware/OVMF_CODE.fd (renamed from OVMF_CODE.fd)bin3653632 -> 3653632 bytes
-rw-r--r--firmware/OVMF_VARS.fd (renamed from OVMF_VARS.fd)bin540672 -> 540672 bytes
-rw-r--r--src/boot.rs6
-rw-r--r--src/main.rs6
-rw-r--r--toolkit/.DS_Storebin6148 -> 6148 bytes
-rw-r--r--toolkit/Cargo.toml3
-rw-r--r--toolkit/src/error.rs24
-rw-r--r--toolkit/src/lib.rs125
-rw-r--r--userland/.DS_Storebin6148 -> 8196 bytes
-rw-r--r--userland/Cargo.toml3
-rw-r--r--userland/src/lib.rs61
43 files changed, 574 insertions, 153 deletions
diff --git a/.DS_Store b/.DS_Store
index 7a765ca..15d2ae1 100644
--- a/.DS_Store
+++ b/.DS_Store
Binary files differ
diff --git a/.cargo/config.toml b/.cargo/config.toml
new file mode 100644
index 0000000..b781ff7
--- /dev/null
+++ b/.cargo/config.toml
@@ -0,0 +1,2 @@
+[build]
+target = ["x86_64-unknown-uefi", "aarch64-unknown-uefi"] \ No newline at end of file
diff --git a/.idea/cutieos.iml b/.idea/cutieos.iml
index a58fa76..ec6116c 100644
--- a/.idea/cutieos.iml
+++ b/.idea/cutieos.iml
@@ -6,6 +6,8 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/toolkit/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/userland/src" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/graphics/src" isTestSource="false" />
+ <excludeFolder url="file://$MODULE_DIR$/esp" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
diff --git a/Cargo.lock b/Cargo.lock
index 04d0280..2e8bfb7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -191,7 +191,6 @@ version = "0.1.0"
dependencies = [
"build-info",
"build-info-build",
- "log",
"toolkit",
"uefi",
"uefi-services",
@@ -216,7 +215,6 @@ dependencies = [
"build-info",
"build-info-build",
"commands",
- "log",
"toolkit",
"uefi",
"uefi-services",
@@ -601,7 +599,6 @@ version = "0.1.0"
dependencies = [
"build-info",
"build-info-build",
- "log",
"uefi",
"uefi-services",
]
@@ -708,7 +705,6 @@ dependencies = [
"build-info",
"build-info-build",
"commands",
- "log",
"toolkit",
"uefi",
"uefi-services",
diff --git a/Cargo.toml b/Cargo.toml
index be4fe11..ac454ac 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,9 +8,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-log = "0.4.20"
uefi = { version = "0.26.0", features = ["alloc"] }
-uefi-services = { version = "0.23.0", features = ["logger"], default-features = false }
+uefi-services = { version = "0.23.0", features = [], default-features = false }
build-info = { version = "0.0.34", features = [], default-features = false }
userland = { path = "userland" }
toolkit = { path = "toolkit" }
diff --git a/commands/.DS_Store b/commands/.DS_Store
new file mode 100644
index 0000000..8333c1e
--- /dev/null
+++ b/commands/.DS_Store
Binary files differ
diff --git a/commands/Cargo.toml b/commands/Cargo.toml
index 330bb6d..476f3e5 100644
--- a/commands/Cargo.toml
+++ b/commands/Cargo.toml
@@ -6,9 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-log = "0.4.20"
uefi = { version = "0.26.0", features = ["alloc"] }
-uefi-services = { version = "0.23.0", features = ["logger"], default-features = false }
+uefi-services = { version = "0.23.0", features = [], default-features = false }
build-info = { version = "0.0.34", features = [], default-features = false }
toolkit = { path = "../toolkit" }
diff --git a/commands/src/append.rs b/commands/src/append.rs
new file mode 100644
index 0000000..24c0d51
--- /dev/null
+++ b/commands/src/append.rs
@@ -0,0 +1,22 @@
+use alloc::format;
+use toolkit::Toolkit;
+use toolkit::error::*;
+use crate::parser::Command;
+
+pub fn run(mut tk: &mut Toolkit, command: Command) {
+ if command.names.len() == 2 {
+ let path = tk.resolve_path(&command.names[0]);
+ match tk.read_file(&path) {
+ None => {
+ display_error(&mut tk, Error::E13);
+ }
+ Some(str) => {
+ tk.write_file(&path, &format!("{}{}", str, &command.names[1]));
+ }
+ }
+ } else if command.names.len() == 0 {
+ display_error(&mut tk, Error::E03);
+ } else if command.names.len() > 1 {
+ display_error(&mut tk, Error::E08);
+ }
+} \ No newline at end of file
diff --git a/commands/src/appendln.rs b/commands/src/appendln.rs
new file mode 100644
index 0000000..58da0d1
--- /dev/null
+++ b/commands/src/appendln.rs
@@ -0,0 +1,22 @@
+use alloc::format;
+use toolkit::Toolkit;
+use toolkit::error::*;
+use crate::parser::Command;
+
+pub fn run(mut tk: &mut Toolkit, command: Command) {
+ if command.names.len() == 2 {
+ let path = tk.resolve_path(&command.names[0]);
+ match tk.read_file(&path) {
+ None => {
+ display_error(&mut tk, Error::E13);
+ }
+ Some(str) => {
+ tk.write_file(&path, &format!("{}\n{}", str, &command.names[1]));
+ }
+ }
+ } else if command.names.len() == 0 {
+ display_error(&mut tk, Error::E03);
+ } else if command.names.len() > 1 {
+ display_error(&mut tk, Error::E08);
+ }
+} \ No newline at end of file
diff --git a/commands/src/cat.rs b/commands/src/cat.rs
new file mode 100644
index 0000000..7590266
--- /dev/null
+++ b/commands/src/cat.rs
@@ -0,0 +1,30 @@
+use toolkit::Toolkit;
+use toolkit::error::*;
+use crate::parser::Command;
+
+pub fn run(mut tk: &mut Toolkit, command: Command) {
+ if command.names.len() == 1 {
+ let path = tk.resolve_path(&command.names[0]);
+
+ if tk.file_exists(&path) {
+ if tk.is_file(&path) {
+ match tk.read_file(&path) {
+ None => {
+ display_error(&mut tk, Error::E13);
+ }
+ Some(str) => {
+ tk.println(&str.replace("\n", "\r\n").replace("\r\r\n", "\r\n"));
+ }
+ }
+ } else {
+ display_error(&mut tk, Error::E12);
+ }
+ } else {
+ display_error(&mut tk, Error::E04);
+ }
+ } else if command.names.len() == 0 {
+ display_error(&mut tk, Error::E03);
+ } else if command.names.len() > 1 {
+ display_error(&mut tk, Error::E08);
+ }
+} \ No newline at end of file
diff --git a/commands/src/cd.rs b/commands/src/cd.rs
index 3ccd502..6b12e5b 100644
--- a/commands/src/cd.rs
+++ b/commands/src/cd.rs
@@ -1,61 +1,25 @@
-use alloc::{format, vec};
-use alloc::borrow::ToOwned;
-use alloc::string::ToString;
-use uefi::CStr16;
-use uefi::fs::Path;
use toolkit::Toolkit;
use toolkit::error::*;
+use crate::parser::Command;
-pub fn run(mut tk: &mut Toolkit, text: &str) {
- if text.starts_with("cd ") && text.len() > 3 {
- let path = &text[3..].replace("/", "\\");
- let mut buf = vec![0; path.len() + 1];
- let cstr = CStr16::from_str_with_buf(path, &mut buf).unwrap();
- let path = Path::new(cstr);
- let mut first = true;
+pub fn run(mut tk: &mut Toolkit, command: Command) {
+ if command.names.len() == 1 {
+ let path = tk.resolve_path(&command.names[0]);
- for i in path.components() {
- if text[3..].starts_with("/") && first {
- first = false;
-
- if tk.file_exists(&i.to_string()) {
- tk.chdir(&i.to_string());
- return;
- } else {
- display_error(&mut tk, Error::E04);
- }
- } else if tk.get_cwd() == "/" && i.to_string() == ".." {
- display_error(&mut tk, Error::E05);
- return;
- } else if i.to_string() == "" || tk.get_cwd() == "/" {
- if tk.file_exists(&i.to_string()) {
- tk.chdir(&i.to_string());
- return;
- } else {
- display_error(&mut tk, Error::E04);
- }
- } else if i.to_string() == ".." {
- let cwd = &tk.get_cwd().replace("/", "\\");
- let mut buf = vec![0; cwd.len() + 1];
- let cstr = CStr16::from_str_with_buf(cwd, &mut buf).unwrap();
- let path = Path::new(cstr);
- tk.chdir(&path.parent().unwrap().to_cstr16().to_string());
- return;
+ if tk.file_exists(&path) {
+ if tk.is_dir(&path) {
+ tk.chdir(&path);
} else {
- let cwd = (&tk.get_cwd()[1..]).to_owned();
-
- if tk.file_exists(&format!("{}\\{}", cwd, i)) {
- tk.chdir(&format!("{}\\{}", cwd, i));
- return;
- } else {
- display_error(&mut tk, Error::E04);
- }
+ display_error(&mut tk, Error::E09);
}
- }
- return;
- } else {
+ return;
+ } else {
+ display_error(&mut tk, Error::E04);
+ }
+ } else if command.names.len() == 0 {
display_error(&mut tk, Error::E03);
- return;
+ } else if command.names.len() > 1 {
+ display_error(&mut tk, Error::E08);
}
} \ No newline at end of file
diff --git a/commands/src/clear.rs b/commands/src/clear.rs
new file mode 100644
index 0000000..88c152d
--- /dev/null
+++ b/commands/src/clear.rs
@@ -0,0 +1,6 @@
+use toolkit::Toolkit;
+use crate::parser::Command;
+
+pub fn run(tk: &mut Toolkit, _command: Command) {
+ tk.clear();
+} \ No newline at end of file
diff --git a/commands/src/debug.rs b/commands/src/debug.rs
new file mode 100644
index 0000000..ed80d90
--- /dev/null
+++ b/commands/src/debug.rs
@@ -0,0 +1,13 @@
+use alloc::string::String;
+use toolkit::Toolkit;
+use crate::parser::Command;
+
+pub fn run(tk: &mut Toolkit, _command: Command) {
+ if tk.globals.contains_key("debug") && tk.globals.get("debug").unwrap() == "1" {
+ tk.globals.insert(String::from("debug"), String::from("0"));
+ tk.println("Shell debugging is now OFF.\r\n");
+ } else {
+ tk.globals.insert(String::from("debug"), String::from("1"));
+ tk.println("Shell debugging is now ON.\r\n");
+ }
+} \ No newline at end of file
diff --git a/commands/src/lib.rs b/commands/src/lib.rs
index ae68a7a..bcc0a12 100644
--- a/commands/src/lib.rs
+++ b/commands/src/lib.rs
@@ -1,36 +1,21 @@
#![no_std]
-mod ver;
-mod pwd;
-mod ls;
-mod shutdown;
-mod reboot;
-mod cd;
-
extern crate alloc;
-use toolkit::*;
-
-pub fn ver(tk: &mut Toolkit, arguments: &str) {
- ver::run(tk, arguments);
-}
-
-pub fn pwd(tk: &mut Toolkit, arguments: &str) {
- pwd::run(tk, arguments);
-}
-
-pub fn ls(tk: &mut Toolkit, arguments: &str) {
- ls::run(tk, arguments);
-}
-
-pub fn shutdown(tk: &mut Toolkit, arguments: &str) {
- shutdown::run(tk, arguments);
-}
-
-pub fn reboot(tk: &mut Toolkit, arguments: &str) {
- reboot::run(tk, arguments);
-}
-
-pub fn cd(tk: &mut Toolkit, arguments: &str) {
- cd::run(tk, arguments);
-} \ No newline at end of file
+pub mod ver;
+pub mod pwd;
+pub mod ls;
+pub mod shutdown;
+pub mod reboot;
+pub mod cd;
+pub mod parser;
+pub mod debug;
+pub mod mkdir;
+pub mod rmdir;
+pub mod path;
+pub mod cat;
+pub mod append;
+pub mod clear;
+pub mod appendln;
+pub mod rm;
+pub mod touch; \ No newline at end of file
diff --git a/commands/src/ls.rs b/commands/src/ls.rs
index 4ecf596..7c0464c 100644
--- a/commands/src/ls.rs
+++ b/commands/src/ls.rs
@@ -2,10 +2,20 @@ use alloc::format;
use alloc::string::{String, ToString};
use uefi::proto::console::text::Color;
use uefi::proto::media::file::FileAttribute;
+use toolkit::error::{display_error, Error};
use toolkit::Toolkit;
+use crate::parser::Command;
-pub fn run(tk: &mut Toolkit, _arguments: &str) {
- let result = tk.scandir(&format!("{}", tk.get_cwd().replace("/", "\\")));
+pub fn run(mut tk: &mut Toolkit, command: Command) {
+ let mut path = tk.get_cwd().replace("/", "\\");
+
+ if command.names.len() == 1 {
+ path = tk.resolve_path(&command.names[0]);
+ } else if command.names.len() > 1 {
+ display_error(&mut tk, Error::E08);
+ }
+
+ let result = tk.scandir(&format!("{}", path));
tk.color(Color::Cyan, Color::Black);
tk.print("\nAttrib");
tk.color(Color::Yellow, Color::Black);
diff --git a/commands/src/mkdir.rs b/commands/src/mkdir.rs
new file mode 100644
index 0000000..f56236f
--- /dev/null
+++ b/commands/src/mkdir.rs
@@ -0,0 +1,19 @@
+use toolkit::Toolkit;
+use toolkit::error::*;
+use crate::parser::Command;
+
+pub fn run(mut tk: &mut Toolkit, command: Command) {
+ if command.names.len() == 1 {
+ let path = tk.resolve_path(&command.names[0]);
+
+ if !tk.file_exists(&path) {
+ tk.mkdir(&path);
+ } else {
+ display_error(&mut tk, Error::E10);
+ }
+ } else if command.names.len() == 0 {
+ display_error(&mut tk, Error::E03);
+ } else if command.names.len() > 1 {
+ display_error(&mut tk, Error::E08);
+ }
+} \ No newline at end of file
diff --git a/commands/src/parser.rs b/commands/src/parser.rs
new file mode 100644
index 0000000..023d602
--- /dev/null
+++ b/commands/src/parser.rs
@@ -0,0 +1,102 @@
+use alloc::collections::BTreeMap;
+use alloc::string::{String, ToString};
+use alloc::vec::Vec;
+
+#[derive(Debug)]
+pub struct Command {
+ pub command: String,
+ pub args: BTreeMap<String, CommandArgument>,
+ pub names: Vec<String>
+}
+
+#[derive(Debug)]
+pub enum CommandArgument {
+ Anonymous,
+ Value(String)
+}
+
+#[derive(Debug)]
+pub enum CommandError {
+ ExecutablePathNotFound,
+ MismatchedQuotes
+}
+
+impl Command {
+ pub fn from_str(input: &str) -> Result<Self, CommandError> {
+ let mut in_double_quotes = false;
+ let mut in_single_quotes = false;
+ let mut escaping = false;
+
+ let input = input.trim();
+ let input_split = input.split(|char| match char {
+ '"' if !in_single_quotes && !escaping => {
+ in_double_quotes = !in_double_quotes;
+ false
+ }
+ '\'' if !in_double_quotes && !escaping => {
+ in_single_quotes = !in_single_quotes;
+ false
+ }
+ '\\' if !escaping => {
+ escaping = true;
+ false
+ },
+ ' ' => !in_double_quotes && !in_single_quotes,
+ _ => {
+ escaping = false;
+ false
+ },
+ });
+
+ let mut parsed = input_split.map(|split| {
+ match split.chars().next().unwrap() {
+ '\'' | '"' => {
+ let end = split.len() - 1;
+ split[1..end].replace("\\n", "\n").replace("\\t", "\t").replace("\\r", "\r").replace('\\', "")
+ }
+ _ => split.replace("\\n", "\n").replace("\\t", "\t").replace("\\r", "\r").replace('\\', "")
+ }
+ });
+ let command = parsed.next().ok_or(CommandError::ExecutablePathNotFound)?;
+ let args: Vec<String> = parsed.collect();
+
+ if in_double_quotes || in_single_quotes {
+ return Err(CommandError::MismatchedQuotes);
+ }
+
+ let mut command_args: BTreeMap<String, CommandArgument> = BTreeMap::new();
+ let mut names: Vec<String> = Vec::new();
+
+ for arg in args.iter() {
+ if arg.starts_with("--") {
+ if arg.contains("=") {
+ let parts: Vec<&str> = arg.split("=").collect();
+ let mut value: &str = parts[1];
+
+ if value.starts_with('"') || value.starts_with("'") {
+ let len = value.len() - 1;
+ value = &value[1..len];
+ }
+
+ command_args.insert(parts[0][2..].parse().unwrap(), CommandArgument::Value(String::from(value)));
+ } else {
+ command_args.insert(arg[2..].parse().unwrap(), CommandArgument::Anonymous);
+ }
+ } else if arg.starts_with("-") {
+ let chars: String = arg[1..].parse().unwrap();
+
+ for i in chars.chars() {
+ command_args.insert(i.to_string(), CommandArgument::Anonymous);
+ }
+ } else {
+ names.push(arg.parse().unwrap());
+ }
+ }
+
+ Ok(Command {
+ command,
+ args: command_args,
+ names
+ })
+ }
+} \ No newline at end of file
diff --git a/commands/src/path.rs b/commands/src/path.rs
new file mode 100644
index 0000000..5ba0a9e
--- /dev/null
+++ b/commands/src/path.rs
@@ -0,0 +1,14 @@
+use alloc::format;
+use toolkit::Toolkit;
+use toolkit::error::*;
+use crate::parser::Command;
+
+pub fn run(mut tk: &mut Toolkit, command: Command) {
+ if command.names.len() == 1 {
+ tk.println(&format!("{}\n", tk.resolve_path(&command.names[0])));
+ } else if command.names.len() == 0 {
+ display_error(&mut tk, Error::E03);
+ } else if command.names.len() > 1 {
+ display_error(&mut tk, Error::E08);
+ }
+} \ No newline at end of file
diff --git a/commands/src/pwd.rs b/commands/src/pwd.rs
index 73313f4..2a56129 100644
--- a/commands/src/pwd.rs
+++ b/commands/src/pwd.rs
@@ -1,7 +1,8 @@
use alloc::string::ToString;
use toolkit::Toolkit;
+use crate::parser::Command;
-pub fn run(tk: &mut Toolkit, _arguments: &str) {
+pub fn run(tk: &mut Toolkit, _command: Command) {
let cwd = tk.get_cwd().to_string();
tk.println(&cwd);
tk.println("");
diff --git a/commands/src/reboot.rs b/commands/src/reboot.rs
index 1cf8eaf..317d9d2 100644
--- a/commands/src/reboot.rs
+++ b/commands/src/reboot.rs
@@ -1,6 +1,7 @@
use toolkit::Toolkit;
+use crate::parser::Command;
-pub fn run(tk: &mut Toolkit, _arguments: &str) {
+pub fn run(tk: &mut Toolkit, _command: Command) {
tk.clear();
tk.poweroff(true);
} \ No newline at end of file
diff --git a/commands/src/rm.rs b/commands/src/rm.rs
new file mode 100644
index 0000000..ae1a05c
--- /dev/null
+++ b/commands/src/rm.rs
@@ -0,0 +1,23 @@
+use toolkit::Toolkit;
+use toolkit::error::*;
+use crate::parser::Command;
+
+pub fn run(mut tk: &mut Toolkit, command: Command) {
+ if command.names.len() == 1 {
+ let path = tk.resolve_path(&command.names[0]);
+
+ if tk.file_exists(&path) {
+ if !tk.is_dir(&path) {
+ tk.unlink(&path);
+ } else {
+ display_error(&mut tk, Error::E12);
+ }
+ } else {
+ display_error(&mut tk, Error::E04);
+ }
+ } else if command.names.len() == 0 {
+ display_error(&mut tk, Error::E03);
+ } else if command.names.len() > 1 {
+ display_error(&mut tk, Error::E08);
+ }
+} \ No newline at end of file
diff --git a/commands/src/rmdir.rs b/commands/src/rmdir.rs
new file mode 100644
index 0000000..d9d20e2
--- /dev/null
+++ b/commands/src/rmdir.rs
@@ -0,0 +1,31 @@
+use toolkit::Toolkit;
+use toolkit::error::*;
+use crate::parser::Command;
+
+pub fn run(mut tk: &mut Toolkit, command: Command) {
+ if command.names.len() == 1 {
+ let path = tk.resolve_path(&command.names[0]);
+
+ if tk.file_exists(&path) {
+ if tk.is_dir(&path) {
+ if tk.scandir(&path).count() == 2 || command.args.contains_key("r") || command.args.contains_key("recursive") {
+ if command.args.contains_key("r") || command.args.contains_key("recursive") {
+ tk.recursive_rmdir(&path);
+ } else {
+ tk.rmdir(&path);
+ }
+ } else {
+ display_error(&mut tk, Error::E11);
+ }
+ } else {
+ display_error(&mut tk, Error::E09);
+ }
+ } else {
+ display_error(&mut tk, Error::E04);
+ }
+ } else if command.names.len() == 0 {
+ display_error(&mut tk, Error::E03);
+ } else if command.names.len() > 1 {
+ display_error(&mut tk, Error::E08);
+ }
+} \ No newline at end of file
diff --git a/commands/src/shutdown.rs b/commands/src/shutdown.rs
index 7c4daf6..969aa25 100644
--- a/commands/src/shutdown.rs
+++ b/commands/src/shutdown.rs
@@ -1,6 +1,7 @@
use toolkit::Toolkit;
+use crate::parser::Command;
-pub fn run(tk: &mut Toolkit, _arguments: &str) {
+pub fn run(tk: &mut Toolkit, _command: Command) {
tk.clear();
tk.poweroff(false);
} \ No newline at end of file
diff --git a/commands/src/touch.rs b/commands/src/touch.rs
new file mode 100644
index 0000000..723ffc3
--- /dev/null
+++ b/commands/src/touch.rs
@@ -0,0 +1,32 @@
+use alloc::string::String;
+use toolkit::Toolkit;
+use toolkit::error::*;
+use crate::parser::Command;
+
+pub fn run(mut tk: &mut Toolkit, command: Command) {
+ if command.names.len() == 1 {
+ let path = tk.resolve_path(&command.names[0]);
+ let mut original = String::from("");
+
+ if tk.file_exists(&path) {
+ if !tk.is_dir(&path) {
+ match tk.read_file(&path) {
+ None => {
+ display_error(&mut tk, Error::E13);
+ }
+ Some(str) => {
+ original = str;
+ }
+ }
+ } else {
+ display_error(&mut tk, Error::E12);
+ }
+ }
+
+ tk.write_file(&path, &original);
+ } else if command.names.len() == 0 {
+ display_error(&mut tk, Error::E03);
+ } else if command.names.len() > 1 {
+ display_error(&mut tk, Error::E08);
+ }
+} \ No newline at end of file
diff --git a/commands/src/ver.rs b/commands/src/ver.rs
index c6376fd..8134028 100644
--- a/commands/src/ver.rs
+++ b/commands/src/ver.rs
@@ -1,7 +1,33 @@
use alloc::format;
+use uefi::proto::console::text::Color;
use toolkit::Toolkit;
+use crate::parser::Command;
-pub fn run(tk: &mut Toolkit, _arguments: &str) {
- tk.println(&format!("CutieOS {} ({}, {})", tk.version.version, tk.version.timestamp, tk.version.compiler));
- tk.println("");
+pub fn run(tk: &mut Toolkit, _command: Command) {
+ tk.color(Color::Cyan, Color::Black);
+ tk.print("\r\n OS name: ");
+ tk.color(Color::LightGray, Color::Black);
+ tk.print("CutieOS");
+
+ tk.color(Color::Cyan, Color::Black);
+ tk.print("\r\n OS version: ");
+ tk.color(Color::LightGray, Color::Black);
+ tk.print(&format!("{}", tk.version.version));
+
+ tk.color(Color::Cyan, Color::Black);
+ tk.print("\r\n Build timestamp: ");
+ tk.color(Color::LightGray, Color::Black);
+ tk.print(&format!("{}", tk.version.timestamp));
+
+ tk.color(Color::Cyan, Color::Black);
+ tk.print("\r\n Build compiler: ");
+ tk.color(Color::LightGray, Color::Black);
+ tk.print(&format!("{}", tk.version.compiler));
+
+ tk.color(Color::Cyan, Color::Black);
+ tk.print("\r\nCompiler profile: ");
+ tk.color(Color::LightGray, Color::Black);
+ tk.print(&format!("{}", tk.version.profile));
+
+ tk.println("\r\n");
} \ No newline at end of file
diff --git a/esp/.DS_Store b/esp/.DS_Store
index 523cd92..d9aacba 100644
--- a/esp/.DS_Store
+++ b/esp/.DS_Store
Binary files differ
diff --git a/esp/CutieOS/test.txt b/esp/CutieOS/test.txt
new file mode 100644
index 0000000..6769dd6
--- /dev/null
+++ b/esp/CutieOS/test.txt
@@ -0,0 +1 @@
+Hello world! \ No newline at end of file
diff --git a/esp/efi/.DS_Store b/esp/efi/.DS_Store
index c7a33d0..c48ba00 100644
--- a/esp/efi/.DS_Store
+++ b/esp/efi/.DS_Store
Binary files differ
diff --git a/esp/efi/boot/bootaa64.efi b/esp/efi/boot/bootaa64.efi
new file mode 100755
index 0000000..1fdc814
--- /dev/null
+++ b/esp/efi/boot/bootaa64.efi
Binary files differ
diff --git a/esp/efi/boot/bootx64.efi b/esp/efi/boot/bootx64.efi
index 8a2dc1a..fe7e088 100755
--- a/esp/efi/boot/bootx64.efi
+++ b/esp/efi/boot/bootx64.efi
Binary files differ
diff --git a/firmware/AAVMF_CODE.fd b/firmware/AAVMF_CODE.fd
new file mode 100644
index 0000000..9e23642
--- /dev/null
+++ b/firmware/AAVMF_CODE.fd
Binary files differ
diff --git a/firmware/AAVMF_VARS.fd b/firmware/AAVMF_VARS.fd
new file mode 100644
index 0000000..51c513d
--- /dev/null
+++ b/firmware/AAVMF_VARS.fd
Binary files differ
diff --git a/OVMF_CODE.fd b/firmware/OVMF_CODE.fd
index 1c3d46f..1c3d46f 100644
--- a/OVMF_CODE.fd
+++ b/firmware/OVMF_CODE.fd
Binary files differ
diff --git a/OVMF_VARS.fd b/firmware/OVMF_VARS.fd
index efb4f46..efb4f46 100644
--- a/OVMF_VARS.fd
+++ b/firmware/OVMF_VARS.fd
Binary files differ
diff --git a/src/boot.rs b/src/boot.rs
index 564b6a3..f954a0b 100644
--- a/src/boot.rs
+++ b/src/boot.rs
@@ -1,19 +1,13 @@
-use log::info;
use userland::run_shell;
use toolkit::Toolkit;
pub fn start_boot(mut tk: Toolkit) {
- info!("Welcome to CutieOS!");
- info!("Disabling boot watchdog");
tk.disable_watchdog();
- info!("Checking for system directory");
if !tk.file_exists("CutieOS") {
tk.mkdir("CutieOS");
}
tk.chdir("CutieOS");
- info!("Handing over control to the userland");
-
run_shell(tk);
} \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 1112428..8834f0f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -18,7 +18,8 @@ fn main(_image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
let version = ToolkitVersionInfo {
version: build_info::format!("{}", $.crate_info.version),
timestamp: build_info::format!("{}", $.timestamp),
- compiler: build_info::format!("{}", $.compiler)
+ compiler: build_info::format!("{}", $.compiler),
+ profile: build_info::format!("{}/{}", $.profile, $.target)
};
unsafe { init_panic(system_table.unsafe_clone()); }
@@ -27,7 +28,8 @@ fn main(_image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
tk.clear();
tk.color(Color::Cyan, Color::Black);
- tk.println(&format!("CutieOS {} ({}, {})", tk.version.version, tk.version.timestamp, tk.version.compiler));
+ tk.println(&format!("CutieOS {} ({})", tk.version.version, tk.version.timestamp, ));
+ tk.println(&format!("{}, {}", tk.version.compiler, tk.version.profile));
let uefi = tk.uefi_version();
let vendor = tk.uefi_vendor();
diff --git a/toolkit/.DS_Store b/toolkit/.DS_Store
index eee283d..b7cc4e5 100644
--- a/toolkit/.DS_Store
+++ b/toolkit/.DS_Store
Binary files differ
diff --git a/toolkit/Cargo.toml b/toolkit/Cargo.toml
index 19c0c62..216ed08 100644
--- a/toolkit/Cargo.toml
+++ b/toolkit/Cargo.toml
@@ -6,9 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-log = "0.4.20"
uefi = { version = "0.26.0", features = ["alloc"] }
-uefi-services = { version = "0.23.0", features = ["logger"], default-features = false }
+uefi-services = { version = "0.23.0", features = [], default-features = false }
build-info = { version = "0.0.34", features = [], default-features = false }
[build-dependencies]
diff --git a/toolkit/src/error.rs b/toolkit/src/error.rs
index 823dcd6..db5c313 100644
--- a/toolkit/src/error.rs
+++ b/toolkit/src/error.rs
@@ -4,21 +4,37 @@ use crate::Toolkit;
#[derive(Copy, Clone)]
pub enum Error {
- //E01,
+ E01,
E02,
E03,
E04,
- E05
+ E05,
+ E06,
+ E07,
+ E08,
+ E09,
+ E10,
+ E11,
+ E12,
+ E13
}
impl Error {
fn description(&self) -> &str {
match self {
- //Error::E01 => "An internal undocumented system error has occurred.",
+ Error::E01 => "An internal undocumented system error has occurred.",
Error::E02 => "The requested command could not be found.",
- Error::E03 => "A required paramater for this command was not provided.",
+ Error::E03 => "Too few arguments were provided to this command.",
Error::E04 => "The requested file or directory could not be found.",
Error::E05 => "Unable to go up one level from the root directory.",
+ Error::E06 => "No command name could be found in the input.",
+ Error::E07 => "Unexpected end of line: quotes do not match.",
+ Error::E08 => "Too many arguments were provided to this command.",
+ Error::E09 => "The requested file is not a directory.",
+ Error::E10 => "The requested file already exists.",
+ Error::E11 => "The directory to affect is not empty.",
+ Error::E12 => "The requested file is a directory.",
+ Error::E13 => "Input/output error occurred while reading the file."
//_ => "Unknown error."
}
}
diff --git a/toolkit/src/lib.rs b/toolkit/src/lib.rs
index d0d64bb..b083cac 100644
--- a/toolkit/src/lib.rs
+++ b/toolkit/src/lib.rs
@@ -4,6 +4,7 @@ extern crate alloc;
use alloc::string::{String, ToString};
use alloc::{format, vec};
+use alloc::collections::BTreeMap;
use alloc::vec::Vec;
use uefi::{Char16, CStr16};
use uefi::prelude::*;
@@ -23,13 +24,15 @@ pub struct ToolkitWorkingPath {
pub struct ToolkitVersionInfo {
pub version: &'static str,
pub timestamp: &'static str,
- pub compiler: &'static str
+ pub compiler: &'static str,
+ pub profile: &'static str
}
pub struct Toolkit {
system_table: SystemTable<Boot>,
pub current_directory: ToolkitWorkingPath,
- pub version: ToolkitVersionInfo
+ pub version: ToolkitVersionInfo,
+ pub globals: BTreeMap<String, String>
}
impl Toolkit {
@@ -51,12 +54,19 @@ impl Toolkit {
current_directory: ToolkitWorkingPath {
name: String::from("")
},
- version
+ version,
+ globals: BTreeMap::new()
}
}
}
impl Toolkit {
+ fn get_fs(&self) -> FileSystem {
+ let handle = self.system_table.boot_services().image_handle();
+ let fs = self.system_table.boot_services().get_image_file_system(handle).expect("Failed to start up filesystem");
+ FileSystem::new(fs)
+ }
+
pub fn color(&mut self, fg: Color, bg: Color) {
self.system_table.stdout().set_color(fg, bg).expect("Failed to set screen color");
}
@@ -120,10 +130,6 @@ impl Toolkit {
stdout.reset(false).expect("Failed to clear screen buffer");
}
- /*pub fn sleep(&mut self, time: usize) {
- self.system_table.boot_services().stall(time * 1000);
- }*/
-
pub fn get_cwd(&self) -> &str {
&self.current_directory.name
}
@@ -179,9 +185,7 @@ impl Toolkit {
if path == "" {
return true;
}
- let handle = self.system_table.boot_services().image_handle();
- let fs = self.system_table.boot_services().get_image_file_system(handle).expect("Failed to start up filesystem");
- let mut filesystem = FileSystem::new(fs);
+ let mut filesystem = self.get_fs();
let mut buf: Vec<u16> = vec![0; path.len() + 1];
return match filesystem.try_exists(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) {
Ok(b) => b,
@@ -189,10 +193,53 @@ impl Toolkit {
};
}
+ pub fn is_dir(&self, path: &str) -> bool {
+ if path == "" {
+ return true;
+ }
+ let mut filesystem = self.get_fs();
+ let mut buf: Vec<u16> = vec![0; path.len() + 1];
+ return match filesystem.metadata(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) {
+ Ok(b) => b.is_directory(),
+ Err(_) => false
+ };
+ }
+
+ pub fn is_file(&self, path: &str) -> bool {
+ if path == "" {
+ return true;
+ }
+ let mut filesystem = self.get_fs();
+ let mut buf: Vec<u16> = vec![0; path.len() + 1];
+ return match filesystem.metadata(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) {
+ Ok(b) => b.is_regular_file(),
+ Err(_) => false
+ };
+ }
+
+ pub fn read_file(&self, path: &str) -> Option<String> {
+ if path == "" {
+ return None;
+ }
+ let mut filesystem = self.get_fs();
+ let mut buf: Vec<u16> = vec![0; path.len() + 1];
+ return match filesystem.read_to_string(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) {
+ Ok(b) => Some(b),
+ Err(_) => None
+ };
+ }
+
+ pub fn write_file(&self, path: &str, text: &str) {
+ if path == "" {
+ return;
+ }
+ let mut filesystem = self.get_fs();
+ let mut buf: Vec<u16> = vec![0; path.len() + 1];
+ filesystem.write(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap()), text.as_bytes()).unwrap();
+ }
+
pub fn scandir(&self, path: &str) -> UefiDirectoryIter {
- let handle = self.system_table.boot_services().image_handle();
- let fs = self.system_table.boot_services().get_image_file_system(handle).expect("Failed to start up filesystem");
- let mut filesystem = FileSystem::new(fs);
+ let mut filesystem = self.get_fs();
let mut buf: Vec<u16> = vec![0; path.len() + 1];
return match filesystem.read_dir(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())) {
Ok(b) => b,
@@ -200,6 +247,36 @@ impl Toolkit {
};
}
+ pub fn resolve_path(&self, orig_og_path: &str) -> String {
+ let og_path = orig_og_path.replace("\\", "/");
+ let mut final_path = self.get_cwd().to_string().replace("/", "\\");
+ let path = &og_path.replace("/", "\\");
+ let mut buf = vec![0; path.len() + 1];
+ let cstr = CStr16::from_str_with_buf(path, &mut buf).unwrap();
+ let path = Path::new(cstr);
+
+ if og_path.starts_with("/") {
+ final_path = String::from("");
+ }
+
+ for i in path.components() {
+ if i.to_string() == ".." {
+ let parts = final_path.split("\\").collect::<Vec<&str>>();
+ let len = parts.len() - 1;
+
+ final_path = parts[..len].join("\\");
+ } else if i.to_string() != "." {
+ final_path = format!("{}\\{}", final_path, i).replace("/", "\\");
+ }
+ }
+
+ if final_path.len() > 0 {
+ final_path[1..].to_string().replace("\\\\", "\\")
+ } else {
+ final_path.to_string().replace("\\\\", "\\")
+ }
+ }
+
pub fn make_readable(&self, _size: u64) -> String {
let size = _size as f64;
@@ -217,13 +294,29 @@ impl Toolkit {
}
pub fn mkdir(&self, path: &str) {
- let handle = self.system_table.boot_services().image_handle();
- let fs = self.system_table.boot_services().get_image_file_system(handle).expect("Failed to start up filesystem");
- let mut filesystem = FileSystem::new(fs);
+ let mut filesystem = self.get_fs();
let mut buf: Vec<u16> = vec![0; path.len() + 1];
filesystem.create_dir(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap();
}
+ pub fn rmdir(&mut self, path: &str) {
+ let mut filesystem = self.get_fs();
+ let mut buf: Vec<u16> = vec![0; path.len() + 1];
+ filesystem.remove_dir(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap();
+ }
+
+ pub fn unlink(&mut self, path: &str) {
+ let mut filesystem = self.get_fs();
+ let mut buf: Vec<u16> = vec![0; path.len() + 1];
+ filesystem.remove_file(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap();
+ }
+
+ pub fn recursive_rmdir(&mut self, path: &str) {
+ let mut filesystem = self.get_fs();
+ let mut buf: Vec<u16> = vec![0; path.len() + 1];
+ filesystem.remove_dir_all(&Path::new(&CStr16::from_str_with_buf(path, &mut buf).unwrap())).unwrap();
+ }
+
pub fn print(&mut self, str: &str) {
let stdout = self.system_table.stdout();
let mut buf = vec![0; str.len() + 1];
diff --git a/userland/.DS_Store b/userland/.DS_Store
index 72f4732..9538772 100644
--- a/userland/.DS_Store
+++ b/userland/.DS_Store
Binary files differ
diff --git a/userland/Cargo.toml b/userland/Cargo.toml
index 3461f8b..12a772e 100644
--- a/userland/Cargo.toml
+++ b/userland/Cargo.toml
@@ -6,9 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-log = "0.4.20"
uefi = { version = "0.26.0", features = ["alloc"] }
-uefi-services = { version = "0.23.0", features = ["logger"], default-features = false }
+uefi-services = { version = "0.23.0", features = [], default-features = false }
build-info = { version = "0.0.34", features = [], default-features = false }
toolkit = { path = "../toolkit" }
commands = { path = "../commands" }
diff --git a/userland/src/lib.rs b/userland/src/lib.rs
index b913876..75bd555 100644
--- a/userland/src/lib.rs
+++ b/userland/src/lib.rs
@@ -6,10 +6,9 @@ use alloc::format;
use uefi::proto::console::text::Color;
use toolkit::Toolkit;
use toolkit::error::*;
+use commands::parser::{Command, CommandError};
pub fn run_shell(mut tk: Toolkit) {
- tk.println("");
-
loop {
tk.color(Color::White, Color::Black);
tk.print(&format!("{}", tk.get_cwd()));
@@ -24,26 +23,44 @@ pub fn run_shell(mut tk: Toolkit) {
continue;
}
- if text.starts_with("cd") {
- commands::cd(&mut tk, text);
- continue;
- } else if text.starts_with("pwd ") || text == "pwd" {
- commands::pwd(&mut tk, "");
- continue;
- } else if text.starts_with("ver ") || text == "ver" {
- commands::ver(&mut tk, "");
- continue;
- } else if text.starts_with("ls ") || text == "ls" {
- commands::ls(&mut tk, "");
- continue;
- } else if text.starts_with("shutdown ") || text == "shutdown" {
- commands::shutdown(&mut tk, "");
- continue;
- } else if text.starts_with("reboot ") || text == "reboot" {
- commands::reboot(&mut tk, "");
- continue;
- }
+ let command = Command::from_str(text);
- display_error(&mut tk, Error::E02);
+ match command {
+ Ok(cmd) => {
+ if tk.globals.contains_key("debug") && tk.globals.get("debug").unwrap() == "1" {
+ tk.println(&format!("{:?}", &cmd));
+ }
+
+ match cmd.command.as_str() {
+ "cd" => commands::cd::run(&mut tk, cmd),
+ "append" => commands::append::run(&mut tk, cmd),
+ "appendln" => commands::appendln::run(&mut tk, cmd),
+ "clear" => commands::clear::run(&mut tk, cmd),
+ "mkdir" => commands::mkdir::run(&mut tk, cmd),
+ "rmdir" => commands::rmdir::run(&mut tk, cmd),
+ "pwd" => commands::pwd::run(&mut tk, cmd),
+ "cat" => commands::cat::run(&mut tk, cmd),
+ "touch" => commands::touch::run(&mut tk, cmd),
+ "path" => commands::path::run(&mut tk, cmd),
+ "ver" => commands::ver::run(&mut tk, cmd),
+ "ls" => commands::ls::run(&mut tk, cmd),
+ "rm" => commands::rm::run(&mut tk, cmd),
+ "shutdown" => commands::shutdown::run(&mut tk, cmd),
+ "reboot" => commands::reboot::run(&mut tk, cmd),
+ "debug" => commands::debug::run(&mut tk, cmd),
+ _ => display_error(&mut tk, Error::E02)
+ }
+ }
+ Err(e) => {
+ match e {
+ CommandError::ExecutablePathNotFound => {
+ display_error(&mut tk, Error::E06);
+ }
+ CommandError::MismatchedQuotes => {
+ display_error(&mut tk, Error::E07);
+ }
+ }
+ }
+ }
}
}