Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions pixie-uefi/src/os/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use futures::channel::oneshot;
use spin::Mutex;
use uefi::proto::console::text::Color;

use crate::os;
use crate::os::executor::event::{Event, EventTrigger};
use crate::os::send_wrapper::SendWrapper;
use crate::os::timer::Timer;
Expand Down Expand Up @@ -239,11 +240,7 @@ impl Executor {
let task = EXECUTOR.lock().ready_tasks.pop_front();
let Some(task) = task else {
// If we don't have anything ready, sleep until the next interrupt.
// SAFETY: hlt is available on all reasonable x86 processors and has no safety
// requirements.
unsafe {
core::arch::asm!("hlt");
}
os::util::hlt();
do_wake(true);
continue;
};
Expand Down
10 changes: 10 additions & 0 deletions pixie-uefi/src/os/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use spin::Mutex;
use uefi::boot::ScopedProtocol;
use uefi::proto::console::text::{Input, Key};

use crate::os;
use crate::os::error::Result;
use crate::os::executor::Executor;
use crate::os::send_wrapper::SendWrapper;
Expand All @@ -21,3 +22,12 @@ pub async fn read_key() -> Result<Key> {
Executor::wait_for_interrupt().await;
}
}

pub fn wait_for_key() -> Result<()> {
loop {
os::util::hlt();
if INPUT.lock().read_key()?.is_some() {
return Ok(());
}
}
}
1 change: 1 addition & 0 deletions pixie-uefi/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod net;
mod send_wrapper;
mod timer;
pub mod ui;
pub mod util;

static INITIALIZED: AtomicBool = AtomicBool::new(false);

Expand Down
16 changes: 15 additions & 1 deletion pixie-uefi/src/os/net/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use uefi::Status;

use super::ETH_PACKET_SIZE;
use crate::os::send_wrapper::SendWrapper;
use crate::os::{input, ui};
use crate::power_control;

type Snp = SendWrapper<ScopedProtocol<SimpleNetwork>>;

Expand Down Expand Up @@ -68,7 +70,19 @@ impl TxToken for SnpTxToken<'_> {
snp.transmit(0, payload, None, None, None)
.expect("Failed to transmit frame");
// Wait until sending is complete.
while snp.get_recycled_transmit_buffer_status().unwrap().is_none() {}
while snp.get_recycled_transmit_buffer_status().unwrap().is_none() {
if snp.mode().media_present.0 == 0 {
let err = uefi::boot::set_watchdog_timer(0, 0x10000, None);
if let Err(err) = err {
if err.status() != Status::UNSUPPORTED {
log::error!("Error disabling watchdog: {err:?}");
}
}
ui::red_screen();
input::wait_for_key().expect("Failed to wait for input");
power_control::reset();
}
}
ret
}
}
Expand Down
10 changes: 10 additions & 0 deletions pixie-uefi/src/os/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,13 @@ pub fn update_content<F: Fn(&mut DrawArea)>(f: F) {
.try_lock()
.expect("content draw area is locked"));
}

pub fn red_screen() {
let mut s = SCREEN.lock();
s.back_buffer.fill(ScreenChar {
c: ' '.try_into().unwrap(),
fg: Color::Red,
bg: Color::Red,
});
s.flush();
}
7 changes: 7 additions & 0 deletions pixie-uefi/src/os/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn hlt() {
// SAFETY: hlt is available on all reasonable x86 processors and has no safety
// requirements.
unsafe {
core::arch::asm!("hlt");
}
}