Add the rust std as a custom sysroot
This commit is contained in:
125
src/main.rs
125
src/main.rs
@@ -12,7 +12,8 @@
|
||||
arbitrary_self_types_pointers,
|
||||
derive_const,
|
||||
const_cmp,
|
||||
const_trait_impl
|
||||
const_trait_impl,
|
||||
trait_alias
|
||||
)]
|
||||
|
||||
use core::sync::atomic::AtomicBool;
|
||||
@@ -22,20 +23,15 @@ use embedded_alloc::LlffHeap as Heap;
|
||||
use log::info;
|
||||
|
||||
use crate::{
|
||||
cursor::{clear_cursor, draw_cursor},
|
||||
drivers::{keyboard::KBD_DRIVER, mouse::MOUSE_DRIVER},
|
||||
io::init_log,
|
||||
keymap::{KeyType, ModifierType, map_keycode},
|
||||
pci::{PciDeviceIterator, scan_virtio_devices},
|
||||
pci::scan_virtio_devices,
|
||||
riscv::enable_supervisor_interrupt,
|
||||
scheduler::{SCHEDULER, idle},
|
||||
tty::TTY0,
|
||||
user::{proc2, test},
|
||||
vga::Vga,
|
||||
virtio::{
|
||||
Virtqueue,
|
||||
input::{EventCodeValue, VirtioInputEvent, VirtioPciDriver, init_plic_pci},
|
||||
},
|
||||
virtual_fs::{FILE_SYSTEM, VirtualFileSystem, init_file_system},
|
||||
virtio::input::init_plic_pci,
|
||||
virtual_fs::init_file_system,
|
||||
};
|
||||
|
||||
extern crate alloc;
|
||||
@@ -44,6 +40,7 @@ mod critical_section;
|
||||
mod cursor;
|
||||
mod data_structures;
|
||||
mod draw;
|
||||
mod drivers;
|
||||
mod fs;
|
||||
mod interrupt;
|
||||
mod io;
|
||||
@@ -75,97 +72,6 @@ const _: () = assert!(core::mem::size_of::<usize>() == core::mem::size_of::<u64>
|
||||
#[cfg(not(target_endian = "little"))]
|
||||
compile_error! {"This kernel implementation assume endianness is little-endian. Some memory access like PCI could not work in big-endian."}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct KeyboardState {
|
||||
// ctrl_modifier: bool,
|
||||
pub shift_modifier: bool,
|
||||
pub alt_gr_modifier: bool,
|
||||
}
|
||||
|
||||
impl KeyboardState {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
// ctrl_modifier: false,
|
||||
shift_modifier: false,
|
||||
alt_gr_modifier: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static mut KBD_QUEUE: Virtqueue = unsafe { core::mem::zeroed() };
|
||||
pub static mut KBD_DRIVER: VirtioPciDriver<KeyboardState> = unsafe {
|
||||
VirtioPciDriver::new(
|
||||
|state, event| {
|
||||
let mut kbd_buffer = FILE_SYSTEM.open("/dev/input/keyboard".as_ref()).unwrap();
|
||||
kbd_buffer
|
||||
.write(core::mem::transmute::<
|
||||
&VirtioInputEvent,
|
||||
&[u8; size_of::<VirtioInputEvent>()],
|
||||
>(event))
|
||||
.unwrap();
|
||||
|
||||
if event.is_key() {
|
||||
let event = event.as_key_event();
|
||||
#[allow(clippy::single_match)]
|
||||
match map_keycode(event.code, state) {
|
||||
KeyType::Ascii(c) if event.value == EventCodeValue::Pressed => {
|
||||
let mut buf = [0; 4];
|
||||
let to_send = c.encode_utf8(&mut buf);
|
||||
for c in to_send.as_bytes() {
|
||||
TTY0.buffer.borrow_mut().push(*c);
|
||||
}
|
||||
}
|
||||
KeyType::Modifier(ModifierType::Shift) => {
|
||||
state.shift_modifier = !state.shift_modifier;
|
||||
}
|
||||
KeyType::Modifier(ModifierType::AltGr) => {
|
||||
state.alt_gr_modifier = !state.alt_gr_modifier;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
println!("event: {:#?}", event);
|
||||
} else {
|
||||
// println!("key pressed, {:#?}", event);
|
||||
}
|
||||
},
|
||||
KeyboardState::new(),
|
||||
&mut KBD_QUEUE,
|
||||
)
|
||||
};
|
||||
|
||||
pub static mut MOUSE_POSITION: (u16, u16) = (0, 0);
|
||||
|
||||
static mut MOUSE_QUEUE: Virtqueue = unsafe { core::mem::zeroed() };
|
||||
pub static mut MOUSE_DRIVER: VirtioPciDriver<()> = unsafe {
|
||||
VirtioPciDriver::new(
|
||||
|_, event| {
|
||||
if event.is_relative() {
|
||||
let event = event.as_relative_event();
|
||||
|
||||
clear_cursor(&mut Vga, MOUSE_POSITION.0, MOUSE_POSITION.1);
|
||||
|
||||
match event.code {
|
||||
virtio::input::EventCodeRelative::X => {
|
||||
MOUSE_POSITION.0 = (MOUSE_POSITION.0 as i32 + event.value) as u16
|
||||
}
|
||||
virtio::input::EventCodeRelative::Y => {
|
||||
MOUSE_POSITION.1 = (MOUSE_POSITION.1 as i32 + event.value) as u16
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
draw_cursor(&mut Vga, MOUSE_POSITION.0, MOUSE_POSITION.1);
|
||||
|
||||
// println!("mouse moved relatively, {:#?}", event);
|
||||
} else {
|
||||
// println!("mouse moved, {:#?}", event);
|
||||
}
|
||||
},
|
||||
(),
|
||||
&mut MOUSE_QUEUE,
|
||||
)
|
||||
};
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn supervisor_mode_entry() {
|
||||
unsafe {
|
||||
@@ -180,19 +86,20 @@ pub extern "C" fn supervisor_mode_entry() {
|
||||
info!("Hello World !");
|
||||
// unsafe { Vga.draw_string(10, 10, "Hello World !", Color::WHITE, Color::BLACK) };
|
||||
|
||||
SCHEDULER.lock().create_process(Box::new(test), "proc1");
|
||||
SCHEDULER.lock().create_process(Box::new(proc2), "proc2");
|
||||
// let binding = Box::leak(Box::new(["coucou".as_bytes()]));
|
||||
SCHEDULER
|
||||
.lock()
|
||||
.create_process(Box::new(test), "proc1", 0, core::ptr::null());
|
||||
SCHEDULER
|
||||
.lock()
|
||||
.create_process(Box::new(proc2), "proc2", 0, core::ptr::null());
|
||||
|
||||
SCHEDULER
|
||||
.lock()
|
||||
.create_process_from_file("/usr/bin/test_pic");
|
||||
.create_process_from_file("/usr/bin/test_pic", 0, core::ptr::null());
|
||||
|
||||
enable_supervisor_interrupt();
|
||||
|
||||
for pci in PciDeviceIterator::new() {
|
||||
println!("{:x?}", pci.vendor_and_device_id())
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let (pci_keyboard, pci_mouse) = scan_virtio_devices();
|
||||
let (pci_keyboard, pci_mouse) = (pci_keyboard.unwrap(), pci_mouse.unwrap());
|
||||
@@ -214,5 +121,5 @@ pub extern "C" fn supervisor_mode_entry() {
|
||||
init_plic_pci(pci_keyboard.irq);
|
||||
init_plic_pci(pci_mouse.irq);
|
||||
}
|
||||
idle();
|
||||
idle(0, core::ptr::null());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user