vmbase: Improve safety of console::init()
As the console should only be accessed once it has been MMIO guarded and
mapped in the MMU, prevent eprintln!() from writing to the UART before
console::init() has been called.
Mark console::init() as unsafe, documenting the constraints on when it
should be called and, in the entry code, move it _after_ we've called
mmio_guard.map(UART_PAGE).
Move BASE_ADDRESS to the more appropriate layout module and allow the
caller to pass the UART base to console::init() and rename it UART_ADDR,
for clarity.
Test: m pvmfw librialto libvmbase_example
Change-Id: I9543765fd0429b38b45bc2e7b7c83bedf79194f3
diff --git a/vmbase/src/layout.rs b/vmbase/src/layout.rs
index 993141d..e65abda 100644
--- a/vmbase/src/layout.rs
+++ b/vmbase/src/layout.rs
@@ -16,7 +16,6 @@
pub mod crosvm;
-use crate::console;
use crate::linker::__stack_chk_guard;
use crate::memory::{page_4kb_of, PAGE_SIZE};
use aarch64_paging::paging::VirtualAddress;
@@ -27,9 +26,14 @@
/// First address that can't be translated by a level 1 TTBR0_EL1.
pub const MAX_VIRT_ADDR: usize = 1 << 40;
+/// Base memory-mapped address of the primary UART device.
+///
+/// See SERIAL_ADDR in https://crosvm.dev/book/appendix/memory_layout.html#common-layout.
+pub const UART_ADDR: usize = 0x3f8;
+
/// Address of the single page containing all the UART devices.
pub const UART_PAGE_ADDR: usize = 0;
-const_assert_eq!(UART_PAGE_ADDR, page_4kb_of(console::BASE_ADDRESS));
+const_assert_eq!(UART_PAGE_ADDR, page_4kb_of(UART_ADDR));
/// Get an address from a linker-defined symbol.
#[macro_export]