Nothing to see here, move along meow
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 1.2 kB View raw
1#![no_std] 2#![no_main] 3 4use lancer_core::ipc::pack_bytes; 5use lancer_user::syscall; 6 7const COM1_DATA: u64 = 0x3F8; 8const COM1_LSR: u64 = 0x3FD; 9 10const IRQ_CAP_SLOT: u64 = 2; 11const NOTIF_CAP_SLOT: u64 = 3; 12const ENDPOINT_SLOT: u64 = 1; 13 14const MAX_BYTES_PER_BATCH: usize = 40; 15 16#[unsafe(no_mangle)] 17pub extern "C" fn lancer_main() -> ! { 18 syscall::irq_ack(IRQ_CAP_SLOT); 19 20 loop { 21 let (_status, _bits) = syscall::notify_wait(NOTIF_CAP_SLOT); 22 23 let mut buf = [0u8; MAX_BYTES_PER_BATCH]; 24 let count = core::iter::from_fn(|| { 25 let lsr = syscall::io_in8(IRQ_CAP_SLOT, COM1_LSR); 26 if lsr < 0 { 27 return None; 28 } 29 if lsr as u8 & 0x01 != 0 { 30 let data = syscall::io_in8(IRQ_CAP_SLOT, COM1_DATA); 31 if data >= 0 { Some(data as u8) } else { None } 32 } else { 33 None 34 } 35 }) 36 .take(MAX_BYTES_PER_BATCH) 37 .enumerate() 38 .fold(0usize, |_, (i, ch)| { 39 buf[i] = ch; 40 i + 1 41 }); 42 43 if count > 0 { 44 let msg = pack_bytes(&buf[..count]); 45 syscall::send(ENDPOINT_SLOT, msg); 46 } 47 48 syscall::irq_ack(IRQ_CAP_SLOT); 49 } 50}