1
0
Fork 0
forked from AbleOS/ableos

Compare commits

...

4 commits

29 changed files with 164 additions and 165 deletions

View file

@ -83,33 +83,31 @@ extern "x86-interrupt" fn spurious(_: InterruptStackFrame) {
}
}
#[allow(unused_imports)]
fn interrupt(interrupt_type: Interrupt) {
use crate::arch::INTERRUPT_LIST;
use crate::kmain::EXECUTOR;
let il = INTERRUPT_LIST.lock();
let val = il.list.get(&interrupt_type).unwrap();
use crate::{arch::INTERRUPT_LIST, kmain::EXECUTOR};
// let il = INTERRUPT_LIST.lock();
// let val = il.list.get(&interrupt_type).unwrap();
use crate::holeybytes::kernel_services::service_definition_service::sds_search_service;
let buffer = sds_search_service(val);
if buffer != 0 {
use {crate::kmain::IPC_BUFFERS, alloc::vec::Vec};
let mut buffs = IPC_BUFFERS.lock();
match buffs.get_mut(&buffer) {
Some(buff) => {
let mut msg_vec = Vec::new();
msg_vec.push(0xFF);
buff.push(msg_vec.to_vec());
log::debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer);
}
None => {
log::error!("Access of non-existent buffer {}", buffer)
}
}
// use crate::holeybytes::kernel_services::service_definition_service::sds_search_service;
// let buffer = sds_search_service(val);
// if buffer != 0 {
// use {crate::kmain::IPC_BUFFERS, alloc::vec::Vec};
// let mut buffs = IPC_BUFFERS.lock();
// match buffs.get_mut(&buffer) {
// Some(buff) => {
// let mut msg_vec = Vec::new();
// msg_vec.push(0xFF);
// buff.push(msg_vec.to_vec());
// log::debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer);
// }
// None => {
// log::error!("Access of non-existent buffer {}", buffer)
// }
// }
// }
// log::info!("{}", buffer);
}
unsafe{
unsafe {
EXECUTOR.send_interrupt(interrupt_type as u8);
}
}

View file

