Redo networking (#22)
* Rewriting network functions * Add buffer to dup Fix non-blocking handling by triggering once on enabling events to read to EOF * Modifications for UDP API * Implement TCP client side * Add active close * Add DMAR parser * Implement basic TCP listening. Need to improve the state machine * Reduce debugging * Fixes for close procedure * Updates to fix path processing in libstd
This commit is contained in:
parent
268c859fd6
commit
2491e4771e
54 changed files with 1859 additions and 1451 deletions
10
Makefile
10
Makefile
|
|
@ -42,7 +42,6 @@ clean:
|
||||||
cargo clean --manifest-path programs/userutils/Cargo.toml
|
cargo clean --manifest-path programs/userutils/Cargo.toml
|
||||||
cargo clean --manifest-path programs/smith/Cargo.toml
|
cargo clean --manifest-path programs/smith/Cargo.toml
|
||||||
cargo clean --manifest-path programs/tar/Cargo.toml
|
cargo clean --manifest-path programs/tar/Cargo.toml
|
||||||
cargo clean --manifest-path schemes/arpd/Cargo.toml
|
|
||||||
cargo clean --manifest-path schemes/ethernetd/Cargo.toml
|
cargo clean --manifest-path schemes/ethernetd/Cargo.toml
|
||||||
cargo clean --manifest-path schemes/example/Cargo.toml
|
cargo clean --manifest-path schemes/example/Cargo.toml
|
||||||
cargo clean --manifest-path schemes/ipd/Cargo.toml
|
cargo clean --manifest-path schemes/ipd/Cargo.toml
|
||||||
|
|
@ -92,7 +91,6 @@ update:
|
||||||
cargo update --manifest-path programs/userutils/Cargo.toml
|
cargo update --manifest-path programs/userutils/Cargo.toml
|
||||||
cargo update --manifest-path programs/smith/Cargo.toml
|
cargo update --manifest-path programs/smith/Cargo.toml
|
||||||
cargo update --manifest-path programs/tar/Cargo.toml
|
cargo update --manifest-path programs/tar/Cargo.toml
|
||||||
cargo update --manifest-path schemes/arpd/Cargo.toml
|
|
||||||
cargo update --manifest-path schemes/ethernetd/Cargo.toml
|
cargo update --manifest-path schemes/ethernetd/Cargo.toml
|
||||||
cargo update --manifest-path schemes/example/Cargo.toml
|
cargo update --manifest-path schemes/example/Cargo.toml
|
||||||
cargo update --manifest-path schemes/ipd/Cargo.toml
|
cargo update --manifest-path schemes/ipd/Cargo.toml
|
||||||
|
|
@ -120,7 +118,12 @@ $(KBUILD)/harddrive.bin: $(KBUILD)/kernel
|
||||||
qemu: $(KBUILD)/harddrive.bin
|
qemu: $(KBUILD)/harddrive.bin
|
||||||
$(QEMU) $(QEMUFLAGS) -kernel $<
|
$(QEMU) $(QEMUFLAGS) -kernel $<
|
||||||
else
|
else
|
||||||
QEMUFLAGS+=-machine q35 -smp 4 -m 1024
|
QEMUFLAGS+=-smp 4 -m 1024
|
||||||
|
ifeq ($(iommu),no)
|
||||||
|
QEMUFLAGS+=-machine q35
|
||||||
|
else
|
||||||
|
QEMUFLAGS+=-machine q35,iommu=on
|
||||||
|
endif
|
||||||
ifeq ($(net),no)
|
ifeq ($(net),no)
|
||||||
QEMUFLAGS+=-net none
|
QEMUFLAGS+=-net none
|
||||||
else
|
else
|
||||||
|
|
@ -406,7 +409,6 @@ userutils: \
|
||||||
filesystem/bin/sudo
|
filesystem/bin/sudo
|
||||||
|
|
||||||
schemes: \
|
schemes: \
|
||||||
filesystem/bin/arpd \
|
|
||||||
filesystem/bin/ethernetd \
|
filesystem/bin/ethernetd \
|
||||||
filesystem/bin/example \
|
filesystem/bin/example \
|
||||||
filesystem/bin/ipd \
|
filesystem/bin/ipd \
|
||||||
|
|
|
||||||
170
arch/x86_64/src/acpi/dmar.rs
Normal file
170
arch/x86_64/src/acpi/dmar.rs
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
use core::mem;
|
||||||
|
|
||||||
|
use super::sdt::Sdt;
|
||||||
|
|
||||||
|
/// The DMA Remapping Table
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Dmar {
|
||||||
|
sdt: &'static Sdt,
|
||||||
|
pub addr_width: u8,
|
||||||
|
pub flags: u8,
|
||||||
|
_rsv: [u8; 10],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dmar {
|
||||||
|
pub fn new(sdt: &'static Sdt) -> Option<Dmar> {
|
||||||
|
if &sdt.signature == b"DMAR" && sdt.data_len() >= 12 { //Not valid if no local address and flags
|
||||||
|
let addr_width = unsafe { *(sdt.data_address() as *const u8) };
|
||||||
|
let flags = unsafe { *(sdt.data_address() as *const u8).offset(1) };
|
||||||
|
let rsv: [u8; 10] = unsafe { *((sdt.data_address() as *const u8).offset(2) as *const [u8; 10]) };
|
||||||
|
|
||||||
|
Some(Dmar {
|
||||||
|
sdt: sdt,
|
||||||
|
addr_width: addr_width,
|
||||||
|
flags: flags,
|
||||||
|
_rsv: rsv,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn iter(&self) -> DmarIter {
|
||||||
|
DmarIter {
|
||||||
|
sdt: self.sdt,
|
||||||
|
i: 12 // Skip address width and flags
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
|
||||||
|
/// DMAR DMA Remapping Hardware Unit Definition
|
||||||
|
// TODO: Implement iterator on DmarDrhd scope
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[repr(packed)]
|
||||||
|
pub struct DmarDrhd {
|
||||||
|
kind: u16,
|
||||||
|
length: u16,
|
||||||
|
flags: u8,
|
||||||
|
_rsv: u8,
|
||||||
|
segment: u16,
|
||||||
|
base: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// DMAR Reserved Memory Region Reporting
|
||||||
|
// TODO: Implement iterator on DmarRmrr scope
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[repr(packed)]
|
||||||
|
pub struct DmarRmrr {
|
||||||
|
kind: u16,
|
||||||
|
length: u16,
|
||||||
|
_rsv: u16,
|
||||||
|
segment: u16,
|
||||||
|
base: u64,
|
||||||
|
limit: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// DMAR Root Port ATS Capability Reporting
|
||||||
|
// TODO: Implement iterator on DmarAtsr scope
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[repr(packed)]
|
||||||
|
pub struct DmarAtsr {
|
||||||
|
kind: u16,
|
||||||
|
length: u16,
|
||||||
|
flags: u8,
|
||||||
|
_rsv: u8,
|
||||||
|
segment: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// DMAR Remapping Hardware Static Affinity
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[repr(packed)]
|
||||||
|
pub struct DmarRhsa {
|
||||||
|
kind: u16,
|
||||||
|
length: u16,
|
||||||
|
_rsv: u32,
|
||||||
|
base: u64,
|
||||||
|
domain: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// DMAR ACPI Name-space Device Declaration
|
||||||
|
// TODO: Implement iterator on DmarAndd object name
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[repr(packed)]
|
||||||
|
pub struct DmarAndd {
|
||||||
|
kind: u16,
|
||||||
|
length: u16,
|
||||||
|
_rsv: [u8; 3],
|
||||||
|
acpi_dev: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// DMAR Entries
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum DmarEntry {
|
||||||
|
Drhd(&'static DmarDrhd),
|
||||||
|
InvalidDrhd(usize),
|
||||||
|
Rmrr(&'static DmarRmrr),
|
||||||
|
InvalidRmrr(usize),
|
||||||
|
Atsr(&'static DmarAtsr),
|
||||||
|
InvalidAtsr(usize),
|
||||||
|
Rhsa(&'static DmarRhsa),
|
||||||
|
InvalidRhsa(usize),
|
||||||
|
Andd(&'static DmarAndd),
|
||||||
|
InvalidAndd(usize),
|
||||||
|
Unknown(u16)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DmarIter {
|
||||||
|
sdt: &'static Sdt,
|
||||||
|
i: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for DmarIter {
|
||||||
|
type Item = DmarEntry;
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
if self.i + 4 <= self.sdt.data_len() {
|
||||||
|
let entry_type = unsafe { *((self.sdt.data_address() as *const u8).offset(self.i as isize) as *const u16) };
|
||||||
|
let entry_len = unsafe { *((self.sdt.data_address() as *const u8).offset(self.i as isize + 2) as *const u16) } as usize;
|
||||||
|
|
||||||
|
if self.i + entry_len <= self.sdt.data_len() {
|
||||||
|
let item = match entry_type {
|
||||||
|
0 => if entry_len >= mem::size_of::<DmarDrhd>() {
|
||||||
|
DmarEntry::Drhd(unsafe { &*((self.sdt.data_address() + self.i) as *const DmarDrhd) })
|
||||||
|
} else {
|
||||||
|
DmarEntry::InvalidDrhd(entry_len)
|
||||||
|
},
|
||||||
|
1 => if entry_len >= mem::size_of::<DmarRmrr>() {
|
||||||
|
DmarEntry::Rmrr(unsafe { &*((self.sdt.data_address() + self.i) as *const DmarRmrr) })
|
||||||
|
} else {
|
||||||
|
DmarEntry::InvalidRmrr(entry_len)
|
||||||
|
},
|
||||||
|
2 => if entry_len >= mem::size_of::<DmarAtsr>() {
|
||||||
|
DmarEntry::Atsr(unsafe { &*((self.sdt.data_address() + self.i) as *const DmarAtsr) })
|
||||||
|
} else {
|
||||||
|
DmarEntry::InvalidAtsr(entry_len)
|
||||||
|
},
|
||||||
|
3 => if entry_len == mem::size_of::<DmarRhsa>() {
|
||||||
|
DmarEntry::Rhsa(unsafe { &*((self.sdt.data_address() + self.i) as *const DmarRhsa) })
|
||||||
|
} else {
|
||||||
|
DmarEntry::InvalidRhsa(entry_len)
|
||||||
|
},
|
||||||
|
4 => if entry_len >= mem::size_of::<DmarAndd>() {
|
||||||
|
DmarEntry::Andd(unsafe { &*((self.sdt.data_address() + self.i) as *const DmarAndd) })
|
||||||
|
} else {
|
||||||
|
DmarEntry::InvalidAndd(entry_len)
|
||||||
|
},
|
||||||
|
_ => DmarEntry::Unknown(entry_type)
|
||||||
|
};
|
||||||
|
|
||||||
|
self.i += entry_len;
|
||||||
|
|
||||||
|
Some(item)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,12 +9,14 @@ use memory::{allocate_frames, Frame};
|
||||||
use paging::{entry, ActivePageTable, Page, PhysicalAddress, VirtualAddress};
|
use paging::{entry, ActivePageTable, Page, PhysicalAddress, VirtualAddress};
|
||||||
use start::{kstart_ap, CPU_COUNT, AP_READY};
|
use start::{kstart_ap, CPU_COUNT, AP_READY};
|
||||||
|
|
||||||
|
use self::dmar::Dmar;
|
||||||
use self::local_apic::LocalApic;
|
use self::local_apic::LocalApic;
|
||||||
use self::madt::{Madt, MadtEntry};
|
use self::madt::{Madt, MadtEntry};
|
||||||
use self::rsdt::Rsdt;
|
use self::rsdt::Rsdt;
|
||||||
use self::sdt::Sdt;
|
use self::sdt::Sdt;
|
||||||
use self::xsdt::Xsdt;
|
use self::xsdt::Xsdt;
|
||||||
|
|
||||||
|
pub mod dmar;
|
||||||
pub mod local_apic;
|
pub mod local_apic;
|
||||||
pub mod madt;
|
pub mod madt;
|
||||||
pub mod rsdt;
|
pub mod rsdt;
|
||||||
|
|
@ -133,6 +135,12 @@ pub fn init_sdt(sdt: &'static Sdt, active_table: &mut ActivePageTable) {
|
||||||
// Unmap trampoline
|
// Unmap trampoline
|
||||||
active_table.unmap(trampoline_page);
|
active_table.unmap(trampoline_page);
|
||||||
active_table.flush(trampoline_page);
|
active_table.flush(trampoline_page);
|
||||||
|
} else if let Some(dmar) = Dmar::new(sdt) {
|
||||||
|
println!(": {}: {}", dmar.addr_width, dmar.flags);
|
||||||
|
|
||||||
|
for dmar_entry in dmar.iter() {
|
||||||
|
println!(" {:?}", dmar_entry);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
println!(": Unknown");
|
println!(": Unknown");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,43 @@ impl<R> EventQueue<R> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Remove a file from the event queue, returning its callback if found
|
||||||
|
pub fn remove(&mut self, fd: RawFd) -> Result<Option<Box<FnMut(usize) -> Result<Option<R>>>>> {
|
||||||
|
if let Some(callback) = self.callbacks.remove(&fd) {
|
||||||
|
syscall::fevent(fd, 0).map_err(|x| Error::from_sys(x))?;
|
||||||
|
|
||||||
|
Ok(Some(callback))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Send an event to a descriptor callback
|
||||||
|
pub fn trigger(&mut self, fd: RawFd, count: usize) -> Result<Option<R>> {
|
||||||
|
if let Some(callback) = self.callbacks.get_mut(&fd) {
|
||||||
|
callback(count)
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Send an event to all descriptor callbacks, useful for cleaning out buffers after init
|
||||||
|
pub fn trigger_all(&mut self, count: usize) -> Result<Vec<R>> {
|
||||||
|
let mut rets = Vec::new();
|
||||||
|
for (_fd, callback) in self.callbacks.iter_mut() {
|
||||||
|
if let Some(ret) = callback(count)? {
|
||||||
|
rets.push(ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(rets)
|
||||||
|
}
|
||||||
|
|
||||||
/// Process the event queue until a callback returns Some(R)
|
/// Process the event queue until a callback returns Some(R)
|
||||||
pub fn run(&mut self) -> Result<R> {
|
pub fn run(&mut self) -> Result<R> {
|
||||||
loop {
|
loop {
|
||||||
let mut event = syscall::Event::default();
|
let mut event = syscall::Event::default();
|
||||||
self.file.read(&mut event)?;
|
if self.file.read(&mut event)? > 0 {
|
||||||
if let Some(callback) = self.callbacks.get_mut(&event.id) {
|
if let Some(ret) = self.trigger(event.id, event.data)? {
|
||||||
if let Some(ret) = callback(event.data)? {
|
|
||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use syscall::error::*;
|
||||||
pub trait Resource {
|
pub trait Resource {
|
||||||
/// Duplicate the resource
|
/// Duplicate the resource
|
||||||
/// Returns `EPERM` if the operation is not supported.
|
/// Returns `EPERM` if the operation is not supported.
|
||||||
fn dup(&self) -> Result<Box<Self>> {
|
fn dup(&self, _buf: &[u8]) -> Result<Box<Self>> {
|
||||||
Err(Error::new(EPERM))
|
Err(Error::new(EPERM))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ pub trait ResourceScheme<T: Resource> {
|
||||||
SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
|
SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
|
||||||
SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
|
SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
|
||||||
|
|
||||||
SYS_DUP => self.dup(packet.b),
|
SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
|
||||||
SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
|
SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
|
||||||
SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
|
SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
|
||||||
SYS_LSEEK => self.seek(packet.b, packet.c, packet.d),
|
SYS_LSEEK => self.seek(packet.b, packet.c, packet.d),
|
||||||
|
|
@ -54,9 +54,9 @@ pub trait ResourceScheme<T: Resource> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resource operations */
|
/* Resource operations */
|
||||||
fn dup(&self, old_id: usize) -> Result<usize> {
|
fn dup(&self, old_id: usize, buf: &[u8]) -> Result<usize> {
|
||||||
let old = unsafe { &*(old_id as *const T) };
|
let old = unsafe { &*(old_id as *const T) };
|
||||||
let resource = old.dup()?;
|
let resource = old.dup(buf)?;
|
||||||
let resource_ptr = Box::into_raw(resource);
|
let resource_ptr = Box::into_raw(resource);
|
||||||
Ok(resource_ptr as usize)
|
Ok(resource_ptr as usize)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,10 +52,14 @@ fn main() {
|
||||||
let mut event = Event::default();
|
let mut event = Event::default();
|
||||||
event_file.read(&mut event).expect("ahcid: failed to read event file");
|
event_file.read(&mut event).expect("ahcid: failed to read event file");
|
||||||
if event.id == socket_fd {
|
if event.id == socket_fd {
|
||||||
let mut packet = Packet::default();
|
loop {
|
||||||
socket.read(&mut packet).expect("ahcid: failed to read disk scheme");
|
let mut packet = Packet::default();
|
||||||
scheme.handle(&mut packet);
|
if socket.read(&mut packet).expect("ahcid: failed to read disk scheme") == 0 {
|
||||||
socket.write(&mut packet).expect("ahcid: failed to write disk scheme");
|
break;
|
||||||
|
}
|
||||||
|
scheme.handle(&mut packet);
|
||||||
|
socket.write(&mut packet).expect("ahcid: failed to write disk scheme");
|
||||||
|
}
|
||||||
} else if event.id == irq_fd {
|
} else if event.id == irq_fd {
|
||||||
let mut irq = [0; 8];
|
let mut irq = [0; 8];
|
||||||
if irq_file.read(&mut irq).expect("ahcid: failed to read irq file") >= irq.len() {
|
if irq_file.read(&mut irq).expect("ahcid: failed to read irq file") >= irq.len() {
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ impl Scheme for DiskScheme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dup(&self, id: usize) -> Result<usize> {
|
fn dup(&self, id: usize, _buf: &[u8]) -> Result<usize> {
|
||||||
let mut handles = self.handles.lock();
|
let mut handles = self.handles.lock();
|
||||||
let new_handle = {
|
let new_handle = {
|
||||||
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ impl Scheme for Intel8254x {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dup(&self, id: usize) -> Result<usize> {
|
fn dup(&self, id: usize, _buf: &[u8]) -> Result<usize> {
|
||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,16 +80,20 @@ fn main() {
|
||||||
|
|
||||||
let socket_packet = socket.clone();
|
let socket_packet = socket.clone();
|
||||||
event_queue.add(socket_fd, move |_count: usize| -> Result<Option<usize>> {
|
event_queue.add(socket_fd, move |_count: usize| -> Result<Option<usize>> {
|
||||||
let mut packet = Packet::default();
|
loop {
|
||||||
socket_packet.borrow_mut().read(&mut packet)?;
|
let mut packet = Packet::default();
|
||||||
|
if socket_packet.borrow_mut().read(&mut packet)? == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
let a = packet.a;
|
let a = packet.a;
|
||||||
device.handle(&mut packet);
|
device.handle(&mut packet);
|
||||||
if packet.a == (-EWOULDBLOCK) as usize {
|
if packet.a == (-EWOULDBLOCK) as usize {
|
||||||
packet.a = a;
|
packet.a = a;
|
||||||
todo.borrow_mut().push(packet);
|
todo.borrow_mut().push(packet);
|
||||||
} else {
|
} else {
|
||||||
socket_packet.borrow_mut().write(&mut packet)?;
|
socket_packet.borrow_mut().write(&mut packet)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let next_read = device.next_read();
|
let next_read = device.next_read();
|
||||||
|
|
@ -100,10 +104,8 @@ fn main() {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}).expect("e1000d: failed to catch events on IRQ file");
|
}).expect("e1000d: failed to catch events on IRQ file");
|
||||||
|
|
||||||
loop {
|
for event_count in event_queue.trigger_all(0).expect("e1000d: failed to trigger events") {
|
||||||
let event_count = event_queue.run().expect("e1000d: failed to handle events");
|
socket.borrow_mut().write(&Packet {
|
||||||
|
|
||||||
let event_packet = Packet {
|
|
||||||
id: 0,
|
id: 0,
|
||||||
pid: 0,
|
pid: 0,
|
||||||
uid: 0,
|
uid: 0,
|
||||||
|
|
@ -112,9 +114,22 @@ fn main() {
|
||||||
b: 0,
|
b: 0,
|
||||||
c: syscall::flag::EVENT_READ,
|
c: syscall::flag::EVENT_READ,
|
||||||
d: event_count
|
d: event_count
|
||||||
};
|
}).expect("e1000d: failed to write event");
|
||||||
|
}
|
||||||
|
|
||||||
socket.borrow_mut().write(&event_packet).expect("vesad: failed to write display event");
|
loop {
|
||||||
|
let event_count = event_queue.run().expect("e1000d: failed to handle events");
|
||||||
|
|
||||||
|
socket.borrow_mut().write(&Packet {
|
||||||
|
id: 0,
|
||||||
|
pid: 0,
|
||||||
|
uid: 0,
|
||||||
|
gid: 0,
|
||||||
|
a: syscall::number::SYS_FEVENT,
|
||||||
|
b: 0,
|
||||||
|
c: syscall::flag::EVENT_READ,
|
||||||
|
d: event_count
|
||||||
|
}).expect("e1000d: failed to write event");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe { let _ = syscall::physunmap(address); }
|
unsafe { let _ = syscall::physunmap(address); }
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,92 @@ bitflags! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Ps2d {
|
||||||
|
input: File,
|
||||||
|
lshift: bool,
|
||||||
|
rshift: bool,
|
||||||
|
packets: [u8; 4],
|
||||||
|
packet_i: usize,
|
||||||
|
extra_packet: bool
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ps2d {
|
||||||
|
fn new(input: File, extra_packet: bool) -> Self {
|
||||||
|
Ps2d {
|
||||||
|
input: input,
|
||||||
|
lshift: false,
|
||||||
|
rshift: false,
|
||||||
|
packets: [0; 4],
|
||||||
|
packet_i: 0,
|
||||||
|
extra_packet: extra_packet
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle(&mut self, keyboard: bool, data: u8) {
|
||||||
|
if keyboard {
|
||||||
|
let (scancode, pressed) = if data >= 0x80 {
|
||||||
|
(data - 0x80, false)
|
||||||
|
} else {
|
||||||
|
(data, true)
|
||||||
|
};
|
||||||
|
|
||||||
|
if scancode == 0x2A {
|
||||||
|
self.lshift = pressed;
|
||||||
|
} else if scancode == 0x36 {
|
||||||
|
self.rshift = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.input.write(&KeyEvent {
|
||||||
|
character: keymap::get_char(scancode, self.lshift || self.rshift),
|
||||||
|
scancode: scancode,
|
||||||
|
pressed: pressed
|
||||||
|
}.to_event()).expect("ps2d: failed to write key event");
|
||||||
|
} else {
|
||||||
|
self.packets[self.packet_i] = data;
|
||||||
|
self.packet_i += 1;
|
||||||
|
|
||||||
|
let flags = MousePacketFlags::from_bits_truncate(self.packets[0]);
|
||||||
|
if ! flags.contains(ALWAYS_ON) {
|
||||||
|
println!("MOUSE MISALIGN {:X}", self.packets[0]);
|
||||||
|
|
||||||
|
self.packets = [0; 4];
|
||||||
|
self.packet_i = 0;
|
||||||
|
} else if self.packet_i >= self.packets.len() || (!self.extra_packet && self.packet_i >= 3) {
|
||||||
|
if ! flags.contains(X_OVERFLOW) && ! flags.contains(Y_OVERFLOW) {
|
||||||
|
let mut dx = self.packets[1] as i32;
|
||||||
|
if flags.contains(X_SIGN) {
|
||||||
|
dx -= 0x100;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut dy = -(self.packets[2] as i32);
|
||||||
|
if flags.contains(Y_SIGN) {
|
||||||
|
dy += 0x100;
|
||||||
|
}
|
||||||
|
|
||||||
|
let _extra = if self.extra_packet {
|
||||||
|
self.packets[3]
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
self.input.write(&MouseEvent {
|
||||||
|
x: dx,
|
||||||
|
y: dy,
|
||||||
|
left_button: flags.contains(LEFT_BUTTON),
|
||||||
|
middle_button: flags.contains(MIDDLE_BUTTON),
|
||||||
|
right_button: flags.contains(RIGHT_BUTTON)
|
||||||
|
}.to_event()).expect("ps2d: failed to write mouse event");
|
||||||
|
} else {
|
||||||
|
println!("ps2d: overflow {:X} {:X} {:X} {:X}", self.packets[0], self.packets[1], self.packets[2], self.packets[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.packets = [0; 4];
|
||||||
|
self.packet_i = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
thread::spawn(|| {
|
thread::spawn(|| {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
@ -39,9 +125,11 @@ fn main() {
|
||||||
asm!("cli" :::: "intel", "volatile");
|
asm!("cli" :::: "intel", "volatile");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let input = File::open("display:input").expect("ps2d: failed to open display:input");
|
||||||
|
|
||||||
let extra_packet = controller::Ps2::new().init();
|
let extra_packet = controller::Ps2::new().init();
|
||||||
|
|
||||||
let mut input = File::open("display:input").expect("ps2d: failed to open display:input");
|
let mut ps2d = Ps2d::new(input, extra_packet);
|
||||||
|
|
||||||
let mut event_queue = EventQueue::<(bool, u8)>::new().expect("ps2d: failed to create event queue");
|
let mut event_queue = EventQueue::<(bool, u8)>::new().expect("ps2d: failed to create event queue");
|
||||||
|
|
||||||
|
|
@ -81,75 +169,13 @@ fn main() {
|
||||||
}
|
}
|
||||||
}).expect("ps2d: failed to poll irq:12");
|
}).expect("ps2d: failed to poll irq:12");
|
||||||
|
|
||||||
let mut lshift = false;
|
for (keyboard, data) in event_queue.trigger_all(0).expect("ps2d: failed to trigger events") {
|
||||||
let mut rshift = false;
|
ps2d.handle(keyboard, data);
|
||||||
let mut packets = [0; 4];
|
}
|
||||||
let mut packet_i = 0;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (keyboard, data) = event_queue.run().expect("ps2d: failed to handle events");
|
let (keyboard, data) = event_queue.run().expect("ps2d: failed to handle events");
|
||||||
|
ps2d.handle(keyboard, data);
|
||||||
if keyboard {
|
|
||||||
let (scancode, pressed) = if data >= 0x80 {
|
|
||||||
(data - 0x80, false)
|
|
||||||
} else {
|
|
||||||
(data, true)
|
|
||||||
};
|
|
||||||
|
|
||||||
if scancode == 0x2A {
|
|
||||||
lshift = pressed;
|
|
||||||
} else if scancode == 0x36 {
|
|
||||||
rshift = pressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
input.write(&KeyEvent {
|
|
||||||
character: keymap::get_char(scancode, lshift || rshift),
|
|
||||||
scancode: scancode,
|
|
||||||
pressed: pressed
|
|
||||||
}.to_event()).expect("ps2d: failed to write key event");
|
|
||||||
} else {
|
|
||||||
packets[packet_i] = data;
|
|
||||||
packet_i += 1;
|
|
||||||
|
|
||||||
let flags = MousePacketFlags::from_bits_truncate(packets[0]);
|
|
||||||
if ! flags.contains(ALWAYS_ON) {
|
|
||||||
println!("MOUSE MISALIGN {:X}", packets[0]);
|
|
||||||
|
|
||||||
packets = [0; 4];
|
|
||||||
packet_i = 0;
|
|
||||||
} else if packet_i >= packets.len() || (!extra_packet && packet_i >= 3) {
|
|
||||||
if ! flags.contains(X_OVERFLOW) && ! flags.contains(Y_OVERFLOW) {
|
|
||||||
let mut dx = packets[1] as i32;
|
|
||||||
if flags.contains(X_SIGN) {
|
|
||||||
dx -= 0x100;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut dy = -(packets[2] as i32);
|
|
||||||
if flags.contains(Y_SIGN) {
|
|
||||||
dy += 0x100;
|
|
||||||
}
|
|
||||||
|
|
||||||
let _extra = if extra_packet {
|
|
||||||
packets[3]
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
input.write(&MouseEvent {
|
|
||||||
x: dx,
|
|
||||||
y: dy,
|
|
||||||
left_button: flags.contains(LEFT_BUTTON),
|
|
||||||
middle_button: flags.contains(MIDDLE_BUTTON),
|
|
||||||
right_button: flags.contains(RIGHT_BUTTON)
|
|
||||||
}.to_event()).expect("ps2d: failed to write mouse event");
|
|
||||||
} else {
|
|
||||||
println!("ps2d: overflow {:X} {:X} {:X} {:X}", packets[0], packets[1], packets[2], packets[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
packets = [0; 4];
|
|
||||||
packet_i = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ impl SchemeMut for Rtl8168 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dup(&mut self, id: usize) -> Result<usize> {
|
fn dup(&mut self, id: usize, _buf: &[u8]) -> Result<usize> {
|
||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,16 +85,20 @@ fn main() {
|
||||||
let socket_fd = socket.borrow().as_raw_fd();
|
let socket_fd = socket.borrow().as_raw_fd();
|
||||||
let socket_packet = socket.clone();
|
let socket_packet = socket.clone();
|
||||||
event_queue.add(socket_fd, move |_count: usize| -> Result<Option<usize>> {
|
event_queue.add(socket_fd, move |_count: usize| -> Result<Option<usize>> {
|
||||||
let mut packet = Packet::default();
|
loop {
|
||||||
socket_packet.borrow_mut().read(&mut packet)?;
|
let mut packet = Packet::default();
|
||||||
|
if socket_packet.borrow_mut().read(&mut packet)? == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
let a = packet.a;
|
let a = packet.a;
|
||||||
device.borrow_mut().handle(&mut packet);
|
device.borrow_mut().handle(&mut packet);
|
||||||
if packet.a == (-EWOULDBLOCK) as usize {
|
if packet.a == (-EWOULDBLOCK) as usize {
|
||||||
packet.a = a;
|
packet.a = a;
|
||||||
todo.borrow_mut().push(packet);
|
todo.borrow_mut().push(packet);
|
||||||
} else {
|
} else {
|
||||||
socket_packet.borrow_mut().write(&mut packet)?;
|
socket_packet.borrow_mut().write(&mut packet)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let next_read = device.borrow().next_read();
|
let next_read = device.borrow().next_read();
|
||||||
|
|
@ -105,10 +109,8 @@ fn main() {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}).expect("rtl8168d: failed to catch events on IRQ file");
|
}).expect("rtl8168d: failed to catch events on IRQ file");
|
||||||
|
|
||||||
loop {
|
for event_count in event_queue.trigger_all(0).expect("rtl8168d: failed to trigger events") {
|
||||||
let event_count = event_queue.run().expect("rtl8168d: failed to handle events");
|
socket.borrow_mut().write(&Packet {
|
||||||
|
|
||||||
let event_packet = Packet {
|
|
||||||
id: 0,
|
id: 0,
|
||||||
pid: 0,
|
pid: 0,
|
||||||
uid: 0,
|
uid: 0,
|
||||||
|
|
@ -117,9 +119,22 @@ fn main() {
|
||||||
b: 0,
|
b: 0,
|
||||||
c: syscall::flag::EVENT_READ,
|
c: syscall::flag::EVENT_READ,
|
||||||
d: event_count
|
d: event_count
|
||||||
};
|
}).expect("rtl8168d: failed to write event");
|
||||||
|
}
|
||||||
|
|
||||||
socket.borrow_mut().write(&event_packet).expect("vesad: failed to write display event");
|
loop {
|
||||||
|
let event_count = event_queue.run().expect("rtl8168d: failed to handle events");
|
||||||
|
|
||||||
|
socket.borrow_mut().write(&Packet {
|
||||||
|
id: 0,
|
||||||
|
pid: 0,
|
||||||
|
uid: 0,
|
||||||
|
gid: 0,
|
||||||
|
a: syscall::number::SYS_FEVENT,
|
||||||
|
b: 0,
|
||||||
|
c: syscall::flag::EVENT_READ,
|
||||||
|
d: event_count
|
||||||
|
}).expect("rtl8168d: failed to write event");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe { let _ = syscall::physunmap(address); }
|
unsafe { let _ = syscall::physunmap(address); }
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,6 @@ fn main() {
|
||||||
loop {
|
loop {
|
||||||
let mut packet = Packet::default();
|
let mut packet = Packet::default();
|
||||||
socket.read(&mut packet).expect("vesad: failed to read display scheme");
|
socket.read(&mut packet).expect("vesad: failed to read display scheme");
|
||||||
//println!("vesad: {:?}", packet);
|
|
||||||
|
|
||||||
// If it is a read packet, and there is no data, block it. Otherwise, handle packet
|
// If it is a read packet, and there is no data, block it. Otherwise, handle packet
|
||||||
if packet.a == syscall::number::SYS_READ && packet.d > 0 && scheme.will_block(packet.b) {
|
if packet.a == syscall::number::SYS_READ && packet.d > 0 && scheme.will_block(packet.b) {
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ impl SchemeMut for DisplayScheme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dup(&mut self, id: usize) -> Result<usize> {
|
fn dup(&mut self, id: usize, _buf: &[u8]) -> Result<usize> {
|
||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
randd
|
randd
|
||||||
initfs:bin/pcid /etc/pcid.toml
|
initfs:bin/pcid /etc/pcid.toml
|
||||||
ethernetd
|
ethernetd
|
||||||
arpd
|
|
||||||
ipd
|
ipd
|
||||||
tcpd
|
tcpd
|
||||||
udpd
|
udpd
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ impl Scheme for DebugScheme {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dup(&self, _file: usize) -> Result<usize> {
|
fn dup(&self, _file: usize, _buf: &[u8]) -> Result<usize> {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ impl Scheme for EnvScheme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dup(&self, id: usize) -> Result<usize> {
|
fn dup(&self, id: usize, _buf: &[u8]) -> Result<usize> {
|
||||||
let new_handle = {
|
let new_handle = {
|
||||||
let handles = self.handles.read();
|
let handles = self.handles.read();
|
||||||
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ impl Scheme for EventScheme {
|
||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dup(&self, id: usize) -> Result<usize> {
|
fn dup(&self, id: usize, _buf: &[u8]) -> Result<usize> {
|
||||||
let handle = {
|
let handle = {
|
||||||
let handles = self.handles.read();
|
let handles = self.handles.read();
|
||||||
let handle_weak = handles.get(&id).ok_or(Error::new(EBADF))?;
|
let handle_weak = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ impl Scheme for InitFsScheme {
|
||||||
Err(Error::new(ENOENT))
|
Err(Error::new(ENOENT))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dup(&self, id: usize) -> Result<usize> {
|
fn dup(&self, id: usize, _buf: &[u8]) -> Result<usize> {
|
||||||
let (path, data, mode, seek) = {
|
let (path, data, mode, seek) = {
|
||||||
let handles = self.handles.read();
|
let handles = self.handles.read();
|
||||||
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue