Minor adaptions

pull/35/head
Andre Richter 5 years ago
parent 4a58672d4d
commit 515a96925d
No known key found for this signature in database
GPG Key ID: 2116C1AB102F615E

@ -10,6 +10,7 @@ enabled step-by-step in following tutorials.
- `interface.rs` is introduced:
- Provides `Traits` for abstracting `kernel` from `BSP` code.
- Panic handler `print!()`s supplied error messages.
- This is showcased in `main()`.
## Diff to previous
```diff
@ -41,7 +42,7 @@ diff -uNr 02_runtime_init/src/bsp/rpi3/panic_wait.rs 03_hacky_hello_world/src/bs
-fn panic(_info: &PanicInfo) -> ! {
+fn panic(info: &PanicInfo) -> ! {
+ if let Some(args) = info.message() {
+ println!("{}", args);
+ println!("Kernel panic: {}", args);
+ } else {
+ println!("Kernel panic!");
+ }
@ -121,9 +122,9 @@ diff -uNr 02_runtime_init/src/interface.rs 03_hacky_hello_world/src/interface.rs
+pub mod console {
+ /// Console write functions.
+ ///
+ /// `core::fmt::Write` is exactly what we need. Re-export it here because
+ /// implementing `console::Write` gives a better hint to the reader about
+ /// the intention.
+ /// `core::fmt::Write` is exactly what we need for now. Re-export it here
+ /// because implementing `console::Write` gives a better hint to the reader
+ /// about the intention.
+ pub use core::fmt::Write;
+
+ /// Console read functions.

Binary file not shown.

Binary file not shown.

@ -10,7 +10,7 @@ use core::panic::PanicInfo;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
if let Some(args) = info.message() {
println!("{}", args);
println!("Kernel panic: {}", args);
} else {
println!("Kernel panic!");
}

@ -22,9 +22,9 @@
pub mod console {
/// Console write functions.
///
/// `core::fmt::Write` is exactly what we need. Re-export it here because
/// implementing `console::Write` gives a better hint to the reader about
/// the intention.
/// `core::fmt::Write` is exactly what we need for now. Re-export it here
/// because implementing `console::Write` gives a better hint to the reader
/// about the intention.
pub use core::fmt::Write;
/// Console read functions.

@ -5,6 +5,8 @@
All hand-written assembly is replaced by Rust code from the [cortex-a] crate,
which provides zero-overhead abstractions and wraps the `unsafe` parts.
- `bsp::wait_forever()` is introduced.
[cortex-a]: https://github.com/rust-embedded/cortex-a
## Diff to previous
@ -115,6 +117,20 @@ diff -uNr 03_hacky_hello_world/src/bsp/rpi3.rs 04_zero_overhead_abstraction/src/
/// A mystical, magical device for generating QEMU output out of the void.
struct QEMUOutput;
@@ -37,6 +63,13 @@
// Implementation of the kernel's BSP calls
////////////////////////////////////////////////////////////////////////////////
+/// Park execution on the calling CPU core.
+pub fn wait_forever() -> ! {
+ loop {
+ asm::wfe()
+ }
+}
+
/// Returns a ready-to-use `console::Write` implementation.
pub fn console() -> impl interface::console::Write {
QEMUOutput {}
diff -uNr 03_hacky_hello_world/src/main.rs 04_zero_overhead_abstraction/src/main.rs
--- 03_hacky_hello_world/src/main.rs
@ -129,14 +145,16 @@ diff -uNr 03_hacky_hello_world/src/main.rs 04_zero_overhead_abstraction/src/main
#![feature(panic_info_message)]
#![no_main]
#![no_std]
@@ -33,7 +31,7 @@
@@ -33,7 +31,8 @@
/// Entrypoint of the `kernel`.
fn kernel_entry() -> ! {
- println!("Hello from Rust!");
+ println!("Hello from pure Rust!");
+ println!("[0] Hello from pure Rust!");
panic!("Stopping here.")
- panic!("Stopping here.")
+ println!("[1] Stopping here.");
+ bsp::wait_forever()
}
diff -uNr 03_hacky_hello_world/src/runtime_init.rs 04_zero_overhead_abstraction/src/runtime_init.rs

@ -63,6 +63,13 @@ impl interface::console::Write for QEMUOutput {
// Implementation of the kernel's BSP calls
////////////////////////////////////////////////////////////////////////////////
/// Park execution on the calling CPU core.
pub fn wait_forever() -> ! {
loop {
asm::wfe()
}
}
/// Returns a ready-to-use `console::Write` implementation.
pub fn console() -> impl interface::console::Write {
QEMUOutput {}

@ -11,7 +11,7 @@ use cortex_a::asm;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
if let Some(args) = info.message() {
println!("{}", args);
println!("Kernel panic: {}", args);
} else {
println!("Kernel panic!");
}

@ -22,9 +22,9 @@
pub mod console {
/// Console write functions.
///
/// `core::fmt::Write` is exactly what we need. Re-export it here because
/// implementing `console::Write` gives a better hint to the reader about
/// the intention.
/// `core::fmt::Write` is exactly what we need for now. Re-export it here
/// because implementing `console::Write` gives a better hint to the reader
/// about the intention.
pub use core::fmt::Write;
/// Console read functions.

@ -31,7 +31,8 @@ mod print;
/// Entrypoint of the `kernel`.
fn kernel_entry() -> ! {
println!("Hello from pure Rust!");
println!("[0] Hello from pure Rust!");
panic!("Stopping here.")
println!("[1] Stopping here.");
bsp::wait_forever()
}

Loading…
Cancel
Save