Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions src/sys/ata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use bit_field::BitField;
use core::convert::TryInto;
use core::fmt;
use core::hint::spin_loop;
use lazy_static::lazy_static;
use spin::Mutex;

// Information Technology
Expand Down Expand Up @@ -308,9 +307,7 @@ impl Bus {
}
}

lazy_static! {
pub static ref BUSES: Mutex<Vec<Bus>> = Mutex::new(Vec::new());
}
pub static BUSES: Mutex<Vec<Bus>> = Mutex::new(Vec::new());

pub fn init() {
{
Expand Down
8 changes: 4 additions & 4 deletions src/sys/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use crate::sys::x86::reg;
use crate::sys::x86::seg::SegmentSelector;

use bit_field::BitField;
use lazy_static::lazy_static;
use spin::LazyLock;

lazy_static! {
static ref GDT: GlobalDescriptorTable = GlobalDescriptorTable::new(&tss::TSS);
}
static GDT: LazyLock<GlobalDescriptorTable> = LazyLock::new(||
GlobalDescriptorTable::new(&tss::TSS)
);

pub const SYS_CODE: SegmentSelector = SegmentSelector::new(1, 0);
pub const SYS_DATA: SegmentSelector = SegmentSelector::new(2, 0);
Expand Down
17 changes: 7 additions & 10 deletions src/sys/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use crate::sys::x86;

use bit_field::BitField;
use core::arch::asm;
use lazy_static::lazy_static;
use spin::Mutex;
use spin::{LazyLock, Mutex};

const LEN: usize = 256;

Expand Down Expand Up @@ -137,15 +136,13 @@ impl Entry {

fn default_handler() {}

lazy_static! {
static ref IRQ_HANDLERS: Mutex<[fn(); 16]> = {
Mutex::new([default_handler; 16])
};
static IRQ_HANDLERS: Mutex<[fn(); 16]> = {
Mutex::new([default_handler; 16])
};

static ref IDT: InterruptDescriptorTable = {
InterruptDescriptorTable::new()
};
}
static IDT: LazyLock<InterruptDescriptorTable> = LazyLock::new(||
InterruptDescriptorTable::new()
);

macro_rules! irq_handler {
($handler:ident, $irq:expr) => {
Expand Down
5 changes: 1 addition & 4 deletions src/sys/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ use alloc::collections::vec_deque::VecDeque;
use alloc::format;
use alloc::string::String;
use core::sync::atomic::{AtomicBool, Ordering};
use lazy_static::lazy_static;
use pc_keyboard::{
layouts, DecodedKey, Error, HandleControl, KeyCode, KeyEvent, KeyState,
Keyboard, ScancodeSet1,
};
use spin::Mutex;

lazy_static! {
pub static ref BUF: Mutex<VecDeque<u8>> = Mutex::new(VecDeque::new());
}
pub static BUF: Mutex<VecDeque<u8>> = Mutex::new(VecDeque::new());

pub static KEYBOARD: Mutex<Option<KeyboardDecoder>> = Mutex::new(None);

Expand Down
5 changes: 1 addition & 4 deletions src/sys/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ use crate::sys::x86::int;
use alloc::string::String;
use core::fmt;
use core::fmt::Write;
use lazy_static::lazy_static;
use spin::Mutex;

lazy_static! {
static ref LOG: Mutex<LogBuffer> = Mutex::new(LogBuffer::new());
}
static LOG: Mutex<LogBuffer> = Mutex::new(LogBuffer::new());

const LOG_SIZE: usize = 10 << 10; // 10 KB

Expand Down
11 changes: 4 additions & 7 deletions src/sys/net/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ pub mod tcp;
pub mod udp;

use alloc::vec;
use lazy_static::lazy_static;
use smoltcp::iface::SocketSet;
use smoltcp::time::Duration;
use spin::Mutex;
use spin::{LazyLock, Mutex};

lazy_static! {
pub static ref SOCKETS: Mutex<SocketSet<'static>> = {
Mutex::new(SocketSet::new(vec![]))
};
}
pub static SOCKETS: LazyLock<Mutex<SocketSet<'static>>> = LazyLock::new(||
Mutex::new(SocketSet::new(vec![]))
);

fn random_port() -> u16 {
49152 + sys::rng::get_u16() % 16384
Expand Down
5 changes: 1 addition & 4 deletions src/sys/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::sys::x86::port::*;
use alloc::vec;
use alloc::vec::Vec;
use bit_field::BitField;
use lazy_static::lazy_static;
use spin::Mutex;

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -133,9 +132,7 @@ impl DeviceConfig {
}
}

lazy_static! {
pub static ref PCI_DEVICES: Mutex<Vec<DeviceConfig>> = Mutex::new(vec![]);
}
pub static PCI_DEVICES: Mutex<Vec<DeviceConfig>> = Mutex::new(vec![]);

pub fn find_device(vendor_id: u16, device_id: u16) -> Option<DeviceConfig> {
for &device in PCI_DEVICES.lock().iter() {
Expand Down
9 changes: 3 additions & 6 deletions src/sys/process/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ use alloc::collections::btree_map::BTreeMap;
use alloc::string::String;
use core::alloc::{GlobalAlloc, Layout};
use core::sync::atomic::{AtomicUsize, Ordering};
use lazy_static::lazy_static;
use spin::RwLock;

pub const MAX_PROCS: usize = 32;
static PID: AtomicUsize = AtomicUsize::new(0);

type ProcessTable = [Option<Box<Process>>; MAX_PROCS];

lazy_static! {
pub static ref PROCESS_TABLE: RwLock<ProcessTable> = {
RwLock::new([(); MAX_PROCS].map(|_| None))
};
}
pub static PROCESS_TABLE: RwLock<ProcessTable> = RwLock::new(
[const { None }; MAX_PROCS]
);

pub fn init() {
let mut table = PROCESS_TABLE.write();
Expand Down
11 changes: 4 additions & 7 deletions src/sys/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ use crate::sys;

use crate::sys::fs::{FileIO, IO};

use lazy_static::lazy_static;
use rand::{RngCore, SeedableRng};
use rand_hc::Hc128Rng;
use sha2::{Digest, Sha256};
use spin::Mutex;
use spin::{Once, Mutex};

lazy_static! {
static ref RNG: Mutex<Hc128Rng> = Mutex::new(Hc128Rng::from_seed([0; 32]));
}
static RNG: Once<Mutex<Hc128Rng>> = Once::new();

#[derive(Debug, Clone)]
pub struct Random;
Expand Down Expand Up @@ -47,7 +44,7 @@ impl FileIO for Random {
}

pub fn get_u64() -> u64 {
RNG.lock().next_u64()
RNG.get().expect("RNG not initialized").lock().next_u64()
}

pub fn get_u32() -> u32 {
Expand Down Expand Up @@ -87,5 +84,5 @@ pub fn init() {
seed = hasher.finalize().into();
}

*RNG.lock() = Hc128Rng::from_seed(seed);
RNG.call_once(|| Mutex::new(Hc128Rng::from_seed(seed)));
}
11 changes: 4 additions & 7 deletions src/sys/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ use crate::sys::x86::int;

use core::fmt;
use core::fmt::Write;
use lazy_static::lazy_static;
use spin::Mutex;
use spin::{LazyLock, Mutex};
use uart_16550::SerialPort;
use vte::{Params, Parser, Perform};

lazy_static! {
pub static ref SERIAL: Mutex<Serial> = Mutex::new(Serial::new(0x3F8));
pub static ref PARSER: Mutex<Parser> = Mutex::new(Parser::new());
}
pub static SERIAL: Mutex<Serial> = Mutex::new(Serial::new(0x3F8));
pub static PARSER: LazyLock<Mutex<Parser>> = LazyLock::new(|| Mutex::new(Parser::new()));

pub struct Serial {
port: SerialPort,
}

impl Serial {
fn new(addr: u16) -> Self {
const fn new(addr: u16) -> Self {
Self {
port: unsafe { SerialPort::new(addr) }
}
Expand Down
66 changes: 32 additions & 34 deletions src/sys/tss.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
use crate::STACK_SIZE;

use core::ptr::addr_of;
use lazy_static::lazy_static;
use spin::LazyLock;

pub const DF: usize = 0; // Double fault
pub const PF: usize = 1; // Page fault
pub const GP: usize = 2; // General protection

lazy_static! {
pub static ref TSS: TaskStateSegment = {
let mut tss = TaskStateSegment::new();
pub static TSS: LazyLock<TaskStateSegment> = LazyLock::new(|| {
let mut tss = TaskStateSegment::new();

let addr = {
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
STACK_SIZE + addr_of!(STACK) as usize
};
tss.set_kernel_stack(addr);

#[cfg(target_arch = "x86")]
{
tss.stack[0].ss = crate::sys::gdt::SYS_DATA.bits;
}

#[cfg(target_arch = "x86_64")]
{
let addr = {
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
STACK_SIZE + addr_of!(STACK) as usize
};
tss.set_kernel_stack(addr);

#[cfg(target_arch = "x86")]
{
tss.stack[0].ss = crate::sys::gdt::SYS_DATA.bits;
}

#[cfg(target_arch = "x86_64")]
{
let addr = {
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
STACK_SIZE + addr_of!(STACK) as usize
};
tss.set_interrupt_stack(DF, addr);

let addr = {
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
STACK_SIZE + addr_of!(STACK) as usize
};
tss.set_interrupt_stack(PF, addr);

let addr = {
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
STACK_SIZE + addr_of!(STACK) as usize
};
tss.set_interrupt_stack(GP, addr);
}
tss
};
}
tss.set_interrupt_stack(DF, addr);

let addr = {
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
STACK_SIZE + addr_of!(STACK) as usize
};
tss.set_interrupt_stack(PF, addr);

let addr = {
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
STACK_SIZE + addr_of!(STACK) as usize
};
tss.set_interrupt_stack(GP, addr);
}
tss
});

#[cfg(target_arch = "x86")]
#[repr(C)]
Expand Down
16 changes: 9 additions & 7 deletions src/sys/vga/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use crate::api::font::Font;

use crate::sys;

use lazy_static::lazy_static;
use spin::Mutex;
use spin::{LazyLock, Mutex};
use vte::{Params, Parser, Perform};

const FG: Color = Color::DarkWhite;
Expand Down Expand Up @@ -64,18 +63,21 @@ struct ScreenBuffer {
static mut SCROLL_BUFFER: [[ScreenChar; SCREEN_WIDTH]; SCROLL_HEIGHT] =
[[ScreenChar::zeroed(); SCREEN_WIDTH]; SCROLL_HEIGHT];

lazy_static! {
pub static ref PARSER: Mutex<Parser> = Mutex::new(Parser::new());
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
pub static PARSER: LazyLock<Mutex<Parser>> = LazyLock::new(||
Mutex::new(Parser::new())
);

pub static WRITER: LazyLock<Mutex<Writer>> = LazyLock::new(||
Mutex::new(Writer {
cursor: [0; 2],
writer: [0; 2],
color_code: ColorCode::new(FG, BG),
screen_buffer: unsafe { &mut *(0xB8000 as *mut ScreenBuffer) },
scroll_buffer: unsafe { &mut *core::ptr::addr_of_mut!(SCROLL_BUFFER) },
scroll_reader: 0,
scroll_bottom: SCREEN_HEIGHT,
});
}
})
);

pub struct Writer {
cursor: [usize; 2], // x, y
Expand Down
5 changes: 1 addition & 4 deletions src/usr/chess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ use alloc::string::{String,ToString};
use alloc::sync::Arc;
use alloc::vec::Vec;

use lazy_static::lazy_static;
use littlewing::chess::*;
use littlewing::color::*;
use spin::Mutex;

lazy_static! {
static ref MOVES: Mutex<Vec<String>> = Mutex::new(Vec::new());
}
static MOVES: Mutex<Vec<String>> = Mutex::new(Vec::new());

const FEN: &str = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
const COMMANDS: [&str; 11] = [
Expand Down
5 changes: 1 addition & 4 deletions src/usr/lisp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use core::cell::RefCell;
use core::cmp;
use core::convert::TryInto;
use core::fmt;
use lazy_static::lazy_static;
use spin::Mutex;

// MOROS Lisp is a lisp-1 like Scheme and Clojure
Expand Down Expand Up @@ -151,9 +150,7 @@ pub enum Err {
Reason(String),
}

lazy_static! {
pub static ref FUNCTIONS: Mutex<Vec<String>> = Mutex::new(Vec::new());
}
pub static FUNCTIONS: Mutex<Vec<String>> = Mutex::new(Vec::new());

#[macro_export]
macro_rules! ensure_length_eq {
Expand Down
Loading