Merge changes Ia2c90b0c,I3306214a into main
* changes:
vmbase: Replace emergency_write_str with eprintln!
vmbase: bionic: Replace eprintln!() with error!()
diff --git a/rialto/src/exceptions.rs b/rialto/src/exceptions.rs
index b806b08..e87e0d3 100644
--- a/rialto/src/exceptions.rs
+++ b/rialto/src/exceptions.rs
@@ -15,7 +15,6 @@
//! Exception handlers.
use vmbase::{
- console::emergency_write_str,
eprintln,
exceptions::{ArmException, Esr, HandleExceptionError},
logger,
@@ -49,45 +48,45 @@
#[no_mangle]
extern "C" fn irq_current() {
- emergency_write_str("irq_current\n");
+ eprintln!("irq_current");
reboot();
}
#[no_mangle]
extern "C" fn fiq_current() {
- emergency_write_str("fiq_current\n");
+ eprintln!("fiq_current");
reboot();
}
#[no_mangle]
extern "C" fn serr_current() {
- emergency_write_str("serr_current\n");
+ eprintln!("serr_current");
print_esr();
reboot();
}
#[no_mangle]
extern "C" fn sync_lower() {
- emergency_write_str("sync_lower\n");
+ eprintln!("sync_lower");
print_esr();
reboot();
}
#[no_mangle]
extern "C" fn irq_lower() {
- emergency_write_str("irq_lower\n");
+ eprintln!("irq_lower");
reboot();
}
#[no_mangle]
extern "C" fn fiq_lower() {
- emergency_write_str("fiq_lower\n");
+ eprintln!("fiq_lower");
reboot();
}
#[no_mangle]
extern "C" fn serr_lower() {
- emergency_write_str("serr_lower\n");
+ eprintln!("serr_lower");
print_esr();
reboot();
}
diff --git a/vmbase/README.md b/vmbase/README.md
index 280d7e1..28d930a 100644
--- a/vmbase/README.md
+++ b/vmbase/README.md
@@ -76,10 +76,10 @@
must use the C ABI, and have the expected names. For example, to log sync exceptions and reboot:
```rust
-use vmbase::{console::emergency_write_str, power::reboot};
+use vmbase::power::reboot;
extern "C" fn sync_exception_current() {
- emergency_write_str("sync_exception_current\n");
+ eprintln!("sync_exception_current");
let mut esr: u64;
unsafe {
@@ -93,14 +93,9 @@
The `println!` macro shouldn't be used in exception handlers, because it relies on a global instance
of the UART driver which might be locked when the exception happens, which would result in deadlock.
-Instead you can use `emergency_write_str` and `eprintln!`, which will re-initialize the UART every
-time to ensure that it can be used. This should still be used with care, as it may interfere with
-whatever the rest of the program is doing with the UART.
-
-Note also that in some cases when the system is in a bad state resulting in the stack not working
-properly, `eprintln!` may hang. `emergency_write_str` may be more reliable as it seems to avoid
-any stack allocation. This is why the example above uses `emergency_write_str` first to ensure that
-at least something is logged, before trying `eprintln!` to print more details.
+Instead you can use `eprintln!`, which will re-initialize the UART every time to ensure that it can
+be used. This should still be used with care, as it may interfere with whatever the rest of the
+program is doing with the UART.
See [example/src/exceptions.rs](examples/src/exceptions.rs) for a complete example.
diff --git a/vmbase/src/bionic.rs b/vmbase/src/bionic.rs
index 8470e92..6ea8d60 100644
--- a/vmbase/src/bionic.rs
+++ b/vmbase/src/bionic.rs
@@ -14,7 +14,6 @@
//! Low-level compatibility layer between baremetal Rust and Bionic C functions.
-use crate::eprintln;
use crate::rand::fill_with_entropy;
use crate::read_sysreg;
use core::ffi::c_char;
@@ -120,7 +119,7 @@
if let (Ok(prefix), Ok(format)) = (prefix.to_str(), format.to_str()) {
// We don't bother with printf formatting.
- eprintln!("FATAL BIONIC ERROR: {prefix}: \"{format}\" (unformatted)");
+ error!("FATAL BIONIC ERROR: {prefix}: \"{format}\" (unformatted)");
}
}
@@ -216,9 +215,9 @@
let error = cstr_error(get_errno()).to_str().unwrap();
if let Some(prefix) = prefix {
- eprintln!("{prefix}: {error}");
+ error!("{prefix}: {error}");
} else {
- eprintln!("{error}");
+ error!("{error}");
}
}