Compare commits
1 commit
master
...
pls-build-
Author | SHA1 | Date | |
---|---|---|---|
Monadic Cat | 89157977a1 |
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -3,9 +3,8 @@ ableos/target
|
||||||
aos_wasm_stress_test/target
|
aos_wasm_stress_test/target
|
||||||
facepalm/target
|
facepalm/target
|
||||||
shadeable/target
|
shadeable/target
|
||||||
|
qprofiler
|
||||||
userland/*/target
|
userland/*/target
|
||||||
kernel/target
|
kernel/target
|
||||||
userland/root_fs/mnt/*
|
userland/root_fs/mnt/*
|
||||||
target/
|
|
||||||
|
|
||||||
!*/.gitkeep
|
!*/.gitkeep
|
||||||
|
|
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
|
@ -2,5 +2,7 @@
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"stddef.h": "c"
|
"stddef.h": "c"
|
||||||
},
|
},
|
||||||
"rust-analyzer.checkOnSave.allTargets": false,
|
"settings": {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
1100
Cargo.lock
generated
1100
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
10
Cargo.toml
10
Cargo.toml
|
@ -1,10 +0,0 @@
|
||||||
[workspace]
|
|
||||||
|
|
||||||
members = [
|
|
||||||
"ableos",
|
|
||||||
"kernel",
|
|
||||||
"facepalm",
|
|
||||||
"shadeable",
|
|
||||||
"repbuild",
|
|
||||||
|
|
||||||
]
|
|
|
@ -7,9 +7,8 @@ build-std = ["core", "compiler_builtins", "alloc"]
|
||||||
build-std-features = ["compiler-builtins-mem"]
|
build-std-features = ["compiler-builtins-mem"]
|
||||||
|
|
||||||
[target.'cfg(target_arch = "x86_64")']
|
[target.'cfg(target_arch = "x86_64")']
|
||||||
rustflags = ["-C", "target-feature=+rdrand"]
|
rustflags = ["-C", "target-feature=+rdrnd"]
|
||||||
runner = "bootimage runner"
|
runner = "bootimage runner"
|
||||||
|
|
||||||
[target.riscv64gc-unknown-none-elf]
|
[target.riscv64gc-unknown-none-elf]
|
||||||
rustflags = "-C link-arg=-Tableos/src/arch/riscv/virt.lds"
|
rustflags = "-C link-arg=-T../ableos/src/arch/riscv/virt.lds"
|
||||||
# ableos/src/arch/riscv/virt.lds
|
|
||||||
|
|
21
ableos/Cargo.lock
generated
21
ableos/Cargo.lock
generated
|
@ -112,9 +112,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "axel"
|
name = "axel"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/able/aos_userland#a96bc8b896fdee392e8f26125298da6b4b21dd9a"
|
source = "git+https://git.ablecorp.us/able/aos_userland.git#065a88b4b4a1fa55597f84012fd452ad4c77bee0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown 0.7.2",
|
"hashbrown 0.12.0",
|
||||||
"log",
|
"log",
|
||||||
"logos",
|
"logos",
|
||||||
"versioning",
|
"versioning",
|
||||||
|
@ -571,12 +571,11 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rhai"
|
name = "rhai"
|
||||||
version = "1.6.1"
|
version = "1.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ef3d57e55ca044c53ced279d2d3ee9df229b247556b005a23713d5206a2ecfc"
|
checksum = "49c94fda0280985896ed6d8bf0b43bbb5a7f0e39ccc8728ac907ddb4f06dae94"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.7.6",
|
"ahash 0.7.6",
|
||||||
"bitflags",
|
|
||||||
"core-error",
|
"core-error",
|
||||||
"instant",
|
"instant",
|
||||||
"libm",
|
"libm",
|
||||||
|
@ -589,9 +588,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rhai_codegen"
|
name = "rhai_codegen"
|
||||||
version = "1.4.0"
|
version = "1.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "faa0ff1c9dc19c9f8bba510a2a75d3f0449f6233570c2672c7e31c692a11a59a"
|
checksum = "e02d33d76a7aa8ec72ac8298d5b52134fd2dff77445ada0c65f6f8c40d8f2931"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -706,13 +705,11 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smartstring"
|
name = "smartstring"
|
||||||
version = "1.0.1"
|
version = "0.2.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29"
|
checksum = "e714dff2b33f2321fdcd475b71cec79781a692d846f37f415fb395a1d2bcd48e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
"version_check",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -817,7 +814,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "versioning"
|
name = "versioning"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
source = "git+https://git.ablecorp.us/able/aos_userland#a96bc8b896fdee392e8f26125298da6b4b21dd9a"
|
source = "git+https://git.ablecorp.us/able/aos_userland.git#065a88b4b4a1fa55597f84012fd452ad4c77bee0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
|
@ -18,7 +18,7 @@ run-args = [
|
||||||
"-smp",
|
"-smp",
|
||||||
"cores=2",
|
"cores=2",
|
||||||
|
|
||||||
"-device",
|
"-device", #"ati-vga",
|
||||||
"cirrus-vga",
|
"cirrus-vga",
|
||||||
|
|
||||||
# "-device",
|
# "-device",
|
||||||
|
@ -27,14 +27,13 @@ run-args = [
|
||||||
# "-drive",
|
# "-drive",
|
||||||
# "file=disk.qcow2,if=none,id=drive0",
|
# "file=disk.qcow2,if=none,id=drive0",
|
||||||
|
|
||||||
"-device",
|
# "-device",
|
||||||
"virtio-rng",
|
# "virtio-rng",
|
||||||
|
|
||||||
"-qmp",
|
# "-qmp",
|
||||||
"unix:../qmp-sock,server,nowait"
|
# "unix:../qmp-sock,server,nowait"
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
test-args = [
|
test-args = [
|
||||||
"-device",
|
"-device",
|
||||||
"isa-debug-exit,iobase=0xf4,iosize=0x04",
|
"isa-debug-exit,iobase=0xf4,iosize=0x04",
|
||||||
|
@ -42,45 +41,54 @@ test-args = [
|
||||||
"stdio",
|
"stdio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
linked_list_allocator = "0.9.0"
|
linked_list_allocator = "0.9.0"
|
||||||
lliw = "0.2.0"
|
lliw = "0.2.0"
|
||||||
spin = "0.9"
|
spin = "0.5.2"
|
||||||
log = "*"
|
log = "*"
|
||||||
pretty-hex = "0.2.1"
|
pretty-hex = "0.2.1"
|
||||||
unicode-width = "0.1.7"
|
unicode-width = "0.1.7"
|
||||||
picorand = "0.1.0"
|
picorand = "*"
|
||||||
watson = "0.4"
|
watson = "0.4"
|
||||||
genfs = "0.1.0"
|
genfs = "0.1.0"
|
||||||
rhai = "1.6.0"
|
rhai = "1.5"
|
||||||
libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}
|
libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}
|
||||||
axel = { git = "https://git.ablecorp.us/able/aos_userland" }
|
acpi = "4.1.0"
|
||||||
versioning = { git = "https://git.ablecorp.us/able/aos_userland" }
|
|
||||||
|
axel = { git = "https://git.ablecorp.us:443/able/aos_userland.git" }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies.logos]
|
[dependencies.logos]
|
||||||
version = "0.12"
|
version = "0.12.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["export_derive"]
|
features = ["export_derive"]
|
||||||
|
|
||||||
[dependencies.rdrand]
|
[dependencies.rdrand]
|
||||||
version = "0.8"
|
version = "0.8.1"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies.kernel]
|
[dependencies.kernel]
|
||||||
path = "../kernel"
|
path = "../kernel"
|
||||||
|
|
||||||
[dependencies.serde]
|
[dependencies.serde]
|
||||||
version = "1.0"
|
version = "*"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["derive", "alloc"]
|
features = ["derive", "alloc"]
|
||||||
|
|
||||||
[dependencies.hashbrown]
|
[dependencies.hashbrown]
|
||||||
version = "0.7"
|
version = "0.7.2"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["inline-more"]
|
features = ["inline-more"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies.rkyv]
|
[dependencies.rkyv]
|
||||||
version = "0.7"
|
version = "0.7.29"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["size_64", "alloc"]
|
features = ["size_64", "alloc"]
|
||||||
|
|
||||||
|
@ -95,11 +103,15 @@ git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git"
|
||||||
[dependencies.ext2]
|
[dependencies.ext2]
|
||||||
git = "https://git.ablecorp.us:443/able/ext2-rs.git"
|
git = "https://git.ablecorp.us:443/able/ext2-rs.git"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies.toml]
|
[dependencies.toml]
|
||||||
git = "https://github.com/diondokter/toml-rs"
|
git = "https://github.com/diondokter/toml-rs"
|
||||||
# version = "0.5.8"
|
# version = "0.5.8"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies.shadeable]
|
[dependencies.shadeable]
|
||||||
path = "../shadeable"
|
path = "../shadeable"
|
||||||
|
|
||||||
|
@ -116,6 +128,10 @@ default-features = false
|
||||||
features = ["core"]
|
features = ["core"]
|
||||||
version = "*"
|
version = "*"
|
||||||
|
|
||||||
|
[dependencies.lazy_static]
|
||||||
|
features = ["spin_no_std"]
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
[dependencies.externc-libm]
|
[dependencies.externc-libm]
|
||||||
git = "https://git.ablecorp.us:443/able/externc-libm.git"
|
git = "https://git.ablecorp.us:443/able/externc-libm.git"
|
||||||
|
|
||||||
|
@ -133,4 +149,3 @@ volatile = "0.2.6"
|
||||||
x86_64 = "*"
|
x86_64 = "*"
|
||||||
pc-beeper = {git = "https://github.com/AbleOS/pc-beeper"}
|
pc-beeper = {git = "https://github.com/AbleOS/pc-beeper"}
|
||||||
vga = "*"
|
vga = "*"
|
||||||
acpi = "4.1.0"
|
|
|
@ -1,7 +1,8 @@
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
|
||||||
pub static ALIAS_TABLE: spin::Mutex<AliasTable> = spin::Mutex::new(AliasTable::new());
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref ALIAS_TABLE: spin::Mutex<AliasTable> = spin::Mutex::new(AliasTable::new());
|
||||||
|
}
|
||||||
/// A table of aliases
|
/// A table of aliases
|
||||||
///
|
///
|
||||||
/// This is used to allow users to specify aliases for files and commands
|
/// This is used to allow users to specify aliases for files and commands
|
||||||
|
@ -15,7 +16,6 @@ impl AliasTable {
|
||||||
table: HashMap::new(),
|
table: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_alias(&mut self, alias: String, path: String) {
|
pub fn add_alias(&mut self, alias: String, path: String) {
|
||||||
self.table.insert(alias, path);
|
self.table.insert(alias, path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
//! The allocator to be implemented by ableOS
|
/*!
|
||||||
|
The allocator to be implemented by ableOS
|
||||||
|
*/
|
||||||
|
|
||||||
use alloc::alloc::{GlobalAlloc, Layout};
|
use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
use core::ptr::null_mut;
|
use core::ptr::null_mut;
|
||||||
|
|
||||||
pub struct AAloc;
|
pub struct AAloc;
|
||||||
|
|
||||||
unsafe impl GlobalAlloc for AAloc {
|
unsafe impl GlobalAlloc for AAloc {
|
||||||
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
|
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
|
||||||
println!("Allocating memory");
|
println!("Allocating memory");
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
mod aalloc;
|
mod aalloc;
|
||||||
|
|
||||||
use linked_list_allocator::LockedHeap;
|
|
||||||
|
|
||||||
pub const HEAP_START: usize = 0x_4444_4444_0000;
|
pub const HEAP_START: usize = 0x_4444_4444_0000;
|
||||||
|
/// 131072 bytes
|
||||||
|
// pub const HEAP_MULTIPLIER: usize = 1024;
|
||||||
pub const HEAP_MULTIPLIER: usize = 100000;
|
pub const HEAP_MULTIPLIER: usize = 100000;
|
||||||
|
|
||||||
pub const HEAP_BASE: usize = 100;
|
pub const HEAP_BASE: usize = 100;
|
||||||
|
|
||||||
pub const HEAP_SIZE: usize = HEAP_BASE * HEAP_MULTIPLIER;
|
pub const HEAP_SIZE: usize = HEAP_BASE * HEAP_MULTIPLIER;
|
||||||
|
|
||||||
|
use linked_list_allocator::LockedHeap;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
pub static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
pub static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
||||||
|
|
||||||
#[alloc_error_handler]
|
#[alloc_error_handler]
|
||||||
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
|
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
|
||||||
|
// error!("allocation error: {:?}", layout);
|
||||||
|
|
||||||
panic!("allocation error: {:?}", layout)
|
panic!("allocation error: {:?}", layout)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
use core::ptr::null_mut;
|
use core::ptr::null_mut;
|
||||||
|
|
||||||
pub struct Dummy;
|
pub struct Dummy;
|
||||||
|
|
||||||
unsafe impl GlobalAlloc for Dummy {
|
unsafe impl GlobalAlloc for Dummy {
|
||||||
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
|
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
|
||||||
null_mut()
|
null_mut()
|
||||||
|
|
|
@ -7,27 +7,21 @@ impl Graphics for GraphicsBuffer {
|
||||||
fn put_line(coords_start: Point, coords_end: Point, thickness: u32, color: Rgb) {
|
fn put_line(coords_start: Point, coords_end: Point, thickness: u32, color: Rgb) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_rect(coords_start: Point, coords_end: Point, color: Rgb) {
|
fn put_rect(coords_start: Point, coords_end: Point, color: Rgb) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_circle(coords: Point, radius: u32) {
|
fn put_circle(coords: Point, radius: u32) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_triangle(coords_1: Point, coords_2: Point, coords_3: Point, thickness: u32, color: Rgb) {
|
fn put_triangle(coords_1: Point, coords_2: Point, coords_3: Point, thickness: u32, color: Rgb) {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_pixel(coords: Point, color: Rgb) {
|
fn put_pixel(coords: Point, color: Rgb) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint_cursor(coords: Point) {
|
fn paint_cursor(coords: Point) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hide_cursor() {}
|
fn hide_cursor() {}
|
||||||
fn show_cursor() {}
|
fn show_cursor() {}
|
||||||
fn draw() {}
|
fn draw() {}
|
||||||
|
|
|
@ -1,8 +1,36 @@
|
||||||
//! A not-very-useful abstraction of GPIOs in Rust
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
// A not-very-useful abstraction of GPIOs in Rust
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicBool, Ordering::SeqCst};
|
use core::sync::atomic::{AtomicBool, Ordering::SeqCst};
|
||||||
|
|
||||||
|
/// A struct that represents an nRF52 Pin
|
||||||
|
pub struct Pin(u8);
|
||||||
|
|
||||||
|
/// A struct that represents P0 of the nRF52
|
||||||
|
pub struct Pins {
|
||||||
|
pub p0_31: Pin,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Pins {
|
||||||
|
/// A function to obtain a Port 0 singleton structure
|
||||||
|
pub fn take() -> Self {
|
||||||
|
static TAKEN: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
|
// Enforce this as a singleton
|
||||||
|
assert!(!TAKEN.swap(true, SeqCst));
|
||||||
|
|
||||||
|
Self { p0_31: Pin(31) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The level of a GPIO
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub enum Level {
|
||||||
|
Low,
|
||||||
|
High,
|
||||||
|
}
|
||||||
|
|
||||||
const REG_P0_PIN_CNF_BASE: *mut u32 = 0x5000_0700 as *mut u32;
|
const REG_P0_PIN_CNF_BASE: *mut u32 = 0x5000_0700 as *mut u32;
|
||||||
const REG_P0_OUT_SET: *mut u32 = 0x5000_0508 as *mut u32;
|
const REG_P0_OUT_SET: *mut u32 = 0x5000_0508 as *mut u32;
|
||||||
const REG_P0_OUT_CLR: *mut u32 = 0x5000_050C as *mut u32;
|
const REG_P0_OUT_CLR: *mut u32 = 0x5000_050C as *mut u32;
|
||||||
|
@ -12,8 +40,7 @@ const PIN_CNF_INPUT_CONNECT: u32 = 0x0000_0000;
|
||||||
const PIN_CNF_PULL_DISABLED: u32 = 0x0000_0000;
|
const PIN_CNF_PULL_DISABLED: u32 = 0x0000_0000;
|
||||||
const PIN_CNF_DRIVE_S0S1: u32 = 0x0000_0000;
|
const PIN_CNF_DRIVE_S0S1: u32 = 0x0000_0000;
|
||||||
const PIN_CNF_SENSE_DISABLED: u32 = 0x0000_0000;
|
const PIN_CNF_SENSE_DISABLED: u32 = 0x0000_0000;
|
||||||
/// A struct that represents an nRF52 Pin
|
|
||||||
pub struct Pin(u8);
|
|
||||||
impl Pin {
|
impl Pin {
|
||||||
/// Set a pin to be a push pull output
|
/// Set a pin to be a push pull output
|
||||||
pub fn set_push_pull_output(&mut self, level: Level) {
|
pub fn set_push_pull_output(&mut self, level: Level) {
|
||||||
|
@ -44,27 +71,3 @@ impl Pin {
|
||||||
unsafe { core::ptr::write_volatile(REG_P0_OUT_CLR, 1 << (self.0 as u32)) }
|
unsafe { core::ptr::write_volatile(REG_P0_OUT_CLR, 1 << (self.0 as u32)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The level of a GPIO
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
pub enum Level {
|
|
||||||
Low,
|
|
||||||
High,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A struct that represents P0 of the nRF52
|
|
||||||
pub struct Pins {
|
|
||||||
pub p0_31: Pin,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Pins {
|
|
||||||
/// A function to obtain a Port 0 singleton structure
|
|
||||||
pub fn take() -> Self {
|
|
||||||
static TAKEN: AtomicBool = AtomicBool::new(false);
|
|
||||||
|
|
||||||
// Enforce this as a singleton
|
|
||||||
assert!(!TAKEN.swap(true, SeqCst));
|
|
||||||
|
|
||||||
Self { p0_31: Pin(31) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
use core::ptr;
|
||||||
|
|
||||||
|
// mod panic;
|
||||||
pub mod drivers;
|
pub mod drivers;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
|
|
||||||
use crate::arch::drivers::nrf52::{Level, Pins};
|
use crate::arch::drivers::nrf52::{Level, Pins};
|
||||||
use core::ptr;
|
|
||||||
use core::ptr::write_volatile;
|
use core::ptr::write_volatile;
|
||||||
|
|
||||||
global_asm!(include_str!("boot.s"));
|
global_asm!(include_str!("boot.s"));
|
||||||
|
|
||||||
fn delay(ticks: usize) {
|
fn delay(ticks: usize) {
|
||||||
|
@ -32,6 +33,7 @@ pub extern "C" fn not_main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
// let gpios = Pins::take();
|
// let gpios = Pins::take();
|
||||||
// let mut led = gpios.p0_31;
|
// let mut led = gpios.p0_31;
|
||||||
//
|
//
|
||||||
|
@ -44,15 +46,14 @@ pub extern "C" fn not_main() {
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// led.set_push_pull_output(Level::Low);
|
// led.set_push_pull_output(Level::Low);
|
||||||
|
|
||||||
crate::kmain::kernel_main();
|
crate::kmain::kernel_main();
|
||||||
|
|
||||||
sloop();
|
sloop();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sloop() -> ! {
|
pub fn sloop() -> ! {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print() {
|
pub fn print() {
|
||||||
for byte in b"ableOS Arm 64" {
|
for byte in b"ableOS Arm 64" {
|
||||||
const UART0: *mut u8 = 0x0900_0000 as *mut u8;
|
const UART0: *mut u8 = 0x0900_0000 as *mut u8;
|
||||||
|
|
|
@ -2,6 +2,7 @@ use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
use core::ptr::null_mut;
|
use core::ptr::null_mut;
|
||||||
|
|
||||||
pub struct Dummy;
|
pub struct Dummy;
|
||||||
|
|
||||||
unsafe impl GlobalAlloc for Dummy {
|
unsafe impl GlobalAlloc for Dummy {
|
||||||
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
|
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
|
||||||
null_mut()
|
null_mut()
|
||||||
|
|
|
@ -7,27 +7,21 @@ impl Graphics for GraphicsBuffer {
|
||||||
fn put_line(coords_start: Point, coords_end: Point, thickness: u32, color: Rgb) {
|
fn put_line(coords_start: Point, coords_end: Point, thickness: u32, color: Rgb) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_rect(coords_start: Point, coords_end: Point, color: Rgb) {
|
fn put_rect(coords_start: Point, coords_end: Point, color: Rgb) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_circle(coords: Point, radius: u32) {
|
fn put_circle(coords: Point, radius: u32) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_triangle(coords_1: Point, coords_2: Point, coords_3: Point, thickness: u32, color: Rgb) {
|
fn put_triangle(coords_1: Point, coords_2: Point, coords_3: Point, thickness: u32, color: Rgb) {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_pixel(coords: Point, color: Rgb) {
|
fn put_pixel(coords: Point, color: Rgb) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint_cursor(coords: Point) {
|
fn paint_cursor(coords: Point) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hide_cursor() {}
|
fn hide_cursor() {}
|
||||||
fn show_cursor() {}
|
fn show_cursor() {}
|
||||||
fn draw() {}
|
fn draw() {}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
/// We label the mmio function unsafe since
|
/// We label the mmio function unsafe since
|
||||||
/// we will be working with raw memory. Rust cannot
|
/// we will be working with raw memory. Rust cannot
|
||||||
/// make any guarantees when we do this.
|
/// make any guarantees when we do this.
|
||||||
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn mmio_write(address: usize, offset: usize, value: u8) {
|
fn mmio_write(address: usize, offset: usize, value: u8) {
|
||||||
// Set the pointer based off of the address
|
// Set the pointer based off of the address
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
pub mod allocator;
|
pub mod allocator;
|
||||||
pub mod graphics;
|
pub mod graphics;
|
||||||
pub mod mmio;
|
pub mod mmio;
|
||||||
pub mod sysinfo;
|
|
||||||
pub mod uart;
|
pub mod uart;
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
pub fn sysinfo() {}
|
|
||||||
pub fn master() -> Option<Master> {
|
|
||||||
Some(Master {
|
|
||||||
brand_string: Some("riscv".to_string()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Master {
|
|
||||||
// TODO: Rename struct
|
|
||||||
// version_information: Option<VersionInformation>,
|
|
||||||
// thermal_power_management_information: Option<ThermalPowerManagementInformation>,
|
|
||||||
// structured_extended_information: Option<StructuredExtendedInformation>,
|
|
||||||
// extended_processor_signature: Option<ExtendedProcessorSignature>,
|
|
||||||
pub brand_string: Option<String>,
|
|
||||||
// cache_line: Option<CacheLine>,
|
|
||||||
// time_stamp_counter: Option<TimeStampCounter>,
|
|
||||||
// physical_address_size: Option<PhysicalAddressSize>,
|
|
||||||
}
|
|
||||||
impl Master {
|
|
||||||
pub fn brand_string(&self) -> Option<&str> {
|
|
||||||
self.brand_string.as_deref()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,6 @@
|
||||||
use core::fmt::{Error, Write};
|
use core::fmt::Write;
|
||||||
|
|
||||||
|
use core::fmt::Error;
|
||||||
|
|
||||||
/// Initialize the UART driver by setting
|
/// Initialize the UART driver by setting
|
||||||
/// the word length, FIFOs, and interrupts
|
/// the word length, FIFOs, and interrupts
|
||||||
|
@ -111,7 +113,6 @@ impl Uart {
|
||||||
uart_init(self.base_address);
|
uart_init(self.base_address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a slightly different syntax. Write is this "trait", meaning it is much like
|
// This is a slightly different syntax. Write is this "trait", meaning it is much like
|
||||||
// an interface where we're just guaranteeing a certain function signature. In the Write
|
// an interface where we're just guaranteeing a certain function signature. In the Write
|
||||||
// trait, one is absolutely required to be implemented, which is write_str. There are other
|
// trait, one is absolutely required to be implemented, which is write_str. There are other
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
pub mod drivers;
|
pub mod drivers;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
|
|
||||||
use crate::print;
|
|
||||||
use crate::println;
|
|
||||||
use core::arch::asm;
|
|
||||||
|
|
||||||
#[naked]
|
#[naked]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
unsafe extern "C" fn _boot() -> ! {
|
unsafe extern "C" fn _boot() -> ! {
|
||||||
|
@ -36,10 +31,9 @@ unsafe extern "C" fn _boot() -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn _start() -> ! {
|
extern "C" fn _start() -> ! {
|
||||||
use crate::serial_println;
|
|
||||||
|
|
||||||
let uart = crate::arch::drivers::uart::Uart::new(0x1000_0000);
|
let uart = crate::arch::drivers::uart::Uart::new(0x1000_0000);
|
||||||
uart.init();
|
uart.init();
|
||||||
|
use crate::serial_println;
|
||||||
serial_println!("Hello, world!\r");
|
serial_println!("Hello, world!\r");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -51,29 +45,6 @@ extern "C" fn _start() -> ! {
|
||||||
uart.put('\r' as u8);
|
uart.put('\r' as u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
91 => {
|
|
||||||
if let Some(ch) = uart.get() {
|
|
||||||
match ch as char {
|
|
||||||
'A' => {
|
|
||||||
serial_println!("That's the up arrow!");
|
|
||||||
}
|
|
||||||
'B' => {
|
|
||||||
serial_println!("That's the down arrow!");
|
|
||||||
}
|
|
||||||
'C' => {
|
|
||||||
serial_println!("That's the right arrow!");
|
|
||||||
}
|
|
||||||
'D' => {
|
|
||||||
serial_println!("That's the left arrow!");
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
serial_println!("That's something else!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
_ => {
|
_ => {
|
||||||
uart.put(c);
|
uart.put(c);
|
||||||
}
|
}
|
||||||
|
@ -82,6 +53,7 @@ extern "C" fn _start() -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
serial_println!("Serial connection closed.\r");
|
serial_println!("Serial connection closed.\r");
|
||||||
|
|
||||||
sloop()
|
sloop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +64,13 @@ pub fn sloop() -> ! {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
use core::arch::asm;
|
||||||
|
|
||||||
pub fn shutdown() {}
|
pub fn shutdown() {}
|
||||||
|
|
||||||
|
use crate::print;
|
||||||
|
use crate::println;
|
||||||
|
|
||||||
pub fn generate_process_pass() -> u128 {
|
pub fn generate_process_pass() -> u128 {
|
||||||
123
|
123
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::allocator::{HEAP_SIZE, HEAP_START};
|
|
||||||
use alloc::alloc::{GlobalAlloc, Layout};
|
use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
|
|
||||||
|
use crate::allocator::{HEAP_SIZE, HEAP_START};
|
||||||
use core::ptr::null_mut;
|
use core::ptr::null_mut;
|
||||||
use x86_64::{
|
use x86_64::{
|
||||||
structures::paging::{
|
structures::paging::{
|
||||||
|
@ -8,6 +9,7 @@ use x86_64::{
|
||||||
VirtAddr,
|
VirtAddr,
|
||||||
};
|
};
|
||||||
pub struct Dummy;
|
pub struct Dummy;
|
||||||
|
|
||||||
unsafe impl GlobalAlloc for Dummy {
|
unsafe impl GlobalAlloc for Dummy {
|
||||||
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
|
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
|
||||||
null_mut()
|
null_mut()
|
||||||
|
|
|
@ -8,32 +8,25 @@ impl Graphics for GraphicsBuffer {
|
||||||
fn put_line(coords_start: Point, coords_end: Point, thickness: u32, color: Rgb) {
|
fn put_line(coords_start: Point, coords_end: Point, thickness: u32, color: Rgb) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_rect(coords_start: Point, coords_end: Point, color: Rgb) {}
|
fn put_rect(coords_start: Point, coords_end: Point, color: Rgb) {}
|
||||||
|
|
||||||
fn put_circle(coords: Point, radius: u32) {
|
fn put_circle(coords: Point, radius: u32) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_triangle(coords_1: Point, coords_2: Point, coords_3: Point, thickness: u32, color: Rgb) {
|
fn put_triangle(coords_1: Point, coords_2: Point, coords_3: Point, thickness: u32, color: Rgb) {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_pixel(coords: Point, color: Rgb) {
|
fn put_pixel(coords: Point, color: Rgb) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint_cursor(coords: Point) {
|
fn paint_cursor(coords: Point) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hide_cursor() {
|
fn hide_cursor() {
|
||||||
unsafe {
|
unsafe {
|
||||||
outw(0x0A, 0x3D4);
|
outw(0x0A, 0x3D4);
|
||||||
outw(0x20, 0x3D5);
|
outw(0x20, 0x3D5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_cursor() {}
|
fn show_cursor() {}
|
||||||
fn draw() {}
|
fn draw() {}
|
||||||
fn clear() {
|
fn clear() {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
pub mod allocator;
|
pub mod allocator;
|
||||||
pub mod graphics;
|
pub mod graphics;
|
||||||
pub mod serial;
|
pub mod serial;
|
||||||
pub mod sysinfo;
|
|
||||||
pub mod timer;
|
pub mod timer;
|
||||||
|
|
||||||
#[deprecated(note = "The use of hardware specific drivers for VGA is discouraged")]
|
// #[deprecated(note = "The use of hardware specific drivers for VGA is discouraged")]
|
||||||
pub mod vga;
|
pub mod vga;
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use spin::{Lazy, Mutex};
|
use lazy_static::lazy_static;
|
||||||
|
use spin::Mutex;
|
||||||
use uart_16550::SerialPort;
|
use uart_16550::SerialPort;
|
||||||
|
lazy_static! {
|
||||||
pub static SERIAL1: Lazy<Mutex<SerialPort>> = Lazy::new(|| {
|
pub static ref SERIAL1: Mutex<SerialPort> = {
|
||||||
let mut serial_port = unsafe { SerialPort::new(0x3F8) };
|
let mut serial_port = unsafe { SerialPort::new(0x3F8) };
|
||||||
serial_port.init();
|
serial_port.init();
|
||||||
Mutex::new(serial_port)
|
Mutex::new(serial_port)
|
||||||
});
|
};
|
||||||
|
}
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn _print(args: ::core::fmt::Arguments) {
|
pub fn _print(args: ::core::fmt::Arguments) {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
@ -15,7 +16,6 @@ pub fn _print(args: ::core::fmt::Arguments) {
|
||||||
.write_fmt(args)
|
.write_fmt(args)
|
||||||
.expect("Printing to serial failed");
|
.expect("Printing to serial failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints to the host through the serial interface.
|
/// Prints to the host through the serial interface.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! sprint {
|
macro_rules! sprint {
|
||||||
|
@ -23,7 +23,6 @@ macro_rules! sprint {
|
||||||
$crate::arch::drivers::serial::_print(format_args!($($arg)*));
|
$crate::arch::drivers::serial::_print(format_args!($($arg)*));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints to the host through the serial interface, appending a newline.
|
/// Prints to the host through the serial interface, appending a newline.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! sprintln {
|
macro_rules! sprintln {
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
use core::fmt;
|
|
||||||
use spin::{Lazy, Mutex};
|
|
||||||
use volatile::Volatile;
|
|
||||||
|
|
||||||
const BUFFER_HEIGHT: usize = 25;
|
|
||||||
const BUFFER_WIDTH: usize = 80;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
|
@ -26,34 +19,31 @@ pub enum Color {
|
||||||
Yellow = 14,
|
Yellow = 14,
|
||||||
White = 15,
|
White = 15,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
struct ColorCode(u8);
|
struct ColorCode(u8);
|
||||||
impl ColorCode {
|
impl ColorCode {
|
||||||
const fn new(foreground: Color, background: Color) -> ColorCode {
|
fn new(foreground: Color, background: Color) -> ColorCode {
|
||||||
ColorCode((background as u8) << 4 | (foreground as u8))
|
ColorCode((background as u8) << 4 | (foreground as u8))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
struct ScreenChar {
|
struct ScreenChar {
|
||||||
ascii_character: u8,
|
ascii_character: u8,
|
||||||
color_code: ColorCode,
|
color_code: ColorCode,
|
||||||
}
|
}
|
||||||
|
const BUFFER_HEIGHT: usize = 25;
|
||||||
|
const BUFFER_WIDTH: usize = 80;
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
struct Buffer {
|
struct Buffer {
|
||||||
chars: [[Volatile<ScreenChar>; BUFFER_WIDTH]; BUFFER_HEIGHT],
|
chars: [[Volatile<ScreenChar>; BUFFER_WIDTH]; BUFFER_HEIGHT],
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Writer {
|
pub struct Writer {
|
||||||
column_position: usize,
|
column_position: usize,
|
||||||
color_code: ColorCode,
|
color_code: ColorCode,
|
||||||
buffer: &'static mut Buffer,
|
buffer: &'static mut Buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Writer {
|
impl Writer {
|
||||||
pub fn write_byte(&mut self, byte: u8) {
|
pub fn write_byte(&mut self, byte: u8) {
|
||||||
match byte {
|
match byte {
|
||||||
|
@ -73,7 +63,6 @@ impl Writer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_string(&mut self, s: &str) {
|
pub fn write_string(&mut self, s: &str) {
|
||||||
for byte in s.bytes() {
|
for byte in s.bytes() {
|
||||||
match byte {
|
match byte {
|
||||||
|
@ -84,7 +73,6 @@ impl Writer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_line(&mut self) {
|
fn new_line(&mut self) {
|
||||||
for row in 1..BUFFER_HEIGHT {
|
for row in 1..BUFFER_HEIGHT {
|
||||||
for col in 0..BUFFER_WIDTH {
|
for col in 0..BUFFER_WIDTH {
|
||||||
|
@ -95,7 +83,6 @@ impl Writer {
|
||||||
self.clear_row(BUFFER_HEIGHT - 1);
|
self.clear_row(BUFFER_HEIGHT - 1);
|
||||||
self.column_position = 0;
|
self.column_position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_row(&mut self, row: usize) {
|
fn clear_row(&mut self, row: usize) {
|
||||||
let blank = ScreenChar {
|
let blank = ScreenChar {
|
||||||
ascii_character: b' ',
|
ascii_character: b' ',
|
||||||
|
@ -121,33 +108,35 @@ impl Writer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Write for Writer {
|
impl fmt::Write for Writer {
|
||||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||||
self.write_string(s);
|
self.write_string(s);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lazy_static! {
|
||||||
pub static WRITER: Lazy<Mutex<Writer>> = Lazy::new(|| {
|
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
|
||||||
Mutex::new(Writer {
|
|
||||||
column_position: 0,
|
column_position: 0,
|
||||||
color_code: ColorCode::new(Color::White, Color::Black),
|
color_code: ColorCode::new(Color::White, Color::Black),
|
||||||
buffer: unsafe { &mut *(0xb8000 as *mut Buffer) },
|
buffer: unsafe { &mut *(0xb8000 as *mut Buffer) },
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
use core::fmt;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use spin::Mutex;
|
||||||
|
|
||||||
|
use volatile::Volatile;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! kprint {
|
macro_rules! kprint {
|
||||||
($($arg:tt)*) => ($crate::arch::drivers::vga::_kprint(format_args!($($arg)*)));
|
($($arg:tt)*) => ($crate::arch::drivers::vga::_kprint(format_args!($($arg)*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! kprintln {
|
macro_rules! kprintln {
|
||||||
() => ($crate::kprint!("\n"));
|
() => ($crate::kprint!("\n"));
|
||||||
($($arg:tt)*) => ($crate::kprint!("{}\n", format_args!($($arg)*)));
|
($($arg:tt)*) => ($crate::kprint!("{}\n", format_args!($($arg)*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn _kprint(args: fmt::Arguments) {
|
pub fn _kprint(args: fmt::Arguments) {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
use spin::Lazy;
|
use lazy_static::lazy_static;
|
||||||
use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector};
|
use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector};
|
||||||
use x86_64::structures::tss::TaskStateSegment;
|
use x86_64::structures::tss::TaskStateSegment;
|
||||||
use x86_64::VirtAddr;
|
use x86_64::VirtAddr;
|
||||||
|
|
||||||
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0;
|
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0;
|
||||||
|
lazy_static! {
|
||||||
struct Selectors {
|
static ref TSS: TaskStateSegment = {
|
||||||
code_selector: SegmentSelector,
|
|
||||||
tss_selector: SegmentSelector,
|
|
||||||
}
|
|
||||||
|
|
||||||
static TSS: Lazy<TaskStateSegment> = Lazy::new(|| {
|
|
||||||
let mut tss = TaskStateSegment::new();
|
let mut tss = TaskStateSegment::new();
|
||||||
tss.interrupt_stack_table[DOUBLE_FAULT_IST_INDEX as usize] = {
|
tss.interrupt_stack_table[DOUBLE_FAULT_IST_INDEX as usize] = {
|
||||||
const STACK_SIZE: usize = 4096 * 5;
|
const STACK_SIZE: usize = 4096 * 5;
|
||||||
|
@ -20,9 +14,14 @@ static TSS: Lazy<TaskStateSegment> = Lazy::new(|| {
|
||||||
stack_start + STACK_SIZE
|
stack_start + STACK_SIZE
|
||||||
};
|
};
|
||||||
tss
|
tss
|
||||||
});
|
};
|
||||||
|
}
|
||||||
static GDT: Lazy<(GlobalDescriptorTable, Selectors)> = Lazy::new(|| {
|
struct Selectors {
|
||||||
|
code_selector: SegmentSelector,
|
||||||
|
tss_selector: SegmentSelector,
|
||||||
|
}
|
||||||
|
lazy_static! {
|
||||||
|
static ref GDT: (GlobalDescriptorTable, Selectors) = {
|
||||||
let mut gdt = GlobalDescriptorTable::new();
|
let mut gdt = GlobalDescriptorTable::new();
|
||||||
let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
|
let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
|
||||||
let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS));
|
let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS));
|
||||||
|
@ -33,8 +32,8 @@ static GDT: Lazy<(GlobalDescriptorTable, Selectors)> = Lazy::new(|| {
|
||||||
tss_selector,
|
tss_selector,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
};
|
||||||
|
}
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
use x86_64::instructions::segmentation::{Segment, CS};
|
use x86_64::instructions::segmentation::{Segment, CS};
|
||||||
use x86_64::instructions::tables::load_tss;
|
use x86_64::instructions::tables::load_tss;
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
// #![allow(clippy::print_literal)]
|
// #![allow(clippy::print_literal)]
|
||||||
use super::{gdt, interrupts};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
logger,
|
logger,
|
||||||
scheduler::{capabilities::Capabilities, SCHEDULER},
|
scheduler::{capabilities::Capabilities, SCHEDULER},
|
||||||
serial_println,
|
serial_println,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::{gdt, interrupts};
|
||||||
|
|
||||||
/// x86_64 initialization
|
/// x86_64 initialization
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
use crate::{
|
use crate::network::socket::SimpleSock;
|
||||||
network::socket::SimpleSock, relib::network::socket::Socket,
|
use crate::relib::network::socket::Socket;
|
||||||
scheduler::priority::Priority::High, stdio::StdIO,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut log_socket_id = SimpleSock::new();
|
let mut log_socket_id = SimpleSock::new();
|
||||||
log_socket_id.register_protocol("Logger".to_string());
|
log_socket_id.register_protocol("Logger".to_string());
|
||||||
|
@ -23,9 +22,10 @@ pub fn init() {
|
||||||
}
|
}
|
||||||
Err(err) => error!("{}", err),
|
Err(err) => error!("{}", err),
|
||||||
}
|
}
|
||||||
|
|
||||||
gdt::init();
|
gdt::init();
|
||||||
|
|
||||||
|
use crate::scheduler::priority::Priority::High;
|
||||||
|
use crate::stdio::StdIO;
|
||||||
let mut scheduler = SCHEDULER.lock();
|
let mut scheduler = SCHEDULER.lock();
|
||||||
let process_0 = scheduler.new_process(
|
let process_0 = scheduler.new_process(
|
||||||
Capabilities::empty(),
|
Capabilities::empty(),
|
||||||
|
@ -34,9 +34,11 @@ pub fn init() {
|
||||||
StdIO::new("null".to_string()),
|
StdIO::new("null".to_string()),
|
||||||
);
|
);
|
||||||
scheduler.add_process(process_0);
|
scheduler.add_process(process_0);
|
||||||
|
|
||||||
drop(scheduler);
|
drop(scheduler);
|
||||||
|
|
||||||
interrupts::init_idt();
|
interrupts::init_idt();
|
||||||
|
|
||||||
unsafe { interrupts::PICS.lock().initialize() };
|
unsafe { interrupts::PICS.lock().initialize() };
|
||||||
x86_64::instructions::interrupts::enable();
|
x86_64::instructions::interrupts::enable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,14 @@ use crate::{
|
||||||
print, println,
|
print, println,
|
||||||
rhai_shell::KEYBUFF,
|
rhai_shell::KEYBUFF,
|
||||||
};
|
};
|
||||||
use cpuio::outb;
|
|
||||||
use pic8259::ChainedPics;
|
|
||||||
use spin::Lazy;
|
|
||||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
|
||||||
|
|
||||||
|
use cpuio::outb;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use pic8259::ChainedPics;
|
||||||
|
use spin;
|
||||||
|
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||||
pub const PIC_1_OFFSET: u8 = 32;
|
pub const PIC_1_OFFSET: u8 = 32;
|
||||||
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
||||||
|
|
||||||
pub static PICS: spin::Mutex<ChainedPics> =
|
pub static PICS: spin::Mutex<ChainedPics> =
|
||||||
spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
|
spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ pub enum InterruptIndex {
|
||||||
// SecondInterrupt = PIC_2_OFFSET,
|
// SecondInterrupt = PIC_2_OFFSET,
|
||||||
Cmos = 0x70,
|
Cmos = 0x70,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InterruptIndex {
|
impl InterruptIndex {
|
||||||
fn as_u8(self) -> u8 {
|
fn as_u8(self) -> u8 {
|
||||||
self as u8
|
self as u8
|
||||||
|
@ -33,13 +32,15 @@ impl InterruptIndex {
|
||||||
usize::from(self.as_u8())
|
usize::from(self.as_u8())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn init_idt() {
|
||||||
static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
|
IDT.load();
|
||||||
|
}
|
||||||
|
lazy_static! {
|
||||||
|
static ref IDT: InterruptDescriptorTable = {
|
||||||
let mut idt = InterruptDescriptorTable::new();
|
let mut idt = InterruptDescriptorTable::new();
|
||||||
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
||||||
unsafe {
|
unsafe {
|
||||||
idt.double_fault
|
idt.double_fault.set_handler_fn(double_fault_handler)
|
||||||
.set_handler_fn(double_fault_handler)
|
|
||||||
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,23 +52,20 @@ static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
|
||||||
|
|
||||||
idt[6].set_handler_fn(floppy_disk_interrupt_handler);
|
idt[6].set_handler_fn(floppy_disk_interrupt_handler);
|
||||||
|
|
||||||
idt
|
|
||||||
});
|
|
||||||
|
|
||||||
|
idt
|
||||||
|
};
|
||||||
|
}
|
||||||
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
|
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
|
||||||
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
|
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
|
||||||
}
|
}
|
||||||
|
// new
|
||||||
extern "x86-interrupt" fn double_fault_handler(
|
extern "x86-interrupt" fn double_fault_handler(
|
||||||
stack_frame: InterruptStackFrame,
|
stack_frame: InterruptStackFrame,
|
||||||
error_code: u64,
|
_error_code: u64,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
panic!(
|
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
|
||||||
"EXCEPTION: Error code{}\nDOUBLE FAULT\n{:#?}",
|
|
||||||
error_code, stack_frame
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||||
kernel::tick();
|
kernel::tick();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -75,7 +73,6 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFr
|
||||||
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
|
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||||
use crate::keyboard::{
|
use crate::keyboard::{
|
||||||
CustomLayout, CustomScancodeSet, DecodedKey, DecodedKeyKind, HandleControl, KeyCode,
|
CustomLayout, CustomScancodeSet, DecodedKey, DecodedKeyKind, HandleControl, KeyCode,
|
||||||
|
@ -83,15 +80,14 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
|
||||||
};
|
};
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
use x86_64::instructions::port::Port;
|
use x86_64::instructions::port::Port;
|
||||||
|
lazy_static! {
|
||||||
static KEYBOARD: Lazy<Mutex<Keyboard<CustomLayout, CustomScancodeSet>>> = Lazy::new(|| {
|
static ref KEYBOARD: Mutex<Keyboard<CustomLayout, CustomScancodeSet>> =
|
||||||
Mutex::new(Keyboard::new(
|
Mutex::new(Keyboard::new(
|
||||||
CustomLayout::new_us104key(),
|
CustomLayout::new_us104key(),
|
||||||
CustomScancodeSet::default(),
|
CustomScancodeSet::default(),
|
||||||
HandleControl::Ignore,
|
HandleControl::Ignore
|
||||||
))
|
));
|
||||||
});
|
}
|
||||||
|
|
||||||
let mut keyboard = KEYBOARD.lock();
|
let mut keyboard = KEYBOARD.lock();
|
||||||
let mut port = Port::new(0x60);
|
let mut port = Port::new(0x60);
|
||||||
let scancode: u8 = unsafe { port.read() };
|
let scancode: u8 = unsafe { port.read() };
|
||||||
|
@ -147,10 +143,6 @@ extern "x86-interrupt" fn floppy_disk_interrupt_handler(_stack_frame: InterruptS
|
||||||
println!("EXCEPTION: FLOPPY DISK");
|
println!("EXCEPTION: FLOPPY DISK");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_idt() {
|
|
||||||
IDT.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_pit_frequency(freq: u32) {
|
fn set_pit_frequency(freq: u32) {
|
||||||
let divisor: u16 = (1193180 / freq).try_into().unwrap();
|
let divisor: u16 = (1193180 / freq).try_into().unwrap();
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ pub fn create_example_mapping(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EmptyFrameAllocator;
|
pub struct EmptyFrameAllocator;
|
||||||
|
|
||||||
unsafe impl FrameAllocator<Size4KiB> for EmptyFrameAllocator {
|
unsafe impl FrameAllocator<Size4KiB> for EmptyFrameAllocator {
|
||||||
fn allocate_frame(&mut self) -> Option<PhysFrame<Size4KiB>> {
|
fn allocate_frame(&mut self) -> Option<PhysFrame<Size4KiB>> {
|
||||||
None
|
None
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
|
use crate::arch::drivers::allocator;
|
||||||
|
use bootloader::{entry_point, BootInfo};
|
||||||
|
use x86_64::{
|
||||||
|
instructions::hlt,
|
||||||
|
{structures::paging::Page, VirtAddr},
|
||||||
|
};
|
||||||
|
|
||||||
pub mod drivers;
|
pub mod drivers;
|
||||||
pub mod gdt;
|
pub mod gdt;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
pub mod interrupts;
|
pub mod interrupts;
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
|
|
||||||
use crate::arch::drivers::allocator;
|
|
||||||
use bootloader::{entry_point, BootInfo};
|
|
||||||
use x86_64::{instructions::hlt, VirtAddr};
|
|
||||||
|
|
||||||
entry_point![start];
|
entry_point![start];
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn start(boot_info: &'static BootInfo) -> ! {
|
pub fn start(boot_info: &'static BootInfo) -> ! {
|
||||||
|
@ -16,12 +19,13 @@ pub fn start(boot_info: &'static BootInfo) -> ! {
|
||||||
let mut mapper = unsafe { memory::init(phys_mem_offset) };
|
let mut mapper = unsafe { memory::init(phys_mem_offset) };
|
||||||
let mut frame_allocator =
|
let mut frame_allocator =
|
||||||
unsafe { memory::BootInfoFrameAllocator::init(&boot_info.memory_map) };
|
unsafe { memory::BootInfoFrameAllocator::init(&boot_info.memory_map) };
|
||||||
|
if false {
|
||||||
|
let page = Page::containing_address(VirtAddr::new(0xdeadbeaf000));
|
||||||
|
memory::create_example_mapping(page, &mut mapper, &mut frame_allocator);
|
||||||
|
|
||||||
// let page = Page::containing_address(VirtAddr::new(0xdeadbeaf000));
|
let page_ptr: *mut u64 = page.start_address().as_mut_ptr();
|
||||||
// memory::create_example_mapping(page, &mut mapper, &mut frame_allocator);
|
unsafe { page_ptr.offset(400).write_volatile(0xf021_f077_f065_804e) };
|
||||||
//
|
}
|
||||||
// let page_ptr: *mut u64 = page.start_address().as_mut_ptr();
|
|
||||||
// unsafe { page_ptr.offset(400).write_volatile(0xf021_f077_f065_804e) };
|
|
||||||
|
|
||||||
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
|
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
|
||||||
|
|
||||||
|
@ -50,5 +54,6 @@ pub fn generate_process_pass() -> u128 {
|
||||||
use rdrand::RdRand;
|
use rdrand::RdRand;
|
||||||
let gen = RdRand::new().unwrap();
|
let gen = RdRand::new().unwrap();
|
||||||
|
|
||||||
(gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128)
|
let ret = (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128);
|
||||||
|
ret
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@ pub struct KernelConfig {
|
||||||
|
|
||||||
impl KernelConfig {
|
impl KernelConfig {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
toml::from_str(include_str!("../assets/kernel.toml")).unwrap()
|
let p: KernelConfig = toml::from_str(include_str!("../assets/kernel.toml")).unwrap();
|
||||||
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_level(&self) -> LevelFilter {
|
pub fn log_level(&self) -> LevelFilter {
|
||||||
|
@ -42,12 +43,6 @@ impl KernelConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for KernelConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Debug, Deserialize)]
|
#[derive(Serialize, Debug, Deserialize)]
|
||||||
pub struct LoggingConfig {
|
pub struct LoggingConfig {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use kernel::device_interface::character::CharacterDevice;
|
use kernel::device_interface::character::CharacterDevice;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
|
||||||
pub struct DevNull;
|
pub struct DevNull;
|
||||||
|
|
||||||
impl CharacterDevice for DevNull {
|
impl CharacterDevice for DevNull {
|
||||||
fn can_read(&self) -> bool {
|
fn can_read(&self) -> bool {
|
||||||
true
|
true
|
||||||
|
|
|
@ -44,6 +44,5 @@ fn add1_char(c: char) -> char {
|
||||||
if c == char::MAX {
|
if c == char::MAX {
|
||||||
return 0x00 as char;
|
return 0x00 as char;
|
||||||
}
|
}
|
||||||
|
|
||||||
char::from_u32(c as u32 + 1).unwrap()
|
char::from_u32(c as u32 + 1).unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use kernel::device_interface::character::CharacterDevice;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DevZero;
|
pub struct DevZero;
|
||||||
|
|
||||||
impl CharacterDevice for DevZero {
|
impl CharacterDevice for DevZero {
|
||||||
fn can_read(&self) -> bool {
|
fn can_read(&self) -> bool {
|
||||||
true
|
true
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
pub mod dev_null;
|
pub mod dev_null;
|
||||||
pub mod dev_unicode;
|
pub mod dev_unicode;
|
||||||
|
|
||||||
pub mod dev_zero;
|
pub mod dev_zero;
|
||||||
|
|
||||||
pub use kernel::device_interface::character::CharacterDevice;
|
pub use kernel::device_interface::character::CharacterDevice;
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
// ! A virtual terminal device.
|
// ! A virtual terminal device.
|
||||||
|
|
||||||
use core::ops::Not;
|
|
||||||
use core::sync::atomic::AtomicU32;
|
|
||||||
use core::sync::atomic::Ordering;
|
|
||||||
use kernel::device_interface::character::CharacterDevice;
|
use kernel::device_interface::character::CharacterDevice;
|
||||||
use shadeable::pixel_format::Rgba64;
|
|
||||||
|
|
||||||
|
use core::ops::Not;
|
||||||
|
use shadeable::pixel_format::Rgba64;
|
||||||
pub const VTERM_HEIGHT: u32 = 40;
|
pub const VTERM_HEIGHT: u32 = 40;
|
||||||
pub const VTERM_WIDTH: u32 = 100;
|
pub const VTERM_WIDTH: u32 = 100;
|
||||||
|
|
||||||
pub static VIRTUAL_TERMINAL_COUNT: AtomicU32 = AtomicU32::new(0);
|
|
||||||
|
|
||||||
/// Fg and bg colors for vterm
|
/// Fg and bg colors for vterm
|
||||||
pub type ColorCharacter = (Rgba64, Rgba64);
|
pub type ColorCharacter = (Rgba64, Rgba64);
|
||||||
|
|
||||||
/// A vterm representation of a character
|
/// A vterm representation of a character
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct VtermCharacter {
|
pub struct VtermCharacter {
|
||||||
|
@ -31,27 +25,21 @@ impl Style {
|
||||||
pub fn bold(&self) -> bool {
|
pub fn bold(&self) -> bool {
|
||||||
(self.0 & 0x01) > 0
|
(self.0 & 0x01) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn underlined(&self) -> bool {
|
pub fn underlined(&self) -> bool {
|
||||||
(self.0 & 0x02) > 0
|
(self.0 & 0x02) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn italic(&self) -> bool {
|
pub fn italic(&self) -> bool {
|
||||||
(self.0 & 0x04) > 0
|
(self.0 & 0x04) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn blinking(&self) -> bool {
|
pub fn blinking(&self) -> bool {
|
||||||
(self.0 & 0x08) > 0
|
(self.0 & 0x08) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reversed(&self) -> bool {
|
pub fn reversed(&self) -> bool {
|
||||||
(self.0 & 0x10) > 0
|
(self.0 & 0x10) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn struck(&self) -> bool {
|
pub fn struck(&self) -> bool {
|
||||||
(self.0 & 0x20) > 0
|
(self.0 & 0x20) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn set_bold(mut self, v: bool) -> Self {
|
pub fn set_bold(mut self, v: bool) -> Self {
|
||||||
if v {
|
if v {
|
||||||
|
@ -61,7 +49,6 @@ impl Style {
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn set_underlined(mut self, v: bool) -> Self {
|
pub fn set_underlined(mut self, v: bool) -> Self {
|
||||||
if v {
|
if v {
|
||||||
|
@ -71,7 +58,6 @@ impl Style {
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn set_italic(mut self, v: bool) -> Self {
|
pub fn set_italic(mut self, v: bool) -> Self {
|
||||||
if v {
|
if v {
|
||||||
|
@ -81,7 +67,6 @@ impl Style {
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn set_blinking(mut self, v: bool) -> Self {
|
pub fn set_blinking(mut self, v: bool) -> Self {
|
||||||
if v {
|
if v {
|
||||||
|
@ -91,7 +76,6 @@ impl Style {
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn set_reversed(mut self, v: bool) -> Self {
|
pub fn set_reversed(mut self, v: bool) -> Self {
|
||||||
if v {
|
if v {
|
||||||
|
@ -101,7 +85,6 @@ impl Style {
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn set_struck(mut self, v: bool) -> Self {
|
pub fn set_struck(mut self, v: bool) -> Self {
|
||||||
if v {
|
if v {
|
||||||
|
@ -112,23 +95,18 @@ impl Style {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct VTerm {
|
pub struct VTerm {
|
||||||
pub characters: [[VtermCharacter; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize],
|
|
||||||
pub cursor_visible: bool,
|
|
||||||
|
|
||||||
/// Internal ID of the vterm
|
/// Internal ID of the vterm
|
||||||
iid: u32,
|
iid: u32,
|
||||||
|
pub characters: [[VtermCharacter; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize],
|
||||||
/// The internal representation of the vterm
|
/// The internal representation of the vterm
|
||||||
style: Style,
|
style: Style,
|
||||||
|
|
||||||
/// The cursor position in layout x,y
|
/// The cursor position in layout x,y
|
||||||
cursor_position: (u32, u32),
|
cursor_position: (u32, u32),
|
||||||
|
pub cursor_visible: bool,
|
||||||
key_buff: Vec<char>,
|
key_buff: Vec<char>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for VTerm {
|
impl Default for VTerm {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
VTerm {
|
VTerm {
|
||||||
|
@ -172,7 +150,6 @@ impl VTerm {
|
||||||
self.cursor_position.1 = y;
|
self.cursor_position.1 = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the vterm style
|
/// Set the vterm style
|
||||||
pub fn set_vterm_style(&mut self, style: Style) {
|
pub fn set_vterm_style(&mut self, style: Style) {
|
||||||
self.style = style;
|
self.style = style;
|
||||||
|
@ -200,30 +177,30 @@ impl CharacterDevice for VTerm {
|
||||||
'\n' => {
|
'\n' => {
|
||||||
self.cursor_position.1 += 1;
|
self.cursor_position.1 += 1;
|
||||||
self.cursor_position.0 = 0;
|
self.cursor_position.0 = 0;
|
||||||
true
|
return true;
|
||||||
}
|
}
|
||||||
'\r' => {
|
'\r' => {
|
||||||
self.cursor_position.0 = 0;
|
self.cursor_position.0 = 0;
|
||||||
true
|
return true;
|
||||||
}
|
}
|
||||||
'\t' => {
|
'\t' => {
|
||||||
self.cursor_position.0 += 4;
|
self.cursor_position.0 += 4;
|
||||||
true
|
return true;
|
||||||
}
|
}
|
||||||
'\x08' => {
|
'\x08' => {
|
||||||
self.cursor_position.0 -= 1;
|
self.cursor_position.0 -= 1;
|
||||||
self.characters[self.cursor_position.1 as usize][self.cursor_position.0 as usize]
|
self.characters[self.cursor_position.1 as usize][self.cursor_position.0 as usize]
|
||||||
.character = ' ';
|
.character = ' ';
|
||||||
true
|
return true;
|
||||||
}
|
}
|
||||||
// This is a form feed, which is used to clear the screen
|
/// This is a form feed, which is used to clear the screen
|
||||||
'\x0c' => {
|
'\x0c' => {
|
||||||
self.characters = [[VtermCharacter {
|
self.characters = [[VtermCharacter {
|
||||||
character: ' ',
|
character: ' ',
|
||||||
char_color: (0xff_ff_ff_ff, 0x00_00_00_00),
|
char_color: (0xff_ff_ff_ff, 0x00_00_00_00),
|
||||||
style: Style::default(),
|
style: Style::default(),
|
||||||
}; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize];
|
}; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize];
|
||||||
true
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -236,11 +213,11 @@ impl CharacterDevice for VTerm {
|
||||||
|
|
||||||
if self.cursor_position.0 < VTERM_WIDTH {
|
if self.cursor_position.0 < VTERM_WIDTH {
|
||||||
self.cursor_position.0 += 1;
|
self.cursor_position.0 += 1;
|
||||||
true
|
return true;
|
||||||
} else {
|
} else {
|
||||||
self.cursor_position.0 = 0;
|
self.cursor_position.0 = 0;
|
||||||
self.cursor_position.1 += 1;
|
self.cursor_position.1 += 1;
|
||||||
true
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,7 +229,6 @@ impl CharacterDevice for VTerm {
|
||||||
char_color: (0xff_ff_ff_ff, 0x00_00_00_00),
|
char_color: (0xff_ff_ff_ff, 0x00_00_00_00),
|
||||||
style: Style::default(),
|
style: Style::default(),
|
||||||
}; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize];
|
}; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize];
|
||||||
|
|
||||||
self.cursor_position = (0, 0);
|
self.cursor_position = (0, 0);
|
||||||
self.cursor_visible = true;
|
self.cursor_visible = true;
|
||||||
self.style = Style::default();
|
self.style = Style::default();
|
||||||
|
@ -262,3 +238,9 @@ impl CharacterDevice for VTerm {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref VIRTUAL_TERMINAL_COUNT: AtomicU32 = AtomicU32::new(0);
|
||||||
|
}
|
||||||
|
use core::sync::atomic::AtomicU32;
|
||||||
|
use core::sync::atomic::Ordering;
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Vendor {
|
pub enum Vendor {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
|
|
||||||
Ati = 1002,
|
Ati = 1002,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn match_vendor(id: u16) -> Vendor {
|
pub fn match_vendor(id: u16) -> Vendor {
|
||||||
use Vendor::*;
|
use Vendor::*;
|
||||||
|
|
||||||
match id {
|
match id {
|
||||||
1002 => Ati,
|
1002 => Ati,
|
||||||
|
|
||||||
_ => Unknown,
|
_ => Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,57 +2,42 @@ pub mod character_devs;
|
||||||
pub mod id;
|
pub mod id;
|
||||||
pub mod pci_inner;
|
pub mod pci_inner;
|
||||||
|
|
||||||
mod dev_vterm;
|
|
||||||
|
|
||||||
pub use self::Device::*;
|
|
||||||
|
|
||||||
use crate::devices::dev_vterm::VTerm;
|
|
||||||
use character_devs::{dev_null::DevNull, dev_unicode::DevUnicode, dev_zero::DevZero};
|
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
mod dev_vterm;
|
||||||
|
use crate::devices::dev_vterm::VTerm;
|
||||||
use kernel::device_interface::character::CharacterDevice;
|
use kernel::device_interface::character::CharacterDevice;
|
||||||
use spin::Lazy;
|
|
||||||
|
|
||||||
pub static DEVICE_TABLE: Lazy<spin::Mutex<DeviceTable>> =
|
|
||||||
Lazy::new(|| spin::Mutex::new(DeviceTable::new()));
|
|
||||||
|
|
||||||
// FIXME: This is a hack to hold a device.
|
// FIXME: This is a hack to hold a device.
|
||||||
// #[derive(Debug)]
|
// #[derive(Debug)]
|
||||||
pub enum Device {
|
pub enum Device {
|
||||||
Character(Box<dyn CharacterDevice>),
|
Character(Box<dyn CharacterDevice>),
|
||||||
Vterm(Box<VTerm>),
|
Vterm(VTerm),
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Sync for Device {}
|
unsafe impl Sync for Device {}
|
||||||
unsafe impl Send for Device {}
|
unsafe impl Send for Device {}
|
||||||
|
|
||||||
pub struct DeviceTable {
|
pub struct DeviceTable {
|
||||||
pub devices: HashMap<String, Device>,
|
pub devices: HashMap<String, Device>,
|
||||||
}
|
}
|
||||||
|
use self::character_devs::{dev_null::DevNull, dev_unicode::DevUnicode, dev_zero::DevZero};
|
||||||
|
pub use self::Device::*;
|
||||||
impl DeviceTable {
|
impl DeviceTable {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
DeviceTable {
|
let mut table: HashMap<String, Device> = HashMap::new();
|
||||||
devices: [
|
table.insert("null".to_string(), Character(Box::new(DevNull)));
|
||||||
("null", Character(Box::new(DevNull))),
|
table.insert("zero".to_string(), Character(Box::new(DevZero)));
|
||||||
("zero", Character(Box::new(DevZero))),
|
table.insert(
|
||||||
(
|
"unicode".to_string(),
|
||||||
"unicode",
|
|
||||||
Character(Box::new(DevUnicode {
|
Character(Box::new(DevUnicode {
|
||||||
next_write_char: 0x00 as char,
|
next_write_char: 0x00 as char,
|
||||||
next_read_char: 0x00 as char,
|
next_read_char: 0x00 as char,
|
||||||
})),
|
})),
|
||||||
),
|
);
|
||||||
("kvterm", Vterm(Box::new(VTerm::new()))),
|
table.insert("kvterm".to_string(), Vterm(VTerm::new()));
|
||||||
]
|
DeviceTable { devices: table }
|
||||||
.into_iter()
|
|
||||||
.map(|(k, v)| (k.to_string(), v))
|
|
||||||
.collect(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DeviceTable {
|
lazy_static::lazy_static!(
|
||||||
fn default() -> Self {
|
pub static ref DEVICE_TABLE: spin::Mutex<DeviceTable> =
|
||||||
Self::new()
|
spin::Mutex::new(DeviceTable::new());
|
||||||
}
|
);
|
||||||
}
|
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
//!
|
//!
|
||||||
//!
|
//!
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn scan_pci_bus() {}
|
||||||
|
|
||||||
pub enum Vendors {
|
pub enum Vendors {
|
||||||
ThreeDfxInteractiveInc = 0x121a,
|
ThreeDfxInteractiveInc = 0x121a,
|
||||||
ThreeDLabs = 0x3d3d,
|
ThreeDLabs = 0x3d3d,
|
||||||
|
@ -50,6 +53,3 @@ pub enum Vendors {
|
||||||
pub struct PciDevice {
|
pub struct PciDevice {
|
||||||
pub vendor: Vendors,
|
pub vendor: Vendors,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn scan_pci_bus() {}
|
|
||||||
|
|
|
@ -1,21 +1,16 @@
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
|
||||||
pub const REFRESH_RATE: u8 = 60;
|
|
||||||
|
|
||||||
pub type RefreshRate = u8;
|
|
||||||
pub type Resolution = (usize, usize);
|
|
||||||
pub type Point = (GCoord, GCoord);
|
|
||||||
pub type GCoord = usize;
|
|
||||||
|
|
||||||
pub enum GModes {
|
pub enum GModes {
|
||||||
Vga800x600,
|
Vga800x600,
|
||||||
Custom(u16, u16),
|
Custom(u16, u16),
|
||||||
}
|
}
|
||||||
|
pub type GCoord = usize;
|
||||||
|
|
||||||
// TODO remap to a bitmasked u32
|
// TODO remap to a bitmasked u32
|
||||||
// REASON: More effecient memory wise so less overhead on the wasm memory
|
/* REASON: More effecient memory wise so less overhead on the wasm memory
|
||||||
// Current: u32+u32+u32
|
Current: u32+u32+u32
|
||||||
// Proposed: u32 with bitmaps
|
Proposed: u32 with bitmaps
|
||||||
|
*/
|
||||||
|
|
||||||
pub struct Rgb {
|
pub struct Rgb {
|
||||||
pub r: u32,
|
pub r: u32,
|
||||||
pub g: u32,
|
pub g: u32,
|
||||||
|
@ -27,8 +22,13 @@ impl Rgb {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub type RefreshRate = u8;
|
||||||
|
|
||||||
|
pub const REFRESH_RATE: u8 = 60;
|
||||||
|
pub type Resolution = (usize, usize);
|
||||||
|
pub type Point = (GCoord, GCoord);
|
||||||
pub struct FrameBuffer;
|
pub struct FrameBuffer;
|
||||||
|
// [[Rgb; 5]; 5]
|
||||||
pub trait Graphics {
|
pub trait Graphics {
|
||||||
fn put_line(coords_start: Point, coords_end: Point, thickness: u32, color: Rgb);
|
fn put_line(coords_start: Point, coords_end: Point, thickness: u32, color: Rgb);
|
||||||
fn put_rect(coords_start: Point, coords_end: Point, color: Rgb);
|
fn put_rect(coords_start: Point, coords_end: Point, color: Rgb);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
// TODO: Bitmasking
|
// TODO: Bitmasking
|
||||||
pub enum Mouse {
|
pub enum Mouse {
|
||||||
Button1,
|
Button1,
|
||||||
|
|
|
@ -3,7 +3,6 @@ use kernel::device_interface::character::CharacterDevice;
|
||||||
pub struct Serial {
|
pub struct Serial {
|
||||||
pub base: usize,
|
pub base: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CharacterDevice for Serial {
|
impl CharacterDevice for Serial {
|
||||||
fn can_read(&self) -> bool {
|
fn can_read(&self) -> bool {
|
||||||
true
|
true
|
||||||
|
@ -17,7 +16,7 @@ impl CharacterDevice for Serial {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_char(&mut self, _c: char) -> bool {
|
fn write_char(&mut self, c: char) -> bool {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +28,6 @@ impl CharacterDevice for Serial {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_serial_test() {
|
pub fn new_serial_test() {
|
||||||
let mut serial = Serial { base: 0x3F8 };
|
let mut serial = Serial { base: 0x3F8 };
|
||||||
serial.initialize();
|
serial.initialize();
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use logos::{Lexer, Logos};
|
|
||||||
|
|
||||||
// TODO improve tokenizer/parser
|
// TODO improve tokenizer/parser
|
||||||
|
|
||||||
pub fn colorify(eval: &str) {
|
pub fn colorify(eval: &str) {
|
||||||
let y = eval.split('$');
|
let y = eval.split("$");
|
||||||
for z in y {
|
for z in y {
|
||||||
match z {
|
match z {
|
||||||
"BLACK" => {
|
"BLACK" => {
|
||||||
|
@ -56,13 +55,15 @@ pub fn colorify(eval: &str) {
|
||||||
"RESET" => {
|
"RESET" => {
|
||||||
// set_vga_color(Color::White, Color::Black);
|
// set_vga_color(Color::White, Color::Black);
|
||||||
}
|
}
|
||||||
_elk => {
|
elk => {
|
||||||
// kprint!("{}", elk);
|
// kprint!("{}", elk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use logos::Logos;
|
||||||
|
|
||||||
#[derive(Logos, Debug, PartialEq)]
|
#[derive(Logos, Debug, PartialEq)]
|
||||||
pub enum Token {
|
pub enum Token {
|
||||||
// Hex(u32),
|
// Hex(u32),
|
||||||
|
@ -79,7 +80,6 @@ pub enum Token {
|
||||||
#[regex(r"[ \t\n\f]+", logos::skip)]
|
#[regex(r"[ \t\n\f]+", logos::skip)]
|
||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn colorify_2(eval: &str) {
|
pub fn colorify_2(eval: &str) {
|
||||||
let lexer = Token::lexer(eval);
|
let lexer = Token::lexer(eval);
|
||||||
for token in lexer {
|
for token in lexer {
|
||||||
|
@ -91,7 +91,7 @@ pub fn colorify_2(eval: &str) {
|
||||||
Reset => {
|
Reset => {
|
||||||
// set_vga_color(Color::White, Color::Black);
|
// set_vga_color(Color::White, Color::Black);
|
||||||
}
|
}
|
||||||
Text(_text) => {
|
Text(text) => {
|
||||||
// kprint!("{}", text);
|
// kprint!("{}", text);
|
||||||
}
|
}
|
||||||
err => {
|
err => {
|
||||||
|
@ -100,7 +100,9 @@ pub fn colorify_2(eval: &str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
use logos::Lexer;
|
||||||
|
|
||||||
|
// use crate::kprint;
|
||||||
fn parse_text(lex: &mut Lexer<Token>) -> Option<String> {
|
fn parse_text(lex: &mut Lexer<Token>) -> Option<String> {
|
||||||
let slice = lex.slice();
|
let slice = lex.slice();
|
||||||
Some(String::from(slice))
|
Some(String::from(slice))
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
use alloc::{string::String, vec, vec::Vec};
|
use alloc::{string::String, vec, vec::Vec};
|
||||||
|
// use crate::String;
|
||||||
pub static CLIPBOARD: spin::Mutex<Clipboard> = spin::Mutex::new(Clipboard::new());
|
// use crate::Vec;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Mime {
|
pub enum Mime {
|
||||||
None,
|
None,
|
||||||
Text(String),
|
Text(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref CLIPBOARD: spin::Mutex<Clipboard> = {
|
||||||
|
let clipboard = Clipboard::new();
|
||||||
|
spin::Mutex::new(clipboard)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// ctrl+v paste but not pop and pastes
|
// ctrl+v paste but not pop and pastes
|
||||||
// ctrl+shift+v pops from the stack and pastes
|
// ctrl+shift+v pops from the stack and pastes
|
||||||
// ctrl+c pushes to the stack
|
// ctrl+c pushes to the stack
|
||||||
|
@ -18,36 +25,30 @@ pub struct Clipboard {
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
pub pages: Vec<Mime>,
|
pub pages: Vec<Mime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clipboard {
|
impl Clipboard {
|
||||||
pub const fn new() -> Clipboard {
|
pub fn new() -> Clipboard {
|
||||||
Clipboard {
|
Clipboard {
|
||||||
index: 0,
|
index: 0,
|
||||||
pages: vec![],
|
pages: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
self.pages = vec![];
|
self.pages = vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_index(&mut self, index_new: usize) {
|
pub fn set_index(&mut self, index_new: usize) {
|
||||||
self.index = index_new;
|
self.index = index_new;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clip_end(&mut self) {
|
pub fn clip_end(&mut self) {
|
||||||
self.index = 0;
|
self.index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clip_home(&mut self) {
|
pub fn clip_home(&mut self) {
|
||||||
self.index = self.pages.len();
|
self.index = self.pages.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy(&mut self, copy_mime: Mime) {
|
pub fn copy(&mut self, copy_mime: Mime) {
|
||||||
self.pages.push(copy_mime);
|
self.pages.push(copy_mime);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn paste(&mut self) -> &Mime {
|
pub fn paste(&mut self) -> &Mime {
|
||||||
&self.pages[self.index] as _
|
let paste_pos = &self.pages[self.index];
|
||||||
|
paste_pos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
|
|
||||||
|
// pub struct Duration {}
|
||||||
|
|
||||||
pub struct AtomicU32(u32);
|
pub struct AtomicU32(u32);
|
||||||
|
|
||||||
impl AtomicU32 {
|
impl AtomicU32 {
|
||||||
//if v != current value
|
//if v != current value
|
||||||
pub fn wait(&self, _v: u32) {
|
pub fn wait(&self, _v: u32) {
|
||||||
|
@ -18,8 +21,9 @@ impl AtomicU32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
// SUPER HANDWAVEY
|
|
||||||
// YOU WILL NEED LOCKING THAT I DIDNT WRITE OUT (you == zuurr#9735)
|
SUPER HANDWAVEY
|
||||||
|
YOU WILL NEED LOCKING THAT I DIDNT WRITE OUT (you == zuurr#9735)
|
||||||
|
|
||||||
// all the red is by design
|
// all the red is by design
|
||||||
pub fn futex_wait(atom: &AtomicU32, value: usize, current_thread: ThreadID) {
|
pub fn futex_wait(atom: &AtomicU32, value: usize, current_thread: ThreadID) {
|
||||||
|
@ -40,6 +44,7 @@ pub fn futex_wake(atom: &AtomicU32, threads_to_wake: usize) {
|
||||||
waiting_thread.wake()
|
waiting_thread.wake()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct FutexWaitlist {
|
struct FutexWaitlist {
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
#![cfg_attr(
|
||||||
|
not(any(target_arch = "x86_64", target_arch = "x86")),
|
||||||
|
allow(dead_code)
|
||||||
|
)]
|
||||||
|
|
||||||
//! ```
|
//! ```
|
||||||
//! extern crate cupid;
|
//! extern crate cupid;
|
||||||
//!
|
//!
|
||||||
|
@ -12,50 +17,10 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![cfg_attr(
|
|
||||||
not(any(target_arch = "x86_64", target_arch = "x86")),
|
|
||||||
allow(dead_code)
|
|
||||||
)]
|
|
||||||
|
|
||||||
use core::arch::asm;
|
use core::arch::asm;
|
||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
use core::{fmt, slice, str};
|
use core::{fmt, slice, str};
|
||||||
|
|
||||||
// 3 calls of 4 registers of 4 bytes
|
|
||||||
const BRAND_STRING_LENGTH: usize = 3 * 4 * 4;
|
|
||||||
|
|
||||||
macro_rules! bit {
|
|
||||||
($reg:ident, {$($idx:expr => $name:ident),+ $(,)?}) => {
|
|
||||||
$(pub fn $name(self) -> bool {
|
|
||||||
((self.$reg >> $idx) & 1) != 0
|
|
||||||
})+
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! dump {
|
|
||||||
($me:expr, $f: expr, $sname:expr, {$($name:ident),+ $(,)?}) => {
|
|
||||||
$f.debug_struct($sname)
|
|
||||||
$(.field(stringify!($name), &$me.$name()))+
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! delegate_flag {
|
|
||||||
($item:ident, {$($name:ident),+ $(,)?}) => {
|
|
||||||
$(pub fn $name(&self) -> bool {
|
|
||||||
self.$item.map(|i| i.$name()).unwrap_or(false)
|
|
||||||
})+
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! master_attr_reader {
|
|
||||||
($name:ident, $kind:ty) => {
|
|
||||||
pub fn $name(&self) -> Option<&$kind> {
|
|
||||||
self.$name.as_ref()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
pub enum RequestType {
|
pub enum RequestType {
|
||||||
BasicInformation = 0x00000000,
|
BasicInformation = 0x00000000,
|
||||||
|
@ -73,6 +38,85 @@ pub enum RequestType {
|
||||||
PhysicalAddressSize = 0x80000008,
|
PhysicalAddressSize = 0x80000008,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cpuid(code: RequestType) -> (u32, u32, u32, u32) {
|
||||||
|
let eax;
|
||||||
|
let ebx;
|
||||||
|
let ecx;
|
||||||
|
let edx;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
asm!(
|
||||||
|
"movq %rbx, {0:r}",
|
||||||
|
"cpuid",
|
||||||
|
"xchgq %rbx, {0:r}",
|
||||||
|
lateout(reg) ebx,
|
||||||
|
inlateout("eax") code as u32 => eax,
|
||||||
|
inlateout("ecx") 0 => ecx,
|
||||||
|
lateout("edx") edx,
|
||||||
|
options(nostack, preserves_flags, att_syntax),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
(eax, ebx, ecx, edx)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The main entrypoint to the CPU information
|
||||||
|
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
||||||
|
pub fn master() -> Option<Master> {
|
||||||
|
Some(Master::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
// This matches the Intel Architecture guide, with bits 31 -> 0.
|
||||||
|
// The bit positions are inclusive.
|
||||||
|
fn bits_of(val: u32, start_bit: u8, end_bit: u8) -> u32 {
|
||||||
|
let mut silly = 0;
|
||||||
|
|
||||||
|
for _ in start_bit..end_bit + 1 {
|
||||||
|
silly <<= 1;
|
||||||
|
silly |= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(val >> start_bit) & silly
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_bytes(v: &u32) -> &[u8] {
|
||||||
|
let start = v as *const u32 as *const u8;
|
||||||
|
// TODO: use u32::BYTES
|
||||||
|
unsafe { slice::from_raw_parts(start, 4) }
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! bit {
|
||||||
|
($reg:ident, {$($idx:expr => $name:ident),+}) => {
|
||||||
|
$(pub fn $name(self) -> bool {
|
||||||
|
((self.$reg >> $idx) & 1) != 0
|
||||||
|
})+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! dump {
|
||||||
|
($me:expr, $f: expr, $sname:expr, {$($name:ident),+}) => {
|
||||||
|
$f.debug_struct($sname)
|
||||||
|
$(.field(stringify!($name), &$me.$name()))+
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! delegate_flag {
|
||||||
|
($item:ident, {$($name:ident),+}) => {
|
||||||
|
$(pub fn $name(&self) -> bool {
|
||||||
|
self.$item.map(|i| i.$name()).unwrap_or(false)
|
||||||
|
})+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! master_attr_reader {
|
||||||
|
($name:ident, $kind:ty) => {
|
||||||
|
pub fn $name(&self) -> Option<&$kind> {
|
||||||
|
self.$name.as_ref()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct VersionInformation {
|
pub struct VersionInformation {
|
||||||
eax: u32,
|
eax: u32,
|
||||||
|
@ -202,8 +246,8 @@ impl VersionInformation {
|
||||||
27 => osxsave,
|
27 => osxsave,
|
||||||
28 => avx,
|
28 => avx,
|
||||||
29 => f16c,
|
29 => f16c,
|
||||||
30 => rdrand,
|
30 => rdrand
|
||||||
// 31 - unused,
|
// 31 - unused
|
||||||
});
|
});
|
||||||
|
|
||||||
bit!(edx, {
|
bit!(edx, {
|
||||||
|
@ -238,16 +282,10 @@ impl VersionInformation {
|
||||||
28 => htt,
|
28 => htt,
|
||||||
29 => tm,
|
29 => tm,
|
||||||
// 30 -reserved
|
// 30 -reserved
|
||||||
31 => pbe,
|
31 => pbe
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for VersionInformation {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for VersionInformation {
|
impl fmt::Debug for VersionInformation {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
dump!(self, f, "VersionInformation", {
|
dump!(self, f, "VersionInformation", {
|
||||||
|
@ -313,7 +351,7 @@ impl fmt::Debug for VersionInformation {
|
||||||
ss,
|
ss,
|
||||||
htt,
|
htt,
|
||||||
tm,
|
tm,
|
||||||
pbe,
|
pbe
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,7 +373,7 @@ impl ExtendedProcessorSignature {
|
||||||
// 1-4 reserved
|
// 1-4 reserved
|
||||||
5 => lzcnt,
|
5 => lzcnt,
|
||||||
// 6-7 reserved
|
// 6-7 reserved
|
||||||
8 => prefetchw,
|
8 => prefetchw
|
||||||
// 9-31 reserved
|
// 9-31 reserved
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -348,7 +386,7 @@ impl ExtendedProcessorSignature {
|
||||||
26 => gigabyte_pages,
|
26 => gigabyte_pages,
|
||||||
27 => rdtscp_and_ia32_tsc_aux,
|
27 => rdtscp_and_ia32_tsc_aux,
|
||||||
// 28 reserved
|
// 28 reserved
|
||||||
29 => intel_64_bit_architecture,
|
29 => intel_64_bit_architecture
|
||||||
// 30-31 reserved
|
// 30-31 reserved
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -363,11 +401,14 @@ impl fmt::Debug for ExtendedProcessorSignature {
|
||||||
execute_disable,
|
execute_disable,
|
||||||
gigabyte_pages,
|
gigabyte_pages,
|
||||||
rdtscp_and_ia32_tsc_aux,
|
rdtscp_and_ia32_tsc_aux,
|
||||||
intel_64_bit_architecture,
|
intel_64_bit_architecture
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3 calls of 4 registers of 4 bytes
|
||||||
|
const BRAND_STRING_LENGTH: usize = 3 * 4 * 4;
|
||||||
|
|
||||||
pub struct BrandString {
|
pub struct BrandString {
|
||||||
bytes: [u8; BRAND_STRING_LENGTH],
|
bytes: [u8; BRAND_STRING_LENGTH],
|
||||||
}
|
}
|
||||||
|
@ -404,7 +445,7 @@ impl Clone for BrandString {
|
||||||
for (d, s) in bytes.iter_mut().zip(self.bytes.iter()) {
|
for (d, s) in bytes.iter_mut().zip(self.bytes.iter()) {
|
||||||
*d = *s;
|
*d = *s;
|
||||||
}
|
}
|
||||||
BrandString { bytes }
|
BrandString { bytes: bytes }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,7 +501,7 @@ impl ThermalPowerManagementInformation {
|
||||||
9 => hwp_activity_window,
|
9 => hwp_activity_window,
|
||||||
10 => hwp_energy_performance_preference,
|
10 => hwp_energy_performance_preference,
|
||||||
// 12 - reserved
|
// 12 - reserved
|
||||||
13 => hdc,
|
13 => hdc
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn number_of_interrupt_thresholds(self) -> u32 {
|
pub fn number_of_interrupt_thresholds(self) -> u32 {
|
||||||
|
@ -488,7 +529,9 @@ impl fmt::Debug for ThermalPowerManagementInformation {
|
||||||
hwp_activity_window,
|
hwp_activity_window,
|
||||||
hwp_energy_performance_preference,
|
hwp_energy_performance_preference,
|
||||||
hdc,
|
hdc,
|
||||||
|
|
||||||
number_of_interrupt_thresholds,
|
number_of_interrupt_thresholds,
|
||||||
|
|
||||||
hardware_coordination_feedback,
|
hardware_coordination_feedback,
|
||||||
performance_energy_bias
|
performance_energy_bias
|
||||||
})
|
})
|
||||||
|
@ -529,7 +572,7 @@ impl StructuredExtendedInformation {
|
||||||
19 => adx,
|
19 => adx,
|
||||||
20 => smap,
|
20 => smap,
|
||||||
// 21-24 - reserved
|
// 21-24 - reserved
|
||||||
25 => intel_processor_trace,
|
25 => intel_processor_trace
|
||||||
// 26-31 - reserved
|
// 26-31 - reserved
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -558,7 +601,7 @@ impl fmt::Debug for StructuredExtendedInformation {
|
||||||
adx,
|
adx,
|
||||||
smap,
|
smap,
|
||||||
intel_processor_trace,
|
intel_processor_trace,
|
||||||
prefetchwt1,
|
prefetchwt1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -576,6 +619,7 @@ pub enum CacheLineAssociativity {
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct CacheLine(u32);
|
pub struct CacheLine(u32);
|
||||||
|
|
||||||
impl CacheLine {
|
impl CacheLine {
|
||||||
fn new() -> CacheLine {
|
fn new() -> CacheLine {
|
||||||
let (_, _, c, _) = cpuid(RequestType::CacheLine);
|
let (_, _, c, _) = cpuid(RequestType::CacheLine);
|
||||||
|
@ -640,6 +684,7 @@ impl fmt::Debug for TimeStampCounter {
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct PhysicalAddressSize(u32);
|
pub struct PhysicalAddressSize(u32);
|
||||||
|
|
||||||
impl PhysicalAddressSize {
|
impl PhysicalAddressSize {
|
||||||
fn new() -> PhysicalAddressSize {
|
fn new() -> PhysicalAddressSize {
|
||||||
let (a, _, _, _) = cpuid(RequestType::PhysicalAddressSize);
|
let (a, _, _, _) = cpuid(RequestType::PhysicalAddressSize);
|
||||||
|
@ -707,12 +752,12 @@ impl Master {
|
||||||
let tpm = when_supported(
|
let tpm = when_supported(
|
||||||
max_value,
|
max_value,
|
||||||
RequestType::ThermalPowerManagementInformation,
|
RequestType::ThermalPowerManagementInformation,
|
||||||
ThermalPowerManagementInformation::new,
|
|| ThermalPowerManagementInformation::new(),
|
||||||
);
|
);
|
||||||
let sei = when_supported(
|
let sei = when_supported(
|
||||||
max_value,
|
max_value,
|
||||||
RequestType::StructuredExtendedInformation,
|
RequestType::StructuredExtendedInformation,
|
||||||
StructuredExtendedInformation::new,
|
|| StructuredExtendedInformation::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Extended information
|
// Extended information
|
||||||
|
@ -722,8 +767,9 @@ impl Master {
|
||||||
let eps = when_supported(max_value, RequestType::ExtendedProcessorSignature, || {
|
let eps = when_supported(max_value, RequestType::ExtendedProcessorSignature, || {
|
||||||
ExtendedProcessorSignature::new()
|
ExtendedProcessorSignature::new()
|
||||||
});
|
});
|
||||||
let brand_string = when_supported(max_value, RequestType::BrandString3, BrandString::new);
|
let brand_string =
|
||||||
let cache_line = when_supported(max_value, RequestType::CacheLine, CacheLine::new);
|
when_supported(max_value, RequestType::BrandString3, || BrandString::new());
|
||||||
|
let cache_line = when_supported(max_value, RequestType::CacheLine, || CacheLine::new());
|
||||||
let tsc = when_supported(max_value, RequestType::TimeStampCounter, || {
|
let tsc = when_supported(max_value, RequestType::TimeStampCounter, || {
|
||||||
TimeStampCounter::new()
|
TimeStampCounter::new()
|
||||||
});
|
});
|
||||||
|
@ -736,8 +782,8 @@ impl Master {
|
||||||
thermal_power_management_information: tpm,
|
thermal_power_management_information: tpm,
|
||||||
structured_extended_information: sei,
|
structured_extended_information: sei,
|
||||||
extended_processor_signature: eps,
|
extended_processor_signature: eps,
|
||||||
brand_string,
|
brand_string: brand_string,
|
||||||
cache_line,
|
cache_line: cache_line,
|
||||||
time_stamp_counter: tsc,
|
time_stamp_counter: tsc,
|
||||||
physical_address_size: pas,
|
physical_address_size: pas,
|
||||||
}
|
}
|
||||||
|
@ -761,7 +807,7 @@ impl Master {
|
||||||
self.brand_string
|
self.brand_string
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|bs| bs as &str)
|
.map(|bs| bs as &str)
|
||||||
.or_else(|| self.version_information.and_then(|vi| vi.brand_string()))
|
.or(self.version_information.and_then(|vi| vi.brand_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate_flag!(version_information, {
|
delegate_flag!(version_information, {
|
||||||
|
@ -823,7 +869,7 @@ impl Master {
|
||||||
ss,
|
ss,
|
||||||
htt,
|
htt,
|
||||||
tm,
|
tm,
|
||||||
pbe,
|
pbe
|
||||||
});
|
});
|
||||||
|
|
||||||
delegate_flag!(thermal_power_management_information, {
|
delegate_flag!(thermal_power_management_information, {
|
||||||
|
@ -839,7 +885,7 @@ impl Master {
|
||||||
hwp_energy_performance_preference,
|
hwp_energy_performance_preference,
|
||||||
hdc,
|
hdc,
|
||||||
hardware_coordination_feedback,
|
hardware_coordination_feedback,
|
||||||
performance_energy_bias,
|
performance_energy_bias
|
||||||
});
|
});
|
||||||
|
|
||||||
delegate_flag!(structured_extended_information, {
|
delegate_flag!(structured_extended_information, {
|
||||||
|
@ -871,66 +917,11 @@ impl Master {
|
||||||
execute_disable,
|
execute_disable,
|
||||||
gigabyte_pages,
|
gigabyte_pages,
|
||||||
rdtscp_and_ia32_tsc_aux,
|
rdtscp_and_ia32_tsc_aux,
|
||||||
intel_64_bit_architecture,
|
intel_64_bit_architecture
|
||||||
});
|
});
|
||||||
|
|
||||||
delegate_flag!(time_stamp_counter, { invariant_tsc });
|
delegate_flag!(time_stamp_counter, { invariant_tsc });
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Master {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The main entrypoint to the CPU information
|
|
||||||
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
|
|
||||||
pub fn master() -> Option<Master> {
|
|
||||||
Some(Master::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn sysinfo() {}
|
|
||||||
|
|
||||||
pub fn as_bytes(v: &u32) -> &[u8] {
|
|
||||||
let start = v as *const u32 as *const u8;
|
|
||||||
// TODO: use u32::BYTES
|
|
||||||
unsafe { slice::from_raw_parts(start, 4) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cpuid(code: RequestType) -> (u32, u32, u32, u32) {
|
|
||||||
let eax;
|
|
||||||
let ebx;
|
|
||||||
let ecx;
|
|
||||||
let edx;
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
asm!(
|
|
||||||
"movq %rbx, {0:r}",
|
|
||||||
"cpuid",
|
|
||||||
"xchgq %rbx, {0:r}",
|
|
||||||
lateout(reg) ebx,
|
|
||||||
inlateout("eax") code as u32 => eax,
|
|
||||||
inlateout("ecx") 0 => ecx,
|
|
||||||
lateout("edx") edx,
|
|
||||||
options(nostack, preserves_flags, att_syntax),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
(eax, ebx, ecx, edx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// This matches the Intel Architecture guide, with bits 31 -> 0.
|
|
||||||
// The bit positions are inclusive.
|
|
||||||
fn bits_of(val: u32, start_bit: u8, end_bit: u8) -> u32 {
|
|
||||||
let mut silly = 0;
|
|
||||||
for _ in start_bit..end_bit + 1 {
|
|
||||||
silly <<= 1;
|
|
||||||
silly |= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
(val >> start_bit) & silly
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] {
|
if #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] {
|
|
@ -1,74 +1,34 @@
|
||||||
use super::systeminfo::SystemMemory;
|
// Can be standardized
|
||||||
use crate::{arch::drivers::sysinfo::master, ALLOCATOR};
|
// NOTE: Move this to relib
|
||||||
use core::fmt::Display;
|
pub struct SemanticVersion {
|
||||||
use versioning::Version;
|
pub major: u8,
|
||||||
use x86_64::instructions::interrupts::{disable, enable};
|
pub minor: u8,
|
||||||
|
pub patch: u8,
|
||||||
pub enum CpuType {
|
|
||||||
RiscV(String),
|
|
||||||
X86_64(String),
|
|
||||||
}
|
}
|
||||||
impl Display for CpuType {
|
impl core::fmt::Display for SemanticVersion {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||||
write!(
|
write!(f, "v{}.{}.{}", self.major, self.minor, self.patch)
|
||||||
f,
|
|
||||||
"{}",
|
|
||||||
match self {
|
|
||||||
CpuType::RiscV(s) => s,
|
|
||||||
CpuType::X86_64(s) => s,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// NOTE: Move to somewhere else
|
||||||
/// simple info you would want to know in a neofetch like program
|
lazy_static! {
|
||||||
pub struct KernelInfo {
|
pub static ref KINFO: KernelInfo = KernelInfo {
|
||||||
// os: String,
|
kernel_version: SemanticVersion {
|
||||||
// host: String,
|
|
||||||
pub kernel_version: Version,
|
|
||||||
pub cpu: CpuType,
|
|
||||||
// gpu: String,
|
|
||||||
pub memory: SystemMemory,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl KernelInfo {
|
|
||||||
pub fn get() -> KernelInfo {
|
|
||||||
disable();
|
|
||||||
let allocator = ALLOCATOR.lock();
|
|
||||||
let total = allocator.size();
|
|
||||||
let used = allocator.used();
|
|
||||||
enable();
|
|
||||||
|
|
||||||
let cpu = CpuType::X86_64(master().unwrap().brand_string().unwrap().to_string());
|
|
||||||
KernelInfo {
|
|
||||||
kernel_version: Version {
|
|
||||||
major: 0,
|
major: 0,
|
||||||
minor: 0,
|
minor: 0,
|
||||||
patch: 0,
|
patch: 0,
|
||||||
},
|
},
|
||||||
cpu,
|
memory: SystemMemory { used: 0, total: 0 }
|
||||||
memory: SystemMemory { total, used },
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for KernelInfo {
|
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"
|
|
||||||
OS: AbleOS
|
|
||||||
Host: {{}}
|
|
||||||
Kernel: {}.{}.{}
|
|
||||||
CPU: {}
|
|
||||||
Memory: {}/{}
|
|
||||||
",
|
|
||||||
self.kernel_version.major,
|
|
||||||
self.kernel_version.minor,
|
|
||||||
self.kernel_version.patch,
|
|
||||||
self.cpu,
|
|
||||||
self.memory.used,
|
|
||||||
self.memory.total
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
/// simple info you would want to know in a neofetch like program
|
||||||
|
pub struct KernelInfo {
|
||||||
|
// os: String,
|
||||||
|
// host: String,
|
||||||
|
pub kernel_version: SemanticVersion,
|
||||||
|
// cpu: String,
|
||||||
|
// gpu: String,
|
||||||
|
pub memory: SystemMemory,
|
||||||
}
|
}
|
||||||
|
use super::systeminfo::SystemMemory;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
|
@ -5,7 +5,6 @@ pub struct MailBoxes {
|
||||||
flags: u8,
|
flags: u8,
|
||||||
mailboxes: [u64; 4],
|
mailboxes: [u64; 4],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MailBoxes {
|
impl MailBoxes {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -13,18 +12,15 @@ impl MailBoxes {
|
||||||
mailboxes: [0; 4],
|
mailboxes: [0; 4],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
self.flags = 0b0000_0000;
|
self.flags = 0b0000_0000;
|
||||||
self.mailboxes = [0; 4];
|
self.mailboxes = [0; 4];
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_mailbox(&mut self, mailbox_num: u8, mailbox_data: u64) {
|
pub fn set_mailbox(&mut self, mailbox_num: u8, mailbox_data: u64) {
|
||||||
if let 0..=3 = mailbox_num {
|
if let 0..=3 = mailbox_num {
|
||||||
self.mailboxes[mailbox_num as usize] = mailbox_data
|
self.mailboxes[mailbox_num as usize] = mailbox_data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_flag(&mut self, flag_num: u8) {
|
pub fn set_flag(&mut self, flag_num: u8) {
|
||||||
match flag_num {
|
match flag_num {
|
||||||
0 => {
|
0 => {
|
||||||
|
@ -105,9 +101,3 @@ impl MailBoxes {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MailBoxes {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
pub mod absi;
|
pub mod absi;
|
||||||
pub mod clip;
|
pub mod clip;
|
||||||
pub mod futex;
|
pub mod futex;
|
||||||
|
// pub mod info;
|
||||||
|
pub mod info;
|
||||||
pub mod kinfo;
|
pub mod kinfo;
|
||||||
pub mod mail;
|
pub mod mail;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod systeminfo;
|
pub mod systeminfo;
|
||||||
pub mod virtual_memory;
|
pub mod virtual_memory;
|
||||||
pub mod y_compositor;
|
pub mod y_compositor;
|
||||||
|
|
||||||
pub const BANNER: &str = include_str!("banner.txt");
|
pub const BANNER: &str = include_str!("banner.txt");
|
||||||
|
|
|
@ -5,3 +5,4 @@ pub struct Notification {
|
||||||
text_body: String,
|
text_body: String,
|
||||||
time: u64,
|
time: u64,
|
||||||
}
|
}
|
||||||
|
impl Notification {}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
|
pub type PackageName = String;
|
||||||
use crate::experiments::kinfo::SemanticVersion;
|
use crate::experiments::kinfo::SemanticVersion;
|
||||||
|
|
||||||
// Scuffed
|
// Scuffed
|
||||||
pub type Hash = u8;
|
pub type Hash = u8;
|
||||||
pub type PackageName = String;
|
|
||||||
|
|
||||||
pub struct MetaPackage {
|
pub struct MetaPackage {
|
||||||
pub name: u8,
|
pub name: u8,
|
||||||
pub version: SemanticVersion,
|
pub version: SemanticVersion,
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
pub trait Server {
|
pub trait Server {
|
||||||
/// Initialize the server and return a number
|
/// Initialize the server and return a number
|
||||||
fn initialize() -> u32;
|
fn initialize() -> u32;
|
||||||
|
|
||||||
/// kill the server
|
/// kill the server
|
||||||
fn kill() -> bool;
|
fn kill() -> bool;
|
||||||
|
|
||||||
// put data in the servers outbox
|
// put data in the servers outbox
|
||||||
fn send();
|
fn send();
|
||||||
|
|
||||||
// put data in the servers inbox and notify it
|
// put data in the servers inbox and notify it
|
||||||
fn recieve();
|
fn recieve();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,36 @@
|
||||||
// Can be standardized
|
// Can be standardized
|
||||||
// NOTE: move the file to the src/ dir
|
// NOTE: move the file to the src/ dir
|
||||||
|
pub struct SystemMemory {
|
||||||
|
pub used: u64,
|
||||||
|
pub total: u64,
|
||||||
|
}
|
||||||
|
impl core::fmt::Display for SystemMemory {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||||
|
write!(f, "{} Bytes / {} Bytes", self.used, self.total)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
pub fn format_system_info() -> core::string::String {
|
||||||
|
let x = format!(
|
||||||
|
"{}
|
||||||
|
OS: AbleOS
|
||||||
|
Host: ComputAble
|
||||||
|
Kernel: {}
|
||||||
|
Uptime: 0:0:0
|
||||||
|
Packages: 0
|
||||||
|
Shell: Ashell
|
||||||
|
Gpu: MIPS32 R4000 R4k
|
||||||
|
Cpu: {}
|
||||||
|
Memory: {}
|
||||||
|
",
|
||||||
|
crate::experiments::BANNER,
|
||||||
|
crate::experiments::kinfo::KINFO.kernel_version,
|
||||||
|
crate::arch::ARCH,
|
||||||
|
crate::experiments::kinfo::KINFO.memory
|
||||||
|
);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
// */
|
||||||
pub const KERNEL_VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const KERNEL_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
/// A constant to check if the kernel is in debug mode
|
/// A constant to check if the kernel is in debug mode
|
||||||
|
@ -8,14 +38,3 @@ pub const RELEASE_TYPE: &str = "debug";
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
/// A constant to check if the kernel is in release mode
|
/// A constant to check if the kernel is in release mode
|
||||||
pub const RELEASE_TYPE: &str = "release";
|
pub const RELEASE_TYPE: &str = "release";
|
||||||
|
|
||||||
pub struct SystemMemory {
|
|
||||||
pub used: usize,
|
|
||||||
pub total: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl core::fmt::Display for SystemMemory {
|
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
|
||||||
write!(f, "{} Bytes / {} Bytes", self.used, self.total)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,4 +4,4 @@ pub struct Scheduler {
|
||||||
executables: usize,
|
executables: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RunQueue;
|
pub struct RunQueue {}
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
pub struct Compositor;
|
pub struct Compositor {}
|
||||||
|
|
||||||
impl Compositor {
|
impl Compositor {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self
|
Self {}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Compositor {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
use crate::driver_traits::graphics::Point;
|
use crate::driver_traits::graphics::Point;
|
||||||
|
|
||||||
pub type MenuBar = Vec<MenuOption>;
|
|
||||||
|
|
||||||
pub struct MenuOption {
|
pub struct MenuOption {
|
||||||
symbol: char,
|
symbol: char,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type MenuBar = Vec<MenuOption>;
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
title: String,
|
title: String,
|
||||||
position: Point,
|
position: Point,
|
||||||
fullscreen: bool,
|
fullscreen: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
// all of these should return a result
|
// all of these should return a result
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(title: String, position: Point, fullscreen: bool) -> Self {
|
pub fn new(title: String, position: Point, fullscreen: bool) -> Self {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -6,17 +6,24 @@ use ext2::{
|
||||||
sector::{SectorSize, Size1024},
|
sector::{SectorSize, Size1024},
|
||||||
volume::Volume,
|
volume::Volume,
|
||||||
};
|
};
|
||||||
use spin::Lazy;
|
|
||||||
|
|
||||||
pub static FILE_SYSTEM: Lazy<spin::Mutex<Synced<Ext2<Size1024, Vec<u8>>>>> =
|
fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
|
||||||
Lazy::new(|| spin::Mutex::new(load_fs()));
|
let mut volume = Vec::new();
|
||||||
|
volume.extend_from_slice(include_bytes!("../../../userland/root_fs/ext2.img"));
|
||||||
|
|
||||||
pub fn walk<S: SectorSize, V: Volume<u8, S>>(
|
let fs = Synced::<Ext2<Size1024, _>>::new(volume).unwrap();
|
||||||
fs: &Synced<Ext2<S, V>>,
|
|
||||||
|
fs
|
||||||
|
}
|
||||||
|
|
||||||
|
// use serde::__private::from_utf8_lossy;
|
||||||
|
|
||||||
|
pub fn walk<'vol, S: SectorSize, V: Volume<u8, S>>(
|
||||||
|
fs: &'vol Synced<Ext2<S, V>>,
|
||||||
inode: Inode<S, V>,
|
inode: Inode<S, V>,
|
||||||
name: String,
|
name: String,
|
||||||
) {
|
) {
|
||||||
if let Some(dir) = inode.directory() {
|
inode.directory().map(|dir| {
|
||||||
for entry in dir {
|
for entry in dir {
|
||||||
assert!(entry.is_ok());
|
assert!(entry.is_ok());
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
|
@ -31,12 +38,8 @@ pub fn walk<S: SectorSize, V: Volume<u8, S>>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
lazy_static::lazy_static!(
|
||||||
|
pub static ref FILE_SYSTEM:spin::Mutex<Synced<Ext2<Size1024, Vec<u8>>>>= spin::Mutex::new(load_fs());
|
||||||
fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
|
);
|
||||||
let mut volume = Vec::new();
|
|
||||||
volume.extend_from_slice(include_bytes!("../../../userland/root_fs/ext2.img"));
|
|
||||||
|
|
||||||
Synced::<Ext2<Size1024, _>>::new(volume).unwrap()
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
|
// use crate::vga_e::VGAE;
|
||||||
use ab_glyph::{Font, FontRef, Glyph};
|
use ab_glyph::{Font, FontRef, Glyph};
|
||||||
|
|
||||||
use shadeable::{evaluate_shader, pixel_format::Rgba64};
|
use shadeable::{evaluate_shader, pixel_format::Rgba64};
|
||||||
use spin::Lazy;
|
use spin;
|
||||||
|
// use vga::{colors::Color16, writers::GraphicsWriter};
|
||||||
pub static SCREEN_BUFFER: Lazy<spin::Mutex<ScreenBuffer>> =
|
|
||||||
Lazy::new(|| spin::Mutex::new(ScreenBuffer::new(640, 480)));
|
|
||||||
|
|
||||||
const FONT_SCALE: f32 = 1.6;
|
|
||||||
const GLYPH_HEIGHT: f32 = 18.0;
|
|
||||||
const GLYPH_WIDTH: f32 = 10.0;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ScreenSize {
|
pub struct ScreenSize {
|
||||||
|
@ -15,6 +11,15 @@ pub struct ScreenSize {
|
||||||
pub y: usize,
|
pub y: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FONT_SCALE: f32 = 1.6;
|
||||||
|
const GLYPH_HEIGHT: f32 = 18.0;
|
||||||
|
const GLYPH_WIDTH: f32 = 10.0;
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref SCREEN_BUFFER: spin::Mutex<ScreenBuffer> = spin::Mutex::new(ScreenBuffer::new(640, 480));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
impl ScreenSize {
|
impl ScreenSize {
|
||||||
pub fn new(x: usize, y: usize) -> Self {
|
pub fn new(x: usize, y: usize) -> Self {
|
||||||
Self { x, y }
|
Self { x, y }
|
||||||
|
@ -29,7 +34,7 @@ pub enum GraphicsReturn {
|
||||||
pub struct ScreenBuffer {
|
pub struct ScreenBuffer {
|
||||||
pub size: ScreenSize,
|
pub size: ScreenSize,
|
||||||
pub clear_color: Rgba64,
|
pub clear_color: Rgba64,
|
||||||
pub buff: Box<[Rgba64]>,
|
pub buff: Box<[Rgba64]>, // Vec<Rgba64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScreenBuffer {
|
impl ScreenBuffer {
|
||||||
|
@ -41,7 +46,6 @@ impl ScreenBuffer {
|
||||||
buff: vec![0u64; x * y].into_boxed_slice(),
|
buff: vec![0u64; x * y].into_boxed_slice(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_filled_circle(&mut self, cx: i32, cy: i32, radius: usize, color: Rgba64) {
|
pub fn draw_filled_circle(&mut self, cx: i32, cy: i32, radius: usize, color: Rgba64) {
|
||||||
let r = radius as i32 * 2;
|
let r = radius as i32 * 2;
|
||||||
for y in 0..640 {
|
for y in 0..640 {
|
||||||
|
@ -66,7 +70,6 @@ impl ScreenBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn blit(&mut self, _width: usize, _height: usize) {}
|
pub fn blit(&mut self, _width: usize, _height: usize) {}
|
||||||
|
|
||||||
pub fn draw_filled_rect(&mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: Rgba64) {
|
pub fn draw_filled_rect(&mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: Rgba64) {
|
||||||
for y in y1..y2 {
|
for y in y1..y2 {
|
||||||
for x in x1..x2 {
|
for x in x1..x2 {
|
||||||
|
@ -196,6 +199,38 @@ impl ScreenBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
|
pub trait VgaBuffer {
|
||||||
|
fn copy_to_buffer(&self) -> GraphicsReturn;
|
||||||
|
}
|
||||||
|
impl VgaBuffer for ScreenBuffer {
|
||||||
|
fn copy_to_buffer(&self) -> GraphicsReturn {
|
||||||
|
let mode = VGAE.lock();
|
||||||
|
for y in 0..self.size.y {
|
||||||
|
for x in 0..self.size.x {
|
||||||
|
|
||||||
|
use shadeable::pixel_format::into_vga_16;
|
||||||
|
let vga_color = into_vga_16(self.buff[y * self.size.x + x]);
|
||||||
|
// let vga_color = vga::colors::Color16::Cyan;
|
||||||
|
|
||||||
|
if Color16::Cyan != vga_color {
|
||||||
|
mode.set_pixel(x, y, vga_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphicsReturn::Ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
pub fn get_coordinates(x1: i32, y1: i32, x2: i32, y2: i32) -> Vec<(usize, usize)> {
|
pub fn get_coordinates(x1: i32, y1: i32, x2: i32, y2: i32) -> Vec<(usize, usize)> {
|
||||||
let mut coordinates: Vec<(usize, usize)> = vec![];
|
let mut coordinates: Vec<(usize, usize)> = vec![];
|
||||||
|
@ -237,6 +272,5 @@ pub fn get_coordinates(x1: i32, y1: i32, x2: i32, y2: i32) -> Vec<(usize, usize)
|
||||||
current_y += sy;
|
current_y += sy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
coordinates
|
coordinates
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use spin::Lazy;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
pub static KERNEL_STATE: Lazy<spin::Mutex<KernelInternalState>> =
|
lazy_static! {
|
||||||
Lazy::new(|| spin::Mutex::new(KernelInternalState::new()));
|
pub static ref KERNEL_STATE: spin::Mutex<KernelInternalState> =
|
||||||
|
spin::Mutex::new(KernelInternalState::new());
|
||||||
|
}
|
||||||
|
|
||||||
pub struct KernelInternalState {
|
pub struct KernelInternalState {
|
||||||
pub hostname: String,
|
pub hostname: String,
|
||||||
|
@ -28,9 +30,3 @@ impl KernelInternalState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for KernelInternalState {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,382 +2,104 @@ use crate::{
|
||||||
DecodedKey, HandleControl, KeyCode, KeyboardLayout, LayoutEntry, LayoutEntryKind, Modifiers,
|
DecodedKey, HandleControl, KeyCode, KeyboardLayout, LayoutEntry, LayoutEntryKind, Modifiers,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Do not edit this file directly. Instead, create a `Keyboard` and modify that.
|
||||||
|
|
||||||
pub struct CustomLayout {
|
pub struct CustomLayout {
|
||||||
mapping: [LayoutEntry; 256],
|
mapping: [LayoutEntry; 256],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CustomLayout {
|
impl Default for CustomLayout {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new_us104key()
|
Self::new_us104key()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[rustfmt::skip]
|
||||||
impl CustomLayout {
|
impl CustomLayout {
|
||||||
pub fn new_us104key() -> Self {
|
pub fn new_us104key() -> Self {
|
||||||
let mut mapping = Self {
|
let mut mapping = Self {
|
||||||
mapping: [LayoutEntry::default(); 256],
|
mapping: [LayoutEntry::default(); 256],
|
||||||
};
|
};
|
||||||
|
mapping.set(KeyCode::BackTick, LayoutEntry::regular().unshifted('`').shifted('`'));
|
||||||
mapping.set(
|
|
||||||
KeyCode::BackTick,
|
|
||||||
LayoutEntry::regular().unshifted('`').shifted('`'),
|
|
||||||
);
|
|
||||||
mapping.set(KeyCode::Escape, LayoutEntry::regular().unshifted('\x1B'));
|
mapping.set(KeyCode::Escape, LayoutEntry::regular().unshifted('\x1B'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::Key0, LayoutEntry::regular().unshifted('0').shifted(')'));
|
||||||
KeyCode::Key0,
|
mapping.set(KeyCode::Key1, LayoutEntry::regular().unshifted('1').shifted('!'));
|
||||||
LayoutEntry::regular().unshifted('0').shifted(')'),
|
mapping.set(KeyCode::Key2, LayoutEntry::regular().unshifted('2').shifted('@'));
|
||||||
);
|
mapping.set(KeyCode::Key3, LayoutEntry::regular().unshifted('3').shifted('#'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::Key4, LayoutEntry::regular().unshifted('4').shifted('$'));
|
||||||
KeyCode::Key1,
|
mapping.set(KeyCode::Key5, LayoutEntry::regular().unshifted('5').shifted('%'));
|
||||||
LayoutEntry::regular().unshifted('1').shifted('!'),
|
mapping.set(KeyCode::Key6, LayoutEntry::regular().unshifted('6').shifted('^'));
|
||||||
);
|
mapping.set(KeyCode::Key7, LayoutEntry::regular().unshifted('7').shifted('&'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::Key8, LayoutEntry::regular().unshifted('8').shifted('*'));
|
||||||
KeyCode::Key2,
|
mapping.set(KeyCode::Key9, LayoutEntry::regular().unshifted('9').shifted('('));
|
||||||
LayoutEntry::regular().unshifted('2').shifted('@'),
|
mapping.set(KeyCode::Minus, LayoutEntry::regular().unshifted('-').shifted('_'));
|
||||||
);
|
mapping.set(KeyCode::Equals, LayoutEntry::regular().unshifted('=').shifted('+'));
|
||||||
mapping.set(
|
|
||||||
KeyCode::Key3,
|
|
||||||
LayoutEntry::regular().unshifted('3').shifted('#'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Key4,
|
|
||||||
LayoutEntry::regular().unshifted('4').shifted('$'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Key5,
|
|
||||||
LayoutEntry::regular().unshifted('5').shifted('%'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Key6,
|
|
||||||
LayoutEntry::regular().unshifted('6').shifted('^'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Key7,
|
|
||||||
LayoutEntry::regular().unshifted('7').shifted('&'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Key8,
|
|
||||||
LayoutEntry::regular().unshifted('8').shifted('*'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Key9,
|
|
||||||
LayoutEntry::regular().unshifted('9').shifted('('),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Minus,
|
|
||||||
LayoutEntry::regular().unshifted('-').shifted('_'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Equals,
|
|
||||||
LayoutEntry::regular().unshifted('=').shifted('+'),
|
|
||||||
);
|
|
||||||
mapping.set(KeyCode::Backspace, LayoutEntry::regular().all('\x08'));
|
mapping.set(KeyCode::Backspace, LayoutEntry::regular().all('\x08'));
|
||||||
mapping.set(KeyCode::Tab, LayoutEntry::regular().all('\x09'));
|
mapping.set(KeyCode::Tab, LayoutEntry::regular().all('\x09'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::Q, LayoutEntry::alphabet().low('q').high('Q').raw_unicode('\u{0011}'));
|
||||||
KeyCode::Q,
|
mapping.set(KeyCode::W, LayoutEntry::alphabet().low('w').high('W').raw_unicode('\u{0017}'));
|
||||||
LayoutEntry::alphabet()
|
mapping.set(KeyCode::E, LayoutEntry::alphabet().low('e').high('E').raw_unicode('\u{0005}'));
|
||||||
.low('q')
|
mapping.set(KeyCode::R, LayoutEntry::alphabet().low('r').high('R').raw_unicode('\u{0012}'));
|
||||||
.high('Q')
|
mapping.set(KeyCode::T, LayoutEntry::alphabet().low('t').high('T').raw_unicode('\u{0014}'));
|
||||||
.raw_unicode('\u{0011}'),
|
mapping.set(KeyCode::Y, LayoutEntry::alphabet().low('y').high('Y').raw_unicode('\u{0019}'));
|
||||||
);
|
mapping.set(KeyCode::U, LayoutEntry::alphabet().low('u').high('U').raw_unicode('\u{0015}'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::I, LayoutEntry::alphabet().low('i').high('I').raw_unicode('\u{0009}'));
|
||||||
KeyCode::W,
|
mapping.set(KeyCode::O, LayoutEntry::alphabet().low('o').high('O').raw_unicode('\u{000F}'));
|
||||||
LayoutEntry::alphabet()
|
mapping.set(KeyCode::P, LayoutEntry::alphabet().low('p').high('P').raw_unicode('\u{0010}'));
|
||||||
.low('w')
|
mapping.set(KeyCode::A, LayoutEntry::alphabet().low('a').high('A').raw_unicode('\u{0001}'));
|
||||||
.high('W')
|
mapping.set(KeyCode::S, LayoutEntry::alphabet().low('s').high('S').raw_unicode('\u{0013}'));
|
||||||
.raw_unicode('\u{0017}'),
|
mapping.set(KeyCode::D, LayoutEntry::alphabet().low('d').high('D').raw_unicode('\u{0004}'));
|
||||||
);
|
mapping.set(KeyCode::F, LayoutEntry::alphabet().low('f').high('F').raw_unicode('\u{0006}'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::G, LayoutEntry::alphabet().low('g').high('G').raw_unicode('\u{0007}'));
|
||||||
KeyCode::E,
|
mapping.set(KeyCode::H, LayoutEntry::alphabet().low('h').high('H').raw_unicode('\u{0008}'));
|
||||||
LayoutEntry::alphabet()
|
mapping.set(KeyCode::J, LayoutEntry::alphabet().low('j').high('J').raw_unicode('\u{000A}'));
|
||||||
.low('e')
|
mapping.set(KeyCode::K, LayoutEntry::alphabet().low('k').high('K').raw_unicode('\u{000B}'));
|
||||||
.high('E')
|
mapping.set(KeyCode::L, LayoutEntry::alphabet().low('l').high('L').raw_unicode('\u{000C}'));
|
||||||
.raw_unicode('\u{0005}'),
|
mapping.set(KeyCode::Z, LayoutEntry::alphabet().low('z').high('Z').raw_unicode('\u{001A}'));
|
||||||
);
|
mapping.set(KeyCode::X, LayoutEntry::alphabet().low('x').high('X').raw_unicode('\u{0018}'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::C, LayoutEntry::alphabet().low('c').high('C').raw_unicode('\u{0003}'));
|
||||||
KeyCode::R,
|
mapping.set(KeyCode::V, LayoutEntry::alphabet().low('v').high('V').raw_unicode('\u{0016}'));
|
||||||
LayoutEntry::alphabet()
|
mapping.set(KeyCode::B, LayoutEntry::alphabet().low('b').high('B').raw_unicode('\u{0002}'));
|
||||||
.low('r')
|
mapping.set(KeyCode::N, LayoutEntry::alphabet().low('n').high('N').raw_unicode('\u{000E}'));
|
||||||
.high('R')
|
mapping.set(KeyCode::M, LayoutEntry::alphabet().low('m').high('M').raw_unicode('\u{000D}'));
|
||||||
.raw_unicode('\u{0012}'),
|
mapping.set(KeyCode::BracketSquareLeft, LayoutEntry::regular().unshifted('{').shifted('['));
|
||||||
);
|
mapping.set(KeyCode::BracketSquareRight, LayoutEntry::regular().unshifted('}').shifted(']'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::BackSlash, LayoutEntry::regular().unshifted('|').shifted('\\'));
|
||||||
KeyCode::T,
|
mapping.set(KeyCode::SemiColon, LayoutEntry::regular().unshifted(';').shifted(':'));
|
||||||
LayoutEntry::alphabet()
|
mapping.set(KeyCode::Quote, LayoutEntry::regular().unshifted('\'').shifted('"'));
|
||||||
.low('t')
|
|
||||||
.high('T')
|
|
||||||
.raw_unicode('\u{0014}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Y,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('y')
|
|
||||||
.high('Y')
|
|
||||||
.raw_unicode('\u{0019}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::U,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('u')
|
|
||||||
.high('U')
|
|
||||||
.raw_unicode('\u{0015}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::I,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('i')
|
|
||||||
.high('I')
|
|
||||||
.raw_unicode('\u{0009}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::O,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('o')
|
|
||||||
.high('O')
|
|
||||||
.raw_unicode('\u{000F}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::P,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('p')
|
|
||||||
.high('P')
|
|
||||||
.raw_unicode('\u{0010}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::A,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('a')
|
|
||||||
.high('A')
|
|
||||||
.raw_unicode('\u{0001}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::S,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('s')
|
|
||||||
.high('S')
|
|
||||||
.raw_unicode('\u{0013}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::D,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('d')
|
|
||||||
.high('D')
|
|
||||||
.raw_unicode('\u{0004}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::F,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('f')
|
|
||||||
.high('F')
|
|
||||||
.raw_unicode('\u{0006}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::G,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('g')
|
|
||||||
.high('G')
|
|
||||||
.raw_unicode('\u{0007}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::H,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('h')
|
|
||||||
.high('H')
|
|
||||||
.raw_unicode('\u{0008}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::J,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('j')
|
|
||||||
.high('J')
|
|
||||||
.raw_unicode('\u{000A}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::K,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('k')
|
|
||||||
.high('K')
|
|
||||||
.raw_unicode('\u{000B}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::L,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('l')
|
|
||||||
.high('L')
|
|
||||||
.raw_unicode('\u{000C}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Z,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('z')
|
|
||||||
.high('Z')
|
|
||||||
.raw_unicode('\u{001A}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::X,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('x')
|
|
||||||
.high('X')
|
|
||||||
.raw_unicode('\u{0018}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::C,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('c')
|
|
||||||
.high('C')
|
|
||||||
.raw_unicode('\u{0003}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::V,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('v')
|
|
||||||
.high('V')
|
|
||||||
.raw_unicode('\u{0016}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::B,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('b')
|
|
||||||
.high('B')
|
|
||||||
.raw_unicode('\u{0002}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::N,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('n')
|
|
||||||
.high('N')
|
|
||||||
.raw_unicode('\u{000E}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::M,
|
|
||||||
LayoutEntry::alphabet()
|
|
||||||
.low('m')
|
|
||||||
.high('M')
|
|
||||||
.raw_unicode('\u{000D}'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::BracketSquareLeft,
|
|
||||||
LayoutEntry::regular().unshifted('{').shifted('['),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::BracketSquareRight,
|
|
||||||
LayoutEntry::regular().unshifted('}').shifted(']'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::BackSlash,
|
|
||||||
LayoutEntry::regular().unshifted('|').shifted('\\'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::SemiColon,
|
|
||||||
LayoutEntry::regular().unshifted(';').shifted(':'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Quote,
|
|
||||||
LayoutEntry::regular().unshifted('\'').shifted('"'),
|
|
||||||
);
|
|
||||||
mapping.set(KeyCode::Enter, LayoutEntry::regular().all('\x0A'));
|
mapping.set(KeyCode::Enter, LayoutEntry::regular().all('\x0A'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::Comma, LayoutEntry::regular().unshifted(',').shifted('<'));
|
||||||
KeyCode::Comma,
|
mapping.set(KeyCode::Fullstop, LayoutEntry::regular().unshifted('.').shifted('>'));
|
||||||
LayoutEntry::regular().unshifted(',').shifted('<'),
|
mapping.set(KeyCode::Slash, LayoutEntry::regular().unshifted('/').shifted('?'));
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Fullstop,
|
|
||||||
LayoutEntry::regular().unshifted('.').shifted('>'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Slash,
|
|
||||||
LayoutEntry::regular().unshifted('/').shifted('?'),
|
|
||||||
);
|
|
||||||
mapping.set(KeyCode::Spacebar, LayoutEntry::regular().all(' '));
|
mapping.set(KeyCode::Spacebar, LayoutEntry::regular().all(' '));
|
||||||
mapping.set(KeyCode::Delete, LayoutEntry::regular().all('\x7F'));
|
mapping.set(KeyCode::Delete, LayoutEntry::regular().all('\x7F'));
|
||||||
mapping.set(KeyCode::NumpadSlash, LayoutEntry::numpad().all('/'));
|
mapping.set(KeyCode::NumpadSlash, LayoutEntry::numpad().all('/'));
|
||||||
mapping.set(KeyCode::NumpadStar, LayoutEntry::numpad().all('*'));
|
mapping.set(KeyCode::NumpadStar, LayoutEntry::numpad().all('*'));
|
||||||
mapping.set(KeyCode::NumpadMinus, LayoutEntry::numpad().all('-'));
|
mapping.set(KeyCode::NumpadMinus, LayoutEntry::numpad().all('-'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::Numpad7, LayoutEntry::numpad().low('7').high(KeyCode::Home));
|
||||||
KeyCode::Numpad7,
|
mapping.set(KeyCode::Numpad8, LayoutEntry::numpad().low('8').high(KeyCode::ArrowUp));
|
||||||
LayoutEntry::numpad().low('7').high(KeyCode::Home),
|
mapping.set(KeyCode::Numpad9, LayoutEntry::numpad().low('9').high(KeyCode::PageUp));
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Numpad8,
|
|
||||||
LayoutEntry::numpad().low('8').high(KeyCode::ArrowUp),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Numpad9,
|
|
||||||
LayoutEntry::numpad().low('9').high(KeyCode::PageUp),
|
|
||||||
);
|
|
||||||
mapping.set(KeyCode::NumpadPlus, LayoutEntry::numpad().all('+'));
|
mapping.set(KeyCode::NumpadPlus, LayoutEntry::numpad().all('+'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::Numpad4, LayoutEntry::numpad().low('4').high(KeyCode::ArrowLeft));
|
||||||
KeyCode::Numpad4,
|
|
||||||
LayoutEntry::numpad().low('4').high(KeyCode::ArrowLeft),
|
|
||||||
);
|
|
||||||
mapping.set(KeyCode::Numpad5, LayoutEntry::numpad().all('5'));
|
mapping.set(KeyCode::Numpad5, LayoutEntry::numpad().all('5'));
|
||||||
mapping.set(
|
mapping.set(KeyCode::Numpad6, LayoutEntry::numpad().low('6').high(KeyCode::ArrowRight));
|
||||||
KeyCode::Numpad6,
|
mapping.set(KeyCode::Numpad1, LayoutEntry::numpad().low('1').high(KeyCode::End));
|
||||||
LayoutEntry::numpad().low('6').high(KeyCode::ArrowRight),
|
mapping.set(KeyCode::Numpad2, LayoutEntry::numpad().low('2').high(KeyCode::ArrowDown));
|
||||||
);
|
mapping.set(KeyCode::Numpad3, LayoutEntry::numpad().low('3').high(KeyCode::PageDown));
|
||||||
mapping.set(
|
mapping.set(KeyCode::Numpad0, LayoutEntry::numpad().low('0').high(KeyCode::Insert));
|
||||||
KeyCode::Numpad1,
|
mapping.set(KeyCode::NumpadPeriod, LayoutEntry::numpad().low('.').high('\x7F'));
|
||||||
LayoutEntry::numpad().low('1').high(KeyCode::End),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Numpad2,
|
|
||||||
LayoutEntry::numpad().low('2').high(KeyCode::ArrowDown),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Numpad3,
|
|
||||||
LayoutEntry::numpad().low('3').high(KeyCode::PageDown),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Numpad0,
|
|
||||||
LayoutEntry::numpad().low('0').high(KeyCode::Insert),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::NumpadPeriod,
|
|
||||||
LayoutEntry::numpad().low('.').high('\x7F'),
|
|
||||||
);
|
|
||||||
mapping.set(KeyCode::NumpadEnter, LayoutEntry::numpad().all('\x0A'));
|
mapping.set(KeyCode::NumpadEnter, LayoutEntry::numpad().all('\x0A'));
|
||||||
mapping
|
mapping
|
||||||
}
|
}
|
||||||
pub fn new_us105key() -> Self {
|
pub fn new_us105key() -> Self {
|
||||||
let mut mapping = Self::new_us104key();
|
let mut mapping = Self::new_us104key();
|
||||||
mapping.set(
|
mapping.set(KeyCode::BackTick, LayoutEntry::regular().unshifted('`').shifted('¬').altgr('|'));
|
||||||
KeyCode::BackTick,
|
mapping.set(KeyCode::Key2, LayoutEntry::regular().unshifted('2').shifted('"'));
|
||||||
LayoutEntry::regular()
|
mapping.set(KeyCode::Quote, LayoutEntry::regular().unshifted('\'').shifted('@'));
|
||||||
.unshifted('`')
|
mapping.set(KeyCode::Key3, LayoutEntry::regular().unshifted('3').shifted('£'));
|
||||||
.shifted('¬')
|
mapping.set(KeyCode::BackTick, LayoutEntry::regular().unshifted('4').shifted('$').altgr('€'));
|
||||||
.altgr('|'),
|
mapping.set(KeyCode::HashTilde, LayoutEntry::regular().unshifted('#').shifted('~'));
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Key2,
|
|
||||||
LayoutEntry::regular().unshifted('2').shifted('"'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Quote,
|
|
||||||
LayoutEntry::regular().unshifted('\'').shifted('@'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::Key3,
|
|
||||||
LayoutEntry::regular().unshifted('3').shifted('£'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::BackTick,
|
|
||||||
LayoutEntry::regular()
|
|
||||||
.unshifted('4')
|
|
||||||
.shifted('$')
|
|
||||||
.altgr('€'),
|
|
||||||
);
|
|
||||||
mapping.set(
|
|
||||||
KeyCode::HashTilde,
|
|
||||||
LayoutEntry::regular().unshifted('#').shifted('~'),
|
|
||||||
);
|
|
||||||
mapping
|
mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set(&mut self, pos: KeyCode, entry: LayoutEntry) {
|
|
||||||
self.mapping[pos as usize] = entry;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl KeyboardLayout for CustomLayout {
|
impl KeyboardLayout for CustomLayout {
|
||||||
fn map_keycode(
|
fn map_keycode(
|
||||||
&self,
|
&self,
|
||||||
|
@ -442,3 +164,13 @@ impl KeyboardLayout for CustomLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note(elfein) Not super hard to get right, but still- DO NOT TOUCH
|
||||||
|
impl CustomLayout {
|
||||||
|
// See how hard this is to get right?
|
||||||
|
// See the complexity of all the methods?
|
||||||
|
// Yeah- if you don't know what you're doing, ask before you touch!
|
||||||
|
pub fn set(&mut self, pos: KeyCode, entry: LayoutEntry) {
|
||||||
|
self.mapping[pos as usize] = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,20 +6,17 @@ pub struct CustomScancodeSet {
|
||||||
single_byte: [Option<KeyCode>; 256],
|
single_byte: [Option<KeyCode>; 256],
|
||||||
extended: [Option<KeyCode>; 256],
|
extended: [Option<KeyCode>; 256],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CustomScancodeSet {
|
impl Default for CustomScancodeSet {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::scancode_set1()
|
Self::scancode_set1()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CustomScancodeSet {
|
impl CustomScancodeSet {
|
||||||
pub fn scancode_set1() -> Self {
|
pub fn scancode_set1() -> Self {
|
||||||
let mut scancode_set = Self {
|
let mut scancode_set = Self {
|
||||||
single_byte: [None; 256],
|
single_byte: [None; 256],
|
||||||
extended: [None; 256],
|
extended: [None; 256],
|
||||||
};
|
};
|
||||||
|
|
||||||
scancode_set.single_byte[0x01] = Some(KeyCode::Escape); // 01
|
scancode_set.single_byte[0x01] = Some(KeyCode::Escape); // 01
|
||||||
scancode_set.single_byte[0x02] = Some(KeyCode::Key1); // 02
|
scancode_set.single_byte[0x02] = Some(KeyCode::Key1); // 02
|
||||||
scancode_set.single_byte[0x03] = Some(KeyCode::Key2); // 03
|
scancode_set.single_byte[0x03] = Some(KeyCode::Key2); // 03
|
||||||
|
@ -184,7 +181,6 @@ impl CustomScancodeSet {
|
||||||
}
|
}
|
||||||
scancode_set
|
scancode_set
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scancode_set2() -> Self {
|
pub fn scancode_set2() -> Self {
|
||||||
Self {
|
Self {
|
||||||
single_byte: [None; 256],
|
single_byte: [None; 256],
|
||||||
|
@ -192,7 +188,6 @@ impl CustomScancodeSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScancodeSet for CustomScancodeSet {
|
impl ScancodeSet for CustomScancodeSet {
|
||||||
fn advance_state(&self, state: &mut DecodeState, code: u8) -> Result<Option<KeyEvent>, Error> {
|
fn advance_state(&self, state: &mut DecodeState, code: u8) -> Result<Option<KeyEvent>, Error> {
|
||||||
match *state {
|
match *state {
|
||||||
|
@ -243,7 +238,6 @@ impl ScancodeSet for CustomScancodeSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_scancode(&self, code: u8) -> Result<KeyCode, Error> {
|
fn map_scancode(&self, code: u8) -> Result<KeyCode, Error> {
|
||||||
if let Some(kc) = self.single_byte[code as usize] {
|
if let Some(kc) = self.single_byte[code as usize] {
|
||||||
Ok(kc)
|
Ok(kc)
|
||||||
|
@ -251,7 +245,6 @@ impl ScancodeSet for CustomScancodeSet {
|
||||||
Err(Error::UnknownKeyCode)
|
Err(Error::UnknownKeyCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_extended_scancode(&self, code: u8) -> Result<KeyCode, Error> {
|
fn map_extended_scancode(&self, code: u8) -> Result<KeyCode, Error> {
|
||||||
if let Some(kc) = self.extended[code as usize] {
|
if let Some(kc) = self.extended[code as usize] {
|
||||||
Ok(kc)
|
Ok(kc)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::DecodedKey;
|
use super::DecodedKey;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum LayoutEntryKind {
|
pub enum LayoutEntryKind {
|
||||||
|
@ -32,7 +32,6 @@ impl LayoutEntry {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn numpad() -> Self {
|
pub fn numpad() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -40,7 +39,6 @@ impl LayoutEntry {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn alphabet() -> Self {
|
pub fn alphabet() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -48,43 +46,36 @@ impl LayoutEntry {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn unshifted(mut self, c: impl Into<DecodedKey>) -> Self {
|
pub fn unshifted(mut self, c: impl Into<DecodedKey>) -> Self {
|
||||||
self.unshifted = Some(c.into());
|
self.unshifted = Some(c.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn shifted(mut self, c: impl Into<DecodedKey>) -> Self {
|
pub fn shifted(mut self, c: impl Into<DecodedKey>) -> Self {
|
||||||
self.shifted = Some(c.into());
|
self.shifted = Some(c.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn altgr(mut self, c: impl Into<DecodedKey>) -> Self {
|
pub fn altgr(mut self, c: impl Into<DecodedKey>) -> Self {
|
||||||
self.altgr = Some(c.into());
|
self.altgr = Some(c.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn raw_unicode(mut self, c: impl Into<DecodedKey>) -> Self {
|
pub fn raw_unicode(mut self, c: impl Into<DecodedKey>) -> Self {
|
||||||
self.raw_unicode = Some(c.into());
|
self.raw_unicode = Some(c.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn locked(mut self, c: impl Into<DecodedKey>) -> Self {
|
pub fn locked(mut self, c: impl Into<DecodedKey>) -> Self {
|
||||||
self.locked = Some(c.into());
|
self.locked = Some(c.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn locked_shifted(mut self, c: impl Into<DecodedKey>) -> Self {
|
pub fn locked_shifted(mut self, c: impl Into<DecodedKey>) -> Self {
|
||||||
self.locked_shifted = Some(c.into());
|
self.locked_shifted = Some(c.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn common(self, c: impl Into<DecodedKey> + Clone) -> Self {
|
pub fn common(self, c: impl Into<DecodedKey> + Clone) -> Self {
|
||||||
self.unshifted(c.clone())
|
self.unshifted(c.clone())
|
||||||
|
@ -92,17 +83,14 @@ impl LayoutEntry {
|
||||||
.locked(c.clone())
|
.locked(c.clone())
|
||||||
.locked_shifted(c)
|
.locked_shifted(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn low(self, c: impl Into<DecodedKey> + Clone) -> Self {
|
pub fn low(self, c: impl Into<DecodedKey> + Clone) -> Self {
|
||||||
self.unshifted(c.clone()).locked_shifted(c)
|
self.unshifted(c.clone()).locked_shifted(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn high(self, c: impl Into<DecodedKey> + Clone) -> Self {
|
pub fn high(self, c: impl Into<DecodedKey> + Clone) -> Self {
|
||||||
self.shifted(c.clone()).locked(c)
|
self.shifted(c.clone()).locked(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn all(self, c: impl Into<DecodedKey> + Clone) -> Self {
|
pub fn all(self, c: impl Into<DecodedKey> + Clone) -> Self {
|
||||||
self.unshifted(c.clone())
|
self.unshifted(c.clone())
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use super::*;
|
||||||
|
|
||||||
mod custom_layout;
|
mod custom_layout;
|
||||||
mod custom_scancode_set;
|
mod custom_scancode_set;
|
||||||
mod layout_entry;
|
mod layout_entry;
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
mod abstractions;
|
mod abstractions;
|
||||||
mod small_types;
|
mod small_types;
|
||||||
mod traits;
|
mod traits;
|
||||||
|
|
||||||
pub use abstractions::*;
|
pub use abstractions::*;
|
||||||
pub use small_types::*;
|
pub use small_types::*;
|
||||||
pub use traits::*;
|
pub use traits::*;
|
||||||
|
|
||||||
const EXTENDED_KEY_CODE: u8 = 0xE0;
|
|
||||||
const KEYCODE_BITS: u8 = 11;
|
const KEYCODE_BITS: u8 = 11;
|
||||||
|
const EXTENDED_KEY_CODE: u8 = 0xE0;
|
||||||
const KEY_RELEASE_CODE: u8 = 0xF0;
|
const KEY_RELEASE_CODE: u8 = 0xF0;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Keyboard<T, S>
|
pub struct Keyboard<T, S>
|
||||||
where
|
where
|
||||||
|
@ -26,7 +22,6 @@ where
|
||||||
layout: T,
|
layout: T,
|
||||||
set: S,
|
set: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, S> Keyboard<T, S>
|
impl<T, S> Keyboard<T, S>
|
||||||
where
|
where
|
||||||
T: KeyboardLayout + Default,
|
T: KeyboardLayout + Default,
|
||||||
|
@ -52,17 +47,14 @@ where
|
||||||
set: S::default(),
|
set: S::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// /// Change the Ctrl key mapping.
|
||||||
/// Change the Ctrl key mapping.
|
|
||||||
pub fn set_ctrl_handling(&mut self, new_value: HandleControl) {
|
pub fn set_ctrl_handling(&mut self, new_value: HandleControl) {
|
||||||
self.handle_ctrl = new_value;
|
self.handle_ctrl = new_value;
|
||||||
}
|
}
|
||||||
|
// /// Get the current Ctrl key mapping.
|
||||||
/// Get the current Ctrl key mapping.
|
|
||||||
pub fn get_ctrl_handling(&self) -> HandleControl {
|
pub fn get_ctrl_handling(&self) -> HandleControl {
|
||||||
self.handle_ctrl
|
self.handle_ctrl
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clears the bit register.
|
/// Clears the bit register.
|
||||||
///
|
///
|
||||||
/// Call this when there is a timeout reading data from the keyboard.
|
/// Call this when there is a timeout reading data from the keyboard.
|
||||||
|
@ -71,7 +63,6 @@ where
|
||||||
self.num_bits = 0;
|
self.num_bits = 0;
|
||||||
self.decode_state = DecodeState::Start;
|
self.decode_state = DecodeState::Start;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes a 16-bit word from the keyboard.
|
/// Processes a 16-bit word from the keyboard.
|
||||||
///
|
///
|
||||||
/// * The start bit (0) must be in bit 0.
|
/// * The start bit (0) must be in bit 0.
|
||||||
|
@ -83,7 +74,6 @@ where
|
||||||
let byte = self.check_word(word)?;
|
let byte = self.check_word(word)?;
|
||||||
self.add_byte(byte)
|
self.add_byte(byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes an 8-bit byte from the keyboard.
|
/// Processes an 8-bit byte from the keyboard.
|
||||||
///
|
///
|
||||||
/// We assume the start, stop and parity bits have been processed and
|
/// We assume the start, stop and parity bits have been processed and
|
||||||
|
@ -91,7 +81,6 @@ where
|
||||||
pub fn add_byte(&mut self, byte: u8) -> Result<Option<KeyEvent>, Error> {
|
pub fn add_byte(&mut self, byte: u8) -> Result<Option<KeyEvent>, Error> {
|
||||||
self.set.advance_state(&mut self.decode_state, byte)
|
self.set.advance_state(&mut self.decode_state, byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shift a bit into the register.
|
/// Shift a bit into the register.
|
||||||
///
|
///
|
||||||
/// Call this /or/ call `add_word` - don't call both.
|
/// Call this /or/ call `add_word` - don't call both.
|
||||||
|
@ -108,7 +97,6 @@ where
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes a `KeyEvent` returned from `add_bit`, `add_byte` or `add_word`
|
/// Processes a `KeyEvent` returned from `add_bit`, `add_byte` or `add_word`
|
||||||
/// and produces a decoded key.
|
/// and produces a decoded key.
|
||||||
///
|
///
|
||||||
|
@ -211,15 +199,12 @@ where
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_bit(&self, word: u16, offset: usize) -> bool {
|
fn get_bit(&self, word: u16, offset: usize) -> bool {
|
||||||
((word >> offset) & 0x0001) != 0
|
((word >> offset) & 0x0001) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_even_number_bits(&self, data: u8) -> bool {
|
fn has_even_number_bits(&self, data: u8) -> bool {
|
||||||
(data.count_ones() % 2) == 0
|
(data.count_ones() % 2) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check 11-bit word has 1 start bit, 1 stop bit and an odd parity bit.
|
/// Check 11-bit word has 1 start bit, 1 stop bit and an odd parity bit.
|
||||||
fn check_word(&self, word: u16) -> Result<u8, Error> {
|
fn check_word(&self, word: u16) -> Result<u8, Error> {
|
||||||
let start_bit = self.get_bit(word, 0);
|
let start_bit = self.get_bit(word, 0);
|
||||||
|
@ -237,11 +222,9 @@ where
|
||||||
if need_parity != parity_bit {
|
if need_parity != parity_bit {
|
||||||
return Err(Error::ParityError);
|
return Err(Error::ParityError);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(data)
|
Ok(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_format() {
|
pub fn parse_format() {
|
||||||
let test = include_str!("../../keymaps/qwerty.keymap").lines();
|
let test = include_str!("../../keymaps/qwerty.keymap").lines();
|
||||||
// r#"0-NONE\n1-HI#Says HI"#
|
// r#"0-NONE\n1-HI#Says HI"#
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Modifiers {
|
pub struct Modifiers {
|
||||||
pub lshift: bool,
|
pub lshift: bool,
|
||||||
|
@ -10,21 +9,17 @@ pub struct Modifiers {
|
||||||
pub capslock: bool,
|
pub capslock: bool,
|
||||||
pub alt_gr: bool,
|
pub alt_gr: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Modifiers {
|
impl Modifiers {
|
||||||
pub fn is_shifted(&self) -> bool {
|
pub fn is_shifted(&self) -> bool {
|
||||||
self.lshift | self.rshift
|
self.lshift | self.rshift
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_ctrl(&self) -> bool {
|
pub fn is_ctrl(&self) -> bool {
|
||||||
self.lctrl | self.rctrl
|
self.lctrl | self.rctrl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_caps(&self) -> bool {
|
pub fn is_caps(&self) -> bool {
|
||||||
self.capslock
|
self.capslock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
pub enum KeyState {
|
pub enum KeyState {
|
||||||
Up,
|
Up,
|
||||||
|
@ -35,13 +30,11 @@ pub struct KeyEvent {
|
||||||
pub code: KeyCode,
|
pub code: KeyCode,
|
||||||
pub state: KeyState,
|
pub state: KeyState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyEvent {
|
impl KeyEvent {
|
||||||
pub fn new(code: KeyCode, state: KeyState) -> KeyEvent {
|
pub fn new(code: KeyCode, state: KeyState) -> KeyEvent {
|
||||||
KeyEvent { code, state }
|
KeyEvent { code, state }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
pub enum HandleControl {
|
pub enum HandleControl {
|
||||||
/// If either Ctrl key is held down, convert the letters A through Z into
|
/// If either Ctrl key is held down, convert the letters A through Z into
|
||||||
|
@ -52,7 +45,6 @@ pub enum HandleControl {
|
||||||
/// and leave the letters as letters.
|
/// and leave the letters as letters.
|
||||||
Ignore,
|
Ignore,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
pub enum DecodeState {
|
pub enum DecodeState {
|
||||||
Start,
|
Start,
|
||||||
|
@ -60,7 +52,6 @@ pub enum DecodeState {
|
||||||
Release,
|
Release,
|
||||||
ExtendedRelease,
|
ExtendedRelease,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicates different error conditions.
|
/// Indicates different error conditions.
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
@ -70,7 +61,6 @@ pub enum Error {
|
||||||
UnknownKeyCode,
|
UnknownKeyCode,
|
||||||
InvalidState,
|
InvalidState,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum DecodedKeyKind {
|
pub enum DecodedKeyKind {
|
||||||
|
@ -83,7 +73,6 @@ pub struct DecodedKey {
|
||||||
pub kind: DecodedKeyKind,
|
pub kind: DecodedKeyKind,
|
||||||
pub value: u32,
|
pub value: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<char> for DecodedKey {
|
impl From<char> for DecodedKey {
|
||||||
fn from(ch: char) -> Self {
|
fn from(ch: char) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -92,7 +81,6 @@ impl From<char> for DecodedKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<KeyCode> for DecodedKey {
|
impl From<KeyCode> for DecodedKey {
|
||||||
fn from(kc: KeyCode) -> Self {
|
fn from(kc: KeyCode) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -101,7 +89,6 @@ impl From<KeyCode> for DecodedKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DecodedKey {
|
impl DecodedKey {
|
||||||
pub const ZERO: Self = Self {
|
pub const ZERO: Self = Self {
|
||||||
kind: DecodedKeyKind::Unicode,
|
kind: DecodedKeyKind::Unicode,
|
||||||
|
@ -120,7 +107,6 @@ impl DecodedKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! keycode_enum {
|
macro_rules! keycode_enum {
|
||||||
(@get_last $Variant:ident) => {
|
(@get_last $Variant:ident) => {
|
||||||
Self::$Variant
|
Self::$Variant
|
||||||
|
@ -148,7 +134,6 @@ macro_rules! keycode_enum {
|
||||||
keycode_enum!($($Variant=$Value,)* );
|
keycode_enum!($($Variant=$Value,)* );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will be a way to map keys to other keys / keyyngs / macros
|
// This will be a way to map keys to other keys / keyyngs / macros
|
||||||
keycode_enum! {
|
keycode_enum! {
|
||||||
AltLeft = 0x00,
|
AltLeft = 0x00,
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
use super::Error;
|
use super::*;
|
||||||
use crate::{DecodeState, DecodedKey, HandleControl, KeyCode, KeyEvent, Modifiers};
|
|
||||||
|
|
||||||
pub trait ScancodeSet {
|
pub trait ScancodeSet {
|
||||||
/// Handles the state logic for the decoding of scan codes into key events.
|
/// Handles the state logic for the decoding of scan codes into key events.
|
||||||
fn advance_state(&self, state: &mut DecodeState, code: u8) -> Result<Option<KeyEvent>, Error>;
|
fn advance_state(&self, state: &mut DecodeState, code: u8) -> Result<Option<KeyEvent>, Error>;
|
||||||
|
|
||||||
/// Convert a Scan Code set X byte to our 'KeyType' enum
|
/// Convert a Scan Code set X byte to our 'KeyType' enum
|
||||||
fn map_scancode(&self, code: u8) -> Result<KeyCode, Error>;
|
fn map_scancode(&self, code: u8) -> Result<KeyCode, Error>;
|
||||||
|
|
||||||
/// Convert a Scan Code Set X extended byte (prefixed E0) to our `KeyType`
|
/// Convert a Scan Code Set X extended byte (prefixed E0) to our `KeyType`
|
||||||
/// enum.
|
/// enum.
|
||||||
fn map_extended_scancode(&self, code: u8) -> Result<KeyCode, Error>;
|
fn map_extended_scancode(&self, code: u8) -> Result<KeyCode, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait KeyboardLayout {
|
pub trait KeyboardLayout {
|
||||||
/// Convert a `KeyType` enum to a Unicode character, if possible.
|
/// Convert a `KeyType` enum to a Unicode character, if possible.
|
||||||
/// `KeyType::A` maps to `Some('a')` (or `Some('A')` if shifted), while
|
/// `KeyType::A` maps to `Some('a')` (or `Some('A')` if shifted), while
|
||||||
|
|
|
@ -1,18 +1,23 @@
|
||||||
#![allow(clippy::empty_loop)]
|
#![allow(clippy::empty_loop)]
|
||||||
|
|
||||||
use crate::arch::drivers::sysinfo::master;
|
// use acpi::AcpiTables;
|
||||||
use crate::scheduler::SCHEDULER;
|
// use x86_64::instructions::interrupts::{disable, enable};
|
||||||
use crate::{
|
|
||||||
|
// use crate::{scratchpad, SCHEDULER, SCREEN_BUFFER};
|
||||||
|
|
||||||
|
use {
|
||||||
|
crate::{
|
||||||
arch::{init, sloop},
|
arch::{init, sloop},
|
||||||
relib::network::socket::{SimpleSock, Socket},
|
relib::network::socket::{SimpleSock, Socket},
|
||||||
scratchpad,
|
scratchpad,
|
||||||
|
},
|
||||||
|
lazy_static::lazy_static,
|
||||||
};
|
};
|
||||||
use crate::{boot_conf::KernelConfig, systeminfo::RELEASE_TYPE};
|
|
||||||
use kernel::KERNEL_VERSION;
|
|
||||||
use spin::Lazy;
|
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
// TODO: Change this structure to allow for multiple cores loaded
|
// TODO: Change this structure to allow for multiple cores loaded
|
||||||
pub static KERNEL_CONF: Lazy<KernelConfig> = Lazy::new(KernelConfig::new);
|
pub static ref KERNEL_CONF: KernelConfig = KernelConfig::new();
|
||||||
|
}
|
||||||
|
|
||||||
/// The main entry point of the kernel
|
/// The main entry point of the kernel
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -24,7 +29,7 @@ pub fn kernel_main() -> ! {
|
||||||
} else {
|
} else {
|
||||||
log::set_max_level(log::LevelFilter::Off);
|
log::set_max_level(log::LevelFilter::Off);
|
||||||
}
|
}
|
||||||
let scheduler = SCHEDULER.lock();
|
let mut scheduler = SCHEDULER.lock();
|
||||||
for proc in &scheduler.execution_queue {
|
for proc in &scheduler.execution_queue {
|
||||||
trace!("{:?}", proc);
|
trace!("{:?}", proc);
|
||||||
}
|
}
|
||||||
|
@ -46,9 +51,18 @@ pub fn cpu_socket_startup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_version_data() {
|
pub fn log_version_data() {
|
||||||
info!("{} v{:?}", RELEASE_TYPE, KERNEL_VERSION);
|
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
||||||
info!(
|
info!(
|
||||||
"Brand String: {}",
|
"Brand String: {}",
|
||||||
master().unwrap().brand_string().unwrap()
|
master().unwrap().brand_string().unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use crate::info::master;
|
||||||
|
|
||||||
|
use kernel::KERNEL_VERSION;
|
||||||
|
|
||||||
|
use crate::scheduler::SCHEDULER;
|
||||||
|
use crate::{
|
||||||
|
boot_conf::KernelConfig, scheduler::capabilities::FileAccess, systeminfo::RELEASE_TYPE,
|
||||||
|
};
|
||||||
|
|
|
@ -4,82 +4,111 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![feature(abi_x86_interrupt)]
|
#![feature(
|
||||||
#![feature(alloc_error_handler)]
|
abi_x86_interrupt,
|
||||||
#![feature(prelude_import)]
|
asm_sym,
|
||||||
#![feature(asm_sym)] // Needed for riscv
|
alloc_error_handler,
|
||||||
#![feature(naked_functions)]
|
core_intrinsics,
|
||||||
|
exclusive_range_pattern,
|
||||||
#[macro_use]
|
lang_items,
|
||||||
pub extern crate log;
|
naked_functions,
|
||||||
|
slice_pattern,
|
||||||
pub extern crate alloc;
|
prelude_import
|
||||||
pub extern crate externc_libm as libm;
|
)]
|
||||||
|
|
||||||
/// Contains architecture specific code for aarch64.
|
/// Contains architecture specific code for aarch64.
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
#[path = "arch/aarch64/mod.rs"]
|
#[path = "arch/aarch64/mod.rs"]
|
||||||
pub mod arch;
|
pub mod arch;
|
||||||
|
|
||||||
/// Contains architecture specific code for riscv64.
|
|
||||||
#[cfg(target_arch = "riscv64")]
|
|
||||||
#[path = "arch/riscv/mod.rs"]
|
|
||||||
pub mod arch;
|
|
||||||
|
|
||||||
/// Contains architecture specific code for x86_64.
|
/// Contains architecture specific code for x86_64.
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
#[path = "arch/x86_64/mod.rs"]
|
#[path = "arch/x86_64/mod.rs"]
|
||||||
pub mod arch;
|
pub mod arch;
|
||||||
|
|
||||||
|
/// Contains architecture specific code for riscv64.
|
||||||
|
#[cfg(target_arch = "riscv64")]
|
||||||
|
#[path = "arch/riscv/mod.rs"]
|
||||||
|
pub mod arch;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
pub mod print;
|
||||||
|
pub mod devices;
|
||||||
|
pub mod rhai_shell;
|
||||||
|
pub mod wasm_jumploader;
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub mod port_io;
|
pub mod port_io;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod print;
|
pub mod serial_print;
|
||||||
|
pub mod time;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod serial_print;
|
pub extern crate log;
|
||||||
|
|
||||||
|
/////////////
|
||||||
|
// Modules //
|
||||||
|
/////////////
|
||||||
pub mod allocator;
|
pub mod allocator;
|
||||||
pub mod boot_conf;
|
|
||||||
pub mod devices;
|
|
||||||
pub mod driver_traits;
|
pub mod driver_traits;
|
||||||
pub mod experiments;
|
pub mod experiments;
|
||||||
pub mod filesystem;
|
|
||||||
pub mod graphics;
|
pub mod graphics;
|
||||||
pub mod kernel_state;
|
pub mod kernel_state;
|
||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
pub mod kmain;
|
pub mod kmain;
|
||||||
pub mod logger;
|
pub mod logger;
|
||||||
pub mod prelude;
|
pub mod proto_filetable;
|
||||||
pub mod relib;
|
pub mod relib;
|
||||||
pub mod rhai_shell;
|
|
||||||
pub mod scheduler;
|
pub mod scheduler;
|
||||||
pub mod scratchpad;
|
|
||||||
pub mod stdio;
|
|
||||||
pub mod time;
|
|
||||||
pub mod utils;
|
|
||||||
pub mod virtio;
|
|
||||||
pub mod wasm;
|
|
||||||
pub mod wasm_jumploader;
|
|
||||||
|
|
||||||
mod unicode_utils;
|
mod unicode_utils;
|
||||||
|
pub mod utils;
|
||||||
|
// pub mod vga_e;
|
||||||
|
pub mod wasm;
|
||||||
|
|
||||||
#[prelude_import]
|
pub extern crate alloc;
|
||||||
pub use prelude::rust_2021::*;
|
pub extern crate externc_libm as libm;
|
||||||
|
|
||||||
|
//////////////////
|
||||||
|
// Re-exports ///
|
||||||
|
////////////////
|
||||||
pub use allocator::*;
|
pub use allocator::*;
|
||||||
pub use driver_traits::*;
|
pub use driver_traits::*;
|
||||||
pub use experiments::*;
|
pub use experiments::*;
|
||||||
pub use graphics::*;
|
pub use graphics::*;
|
||||||
pub use kernel;
|
|
||||||
pub use kernel::messaging;
|
|
||||||
pub use kernel::panic;
|
|
||||||
pub use kernel_state::*;
|
pub use kernel_state::*;
|
||||||
pub use keyboard::*;
|
pub use keyboard::*;
|
||||||
pub use logger::*;
|
pub use logger::*;
|
||||||
|
pub use proto_filetable::*;
|
||||||
pub use relib::*;
|
pub use relib::*;
|
||||||
pub use scratchpad::*;
|
// pub use scheduler::*;
|
||||||
pub use utils::*;
|
pub use utils::*;
|
||||||
pub use virtio::*;
|
// pub use vga_e::*;
|
||||||
pub use wasm::*;
|
pub use wasm::*;
|
||||||
|
pub mod boot_conf;
|
||||||
|
pub mod virtio;
|
||||||
|
pub use virtio::*;
|
||||||
|
|
||||||
|
// pub mod alias_table;
|
||||||
|
// pub use alias_table::*;
|
||||||
|
|
||||||
|
// pub mod tests;
|
||||||
|
// pub use tests::*;
|
||||||
|
|
||||||
|
pub mod scratchpad;
|
||||||
|
pub use scratchpad::*;
|
||||||
|
pub mod filesystem;
|
||||||
|
|
||||||
|
///////////////
|
||||||
|
/// Kernel ///
|
||||||
|
/////////////
|
||||||
|
pub use kernel;
|
||||||
|
pub use kernel::messaging;
|
||||||
|
pub use kernel::panic;
|
||||||
|
|
||||||
|
pub mod prelude;
|
||||||
|
|
||||||
|
#[prelude_import]
|
||||||
|
pub use prelude::rust_2021::*;
|
||||||
|
|
||||||
|
pub mod stdio;
|
||||||
|
|
|
@ -1,31 +1,34 @@
|
||||||
|
use crate::boot_conf;
|
||||||
use crate::kmain::KERNEL_CONF;
|
use crate::kmain::KERNEL_CONF;
|
||||||
use crate::network::socket::{SimpleSock, Socket};
|
use crate::network::socket::{SimpleSock, Socket};
|
||||||
use crate::time::fetch_time;
|
use crate::time::fetch_time;
|
||||||
|
use core::sync::atomic::Ordering;
|
||||||
|
|
||||||
|
use kernel::TICK;
|
||||||
use lliw::{Fg, Reset};
|
use lliw::{Fg, Reset};
|
||||||
use log::{Level, Metadata, Record};
|
use log::{Level, Metadata, Record};
|
||||||
use log::{LevelFilter, SetLoggerError};
|
|
||||||
|
|
||||||
static LOGGER: SimpleLogger = SimpleLogger;
|
struct SimpleLogger;
|
||||||
// TODO: Rebuild this to take advantage of sockets
|
// TODO: Rebuild this to take advantage of sockets
|
||||||
// DETAIL: Log to a socket instead of the screen
|
// DETAIL: Log to a socket instead of the screen
|
||||||
// So that we can log in the kernel and display it in userland
|
// So that we can log in the kernel and display it in userland
|
||||||
struct SimpleLogger;
|
|
||||||
impl log::Log for SimpleLogger {
|
impl log::Log for SimpleLogger {
|
||||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||||
metadata.level() <= Level::Trace
|
metadata.level() <= Level::Trace
|
||||||
}
|
}
|
||||||
fn log(&self, record: &Record) {
|
fn log(&self, record: &Record) {
|
||||||
if self.enabled(record.metadata()) {
|
if self.enabled(record.metadata()) {
|
||||||
|
let color;
|
||||||
|
|
||||||
let time_float = fetch_time();
|
let time_float = fetch_time();
|
||||||
|
|
||||||
let color = match record.level() {
|
match record.level() {
|
||||||
log::Level::Error => (Fg::Red, "$RED$"),
|
log::Level::Error => color = (Fg::Red, "$RED$"),
|
||||||
log::Level::Warn => (Fg::LightYellow, "$LIGHTYELLOW$"),
|
log::Level::Warn => color = (Fg::LightYellow, "$LIGHTYELLOW$"),
|
||||||
log::Level::Info => (Fg::LightWhite, "$LIGHTGRAY$"),
|
log::Level::Info => color = (Fg::LightWhite, "$LIGHTGRAY$"),
|
||||||
log::Level::Debug => (Fg::Blue, "$BLUE$"),
|
log::Level::Debug => color = (Fg::Blue, "$BLUE$"),
|
||||||
log::Level::Trace => (Fg::Yellow, "$YELLOW$"),
|
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"),
|
||||||
};
|
}
|
||||||
|
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"[{}{}$RESET$][$GREEN${}$RESET$]{}\n",
|
"[{}{}$RESET$][$GREEN${}$RESET$]{}\n",
|
||||||
color.1,
|
color.1,
|
||||||
|
@ -63,6 +66,10 @@ impl log::Log for SimpleLogger {
|
||||||
fn flush(&self) {}
|
fn flush(&self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use log::{LevelFilter, SetLoggerError};
|
||||||
|
|
||||||
|
static LOGGER: SimpleLogger = SimpleLogger;
|
||||||
|
|
||||||
pub fn init() -> Result<(), SetLoggerError> {
|
pub fn init() -> Result<(), SetLoggerError> {
|
||||||
log::set_logger(&LOGGER).map(|()| log::set_max_level(LevelFilter::Trace))
|
log::set_logger(&LOGGER).map(|()| log::set_max_level(LevelFilter::Trace))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ use cpuio::{inb, inl, outb, outl};
|
||||||
pub fn read32(reg: u16) -> u32 {
|
pub fn read32(reg: u16) -> u32 {
|
||||||
unsafe { inl(reg) }
|
unsafe { inl(reg) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read8(reg: u16) -> u8 {
|
pub fn read8(reg: u16) -> u8 {
|
||||||
unsafe { inb(reg) }
|
unsafe { inb(reg) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
pub use crate::print::*;
|
|
||||||
pub use crate::serial_print::*;
|
|
||||||
pub use alloc::{boxed::Box, format, string::*, vec, vec::*};
|
|
||||||
pub use core::arch::asm;
|
pub use core::arch::asm;
|
||||||
pub use core::prelude::rust_2021::*;
|
pub use core::prelude::rust_2021::*;
|
||||||
pub use core::prelude::v1::*;
|
pub use core::prelude::v1::*;
|
||||||
|
|
||||||
|
pub use crate::print::*;
|
||||||
|
pub use crate::serial_print::*;
|
||||||
|
|
||||||
pub use log::{debug, info, trace, warn};
|
pub use log::{debug, info, trace, warn};
|
||||||
|
|
||||||
|
pub use alloc::{boxed::Box, format, string::*, vec, vec::*};
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
// TODO: refactor this file
|
// TODO: refactor this file
|
||||||
// TODO: make STDOUT redirect to a socket owned
|
// TODO: make STDOUT redirect to a socket owned
|
||||||
// by the process named "stdout"
|
// by the process named "stdout"
|
||||||
|
|
||||||
use core::fmt::{Arguments, Error};
|
|
||||||
|
|
||||||
pub struct Stdout;
|
pub struct Stdout;
|
||||||
|
use core::fmt::{Arguments, Error};
|
||||||
impl Stdout {
|
impl Stdout {
|
||||||
pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */
|
pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */
|
||||||
{
|
{
|
||||||
|
@ -12,7 +10,6 @@ impl Stdout {
|
||||||
// Ok(())
|
// Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Write for Stdout {
|
impl core::fmt::Write for Stdout {
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
||||||
|
@ -36,7 +33,6 @@ impl core::fmt::Write for Stdout {
|
||||||
core::fmt::write(&mut self, args)
|
core::fmt::write(&mut self, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! print {
|
macro_rules! print {
|
||||||
() => {
|
() => {
|
||||||
|
@ -50,5 +46,6 @@ macro_rules! print {
|
||||||
macro_rules! println {
|
macro_rules! println {
|
||||||
($($tt:tt)*) => {
|
($($tt:tt)*) => {
|
||||||
::core::writeln!($crate::print::Stdout, $($tt)*)
|
::core::writeln!($crate::print::Stdout, $($tt)*)
|
||||||
|
// panic![];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
5
ableos/src/proto_filetable/contain.rs
Normal file
5
ableos/src/proto_filetable/contain.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
use crate::ProtoFileTable;
|
||||||
|
|
||||||
|
lazy_static::lazy_static!(
|
||||||
|
pub static ref FILE_TABLE: spin::Mutex<ProtoFileTable> = spin::Mutex::new(ProtoFileTable::new());
|
||||||
|
);
|
82
ableos/src/proto_filetable/file.rs
Normal file
82
ableos/src/proto_filetable/file.rs
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
use core::fmt;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
pub struct PathRep {
|
||||||
|
pub location: FileLocations,
|
||||||
|
pub file_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct FilePermissions {
|
||||||
|
pub read: bool,
|
||||||
|
pub write: bool,
|
||||||
|
pub execute: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct FileMetadata {
|
||||||
|
pub file_type: String,
|
||||||
|
pub size: usize,
|
||||||
|
// pub permissions: FilePermissions,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum FileLocations {
|
||||||
|
Bin,
|
||||||
|
Config,
|
||||||
|
Home,
|
||||||
|
}
|
||||||
|
impl fmt::Display for FileLocations {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "{:?}", self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct File {
|
||||||
|
pub location: FileLocations,
|
||||||
|
pub file_name: String,
|
||||||
|
pub meta_data: FileMetadata,
|
||||||
|
pub data_pointer: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl File {
|
||||||
|
/// Write the provided bytes to a file
|
||||||
|
pub fn write_bytes(&mut self, bytes: &[u8]) {
|
||||||
|
for byte in bytes {
|
||||||
|
self.data_pointer.push(*byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.meta_data.size = self.data_pointer.len();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(location: FileLocations, file_name: String, file_type: String) -> Self {
|
||||||
|
let bytes: Vec<u8> = vec![];
|
||||||
|
let abc123 = bytes;
|
||||||
|
|
||||||
|
Self {
|
||||||
|
location,
|
||||||
|
file_name,
|
||||||
|
meta_data: FileMetadata { file_type, size: 0 },
|
||||||
|
data_pointer: abc123,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn size(&self) -> usize {
|
||||||
|
self.meta_data.size.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_to_string(&mut self, _string: &mut String) {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_and_return(&mut self) -> String {
|
||||||
|
String::from_utf8(self.data_pointer.clone()).expect("Found invalid UTF-8")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for File {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "{}://{}", self.location, self.file_name)
|
||||||
|
}
|
||||||
|
}
|
56
ableos/src/proto_filetable/mod.rs
Normal file
56
ableos/src/proto_filetable/mod.rs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
//! A file table module for AbleOS
|
||||||
|
//!
|
||||||
|
//! This module provides a file table interface for AbleOS.
|
||||||
|
//!
|
||||||
|
//! # Examples
|
||||||
|
//! ```
|
||||||
|
//! use relib::filesystem::ProtoFileTable;
|
||||||
|
//! let mut file_table = ProtoFileTable::new();
|
||||||
|
//! file_table.add_file("test.txt", "Hello, world!".as_bytes());
|
||||||
|
//! let file = file_table.get_file("test.txt");
|
||||||
|
//! assert_eq!(file.unwrap().as_slice(), "Hello, world!".as_bytes());
|
||||||
|
//! ```
|
||||||
|
//! # Notes
|
||||||
|
//! The file table is a simple in-memory hashmap.
|
||||||
|
//! The file table is not thread safe.
|
||||||
|
//! The file table is not persistent.
|
||||||
|
|
||||||
|
use hashbrown::HashMap;
|
||||||
|
|
||||||
|
pub mod contain;
|
||||||
|
pub mod file;
|
||||||
|
use file::File;
|
||||||
|
/// A prototype file table for AbleOS
|
||||||
|
///
|
||||||
|
/// This module provides a file table interface for AbleOS.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
/// ```
|
||||||
|
/// use crate::filesystem::ProtoFileTable;
|
||||||
|
/// let mut file_table = ProtoFileTable::new();
|
||||||
|
/// file_table.add_file("test.txt", "Hello, world!".as_bytes());
|
||||||
|
/// let file = file_table.get_file("test.txt");
|
||||||
|
/// assert_eq!(file.unwrap().as_slice(), "Hello, world!".as_bytes());
|
||||||
|
/// ```
|
||||||
|
pub struct ProtoFileTable {
|
||||||
|
files: HashMap<String, File>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProtoFileTable {
|
||||||
|
pub fn new() -> ProtoFileTable {
|
||||||
|
ProtoFileTable {
|
||||||
|
files: HashMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_file(&mut self, path: &str, contents: File) {
|
||||||
|
self.files.insert(path.to_string(), contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_file(&self, path: &str) -> Option<&File> {
|
||||||
|
self.files.get(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
16
ableos/src/proto_filetable/tests.rs
Normal file
16
ableos/src/proto_filetable/tests.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
use super::file::FileLocations;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
// #[test]
|
||||||
|
fn test_add_file() {
|
||||||
|
let mut file_table = ProtoFileTable::new();
|
||||||
|
let file_to_add = File::new(FileLocations::Bin, "test".to_string(), "txt".to_string());
|
||||||
|
file_to_add.write_bytes(b"Hello, world!");
|
||||||
|
file_table.add_file("test", file_to_add);
|
||||||
|
let file = file_table.get_file("test.txt");
|
||||||
|
assert_eq!(
|
||||||
|
file.unwrap().data_pointer.as_slice(),
|
||||||
|
"Hello, world!".as_bytes()
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,6 +1,9 @@
|
||||||
/// # clparse
|
/*
|
||||||
/// simple command line parser for ableOS
|
clparse
|
||||||
|
* A simple command line parser for ableOS
|
||||||
|
*/
|
||||||
|
|
||||||
|
// use std::collections::HashMap;
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Argument {
|
pub struct Argument {
|
||||||
key: String,
|
key: String,
|
||||||
|
@ -16,22 +19,25 @@ pub struct Command {
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn parse(command: String) -> Command {
|
pub fn parse(command: String) -> Command {
|
||||||
let split_command = command.split('?');
|
let split_command = command.split("?");
|
||||||
let mut root = "".to_string();
|
let mut root = "".to_string();
|
||||||
|
let mut root_count = 0;
|
||||||
let mut args: Vec<Argument> = vec![];
|
let mut args: Vec<Argument> = vec![];
|
||||||
for (root_count, subcommand) in split_command.enumerate() {
|
for subcommand in split_command {
|
||||||
match root_count {
|
match root_count {
|
||||||
0 => root = subcommand.to_string(),
|
0 => root = subcommand.to_string(),
|
||||||
1 => {
|
1 => {
|
||||||
for subarg in subcommand.split('&') {
|
for subarg in subcommand.split("&") {
|
||||||
let mut arg1 = "";
|
let mut arg1 = "";
|
||||||
let mut arg2 = "";
|
let mut arg2 = "";
|
||||||
for (n, arg) in subarg.split('=').enumerate() {
|
let mut arg_count = 0;
|
||||||
if n == 0 {
|
for arg in subarg.split("=") {
|
||||||
|
if arg_count == 0 {
|
||||||
arg1 = arg;
|
arg1 = arg;
|
||||||
} else {
|
} else {
|
||||||
arg2 = arg;
|
arg2 = arg;
|
||||||
}
|
}
|
||||||
|
arg_count += 1;
|
||||||
}
|
}
|
||||||
let arg_struct = Argument {
|
let arg_struct = Argument {
|
||||||
key: arg1.to_string(),
|
key: arg1.to_string(),
|
||||||
|
@ -42,6 +48,7 @@ impl Command {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
root_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command {
|
Command {
|
||||||
|
@ -50,7 +57,6 @@ impl Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test() {
|
pub fn test() {
|
||||||
let x = Command::parse("hi?there=uwu&hi=abc".to_string());
|
let x = Command::parse("hi?there=uwu&hi=abc".to_string());
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
pub fn encode(bytes: &[u8]) -> Vec<u8> {
|
pub fn encode(bytes: &[u8]) -> Vec<u8> {
|
||||||
let mut encoding = if bytes.first().is_none() {
|
let mut encoding;
|
||||||
|
|
||||||
|
if bytes.first().is_none() {
|
||||||
return vec![];
|
return vec![];
|
||||||
} else {
|
} else {
|
||||||
vec![*bytes.first().unwrap()]
|
encoding = vec![*bytes.first().unwrap()];
|
||||||
};
|
}
|
||||||
|
|
||||||
let mut occurrences = 1;
|
let mut occurrences = 1;
|
||||||
|
|
||||||
|
@ -17,12 +19,13 @@ pub fn encode(bytes: &[u8]) -> Vec<u8> {
|
||||||
}
|
}
|
||||||
|
|
||||||
encoding.push(occurrences);
|
encoding.push(occurrences);
|
||||||
|
|
||||||
encoding
|
encoding
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read a run-length encoding and return its decoded contents.
|
/// Read a run-length encoding and return its decoded contents.
|
||||||
///
|
///
|
||||||
/// - `bytes` - The bytes to be decoded.
|
/// * `bytes` - The bytes to be decoded.
|
||||||
pub fn decode(bytes: &[u8]) -> Vec<u8> {
|
pub fn decode(bytes: &[u8]) -> Vec<u8> {
|
||||||
let mut decoding = Vec::<u8>::new();
|
let mut decoding = Vec::<u8>::new();
|
||||||
|
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
pub mod mono_bitmap;
|
pub mod mono_bitmap;
|
||||||
|
|
||||||
|
pub mod stupid_simple_image;
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
use shadeable::pixel_format::new_rgba64;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
graphics::SCREEN_BUFFER,
|
graphics::SCREEN_BUFFER,
|
||||||
relib::encoding::rle::{decode, encode},
|
relib::encoding::rle::{decode, encode},
|
||||||
};
|
};
|
||||||
use shadeable::pixel_format::new_rgba64;
|
// use super::qoi;
|
||||||
|
|
||||||
pub fn bruh() {
|
pub fn bruh() {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
|
6
ableos/src/relib/image/stupid_simple_image/mod.rs
Normal file
6
ableos/src/relib/image/stupid_simple_image/mod.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
/*
|
||||||
|
r[255,0,0]
|
||||||
|
g[0,0,0]
|
||||||
|
b[0,0,0]
|
||||||
|
a[0,0,0]
|
||||||
|
*/
|
|
@ -1,6 +1,3 @@
|
||||||
pub static SOCKETS: spin::Mutex<SocketState> = spin::Mutex::new(vec![]);
|
|
||||||
|
|
||||||
pub type SocketState = Vec<SimpleSock>;
|
|
||||||
pub type Stream = Vec<u8>;
|
pub type Stream = Vec<u8>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -10,7 +7,12 @@ pub struct SocketID {
|
||||||
|
|
||||||
impl SocketID {
|
impl SocketID {
|
||||||
pub fn protocol(self) -> Option<String> {
|
pub fn protocol(self) -> Option<String> {
|
||||||
SOCKETS.lock()[self.id].protocol.clone()
|
let x = SOCKETS.lock()[self.id].protocol.clone();
|
||||||
|
|
||||||
|
match x {
|
||||||
|
Some(protocol_name) => Some(protocol_name),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +37,11 @@ impl Socket for SocketID {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type SocketState = Vec<SimpleSock>;
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref SOCKETS: spin::Mutex<SocketState> = spin::Mutex::new(vec![]);
|
||||||
|
}
|
||||||
pub trait Socket {
|
pub trait Socket {
|
||||||
fn peek(&mut self) -> SocketReturns;
|
fn peek(&mut self) -> SocketReturns;
|
||||||
|
|
||||||
|
@ -47,7 +54,6 @@ pub trait Socket {
|
||||||
|
|
||||||
fn close(&mut self) {}
|
fn close(&mut self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum SocketReturns {
|
pub enum SocketReturns {
|
||||||
ReadOk(Stream),
|
ReadOk(Stream),
|
||||||
|
@ -110,11 +116,10 @@ impl Socket for SimpleSock {
|
||||||
let mut return_vec = vec![];
|
let mut return_vec = vec![];
|
||||||
|
|
||||||
for x in &self.stream {
|
for x in &self.stream {
|
||||||
return_vec.push(*x);
|
return_vec.push(x.clone());
|
||||||
}
|
}
|
||||||
SocketReturns::ReadOk(return_vec)
|
SocketReturns::ReadOk(return_vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read(&mut self, length: usize) -> SocketReturns {
|
fn read(&mut self, length: usize) -> SocketReturns {
|
||||||
let mut return_vec = vec![];
|
let mut return_vec = vec![];
|
||||||
if length > self.stream.len() {
|
if length > self.stream.len() {
|
||||||
|
@ -127,11 +132,9 @@ impl Socket for SimpleSock {
|
||||||
SocketReturns::ReadOk(return_vec)
|
SocketReturns::ReadOk(return_vec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_protocol(&mut self, protocol_name: String) {
|
fn register_protocol(&mut self, protocol_name: String) {
|
||||||
self.protocol = Some(protocol_name);
|
self.protocol = Some(protocol_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_protocol(&mut self, protocol_name: String) -> bool {
|
fn check_protocol(&mut self, protocol_name: String) -> bool {
|
||||||
if self.protocol == Some(protocol_name) {
|
if self.protocol == Some(protocol_name) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -139,13 +142,11 @@ impl Socket for SimpleSock {
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&mut self, stream: Stream) -> SocketReturns {
|
fn write(&mut self, stream: Stream) -> SocketReturns {
|
||||||
for byte in stream {
|
for byte in stream {
|
||||||
self.stream.push(byte);
|
self.stream.push(byte);
|
||||||
}
|
}
|
||||||
SocketReturns::WriteOk
|
SocketReturns::WriteOk
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close(&mut self) {}
|
fn close(&mut self) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,8 @@
|
||||||
use super::Time;
|
use super::Time;
|
||||||
use core::fmt::{Display, Error, Formatter};
|
use core::fmt::{Display, Error, Formatter};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct Kilosecond(usize);
|
pub struct Kilosecond(usize);
|
||||||
impl Kilosecond {
|
|
||||||
pub fn from_ms(ms: usize) -> Self {
|
|
||||||
Self(ms)
|
|
||||||
}
|
|
||||||
pub fn from_sec(sec: usize) -> Self {
|
|
||||||
Self(sec * 1000)
|
|
||||||
}
|
|
||||||
pub fn from_minutes(min: usize) -> Self {
|
|
||||||
Self(min * 60 * 1000)
|
|
||||||
}
|
|
||||||
pub fn from_hours(hrs: usize) -> Self {
|
|
||||||
Self(hrs * 60 * 60 * 1000)
|
|
||||||
}
|
|
||||||
pub fn from_days(days: usize) -> Self {
|
|
||||||
Self(days * 24 * 60 * 60 * 1000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for Kilosecond {
|
impl Display for Kilosecond {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||||
let mut reg = self.0;
|
let mut reg = self.0;
|
||||||
|
@ -55,23 +36,37 @@ impl Display for Kilosecond {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::Add for Kilosecond {
|
impl core::ops::Add for Kilosecond {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
fn add(self, rhs: Self) -> Self {
|
fn add(self, rhs: Self) -> Self {
|
||||||
Self(self.0 + rhs.0)
|
Self(self.0 + rhs.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::Sub for Kilosecond {
|
impl core::ops::Sub for Kilosecond {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
fn sub(self, rhs: Self) -> Self {
|
fn sub(self, rhs: Self) -> Self {
|
||||||
Self(self.0 - rhs.0)
|
Self(self.0 - rhs.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Time> for Kilosecond {
|
impl From<Time> for Kilosecond {
|
||||||
fn from(t: Time) -> Self {
|
fn from(t: Time) -> Self {
|
||||||
Self((t.hour as usize * 3600 + t.minutes as usize * 60 + t.seconds as usize) * 1000)
|
Self((t.hour as usize * 3600 + t.minutes as usize * 60 + t.seconds as usize) * 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Kilosecond {
|
||||||
|
pub fn from_ms(ms: usize) -> Self {
|
||||||
|
Self(ms)
|
||||||
|
}
|
||||||
|
pub fn from_sec(sec: usize) -> Self {
|
||||||
|
Self(sec * 1000)
|
||||||
|
}
|
||||||
|
pub fn from_minutes(min: usize) -> Self {
|
||||||
|
Self(min * 60 * 1000)
|
||||||
|
}
|
||||||
|
pub fn from_hours(hrs: usize) -> Self {
|
||||||
|
Self(hrs * 60 * 60 * 1000)
|
||||||
|
}
|
||||||
|
pub fn from_days(days: usize) -> Self {
|
||||||
|
Self(days * 24 * 60 * 60 * 1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
pub mod kilotime;
|
|
||||||
|
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
pub struct Time {
|
pub struct Time {
|
||||||
pub year: u16,
|
pub year: u16,
|
||||||
pub month: u16,
|
pub month: u16,
|
||||||
|
@ -11,7 +7,6 @@ pub struct Time {
|
||||||
pub seconds: u16,
|
pub seconds: u16,
|
||||||
pub microseconds: u32,
|
pub microseconds: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Time {
|
impl fmt::Display for Time {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
|
@ -21,3 +16,5 @@ impl fmt::Display for Time {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub mod kilotime;
|
||||||
|
use core::fmt;
|
||||||
|
|
|
@ -1,27 +1,9 @@
|
||||||
use crate::arch::drivers::sysinfo::master;
|
|
||||||
use crate::filesystem::FILE_SYSTEM;
|
|
||||||
use crate::time::fetch_time;
|
|
||||||
use crate::wasm_jumploader::interp;
|
|
||||||
use crate::ALLOCATOR;
|
|
||||||
use crate::{
|
|
||||||
arch::{shutdown, sloop},
|
|
||||||
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
|
||||||
KERNEL_STATE,
|
|
||||||
};
|
|
||||||
use genfs::{Fs, OpenOptions};
|
|
||||||
use rhai::Engine;
|
|
||||||
use spin::Lazy;
|
|
||||||
use x86_64::instructions::interrupts::{disable, enable};
|
|
||||||
|
|
||||||
pub static KEYBUFF: spin::Mutex<Vec<char>> = spin::Mutex::new(Vec::new());
|
|
||||||
pub static CURRENT_DIR: Lazy<spin::Mutex<String>> = Lazy::new(|| spin::Mutex::new("/".to_string()));
|
|
||||||
|
|
||||||
#[cfg(target_arch = "riscv64")]
|
#[cfg(target_arch = "riscv64")]
|
||||||
pub fn shell() {}
|
pub fn shell() {}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub fn shell() {
|
pub fn shell() {
|
||||||
let _current_dir = "/".to_string();
|
let mut current_dir = "/".to_string();
|
||||||
let engine = engine_construction();
|
let engine = engine_construction();
|
||||||
let mut scope = rhai::Scope::new();
|
let mut scope = rhai::Scope::new();
|
||||||
|
|
||||||
|
@ -56,6 +38,23 @@ pub fn shell() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lazy_static::lazy_static!(
|
||||||
|
pub static ref KEYBUFF: spin::Mutex<Vec<char>> = spin::Mutex::new(Vec::new());
|
||||||
|
pub static ref CURRENT_DIR: spin::Mutex<String> = spin::Mutex::new("/".to_string());
|
||||||
|
);
|
||||||
|
|
||||||
|
use rhai::Engine;
|
||||||
|
use x86_64::instructions::interrupts::{disable, enable};
|
||||||
|
|
||||||
|
use crate::info::master;
|
||||||
|
use crate::time::fetch_time;
|
||||||
|
use crate::wasm_jumploader::interp;
|
||||||
|
use crate::{allocator, ALLOCATOR};
|
||||||
|
use crate::{
|
||||||
|
arch::{shutdown, sloop},
|
||||||
|
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
||||||
|
KERNEL_STATE,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn afetch() {
|
pub fn afetch() {
|
||||||
let kstate = KERNEL_STATE.lock();
|
let kstate = KERNEL_STATE.lock();
|
||||||
|
@ -68,6 +67,7 @@ pub fn afetch() {
|
||||||
let used = allocator.used();
|
let used = allocator.used();
|
||||||
enable();
|
enable();
|
||||||
|
|
||||||
|
// let mem = format!("{}/{}", used, size);
|
||||||
println!(
|
println!(
|
||||||
include_str!("balloon.txt"),
|
include_str!("balloon.txt"),
|
||||||
kstate.hostname,
|
kstate.hostname,
|
||||||
|
@ -75,33 +75,57 @@ pub fn afetch() {
|
||||||
KERNEL_VERSION,
|
KERNEL_VERSION,
|
||||||
tick_time,
|
tick_time,
|
||||||
master().unwrap().brand_string().unwrap(),
|
master().unwrap().brand_string().unwrap(),
|
||||||
// "",
|
|
||||||
// mem
|
// mem
|
||||||
used,
|
used,
|
||||||
size
|
size
|
||||||
);
|
);
|
||||||
drop(kstate);
|
drop(kstate);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_hostname(name: String) {
|
pub fn set_hostname(name: String) {
|
||||||
let mut kstate = KERNEL_STATE.lock();
|
let mut kstate = KERNEL_STATE.lock();
|
||||||
kstate.hostname = name;
|
kstate.hostname = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Examine a memory pointer
|
fn engine_construction() -> Engine {
|
||||||
pub fn peek_memory(ptr: i64) -> i64 {
|
let mut engine = rhai::Engine::new();
|
||||||
unsafe { *(ptr as *const u8) as _ }
|
|
||||||
|
engine.on_print(|x| println!("{}", x));
|
||||||
|
|
||||||
|
engine.on_debug(|x, src, pos| {
|
||||||
|
let src = src.unwrap_or("unknown");
|
||||||
|
println!("DEBUG: {} at {:?}: {}", src, pos, x);
|
||||||
|
debug!("{} at {:?}: {}", src, pos, x);
|
||||||
|
});
|
||||||
|
|
||||||
|
engine.register_fn("ls", ls);
|
||||||
|
engine.register_fn("cat", echo_file);
|
||||||
|
engine.register_fn("cd", change_directory);
|
||||||
|
engine.register_fn("afetch", afetch);
|
||||||
|
engine.register_fn("set_hostname", set_hostname);
|
||||||
|
engine.register_fn("shutdown", shutdown);
|
||||||
|
engine.register_fn("peek", peek_memory);
|
||||||
|
engine.register_fn("poke", poke_memory);
|
||||||
|
engine.register_fn("sloop", sloop);
|
||||||
|
engine.register_fn("wasm", interp);
|
||||||
|
engine.register_fn("log_dump", log_dump);
|
||||||
|
|
||||||
|
engine
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn poke_memory(ptr: i64, val: i64) {
|
/// Examine a memory pointer
|
||||||
match val.try_into() {
|
pub fn peek_memory(ptr: i64) -> u8 {
|
||||||
Ok(val) => unsafe { *(ptr as *mut u8) = val },
|
let ptr: usize = ptr.abs() as usize;
|
||||||
Err(_) => error!("{val} cannot be converted into u8"),
|
println!(">:(");
|
||||||
|
unsafe { *(ptr as *const u8) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn poke_memory(ptr: i64, val: u8) {
|
||||||
|
let ptr: usize = ptr.abs() as usize;
|
||||||
|
unsafe { *(ptr as *mut u8) = val }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ls() {
|
pub fn ls() {
|
||||||
let current_dir = CURRENT_DIR.lock();
|
let mut current_dir = CURRENT_DIR.lock();
|
||||||
|
|
||||||
let fs = &*FILE_SYSTEM.lock();
|
let fs = &*FILE_SYSTEM.lock();
|
||||||
|
|
||||||
|
@ -141,6 +165,9 @@ pub fn log_dump() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use crate::filesystem::FILE_SYSTEM;
|
||||||
|
use genfs::{DirEntry, Fs, OpenOptions};
|
||||||
|
|
||||||
pub fn echo_file(path: String) {
|
pub fn echo_file(path: String) {
|
||||||
let mut current_dir = CURRENT_DIR.lock();
|
let mut current_dir = CURRENT_DIR.lock();
|
||||||
|
|
||||||
|
@ -154,10 +181,12 @@ pub fn echo_file(path: String) {
|
||||||
|
|
||||||
if file.is_dir() {
|
if file.is_dir() {
|
||||||
println!("{} is a directory", path);
|
println!("{} is a directory", path);
|
||||||
|
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
let mut file_contents = Vec::new();
|
let mut file_contents = Vec::new();
|
||||||
|
|
||||||
let _ret = file.read_to_end(&mut file_contents).unwrap();
|
let ret = file.read_to_end(&mut file_contents).unwrap();
|
||||||
|
|
||||||
let file_contents_str = String::from_utf8_lossy(&file_contents);
|
let file_contents_str = String::from_utf8_lossy(&file_contents);
|
||||||
|
|
||||||
|
@ -168,13 +197,13 @@ pub fn echo_file(path: String) {
|
||||||
pub fn change_directory(path: String) {
|
pub fn change_directory(path: String) {
|
||||||
let mut current_dir = CURRENT_DIR.lock();
|
let mut current_dir = CURRENT_DIR.lock();
|
||||||
|
|
||||||
let _fs = &*FILE_SYSTEM.lock();
|
let fs = &*FILE_SYSTEM.lock();
|
||||||
if path == "." || path == ".." {
|
if path == "." || path == ".." {
|
||||||
let mut split_dir = current_dir.split('/').collect::<Vec<&str>>();
|
let mut split_dir = current_dir.split("/").collect::<Vec<&str>>();
|
||||||
let mut new_dir = String::new();
|
let mut new_dir = String::new();
|
||||||
split_dir.remove(split_dir.len() - 1);
|
split_dir.remove(split_dir.len() - 1);
|
||||||
println!("{:?}", split_dir);
|
println!("{:?}", split_dir);
|
||||||
if split_dir.is_empty() {
|
if split_dir.len() == 0 {
|
||||||
new_dir = "/".to_string();
|
new_dir = "/".to_string();
|
||||||
} else {
|
} else {
|
||||||
for x in split_dir {
|
for x in split_dir {
|
||||||
|
@ -185,33 +214,8 @@ pub fn change_directory(path: String) {
|
||||||
*current_dir = new_dir;
|
*current_dir = new_dir;
|
||||||
} else {
|
} else {
|
||||||
if !current_dir.ends_with('/') {
|
if !current_dir.ends_with('/') {
|
||||||
current_dir.push('/');
|
current_dir.push_str("/");
|
||||||
}
|
}
|
||||||
current_dir.push_str(&path);
|
current_dir.push_str(&path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn engine_construction() -> Engine {
|
|
||||||
let mut engine = rhai::Engine::new();
|
|
||||||
|
|
||||||
engine.on_print(|x| println!("{}", x));
|
|
||||||
engine.on_debug(|x, src, pos| {
|
|
||||||
let src = src.unwrap_or("unknown");
|
|
||||||
println!("DEBUG: {} at {:?}: {}", src, pos, x);
|
|
||||||
debug!("{} at {:?}: {}", src, pos, x);
|
|
||||||
});
|
|
||||||
|
|
||||||
engine.register_fn("ls", ls);
|
|
||||||
engine.register_fn("cat", echo_file);
|
|
||||||
engine.register_fn("cd", change_directory);
|
|
||||||
engine.register_fn("afetch", afetch);
|
|
||||||
engine.register_fn("set_hostname", set_hostname);
|
|
||||||
engine.register_fn("shutdown", shutdown);
|
|
||||||
engine.register_fn("peek", peek_memory);
|
|
||||||
engine.register_fn("poke", poke_memory);
|
|
||||||
engine.register_fn("sloop", sloop);
|
|
||||||
engine.register_fn("wasm", interp);
|
|
||||||
engine.register_fn("log_dump", log_dump);
|
|
||||||
|
|
||||||
engine
|
|
||||||
}
|
|
||||||
|
|
|
@ -54,7 +54,6 @@ pub struct Capabilities {
|
||||||
pub sound_cards: SoundCardAccess,
|
pub sound_cards: SoundCardAccess,
|
||||||
pub network_access: NetworkAccess,
|
pub network_access: NetworkAccess,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Capabilities {
|
impl Capabilities {
|
||||||
/// Generate a set of empty capabilities
|
/// Generate a set of empty capabilities
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
|
use crate::{arch::generate_process_pass, stdio::StdIO};
|
||||||
|
|
||||||
|
use crate::scheduler::capabilities::Capabilities;
|
||||||
|
|
||||||
|
use kernel::proccess::PID;
|
||||||
pub mod capabilities;
|
pub mod capabilities;
|
||||||
pub mod priority;
|
pub mod priority;
|
||||||
pub mod proc;
|
pub mod proc;
|
||||||
|
|
||||||
use crate::scheduler::capabilities::Capabilities;
|
|
||||||
use crate::{arch::generate_process_pass, stdio::StdIO};
|
|
||||||
use kernel::proccess::PID;
|
|
||||||
use priority::Priority;
|
use priority::Priority;
|
||||||
use proc::Process;
|
use proc::Process;
|
||||||
|
|
||||||
pub static SCHEDULER: spin::Mutex<Scheduler> = spin::Mutex::new(Scheduler::new());
|
|
||||||
|
|
||||||
/// Add additional wake conditions to the list
|
/// Add additional wake conditions to the list
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum WakeCondition {
|
pub enum WakeCondition {
|
||||||
|
@ -36,12 +34,11 @@ pub struct Scheduler {
|
||||||
pub execution_queue: Vec<Process>,
|
pub execution_queue: Vec<Process>,
|
||||||
pub sleeping_queue: Vec<BlockedProcess>,
|
pub sleeping_queue: Vec<BlockedProcess>,
|
||||||
pub blocked_queue: Vec<BlockedProcess>,
|
pub blocked_queue: Vec<BlockedProcess>,
|
||||||
// All timed processes sorted by wake time
|
// / All timed processes sorted by wake time
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scheduler {
|
impl Scheduler {
|
||||||
/// Create a new scheduler
|
/// Create a new scheduler
|
||||||
pub const fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
free_pid: 0,
|
free_pid: 0,
|
||||||
process_exec_time: 0,
|
process_exec_time: 0,
|
||||||
|
@ -72,14 +69,15 @@ impl Scheduler {
|
||||||
working_dir: String,
|
working_dir: String,
|
||||||
stdio: StdIO,
|
stdio: StdIO,
|
||||||
) -> Process {
|
) -> Process {
|
||||||
Process {
|
let mut process = Process {
|
||||||
pid: 0,
|
pid: 0,
|
||||||
priority,
|
priority,
|
||||||
working_dir,
|
working_dir,
|
||||||
stdio,
|
stdio,
|
||||||
password: generate_process_pass(),
|
password: generate_process_pass(),
|
||||||
capabilities,
|
capabilities,
|
||||||
}
|
};
|
||||||
|
process
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sleep_process(&mut self, process: &mut Process) {
|
pub fn sleep_process(&mut self, process: &mut Process) {
|
||||||
|
@ -88,7 +86,11 @@ impl Scheduler {
|
||||||
wake_condition: WakeCondition::TimerInterrupt(0),
|
wake_condition: WakeCondition::TimerInterrupt(0),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.sleeping_queue.push(sleeping_process);
|
self.sleeping_queue.push(sleeping_process.clone());
|
||||||
self.execution_queue.remove(0);
|
self.execution_queue.remove(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref SCHEDULER: spin::Mutex<Scheduler> = spin::Mutex::new(Scheduler::new());
|
||||||
|
}
|
||||||
|
|
|
@ -22,3 +22,5 @@ pub struct Process {
|
||||||
pub working_dir: String,
|
pub working_dir: String,
|
||||||
pub stdio: StdIO,
|
pub stdio: StdIO,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Process {}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
use core::alloc::Layout;
|
use acpi::AcpiTables;
|
||||||
|
use kernel::device_interface::character::CharacterDevice;
|
||||||
|
|
||||||
|
use crate::devices::DEVICE_TABLE;
|
||||||
use crate::rhai_shell::shell;
|
use crate::rhai_shell::shell;
|
||||||
use acpi::{AcpiTables, PlatformInfo};
|
|
||||||
|
use crate::stdio::StdIO;
|
||||||
|
|
||||||
|
use crate::devices::Device::Vterm;
|
||||||
|
|
||||||
/// Experimental scratchpad for testing.
|
/// Experimental scratchpad for testing.
|
||||||
pub fn scratchpad() {
|
pub fn scratchpad() {
|
||||||
|
@ -16,10 +21,12 @@ pub fn scratchpad() {
|
||||||
for node in axel {
|
for node in axel {
|
||||||
info!("{:?}", node);
|
info!("{:?}", node);
|
||||||
}
|
}
|
||||||
// acpi();
|
|
||||||
shell();
|
shell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use core::fmt::Write;
|
||||||
|
|
||||||
pub fn pci_fun() {}
|
pub fn pci_fun() {}
|
||||||
|
|
||||||
pub fn acpi() {
|
pub fn acpi() {
|
||||||
|
@ -28,22 +35,8 @@ pub fn acpi() {
|
||||||
unsafe {
|
unsafe {
|
||||||
_table = AcpiTables::search_for_rsdp_bios(acpi_handler);
|
_table = AcpiTables::search_for_rsdp_bios(acpi_handler);
|
||||||
}
|
}
|
||||||
match _table.unwrap().platform_info().unwrap() {
|
|
||||||
PlatformInfo {
|
|
||||||
power_profile,
|
|
||||||
interrupt_model,
|
|
||||||
processor_info,
|
|
||||||
pm_timer,
|
|
||||||
} => {
|
|
||||||
info!("{:?}", power_profile);
|
|
||||||
info!("{:?}", interrupt_model);
|
|
||||||
// info!("{:?}", processor_info.unwrap());
|
|
||||||
// info!("{:?}", pm_timer.unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => todo!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: move to a better place
|
// TODO: move to a better place
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub struct AcpiStruct {}
|
pub struct AcpiStruct {}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use core::fmt::{Arguments, Error};
|
|
||||||
|
|
||||||
pub struct Serialout;
|
pub struct Serialout;
|
||||||
|
use core::fmt::{Arguments, Error};
|
||||||
impl Serialout {
|
impl Serialout {
|
||||||
pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */
|
pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */
|
||||||
{
|
{
|
||||||
|
@ -8,7 +7,6 @@ impl Serialout {
|
||||||
// Ok(())
|
// Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Write for Serialout {
|
impl core::fmt::Write for Serialout {
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
||||||
|
@ -32,7 +30,6 @@ impl core::fmt::Write for Serialout {
|
||||||
core::fmt::write(&mut self, args)
|
core::fmt::write(&mut self, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! serial_print {
|
macro_rules! serial_print {
|
||||||
() => {
|
() => {
|
||||||
|
@ -42,10 +39,10 @@ macro_rules! serial_print {
|
||||||
::core::write!($crate::serial_print::Serialout, $($tt)*)
|
::core::write!($crate::serial_print::Serialout, $($tt)*)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! serial_println {
|
macro_rules! serial_println {
|
||||||
($($tt:tt)*) => {
|
($($tt:tt)*) => {
|
||||||
::core::writeln!($crate::serial_print::Serialout, $($tt)*)
|
::core::writeln!($crate::serial_print::Serialout, $($tt)*)
|
||||||
|
// panic![];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
use {
|
use {
|
||||||
crate::devices::Device::{Character, Vterm},
|
crate::{
|
||||||
|
devices::Device::{Character, Vterm},
|
||||||
|
kprintln,
|
||||||
|
},
|
||||||
core::fmt::{Arguments, Error, Write},
|
core::fmt::{Arguments, Error, Write},
|
||||||
kernel::device_interface::character::CharacterDevice,
|
kernel::device_interface::character::CharacterDevice,
|
||||||
};
|
};
|
||||||
|
@ -37,23 +40,7 @@ impl StdIO {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&mut self) {
|
pub fn read(&mut self) {
|
||||||
use crate::devices::DEVICE_TABLE;
|
todo!();
|
||||||
let mut dt = DEVICE_TABLE.lock();
|
|
||||||
let key_device = dt.devices.get_mut(&self.device).unwrap();
|
|
||||||
|
|
||||||
match key_device {
|
|
||||||
Character(dev) => {
|
|
||||||
let mut buf = String::new();
|
|
||||||
dev.read_char().map(|c| buf.push(c));
|
|
||||||
println!("{}", buf);
|
|
||||||
}
|
|
||||||
Vterm(vterm) => {
|
|
||||||
let mut buf = String::new();
|
|
||||||
vterm.read_char().map(|c| buf.push(c));
|
|
||||||
println!("{}", buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
|
use picorand::PicoRandGenerate;
|
||||||
|
use rkyv::{ser::serializers::AllocSerializer, Deserialize};
|
||||||
|
use shadeable::pixel_format::from_vga_16;
|
||||||
|
use vga::colors::Color16;
|
||||||
|
use y_compositor_protocol::Version;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
kmain::KERNEL_CONF,
|
kmain::KERNEL_CONF,
|
||||||
network::socket::{SimpleSock, Socket, SocketReturns},
|
network::socket::{SimpleSock, Socket, SocketReturns},
|
||||||
num_to_vga16, VgaBuffer, SCREEN_BUFFER,
|
num_to_vga16, VgaBuffer, SCREEN_BUFFER,
|
||||||
};
|
};
|
||||||
use kernel::TICK;
|
use kernel::TICK;
|
||||||
use picorand::PicoRandGenerate;
|
|
||||||
use rkyv::{ser::serializers::AllocSerializer, Deserialize};
|
|
||||||
use shadeable::pixel_format::from_vga_16;
|
|
||||||
use vga::colors::Color16;
|
|
||||||
use y_compositor_protocol::Version;
|
|
||||||
|
|
||||||
pub fn run_tests() {
|
pub fn run_tests() {
|
||||||
if KERNEL_CONF.tests.run_tests {
|
if KERNEL_CONF.tests.run_tests {
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
use core::sync::atomic::Ordering;
|
|
||||||
use kernel::TICK;
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub fn fetch_time() -> f64 {
|
pub fn fetch_time() -> f64 {
|
||||||
use x86_64::instructions::interrupts::{disable, enable};
|
use x86_64::instructions::interrupts::{disable, enable};
|
||||||
|
@ -11,6 +8,8 @@ pub fn fetch_time() -> f64 {
|
||||||
time
|
time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use core::sync::atomic::Ordering;
|
||||||
|
use kernel::TICK;
|
||||||
#[cfg(target_arch = "riscv64")]
|
#[cfg(target_arch = "riscv64")]
|
||||||
pub fn fetch_time() -> f64 {
|
pub fn fetch_time() -> f64 {
|
||||||
let time = TICK.load(Ordering::Relaxed) as f64;
|
let time = TICK.load(Ordering::Relaxed) as f64;
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
pub const CONSOLE: &str = "\u{E795}";
|
|
||||||
pub const POWER_SIGN: &str = "\u{23FB}";
|
pub const POWER_SIGN: &str = "\u{23FB}";
|
||||||
pub const LAMBDA: &str = "λ";
|
pub const CONSOLE: &str = "\u{E795}";
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
//!
|
//!
|
||||||
|
//!
|
||||||
|
//!
|
||||||
|
//!
|
||||||
|
//!
|
||||||
|
|
||||||
pub enum UsbSpeed {
|
pub enum UsbSpeed {
|
||||||
/// Super-speed functions operate at up to 5 Gb/s.
|
/// Super-speed functions operate at up to 5 Gb/s.
|
||||||
Super,
|
Super,
|
||||||
|
|
||||||
/// High-speed functions operate at up to 480 Mb/s.
|
/// High-speed functions operate at up to 480 Mb/s.
|
||||||
High,
|
High,
|
||||||
|
|
||||||
/// Full-speed functions operate at up to 12 Mb/s.
|
/// Full-speed functions operate at up to 12 Mb/s.
|
||||||
Full,
|
Full,
|
||||||
|
|
||||||
/// Low-speed functions operate at up to 1.5 Mb/s.
|
/// Low-speed functions operate at up to 1.5 Mb/s.
|
||||||
Low,
|
Low,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
//! Small generic utilities
|
//! Small generic utilities
|
||||||
|
//!
|
||||||
|
//!
|
||||||
|
//!
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn type_of<T>(_: &T) -> &str {
|
pub fn type_of<T>(_: &T) -> &str {
|
||||||
core::any::type_name::<T>()
|
core::any::type_name::<T>()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
#[allow(unconditional_recursion)]
|
|
||||||
pub extern "C" fn stack_overflow() -> u8 {
|
|
||||||
stack_overflow();
|
|
||||||
// meme number
|
|
||||||
69 // NOTE: Any specific reason for this number aside from memes?
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -22,3 +16,11 @@ mod tests {
|
||||||
assert_eq!(type_of(&1), "i32");
|
assert_eq!(type_of(&1), "i32");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
#[allow(unconditional_recursion)]
|
||||||
|
pub extern "C" fn stack_overflow() -> u8 {
|
||||||
|
stack_overflow();
|
||||||
|
// meme number
|
||||||
|
69 // NOTE: Any specific reason for this number aside from memes?
|
||||||
|
}
|
||||||
|
|
|
@ -3,18 +3,19 @@ use vga::{
|
||||||
writers::{Graphics640x480x16, GraphicsWriter},
|
writers::{Graphics640x480x16, GraphicsWriter},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub static VGAE_BUFF_OFFSET_X: spin::Mutex<u8> = spin::Mutex::new(0);
|
lazy_static::lazy_static! {
|
||||||
pub static VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
|
pub static ref VGAE: spin::Mutex<Graphics640x480x16> = {
|
||||||
pub static VGAE: spin::Mutex<Graphics640x480x16> = {
|
|
||||||
let xyz = Graphics640x480x16::new();
|
let xyz = Graphics640x480x16::new();
|
||||||
xyz.set_mode();
|
xyz.set_mode();
|
||||||
spin::Mutex::new(xyz)
|
spin::Mutex::new(xyz)
|
||||||
};
|
};
|
||||||
|
pub static ref VGAE_BUFF_OFFSET_X: spin::Mutex<u8> = spin::Mutex::new(0);
|
||||||
|
pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts a number to ... i forgor 💀
|
/// Converts a number to ... i forgor 💀
|
||||||
pub const fn num_to_vga16(num: u8) -> Color16 {
|
pub fn num_to_vga16(num: u8) -> Color16 {
|
||||||
use Color16::*;
|
use Color16::*;
|
||||||
|
|
||||||
match num {
|
match num {
|
||||||
0 => Black,
|
0 => Black,
|
||||||
1 => Blue,
|
1 => Blue,
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue