Refactoring

- Applied some clippy lints
- Formatting
- Replaced lazy_static with Lazy from spin
This commit is contained in:
Erin 2022-04-11 22:51:54 +02:00 committed by ondra05
parent 2e1ad746fe
commit 56b569deb2
35 changed files with 218 additions and 314 deletions

15
Cargo.lock generated
View file

@ -37,7 +37,6 @@ dependencies = [
"genfs",
"hashbrown 0.7.2",
"kernel",
"lazy_static",
"libwasm",
"linked_list_allocator",
"lliw",
@ -53,7 +52,7 @@ dependencies = [
"rkyv",
"serde",
"shadeable",
"spin 0.5.2",
"spin",
"toml",
"uart_16550",
"unicode-width",
@ -274,7 +273,7 @@ dependencies = [
"bitflags",
"genfs",
"rlibc",
"spin 0.9.2",
"spin",
]
[[package]]
@ -384,7 +383,6 @@ dependencies = [
name = "kernel"
version = "0.1.2"
dependencies = [
"lazy_static",
"log",
"versioning",
]
@ -394,9 +392,6 @@ name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
dependencies = [
"spin 0.5.2",
]
[[package]]
name = "libc"
@ -842,12 +837,6 @@ dependencies = [
"version_check",
]
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "spin"
version = "0.9.2"

View file

@ -34,6 +34,7 @@ run-args = [
"unix:../qmp-sock,server,nowait"
]
test-args = [
"-device",
"isa-debug-exit,iobase=0xf4,iosize=0x04",
@ -41,12 +42,10 @@ test-args = [
"stdio",
]
[dependencies]
linked_list_allocator = "0.9.0"
lliw = "0.2.0"
spin = "0.5.2"
spin = "0.9"
log = "*"
pretty-hex = "0.2.1"
unicode-width = "0.1.7"
@ -56,39 +55,32 @@ genfs = "0.1.0"
rhai = "1.6.0"
libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}
acpi = "4.1.0"
axel = { git = "https://git.ablecorp.us/able/aos_userland" }
[dependencies.logos]
version = "0.12.0"
version = "0.12"
default-features = false
features = ["export_derive"]
[dependencies.rdrand]
version = "0.8.1"
version = "0.8"
default-features = false
[dependencies.kernel]
path = "../kernel"
[dependencies.serde]
version = "1.0.136"
version = "1.0"
default-features = false
features = ["derive", "alloc"]
[dependencies.hashbrown]
version = "0.7.2"
version = "0.7"
default-features = false
features = ["inline-more"]
[dependencies.rkyv]
version = "0.7.29"
version = "0.7"
default-features = false
features = ["size_64", "alloc"]
@ -103,15 +95,11 @@ git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git"
[dependencies.ext2]
git = "https://git.ablecorp.us:443/able/ext2-rs.git"
[dependencies.toml]
git = "https://github.com/diondokter/toml-rs"
# version = "0.5.8"
default-features = false
[dependencies.shadeable]
path = "../shadeable"
@ -128,10 +116,6 @@ default-features = false
features = ["core"]
version = "*"
[dependencies.lazy_static]
features = ["spin_no_std"]
version = "1.0"
[dependencies.externc-libm]
git = "https://git.ablecorp.us:443/able/externc-libm.git"

View file

@ -1,8 +1,7 @@
use hashbrown::HashMap;
lazy_static::lazy_static! {
pub static ref ALIAS_TABLE: spin::Mutex<AliasTable> = spin::Mutex::new(AliasTable::new());
}
pub static ALIAS_TABLE: spin::Mutex<AliasTable> = spin::Mutex::new(AliasTable::new());
/// A table of aliases
///
/// This is used to allow users to specify aliases for files and commands

View file

@ -1,13 +1,12 @@
use lazy_static::lazy_static;
use spin::Mutex;
use spin::{Lazy, Mutex};
use uart_16550::SerialPort;
lazy_static! {
pub static ref SERIAL1: Mutex<SerialPort> = {
pub static SERIAL1: Lazy<Mutex<SerialPort>> = Lazy::new(|| {
let mut serial_port = unsafe { SerialPort::new(0x3F8) };
serial_port.init();
Mutex::new(serial_port)
};
}
});
#[doc(hidden)]
pub fn _print(args: ::core::fmt::Arguments) {
use core::fmt::Write;

View file

@ -23,7 +23,7 @@ pub enum Color {
#[repr(transparent)]
struct ColorCode(u8);
impl ColorCode {
fn new(foreground: Color, background: Color) -> ColorCode {
const fn new(foreground: Color, background: Color) -> ColorCode {
ColorCode((background as u8) << 4 | (foreground as u8))
}
}
@ -114,17 +114,17 @@ impl fmt::Write for Writer {
Ok(())
}
}
lazy_static! {
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
pub static WRITER: Lazy<Mutex<Writer>> = Lazy::new(|| {
Mutex::new(Writer {
column_position: 0,
color_code: ColorCode::new(Color::White, Color::Black),
buffer: unsafe { &mut *(0xb8000 as *mut Buffer) },
});
}
})
});
use core::fmt;
use lazy_static::lazy_static;
use spin::Mutex;
use spin::{Lazy, Mutex};
use volatile::Volatile;

View file

@ -1,10 +1,10 @@
use lazy_static::lazy_static;
use spin::Lazy;
use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector};
use x86_64::structures::tss::TaskStateSegment;
use x86_64::VirtAddr;
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0;
lazy_static! {
static ref TSS: TaskStateSegment = {
static TSS: Lazy<TaskStateSegment> = Lazy::new(|| {
let mut tss = TaskStateSegment::new();
tss.interrupt_stack_table[DOUBLE_FAULT_IST_INDEX as usize] = {
const STACK_SIZE: usize = 4096 * 5;
@ -14,14 +14,9 @@ lazy_static! {
stack_start + STACK_SIZE
};
tss
};
}
struct Selectors {
code_selector: SegmentSelector,
tss_selector: SegmentSelector,
}
lazy_static! {
static ref GDT: (GlobalDescriptorTable, Selectors) = {
});
static GDT: Lazy<(GlobalDescriptorTable, Selectors)> = Lazy::new(|| {
let mut gdt = GlobalDescriptorTable::new();
let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS));
@ -32,8 +27,13 @@ lazy_static! {
tss_selector,
},
)
};
});
struct Selectors {
code_selector: SegmentSelector,
tss_selector: SegmentSelector,
}
pub fn init() {
use x86_64::instructions::segmentation::{Segment, CS};
use x86_64::instructions::tables::load_tss;

View file

@ -6,9 +6,8 @@ use crate::{
};
use cpuio::outb;
use lazy_static::lazy_static;
use pic8259::ChainedPics;
use spin;
use spin::Lazy;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
pub const PIC_1_OFFSET: u8 = 32;
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
@ -35,12 +34,13 @@ impl InterruptIndex {
pub fn init_idt() {
IDT.load();
}
lazy_static! {
static ref IDT: InterruptDescriptorTable = {
static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
let mut idt = InterruptDescriptorTable::new();
idt.breakpoint.set_handler_fn(breakpoint_handler);
unsafe {
idt.double_fault.set_handler_fn(double_fault_handler)
idt.double_fault
.set_handler_fn(double_fault_handler)
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
}
@ -48,14 +48,12 @@ lazy_static! {
set_pit_frequency(1000);
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler);
idt[InterruptIndex::Keyboard.as_usize()] .set_handler_fn(keyboard_interrupt_handler);
idt[InterruptIndex::Keyboard.as_usize()].set_handler_fn(keyboard_interrupt_handler);
idt[6].set_handler_fn(floppy_disk_interrupt_handler);
idt
};
}
});
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
@ -84,14 +82,15 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
};
use spin::Mutex;
use x86_64::instructions::port::Port;
lazy_static! {
static ref KEYBOARD: Mutex<Keyboard<CustomLayout, CustomScancodeSet>> =
static KEYBOARD: Lazy<Mutex<Keyboard<CustomLayout, CustomScancodeSet>>> = Lazy::new(|| {
Mutex::new(Keyboard::new(
CustomLayout::new_us104key(),
CustomScancodeSet::default(),
HandleControl::Ignore
));
}
HandleControl::Ignore,
))
});
let mut keyboard = KEYBOARD.lock();
let mut port = Port::new(0x60);
let scancode: u8 = unsafe { port.read() };

View file

@ -54,6 +54,5 @@ pub fn generate_process_pass() -> u128 {
use rdrand::RdRand;
let gen = RdRand::new().unwrap();
let ret = (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128);
ret
(gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128)
}

View file

@ -177,30 +177,30 @@ impl CharacterDevice for VTerm {
'\n' => {
self.cursor_position.1 += 1;
self.cursor_position.0 = 0;
return true;
true
}
'\r' => {
self.cursor_position.0 = 0;
return true;
true
}
'\t' => {
self.cursor_position.0 += 4;
return true;
true
}
'\x08' => {
self.cursor_position.0 -= 1;
self.characters[self.cursor_position.1 as usize][self.cursor_position.0 as usize]
.character = ' ';
return true;
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' => {
self.characters = [[VtermCharacter {
character: ' ',
char_color: (0xff_ff_ff_ff, 0x00_00_00_00),
style: Style::default(),
}; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize];
return true;
true
}
_ => {
@ -213,11 +213,11 @@ impl CharacterDevice for VTerm {
if self.cursor_position.0 < VTERM_WIDTH {
self.cursor_position.0 += 1;
return true;
true
} else {
self.cursor_position.0 = 0;
self.cursor_position.1 += 1;
return true;
true
}
}
}
@ -239,8 +239,6 @@ impl CharacterDevice for VTerm {
}
}
lazy_static::lazy_static! {
pub static ref VIRTUAL_TERMINAL_COUNT: AtomicU32 = AtomicU32::new(0);
}
pub static VIRTUAL_TERMINAL_COUNT: AtomicU32 = AtomicU32::new(0);
use core::sync::atomic::AtomicU32;
use core::sync::atomic::Ordering;

View file

@ -3,6 +3,7 @@ pub mod id;
pub mod pci_inner;
use hashbrown::HashMap;
use spin::Lazy;
mod dev_vterm;
use crate::devices::dev_vterm::VTerm;
use kernel::device_interface::character::CharacterDevice;
@ -10,7 +11,7 @@ use kernel::device_interface::character::CharacterDevice;
// #[derive(Debug)]
pub enum Device {
Character(Box<dyn CharacterDevice>),
Vterm(VTerm),
Vterm(Box<VTerm>),
}
unsafe impl Sync for Device {}
unsafe impl Send for Device {}
@ -32,12 +33,10 @@ impl DeviceTable {
next_read_char: 0x00 as char,
})),
);
table.insert("kvterm".to_string(), Vterm(VTerm::new()));
table.insert("kvterm".to_string(), Vterm(Box::new(VTerm::new())));
DeviceTable { devices: table }
}
}
lazy_static::lazy_static!(
pub static ref DEVICE_TABLE: spin::Mutex<DeviceTable> =
spin::Mutex::new(DeviceTable::new());
);
pub static DEVICE_TABLE: Lazy<spin::Mutex<DeviceTable>> =
Lazy::new(|| spin::Mutex::new(DeviceTable::new()));