@ -80,6 +80,10 @@ pub fn handler(vm: &mut Vm, pid: &usize) {
let length = vm.registers[5].cast::<u64>() as usize;
trace!("IPC address: {:?}", mem_addr);
unsafe { LazyCell::<Executor>::get_mut(&mut EXECUTOR) }
.unwrap()
.send_buffer(buffer_id as usize);
match buffer_id {
0 => match sds_msg_handler(vm, mem_addr, length) {
Ok(()) => {}
@ -246,12 +250,22 @@ pub fn handler(vm: &mut Vm, pid: &usize) {
// Wait till interrupt
use crate::kmain::EXECUTOR;
let interrupt_type = vm.registers[3].cast::<u8>();
info!("Interrupt subscribled: {}", interrupt_type);
debug!("Interrupt subscribed: {}", interrupt_type);
unsafe {
EXECUTOR.pause(pid.clone());
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
.unwrap()
.interrupt_subscribe(pid.clone(), interrupt_type);
.interrupt_subscribe(*pid, interrupt_type);
}
}
7 => {
// Wait till buffer
use crate::kmain::EXECUTOR;
let buffer_id = vm.registers[3].cast::<u64>() as usize;
debug!("Buffer subscribed: {}", buffer_id);
unsafe {
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
.unwrap()
.buffer_subscribe(*pid, buffer_id);
}
}
_ => {

View file

@ -1,5 +1,9 @@
use {
alloc::{boxed::Box, sync::Arc},
alloc::{
boxed::Box,
collections::{BTreeMap, BTreeSet},
sync::Arc,
},
core::{
future::Future,
pin::Pin,
@ -36,6 +40,7 @@ pub struct Executor {
tasks: Slab<Task>,
task_queue: Arc<SegQueue<usize>>,
interrupt_lookup: [Option<usize>; u8::MAX as usize],
buffer_lookup: BTreeMap<usize, BTreeSet<usize>>,
}
impl Executor {
@ -44,6 +49,7 @@ impl Executor {
tasks: Slab::new(),
task_queue: Arc::new(SegQueue::new()),
interrupt_lookup: [None; u8::MAX as usize],
buffer_lookup: BTreeMap::new(),
}
}
@ -67,10 +73,20 @@ impl Executor {
}
}
pub fn interrupt_subscribe(&mut self, pid : usize, interrupt_type: u8){
pub fn interrupt_subscribe(&mut self, pid: usize, interrupt_type: u8) {
self.pause(pid);
self.interrupt_lookup[interrupt_type as usize] = Some(pid);
}
pub fn buffer_subscribe(&mut self, pid: usize, buffer_id: usize) {
self.pause(pid);
if let Some(buf) = self.buffer_lookup.get_mut(&buffer_id) {
buf.insert(pid);
} else {
self.buffer_lookup.insert(buffer_id, BTreeSet::from([pid]));
}
}
pub fn run(&mut self) {
let mut task_batch = [0; 32];
loop {
@ -85,7 +101,7 @@ impl Executor {
}
if batch_len == 0 {
//break;
// break;
continue;
}
@ -100,26 +116,34 @@ impl Executor {
if let Poll::Ready(()) = task.poll(&mut cx) {
self.tasks.remove(id);
self.interrupt_lookup.map(|pid|{
if let Some(pid) = pid{
self.interrupt_lookup.map(|pid| {
if let Some(pid) = pid {
if pid == id {
return None;
}
}
return pid;
});
self.buffer_lookup.iter_mut().for_each(|(_, pid_set)| {
pid_set.remove(&id);
});
}
}
}
}
}
pub fn send_interrupt(&self, interrupt : u8){
pub fn send_interrupt(&self, interrupt: u8) {
let id = self.interrupt_lookup[interrupt as usize];
if let Some(id) = id{
if let Some(id) = id {
self.unpause(id);
}
}
pub fn send_buffer(&self, id: usize) {
if let Some(buf) = self.buffer_lookup.get(&id) {
buf.iter().for_each(|pid| self.unpause(*pid));
}
}
}
struct Task {

View file

@ -1,5 +1,9 @@
string := @use("string.hb")
$await := fn(buffer_id: uint): void {
return @eca(7, buffer_id)
}
$recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void {
return @eca(4, buffer_id, memory_map_location, @sizeof(Expr))
}

View file

@ -10,6 +10,7 @@ random := @use("random.hb")
file := @use("file_io.hb")
dt := @use("dt.hb")
process := @use("process.hb")
sleep := @use("sleep.hb")
panic := fn(message: ?^u8): never {
log.error("Error: Panic Called, Message:\0")

View file

@ -48,6 +48,8 @@ await_channel := fn(): Channel {
await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
response := @as(?Message(Expr), null)
loop {
// awaiting here causes flickering... idk why
buffer.await(buffer_id)
buffer.recv(?Message(Expr), buffer_id, &response)
if response != null {
return @as(Message(Expr), response)
@ -58,9 +60,11 @@ await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
await_header := fn(buffer_id: uint): MessageHeader {
response := @as(?MessageHeader, null)
loop {
// awaiting here causes flickering... idk why
buffer.await(buffer_id)
buffer.recv(?MessageHeader, buffer_id, &response)
if response != null {
return @as(?MessageHeader, response)
return @as(MessageHeader, response)
}
}
}

View file

@ -1 +0,0 @@
# alloc_test

View file

@ -1,11 +0,0 @@
[package]
name = "alloc_test"
authors = [""]
[dependants.libraries]
[dependants.binaries]
hblang.version = "1.0.0"
[build]
command = "hblang src/main.hb"

View file

@ -1 +0,0 @@
# dt_buffer_test

View file

@ -1,13 +0,0 @@
.{dt} := @use("../../../libraries/stn/src/lib.hb")
main := fn(): void {
dt.get(void, "framebuffer/fb0/width\0")
dt.get(void, "cpu/cpu0/architecture\0")
// Checking if the first detected serial port is memory mapped or port mapped
// 0 -> memory mapped
// 1 -> port mapped
dt.get(void, "serial_ports/sp0/mapping\0")
return
}

View file

@ -1,11 +0,0 @@
[package]
name = "hash_test"
authors = [""]
[dependants.libraries]
[dependants.binaries]
hblang.version = "1.0.0"
[build]
command = "hblang src/main.hb"

View file

@ -1,11 +0,0 @@
[package]
name = "processes"
authors = ["koniifer"]
[dependants.libraries]
[dependants.binaries]
hblang.version = "1.0.0"
[build]
command = "hblang src/main.hb"

View file

@ -1,11 +0,0 @@
[package]
name = "serial_driver_test"
authors = ["able"]
[dependants.libraries]
[dependants.binaries]
hblang.version = "1.0.0"
[build]
command = "hblang src/main.hb"

View file

@ -1,20 +0,0 @@
.{string, buffer} := @use("../../../libraries/stn/src/lib.hb")
log_info := fn(): void {
a := buffer.search("XNumber\0")
if a == 0 {
} else {
msg := "XABC\0"
// inline is broked
// msg_length := @inline(string.length, msg)
msg_length := 5
@as(void, @eca(3, a, msg, msg_length))
}
return
}
main := fn(): int {
log_info()
return 0
}

View file

@ -91,8 +91,8 @@ main := fn(): int {
// Mouse cursor
{
render.put_filled_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR_DARKER)
render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR)
render.put_filled_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR_DARKER)
render.put_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR)
}
render.sync(screen)

View file

@ -1,6 +1,6 @@
[package]
name = "dt_buffer_test"
authors = ["able"]
name = "test"
authors = ["koniifer", "able"]
[dependants.libraries]

View file

@ -0,0 +1,7 @@
stn := @use("./tests/stn/lib.hb")
serial_driver := @use("./tests/serial_driver.hb")
main := fn(): uint {
// return serial_driver.test()
return stn.sleep.test()
}

View file

@ -0,0 +1,18 @@
.{string, buffer} := @use("../../../../libraries/stn/src/lib.hb")
log_info := fn(): void {
a := buffer.search("XNumber\0")
if a == 0 {
} else {
msg := "XABC\0"
msg_length := string.length(msg)
@eca(3, a, msg, msg_length)
}
return
}
test := fn(): uint {
log_info()
return 0
}

View file

@ -1,11 +1,11 @@
stn := @use("../../../libraries/stn/src/lib.hb");
stn := @use("../../../../../libraries/stn/src/lib.hb");
.{allocators, panic, log} := stn
AStruct := struct {
a_field: u8,
}
main := fn(): void {
test := fn(): uint {
// alloc := allocators.FakeAlloc.init()
// astruct := alloc.alloc(AStruct, 2)
// if astruct.ptr != null{
@ -26,5 +26,5 @@ main := fn(): void {
// log.info("Allocator functioned.\0")
// }
// balloc.dealloc(bstruct_ptr, AStruct, 2)
return
return 0
}

View file

@ -0,0 +1,18 @@
.{dt, memory, string, log} := @use("../../../../../libraries/stn/src/lib.hb")
test := fn(): uint {
buffer := memory.request_page(1)
log.info(string.display_int(dt.get(int, "framebuffer/fb0/width\0"), buffer, 10))
string.clear(buffer)
log.info(string.display_int(dt.get(int, "cpu/cpu0/architecture\0"), buffer, 10))
string.clear(buffer)
// 0 -> memory mapped
// 1 -> port mapped
log.info(string.display_int(dt.get(int, "serial_ports/sp0/mapping\0"), buffer, 10))
return 0
}

View file

@ -1,6 +1,6 @@
.{hashers, log, memory, string} := @use("../../../libraries/stn/src/lib.hb")
.{hashers, log, memory, string} := @use("../../../../../libraries/stn/src/lib.hb")
main := fn(): void {
test := fn(): uint {
buffer := memory.request_page(1)
target := "abcdefghijklmnop\0"
strings := [^u8].("abcdefshijklmnop\0", "abcdefghijklnnop\0", "abcdefshijklmnop\0", "abcdefghijklmnop\0", "abcdefghijflmnop\0", "dbcdefghijklmnop\0", "abcdefghijklmnop\0")
@ -28,4 +28,5 @@ main := fn(): void {
log.debug(string.display_int(@bitcast(d), buffer, 16))
string.clear(buffer)
}
return 0
}

View file

@ -0,0 +1,5 @@
hashers := @use("./hashers.hb")
allocators := @use("./allocators.hb")
sleep := @use("./sleep.hb")
dt := @use("./dt.hb")
process := @use("./process.hb")

View file

@ -1,8 +1,8 @@
.{process, log, string, memory} := @use("../../../libraries/stn/src/lib.hb")
.{process, log, string, memory} := @use("../../../../../libraries/stn/src/lib.hb")
exe := @embed("./hello_world_and_spin.hbf")
exe := @embed("./assets/hello_world_and_spin.hbf")
main := fn(): void {
test := fn(): uint {
buf := "\0\0\0\0\0\0\0"
loop {
log.info(
@ -16,4 +16,5 @@ main := fn(): void {
i := 0
loop if i == 1000000 break else i += 1
}
return 0
}

View file

@ -0,0 +1,8 @@
.{sleep, log} := @use("../../../../../libraries/stn/src/lib.hb")
test := fn(): uint {
log.info("BEFORE\0")
sleep.sleep_until_interrupt(32)
log.info("AFTER\0")
return 0
}

View file

@ -1,11 +0,0 @@
[package]
name = "timer_test"
authors = ["Talha Qamar"]
[dependants.libraries]
[dependants.binaries]
hblang.version = "1.0.0"
[build]
command = "hblang src/main.hb"

View file

@ -1,8 +0,0 @@
sleep := @use("../../../libraries/stn/src/sleep.hb")
log := @use("../../../libraries/stn/src/log.hb")
main := fn(): void {
log.info("BEFORE\0")
sleep.sleep_until_interrupt(32)
log.info("AFTER\0")
}

View file

@ -28,32 +28,26 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.horizon]
# path = "boot:///horizon.hbf"
# path = "boot:///ps2_mouse_driver.hbf"
# [boot.limine.ableos.modules.ps2_mouse_driver]
[boot.limine.ableos.modules.ps2_mouse_driver]
path = "boot:///ps2_mouse_driver.hbf"
# [boot.limine.ableos.modules.ps2_keyboard_driver]
# path = "boot:///ps2_keyboard_driver.hbf"
[boot.limine.ableos.modules.timer_test]
path = "boot:///timer_test.hbf"
[boot.limine.ableos.modules.sunset_client]
path = "boot:///sunset_client.hbf"
[boot.limine.ableos.modules.sunset_client_2]
path = "boot:///sunset_client_2.hbf"
# [boot.limine.ableos.modules.sunset_client]
# path = "boot:///sunset_client.hbf"
#
# [boot.limine.ableos.modules.sunset_client_2]
# path = "boot:///sunset_client_2.hbf"
#
# [boot.limine.ableos.modules.sdoom]
# path = "boot:///sdoom.hbf"
#
# [boot.limine.ableos.modules.sunset_server]
# path = "boot:///sunset_server.hbf"
[boot.limine.ableos.modules.sunset_server]
path = "boot:///sunset_server.hbf"
# [boot.limine.ableos.modules.pcspkr]
# path = "boot:///pcspkr.hbf"
# [boot.limine.ableos.modules.alloc_test]
# path = "boot:///alloc_test.hbf"
# [boot.limine.ableos.modules.hash_test]
# path = "boot:///hash_test.hbf"
# [boot.limine.ableos.modules.test]
# path = "boot:///test.hbf"