1
0
Fork 0
forked from AbleOS/ableos

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

View file

@ -34,6 +34,7 @@ run-args = [
"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",
@ -41,12 +42,10 @@ 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.5.2" spin = "0.9"
log = "*" log = "*"
pretty-hex = "0.2.1" pretty-hex = "0.2.1"
unicode-width = "0.1.7" unicode-width = "0.1.7"
@ -56,39 +55,32 @@ genfs = "0.1.0"
rhai = "1.6.0" rhai = "1.6.0"
libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"} libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}
acpi = "4.1.0" acpi = "4.1.0"
axel = { git = "https://git.ablecorp.us/able/aos_userland" } axel = { git = "https://git.ablecorp.us/able/aos_userland" }
[dependencies.logos] [dependencies.logos]
version = "0.12.0" version = "0.12"
default-features = false default-features = false
features = ["export_derive"] features = ["export_derive"]
[dependencies.rdrand] [dependencies.rdrand]
version = "0.8.1" version = "0.8"
default-features = false default-features = false
[dependencies.kernel] [dependencies.kernel]
path = "../kernel" path = "../kernel"
[dependencies.serde] [dependencies.serde]
version = "1.0.136" version = "1.0"
default-features = false default-features = false
features = ["derive", "alloc"] features = ["derive", "alloc"]
[dependencies.hashbrown] [dependencies.hashbrown]
version = "0.7.2" version = "0.7"
default-features = false default-features = false
features = ["inline-more"] features = ["inline-more"]
[dependencies.rkyv] [dependencies.rkyv]
version = "0.7.29" version = "0.7"
default-features = false default-features = false
features = ["size_64", "alloc"] features = ["size_64", "alloc"]
@ -103,15 +95,11 @@ 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"
@ -128,10 +116,6 @@ 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"

View file

@ -1,8 +1,7 @@
use hashbrown::HashMap; use hashbrown::HashMap;
lazy_static::lazy_static! { pub static ALIAS_TABLE: spin::Mutex<AliasTable> = spin::Mutex::new(AliasTable::new());
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

View file

@ -1,13 +1,12 @@
use lazy_static::lazy_static; use spin::{Lazy, Mutex};
use spin::Mutex;
use uart_16550::SerialPort; 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) }; 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;

View file

@ -23,7 +23,7 @@ pub enum Color {
#[repr(transparent)] #[repr(transparent)]
struct ColorCode(u8); struct ColorCode(u8);
impl ColorCode { 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)) ColorCode((background as u8) << 4 | (foreground as u8))
} }
} }
@ -114,17 +114,17 @@ impl fmt::Write for Writer {
Ok(()) 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, 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 core::fmt;
use lazy_static::lazy_static; use spin::{Lazy, Mutex};
use spin::Mutex;
use volatile::Volatile; 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::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! {
static ref TSS: TaskStateSegment = { 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;
@ -14,14 +14,9 @@ lazy_static! {
stack_start + STACK_SIZE stack_start + STACK_SIZE
}; };
tss tss
}; });
}
struct Selectors { static GDT: Lazy<(GlobalDescriptorTable, Selectors)> = Lazy::new(|| {
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));
@ -32,8 +27,13 @@ lazy_static! {
tss_selector, tss_selector,
}, },
) )
}; });
struct Selectors {
code_selector: SegmentSelector,
tss_selector: SegmentSelector,
} }
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;

View file

@ -6,9 +6,8 @@ use crate::{
}; };
use cpuio::outb; use cpuio::outb;
use lazy_static::lazy_static;
use pic8259::ChainedPics; use pic8259::ChainedPics;
use spin; use spin::Lazy;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; 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;
@ -35,12 +34,13 @@ impl InterruptIndex {
pub fn init_idt() { pub fn init_idt() {
IDT.load(); IDT.load();
} }
lazy_static! {
static ref IDT: InterruptDescriptorTable = { static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
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.set_handler_fn(double_fault_handler) idt.double_fault
.set_handler_fn(double_fault_handler)
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX); .set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
} }
@ -48,14 +48,12 @@ lazy_static! {
set_pit_frequency(1000); set_pit_frequency(1000);
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler); 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[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);
@ -84,14 +82,15 @@ 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 ref KEYBOARD: Mutex<Keyboard<CustomLayout, CustomScancodeSet>> = static KEYBOARD: Lazy<Mutex<Keyboard<CustomLayout, CustomScancodeSet>>> = Lazy::new(|| {
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() };

View file

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

View file

@ -177,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;
return true; true
} }
'\r' => { '\r' => {
self.cursor_position.0 = 0; self.cursor_position.0 = 0;
return true; true
} }
'\t' => { '\t' => {
self.cursor_position.0 += 4; self.cursor_position.0 += 4;
return true; 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 = ' ';
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' => { '\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];
return true; true
} }
_ => { _ => {
@ -213,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;
return true; true
} else { } else {
self.cursor_position.0 = 0; self.cursor_position.0 = 0;
self.cursor_position.1 += 1; self.cursor_position.1 += 1;
return true; true
} }
} }
} }
@ -239,8 +239,6 @@ impl CharacterDevice for VTerm {
} }
} }
lazy_static::lazy_static! { pub static VIRTUAL_TERMINAL_COUNT: AtomicU32 = AtomicU32::new(0);
pub static ref VIRTUAL_TERMINAL_COUNT: AtomicU32 = AtomicU32::new(0);
}
use core::sync::atomic::AtomicU32; use core::sync::atomic::AtomicU32;
use core::sync::atomic::Ordering; use core::sync::atomic::Ordering;

View file

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

View file

@ -16,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!()
} }

View file

@ -1,7 +1,7 @@
// 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" => {
@ -55,7 +55,7 @@ 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);
} }
} }
@ -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 => {

View file

@ -1,19 +1,14 @@
use alloc::{string::String, vec, vec::Vec}; use alloc::{string::String, vec, vec::Vec};
// use crate::String; // use crate::String;
// use crate::Vec; // 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 CLIPBOARD: spin::Mutex<Clipboard> = spin::Mutex::new(Clipboard::new());
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
@ -26,29 +21,34 @@ pub struct Clipboard {
pub pages: Vec<Mime>, pub pages: Vec<Mime>,
} }
impl Clipboard { impl Clipboard {
pub fn new() -> Clipboard { pub const 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 {
let paste_pos = &self.pages[self.index]; &self.pages[self.index] as _
paste_pos
} }
} }

View file

@ -445,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: bytes } BrandString { bytes }
} }
} }
@ -752,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
@ -767,9 +767,8 @@ 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 = let brand_string = when_supported(max_value, RequestType::BrandString3, BrandString::new);
when_supported(max_value, RequestType::BrandString3, || BrandString::new()); let cache_line = when_supported(max_value, RequestType::CacheLine, CacheLine::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()
}); });
@ -782,8 +781,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,
} }
@ -807,7 +806,7 @@ impl Master {
self.brand_string self.brand_string
.as_ref() .as_ref()
.map(|bs| bs as &str) .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, { delegate_flag!(version_information, {

View file

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

View file

@ -6,24 +6,23 @@ use ext2::{
sector::{SectorSize, Size1024}, sector::{SectorSize, Size1024},
volume::Volume, volume::Volume,
}; };
use spin::Lazy;
fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> { fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
let mut volume = Vec::new(); let mut volume = Vec::new();
volume.extend_from_slice(include_bytes!("../../../userland/root_fs/ext2.img")); volume.extend_from_slice(include_bytes!("../../../userland/root_fs/ext2.img"));
let fs = Synced::<Ext2<Size1024, _>>::new(volume).unwrap(); Synced::<Ext2<Size1024, _>>::new(volume).unwrap()
fs
} }
// use serde::__private::from_utf8_lossy; // use serde::__private::from_utf8_lossy;
pub fn walk<'vol, S: SectorSize, V: Volume<u8, S>>( pub fn walk<S: SectorSize, V: Volume<u8, S>>(
fs: &'vol Synced<Ext2<S, V>>, fs: &Synced<Ext2<S, V>>,
inode: Inode<S, V>, inode: Inode<S, V>,
name: String, name: String,
) { ) {
inode.directory().map(|dir| { if let Some(dir) = inode.directory() {
for entry in dir { for entry in dir {
assert!(entry.is_ok()); assert!(entry.is_ok());
let entry = entry.unwrap(); 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 ab_glyph::{Font, FontRef, Glyph};
use shadeable::{evaluate_shader, pixel_format::Rgba64}; use shadeable::{evaluate_shader, pixel_format::Rgba64};
use spin; use spin::Lazy;
// use vga::{colors::Color16, writers::GraphicsWriter}; // use vga::{colors::Color16, writers::GraphicsWriter};
#[derive(Debug)] #[derive(Debug)]
@ -15,10 +15,8 @@ const FONT_SCALE: f32 = 1.6;
const GLYPH_HEIGHT: f32 = 18.0; const GLYPH_HEIGHT: f32 = 18.0;
const GLYPH_WIDTH: f32 = 10.0; const GLYPH_WIDTH: f32 = 10.0;
lazy_static::lazy_static! { pub static SCREEN_BUFFER: Lazy<spin::Mutex<ScreenBuffer>> =
pub static ref SCREEN_BUFFER: spin::Mutex<ScreenBuffer> = spin::Mutex::new(ScreenBuffer::new(640, 480)); Lazy::new(|| 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 {
@ -46,6 +44,7 @@ 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 {

View file

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

View file

@ -5,19 +5,15 @@
// use crate::{scratchpad, SCHEDULER, SCREEN_BUFFER}; // use crate::{scratchpad, SCHEDULER, SCREEN_BUFFER};
use { use crate::{
crate::{
arch::{init, sloop}, arch::{init, sloop},
relib::network::socket::{SimpleSock, Socket}, relib::network::socket::{SimpleSock, Socket},
scratchpad, scratchpad,
},
lazy_static::lazy_static,
}; };
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]
@ -29,7 +25,7 @@ pub fn kernel_main() -> ! {
} else { } else {
log::set_max_level(log::LevelFilter::Off); log::set_max_level(log::LevelFilter::Off);
} }
let mut scheduler = SCHEDULER.lock(); let scheduler = SCHEDULER.lock();
for proc in &scheduler.execution_queue { for proc in &scheduler.execution_queue {
trace!("{:?}", proc); trace!("{:?}", proc);
} }
@ -63,6 +59,4 @@ use crate::info::master;
use kernel::KERNEL_VERSION; use kernel::KERNEL_VERSION;
use crate::scheduler::SCHEDULER; use crate::scheduler::SCHEDULER;
use crate::{ use crate::{boot_conf::KernelConfig, systeminfo::RELEASE_TYPE};
boot_conf::KernelConfig, scheduler::capabilities::FileAccess, systeminfo::RELEASE_TYPE,
};

View file

@ -1,10 +1,7 @@
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};
@ -18,17 +15,16 @@ impl log::Log for SimpleLogger {
} }
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();
match record.level() { let color = match record.level() {
log::Level::Error => color = (Fg::Red, "$RED$"), log::Level::Error => (Fg::Red, "$RED$"),
log::Level::Warn => color = (Fg::LightYellow, "$LIGHTYELLOW$"), log::Level::Warn => (Fg::LightYellow, "$LIGHTYELLOW$"),
log::Level::Info => color = (Fg::LightWhite, "$LIGHTGRAY$"), log::Level::Info => (Fg::LightWhite, "$LIGHTGRAY$"),
log::Level::Debug => color = (Fg::Blue, "$BLUE$"), log::Level::Debug => (Fg::Blue, "$BLUE$"),
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"), log::Level::Trace => (Fg::Yellow, "$YELLOW$"),
} };
let msg = format!( let msg = format!(
"[{}{}$RESET$][$GREEN${}$RESET$]{}\n", "[{}{}$RESET$][$GREEN${}$RESET$]{}\n",
color.1, color.1,

View file

@ -19,25 +19,22 @@ 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 subcommand in split_command { for (root_count, subcommand) in split_command.enumerate() {
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 = "";
let mut arg_count = 0; for (n, arg) in subarg.split('=').enumerate() {
for arg in subarg.split("=") { if n == 0 {
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(),
@ -48,7 +45,6 @@ impl Command {
} }
_ => {} _ => {}
} }
root_count += 1;
} }
Command { Command {

View file

@ -1,11 +1,9 @@
pub fn encode(bytes: &[u8]) -> Vec<u8> { pub fn encode(bytes: &[u8]) -> Vec<u8> {
let mut encoding; let mut encoding = if bytes.first().is_none() {
if bytes.first().is_none() {
return vec![]; return vec![];
} else { } else {
encoding = vec![*bytes.first().unwrap()]; vec![*bytes.first().unwrap()]
} };
let mut occurrences = 1; let mut occurrences = 1;

View file

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

View file

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

View file

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

View file

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

View file

@ -1,8 +1,5 @@
use { use {
crate::{ crate::devices::Device::{Character, Vterm},
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,
}; };

View file

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

View file

@ -104,6 +104,6 @@ impl WasmProgram {
if self.raw_bytes[4..8] == WASM_VERSION { if self.raw_bytes[4..8] == WASM_VERSION {
byte_version_valid = true; 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::{ use wasmi::{
Error, Externals, FuncInstance, FuncRef, ModuleImportResolver, RuntimeArgs, RuntimeValue, Error, Externals, FuncInstance, FuncRef, ModuleImportResolver, RuntimeArgs, RuntimeValue,
Signature, Trap, ValueType, Signature, Trap, ValueType,
@ -113,7 +111,7 @@ impl HostExternals {
return false; return false;
} }
} }
return true; true
} }
SEND_SIGNAL_INDEX => { SEND_SIGNAL_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) = let (params, ret_ty): (&[ValueType], Option<ValueType>) =
@ -129,7 +127,7 @@ impl HostExternals {
return false; return false;
} }
} }
return true; true
} }
GET_TIME_INDEX => { GET_TIME_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) = let (params, ret_ty): (&[ValueType], Option<ValueType>) =
@ -145,7 +143,7 @@ impl HostExternals {
return false; return false;
} }
} }
return true; true
} }
GET_RANDOM_INDEX => { GET_RANDOM_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) = let (params, ret_ty): (&[ValueType], Option<ValueType>) =
@ -161,7 +159,7 @@ impl HostExternals {
return false; return false;
} }
} }
return true; true
} }
GET_INPUT_INDEX => { GET_INPUT_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) = let (params, ret_ty): (&[ValueType], Option<ValueType>) =
@ -177,7 +175,7 @@ impl HostExternals {
return false; return false;
} }
} }
return true; true
} }
PRINT_CLEVER_HACK => { PRINT_CLEVER_HACK => {
@ -193,7 +191,7 @@ impl HostExternals {
return false; return false;
} }
} }
return true; true
} }
_ => false, _ => false,
} }
@ -228,4 +226,3 @@ impl ModuleImportResolver for HostExternals {
Ok(FuncInstance::alloc_host(signature.clone(), index)) 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 { match instance {
Ok(inst) => { Ok(inst) => {
let mut instance = inst.assert_no_start(); let instance = inst.assert_no_start();
let mut is_driver = false; let mut is_driver = false;
let mut is_program = false; let _is_program = false;
let mut has_driver_entry = false; let mut has_driver_entry = false;
let mut has_driver_exit = false; let mut has_driver_exit = false;
let mut has_start = 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; 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; has_driver_exit = true;
} }
match instance.export_by_name("start") { match instance.export_by_name("start") {
Some(val) => { Some(_val) => {
trace!("Program start function found"); trace!("Program start function found");
has_start = true; has_start = true;
} }

View file

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

View file

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

View file

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

View file

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