View file

@ -16,7 +16,7 @@ impl CharacterDevice for Serial {
todo!()
}
fn write_char(&mut self, c: char) -> bool {
fn write_char(&mut self, _c: char) -> bool {
todo!()
}

View file

@ -1,7 +1,7 @@
// TODO improve tokenizer/parser
pub fn colorify(eval: &str) {
let y = eval.split("$");
let y = eval.split('$');
for z in y {
match z {
"BLACK" => {
@ -55,7 +55,7 @@ pub fn colorify(eval: &str) {
"RESET" => {
// set_vga_color(Color::White, Color::Black);
}
elk => {
_elk => {
// kprint!("{}", elk);
}
}
@ -91,7 +91,7 @@ pub fn colorify_2(eval: &str) {
Reset => {
// set_vga_color(Color::White, Color::Black);
}
Text(text) => {
Text(_text) => {
// kprint!("{}", text);
}
err => {

View file

@ -1,19 +1,14 @@
use alloc::{string::String, vec, vec::Vec};
// use crate::String;
// use crate::Vec;
use lazy_static::lazy_static;
#[derive(Debug)]
pub enum Mime {
None,
Text(String),
}
lazy_static! {
pub static ref CLIPBOARD: spin::Mutex<Clipboard> = {
let clipboard = Clipboard::new();
spin::Mutex::new(clipboard)
};
}
pub static CLIPBOARD: spin::Mutex<Clipboard> = spin::Mutex::new(Clipboard::new());
// ctrl+v paste but not pop and pastes
// ctrl+shift+v pops from the stack and pastes
@ -26,29 +21,34 @@ pub struct Clipboard {
pub pages: Vec<Mime>,
}
impl Clipboard {
pub fn new() -> Clipboard {
pub const fn new() -> Clipboard {
Clipboard {
index: 0,
pages: vec![],
}
}
pub fn clear(&mut self) {
self.pages = vec![];
}
pub fn set_index(&mut self, index_new: usize) {
self.index = index_new;
}
pub fn clip_end(&mut self) {
self.index = 0;
}
pub fn clip_home(&mut self) {
self.index = self.pages.len();
}
pub fn copy(&mut self, copy_mime: Mime) {
self.pages.push(copy_mime);
}
pub fn paste(&mut self) -> &Mime {
let paste_pos = &self.pages[self.index];
paste_pos
&self.pages[self.index] as _
}
}

View file

@ -445,7 +445,7 @@ impl Clone for BrandString {
for (d, s) in bytes.iter_mut().zip(self.bytes.iter()) {
*d = *s;
}
BrandString { bytes: bytes }
BrandString { bytes }
}
}
@ -752,12 +752,12 @@ impl Master {
let tpm = when_supported(
max_value,
RequestType::ThermalPowerManagementInformation,
|| ThermalPowerManagementInformation::new(),
ThermalPowerManagementInformation::new,
);
let sei = when_supported(
max_value,
RequestType::StructuredExtendedInformation,
|| StructuredExtendedInformation::new(),
StructuredExtendedInformation::new,
);
// Extended information
@ -767,9 +767,8 @@ impl Master {
let eps = when_supported(max_value, RequestType::ExtendedProcessorSignature, || {
ExtendedProcessorSignature::new()
});
let brand_string =
when_supported(max_value, RequestType::BrandString3, || BrandString::new());
let cache_line = when_supported(max_value, RequestType::CacheLine, || CacheLine::new());
let brand_string = 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, || {
TimeStampCounter::new()
});
@ -782,8 +781,8 @@ impl Master {
thermal_power_management_information: tpm,
structured_extended_information: sei,
extended_processor_signature: eps,
brand_string: brand_string,
cache_line: cache_line,
brand_string,
cache_line,
time_stamp_counter: tsc,
physical_address_size: pas,
}
@ -807,7 +806,7 @@ impl Master {
self.brand_string
.as_ref()
.map(|bs| bs as &str)
.or(self.version_information.and_then(|vi| vi.brand_string()))
.or_else(|| self.version_information.and_then(|vi| vi.brand_string()))
}
delegate_flag!(version_information, {

View file

@ -11,16 +11,14 @@ impl core::fmt::Display for SemanticVersion {
}
}
// NOTE: Move to somewhere else
lazy_static! {
pub static ref KINFO: KernelInfo = KernelInfo {
pub static KINFO: KernelInfo = KernelInfo {
kernel_version: SemanticVersion {
major: 0,
minor: 0,
patch: 0,
},
memory: SystemMemory { used: 0, total: 0 }
};
}
memory: SystemMemory { used: 0, total: 0 },
};
/// simple info you would want to know in a neofetch like program
pub struct KernelInfo {
// os: String,
@ -31,4 +29,3 @@ pub struct KernelInfo {
pub memory: SystemMemory,
}
use super::systeminfo::SystemMemory;
use lazy_static::lazy_static;

View file

@ -6,24 +6,23 @@ use ext2::{
sector::{SectorSize, Size1024},
volume::Volume,
};
use spin::Lazy;
fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
let mut volume = Vec::new();
volume.extend_from_slice(include_bytes!("../../../userland/root_fs/ext2.img"));
let fs = Synced::<Ext2<Size1024, _>>::new(volume).unwrap();
fs
Synced::<Ext2<Size1024, _>>::new(volume).unwrap()
}
// use serde::__private::from_utf8_lossy;
pub fn walk<'vol, S: SectorSize, V: Volume<u8, S>>(
fs: &'vol Synced<Ext2<S, V>>,
pub fn walk<S: SectorSize, V: Volume<u8, S>>(
fs: &Synced<Ext2<S, V>>,
inode: Inode<S, V>,
name: String,
) {
inode.directory().map(|dir| {
if let Some(dir) = inode.directory() {
for entry in dir {
assert!(entry.is_ok());
let entry = entry.unwrap();
@ -38,8 +37,8 @@ pub fn walk<'vol, 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());
);
pub static FILE_SYSTEM: Lazy<spin::Mutex<Synced<Ext2<Size1024, Vec<u8>>>>> =
Lazy::new(|| spin::Mutex::new(load_fs()));

View file

@ -2,7 +2,7 @@
use ab_glyph::{Font, FontRef, Glyph};
use shadeable::{evaluate_shader, pixel_format::Rgba64};
use spin;
use spin::Lazy;
// use vga::{colors::Color16, writers::GraphicsWriter};
#[derive(Debug)]
@ -15,10 +15,8 @@ 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));
}
pub static SCREEN_BUFFER: Lazy<spin::Mutex<ScreenBuffer>> =
Lazy::new(|| spin::Mutex::new(ScreenBuffer::new(640, 480)));
impl ScreenSize {
pub fn new(x: usize, y: usize) -> Self {
@ -46,6 +44,7 @@ impl ScreenBuffer {
buff: vec![0u64; x * y].into_boxed_slice(),
}
}
pub fn draw_filled_circle(&mut self, cx: i32, cy: i32, radius: usize, color: Rgba64) {
let r = radius as i32 * 2;
for y in 0..640 {

View file

@ -1,9 +1,7 @@
use lazy_static::lazy_static;
use spin::Lazy;
lazy_static! {
pub static ref KERNEL_STATE: spin::Mutex<KernelInternalState> =
spin::Mutex::new(KernelInternalState::new());
}
pub static KERNEL_STATE: Lazy<spin::Mutex<KernelInternalState>> =
Lazy::new(|| spin::Mutex::new(KernelInternalState::new()));
pub struct KernelInternalState {
pub hostname: String,

View file

@ -5,19 +5,15 @@
// use crate::{scratchpad, SCHEDULER, SCREEN_BUFFER};
use {
crate::{
use crate::{
arch::{init, sloop},
relib::network::socket::{SimpleSock, Socket},
scratchpad,
},
lazy_static::lazy_static,
};
use spin::Lazy;
lazy_static! {
// TODO: Change this structure to allow for multiple cores loaded
pub static ref KERNEL_CONF: KernelConfig = KernelConfig::new();
}
// TODO: Change this structure to allow for multiple cores loaded
pub static KERNEL_CONF: Lazy<KernelConfig> = Lazy::new(KernelConfig::new);
/// The main entry point of the kernel
#[no_mangle]
@ -29,7 +25,7 @@ pub fn kernel_main() -> ! {
} else {
log::set_max_level(log::LevelFilter::Off);
}
let mut scheduler = SCHEDULER.lock();
let scheduler = SCHEDULER.lock();
for proc in &scheduler.execution_queue {
trace!("{:?}", proc);
}
@ -63,6 +59,4 @@ use crate::info::master;
use kernel::KERNEL_VERSION;
use crate::scheduler::SCHEDULER;
use crate::{
boot_conf::KernelConfig, scheduler::capabilities::FileAccess, systeminfo::RELEASE_TYPE,
};
use crate::{boot_conf::KernelConfig, systeminfo::RELEASE_TYPE};

View file

@ -1,10 +1,7 @@
use crate::boot_conf;
use crate::kmain::KERNEL_CONF;
use crate::network::socket::{SimpleSock, Socket};
use crate::time::fetch_time;
use core::sync::atomic::Ordering;
use kernel::TICK;
use lliw::{Fg, Reset};
use log::{Level, Metadata, Record};
@ -18,17 +15,16 @@ impl log::Log for SimpleLogger {
}
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
let color;
let time_float = fetch_time();
match record.level() {
log::Level::Error => color = (Fg::Red, "$RED$"),
log::Level::Warn => color = (Fg::LightYellow, "$LIGHTYELLOW$"),
log::Level::Info => color = (Fg::LightWhite, "$LIGHTGRAY$"),
log::Level::Debug => color = (Fg::Blue, "$BLUE$"),
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"),
}
let color = match record.level() {
log::Level::Error => (Fg::Red, "$RED$"),
log::Level::Warn => (Fg::LightYellow, "$LIGHTYELLOW$"),
log::Level::Info => (Fg::LightWhite, "$LIGHTGRAY$"),
log::Level::Debug => (Fg::Blue, "$BLUE$"),
log::Level::Trace => (Fg::Yellow, "$YELLOW$"),
};
let msg = format!(
"[{}{}$RESET$][$GREEN${}$RESET$]{}\n",
color.1,

View file

@ -19,25 +19,22 @@ pub struct Command {
impl 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_count = 0;
let mut args: Vec<Argument> = vec![];
for subcommand in split_command {
for (root_count, subcommand) in split_command.enumerate() {
match root_count {
0 => root = subcommand.to_string(),
1 => {
for subarg in subcommand.split("&") {
for subarg in subcommand.split('&') {
let mut arg1 = "";
let mut arg2 = "";
let mut arg_count = 0;
for arg in subarg.split("=") {
if arg_count == 0 {
for (n, arg) in subarg.split('=').enumerate() {
if n == 0 {
arg1 = arg;
} else {
arg2 = arg;
}
arg_count += 1;
}
let arg_struct = Argument {
key: arg1.to_string(),
@ -48,7 +45,6 @@ impl Command {
}
_ => {}
}
root_count += 1;
}
Command {

View file

@ -1,11 +1,9 @@
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![];
} else {
encoding = vec![*bytes.first().unwrap()];
}
vec![*bytes.first().unwrap()]
};
let mut occurrences = 1;

View file

@ -7,12 +7,7 @@ pub struct SocketID {
impl SocketID {
pub fn protocol(self) -> Option<String> {
let x = SOCKETS.lock()[self.id].protocol.clone();
match x {
Some(protocol_name) => Some(protocol_name),
None => None,
}
SOCKETS.lock()[self.id].protocol.clone()
}
}
@ -38,10 +33,8 @@ impl Socket for SocketID {
}
pub type SocketState = Vec<SimpleSock>;
pub static SOCKETS: spin::Mutex<SocketState> = spin::Mutex::new(vec![]);
lazy_static::lazy_static! {
pub static ref SOCKETS: spin::Mutex<SocketState> = spin::Mutex::new(vec![]);
}
pub trait Socket {
fn peek(&mut self) -> SocketReturns;
@ -116,7 +109,7 @@ impl Socket for SimpleSock {
let mut return_vec = vec![];
for x in &self.stream {
return_vec.push(x.clone());
return_vec.push(*x);
}
SocketReturns::ReadOk(return_vec)
}

View file

@ -1,9 +1,11 @@
use spin::Lazy;
#[cfg(target_arch = "riscv64")]
pub fn shell() {}
#[cfg(target_arch = "x86_64")]
pub fn shell() {
let mut current_dir = "/".to_string();
let _current_dir = "/".to_string();
let engine = engine_construction();
let mut scope = rhai::Scope::new();
@ -38,10 +40,9 @@ 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());
);
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()));
use rhai::Engine;
use x86_64::instructions::interrupts::{disable, enable};
@ -49,7 +50,7 @@ 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::ALLOCATOR;
use crate::{
arch::{shutdown, sloop},
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
@ -114,18 +115,18 @@ fn engine_construction() -> Engine {
/// Examine a memory pointer
pub fn peek_memory(ptr: i64) -> u8 {
let ptr: usize = ptr.abs() as usize;
let ptr: usize = ptr.unsigned_abs() as _;
println!(">:(");
unsafe { *(ptr as *const u8) }
}
pub fn poke_memory(ptr: i64, val: u8) {
let ptr: usize = ptr.abs() as usize;
let ptr: usize = ptr.unsigned_abs() as _;
unsafe { *(ptr as *mut u8) = val }
}
pub fn ls() {
let mut current_dir = CURRENT_DIR.lock();
let current_dir = CURRENT_DIR.lock();
let fs = &*FILE_SYSTEM.lock();
@ -166,7 +167,7 @@ pub fn log_dump() {
}
use crate::filesystem::FILE_SYSTEM;
use genfs::{DirEntry, Fs, OpenOptions};
use genfs::{Fs, OpenOptions};
pub fn echo_file(path: String) {
let mut current_dir = CURRENT_DIR.lock();
@ -181,12 +182,10 @@ pub fn echo_file(path: String) {
if file.is_dir() {
println!("{} is a directory", path);
return;
} else {
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);
@ -197,13 +196,13 @@ pub fn echo_file(path: String) {
pub fn change_directory(path: String) {
let mut current_dir = CURRENT_DIR.lock();
let fs = &*FILE_SYSTEM.lock();
let _fs = &*FILE_SYSTEM.lock();
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();
split_dir.remove(split_dir.len() - 1);
println!("{:?}", split_dir);
if split_dir.len() == 0 {
if split_dir.is_empty() {
new_dir = "/".to_string();
} else {
for x in split_dir {
@ -214,7 +213,7 @@ pub fn change_directory(path: String) {
*current_dir = new_dir;
} else {
if !current_dir.ends_with('/') {
current_dir.push_str("/");
current_dir.push('/');
}
current_dir.push_str(&path);
}

View file

@ -38,7 +38,7 @@ pub struct Scheduler {
}
impl Scheduler {
/// Create a new scheduler
pub fn new() -> Self {
pub const fn new() -> Self {
Self {
free_pid: 0,
process_exec_time: 0,
@ -69,15 +69,14 @@ impl Scheduler {
working_dir: String,
stdio: StdIO,
) -> Process {
let mut process = Process {
Process {
pid: 0,
priority,
working_dir,
stdio,
password: generate_process_pass(),
capabilities,
};
process
}
}
pub fn sleep_process(&mut self, process: &mut Process) {
@ -86,11 +85,9 @@ impl Scheduler {
wake_condition: WakeCondition::TimerInterrupt(0),
};
self.sleeping_queue.push(sleeping_process.clone());
self.sleeping_queue.push(sleeping_process);
self.execution_queue.remove(0);
}
}
lazy_static::lazy_static! {
pub static ref SCHEDULER: spin::Mutex<Scheduler> = spin::Mutex::new(Scheduler::new());
}
pub static SCHEDULER: spin::Mutex<Scheduler> = spin::Mutex::new(Scheduler::new());

View file

@ -1,13 +1,7 @@
use acpi::AcpiTables;
use kernel::device_interface::character::CharacterDevice;
use crate::devices::DEVICE_TABLE;
use crate::rhai_shell::shell;
use crate::stdio::StdIO;
use crate::devices::Device::Vterm;
/// Experimental scratchpad for testing.
pub fn scratchpad() {
let axel_raw = "kernel{
@ -25,8 +19,6 @@ pub fn scratchpad() {
shell();
}
use core::fmt::Write;
pub fn pci_fun() {}
pub fn acpi() {

View file

@ -1,8 +1,5 @@
use {
crate::{
devices::Device::{Character, Vterm},
kprintln,
},
crate::devices::Device::{Character, Vterm},
core::fmt::{Arguments, Error, Write},
kernel::device_interface::character::CharacterDevice,
};

View file

@ -3,15 +3,13 @@ use vga::{
writers::{Graphics640x480x16, GraphicsWriter},
};
lazy_static::lazy_static! {
pub static ref VGAE: spin::Mutex<Graphics640x480x16> = {
pub static VGAE: spin::Mutex<Graphics640x480x16> = {
let xyz = Graphics640x480x16::new();
xyz.set_mode();
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);
}
};
pub static VGAE_BUFF_OFFSET_X: spin::Mutex<u8> = spin::Mutex::new(0);
pub static VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
/// Converts a number to ... i forgor 💀
pub fn num_to_vga16(num: u8) -> Color16 {

View file

@ -104,6 +104,6 @@ impl WasmProgram {
if self.raw_bytes[4..8] == WASM_VERSION {
byte_version_valid = true;
}
return (byte_magic_valid, byte_version_valid);
(byte_magic_valid, byte_version_valid)
}
}

View file

@ -1,5 +1,3 @@
use core::arch;
use wasmi::{
Error, Externals, FuncInstance, FuncRef, ModuleImportResolver, RuntimeArgs, RuntimeValue,
Signature, Trap, ValueType,
@ -113,7 +111,7 @@ impl HostExternals {
return false;
}
}
return true;
true
}
SEND_SIGNAL_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) =
@ -129,7 +127,7 @@ impl HostExternals {
return false;
}
}
return true;
true
}
GET_TIME_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) =
@ -145,7 +143,7 @@ impl HostExternals {
return false;
}
}
return true;
true
}
GET_RANDOM_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) =
@ -161,7 +159,7 @@ impl HostExternals {
return false;
}
}
return true;
true
}
GET_INPUT_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) =
@ -177,7 +175,7 @@ impl HostExternals {
return false;
}
}
return true;
true
}
PRINT_CLEVER_HACK => {
@ -193,7 +191,7 @@ impl HostExternals {
return false;
}
}
return true;
true
}
_ => false,
}
@ -228,4 +226,3 @@ impl ModuleImportResolver for HostExternals {
Ok(FuncInstance::alloc_host(signature.clone(), index))
}
}
use crate::wasm_jumploader::host_functions::ValueType::I32;

View file

@ -35,25 +35,25 @@ pub fn interp() {
match instance {
Ok(inst) => {
let mut instance = inst.assert_no_start();
let instance = inst.assert_no_start();
let mut is_driver = false;
let mut is_program = false;
let _is_program = false;
let mut has_driver_entry = false;
let mut has_driver_exit = false;
let mut has_start = false;
if let Some(val) = instance.export_by_name("driver_entry") {
if let Some(_val) = instance.export_by_name("driver_entry") {
has_driver_entry = true;
}
if let Some(val) = instance.export_by_name("driver_exit") {
if let Some(_val) = instance.export_by_name("driver_exit") {
has_driver_exit = true;
}
match instance.export_by_name("start") {
Some(val) => {
Some(_val) => {
trace!("Program start function found");
has_start = true;
}

View file

@ -3,13 +3,8 @@ edition = "2021"
name = "kernel"
version = "0.1.2"
[dependencies]
log = "0.4.14"
[dependencies.lazy_static]
version = "1.4.0"
default-features = false
[dependencies.versioning]
git = "https://git.ablecorp.us/able/aos_userland"

View file

@ -23,10 +23,8 @@ pub fn tick() {
TICK.store(data, Relaxed)
}
lazy_static::lazy_static! {
/// The number of ticks since the first CPU was started
pub static ref TICK: AtomicU64 = AtomicU64::new(0);
}
/// The number of ticks since the first CPU was started
pub static TICK: AtomicU64 = AtomicU64::new(0);
///
pub const KERNEL_VERSION: Version = Version {

View file

@ -5,10 +5,6 @@ edition = "2021"
authors = ["Able", "NotAble"]
[dependencies]
<<<<<<< HEAD
=======
clap = { version = "3.1", features = ["cargo", "derive"] }
>>>>>>> e6dbfb4a0a4e14c8bf2ead04bb2078627f5780eb
xshell = "0.1.9"
anyhow = "*"

View file

@ -32,8 +32,8 @@ enum Command {
#[derive(clap::ArgEnum, Debug, Clone)]
enum MachineType {
X86,
RISCV,
ARM,
Riscv,
Arm,
}
fn main() -> anyhow::Result<()> {
@ -51,7 +51,7 @@ fn main() -> anyhow::Result<()> {
MachineType::X86 => {
xshell::cmd!("cargo run --release").run()?;
}
MachineType::ARM => {
MachineType::Arm => {
xshell::cmd!("cargo build --release --target=json_targets/aarch64-ableos.json")
.run()?;
#[rustfmt::skip]
@ -65,7 +65,7 @@ fn main() -> anyhow::Result<()> {
"
).run()?;
}
MachineType::RISCV => {
MachineType::Riscv => {
xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf")
.run()?;
#[rustfmt::skip]
@ -91,23 +91,23 @@ fn main() -> anyhow::Result<()> {
MachineType::X86 => {
xshell::cmd!("cargo doc --open").run()?;
}
MachineType::ARM => {
MachineType::Arm => {
xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json")
.run()?;
}
MachineType::RISCV => {
MachineType::Riscv => {
xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?;
}
}
}
Command::Mount { path } => {
let path = path.unwrap_or("./userland/root_fs/mnt".to_string());
let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string());
xshell::cmd!("sudo mount userland/root_fs/ext2.img {path}").run()?;
}
Command::Unmount { path } => {
let path = path.unwrap_or("./userland/root_fs/mnt".to_string());
let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string());
xshell::cmd!("sudo umount {path}").run()?;
}
}