maybe commit
This commit is contained in:
parent
ffdb6c2816
commit
0189236893
|
@ -3,307 +3,307 @@
|
||||||
use alloc::{format, vec::Vec};
|
use alloc::{format, vec::Vec};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
boot_conf::BootConfig,
|
boot_conf::BootConfig,
|
||||||
capabilities::FileAccess,
|
capabilities::FileAccess,
|
||||||
file::{File, PathRep},
|
file::{File, PathRep},
|
||||||
scheduler::SCHEDULER,
|
scheduler::SCHEDULER,
|
||||||
};
|
};
|
||||||
|
|
||||||
// use crate::scheduler;
|
// use crate::scheduler;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
arch::{init, sloop},
|
arch::{init, sloop},
|
||||||
boot_conf,
|
boot_conf,
|
||||||
experiments::{
|
experiments::{
|
||||||
info::master,
|
info::master,
|
||||||
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
||||||
},
|
},
|
||||||
graphics::{VgaBuffer, SCREEN_BUFFER},
|
graphics::{VgaBuffer, SCREEN_BUFFER},
|
||||||
relib::network::socket::Socket,
|
relib::network::socket::Socket,
|
||||||
relib::network::socket::{SimpleSock, SocketReturns},
|
relib::network::socket::{SimpleSock, SocketReturns},
|
||||||
vga_e::{self, num_to_vga16},
|
vga_e::{self, num_to_vga16},
|
||||||
},
|
},
|
||||||
alloc::{
|
alloc::{
|
||||||
string::{String, ToString},
|
string::{String, ToString},
|
||||||
vec,
|
vec,
|
||||||
},
|
},
|
||||||
core::sync::atomic::{AtomicU64, Ordering::*},
|
core::sync::atomic::{AtomicU64, Ordering::*},
|
||||||
lazy_static::lazy_static,
|
lazy_static::lazy_static,
|
||||||
log::*,
|
log::*,
|
||||||
picorand::PicoRandGenerate,
|
picorand::PicoRandGenerate,
|
||||||
rkyv::{ser::serializers::AllocSerializer, Deserialize},
|
rkyv::{ser::serializers::AllocSerializer, Deserialize},
|
||||||
shadeable::pixel_format::from_vga_16,
|
shadeable::pixel_format::from_vga_16,
|
||||||
y_compositor_protocol::Version,
|
y_compositor_protocol::Version,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[allow(unconditional_recursion)]
|
#[allow(unconditional_recursion)]
|
||||||
pub extern "C" fn stack_overflow() -> u8 {
|
pub extern "C" fn stack_overflow() -> u8 {
|
||||||
stack_overflow();
|
stack_overflow();
|
||||||
// meme number
|
// meme number
|
||||||
69 // NOTE: Any specific reason for this number aside from memes?
|
69 // NOTE: Any specific reason for this number aside from memes?
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref KEY_BUFFER: spin::Mutex<String> = spin::Mutex::new("".to_string());
|
pub static ref KEY_BUFFER: spin::Mutex<String> = spin::Mutex::new("".to_string());
|
||||||
pub static ref TICK: AtomicU64 = AtomicU64::new(0);
|
pub static ref TICK: AtomicU64 = AtomicU64::new(0);
|
||||||
pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new();
|
pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The main entry point of the kernel
|
/// The main entry point of the kernel
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn kernel_main() -> ! {
|
pub fn kernel_main() -> ! {
|
||||||
init::init();
|
init::init();
|
||||||
log::set_max_level(BOOT_CONF.log_level());
|
log::set_max_level(BOOT_CONF.log_level());
|
||||||
// info!("Initialized");
|
// info!("Initialized");
|
||||||
|
|
||||||
// facepalm::start_facepalm();
|
// facepalm::start_facepalm();
|
||||||
|
|
||||||
graphics_pipe_startup();
|
graphics_pipe_startup();
|
||||||
|
|
||||||
if false {
|
if false {
|
||||||
let mut proc_1 = SimpleSock::new();
|
let mut proc_1 = SimpleSock::new();
|
||||||
proc_1.register_protocol("ProcessSpawner".to_string());
|
proc_1.register_protocol("ProcessSpawner".to_string());
|
||||||
|
|
||||||
let version = 0;
|
let version = 0;
|
||||||
use rkyv::ser::Serializer;
|
use rkyv::ser::Serializer;
|
||||||
let mut serializer = AllocSerializer::<0>::default();
|
let mut serializer = AllocSerializer::<0>::default();
|
||||||
serializer.serialize_value(&version).unwrap();
|
serializer.serialize_value(&version).unwrap();
|
||||||
|
|
||||||
let bytes = serializer.into_serializer().into_inner();
|
let bytes = serializer.into_serializer().into_inner();
|
||||||
proc_1.write(bytes.into_vec());
|
proc_1.write(bytes.into_vec());
|
||||||
unsafe {
|
unsafe {
|
||||||
let the_bytes = proc_1.read(3).unwrap();
|
let the_bytes = proc_1.read(3).unwrap();
|
||||||
let archived = rkyv::archived_root::<Version>(&the_bytes);
|
let archived = rkyv::archived_root::<Version>(&the_bytes);
|
||||||
let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap();
|
let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap();
|
||||||
trace!("{:?}", deserialized);
|
trace!("{:?}", deserialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::scheduler::Priority;
|
use crate::scheduler::Priority;
|
||||||
let mut scheduler = SCHEDULER.lock();
|
let mut scheduler = SCHEDULER.lock();
|
||||||
|
|
||||||
use Priority::*;
|
use Priority::*;
|
||||||
|
|
||||||
let mut xyz = scheduler.new_process(High);
|
let mut xyz = scheduler.new_process(High);
|
||||||
xyz.capabilities.files = FileAccess::Some(vec![PathRep {
|
xyz.capabilities.files = FileAccess::Some(vec![PathRep {
|
||||||
location: FileLocations::Home,
|
location: FileLocations::Home,
|
||||||
file_name: "test".to_string(),
|
file_name: "test".to_string(),
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
scheduler.add_process(xyz);
|
scheduler.add_process(xyz);
|
||||||
for x in &scheduler.list {
|
for x in &scheduler.list {
|
||||||
trace!("{:?}", x);
|
trace!("{:?}", x);
|
||||||
}
|
}
|
||||||
drop(scheduler);
|
drop(scheduler);
|
||||||
|
|
||||||
use crate::proto_filetable::contain::FILE_TABLE;
|
use crate::proto_filetable::contain::FILE_TABLE;
|
||||||
use crate::proto_filetable::file::FileLocations;
|
use crate::proto_filetable::file::FileLocations;
|
||||||
|
|
||||||
let mut file_table = FILE_TABLE.lock();
|
let mut file_table = FILE_TABLE.lock();
|
||||||
let mut new_file = File::new(FileLocations::Bin, "test".to_string(), "txt".to_string());
|
let mut new_file = File::new(FileLocations::Bin, "test".to_string(), "txt".to_string());
|
||||||
new_file.write_bytes(b"Hello, world!");
|
new_file.write_bytes(b"Hello, world!");
|
||||||
|
|
||||||
file_table.add_file("test", new_file);
|
file_table.add_file("test", new_file);
|
||||||
|
|
||||||
let file = file_table.get_file("test");
|
let file = file_table.get_file("test");
|
||||||
|
|
||||||
match file {
|
match file {
|
||||||
Some(file) => {
|
Some(file) => {
|
||||||
let file_bytes = &file.data_pointer;
|
let file_bytes = &file.data_pointer;
|
||||||
let file_string = String::from_utf8(file_bytes.to_vec()).unwrap();
|
let file_string = String::from_utf8(file_bytes.to_vec()).unwrap();
|
||||||
info!("{}", file_string);
|
info!("{}", file_string);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
info!("File not found");
|
info!("File not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::wasm::WasmProgram;
|
use crate::wasm::WasmProgram;
|
||||||
let ret = WasmProgram::new_from_bytes(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
|
let ret = WasmProgram::new_from_bytes(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
|
||||||
trace!("Binary Valid: {:?}", ret.validate_header());
|
trace!("Binary Valid: {:?}", ret.validate_header());
|
||||||
|
|
||||||
if BOOT_CONF.run_tests {
|
// quick and dirty testing framework
|
||||||
// quick and dirty testing framework
|
// if BOOT_CONF.run_tests {
|
||||||
screen_writer_test();
|
screen_writer_test();
|
||||||
socket_test();
|
socket_test();
|
||||||
graphics_pipe_test();
|
graphics_pipe_test();
|
||||||
socket_startup_rng();
|
socket_startup_rng();
|
||||||
socket_test_rng();
|
socket_test_rng();
|
||||||
}
|
// }
|
||||||
|
|
||||||
if BOOT_CONF.run_demos {
|
if BOOT_CONF.run_demos {
|
||||||
graphics_api_demo();
|
graphics_api_demo();
|
||||||
}
|
}
|
||||||
|
|
||||||
if BOOT_CONF.run_shader_tests {
|
if BOOT_CONF.run_shader_tests {
|
||||||
shader_tests();
|
shader_tests();
|
||||||
}
|
}
|
||||||
|
|
||||||
sloop()
|
sloop()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// called by arch specific timers to tick up all kernel related functions
|
/// called by arch specific timers to tick up all kernel related functions
|
||||||
pub fn tick() {
|
pub fn tick() {
|
||||||
let mut data = TICK.load(Relaxed);
|
let mut data = TICK.load(Relaxed);
|
||||||
data += 1;
|
data += 1;
|
||||||
|
|
||||||
crate::kernel_state::KERNEL_STATE.lock().update_state();
|
crate::kernel_state::KERNEL_STATE.lock().update_state();
|
||||||
|
|
||||||
let mut scheduler = SCHEDULER.lock();
|
let mut scheduler = SCHEDULER.lock();
|
||||||
scheduler.bump_exec();
|
scheduler.bump_exec();
|
||||||
|
|
||||||
TICK.store(data, Relaxed)
|
TICK.store(data, Relaxed)
|
||||||
}
|
}
|
||||||
/// called every time a key is pressed to add it to the randomness pool
|
/// called every time a key is pressed to add it to the randomness pool
|
||||||
pub fn key_entropy(key: u8) {}
|
pub fn key_entropy(key: u8) {}
|
||||||
|
|
||||||
pub fn cpu_socket_startup() {
|
pub fn cpu_socket_startup() {
|
||||||
let mut cpu_info_socket = SimpleSock::new();
|
let mut cpu_info_socket = SimpleSock::new();
|
||||||
cpu_info_socket.register_protocol("CPU_INFO".to_string());
|
cpu_info_socket.register_protocol("CPU_INFO".to_string());
|
||||||
|
|
||||||
let x = master().unwrap();
|
let x = master().unwrap();
|
||||||
let _xyz = x.brand_string().unwrap();
|
let _xyz = x.brand_string().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_version_data() {
|
pub fn log_version_data() {
|
||||||
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
||||||
info!(
|
info!(
|
||||||
"Brand String: {:?}",
|
"Brand String: {:?}",
|
||||||
master().unwrap().brand_string().unwrap()
|
master().unwrap().brand_string().unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn socket_test() {
|
pub fn socket_test() {
|
||||||
let mut xyz = SimpleSock::new();
|
let mut xyz = SimpleSock::new();
|
||||||
|
|
||||||
xyz.peek();
|
xyz.peek();
|
||||||
|
|
||||||
xyz.write(vec![0, 1, 2, 3]);
|
xyz.write(vec![0, 1, 2, 3]);
|
||||||
|
|
||||||
let x = "simple 🧦".to_string().into_bytes();
|
let x = "simple 🧦".to_string().into_bytes();
|
||||||
xyz.write(x);
|
xyz.write(x);
|
||||||
|
|
||||||
info!("{:?}", &xyz.read(4).unwrap());
|
info!("{:?}", &xyz.read(4).unwrap());
|
||||||
|
|
||||||
match &xyz.peek() {
|
match &xyz.peek() {
|
||||||
SocketReturns::ReadOk(strr) => {
|
SocketReturns::ReadOk(strr) => {
|
||||||
let out = String::from_utf8_lossy(strr);
|
let out = String::from_utf8_lossy(strr);
|
||||||
|
|
||||||
info!("{}", out);
|
info!("{}", out);
|
||||||
}
|
}
|
||||||
SocketReturns::ReadIndexOutOfBounds => todo!(),
|
SocketReturns::ReadIndexOutOfBounds => todo!(),
|
||||||
SocketReturns::WriteOk => todo!(),
|
SocketReturns::WriteOk => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn socket_test_rng() {
|
pub fn socket_test_rng() {
|
||||||
let mut test_sock = SimpleSock::grab_socket("RNGProvider".to_string()).unwrap();
|
let mut test_sock = SimpleSock::grab_socket("RNGProvider".to_string()).unwrap();
|
||||||
info!(
|
info!(
|
||||||
"Recieving {} from protocol {}",
|
"Recieving {} from protocol {}",
|
||||||
test_sock.read(1).unwrap()[0],
|
test_sock.read(1).unwrap()[0],
|
||||||
test_sock.protocol().unwrap()
|
test_sock.protocol().unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn socket_startup_rng() {
|
pub fn socket_startup_rng() {
|
||||||
use picorand::{WyRand, RNG};
|
use picorand::{WyRand, RNG};
|
||||||
let mut random_socket = SimpleSock::new();
|
let mut random_socket = SimpleSock::new();
|
||||||
|
|
||||||
random_socket.register_protocol("RNGProvider".to_string());
|
random_socket.register_protocol("RNGProvider".to_string());
|
||||||
let bruh = TICK.load(core::sync::atomic::Ordering::Relaxed);
|
let bruh = TICK.load(core::sync::atomic::Ordering::Relaxed);
|
||||||
|
|
||||||
let mut rng = RNG::<WyRand, u8>::new(bruh);
|
let mut rng = RNG::<WyRand, u8>::new(bruh);
|
||||||
|
|
||||||
for _ in 0..512 {
|
for _ in 0..512 {
|
||||||
let x = rng.generate();
|
let x = rng.generate();
|
||||||
random_socket.write(vec![x]);
|
random_socket.write(vec![x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn screen_writer_test() {
|
pub fn screen_writer_test() {
|
||||||
let mut sock_print_id = SimpleSock::new();
|
let mut sock_print_id = SimpleSock::new();
|
||||||
|
|
||||||
sock_print_id.register_protocol("Screen Printer".to_string());
|
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!("a原 b画 cフ dァ eイ fル 集").into());
|
||||||
// sock_print_id.write(format!("⋮").into());
|
// sock_print_id.write(format!("⋮").into());
|
||||||
|
|
||||||
sock_print_id.write(format!("λ³ Half Life 3 booting up ㎣").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!("Happy birthday 🎉").into());
|
||||||
// sock_print_id.write(format!("I look forward to ur ai stuff :^>").into());
|
// sock_print_id.write(format!("I look forward to ur ai stuff :^>").into());
|
||||||
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
|
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
|
||||||
|
|
||||||
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() {
|
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() {
|
||||||
vga_e::draw_char(0, 0, current, 0);
|
vga_e::draw_char(0, 0, current, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vga_boot_screen() {
|
pub fn vga_boot_screen() {
|
||||||
let mut abcde = SCREEN_BUFFER.lock();
|
let mut abcde = SCREEN_BUFFER.lock();
|
||||||
|
|
||||||
for y in 0..480 {
|
for y in 0..480 {
|
||||||
for x in 0..640 {
|
for x in 0..640 {
|
||||||
let segment_x = x * 4 / 640;
|
let segment_x = x * 4 / 640;
|
||||||
let segment_y = y * 4 / 480;
|
let segment_y = y * 4 / 480;
|
||||||
let segment = segment_x + segment_y * 4;
|
let segment = segment_x + segment_y * 4;
|
||||||
|
|
||||||
abcde.set_pixel(x, y, from_vga_16(num_to_vga16(segment as u8)));
|
abcde.set_pixel(x, y, from_vga_16(num_to_vga16(segment as u8)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn graphics_pipe_test() {
|
pub fn graphics_pipe_test() {
|
||||||
let mut graphics_pipe = SimpleSock::grab_socket("YCompositor".to_string()).unwrap();
|
let mut graphics_pipe = SimpleSock::grab_socket("YCompositor".to_string()).unwrap();
|
||||||
|
|
||||||
let version = Version {
|
let version = Version {
|
||||||
major: 13,
|
major: 13,
|
||||||
minor: 123,
|
minor: 123,
|
||||||
patch: 0,
|
patch: 0,
|
||||||
};
|
};
|
||||||
use rkyv::ser::Serializer;
|
use rkyv::ser::Serializer;
|
||||||
let mut serializer = AllocSerializer::<0>::default();
|
let mut serializer = AllocSerializer::<0>::default();
|
||||||
serializer.serialize_value(&version).unwrap();
|
serializer.serialize_value(&version).unwrap();
|
||||||
// let bytes = serializer.into_serializer().into_inner();
|
// let bytes = serializer.into_serializer().into_inner();
|
||||||
|
|
||||||
// info!("{:?}", bytes);
|
// info!("{:?}", bytes);
|
||||||
let bytes = serializer.into_serializer().into_inner();
|
let bytes = serializer.into_serializer().into_inner();
|
||||||
graphics_pipe.write(bytes.into_vec());
|
graphics_pipe.write(bytes.into_vec());
|
||||||
unsafe {
|
unsafe {
|
||||||
let the_bytes = graphics_pipe.read(3).unwrap();
|
let the_bytes = graphics_pipe.read(3).unwrap();
|
||||||
let archived = rkyv::archived_root::<Version>(&the_bytes);
|
let archived = rkyv::archived_root::<Version>(&the_bytes);
|
||||||
let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap();
|
let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap();
|
||||||
trace!("{:?}", deserialized);
|
trace!("{:?}", deserialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn graphics_pipe_startup() {
|
pub fn graphics_pipe_startup() {
|
||||||
let mut graphics_pipe = SimpleSock::new();
|
let mut graphics_pipe = SimpleSock::new();
|
||||||
|
|
||||||
graphics_pipe.register_protocol("YCompositor".to_string());
|
graphics_pipe.register_protocol("YCompositor".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn graphics_api_demo() {
|
pub fn graphics_api_demo() {
|
||||||
let mut abcde = SCREEN_BUFFER.lock();
|
let mut abcde = SCREEN_BUFFER.lock();
|
||||||
abcde.force_redraw();
|
abcde.force_redraw();
|
||||||
|
|
||||||
abcde.draw_filled_circle(100, 100, 300, 0x0000ff00);
|
abcde.draw_filled_circle(100, 100, 300, 0x0000ff00);
|
||||||
abcde.draw_unfilled_rect(100, 100, 400, 200, 0xff000000);
|
abcde.draw_unfilled_rect(100, 100, 400, 200, 0xff000000);
|
||||||
abcde.draw_filled_rect(300, 300, 400, 400, 0xff000000);
|
abcde.draw_filled_rect(300, 300, 400, 400, 0xff000000);
|
||||||
abcde.draw_line(100, 100, 400, 200, 0xff000000);
|
abcde.draw_line(100, 100, 400, 200, 0xff000000);
|
||||||
abcde.copy_to_buffer();
|
abcde.copy_to_buffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shader_tests() {
|
pub fn shader_tests() {
|
||||||
let mut graphics = SCREEN_BUFFER.lock();
|
let mut graphics = SCREEN_BUFFER.lock();
|
||||||
|
|
||||||
graphics.clear();
|
graphics.clear();
|
||||||
graphics.force_redraw();
|
graphics.force_redraw();
|
||||||
graphics.draw_filled_rect(25, 25, 50, 50, 0xff000000);
|
graphics.draw_filled_rect(25, 25, 50, 50, 0xff000000);
|
||||||
graphics.set_pixel(50, 50, 0xffffff00);
|
graphics.set_pixel(50, 50, 0xffffff00);
|
||||||
graphics.shade();
|
graphics.shade();
|
||||||
|
|
||||||
graphics.copy_to_buffer();
|
graphics.copy_to_buffer();
|
||||||
|
|
||||||
// drop(graphics)
|
// drop(graphics)
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub fn draw_char(mut x: u32, mut y: u32, character: char, color: Rgba64) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// elf: I don't know if GLYPH_HEIGHT is in the right units here. I'm just guessing.
|
// elf: I don't know if GLYPH_HEIGHT is in the right units here. I'm just guessing.
|
||||||
if x as usize > SCREEN_BUFFER.lock().size.x {
|
if x as usize > mode.size.x {
|
||||||
x = 0;
|
x = 0;
|
||||||
y += (GLYPH_HEIGHT * FONT_SCALE) as u32;
|
y += (GLYPH_HEIGHT * FONT_SCALE) as u32;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue