2016-10-08 04:18:05 +02:00
|
|
|
#![feature(asm)]
|
|
|
|
|
|
|
|
extern crate dma;
|
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
|
|
|
extern crate event;
|
2016-10-23 03:13:57 +02:00
|
|
|
extern crate netutils;
|
2016-10-08 04:18:05 +02:00
|
|
|
extern crate syscall;
|
|
|
|
|
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 std::cell::RefCell;
|
2016-11-11 04:02:51 +01:00
|
|
|
use std::env;
|
2016-10-08 04:18:05 +02:00
|
|
|
use std::fs::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
|
|
|
use std::io::{Read, Write, Result};
|
2016-10-20 20:52:58 +02:00
|
|
|
use std::os::unix::io::{AsRawFd, FromRawFd};
|
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 std::sync::Arc;
|
2016-10-08 04:18:05 +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 event::EventQueue;
|
|
|
|
use syscall::{Packet, Scheme, MAP_WRITE};
|
|
|
|
use syscall::error::EWOULDBLOCK;
|
2016-10-09 04:36:51 +02:00
|
|
|
|
|
|
|
pub mod device;
|
2016-10-08 04:18:05 +02:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut args = env::args().skip(1);
|
|
|
|
|
|
|
|
let bar_str = args.next().expect("e1000d: no address provided");
|
|
|
|
let bar = usize::from_str_radix(&bar_str, 16).expect("e1000d: failed to parse address");
|
|
|
|
|
|
|
|
let irq_str = args.next().expect("e1000d: no irq provided");
|
|
|
|
let irq = irq_str.parse::<u8>().expect("e1000d: failed to parse irq");
|
|
|
|
|
2016-10-23 03:35:23 +02:00
|
|
|
print!("{}", format!(" + E1000 on: {:X}, IRQ: {}\n", bar, irq));
|
|
|
|
|
2016-11-11 04:02:51 +01:00
|
|
|
// Daemonize
|
|
|
|
if unsafe { syscall::clone(0).unwrap() } == 0 {
|
2016-10-20 20:52:58 +02:00
|
|
|
let socket_fd = syscall::open(":network", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK).expect("e1000d: failed to create network scheme");
|
|
|
|
let socket = Arc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) }));
|
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 address = unsafe { syscall::physmap(bar, 128*1024, MAP_WRITE).expect("e1000d: failed to map address") };
|
2016-10-08 04:18:05 +02:00
|
|
|
{
|
2016-10-23 03:35:23 +02:00
|
|
|
let device = Arc::new(unsafe { device::Intel8254x::new(address).expect("e1000d: failed to allocate device") });
|
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-10-23 01:14:52 +02:00
|
|
|
let mut event_queue = EventQueue::<usize>::new().expect("e1000d: failed to create event queue");
|
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 todo = Arc::new(RefCell::new(Vec::<Packet>::new()));
|
|
|
|
|
|
|
|
let device_irq = device.clone();
|
|
|
|
let socket_irq = socket.clone();
|
|
|
|
let todo_irq = todo.clone();
|
|
|
|
let mut irq_file = File::open(format!("irq:{}", irq)).expect("e1000d: failed to open IRQ file");
|
2016-10-23 01:14:52 +02:00
|
|
|
event_queue.add(irq_file.as_raw_fd(), move |_count: usize| -> Result<Option<usize>> {
|
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 mut irq = [0; 8];
|
|
|
|
irq_file.read(&mut irq)?;
|
|
|
|
if unsafe { device_irq.irq() } {
|
|
|
|
irq_file.write(&mut irq)?;
|
|
|
|
|
|
|
|
let mut todo = todo_irq.borrow_mut();
|
|
|
|
let mut i = 0;
|
|
|
|
while i < todo.len() {
|
|
|
|
let a = todo[i].a;
|
|
|
|
device_irq.handle(&mut todo[i]);
|
|
|
|
if todo[i].a == (-EWOULDBLOCK) as usize {
|
|
|
|
todo[i].a = a;
|
|
|
|
i += 1;
|
|
|
|
} else {
|
|
|
|
socket_irq.borrow_mut().write(&mut todo[i])?;
|
|
|
|
todo.remove(i);
|
|
|
|
}
|
|
|
|
}
|
2016-10-23 23:26:36 +02:00
|
|
|
|
|
|
|
let next_read = device_irq.next_read();
|
|
|
|
if next_read > 0 {
|
|
|
|
return Ok(Some(next_read));
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
Ok(None)
|
|
|
|
}).expect("e1000d: failed to catch events on IRQ file");
|
|
|
|
|
2016-10-23 01:14:52 +02:00
|
|
|
let socket_packet = socket.clone();
|
|
|
|
event_queue.add(socket_fd, move |_count: usize| -> Result<Option<usize>> {
|
2016-10-26 21:19:56 +02:00
|
|
|
loop {
|
|
|
|
let mut packet = Packet::default();
|
|
|
|
if socket_packet.borrow_mut().read(&mut packet)? == 0 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
let a = packet.a;
|
|
|
|
device.handle(&mut packet);
|
|
|
|
if packet.a == (-EWOULDBLOCK) as usize {
|
|
|
|
packet.a = a;
|
|
|
|
todo.borrow_mut().push(packet);
|
|
|
|
} else {
|
|
|
|
socket_packet.borrow_mut().write(&mut packet)?;
|
|
|
|
}
|
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-10-23 23:38:49 +02:00
|
|
|
let next_read = device.next_read();
|
|
|
|
if next_read > 0 {
|
|
|
|
return Ok(Some(next_read));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
Ok(None)
|
|
|
|
}).expect("e1000d: failed to catch events on IRQ file");
|
|
|
|
|
2016-10-26 21:19:56 +02:00
|
|
|
for event_count in event_queue.trigger_all(0).expect("e1000d: failed to trigger 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");
|
|
|
|
}
|
|
|
|
|
2016-10-23 01:14:52 +02:00
|
|
|
loop {
|
|
|
|
let event_count = event_queue.run().expect("e1000d: failed to handle events");
|
|
|
|
|
2016-10-26 21:19:56 +02:00
|
|
|
socket.borrow_mut().write(&Packet {
|
2016-10-23 01:14:52 +02:00
|
|
|
id: 0,
|
|
|
|
pid: 0,
|
|
|
|
uid: 0,
|
|
|
|
gid: 0,
|
|
|
|
a: syscall::number::SYS_FEVENT,
|
|
|
|
b: 0,
|
|
|
|
c: syscall::flag::EVENT_READ,
|
|
|
|
d: event_count
|
2016-10-26 21:19:56 +02:00
|
|
|
}).expect("e1000d: failed to write event");
|
2016-10-23 01:14:52 +02:00
|
|
|
}
|
2016-10-08 04:18:05 +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
|
|
|
unsafe { let _ = syscall::physunmap(address); }
|
2016-11-11 04:02:51 +01:00
|
|
|
}
|
2016-10-08 04:18:05 +02:00
|
|
|
}
|