stash to hold stuff till cargo fix
This commit is contained in:
parent
bbe2a0183a
commit
b47e8bd64c
164
ableos/Cargo.lock
generated
164
ableos/Cargo.lock
generated
|
@ -35,15 +35,22 @@ dependencies = [
|
|||
"lliw",
|
||||
"log",
|
||||
"pic8259",
|
||||
"picorand",
|
||||
"pretty-hex",
|
||||
"rkyv",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"shadeable",
|
||||
"smoltcp",
|
||||
"spin",
|
||||
"uart_16550",
|
||||
"unicode-width",
|
||||
"vga",
|
||||
"volatile 0.2.7",
|
||||
"wasmi",
|
||||
"watson",
|
||||
"x86_64",
|
||||
"y-compositor-protocol",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -82,6 +89,12 @@ version = "0.9.21"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a62c8f6168cd106687ee36a2b71a46c4144d73399f72814104d33094b8092fd2"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
|
@ -176,6 +189,15 @@ dependencies = [
|
|||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.12"
|
||||
|
@ -185,6 +207,12 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
|
@ -239,6 +267,12 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "managed"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d"
|
||||
|
||||
[[package]]
|
||||
name = "memory_units"
|
||||
version = "0.3.0"
|
||||
|
@ -312,6 +346,12 @@ dependencies = [
|
|||
"x86_64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "picorand"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6fc30519d2508c7e20e01da371cd27b1d4533fdb98e279955cb636b50210688"
|
||||
|
||||
[[package]]
|
||||
name = "pretty-hex"
|
||||
version = "0.2.1"
|
||||
|
@ -333,6 +373,26 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ptr_meta"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1"
|
||||
dependencies = [
|
||||
"ptr_meta_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ptr_meta_derive"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.14"
|
||||
|
@ -370,17 +430,84 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rkyv"
|
||||
version = "0.7.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49a37de5dfc60bae2d94961dacd03c7b80e426b66a99fa1b17799570dbdd8f96"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
"ptr_meta",
|
||||
"rkyv_derive",
|
||||
"seahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rkyv_derive"
|
||||
version = "0.7.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "719d447dd0e84b23cee6cb5b32d97e21efb112a3e3c636c8da36647b938475a1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "seahash"
|
||||
version = "4.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.133"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.133"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.75"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c059c05b48c5c0067d4b4b2b4f0732dd65feb52daf7e0ea09cd87e7dadc1af79"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shadeable"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"libm",
|
||||
"log",
|
||||
"rhai",
|
||||
"vga",
|
||||
]
|
||||
|
@ -400,6 +527,18 @@ dependencies = [
|
|||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smoltcp"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2308a1657c8db1f5b4993bab4e620bdbe5623bd81f254cf60326767bb243237"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
"log",
|
||||
"managed",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.5.2"
|
||||
|
@ -531,6 +670,22 @@ dependencies = [
|
|||
"parity-wasm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "watson"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cea7ead78c402dbf14e7f11911b0b48955ea13d46e012e2d98775e23c65d4ef"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"webassembly",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webassembly"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d1a10e1dedffff9cfcbdd33c289c65b87da634259a460a3f23d513649fa7a8c"
|
||||
|
||||
[[package]]
|
||||
name = "x86_64"
|
||||
version = "0.14.7"
|
||||
|
@ -541,3 +696,12 @@ dependencies = [
|
|||
"bitflags",
|
||||
"volatile 0.4.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "y-compositor-protocol"
|
||||
version = "0.1.1"
|
||||
source = "git+https://git.ablecorp.us/able/y-compositor-protocol.git#d3bcd0d41c712bfc4b4f0f9e7b5dd470e00c04a2"
|
||||
dependencies = [
|
||||
"rkyv",
|
||||
"serde",
|
||||
]
|
||||
|
|
|
@ -9,6 +9,8 @@ panic = "abort"
|
|||
|
||||
[package.metadata.bootimage]
|
||||
run-args = [
|
||||
"-cpu",
|
||||
"kvm64-v1",
|
||||
"-serial",
|
||||
"stdio",
|
||||
"-smp",
|
||||
|
@ -36,15 +38,45 @@ spin = "0.5.2"
|
|||
vga = "*"
|
||||
log= "*"
|
||||
pretty-hex = "0.2.1"
|
||||
|
||||
unicode-width = "0.1.7"
|
||||
picorand = "*"
|
||||
watson = "0.4"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "*"
|
||||
default-features = false
|
||||
features = ["derive", "alloc"]
|
||||
|
||||
[dependencies.serde_json]
|
||||
version = "*"
|
||||
default-features = false
|
||||
features = ["alloc"]
|
||||
|
||||
|
||||
|
||||
[dependencies.rkyv]
|
||||
version = "0.7.29"
|
||||
default-features = false
|
||||
features = ["size_64", "alloc"]
|
||||
|
||||
|
||||
[dependencies.smoltcp]
|
||||
version = "0.8.0"
|
||||
default-features = false
|
||||
features = ["log", "proto-ipv4"]
|
||||
|
||||
|
||||
|
||||
[dependencies.y-compositor-protocol]
|
||||
git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[dependencies.shadeable]
|
||||
path = "../shadeable"
|
||||
|
||||
|
||||
|
||||
[dependencies.ab_glyph]
|
||||
default-features = false
|
||||
features = ["libm"]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
&[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
|
|
6
ableos/assets/kernel_config.json
Normal file
6
ableos/assets/kernel_config.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"logging_level": "Trace",
|
||||
"run_tests": false,
|
||||
"run_demos": false,
|
||||
"run_shader_tests": true
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
#![allow(clippy::print_literal)]
|
||||
// #![allow(clippy::print_literal)]
|
||||
use crate::logger;
|
||||
|
||||
use super::{gdt, interrupts};
|
||||
|
||||
/// x86_64 initialization
|
||||
pub fn init() {
|
||||
let result = logger::init();
|
||||
match result {
|
||||
|
@ -13,5 +14,4 @@ pub fn init() {
|
|||
interrupts::init_idt();
|
||||
unsafe { interrupts::PICS.lock().initialize() };
|
||||
x86_64::instructions::interrupts::enable();
|
||||
info!("Initialized");
|
||||
}
|
||||
|
|
52
ableos/src/boot_conf.rs
Normal file
52
ableos/src/boot_conf.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
use log::LevelFilter;
|
||||
use serde::{de::value::BoolDeserializer, Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Debug, Deserialize)]
|
||||
pub enum LogLevel {
|
||||
/// A level lower than all log levels.
|
||||
Off,
|
||||
/// Corresponds to the `Error` log level.
|
||||
Error,
|
||||
/// Corresponds to the `Warn` log level.
|
||||
Warn,
|
||||
/// Corresponds to the `Info` log level.
|
||||
Info,
|
||||
/// Corresponds to the `Debug` log level.
|
||||
Debug,
|
||||
/// Corresponds to the `Trace` log level.
|
||||
Trace,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, Deserialize)]
|
||||
pub struct BootConfig {
|
||||
pub logging_level: LogLevel,
|
||||
|
||||
pub run_tests: bool,
|
||||
pub run_demos: bool,
|
||||
pub run_shader_tests: bool,
|
||||
}
|
||||
|
||||
impl BootConfig {
|
||||
pub fn new() -> Self {
|
||||
let data = include_str!("../assets/kernel_config.json");
|
||||
|
||||
// Parse the string of data into a Person object. This is exactly the
|
||||
// same function as the one that produced serde_json::Value above, but
|
||||
// now we are asking it for a Person as output.
|
||||
let p: BootConfig = serde_json::from_str(data).unwrap();
|
||||
info!("{:?}", p);
|
||||
p
|
||||
}
|
||||
|
||||
pub fn log_level(&self) -> LevelFilter {
|
||||
use LevelFilter::*;
|
||||
match self.logging_level {
|
||||
LogLevel::Off => Off,
|
||||
LogLevel::Error => Error,
|
||||
LogLevel::Warn => Warn,
|
||||
LogLevel::Info => Info,
|
||||
LogLevel::Debug => Debug,
|
||||
LogLevel::Trace => Trace,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,23 @@
|
|||
use alloc::{boxed::Box, vec, vec::Vec};
|
||||
use shadeable::pixel_format::{new_rgba64, Rgba64};
|
||||
use vga::{colors::Color16, writers::GraphicsWriter};
|
||||
|
||||
use crate::vga_e::VGAE;
|
||||
use alloc::{boxed::Box, vec, vec::Vec};
|
||||
use shadeable::{
|
||||
evaluate_shader,
|
||||
pixel_format::{new_rgba64, Rgba64},
|
||||
};
|
||||
use spin;
|
||||
use vga::{colors::Color16, writers::GraphicsWriter};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ScreenSize {
|
||||
pub x: usize,
|
||||
pub y: usize,
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref SCREEN_BUFFER: spin::Mutex<ScreenBuffer> = spin::Mutex::new(ScreenBuffer::new(640, 480));
|
||||
|
||||
}
|
||||
|
||||
impl ScreenSize {
|
||||
pub fn new(x: usize, y: usize) -> Self {
|
||||
Self { x, y }
|
||||
|
@ -35,6 +44,20 @@ impl ScreenBuffer {
|
|||
buff: vec![0u64; x * y].into_boxed_slice(),
|
||||
}
|
||||
}
|
||||
pub fn draw_filled_circle(&mut self, cx: i32, cy: i32, radius: usize, color: Rgba64) {
|
||||
let r = radius as i32 * 2;
|
||||
for y in 0..640 {
|
||||
for x in 0..480 {
|
||||
let dx = cx - x as i32 * 2 - 1;
|
||||
let dy = cy - y as i32 * 2 - 1;
|
||||
|
||||
if dx * dx + dy * dy <= r * r {
|
||||
self.set_pixel(x, y, color);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_pixel(&mut self, x: usize, y: usize, color: Rgba64) {
|
||||
self.buff[y * self.size.x + x] = color;
|
||||
|
@ -45,7 +68,67 @@ impl ScreenBuffer {
|
|||
}
|
||||
|
||||
pub fn blit(&mut self, _width: usize, _height: usize) {}
|
||||
pub fn draw_filled_rect(&mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: Rgba64) {
|
||||
for y in y1..y2 {
|
||||
for x in x1..x2 {
|
||||
self.set_pixel(x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn draw_unfilled_rect(
|
||||
&mut self,
|
||||
x1: usize,
|
||||
y1: usize,
|
||||
x2: usize,
|
||||
y2: usize,
|
||||
color: Rgba64,
|
||||
) {
|
||||
// x1 y1 => x2 y1 => x2 y2 => x1 y2 => x1 y1
|
||||
self.draw_line(x1, y1, x2, y1, color);
|
||||
self.draw_line(x2, y1, x2, y2, color);
|
||||
self.draw_line(x2, y2, x1, y2, color);
|
||||
self.draw_line(x1, y2, x1, y1, color);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn draw_line(&mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: Rgba64) {
|
||||
let x = crate::graphics::get_coordinates(
|
||||
x1.try_into().unwrap(),
|
||||
y1.try_into().unwrap(),
|
||||
x2.try_into().unwrap(),
|
||||
y2.try_into().unwrap(),
|
||||
);
|
||||
|
||||
for coord in x {
|
||||
self.set_pixel(coord.0, coord.1, color);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shade(&mut self) {
|
||||
for y in 0..100 {
|
||||
for x in 0..100 {
|
||||
let rgba_ret = evaluate_shader(x, y, self.buff[y * self.size.x + x]);
|
||||
match rgba_ret {
|
||||
Ok(pixel) => {
|
||||
// info!("{:?}", pixel);
|
||||
self.set_pixel(x, y, pixel);
|
||||
}
|
||||
|
||||
Err(err) => error!("{}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info!("Shaders done");
|
||||
}
|
||||
|
||||
// TODO force clear
|
||||
pub fn force_redraw(&mut self) {
|
||||
use shadeable::pixel_format::into_vga_16;
|
||||
VGAE.lock().clear_screen(into_vga_16(self.clear_color));
|
||||
}
|
||||
}
|
||||
|
||||
pub trait VgaBuffer {
|
||||
fn copy_to_buffer(&self) -> GraphicsReturn;
|
||||
}
|
||||
|
@ -55,12 +138,58 @@ impl VgaBuffer for ScreenBuffer {
|
|||
for y in 0..self.size.y {
|
||||
for x in 0..self.size.x {
|
||||
use shadeable::pixel_format::{get_color16, into_vga_16};
|
||||
let vga_color = get_color16(self.buff[y * self.size.x + x]);
|
||||
// let vga_color = into_vga_16(self.buff[y * self.size.x + x]);
|
||||
// let vga_color = get_color16(self.buff[y * self.size.x + x]);
|
||||
|
||||
let vga_color = into_vga_16(self.buff[y * self.size.x + x]);
|
||||
|
||||
if into_vga_16(self.clear_color) != vga_color {
|
||||
mode.set_pixel(x, y, vga_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GraphicsReturn::Ok
|
||||
}
|
||||
}
|
||||
pub fn get_coordinates(x1: i32, y1: i32, x2: i32, y2: i32) -> Vec<(usize, usize)> {
|
||||
let mut coordinates: Vec<(usize, usize)> = vec![];
|
||||
let dx: i32 = i32::abs(x2 - x1);
|
||||
let dy: i32 = i32::abs(y2 - y1);
|
||||
let sx: i32 = {
|
||||
if x1 < x2 {
|
||||
1
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
};
|
||||
let sy: i32 = {
|
||||
if y1 < y2 {
|
||||
1
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
};
|
||||
let mut error: i32 = (if dx > dy { dx } else { -dy }) / 2;
|
||||
let mut current_x: i32 = x1;
|
||||
let mut current_y: i32 = y1;
|
||||
loop {
|
||||
coordinates.push((current_x as usize, current_y as usize));
|
||||
// info!("0 {:?}", (current_x, current_y));
|
||||
|
||||
if current_x == x2 && current_y == y2 {
|
||||
break;
|
||||
}
|
||||
|
||||
let error2: i32 = error;
|
||||
|
||||
if error2 > -dx {
|
||||
error -= dy;
|
||||
current_x += sx;
|
||||
}
|
||||
if error2 < dy {
|
||||
error += dx;
|
||||
current_y += sy;
|
||||
}
|
||||
}
|
||||
coordinates
|
||||
}
|
||||
|
|
|
@ -1,40 +1,32 @@
|
|||
#![allow(clippy::empty_loop)]
|
||||
|
||||
// use std::println;
|
||||
|
||||
use alloc::format;
|
||||
|
||||
use shadeable::pixel_format::{from_vga_16, into_vga_16, new_rgba64};
|
||||
use vga::{colors::Color16, writers::GraphicsWriter};
|
||||
|
||||
use crate::{
|
||||
graphics::VgaBuffer,
|
||||
relib::network::socket::{SimpleSock, SocketReturns},
|
||||
vga_e::{self, num_to_vga16, VGAE},
|
||||
};
|
||||
|
||||
use log::*;
|
||||
|
||||
use {
|
||||
crate::{
|
||||
arch::{drivers::graphics::GraphicsBuffer, init, sloop},
|
||||
driver_traits::graphics::Graphics,
|
||||
arch::{init, sloop},
|
||||
boot_conf,
|
||||
experiments::{
|
||||
info::master,
|
||||
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
||||
},
|
||||
|
||||
graphics::ScreenBuffer,
|
||||
// log::LOG_STATE,
|
||||
graphics::{VgaBuffer, SCREEN_BUFFER},
|
||||
relib::math::rand::RAND_HANDLE,
|
||||
relib::network::socket::Socket,
|
||||
relib::network::socket::{SimpleSock, SocketReturns},
|
||||
scheduler::{test_fn, Thread, ThreadList},
|
||||
vga_e::{self, num_to_vga16},
|
||||
},
|
||||
alloc::{
|
||||
format,
|
||||
string::{String, ToString},
|
||||
vec,
|
||||
},
|
||||
core::sync::atomic::{AtomicU64, Ordering::*},
|
||||
lazy_static::lazy_static,
|
||||
log::*,
|
||||
picorand::PicoRandGenerate,
|
||||
rkyv::{ser::serializers::AllocSerializer, Deserialize},
|
||||
shadeable::pixel_format::from_vga_16,
|
||||
y_compositor_protocol::Version,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -48,38 +40,113 @@ pub extern "C" fn stack_overflow() -> u8 {
|
|||
lazy_static! {
|
||||
pub static ref KEY_BUFFER: spin::Mutex<String> = spin::Mutex::new("".to_string());
|
||||
pub static ref THREAD_LIST: spin::Mutex<ThreadList> = spin::Mutex::new(vec![]);
|
||||
pub static ref TICK: spin::Mutex<u64> = spin::Mutex::new(0);
|
||||
pub static ref TICK: AtomicU64 = AtomicU64::new(0);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn kernel_main() -> ! {
|
||||
let boot_conf = boot_conf::BootConfig::new();
|
||||
|
||||
init::init();
|
||||
log::set_max_level(boot_conf.log_level());
|
||||
// info!("Initialized");
|
||||
|
||||
log::set_max_level(LevelFilter::Trace);
|
||||
// crate::wasm::evaluate();
|
||||
graphics_pipe_startup();
|
||||
|
||||
let mut abcde = ScreenBuffer::new(640, 480);
|
||||
// abcde.clear();
|
||||
// abcde.copy_to_buffer();
|
||||
|
||||
VGAE.lock().clear_screen(Color16::Black);
|
||||
|
||||
trace!("length of screen buffer {}", abcde.buff.len());
|
||||
trace!("Screen size {:?}", abcde.size);
|
||||
|
||||
for y in 0..480 {
|
||||
for x in 0..640 {
|
||||
let segment_x = x * 4 / 640;
|
||||
let segment_y = y * 4 / 480;
|
||||
let segment = segment_x + segment_y * 4;
|
||||
|
||||
abcde.set_pixel(x, y, from_vga_16(num_to_vga16(segment as u8)));
|
||||
}
|
||||
}
|
||||
|
||||
// abcde.copy_to_buffer();
|
||||
/*
|
||||
|
||||
{
|
||||
let mut proc_1 = SimpleSock::new();
|
||||
proc_1.register_protocol("ProcSpawner".to_string());
|
||||
|
||||
let version = 0;
|
||||
use rkyv::ser::Serializer;
|
||||
let mut serializer = AllocSerializer::<0>::default();
|
||||
serializer.serialize_value(&version).unwrap();
|
||||
|
||||
let bytes = serializer.into_serializer().into_inner();
|
||||
proc_1.write(bytes.into_vec());
|
||||
unsafe {
|
||||
let the_bytes = proc_1.read(3).unwrap();
|
||||
let archived = rkyv::archived_root::<Version>(&the_bytes);
|
||||
let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap();
|
||||
// trace!("{:?}", deserialized);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
let mut graphics = SCREEN_BUFFER.lock();
|
||||
graphics.force_redraw();
|
||||
graphics.clear();
|
||||
|
||||
graphics.draw_filled_circle(100, 100, 5, 0x9900ff00);
|
||||
screen_writer_test();
|
||||
|
||||
graphics.copy_to_buffer();
|
||||
|
||||
if boot_conf.run_tests {
|
||||
// quick and dirty testing framework
|
||||
socket_test();
|
||||
graphics_pipe_test();
|
||||
socket_startup_rng();
|
||||
socket_test_rng();
|
||||
}
|
||||
|
||||
if boot_conf.run_demos {
|
||||
graphics_api_demo();
|
||||
}
|
||||
|
||||
if boot_conf.run_shader_tests {
|
||||
shader_tests();
|
||||
}
|
||||
|
||||
// graphics.copy_to_buffer();
|
||||
|
||||
// info!("buffer copied");
|
||||
|
||||
sloop()
|
||||
}
|
||||
|
||||
/// called by arch specific timers to tick up all kernel related functions
|
||||
pub fn tick() {
|
||||
let mut data = TICK.load(Relaxed);
|
||||
data += 1;
|
||||
|
||||
RAND_HANDLE.lock().seed_entropy_timer(data);
|
||||
|
||||
crate::kernel_state::KERNEL_STATE.lock().update_state();
|
||||
TICK.store(data, Relaxed)
|
||||
}
|
||||
|
||||
pub fn key_entropy(key: u8) {
|
||||
RAND_HANDLE.lock().seed_entropy_keyboard(key);
|
||||
}
|
||||
|
||||
pub fn test_threads() {
|
||||
let mut a_thread = Thread::new();
|
||||
|
||||
a_thread.new_task(test_fn);
|
||||
a_thread.new_task(test_fn);
|
||||
THREAD_LIST.lock().push(a_thread);
|
||||
}
|
||||
|
||||
pub fn cpu_socket_startup() {
|
||||
let mut cpu_info_socket = SimpleSock::new();
|
||||
cpu_info_socket.register_protocol("CPU_INFO".to_string());
|
||||
|
||||
let x = master().unwrap();
|
||||
let xyz = x.brand_string().unwrap();
|
||||
}
|
||||
|
||||
pub fn log_version_data() {
|
||||
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
||||
info!(
|
||||
"Brand String: {:?}",
|
||||
master().unwrap().brand_string().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
pub fn socket_test() {
|
||||
let mut xyz = SimpleSock::new();
|
||||
|
||||
xyz.peek();
|
||||
|
@ -102,17 +169,46 @@ pub fn kernel_main() -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn socket_test_rng() {
|
||||
let mut test_sock = SimpleSock::grab_socket("RNGProvider".to_string()).unwrap();
|
||||
info!(
|
||||
"Recieving {} from protocol {}",
|
||||
test_sock.read(1).unwrap()[0],
|
||||
test_sock.protocol().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
pub fn socket_startup_rng() {
|
||||
use picorand::{WyRand, RNG};
|
||||
let mut random_socket = SimpleSock::new();
|
||||
|
||||
random_socket.register_protocol("RNGProvider".to_string());
|
||||
let bruh = TICK.load(core::sync::atomic::Ordering::Relaxed);
|
||||
|
||||
let mut rng = RNG::<WyRand, u8>::new(bruh);
|
||||
|
||||
for _ in 0..512 {
|
||||
let x = rng.generate();
|
||||
random_socket.write(vec![x]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn screen_writer_test() {
|
||||
let mut sock_print_id = SimpleSock::new();
|
||||
|
||||
{
|
||||
sock_print_id.write(format!("a原b画cフdァeイfル 集").into());
|
||||
// sock_print_id.write(format!("simple sockets are based").into());
|
||||
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
|
||||
}
|
||||
// crate::relib::image::mono_bitmap::bruh();
|
||||
sock_print_id.register_protocol("Screen Printer".to_string());
|
||||
|
||||
// sock_print_id.write(format!("a原 b画 cフ dァ eイ fル 集").into());
|
||||
sock_print_id.write(format!("λ³ Half Life 3 booting up ㎣").into());
|
||||
// sock_print_id.write(format!("Happy birthday 🎉").into());
|
||||
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
|
||||
|
||||
if true {
|
||||
let mut prev = None;
|
||||
|
||||
// let mut graphics = SCREEN_BUFFER.lock();
|
||||
// graphics.clear();
|
||||
// graphics.copy_to_buffer();
|
||||
|
||||
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() {
|
||||
vga_e::draw_char(prev, current, 0);
|
||||
|
||||
|
@ -120,61 +216,71 @@ pub fn kernel_main() -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
if false {
|
||||
draw_filled_circle(400, 350, 99, Color16::Black);
|
||||
// let _ = shadeable::evaluate_shader(1);
|
||||
pub fn vga_boot_screen() {
|
||||
let mut abcde = SCREEN_BUFFER.lock();
|
||||
|
||||
for y in 0..480 {
|
||||
for x in 0..640 {
|
||||
let segment_x = x * 4 / 640;
|
||||
let segment_y = y * 4 / 480;
|
||||
let segment = segment_x + segment_y * 4;
|
||||
|
||||
abcde.set_pixel(x, y, from_vga_16(num_to_vga16(segment as u8)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// abcde.clear();
|
||||
// abcde.copy_to_buffer();
|
||||
pub fn graphics_pipe_test() {
|
||||
let mut graphics_pipe = SimpleSock::grab_socket("YCompositor".to_string()).unwrap();
|
||||
|
||||
// stack_overflow();
|
||||
|
||||
sloop()
|
||||
}
|
||||
|
||||
/// called by arch specific timers to tick up all kernel related functions
|
||||
pub fn tick() {
|
||||
let mut data = TICK.lock();
|
||||
*data += 1;
|
||||
RAND_HANDLE.lock().seed_entropy_timer(*data);
|
||||
|
||||
// println!("{}", *data);
|
||||
crate::kernel_state::KERNEL_STATE.lock().update_state();
|
||||
}
|
||||
|
||||
pub fn key_entropy(key: u8) {
|
||||
RAND_HANDLE.lock().seed_entropy_keyboard(key);
|
||||
}
|
||||
|
||||
pub fn test_threads() {
|
||||
let mut a_thread = Thread::new();
|
||||
|
||||
a_thread.new_task(test_fn);
|
||||
a_thread.new_task(test_fn);
|
||||
THREAD_LIST.lock().push(a_thread);
|
||||
}
|
||||
|
||||
fn draw_filled_circle(cx: i32, cy: i32, radius: usize, color: Color16) {
|
||||
let vga = VGAE.lock();
|
||||
|
||||
let r = radius as i32 * 2;
|
||||
for y in 0..640 {
|
||||
for x in 0..480 {
|
||||
let dx = cx - x as i32 * 2 - 1;
|
||||
let dy = cy - y as i32 * 2 - 1;
|
||||
|
||||
if dx * dx + dy * dy <= r * r {
|
||||
vga.set_pixel(x, y, color);
|
||||
let version = Version {
|
||||
major: 13,
|
||||
minor: 123,
|
||||
patch: 0,
|
||||
};
|
||||
}
|
||||
use rkyv::ser::Serializer;
|
||||
let mut serializer = AllocSerializer::<0>::default();
|
||||
serializer.serialize_value(&version).unwrap();
|
||||
// let bytes = serializer.into_serializer().into_inner();
|
||||
|
||||
// info!("{:?}", bytes);
|
||||
let bytes = serializer.into_serializer().into_inner();
|
||||
graphics_pipe.write(bytes.into_vec());
|
||||
unsafe {
|
||||
let the_bytes = graphics_pipe.read(3).unwrap();
|
||||
let archived = rkyv::archived_root::<Version>(&the_bytes);
|
||||
let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap();
|
||||
trace!("{:?}", deserialized);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn log_version_data() {
|
||||
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
||||
info!(
|
||||
"Brand String: {:?}",
|
||||
master().unwrap().brand_string().unwrap()
|
||||
);
|
||||
pub fn graphics_pipe_startup() {
|
||||
let mut graphics_pipe = SimpleSock::new();
|
||||
|
||||
graphics_pipe.register_protocol("YCompositor".to_string());
|
||||
}
|
||||
|
||||
pub fn graphics_api_demo() {
|
||||
let mut abcde = SCREEN_BUFFER.lock();
|
||||
abcde.force_redraw();
|
||||
|
||||
abcde.draw_filled_circle(100, 100, 300, 0x0000ff00);
|
||||
abcde.draw_unfilled_rect(100, 100, 400, 200, 0xff000000);
|
||||
abcde.draw_filled_rect(300, 300, 400, 400, 0xff000000);
|
||||
abcde.draw_line(100, 100, 400, 200, 0xff000000);
|
||||
abcde.copy_to_buffer();
|
||||
}
|
||||
|
||||
pub fn shader_tests() {
|
||||
let mut graphics = SCREEN_BUFFER.lock();
|
||||
|
||||
graphics.clear();
|
||||
graphics.force_redraw();
|
||||
graphics.draw_filled_rect(25, 25, 50, 50, 0xff000000);
|
||||
graphics.set_pixel(50, 50, 0xffffff00);
|
||||
graphics.shade();
|
||||
|
||||
graphics.copy_to_buffer();
|
||||
|
||||
// drop(graphics)
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ pub mod print;
|
|||
pub extern crate log;
|
||||
|
||||
pub mod allocator;
|
||||
pub mod boot_conf;
|
||||
pub mod driver_traits;
|
||||
pub mod experiments;
|
||||
pub mod graphics;
|
||||
|
@ -40,10 +41,9 @@ pub mod keyboard;
|
|||
pub mod kmain;
|
||||
pub mod logger;
|
||||
pub mod panic;
|
||||
pub mod proc;
|
||||
pub mod relib;
|
||||
pub mod scheduler;
|
||||
pub mod wasm;
|
||||
|
||||
mod unicode_utils;
|
||||
pub mod utils;
|
||||
|
||||
|
|
|
@ -21,13 +21,14 @@ impl log::Log for SimpleLogger {
|
|||
log::Level::Debug => color = (Fg::Blue, "$BLUE$"),
|
||||
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"),
|
||||
}
|
||||
|
||||
/*
|
||||
println!(
|
||||
"[{}{}$RESET$][$GREEN$FakeTempTime$RESET$] {}",
|
||||
color.1,
|
||||
record.level(),
|
||||
record.args()
|
||||
);
|
||||
*/
|
||||
serial_println!(
|
||||
"[{}{}{}][{}FakeTempTime{}] {}",
|
||||
color.0,
|
||||
|
|
5
ableos/src/proc.rs
Normal file
5
ableos/src/proc.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
use crate::relib::clparse::Command;
|
||||
|
||||
pub struct ProccessStart {
|
||||
command: Command,
|
||||
}
|
6
ableos/src/relib/encoding/bin.rs
Normal file
6
ableos/src/relib/encoding/bin.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use alloc::{boxed::Box, vec::Vec};
|
||||
use core::result;
|
||||
|
||||
pub struct BinCodeWriter {
|
||||
pub stream: Box<u8>,
|
||||
}
|
|
@ -1 +1,2 @@
|
|||
pub mod bin;
|
||||
pub mod rle;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,11 +1,25 @@
|
|||
use alloc::string::String;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
pub type Stream = Vec<u8>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SocketID {
|
||||
pub id: usize,
|
||||
}
|
||||
|
||||
impl SocketID {
|
||||
pub fn protocol(self) -> Option<String> {
|
||||
let x = SOCKETS.lock()[self.id].protocol.clone();
|
||||
|
||||
match x {
|
||||
Some(protocol_name) => Some(protocol_name),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Socket for SocketID {
|
||||
fn peek(&mut self) -> SocketReturns {
|
||||
SOCKETS.lock()[self.id].peek()
|
||||
|
@ -18,6 +32,13 @@ impl Socket for SocketID {
|
|||
fn write(&mut self, stream: Stream) -> SocketReturns {
|
||||
SOCKETS.lock()[self.id].write(stream)
|
||||
}
|
||||
fn register_protocol(&mut self, protocol_name: String) {
|
||||
SOCKETS.lock()[self.id].protocol = Some(protocol_name);
|
||||
}
|
||||
|
||||
fn check_protocol(&mut self, protocol_name: String) -> bool {
|
||||
SOCKETS.lock()[self.id].check_protocol(protocol_name)
|
||||
}
|
||||
}
|
||||
|
||||
pub type SocketState = Vec<SimpleSock>;
|
||||
|
@ -25,7 +46,6 @@ pub type SocketState = Vec<SimpleSock>;
|
|||
lazy_static::lazy_static! {
|
||||
pub static ref SOCKETS: spin::Mutex<SocketState> = spin::Mutex::new(vec![]);
|
||||
}
|
||||
|
||||
pub trait Socket {
|
||||
fn peek(&mut self) -> SocketReturns;
|
||||
|
||||
|
@ -33,6 +53,9 @@ pub trait Socket {
|
|||
fn read(&mut self, length: usize) -> SocketReturns;
|
||||
|
||||
fn write(&mut self, stream: Stream) -> SocketReturns;
|
||||
fn register_protocol(&mut self, protocol_name: String);
|
||||
fn check_protocol(&mut self, protocol_name: String) -> bool;
|
||||
|
||||
fn close(&mut self) {}
|
||||
}
|
||||
#[derive(Debug)]
|
||||
|
@ -54,11 +77,15 @@ impl SocketReturns {
|
|||
|
||||
pub struct SimpleSock {
|
||||
stream: Vec<u8>,
|
||||
protocol: Option<String>,
|
||||
}
|
||||
|
||||
impl SimpleSock {
|
||||
pub fn new() -> SocketID {
|
||||
let sock = SimpleSock { stream: vec![] };
|
||||
let sock = SimpleSock {
|
||||
stream: vec![],
|
||||
protocol: None,
|
||||
};
|
||||
let mut sock_lock = SOCKETS.lock();
|
||||
sock_lock.push(sock);
|
||||
|
||||
|
@ -69,6 +96,23 @@ impl SimpleSock {
|
|||
pub fn regrab_sock(id: usize) -> SocketID {
|
||||
SocketID { id }
|
||||
}
|
||||
|
||||
pub fn grab_socket(protocol_name: String) -> Option<SocketID> {
|
||||
let socket_handle = SOCKETS.lock();
|
||||
let socket_count = socket_handle.len();
|
||||
drop(socket_handle);
|
||||
|
||||
let return_sock = None;
|
||||
for socket_id in 0..socket_count {
|
||||
let mut id = SimpleSock::regrab_sock(socket_id);
|
||||
|
||||
if id.check_protocol(protocol_name.clone()) {
|
||||
return Some(id);
|
||||
}
|
||||
}
|
||||
|
||||
return_sock
|
||||
}
|
||||
}
|
||||
|
||||
impl Socket for SimpleSock {
|
||||
|
@ -92,6 +136,16 @@ impl Socket for SimpleSock {
|
|||
SocketReturns::ReadOk(return_vec)
|
||||
}
|
||||
}
|
||||
fn register_protocol(&mut self, protocol_name: String) {
|
||||
self.protocol = Some(protocol_name);
|
||||
}
|
||||
fn check_protocol(&mut self, protocol_name: String) -> bool {
|
||||
if self.protocol == Some(protocol_name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
fn write(&mut self, stream: Stream) -> SocketReturns {
|
||||
for byte in stream {
|
||||
self.stream.push(byte);
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
use alloc::string::ToString;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use {
|
||||
ab_glyph::{Font, FontRef, Glyph},
|
||||
vga::{
|
||||
|
@ -19,10 +16,6 @@ lazy_static::lazy_static! {
|
|||
pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
|
||||
}
|
||||
|
||||
pub trait GraphicsAPI {
|
||||
fn add_shader() {}
|
||||
}
|
||||
|
||||
pub fn draw_char(previous_character: Option<char>, character: char, _offset: usize) {
|
||||
let mode = *VGAE.lock();
|
||||
let mut offset_x = VGAE_BUFF_OFFSET_X.lock();
|
||||
|
@ -82,7 +75,7 @@ pub fn draw_char(previous_character: Option<char>, character: char, _offset: usi
|
|||
{
|
||||
// figure it our latter bruh
|
||||
let spacing = used_font.kern_unscaled(previous_glyph.id, q_glyph.id);
|
||||
info!("{spacing} {:?} {:?}", previous_glyph.id, q_glyph.id);
|
||||
// info!("{spacing} {:?} {:?}", previous_glyph.id, q_glyph.id);
|
||||
q_glyph.position.x += spacing * font_scale;
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,117 +0,0 @@
|
|||
use alloc::string::String;
|
||||
|
||||
use {
|
||||
alloc::format,
|
||||
wasm_sys::SysCall,
|
||||
wasmi::{
|
||||
Error, Externals, FuncInstance, FuncRef, ImportsBuilder, ModuleImportResolver,
|
||||
ModuleInstance, RuntimeArgs, RuntimeValue, Signature, Trap, TrapKind, ValueType,
|
||||
},
|
||||
};
|
||||
|
||||
mod wasm_sys;
|
||||
struct HostFunctions;
|
||||
impl HostFunctions {
|
||||
fn check_signature(&self, index: usize, signature: &Signature) -> bool {
|
||||
let (params, ret_ty): (&[ValueType], Option<ValueType>) = match index.into() {
|
||||
SysCall::KILL => (&[], None),
|
||||
SysCall::EMPTY => (&[], None),
|
||||
_ => return false,
|
||||
};
|
||||
signature.params() == params && signature.return_type() == ret_ty
|
||||
}
|
||||
}
|
||||
impl Externals for HostFunctions {
|
||||
fn invoke_index(
|
||||
&mut self,
|
||||
index: usize,
|
||||
args: RuntimeArgs,
|
||||
) -> Result<Option<RuntimeValue>, Trap> {
|
||||
match index.into() {
|
||||
// Take in one arg discard the rest
|
||||
SysCall::KILL => {
|
||||
info!("Program run at runtime called a system call");
|
||||
debug!("Runtime arguments: {:?}", args);
|
||||
Ok(None)
|
||||
}
|
||||
// Do nothing
|
||||
SysCall::EMPTY => Ok(None),
|
||||
SysCall::EXIT => Ok(None),
|
||||
SysCall::CONSOLE_RESET => Ok(None),
|
||||
SysCall::CONSOLE_IN => {
|
||||
info!("In");
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
SysCall::CONSOLE_OUT => {
|
||||
// Eventually change this to 2- ptr and len
|
||||
if args.len() != 1 {
|
||||
return Err(Trap::new(TrapKind::UnexpectedSignature));
|
||||
}
|
||||
let arg: u64 = args.nth(0);
|
||||
let buf = unsafe { String::from_utf8_unchecked(arg.to_le_bytes().to_vec()) };
|
||||
println!["{}", buf];
|
||||
Ok(None)
|
||||
}
|
||||
SysCall::CONSOLE_GET_TITLE => Ok(None),
|
||||
SysCall::CONSOLE_SET_TITLE => Ok(None),
|
||||
_ => panic!("Unimplemented function at {}", index),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ModuleImportResolver for HostFunctions {
|
||||
fn resolve_func(&self, field_name: &str, signature: &Signature) -> Result<FuncRef, Error> {
|
||||
let index = match field_name {
|
||||
"kill" => SysCall::KILL as usize,
|
||||
"empty" => SysCall::EMPTY as usize,
|
||||
"exit" => SysCall::EXIT as usize,
|
||||
"console_out" => SysCall::CONSOLE_OUT as usize,
|
||||
_ => {
|
||||
return Err(Error::Instantiation(format!(
|
||||
"Export {} not found",
|
||||
field_name
|
||||
)))
|
||||
}
|
||||
};
|
||||
|
||||
if !self.check_signature(index, signature) {
|
||||
return Err(Error::Instantiation(format!(
|
||||
"Export {} has a bad signature",
|
||||
field_name
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(FuncInstance::alloc_host(
|
||||
Signature::new(&[][..], None),
|
||||
index,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn evaluate() {
|
||||
// let wasm_binary = include_bytes!("bin/console_out_test.wasm");
|
||||
let wasm_binary = include_bytes!("bin/rust.wasm");
|
||||
|
||||
// Load wasm binary and prepare it for instantiation.
|
||||
let module = wasmi::Module::from_buffer(&wasm_binary).expect("failed to load wasm");
|
||||
|
||||
let imports = ImportsBuilder::new().with_resolver("env", &HostFunctions);
|
||||
|
||||
// Instantiate a module with empty imports and
|
||||
// assert that there is no `start` function.
|
||||
let instance = ModuleInstance::new(&module, &imports)
|
||||
// .expect("failed to instantiate wasm module")
|
||||
.unwrap()
|
||||
.assert_no_start();
|
||||
|
||||
// Finally, invoke the exported function "test" with no parameters
|
||||
// and empty external function executor.
|
||||
let result: i32 = instance
|
||||
.invoke_export("_start", &[], &mut HostFunctions)
|
||||
.expect("failed to execute export")
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
|
||||
println!("{:?}", result);
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
#![allow(non_camel_case_types)]
|
||||
|
||||
macro_rules! syscall_enum {
|
||||
() => {};
|
||||
(@get_last $Variant:ident) => {
|
||||
Self::$Variant
|
||||
};
|
||||
(@get_last $Variant:ident, $($VariantTail:ident),*) => {
|
||||
syscall_enum![@get_last $($VariantTail),*]
|
||||
};
|
||||
($($Variant:ident=$Value:expr,)*) => {
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[repr(usize)]
|
||||
pub enum SysCall {
|
||||
$($Variant = $Value),*
|
||||
}
|
||||
|
||||
impl core::convert::From<usize> for SysCall {
|
||||
fn from(n: usize) -> Self {
|
||||
match n {
|
||||
$($Value => Self::$Variant),*,
|
||||
_ => syscall_enum![@get_last $($Variant),*]
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
($($Variant:ident=$Value:expr),* ) => {
|
||||
syscall_enum!($($Variant=$Value,)* );
|
||||
};
|
||||
}
|
||||
syscall_enum! {
|
||||
KILL=0, // Provide a PID
|
||||
CONSOLE_RESET=1, // Reset the console
|
||||
CONSOLE_IN=2, // Console Input
|
||||
CONSOLE_OUT=3, // Console output
|
||||
CONSOLE_GET_TITLE=4, // Get the console title
|
||||
CONSOLE_SET_TITLE=5, // Set the console title
|
||||
CONSOLE_GET_BAR=6,
|
||||
CONSOLE_SET_BAR=7,
|
||||
|
||||
//
|
||||
GET_HOSTNAME=10,
|
||||
SET_HOSTNAME=11,
|
||||
|
||||
|
||||
NEW_THREAD=12,
|
||||
NEW_TASK=13,
|
||||
KILL_THREAD=14,
|
||||
KILL_TASK=15,
|
||||
GET_THREAD=16,
|
||||
GET_TASK=17,
|
||||
SEND= 18,
|
||||
RECEIVE = 19,
|
||||
RESPOND = 20,
|
||||
|
||||
//File Related syscalls
|
||||
//
|
||||
MAKE_DIRECTORY=22, //
|
||||
DELETE_DIRECTORY=23, //
|
||||
RENAME_DIRECTORY=24, //
|
||||
SET_DIRECTORY_ACCESS=25, //
|
||||
//
|
||||
MAKE_FILE=26, //
|
||||
DELETE_FILE=27, //
|
||||
RENAME_FILE=28, //
|
||||
SET_FILE_ACCESS=29, //
|
||||
|
||||
FILE_READ=30,
|
||||
FILE_WRITE=31,
|
||||
|
||||
SLEEP=32, // Sleep in milliseconds
|
||||
SLEEP_UNTIL=33, // Sleep until this time in milliseconds (if this is below the current time return)
|
||||
NANOSLEEP=34, // Sleep in nanoseconds
|
||||
NANOSLEEP_UNTIL=35, // Sleep until this time nanoseconds (if this is below the current time return)
|
||||
GET_TIME=36, // Gets the system time (some derivitive of seconds)
|
||||
SET_TIME=37, // Sets the system time (some derivitive of seconds)
|
||||
|
||||
// Socket SysCall
|
||||
SOCKET_BIND=39, // Used by servers to lock a port
|
||||
SOCKET_CONNECT=40,
|
||||
SOCKET_DISCONNECT=41,
|
||||
SOCKET_SEND=42,
|
||||
SOCKET_RECEIVE=43,
|
||||
|
||||
|
||||
GET_PID=44, // Get the proccess ID
|
||||
PROCESS_INFO=45, // Get information about the process
|
||||
//scheduler Related Syscals
|
||||
GET_PRIORITY=46, // Get scheduler priority
|
||||
SET_PRIORITY=47, // Set scheduler priority
|
||||
|
||||
EXIT=50,
|
||||
EMPTY=0xFFFF,
|
||||
}
|
10
shadeable/Cargo.lock
generated
10
shadeable/Cargo.lock
generated
|
@ -143,6 +143,15 @@ dependencies = [
|
|||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "no-std-compat"
|
||||
version = "0.4.1"
|
||||
|
@ -228,6 +237,7 @@ name = "shadeable"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"libm",
|
||||
"log",
|
||||
"rhai",
|
||||
"vga",
|
||||
]
|
||||
|
|
|
@ -9,6 +9,7 @@ edition = "2021"
|
|||
|
||||
vga = "*"
|
||||
libm = "*"
|
||||
log ="*"
|
||||
|
||||
[dependencies.rhai]
|
||||
version = "*"
|
||||
|
|
|
@ -2,10 +2,17 @@ const VERSION = 0.5;
|
|||
|
||||
|
||||
fn main(){
|
||||
let abcd = RGBA(0, 33, 0, 0);
|
||||
|
||||
// print(rand_float());
|
||||
let abcd = RGBA(255, 255, 0, 0);
|
||||
//print("hi");
|
||||
|
||||
//debug("hi part 2");
|
||||
|
||||
if PIXEL_X == 30 {
|
||||
PIXEL_RGBA;
|
||||
}
|
||||
else if PIXEL_X == 10 {
|
||||
RGBA(0, 0, 0, 0);
|
||||
} else {
|
||||
abcd;
|
||||
}
|
||||
}
|
|
@ -1,18 +1,58 @@
|
|||
use crate::pixel_format::{rgba_add, rgba_div, rgba_mult, rgba_sub, RGBA};
|
||||
use crate::pixel_format::{get_a, get_b, get_g, get_r, set_a, set_b, set_g, set_r};
|
||||
use crate::pixel_format::{new_rgba64, rgba_div, Rgba64};
|
||||
|
||||
use log::{debug, info};
|
||||
use rhai::Engine;
|
||||
|
||||
pub fn engine_startup() -> Engine {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
// engine.on_print(|x| info!("PRINTED FROM SHADER: {}", x));
|
||||
|
||||
// Any function or closure that takes a '&str', an 'Option<&str>' and a 'Position' argument
|
||||
// can be used to override 'debug'.
|
||||
engine.on_debug(|x, src, pos| {
|
||||
let src = src.unwrap_or("unknown");
|
||||
// debug!("SHADER DEBUG of {} at {:?}: {}", src, pos, x)
|
||||
});
|
||||
|
||||
engine
|
||||
.register_type::<RGBA>()
|
||||
.register_fn("RGBA", RGBA::new)
|
||||
.register_fn("*", rgba_mult)
|
||||
.register_type::<Rgba64>()
|
||||
.register_fn("RGBA", get_rgba_rhai)
|
||||
.register_fn("RGBA", get_rgba_from_int)
|
||||
.register_fn("RGBA", get_rgba_from_int)
|
||||
.register_fn("/", rgba_div)
|
||||
.register_fn("+", rgba_add)
|
||||
.register_fn("-", rgba_sub);
|
||||
// .register_fn("*", rgba_mult)
|
||||
// .register_fn("+", rgba_add)
|
||||
// .register_fn("-", rgba_sub)
|
||||
;
|
||||
|
||||
// engine.register_global_module(RandomPackage::new().as_shared_module());
|
||||
|
||||
engine
|
||||
}
|
||||
use rhai::INT;
|
||||
pub fn get_rgba_rhai(r: INT, g: INT, b: INT, a: INT) -> Rgba64 {
|
||||
let mut pixel = 0;
|
||||
|
||||
pixel |= set_r(pixel, r as u8);
|
||||
pixel |= set_g(pixel, g as u8);
|
||||
pixel |= set_b(pixel, b as u8);
|
||||
pixel |= set_a(pixel, a as u8);
|
||||
pixel
|
||||
}
|
||||
|
||||
pub fn get_rgba_from_int(pixel: INT) -> Rgba64 {
|
||||
let mut pixel = pixel as u64;
|
||||
|
||||
let r = get_r(pixel.try_into().unwrap());
|
||||
let g = get_g(pixel.try_into().unwrap());
|
||||
let b = get_b(pixel.try_into().unwrap());
|
||||
let a = get_a(pixel.try_into().unwrap());
|
||||
|
||||
pixel |= set_r(pixel, r as u8);
|
||||
pixel |= set_g(pixel, g as u8);
|
||||
pixel |= set_b(pixel, b as u8);
|
||||
pixel |= set_a(pixel, a as u8);
|
||||
pixel
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#![no_std]
|
||||
extern crate alloc;
|
||||
use alloc::{boxed::Box, vec, vec::Vec};
|
||||
use alloc::boxed::Box;
|
||||
use engine_internals::engine_startup;
|
||||
use pixel_format::{Rgba64, RGBA};
|
||||
use pixel_format::Rgba64;
|
||||
// use core::fmt::Result;
|
||||
use core::result::Result;
|
||||
use rhai::{EvalAltResult, Scope};
|
||||
|
@ -12,70 +12,17 @@ pub mod pixel_format;
|
|||
|
||||
pub const SHADER: &str = include_str!("../shaders/simple.shade");
|
||||
|
||||
pub fn rhai_test() -> Result<Vec<RGBA>, Box<EvalAltResult>>
|
||||
// ^^^^^^^^^^^^^^^^^^
|
||||
// Rhai API error type
|
||||
{
|
||||
// Create an 'Engine'
|
||||
|
||||
let engine = engine_startup();
|
||||
|
||||
let ast = engine.compile(SHADER)?;
|
||||
let mut scope = Scope::new();
|
||||
|
||||
let a = vec![
|
||||
RGBA {
|
||||
r: 255,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 0,
|
||||
},
|
||||
RGBA {
|
||||
r: 0,
|
||||
g: 255,
|
||||
b: 0,
|
||||
a: 0,
|
||||
},
|
||||
RGBA {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 255,
|
||||
a: 0,
|
||||
},
|
||||
RGBA {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 255,
|
||||
},
|
||||
];
|
||||
|
||||
let mut result_rgba = vec![];
|
||||
|
||||
for pixel in a {
|
||||
/*
|
||||
scope.push("PIXEL_X", 0);
|
||||
scope.push("PIXEL_Y", index);
|
||||
*/
|
||||
scope.push("PIXEL_RGBA", pixel);
|
||||
|
||||
let result: RGBA = engine.call_fn(&mut scope, &ast, "main", ())?;
|
||||
result_rgba.push(result);
|
||||
}
|
||||
|
||||
// Done!
|
||||
Ok(result_rgba)
|
||||
}
|
||||
|
||||
pub fn evaluate_shader(pixel: u8) -> Result<Rgba64, Box<EvalAltResult>> {
|
||||
pub fn evaluate_shader(x: usize, y: usize, pixel: Rgba64) -> Result<Rgba64, Box<EvalAltResult>> {
|
||||
let engine = engine_startup();
|
||||
|
||||
let ast = engine.compile(SHADER)?;
|
||||
let mut scope = Scope::new();
|
||||
|
||||
scope.push("PIXEL_RGBA", pixel);
|
||||
scope.push("PIXEL_X", x);
|
||||
scope.push("PIXEL_Y", y);
|
||||
|
||||
let result: RGBA = engine.call_fn(&mut scope, &ast, "main", ())?;
|
||||
let result: Rgba64 = engine.call_fn(&mut scope, &ast, "main", ())?;
|
||||
|
||||
Ok(8)
|
||||
Ok(result)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#![feature(exclusive_range_pattern)]
|
||||
|
||||
use log::*;
|
||||
use rhai::INT;
|
||||
use vga::colors::Color16;
|
||||
pub type Rgba64 = u64;
|
||||
|
@ -57,27 +57,14 @@ pub fn set_a(rgba: Rgba64, a: u8) -> Rgba64 {
|
|||
return z | y;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RGBA {
|
||||
pub r: INT,
|
||||
pub g: INT,
|
||||
pub b: INT,
|
||||
pub a: INT,
|
||||
}
|
||||
impl RGBA {
|
||||
pub fn new(r: INT, g: INT, b: INT, a: INT) -> Self {
|
||||
Self { r, g, b, a }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rgba_div(a: Rgba64, b: Rgba64) -> Rgba64 {
|
||||
let mut fin: Rgba64 = 0;
|
||||
|
||||
// println!("{}", fin);
|
||||
fin = set_r(fin, get_r(a) / get_r(b));
|
||||
fin |= set_r(fin, get_r(a) / get_r(b));
|
||||
// println!("{}", fin);
|
||||
|
||||
fin = set_g(fin, get_g(a) / get_g(b));
|
||||
fin |= set_g(fin, get_g(a) / get_g(b));
|
||||
/*
|
||||
|
||||
get_b(a) / get_b(b);
|
||||
|
@ -87,31 +74,6 @@ pub fn rgba_div(a: Rgba64, b: Rgba64) -> Rgba64 {
|
|||
|
||||
return fin;
|
||||
}
|
||||
pub fn rgba_mult(a: RGBA, b: RGBA) -> RGBA {
|
||||
RGBA {
|
||||
r: a.r * b.r,
|
||||
g: a.g * b.g,
|
||||
b: a.b * b.b,
|
||||
a: a.a * b.a,
|
||||
}
|
||||
}
|
||||
pub fn rgba_add(a: RGBA, b: RGBA) -> RGBA {
|
||||
RGBA {
|
||||
r: a.r + b.r,
|
||||
g: a.g + b.g,
|
||||
b: a.b + b.b,
|
||||
a: a.a + b.a,
|
||||
}
|
||||
}
|
||||
pub fn rgba_sub(a: RGBA, b: RGBA) -> RGBA {
|
||||
RGBA {
|
||||
r: a.r - b.r,
|
||||
g: a.g - b.g,
|
||||
b: a.b - b.b,
|
||||
a: a.a - b.a,
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
pub fn new_rgba64(r: u8, g: u8, b: u8, a: u8) -> Rgba64 {
|
||||
let mut x = 0;
|
||||
|
@ -141,6 +103,9 @@ pub fn into_vga_16(rgba_64: Rgba64) -> Color16 {
|
|||
171..=255 => 0b1001,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
// trace!("{}", fourbit);
|
||||
|
||||
use Color16::*;
|
||||
match fourbit {
|
||||
0 => Black,
|
||||
|
|
Loading…
Reference in a new issue