forked from koniifer/ableos
changes
This commit is contained in:
parent
20e3ce15be
commit
530a8a9d60
30
Cargo.lock
generated
30
Cargo.lock
generated
|
@ -125,7 +125,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "clparse"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/ableos/ableos_userland#389c85d6a4ed06dce5aa044257e881d1547edfdb"
|
||||
source = "git+https://git.ablecorp.us/ableos/ableos_userland#8fa6c705f23ae310e3c4395a61823449ed5a1d02"
|
||||
dependencies = [
|
||||
"hashbrown 0.13.2",
|
||||
"log",
|
||||
|
@ -420,8 +420,10 @@ dependencies = [
|
|||
"crossbeam-queue",
|
||||
"derive_more",
|
||||
"error-stack 0.3.1",
|
||||
"hashbrown 0.13.2",
|
||||
"limine",
|
||||
"log",
|
||||
"rdrand",
|
||||
"sbi",
|
||||
"slab",
|
||||
"spin",
|
||||
|
@ -430,6 +432,7 @@ dependencies = [
|
|||
"wasmi",
|
||||
"x2apic",
|
||||
"x86_64",
|
||||
"xml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -547,6 +550,12 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
|
||||
[[package]]
|
||||
name = "raw-cpuid"
|
||||
version = "10.7.0"
|
||||
|
@ -556,6 +565,15 @@ dependencies = [
|
|||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rdrand"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e233b642160555c1aa1ff7a78443c6139342f411b6fa6602af2ebbfee9e166bb"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.3"
|
||||
|
@ -773,7 +791,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|||
[[package]]
|
||||
name = "versioning"
|
||||
version = "0.1.3"
|
||||
source = "git+https://git.ablecorp.us/ableos/ableos_userland#389c85d6a4ed06dce5aa044257e881d1547edfdb"
|
||||
source = "git+https://git.ablecorp.us/ableos/ableos_userland#8fa6c705f23ae310e3c4395a61823449ed5a1d02"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
@ -1086,3 +1104,11 @@ dependencies = [
|
|||
"rustversion",
|
||||
"volatile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/ableos/ableos_userland#8fa6c705f23ae310e3c4395a61823449ed5a1d02"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
resolver = "2"
|
||||
|
||||
|
||||
[workspace]
|
||||
members = ["kernel", "repbuild"]
|
||||
|
|
|
@ -10,12 +10,12 @@ log = "0.4"
|
|||
spin = "0.9"
|
||||
uart_16550 = "0.2"
|
||||
slab = { version = "0.4", default-features = false }
|
||||
# xml = { git = "https://git.ablecorp.us/ableos/ableos_userland" }
|
||||
xml = { git = "https://git.ablecorp.us/ableos/ableos_userland" }
|
||||
|
||||
clparse = { git = "https://git.ablecorp.us/ableos/ableos_userland", default-features = false }
|
||||
versioning = { git = "https://git.ablecorp.us/ableos/ableos_userland" }
|
||||
wasmi = { version = "0.29.0", default-features = false }
|
||||
|
||||
hashbrown = "*"
|
||||
|
||||
[dependencies.crossbeam-queue]
|
||||
version = "0.3"
|
||||
|
@ -43,6 +43,9 @@ features = [
|
|||
limine = { version = "0.1", git = "https://github.com/limine-bootloader/limine-rs" }
|
||||
x86_64 = "0.14"
|
||||
x2apic = "0.4"
|
||||
# rdrand = "*"
|
||||
rdrand = { version = "0.8", default-features = false }
|
||||
|
||||
|
||||
[target.'cfg(target_arch = "riscv64")'.dependencies]
|
||||
sbi = "0.2.0"
|
||||
|
|
36
kernel/data/test.wat
Normal file
36
kernel/data/test.wat
Normal file
|
@ -0,0 +1,36 @@
|
|||
(module
|
||||
(data "mouse")
|
||||
(data "x")
|
||||
(data "y")
|
||||
(func $rma (import "host" "read_mem_addr")(param i32)(result i32))
|
||||
(func $co (import "host" "create_object")(param i32 i32)(result i64))
|
||||
(func $roa (import "host" "read_object_attribute")(param i64 i32 i32)(result i32 i32))
|
||||
(memory (export "memory") 1)
|
||||
|
||||
(func
|
||||
(export "start")(result i32)
|
||||
;; Copy into memory the object name
|
||||
(memory.init 0
|
||||
(i32.const 0) ;; target offset
|
||||
(i32.const 0) ;; source offset
|
||||
(i32.const 5))
|
||||
(memory.init 1
|
||||
(i32.const 6) ;; target offset
|
||||
(i32.const 0) ;; source offset
|
||||
(i32.const 1))
|
||||
(memory.init 2
|
||||
(i32.const 7) ;; target offset
|
||||
(i32.const 0) ;; source offset
|
||||
(i32.const 1))
|
||||
|
||||
i32.const 0
|
||||
i32.const 5
|
||||
call $co
|
||||
|
||||
i32.const 6
|
||||
i32.const 1
|
||||
|
||||
call $roa
|
||||
|
||||
)
|
||||
)
|
|
@ -2,6 +2,8 @@ use spin::{Lazy, Mutex};
|
|||
use x2apic::lapic::{LocalApic, LocalApicBuilder};
|
||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
|
||||
|
||||
use crate::interp::wasm;
|
||||
|
||||
pub unsafe fn init() {
|
||||
log::info!("Initialising IDT");
|
||||
IDT.load();
|
||||
|
@ -16,7 +18,7 @@ enum Interrupt {
|
|||
Spurious = u8::MAX,
|
||||
}
|
||||
|
||||
static LAPIC: Lazy<Mutex<LocalApic>> = Lazy::new(|| {
|
||||
pub(crate) static LAPIC: Lazy<Mutex<LocalApic>> = Lazy::new(|| {
|
||||
let mut lapic = LocalApicBuilder::new()
|
||||
.timer_vector(Interrupt::Timer as usize)
|
||||
.error_vector(Interrupt::ApicErr as usize)
|
||||
|
@ -54,7 +56,7 @@ extern "x86-interrupt" fn page_fault(
|
|||
panic!("Page fault ({error_code:?}): {stack_frame:?}")
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn timer(_: InterruptStackFrame) {
|
||||
extern "x86-interrupt" fn timer(isf: InterruptStackFrame) {
|
||||
unsafe { LAPIC.lock().end_of_interrupt() };
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
pub mod memory;
|
||||
|
||||
mod gdt;
|
||||
mod interrupts;
|
||||
pub(crate) mod interrupts;
|
||||
mod logging;
|
||||
|
||||
pub use logging::log;
|
||||
|
@ -82,3 +82,13 @@ pub fn sloop() -> ! {
|
|||
x86_64::instructions::hlt();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hardware_random_u64() -> u64 {
|
||||
use log::trace;
|
||||
use rdrand::RdRand;
|
||||
let gen = RdRand::new().unwrap();
|
||||
let ret = gen.try_next_u64().unwrap();
|
||||
trace!("Random {}", ret);
|
||||
|
||||
ret
|
||||
}
|
||||
|
|
46
kernel/src/handle.rs
Normal file
46
kernel/src/handle.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use core::fmt::{self, Formatter};
|
||||
|
||||
use crate::arch::hardware_random_u64;
|
||||
|
||||
#[derive(Debug, Eq, Hash, PartialEq)]
|
||||
pub struct Handle {
|
||||
pub handle_data: i64,
|
||||
perms: Permissions,
|
||||
}
|
||||
|
||||
impl Handle {
|
||||
pub fn new() -> Handle {
|
||||
Handle {
|
||||
handle_data: hardware_random_u64() as i64,
|
||||
perms: Permissions::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Handle {
|
||||
fn fmt(&self, w: &mut Formatter<'_>) -> Result<(), core::fmt::Error> {
|
||||
write!(w, "{}", self.handle_data);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<i64> for Handle {
|
||||
fn into(self) -> i64 {
|
||||
self.handle_data
|
||||
// (abc[0..3] as i64, abc[4..8] as i64)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Hash, Eq, Debug)]
|
||||
pub struct Permissions {
|
||||
edit_children: bool,
|
||||
edit_attributes: bool,
|
||||
}
|
||||
impl Permissions {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
edit_children: true,
|
||||
edit_attributes: true,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +1,139 @@
|
|||
use alloc::vec::Vec;
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::fmt::Debug;
|
||||
use core::fmt::Display;
|
||||
use log::trace;
|
||||
use wasmi::{Caller, Func, Linker, Module, Store};
|
||||
use xml::XMLElement;
|
||||
|
||||
use crate::handle::{self, Handle};
|
||||
|
||||
pub fn wasm() -> Result<(), wasmi::Error> {
|
||||
use wasmi::Config;
|
||||
use wasmi::Engine;
|
||||
trace!("");
|
||||
let conf = Config::default();
|
||||
let mut conf = Config::default();
|
||||
conf.wasm_bulk_memory(true);
|
||||
// conf.,
|
||||
let engine = Engine::new(&conf);
|
||||
trace!("Engine constructed");
|
||||
// trace!("Engine constructed");
|
||||
|
||||
let wasm = include_bytes!("../../wasm_syscall_test.wasm");
|
||||
// let wasm = include_bytes!("../../wasm_syscall_test.wasm");
|
||||
let wasm = include_bytes!("../../test.wasm");
|
||||
|
||||
trace!("Loading WASM binary");
|
||||
// trace!("Loading WASM binary");
|
||||
let module = Module::new(&engine, &wasm[..]).unwrap();
|
||||
trace!("Constructing wasm module");
|
||||
// trace!("Constructing wasm module");
|
||||
let hs = HostState {
|
||||
proc_handle: crate::handle::Handle::new(),
|
||||
};
|
||||
let mut store = Store::new(&engine, hs);
|
||||
// trace!("constructing host store");
|
||||
|
||||
let mut store = Store::new(&engine, 42);
|
||||
trace!("constructing host store");
|
||||
|
||||
let read_mem_addr = Func::wrap(&mut store, |caller: Caller<'_, HostState>, param: u64| {
|
||||
read_memory_address(caller, param);
|
||||
|
||||
panic!(":)")
|
||||
});
|
||||
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", read_mem_addr)?;
|
||||
trace!("Linked read_mem_addr");
|
||||
linker.define(
|
||||
"host",
|
||||
"read_mem_addr",
|
||||
Func::wrap(
|
||||
&mut store,
|
||||
|caller: Caller<'_, HostState>, param: i32| -> i32 {
|
||||
read_memory_address(caller, param)
|
||||
},
|
||||
),
|
||||
)?;
|
||||
|
||||
let instance = linker.instantiate(&mut store, &module)?.start(&mut store)?;
|
||||
trace!("Instanced the engine and module");
|
||||
linker.define(
|
||||
"host",
|
||||
"read_object_attribute",
|
||||
Func::wrap(&mut store, host_read_object_attribute),
|
||||
)?;
|
||||
|
||||
let hello = instance.get_typed_func::<(), ()>(&store, "_start")?;
|
||||
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 version = instance.get_global(&store, "VERSION");
|
||||
|
||||
// trace!("Version: {:?}", version);
|
||||
let hello = instance.get_typed_func::<(), (i32, i32)>(&store, "start")?;
|
||||
|
||||
let ret = hello.call(&mut store, ())?;
|
||||
trace!("Called _start got return of {:?}", ret);
|
||||
|
||||
hello.call(&mut store, ())?;
|
||||
trace!("Called _start");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub type HostState = u32;
|
||||
pub fn read_memory_address(caller: Caller<'_, HostState>, address: u64) -> u64 {
|
||||
pub struct HostState {
|
||||
/// In ableOS a handle is an unsigned 128 bit number
|
||||
proc_handle: Handle,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
use crate::kmain::OBJECTS;
|
||||
pub fn host_make_object(
|
||||
caller: Caller<'_, HostState>,
|
||||
address_start: i32,
|
||||
length_of_string: i32,
|
||||
) -> i64 {
|
||||
trace!(
|
||||
"Called with addr {{ start {} length {} }}",
|
||||
address_start,
|
||||
length_of_string
|
||||
);
|
||||
let mem = caller.get_export("memory").unwrap().into_memory().unwrap();
|
||||
let mem_array = mem.data(&caller);
|
||||
let mut name = String::new();
|
||||
for i in address_start..(address_start + length_of_string) {
|
||||
let ch = mem_array[i as usize] as char;
|
||||
name.push(ch);
|
||||
}
|
||||
trace!("Object Name {}", name);
|
||||
let hand = handle::Handle::new();
|
||||
{
|
||||
let binding = OBJECTS;
|
||||
let mut olock = binding.lock();
|
||||
let obj = XMLElement::new(name);
|
||||
|
||||
olock.insert(handle::Handle::new(), obj);
|
||||
}
|
||||
|
||||
hand.into()
|
||||
}
|
||||
|
||||
pub fn host_read_object_attribute(
|
||||
caller: Caller<'_, HostState>,
|
||||
handle: i64,
|
||||
address_start: i32,
|
||||
length_of_string: i32,
|
||||
) -> (i32, i32) {
|
||||
{
|
||||
let binding = OBJECTS;
|
||||
let mut olock = binding.lock();
|
||||
|
||||
// olock.get(&handle);
|
||||
}
|
||||
|
||||
let mem = caller.get_export("memory").unwrap().into_memory().unwrap();
|
||||
let mem_array = mem.data(&caller);
|
||||
let mut name = String::new();
|
||||
for i in address_start..(address_start + length_of_string) {
|
||||
let ch = mem_array[i as usize] as char;
|
||||
name.push(ch);
|
||||
}
|
||||
|
||||
(0, 0)
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
//! AbleOS Kernel Entrypoint
|
||||
|
||||
use log::{info, trace};
|
||||
// use std::collections::HashMap;
|
||||
|
||||
use crate::arch::sloop;
|
||||
use log::{info, trace};
|
||||
use spin::{Lazy, Mutex};
|
||||
|
||||
use crate::arch::{hardware_random_u64, sloop};
|
||||
use crate::handle::Handle;
|
||||
use crate::{interp, task};
|
||||
|
||||
use crate::alloc::string::ToString;
|
||||
|
@ -17,10 +21,14 @@ 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(&"9".to_string()) {
|
||||
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"));
|
||||
}
|
||||
|
||||
let bootstrap = bootstrap/*.expect("no bootstrap found")*/;
|
||||
match bootstrap {
|
||||
Some(bootstrap_mod) => {}
|
||||
|
@ -29,11 +37,18 @@ pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
// use xml::XMLElement;
|
||||
// let kcmd = XMLElement::new("cmdline");
|
||||
use xml::XMLElement;
|
||||
let kcmd = XMLElement::new("cmdline");
|
||||
let hnd = Handle::new();
|
||||
OBJECTS.lock().insert(hnd, kcmd);
|
||||
|
||||
let abc = interp::wasm();
|
||||
|
||||
trace!("{:?}", abc);
|
||||
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;
|
||||
|
|
|
@ -15,6 +15,7 @@ extern crate alloc;
|
|||
|
||||
mod allocator;
|
||||
mod arch;
|
||||
pub mod handle;
|
||||
pub mod interp;
|
||||
mod kmain;
|
||||
mod logger;
|
||||
|
|
24
kernel/sycall.md
Normal file
24
kernel/sycall.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
|
||||
|
||||
`create_object`
|
||||
```
|
||||
params
|
||||
i32
|
||||
start address of the string to use as the object name
|
||||
i32
|
||||
length of string
|
||||
returns
|
||||
i64 Handle to the object
|
||||
```
|
||||
|
||||
`read_object_attribute`
|
||||
```
|
||||
params
|
||||
i64 Handle to the object
|
||||
i32
|
||||
start address of the string to use as the attribute name
|
||||
i32
|
||||
end address of the string to use as the attribute name
|
||||
returns
|
||||
```
|
|
@ -2,7 +2,7 @@ ${ABLEOS_KERNEL}=boot:///kernel
|
|||
# TODO: Make a boot background image for ableOS
|
||||
|
||||
DEFAULT_ENTRY=1
|
||||
TIMEOUT=3
|
||||
TIMEOUT=0
|
||||
VERBOSE=yes
|
||||
INTERFACE_RESOLUTION=1024x768
|
||||
# Terminal related settings
|
||||
|
@ -13,9 +13,10 @@ TERM_BACKDROP=008080
|
|||
COMMENT=Default AbleOS boot entry.
|
||||
PROTOCOL=limine
|
||||
KERNEL_PATH=${ABLEOS_KERNEL}
|
||||
KERNEL_CMDLINE="hi=true bye=false baka=9"
|
||||
KERNEL_CMDLINE="baka=false foobles=true"
|
||||
# KERNEL_CMDLINE=""
|
||||
# Setting a default resolution for the framebuffer
|
||||
RESOLUTION=1024x768x24
|
||||
|
||||
MODULE_PATH=boot:///boot/fs.wasm
|
||||
# MODULE_PATH=boot:///boot/fs.wasm
|
||||
# MODULE_CMDLINE=This is the first module.
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue