mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-01-20 21:18:26 +02:00
Add separate binary for minimal UART driver.
This commit is contained in:
parent
d6027f5080
commit
15518aa177
@ -4,5 +4,5 @@ Let's write a small program using our driver to write to the serial console, and
|
||||
bytes.
|
||||
|
||||
```rust,editable,compile_fail
|
||||
{{#include ../examples/src/main.rs:main}}
|
||||
{{#include ../examples/src/main_improved.rs:main}}
|
||||
```
|
||||
|
@ -13,3 +13,11 @@ spin = "0.9.4"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0.73"
|
||||
|
||||
[[bin]]
|
||||
name = "minimal"
|
||||
path = "src/main_minimal.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "improved"
|
||||
path = "src/main_improved.rs"
|
||||
|
@ -17,8 +17,16 @@
|
||||
build:
|
||||
cargo build
|
||||
|
||||
ap-examples.bin: build
|
||||
aarch64-linux-gnu-objcopy -O binary target/aarch64-unknown-none/debug/ap-examples ap-examples.bin
|
||||
minimal.bin: build
|
||||
aarch64-linux-gnu-objcopy -O binary target/aarch64-unknown-none/debug/minimal minimal.bin
|
||||
improved.bin: build
|
||||
aarch64-linux-gnu-objcopy -O binary target/aarch64-unknown-none/debug/improved improved.bin
|
||||
|
||||
qemu: ap-examples.bin
|
||||
qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel ap-examples.bin -s
|
||||
qemu_minimal: minimal.bin
|
||||
qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel minimal.bin -s
|
||||
qemu: improved.bin
|
||||
qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel improved.bin -s
|
||||
|
||||
clean:
|
||||
cargo clean
|
||||
rm -f *.bin
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
mod exceptions;
|
||||
mod pl011;
|
||||
mod pl011_minimal;
|
||||
|
||||
use crate::pl011::Uart;
|
||||
use core::{fmt::Write, panic::PanicInfo};
|
47
src/bare-metal/aps/examples/src/main_minimal.rs
Normal file
47
src/bare-metal/aps/examples/src/main_minimal.rs
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright 2023 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ANCHOR: main
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
mod exceptions;
|
||||
mod pl011_minimal;
|
||||
|
||||
use crate::pl011_minimal::Uart;
|
||||
use core::{fmt::Write, panic::PanicInfo};
|
||||
use log::error;
|
||||
use psci::system_off;
|
||||
|
||||
/// Base address of the primary PL011 UART.
|
||||
pub const PL011_BASE_ADDRESS: usize = 0x900_0000;
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn main(x0: u64, x1: u64, x2: u64, x3: u64) {
|
||||
// Safe because `PL011_BASE_ADDRESS` is the base address of a PL011 device,
|
||||
// and nothing else accesses that address range.
|
||||
let mut uart = unsafe { Uart::new(PL011_BASE_ADDRESS) };
|
||||
|
||||
writeln!(uart, "main({:#x}, {:#x}, {:#x}, {:#x})", x0, x1, x2, x3).unwrap();
|
||||
|
||||
system_off().unwrap();
|
||||
}
|
||||
// ANCHOR_END: main
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
error!("{}", info);
|
||||
system_off().unwrap();
|
||||
loop {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user