forked from AbleOS/ableos
scheduler work and commit
This commit is contained in:
parent
6010397f4a
commit
95998acb99
|
@ -52,32 +52,24 @@ version = "*"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["alloc"]
|
features = ["alloc"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies.rkyv]
|
[dependencies.rkyv]
|
||||||
version = "0.7.29"
|
version = "0.7.29"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["size_64", "alloc"]
|
features = ["size_64", "alloc"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies.smoltcp]
|
[dependencies.smoltcp]
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["log", "proto-ipv4"]
|
features = ["log", "proto-ipv4"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies.y-compositor-protocol]
|
[dependencies.y-compositor-protocol]
|
||||||
git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git"
|
git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies.shadeable]
|
[dependencies.shadeable]
|
||||||
path = "../shadeable"
|
path = "../shadeable"
|
||||||
|
|
||||||
[dependencies.ab_glyph]
|
[dependencies.ab_glyph]
|
||||||
|
version = "*"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["libm"]
|
features = ["libm"]
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"logging_level": "Trace",
|
"logging_level": "Trace",
|
||||||
|
"logger_padding": 10,
|
||||||
"run_tests": false,
|
"run_tests": false,
|
||||||
"run_demos": false,
|
"run_demos": false,
|
||||||
"run_shader_tests": true
|
"run_shader_tests": false
|
||||||
}
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
pub mod allocator;
|
pub mod allocator;
|
||||||
pub mod graphics;
|
pub mod graphics;
|
||||||
pub mod serial;
|
pub mod serial;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
2
ableos/src/arch/x86_64/drivers/timer.rs
Normal file
2
ableos/src/arch/x86_64/drivers/timer.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/// This magic value is the herts of the timer interupts normalized
|
||||||
|
pub const TIMER_INTERRUPT_HERTZ: f64 = 1193182.0;
|
|
@ -93,16 +93,12 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
|
||||||
// print!(" ");
|
// print!(" ");
|
||||||
// WRITER.lock().backspace();
|
// WRITER.lock().backspace();
|
||||||
}
|
}
|
||||||
0x12 => {
|
|
||||||
KERNEL_STATE.lock().shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enter
|
// Enter
|
||||||
0x0A => {
|
0x0A => {
|
||||||
let _xyz = crate::kmain::KEY_BUFFER.lock();
|
// let _xyz = crate::kmain::KEY_BUFFER.lock();
|
||||||
|
|
||||||
// println!("{:?}", clparse::Command::parse(xyz.to_string()));
|
// print!("{}", char::try_from(character).unwrap());
|
||||||
print!("{}", char::try_from(character).unwrap());
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
print!("{}", char::try_from(character).unwrap());
|
print!("{}", char::try_from(character).unwrap());
|
||||||
|
@ -123,11 +119,8 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
|
||||||
value: key,
|
value: key,
|
||||||
} => match KeyCode::from(key) {
|
} => match KeyCode::from(key) {
|
||||||
KeyCode::AltLeft => {}
|
KeyCode::AltLeft => {}
|
||||||
|
// KeyCode::Escape => {}
|
||||||
KeyCode::AltRight => {
|
KeyCode::AltRight => {}
|
||||||
let xyz = crate::kmain::KEY_BUFFER.lock();
|
|
||||||
println!("{:?}", &xyz);
|
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
print!("{:?}", KeyCode::from(key))
|
print!("{:?}", KeyCode::from(key))
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub enum LogLevel {
|
||||||
#[derive(Serialize, Debug, Deserialize)]
|
#[derive(Serialize, Debug, Deserialize)]
|
||||||
pub struct BootConfig {
|
pub struct BootConfig {
|
||||||
pub logging_level: LogLevel,
|
pub logging_level: LogLevel,
|
||||||
|
pub logger_padding: usize,
|
||||||
pub run_tests: bool,
|
pub run_tests: bool,
|
||||||
pub run_demos: bool,
|
pub run_demos: bool,
|
||||||
pub run_shader_tests: bool,
|
pub run_shader_tests: bool,
|
||||||
|
@ -34,7 +34,7 @@ impl BootConfig {
|
||||||
// same function as the one that produced serde_json::Value above, but
|
// same function as the one that produced serde_json::Value above, but
|
||||||
// now we are asking it for a Person as output.
|
// now we are asking it for a Person as output.
|
||||||
let p: BootConfig = serde_json::from_str(data).unwrap();
|
let p: BootConfig = serde_json::from_str(data).unwrap();
|
||||||
info!("{:?}", p);
|
// info!("{:?}", p);
|
||||||
p
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,6 @@ use core::time::Duration;
|
||||||
|
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
use crate::scheduler::ThreadID;
|
|
||||||
|
|
||||||
// pub struct Duration {}
|
// pub struct Duration {}
|
||||||
|
|
||||||
pub struct AtomicU32(u32);
|
pub struct AtomicU32(u32);
|
||||||
|
@ -53,7 +51,7 @@ pub fn futex_wake(atom: &AtomicU32, threads_to_wake: usize) {
|
||||||
|
|
||||||
struct FutexWaitlist {
|
struct FutexWaitlist {
|
||||||
address: u8,
|
address: u8,
|
||||||
data: Vec<ThreadID>,
|
// data: Vec<ThreadID>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FutexWaitlist {
|
impl FutexWaitlist {
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
// Deprecated
|
|
||||||
|
|
||||||
pub type Priority = [Process; 512];
|
|
||||||
|
|
||||||
pub struct VirtualMemoryTable {}
|
|
||||||
|
|
||||||
struct Process {
|
|
||||||
id: u64,
|
|
||||||
mem_table: *mut VirtualMemoryTable, // Pointer to a memory table
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Scheduler {
|
|
||||||
pub high_priority: Priority, //150
|
|
||||||
pub medium_priority: Priority, //100
|
|
||||||
pub low_priority: Priority, // 50
|
|
||||||
pub next_pid: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Scheduler {
|
|
||||||
pub fn bump_up() {}
|
|
||||||
pub fn bump_down() {}
|
|
||||||
pub fn schedule(&mut self) {
|
|
||||||
let current_pid = self.next_pid;
|
|
||||||
self.next_pid += 1;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -100,8 +100,6 @@ pub fn kernel_main() -> ! {
|
||||||
let ret = WasmProgram::new_from_bytes(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
|
let ret = WasmProgram::new_from_bytes(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
|
||||||
trace!("Binary Valid: {:?}", ret.validate_header());
|
trace!("Binary Valid: {:?}", ret.validate_header());
|
||||||
|
|
||||||
// add a plus b
|
|
||||||
|
|
||||||
if BOOT_CONF.run_tests {
|
if BOOT_CONF.run_tests {
|
||||||
// quick and dirty testing framework
|
// quick and dirty testing framework
|
||||||
screen_writer_test();
|
screen_writer_test();
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![feature(
|
#![feature(
|
||||||
abi_x86_interrupt,
|
abi_x86_interrupt,
|
||||||
asm,
|
// asm,
|
||||||
asm_sym,
|
asm_sym,
|
||||||
alloc_error_handler,
|
alloc_error_handler,
|
||||||
core_intrinsics,
|
core_intrinsics,
|
||||||
global_asm,
|
// global_asm,
|
||||||
lang_items,
|
lang_items,
|
||||||
llvm_asm,
|
llvm_asm,
|
||||||
naked_functions
|
naked_functions
|
||||||
|
@ -41,11 +41,11 @@ pub mod keyboard;
|
||||||
pub mod kmain;
|
pub mod kmain;
|
||||||
pub mod logger;
|
pub mod logger;
|
||||||
pub mod panic;
|
pub mod panic;
|
||||||
pub mod proc;
|
|
||||||
pub mod relib;
|
pub mod relib;
|
||||||
pub mod scheduler;
|
pub mod scheduler;
|
||||||
mod unicode_utils;
|
mod unicode_utils;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
pub mod wasm;
|
||||||
|
|
||||||
pub extern crate alloc;
|
pub extern crate alloc;
|
||||||
pub extern crate externc_libm as libm;
|
pub extern crate externc_libm as libm;
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
|
use core::sync::atomic::Ordering;
|
||||||
|
|
||||||
|
use crate::kmain::{BOOT_CONF, TICK};
|
||||||
use crate::serial_println;
|
use crate::serial_println;
|
||||||
use lliw::{Fg, Reset};
|
use lliw::{Fg, Reset};
|
||||||
pub use log::{debug, info, trace, warn};
|
pub use log::{debug, info, trace, warn};
|
||||||
use log::{Level, Metadata, Record};
|
use log::{Level, Metadata, Record};
|
||||||
|
|
||||||
|
use crate::arch::drivers::timer::TIMER_INTERRUPT_HERTZ;
|
||||||
|
|
||||||
struct SimpleLogger;
|
struct SimpleLogger;
|
||||||
|
|
||||||
impl log::Log for SimpleLogger {
|
impl log::Log for SimpleLogger {
|
||||||
|
@ -12,7 +17,10 @@ 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; // = (Fg::Reset, "$GREEN$");
|
let color;
|
||||||
|
let time = TICK.load(Ordering::Relaxed) as f64;
|
||||||
|
|
||||||
|
let time_float = time / TIMER_INTERRUPT_HERTZ;
|
||||||
|
|
||||||
match record.level() {
|
match record.level() {
|
||||||
log::Level::Error => color = (Fg::Red, "$RED$"),
|
log::Level::Error => color = (Fg::Red, "$RED$"),
|
||||||
|
@ -21,22 +29,16 @@ impl log::Log for SimpleLogger {
|
||||||
log::Level::Debug => color = (Fg::Blue, "$BLUE$"),
|
log::Level::Debug => color = (Fg::Blue, "$BLUE$"),
|
||||||
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"),
|
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"),
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
println!(
|
|
||||||
"[{}{}$RESET$][$GREEN$FakeTempTime$RESET$] {}",
|
|
||||||
color.1,
|
|
||||||
record.level(),
|
|
||||||
record.args()
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
serial_println!(
|
serial_println!(
|
||||||
"[{}{}{}][{}FakeTempTime{}] {}",
|
"[{}{}{}][{}{}{}] {}",
|
||||||
color.0,
|
color.0,
|
||||||
record.level(),
|
record.level(),
|
||||||
Fg::Reset,
|
Fg::Reset,
|
||||||
Fg::Green,
|
Fg::Green,
|
||||||
|
time_float,
|
||||||
Reset,
|
Reset,
|
||||||
record.args()
|
record.args(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
use crate::relib::clparse::Command;
|
|
||||||
|
|
||||||
pub struct ProccessStart {
|
|
||||||
command: Command,
|
|
||||||
}
|
|
|
@ -10,13 +10,13 @@ clparse
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// use std::collections::HashMap;
|
// use std::collections::HashMap;
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Argument {
|
pub struct Argument {
|
||||||
key: String,
|
key: String,
|
||||||
value: String,
|
value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Command {
|
pub struct Command {
|
||||||
pub root_command: String,
|
pub root_command: String,
|
||||||
// arguments: HashMap<String, String>,
|
// arguments: HashMap<String, String>,
|
||||||
|
|
|
@ -1,85 +0,0 @@
|
||||||
use {
|
|
||||||
crate::kmain::THREAD_LIST,
|
|
||||||
alloc::{vec, vec::Vec},
|
|
||||||
core::cmp::Ordering,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub type Pointer = fn();
|
|
||||||
pub type ThreadID = u64;
|
|
||||||
pub type TaskID = u64;
|
|
||||||
pub type ThreadList = Vec<Thread>;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Eq, Debug)]
|
|
||||||
pub struct Task {
|
|
||||||
id: TaskID,
|
|
||||||
parent_thread: ThreadID,
|
|
||||||
fn_pointer: Pointer,
|
|
||||||
}
|
|
||||||
impl Task {
|
|
||||||
fn new(parent_thread: ThreadID, task_id: u64, function_pointer: fn()) -> Self {
|
|
||||||
debug!(
|
|
||||||
"New task with TaskID: {} | Parent ThreadID: {}",
|
|
||||||
task_id, parent_thread
|
|
||||||
);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
id: task_id,
|
|
||||||
parent_thread,
|
|
||||||
fn_pointer: function_pointer,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Ord for Task {
|
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
|
||||||
self.id.cmp(&other.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialOrd for Task {
|
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
||||||
Some(self.cmp(other))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialEq for Task {
|
|
||||||
fn eq(&self, other: &Self) -> bool {
|
|
||||||
self.id == other.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Thread {
|
|
||||||
pub id: ThreadID,
|
|
||||||
pub tasks: Vec<Task>,
|
|
||||||
}
|
|
||||||
impl Thread {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
let threads = &*THREAD_LIST.lock();
|
|
||||||
let mut final_threadid = 0;
|
|
||||||
match threads.last() {
|
|
||||||
Some(last_thread) => final_threadid = last_thread.id + 1,
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
debug!("New thread with ThreadID: {}", final_threadid);
|
|
||||||
Self {
|
|
||||||
id: final_threadid,
|
|
||||||
tasks: vec![],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn sort_tasks(&mut self) {
|
|
||||||
self.tasks.sort();
|
|
||||||
}
|
|
||||||
pub fn new_task_id(&self) -> TaskID {
|
|
||||||
let task_id = self.tasks.len().try_into().unwrap();
|
|
||||||
trace!("New TaskID: {}", task_id);
|
|
||||||
task_id
|
|
||||||
}
|
|
||||||
pub fn new_task(&mut self, function_pointer: fn()) {
|
|
||||||
let x = Task::new(self.id, self.new_task_id(), function_pointer);
|
|
||||||
self.tasks.push(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn test_fn() {
|
|
||||||
println!("Hello");
|
|
||||||
}
|
|
64
ableos/src/scheduler/capabilities.rs
Normal file
64
ableos/src/scheduler/capabilities.rs
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
/// Placeholder to be replaced with a proper FileReference when such a thing exists
|
||||||
|
pub type FileID = u8;
|
||||||
|
pub type SoundCardID = u8;
|
||||||
|
pub type DeviceID = u8;
|
||||||
|
pub type ControllerID = u8;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum FileAccess {
|
||||||
|
All,
|
||||||
|
Some(Vec<FileID>),
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum ControllerAccess {
|
||||||
|
All,
|
||||||
|
Some(Vec<ControllerID>),
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum SoundCardAccess {
|
||||||
|
All,
|
||||||
|
Some(Vec<SoundCardID>),
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum MouseAccess {
|
||||||
|
Yes,
|
||||||
|
No,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum KeyboardAccess {
|
||||||
|
Yes,
|
||||||
|
No,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Capabilities {
|
||||||
|
files: FileAccess,
|
||||||
|
mouse: MouseAccess,
|
||||||
|
keyboard: KeyboardAccess,
|
||||||
|
controllers: ControllerAccess,
|
||||||
|
sound_cards: SoundCardAccess,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Capabilities {
|
||||||
|
/// Generate a set of empty capabilities
|
||||||
|
pub fn empty() -> Self {
|
||||||
|
Self {
|
||||||
|
files: FileAccess::None,
|
||||||
|
mouse: MouseAccess::No,
|
||||||
|
keyboard: KeyboardAccess::No,
|
||||||
|
controllers: ControllerAccess::None,
|
||||||
|
sound_cards: SoundCardAccess::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
110
ableos/src/scheduler/mod.rs
Normal file
110
ableos/src/scheduler/mod.rs
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
use alloc::{vec, vec::Vec};
|
||||||
|
|
||||||
|
pub mod capabilities;
|
||||||
|
pub mod proc;
|
||||||
|
use proc::{Process, ProcessPermissions, PID};
|
||||||
|
|
||||||
|
use self::capabilities::Capabilities;
|
||||||
|
|
||||||
|
lazy_static::lazy_static!(
|
||||||
|
|
||||||
|
/// The standard implementation for ableOS
|
||||||
|
pub static ref SCHEDULER: spin::Mutex<Scheduler> = spin::Mutex::new(Scheduler::new());
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
// pub struct VirtualMemoryTable {}
|
||||||
|
|
||||||
|
/// Scheduler priority model
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub enum Priority {
|
||||||
|
/// Exclusively Kernel space | 20 Timer Tick execution time
|
||||||
|
High,
|
||||||
|
/// Kernel / User space | 15 Timer Tick execution time
|
||||||
|
Medium,
|
||||||
|
/// low priority userspace code | 10 Timer Tick execution time
|
||||||
|
Low,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Placeholder
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct FileID(u8);
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum FileAccessTypes {
|
||||||
|
All,
|
||||||
|
Some(Vec<FileID>),
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Scheduler {
|
||||||
|
pub free_pid: PID,
|
||||||
|
|
||||||
|
pub process_exec_time: u64,
|
||||||
|
pub list: Vec<Process>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Scheduler {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
list: vec![],
|
||||||
|
process_exec_time: 0,
|
||||||
|
free_pid: PID(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next_process(&mut self) {
|
||||||
|
self.process_exec_time = 0;
|
||||||
|
let previous_task = self.list[0].clone();
|
||||||
|
self.list.remove(0);
|
||||||
|
self.list.push(previous_task);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a
|
||||||
|
pub fn new_process(&mut self, priority: Priority) {
|
||||||
|
// let new_pid = self.free_pid;
|
||||||
|
|
||||||
|
let process = Process {
|
||||||
|
id: self.free_pid.clone(),
|
||||||
|
capabilities: Capabilities::empty(),
|
||||||
|
priority,
|
||||||
|
};
|
||||||
|
self.free_pid.0 += 1;
|
||||||
|
self.list.push(process);
|
||||||
|
}
|
||||||
|
/// Terminate the process with the matching PID
|
||||||
|
pub fn term_process(&mut self, pid: PID) {
|
||||||
|
let mut process_index = 0;
|
||||||
|
for x in &self.list {
|
||||||
|
if x.id == pid {
|
||||||
|
self.list.remove(process_index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
process_index += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bump_exec(&mut self) {
|
||||||
|
self.process_exec_time += 1;
|
||||||
|
use Priority::*;
|
||||||
|
|
||||||
|
if self.list.len() > 0 {
|
||||||
|
match (self.process_exec_time, self.list[0].priority) {
|
||||||
|
(20, High) => {
|
||||||
|
self.next_process();
|
||||||
|
}
|
||||||
|
(15, Medium) => {
|
||||||
|
self.next_process();
|
||||||
|
}
|
||||||
|
(10, Low) => {
|
||||||
|
self.next_process();
|
||||||
|
}
|
||||||
|
|
||||||
|
(_, _) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
ableos/src/scheduler/proc.rs
Normal file
27
ableos/src/scheduler/proc.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
//! Process definition and general utilities surrounding them
|
||||||
|
|
||||||
|
use super::{capabilities::Capabilities, FileAccessTypes, Priority};
|
||||||
|
|
||||||
|
/// Process Identification
|
||||||
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
|
|
||||||
|
pub struct PID(pub usize);
|
||||||
|
|
||||||
|
/// Temporary till integration of capabilities
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct ProcessPermissions {
|
||||||
|
pub file_access: FileAccessTypes,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A process
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Process {
|
||||||
|
/// Internal PID
|
||||||
|
pub id: PID,
|
||||||
|
///
|
||||||
|
pub capabilities: Capabilities,
|
||||||
|
/// A process's priority
|
||||||
|
pub priority: Priority,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Process {}
|
|
@ -32,7 +32,7 @@ pub fn draw_char(previous_character: Option<char>, character: char, _offset: usi
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let font2 = FontRef::try_from_slice(include_bytes!(
|
let font2 = FontRef::try_from_slice(include_bytes!(
|
||||||
"../../ableos/assets/fonts/unifont_upper-14.0.01.ttf" // "../../ableos/assets/fonts/OpenSansEmoji.ttf"
|
"../../ableos/assets/fonts/unifont_upper-14.0.01.ttf"
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
50
ableos/src/wasm/mod.rs
Normal file
50
ableos/src/wasm/mod.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
/// `NULL a s m` as an array of 4 bytes
|
||||||
|
pub const WASM_BINARY_MAGIC: [u8; 4] = [0x00, 0x61, 0x73, 0x6d];
|
||||||
|
/// `1 0 0 0` as an array of 4 bytes
|
||||||
|
pub const WASM_VERSION: [u8; 4] = [0x01, 0x00, 0x00, 0x00];
|
||||||
|
|
||||||
|
/// Validate a wasm header (8 bytes)
|
||||||
|
|
||||||
|
pub enum SectionType {
|
||||||
|
None = 0,
|
||||||
|
Type = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Section {
|
||||||
|
stype: SectionType,
|
||||||
|
section_size: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WasmProgram {
|
||||||
|
raw_bytes: Vec<u8>,
|
||||||
|
// version:
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WasmProgram {
|
||||||
|
pub fn new_from_bytes(bytes: &[u8]) -> Self {
|
||||||
|
Self {
|
||||||
|
raw_bytes: bytes.to_vec(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn validate_header(self) -> (bool, bool) {
|
||||||
|
let mut byte_magic_valid = false;
|
||||||
|
let mut byte_version_valid = false;
|
||||||
|
|
||||||
|
if self.raw_bytes[0..4] == WASM_BINARY_MAGIC {
|
||||||
|
byte_magic_valid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.raw_bytes[4..8] == WASM_VERSION {
|
||||||
|
byte_version_valid = true;
|
||||||
|
}
|
||||||
|
return (byte_magic_valid, byte_version_valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue