//! count — stream-input consumer (ADR 0006 Phase 3 gate). //! //! Reads lines through `get_line` until EOF or Abort, then reports how //! many it saw via `put_line`. Proves: USE pre-drain, TIL truncation, //! interactive pumping, and ^C abort across the task boundary. #![no_std] #![no_main] use rsapi::{Exports, StreamResult}; #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { loop { core::hint::spin_loop(); } } fn put_u32(exports: &Exports, mut v: u32) { // Small fixed buffer; u32 max is 10 digits. let mut buf = [0u8; 10]; let mut i = buf.len(); if v == 0 { i -= 1; buf[i] = b'0'; } while v > 0 { i -= 1; buf[i] = b'0' + (v % 10) as u8; v /= 10; } let suffix = b" line(s)"; let mut msg = [0u8; 18]; let n = buf.len() - i; msg[..n].copy_from_slice(&buf[i..]); msg[n..n + suffix.len()].copy_from_slice(suffix); (exports.put_line)(rsapi::Line { ptr: msg.as_ptr(), len: n + suffix.len(), }); } /// The image entry point — the loader jumps here with the ABI arguments. #[unsafe(no_mangle)] pub extern "C" fn efi_main( exports: &'static Exports, _argc: usize, _argv: *const rsapi::Arg, ) -> i32 { let mut count: u32 = 0; loop { let mut line = rsapi::Line { ptr: core::ptr::null(), len: 0, }; match (exports.get_line)(&mut line) { StreamResult::Line => count += 1, StreamResult::Eof => break, StreamResult::Abort => return 130, // 128+SIGINT convention } } put_u32(exports, count); 0 }