2016-09-19 02:59:46 +02:00
|
|
|
use core::{mem, str};
|
2016-11-04 13:49:44 +01:00
|
|
|
use core::sync::atomic::Ordering;
|
2016-10-20 23:49:17 +02:00
|
|
|
use spin::Mutex;
|
2016-09-19 02:59:46 +02:00
|
|
|
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
use arch::interrupt::irq::acknowledge;
|
|
|
|
use context;
|
2016-11-17 04:54:38 +01:00
|
|
|
use scheme::{AtomicSchemeId, ATOMIC_SCHEMEID_INIT, SchemeId};
|
2016-09-21 00:23:28 +02:00
|
|
|
use syscall::error::*;
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
use syscall::flag::EVENT_READ;
|
2016-09-21 00:23:28 +02:00
|
|
|
use syscall::scheme::Scheme;
|
2016-09-19 02:59:46 +02:00
|
|
|
|
2016-11-04 13:49:44 +01:00
|
|
|
pub static IRQ_SCHEME_ID: AtomicSchemeId = ATOMIC_SCHEMEID_INIT;
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
|
|
|
|
/// IRQ queues
|
|
|
|
static ACKS: Mutex<[usize; 16]> = Mutex::new([0; 16]);
|
|
|
|
static COUNTS: Mutex<[usize; 16]> = Mutex::new([0; 16]);
|
|
|
|
|
|
|
|
/// Add to the input queue
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern fn irq_trigger(irq: u8) {
|
|
|
|
COUNTS.lock()[irq as usize] += 1;
|
|
|
|
context::event::trigger(IRQ_SCHEME_ID.load(Ordering::SeqCst), irq as usize, EVENT_READ, mem::size_of::<usize>());
|
|
|
|
}
|
|
|
|
|
2016-09-19 02:59:46 +02:00
|
|
|
pub struct IrqScheme;
|
|
|
|
|
2016-11-17 04:54:38 +01:00
|
|
|
impl IrqScheme {
|
|
|
|
pub fn new(scheme_id: SchemeId) -> IrqScheme {
|
|
|
|
IRQ_SCHEME_ID.store(scheme_id, Ordering::SeqCst);
|
|
|
|
IrqScheme
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-19 02:59:46 +02:00
|
|
|
impl Scheme for IrqScheme {
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
fn open(&self, path: &[u8], _flags: usize, uid: u32, _gid: u32) -> Result<usize> {
|
|
|
|
if uid == 0 {
|
|
|
|
let path_str = str::from_utf8(path).or(Err(Error::new(ENOENT)))?;
|
2016-09-19 04:17:08 +02:00
|
|
|
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
let id = path_str.parse::<usize>().or(Err(Error::new(ENOENT)))?;
|
2016-09-19 04:17:08 +02:00
|
|
|
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
if id < COUNTS.lock().len() {
|
|
|
|
Ok(id)
|
|
|
|
} else {
|
|
|
|
Err(Error::new(ENOENT))
|
|
|
|
}
|
2016-09-19 02:59:46 +02:00
|
|
|
} else {
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
Err(Error::new(EACCES))
|
2016-09-19 02:59:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 21:19:56 +02:00
|
|
|
fn dup(&self, file: usize, _buf: &[u8]) -> Result<usize> {
|
2016-09-20 01:28:22 +02:00
|
|
|
Ok(file)
|
2016-09-19 02:59:46 +02:00
|
|
|
}
|
|
|
|
|
2016-09-20 02:29:28 +02:00
|
|
|
fn read(&self, file: usize, buffer: &mut [u8]) -> Result<usize> {
|
2016-09-19 02:59:46 +02:00
|
|
|
// Ensures that the length of the buffer is larger than the size of a usize
|
|
|
|
if buffer.len() >= mem::size_of::<usize>() {
|
2016-10-20 23:49:17 +02:00
|
|
|
let ack = ACKS.lock()[file];
|
|
|
|
let current = COUNTS.lock()[file];
|
|
|
|
if ack != current {
|
|
|
|
// Safe if the length of the buffer is larger than the size of a usize
|
|
|
|
assert!(buffer.len() >= mem::size_of::<usize>());
|
|
|
|
unsafe { *(buffer.as_mut_ptr() as *mut usize) = current; }
|
|
|
|
Ok(mem::size_of::<usize>())
|
|
|
|
} else {
|
|
|
|
Ok(0)
|
2016-09-19 02:59:46 +02:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-21 00:23:28 +02:00
|
|
|
Err(Error::new(EINVAL))
|
2016-09-19 02:59:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-20 02:29:28 +02:00
|
|
|
fn write(&self, file: usize, buffer: &[u8]) -> Result<usize> {
|
2016-09-19 04:17:08 +02:00
|
|
|
if buffer.len() >= mem::size_of::<usize>() {
|
|
|
|
assert!(buffer.len() >= mem::size_of::<usize>());
|
2016-09-19 17:43:30 +02:00
|
|
|
let ack = unsafe { *(buffer.as_ptr() as *const usize) };
|
2016-09-19 04:17:08 +02:00
|
|
|
let current = COUNTS.lock()[file];
|
2016-09-19 17:43:30 +02:00
|
|
|
if ack == current {
|
|
|
|
ACKS.lock()[file] = ack;
|
2016-09-19 04:17:08 +02:00
|
|
|
unsafe { acknowledge(file); }
|
2016-09-20 01:28:22 +02:00
|
|
|
Ok(mem::size_of::<usize>())
|
2016-09-19 04:17:08 +02:00
|
|
|
} else {
|
2016-09-20 01:28:22 +02:00
|
|
|
Ok(0)
|
2016-09-19 04:17:08 +02:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-21 00:23:28 +02:00
|
|
|
Err(Error::new(EINVAL))
|
2016-09-19 04:17:08 +02:00
|
|
|
}
|
2016-09-19 02:59:46 +02:00
|
|
|
}
|
|
|
|
|
2016-10-15 04:12:21 +02:00
|
|
|
fn fevent(&self, file: usize, _flags: usize) -> Result<usize> {
|
|
|
|
Ok(file)
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
}
|
|
|
|
|
2016-09-21 00:23:28 +02:00
|
|
|
fn fsync(&self, _file: usize) -> Result<usize> {
|
|
|
|
Ok(0)
|
2016-09-19 02:59:46 +02:00
|
|
|
}
|
|
|
|
|
2016-09-21 00:23:28 +02:00
|
|
|
fn close(&self, _file: usize) -> Result<usize> {
|
|
|
|
Ok(0)
|
2016-09-19 02:59:46 +02:00
|
|
|
}
|
|
|
|
}
|