forked from koniifer/ableos
Change
This commit is contained in:
parent
530a8a9d60
commit
ec7a80c93a
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -1,3 +1,4 @@
|
|||
{
|
||||
"rust-analyzer.checkOnSave.allTargets": false
|
||||
"rust-analyzer.checkOnSave.allTargets": false,
|
||||
"rust-analyzer.showUnlinkedFileNotification": false
|
||||
}
|
|
@ -41,6 +41,10 @@ static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
|
|||
.set_stack_index(super::gdt::DOUBLE_FAULT_IX);
|
||||
}
|
||||
idt.page_fault.set_handler_fn(page_fault);
|
||||
|
||||
idt[Interrupt::ApicErr as usize].set_handler_fn(apic_err);
|
||||
idt[Interrupt::Spurious as usize].set_handler_fn(spurious);
|
||||
|
||||
idt[Interrupt::Timer as usize].set_handler_fn(timer);
|
||||
idt
|
||||
});
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
use alloc::{string::String, vec::Vec};
|
||||
use core::fmt::Debug;
|
||||
use core::fmt::Display;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use log::trace;
|
||||
use wasmi::Instance;
|
||||
use wasmi::{Caller, Func, Linker, Module, Store};
|
||||
use xml::XMLElement;
|
||||
|
||||
use crate::handle::{self, Handle};
|
||||
use crate::handle;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
pub struct WasmContext {
|
||||
pub proc_id: Option<u64>,
|
||||
pub instance: Instance,
|
||||
pub store: Store<HostState>,
|
||||
}
|
||||
|
||||
pub fn wasm() -> Result<(), wasmi::Error> {
|
||||
use wasmi::Config;
|
||||
|
@ -22,9 +30,7 @@ pub fn wasm() -> Result<(), wasmi::Error> {
|
|||
// trace!("Loading WASM binary");
|
||||
let module = Module::new(&engine, &wasm[..]).unwrap();
|
||||
// trace!("Constructing wasm module");
|
||||
let hs = HostState {
|
||||
proc_handle: crate::handle::Handle::new(),
|
||||
};
|
||||
let hs = HostState {};
|
||||
let mut store = Store::new(&engine, hs);
|
||||
// trace!("constructing host store");
|
||||
|
||||
|
@ -71,14 +77,10 @@ pub fn wasm() -> Result<(), wasmi::Error> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct HostState {
|
||||
/// In ableOS a handle is an unsigned 128 bit number
|
||||
proc_handle: Handle,
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct HostState {}
|
||||
|
||||
pub fn read_memory_address(caller: Caller<'_, HostState>, address: i32) -> i32 {
|
||||
trace!("Proccess Handle: {:?}", caller.data().proc_handle);
|
||||
trace!("Address: {}", address);
|
||||
// let obj = host_make_object(caller, 16, 23);
|
||||
0
|
||||
|
@ -137,3 +139,64 @@ pub fn host_read_object_attribute(
|
|||
|
||||
(0, 0)
|
||||
}
|
||||
|
||||
pub fn build_wasm_context(bytes: Vec<u8>) -> Result<WasmContext, wasmi::Error> {
|
||||
use wasmi::Config;
|
||||
use wasmi::Engine;
|
||||
let mut conf = Config::default();
|
||||
conf.wasm_bulk_memory(true);
|
||||
// conf.,
|
||||
let engine = Engine::new(&conf);
|
||||
// trace!("Engine constructed");
|
||||
|
||||
// let wasm = include_bytes!("../../wasm_syscall_test.wasm");
|
||||
let wasm = include_bytes!("../../test.wasm");
|
||||
|
||||
// trace!("Loading WASM binary");
|
||||
let module = Module::new(&engine, &wasm[..]).unwrap();
|
||||
// trace!("Constructing wasm module");
|
||||
let hs = HostState {};
|
||||
let mut store = Store::new(&engine, hs);
|
||||
// trace!("constructing host store");
|
||||
|
||||
let read_mem_addr = Func::wrap(
|
||||
&mut store,
|
||||
|caller: Caller<'_, HostState>, param: i32| -> i32 { read_memory_address(caller, param) },
|
||||
);
|
||||
|
||||
let mut linker = <Linker<HostState>>::new(&engine);
|
||||
linker.define(
|
||||
"host",
|
||||
"read_mem_addr",
|
||||
Func::wrap(
|
||||
&mut store,
|
||||
|caller: Caller<'_, HostState>, param: i32| -> i32 {
|
||||
read_memory_address(caller, param)
|
||||
},
|
||||
),
|
||||
)?;
|
||||
|
||||
linker.define(
|
||||
"host",
|
||||
"read_object_attribute",
|
||||
Func::wrap(&mut store, host_read_object_attribute),
|
||||
)?;
|
||||
|
||||
linker.define(
|
||||
"host",
|
||||
"create_object",
|
||||
Func::wrap(&mut store, host_make_object),
|
||||
)?;
|
||||
|
||||
let instance = linker
|
||||
.instantiate(&mut store, &module)?
|
||||
.ensure_no_start(&mut store)?;
|
||||
|
||||
let wc = WasmContext {
|
||||
instance,
|
||||
store,
|
||||
proc_id: None,
|
||||
};
|
||||
|
||||
Ok(wc)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use spin::{Lazy, Mutex};
|
|||
|
||||
use crate::arch::{hardware_random_u64, sloop};
|
||||
use crate::handle::Handle;
|
||||
use crate::schedule::Scheduler;
|
||||
use crate::{interp, task};
|
||||
|
||||
use crate::alloc::string::ToString;
|
||||
|
@ -21,13 +22,13 @@ pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! {
|
|||
let kcmd = clparse::Arguments::parse(cmdline.to_string()).unwrap();
|
||||
log::info!("Cmdline: {kcmd:?}");
|
||||
|
||||
if kcmd.arguments.get("baka") == Some(&"true".to_string()) {
|
||||
let _ = crate::arch::log(format_args!(include_str!("../data/⑨. バカ")));
|
||||
}
|
||||
// if kcmd.arguments.get("baka") == Some(&"true".to_string()) {
|
||||
// let _ = crate::arch::log(format_args!(include_str!("../data/⑨. バカ")));
|
||||
// }
|
||||
|
||||
if kcmd.arguments.get("foobles") == Some(&"true".to_string()) {
|
||||
let _ = crate::arch::log(format_args!("foobles\n"));
|
||||
}
|
||||
// if kcmd.arguments.get("foobles") == Some(&"true".to_string()) {
|
||||
// let _ = crate::arch::log(format_args!("foobles\n"));
|
||||
// }
|
||||
|
||||
let bootstrap = bootstrap/*.expect("no bootstrap found")*/;
|
||||
match bootstrap {
|
||||
|
@ -37,18 +38,32 @@ pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
use xml::XMLElement;
|
||||
let kcmd = XMLElement::new("cmdline");
|
||||
let hnd = Handle::new();
|
||||
OBJECTS.lock().insert(hnd, kcmd);
|
||||
// use xml::XMLElement;
|
||||
// let kcmd = XMLElement::new("cmdline");
|
||||
// let hnd = Handle::new();
|
||||
// kcmd.set_attribute("")
|
||||
// OBJECTS.lock().insert(hnd, kcmd);
|
||||
|
||||
let abc = interp::wasm();
|
||||
// let abc = interp::wasm();
|
||||
|
||||
trace!("{:?}", abc);
|
||||
crate::arch::sloop()
|
||||
// trace!("{:?}", abc);
|
||||
|
||||
let sch = SCHEDULER;
|
||||
let mut sch = sch.lock();
|
||||
let wc = interp::build_wasm_context(alloc::vec::Vec::new()).unwrap();
|
||||
sch.schedule(wc, crate::schedule::ContextWake::None);
|
||||
|
||||
sch.run();
|
||||
|
||||
// crate::arch::sloop()
|
||||
}
|
||||
pub const OBJECTS: Lazy<Mutex<HashMap<Handle, xml::XMLElement>>> = Lazy::new(|| {
|
||||
let mut obj: HashMap<Handle, xml::XMLElement> = HashMap::new();
|
||||
Mutex::new(obj)
|
||||
});
|
||||
use hashbrown::HashMap;
|
||||
|
||||
pub const SCHEDULER: Lazy<Mutex<Scheduler>> = Lazy::new(|| {
|
||||
let mut sch = Scheduler::new();
|
||||
Mutex::new(sch)
|
||||
});
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
ptr_sub_ptr
|
||||
)]
|
||||
#![no_std]
|
||||
// #![deny(missing_docs)]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
|
@ -20,6 +21,7 @@ pub mod interp;
|
|||
mod kmain;
|
||||
mod logger;
|
||||
mod memory;
|
||||
mod schedule;
|
||||
mod task;
|
||||
|
||||
use versioning::Version;
|
||||
|
|
104
kernel/src/schedule.rs
Normal file
104
kernel/src/schedule.rs
Normal file
|
@ -0,0 +1,104 @@
|
|||
use core::arch;
|
||||
|
||||
// WasmContext
|
||||
use crate::{arch::sloop, interp::WasmContext};
|
||||
use alloc::vec::Vec;
|
||||
use log::trace;
|
||||
|
||||
pub type ProcId = u64;
|
||||
|
||||
pub struct Scheduler {
|
||||
running: Vec<WasmContext>,
|
||||
halted: Vec<(ContextWake, WasmContext)>,
|
||||
// time_halt: Vec<(ContextWake, WasmContext)>,
|
||||
next_proc_id: ProcId,
|
||||
}
|
||||
|
||||
impl Scheduler {
|
||||
pub fn new() -> Scheduler {
|
||||
Self {
|
||||
running: Vec::new(),
|
||||
halted: Vec::new(),
|
||||
// time_halt: Vec::new(),
|
||||
next_proc_id: 0,
|
||||
}
|
||||
}
|
||||
pub fn run(&mut self) -> ! {
|
||||
loop {
|
||||
let proc = self.running.pop();
|
||||
|
||||
// self.time_halt.sort();
|
||||
|
||||
match proc {
|
||||
Some(proc) => {
|
||||
// trace!("SWAP WasmContext");
|
||||
self.running.push(proc);
|
||||
}
|
||||
|
||||
None => {
|
||||
panic!("nothing scheduled.");
|
||||
sloop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fn sleep_inner(&self, id: ProcId) -> Result<usize, SchedulerError> {
|
||||
let proc_len = self.running.len();
|
||||
let mut proc_found = true;
|
||||
let mut sleep_index = 0;
|
||||
let mut i = 0;
|
||||
for wc in &self.running {
|
||||
if wc.proc_id == Some(id) {
|
||||
sleep_index = i;
|
||||
proc_found = true;
|
||||
break;
|
||||
}
|
||||
if i == proc_len {
|
||||
proc_found = false;
|
||||
trace!("no process with ID {} found", id);
|
||||
return Err(SchedulerError::ProcessIDNotFound(id));
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
|
||||
Ok(sleep_index)
|
||||
}
|
||||
pub fn sleep(&mut self, id: ProcId, time: u64) -> Result<(), SchedulerError> {
|
||||
match self.sleep_inner(id) {
|
||||
Ok(sid) => self
|
||||
.halted
|
||||
.push((ContextWake::Time(time), self.running.remove(sid))),
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn schedule(&mut self, wc: WasmContext, cw: ContextWake) -> Result<(), SchedulerError> {
|
||||
if wc.proc_id != None {
|
||||
panic!("Already Scheduled with PROC_ID {}", wc.proc_id.unwrap());
|
||||
}
|
||||
trace!("Scheduling WC with ProcID {}", self.next_proc_id);
|
||||
|
||||
if cw == ContextWake::None {
|
||||
self.running.push(wc)
|
||||
} else {
|
||||
self.halted.push((cw, wc));
|
||||
}
|
||||
|
||||
self.next_proc_id += 1;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[derive(PartialEq)]
|
||||
pub enum ContextWake {
|
||||
/// Used when spawning a new process to have it instantly start
|
||||
None,
|
||||
Time(u64),
|
||||
ObjectEvent,
|
||||
}
|
||||
|
||||
pub enum SchedulerError {
|
||||
ProcessIDNotFound(ProcId),
|
||||
AlreadyScheduled(),
|
||||
}
|
51
meta.md
Normal file
51
meta.md
Normal file
|
@ -0,0 +1,51 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ARI AbleOS Remote Install
|
||||
|
||||
Server
|
||||
/boot/server_kernel_x86_64.bin
|
||||
/boot/kernel_x86_64.bin
|
||||
/boot/kernel_aarch64.bin
|
||||
|
||||
/home/projects/askl.askl - aksldfhlkasjdhflkajshdflkj
|
||||
|
||||
|
||||
ARI_SERVER.wasm
|
||||
NAS 10.1.10.10
|
||||
|
||||
ARI 10.1.10.10
|
||||
/boot/limine.cfg
|
||||
/boot/kernel_x86_64.bin
|
||||
/boot/kernel.toml
|
||||
/home/projects/askl.askl
|
||||
aksldfhlkasjdhflkajshdflkj
|
||||
|
||||
|
||||
ARI 10.1.10.10
|
||||
/boot/limine.cfg
|
||||
/boot/kernel_aarch64.bin
|
||||
/boot/kernel.toml
|
||||
|
||||
|
||||
|
||||
/system/
|
||||
/shared/
|
||||
/home/programs/
|
||||
project_name/
|
||||
project_name.wasm
|
||||
project_name.toml
|
||||
|
||||
|
||||
|
||||
|
||||
/system/pkgman.toml
|
||||
|
||||
//////
|
||||
[repositories]
|
||||
PUR = "https://git.ablecorp.us/ableos/pur"
|
||||
|
Loading…
Reference in a new issue