Litrally amlmost functional PS/2 driver. #19
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -213,12 +213,12 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "hbbytecode"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#542c69fd6042a4b48462199c4391761bfe1b7c2e"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#37dd13cab295aa9e74d704b3345685b4428d149a"
|
||||
|
||||
[[package]]
|
||||
name = "hblang"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#542c69fd6042a4b48462199c4391761bfe1b7c2e"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#37dd13cab295aa9e74d704b3345685b4428d149a"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
"hbbytecode",
|
||||
|
@ -229,7 +229,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "hbvm"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#542c69fd6042a4b48462199c4391761bfe1b7c2e"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#37dd13cab295aa9e74d704b3345685b4428d149a"
|
||||
dependencies = [
|
||||
"hbbytecode",
|
||||
]
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
//! Environment call handling routines
|
||||
|
||||
use crate::holeybytes::kernel_services::{
|
||||
block_read, dt_msg_handler::dt_msg_handler, logging_service::log_msg_handler,
|
||||
service_definition_service::sds_msg_handler,
|
||||
use {alloc::boxed::Box, core::cell::LazyCell, hbvm::mem::Address};
|
||||
|
||||
use crate::{
|
||||
holeybytes::{
|
||||
kernel_services::{
|
||||
block_read, dt_msg_handler::dt_msg_handler, logging_service::log_msg_handler,
|
||||
service_definition_service::sds_msg_handler,
|
||||
},
|
||||
ExecThread,
|
||||
},
|
||||
kmain::EXECUTOR,
|
||||
task::Executor,
|
||||
};
|
||||
|
||||
use {
|
||||
|
@ -143,6 +152,43 @@ pub fn handler(vm: &mut Vm) {
|
|||
Ok(()) => {}
|
||||
Err(_) => log::error!("Improper dt query"),
|
||||
},
|
||||
6 => unsafe {
|
||||
let program = block_read(mem_addr, length);
|
||||
|
||||
// decode AbleOS Executable format
|
||||
let header = &program[0..46];
|
||||
let magic_slice = &header[0..3];
|
||||
if magic_slice != [0x15, 0x91, 0xD2] {
|
||||
log::error!("Invalid magic number at the start of executable.");
|
||||
return;
|
||||
}
|
||||
|
||||
let executable_format_version =
|
||||
u32::from_le_bytes(header[3..7].try_into().unwrap());
|
||||
let offset = if executable_format_version == 0 {
|
||||
47
|
||||
} else {
|
||||
error!("Invalid executable format.");
|
||||
return;
|
||||
};
|
||||
|
||||
let code_length = u64::from_le_bytes(header[7..15].try_into().unwrap());
|
||||
let data_length = u64::from_le_bytes(header[15..23].try_into().unwrap());
|
||||
let end = (code_length + data_length) as usize;
|
||||
log::debug!("{code_length} + {data_length} = {end}");
|
||||
|
||||
let thr = ExecThread::new(&program[offset..end], Address::new(0));
|
||||
vm.registers[1] = Value(
|
||||
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
|
||||
.unwrap()
|
||||
.spawn(Box::pin(async move {
|
||||
if let Err(e) = thr.await {
|
||||
log::error!("{e:?}");
|
||||
}
|
||||
})) as u64,
|
||||
);
|
||||
log::debug!("spawned a process");
|
||||
},
|
||||
|
||||
buffer_id => {
|
||||
let mut buffs = IPC_BUFFERS.lock();
|
||||
|
|
|
@ -8,7 +8,10 @@ use {
|
|||
device_tree::DeviceTree,
|
||||
holeybytes::ExecThread,
|
||||
ipc::buffer::IpcBuffer,
|
||||
task::Executor,
|
||||
},
|
||||
alloc::boxed::Box,
|
||||
core::cell::LazyCell,
|
||||
hashbrown::HashMap,
|
||||
hbvm::mem::Address,
|
||||
limine::{Framebuffer, FramebufferRequest, NonNullPtr},
|
||||
|
@ -65,8 +68,8 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! {
|
|||
fb1.address.as_ptr().unwrap() as *const u8
|
||||
);
|
||||
|
||||
let mut executor = crate::task::Executor::new(256);
|
||||
unsafe {
|
||||
let executor = LazyCell::<Executor>::force_mut(&mut EXECUTOR);
|
||||
for module in boot_modules.iter() {
|
||||
let cmd = module.cmd.trim_matches('"');
|
||||
let cmd_len = cmd.len() as u64;
|
||||
|
@ -109,11 +112,11 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! {
|
|||
if cmd_len > 0 {
|
||||
thr.set_arguments(cmd.as_ptr() as u64, cmd_len);
|
||||
}
|
||||
executor.spawn(async move {
|
||||
executor.spawn(Box::pin(async move {
|
||||
if let Err(e) = thr.await {
|
||||
log::error!("{e:?}");
|
||||
}
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
debug!("Random number: {}", hardware_random_u64());
|
||||
|
@ -124,6 +127,10 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! {
|
|||
crate::arch::spin_loop()
|
||||
}
|
||||
|
||||
// ! SAFETY: this is not threadsafe at all, like even a little bit.
|
||||
// ! SERIOUSLY
|
||||
pub static mut EXECUTOR: LazyCell<Executor> = LazyCell::new(|| Executor::new());
|
||||
|
||||
pub static DEVICE_TREE: Lazy<Mutex<DeviceTree>> = Lazy::new(|| {
|
||||
let dt = DeviceTree::new();
|
||||
Mutex::new(dt)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
exclusive_wrapper,
|
||||
core_intrinsics,
|
||||
abi_x86_interrupt,
|
||||
lazy_get,
|
||||
alloc_error_handler,
|
||||
ptr_sub_ptr,
|
||||
custom_test_frameworks,
|
||||
|
|
|
@ -29,24 +29,24 @@ pub fn yield_now() -> impl Future<Output = ()> {
|
|||
YieldNow(false)
|
||||
}
|
||||
|
||||
pub struct Executor<F: Future<Output = ()> + Send> {
|
||||
tasks: Slab<Task<F>>,
|
||||
pub struct Executor {
|
||||
tasks: Slab<Task>,
|
||||
task_queue: Arc<TaskQueue>,
|
||||
}
|
||||
|
||||
impl<F: Future<Output = ()> + Send> Executor<F> {
|
||||
pub fn new(size: usize) -> Self {
|
||||
impl Executor {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
tasks: Slab::with_capacity(size),
|
||||
tasks: Slab::new(),
|
||||
task_queue: Arc::new(TaskQueue::new()),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn spawn(&mut self, future: F) {
|
||||
self.task_queue
|
||||
.queue
|
||||
.push(self.tasks.insert(Task::new(future)));
|
||||
pub fn spawn(&mut self, future: Pin<Box<dyn Future<Output = ()> + Send>>) -> usize {
|
||||
let id = self.tasks.insert(Task::new(future));
|
||||
self.task_queue.queue.push(id);
|
||||
id
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
|
@ -83,17 +83,17 @@ impl<F: Future<Output = ()> + Send> Executor<F> {
|
|||
}
|
||||
}
|
||||
|
||||
struct Task<F: Future<Output = ()> + Send> {
|
||||
future: Pin<Box<F>>,
|
||||
struct Task {
|
||||
future: Pin<Box<dyn Future<Output = ()> + Send>>,
|
||||
waker: Option<TaskWaker>,
|
||||
}
|
||||
|
||||
impl<F: Future<Output = ()> + Send> Task<F> {
|
||||
impl Task {
|
||||
#[inline(always)]
|
||||
pub fn new(future: F) -> Self {
|
||||
pub fn new(future: Pin<Box<dyn Future<Output = ()> + Send>>) -> Self {
|
||||
Self {
|
||||
future: Box::pin(future),
|
||||
waker: None,
|
||||
future,
|
||||
waker: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,8 @@ impl Package {
|
|||
let path = format!("sysdata/programs/{}/{}", self.name, file);
|
||||
// compile here
|
||||
|
||||
let mut warnings = String::new();
|
||||
|
||||
hblang::run_compiler(
|
||||
&path,
|
||||
Options {
|
||||
|
@ -85,6 +87,7 @@ impl Package {
|
|||
..Default::default()
|
||||
},
|
||||
out,
|
||||
&mut warnings,
|
||||
)?;
|
||||
|
||||
match std::fs::create_dir("target/programs") {
|
||||
|
@ -100,6 +103,7 @@ impl Package {
|
|||
..Default::default()
|
||||
},
|
||||
out,
|
||||
&mut warnings,
|
||||
)?;
|
||||
std::fs::write(format!("target/programs/{}.hbf", self.name), &out)?;
|
||||
out.clear();
|
||||
|
@ -112,6 +116,7 @@ impl Package {
|
|||
..Default::default()
|
||||
},
|
||||
out,
|
||||
&mut warnings,
|
||||
)?;
|
||||
std::fs::write(format!("target/programs/{}.hba", self.name), &out)?;
|
||||
out.clear();
|
||||
|
|
|
@ -7,6 +7,7 @@ math := @use("math.hb")
|
|||
random := @use("random.hb")
|
||||
file := @use("file_io.hb")
|
||||
dt := @use("dt.hb")
|
||||
process := @use("process.hb")
|
||||
|
||||
panic := fn(message: ?^u8): never {
|
||||
log.error("Error: Panic Called, Message:\0")
|
||||
|
|
12
sysdata/libraries/stn/src/process.hb
Normal file
12
sysdata/libraries/stn/src/process.hb
Normal file
|
@ -0,0 +1,12 @@
|
|||
// ! will be rewritten to take a file object when filesystem is exist
|
||||
// returns PID
|
||||
$spawn := fn(proc_exe: ^u8, length: uint): uint {
|
||||
return @eca(3, 6, proc_exe, length)
|
||||
}
|
||||
|
||||
/* TODO:
|
||||
- Spawn an empty process
|
||||
- Call a function to load bytes into that process from a function
|
||||
Or
|
||||
- Manually fill the bytes in
|
||||
- Execute the process via a run type command */
|
11
sysdata/programs/processes/meta.toml
Normal file
11
sysdata/programs/processes/meta.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "processes"
|
||||
authors = ["koniifer"]
|
||||
|
||||
[dependants.libraries]
|
||||
|
||||
[dependants.binaries]
|
||||
hblang.version = "1.0.0"
|
||||
|
||||
[build]
|
||||
command = "hblang src/main.hb"
|
7
sysdata/programs/processes/src/hello_world_and_spin.hb
Normal file
7
sysdata/programs/processes/src/hello_world_and_spin.hb
Normal file
|
@ -0,0 +1,7 @@
|
|||
.{log} := @use("../../../libraries/stn/src/lib.hb")
|
||||
|
||||
main := fn(): void {
|
||||
log.info("Hello, World!\0")
|
||||
loop {
|
||||
}
|
||||
}
|
BIN
sysdata/programs/processes/src/hello_world_and_spin.hbf
Normal file
BIN
sysdata/programs/processes/src/hello_world_and_spin.hbf
Normal file
Binary file not shown.
19
sysdata/programs/processes/src/main.hb
Normal file
19
sysdata/programs/processes/src/main.hb
Normal file
|
@ -0,0 +1,19 @@
|
|||
.{process, log, string, memory} := @use("../../../libraries/stn/src/lib.hb")
|
||||
|
||||
exe := @embed("./hello_world_and_spin.hbf")
|
||||
|
||||
main := fn(): void {
|
||||
buf := "\0\0\0\0\0\0\0"
|
||||
loop {
|
||||
log.info(
|
||||
string.display_int(
|
||||
@bitcast(process.spawn(@bitcast(&exe), 356)),
|
||||
buf,
|
||||
10,
|
||||
),
|
||||
)
|
||||
// spin so we don't spawn 10 quattuordecillion processes
|
||||
i := 0
|
||||
loop if i == 1000000 break else i += 1
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue