kernel: debug: fix const warnings

This makes debug a const, which prevents it from getting copied all over
the place.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-01-13 21:08:32 +08:00
parent 4dfb8dec80
commit e87eb112ae
2 changed files with 32 additions and 20 deletions

View file

@ -4,27 +4,36 @@ use core::fmt::{Error, Write};
use utralib::generated::*; use utralib::generated::*;
#[macro_use] #[macro_use]
#[cfg(all(not(test), baremetal, any(feature = "debug-print", feature = "print-panics")))] #[cfg(all(
not(test),
baremetal,
any(feature = "debug-print", feature = "print-panics")
))]
pub mod debug_print_hardware { pub mod debug_print_hardware {
use crate::debug::*; // the HW device mapping is done in main.rs/init(); the virtual address has to be in the top 4MiB as it is the only page shared among all processes
pub const SUPERVISOR_UART: Uart = Uart { pub const SUPERVISOR_UART_ADDR: *mut usize = 0xffcf_0000 as *mut usize;
// the HW device mapping is done in main.rs/init(); the virtuall address has to be in the top 4MiB as it is the only page shared among all processes
base: 0xffcf_0000 as *mut usize,
};
#[macro_export] #[macro_export]
macro_rules! print macro_rules! print
{ {
($($args:tt)+) => ({ ($($args:tt)+) => ({
use core::fmt::Write; use core::fmt::Write;
let _ = write!(crate::debug::debug_print_hardware::SUPERVISOR_UART, $($args)+); let _ = write!(crate::debug::Uart {}, $($args)+);
}); });
} }
} }
#[cfg(all(not(test), baremetal, any(feature = "debug-print", feature = "print-panics")))] #[cfg(all(
pub use crate::debug::debug_print_hardware::SUPERVISOR_UART; not(test),
baremetal,
any(feature = "debug-print", feature = "print-panics")
))]
pub use crate::debug::debug_print_hardware::SUPERVISOR_UART_ADDR;
#[cfg(all(not(test), baremetal, not(any(feature = "debug-print", feature = "print-panics"))))] #[cfg(all(
not(test),
baremetal,
not(any(feature = "debug-print", feature = "print-panics"))
))]
#[macro_export] #[macro_export]
macro_rules! print { macro_rules! print {
($($args:tt)+) => {{ ($($args:tt)+) => {{
@ -49,19 +58,19 @@ macro_rules! println
#[cfg(baremetal)] #[cfg(baremetal)]
pub struct Uart { pub struct Uart {
pub base: *mut usize, // pub base: *mut usize,
} }
#[cfg(baremetal)] #[cfg(baremetal)]
impl Uart { impl Uart {
#[allow(dead_code)] #[allow(dead_code)]
pub fn enable_rx(self) { pub fn enable_rx(self) {
let mut uart_csr = CSR::new(self.base as *mut u32); let mut uart_csr = CSR::new(0xffcf_0000 as *mut u32);
uart_csr.rmwf(utra::uart::EV_ENABLE_RX, 1); uart_csr.rmwf(utra::uart::EV_ENABLE_RX, 1);
} }
pub fn putc(&self, c: u8) { pub fn putc(&self, c: u8) {
let mut uart_csr = CSR::new(self.base as *mut u32); let mut uart_csr = CSR::new(0xffcf_0000 as *mut u32);
// Wait until TXFULL is `0` // Wait until TXFULL is `0`
while uart_csr.r(utra::uart::TXFULL) != 0 { while uart_csr.r(utra::uart::TXFULL) != 0 {
() ()
@ -71,7 +80,7 @@ impl Uart {
#[allow(dead_code)] #[allow(dead_code)]
pub fn getc(&self) -> Option<u8> { pub fn getc(&self) -> Option<u8> {
let mut uart_csr = CSR::new(self.base as *mut u32); let mut uart_csr = CSR::new(0xffcf_0000 as *mut u32);
// If EV_PENDING_RX is 1, return the pending character. // If EV_PENDING_RX is 1, return the pending character.
// Otherwise, return None. // Otherwise, return None.
match uart_csr.rf(utra::uart::EV_PENDING_RX) { match uart_csr.rf(utra::uart::EV_PENDING_RX) {
@ -85,12 +94,16 @@ impl Uart {
} }
} }
#[cfg(all(not(test), baremetal, any(feature = "debug-print", feature = "print-panics")))] #[cfg(all(
not(test),
baremetal,
any(feature = "debug-print", feature = "print-panics")
))]
pub fn irq(_irq_number: usize, _arg: *mut usize) { pub fn irq(_irq_number: usize, _arg: *mut usize) {
println!( println!(
"Interrupt {}: Key pressed: {}", "Interrupt {}: Key pressed: {}",
_irq_number, _irq_number,
SUPERVISOR_UART Uart {}
.getc() .getc()
.expect("no character queued despite interrupt") as char .expect("no character queued despite interrupt") as char
); );
@ -123,8 +136,7 @@ macro_rules! klog
#[cfg(not(feature = "debug-print"))] #[cfg(not(feature = "debug-print"))]
#[macro_export] #[macro_export]
macro_rules! klog macro_rules! klog {
{
($($args:tt)+) => {{ ($($args:tt)+) => {{
() ()
}}; }};

View file

@ -65,7 +65,7 @@ pub extern "C" fn init(arg_offset: *const u32, init_offset: *const u32, rpt_offs
memory_manager memory_manager
.map_range( .map_range(
utra::uart::HW_UART_BASE as *mut u8, utra::uart::HW_UART_BASE as *mut u8,
((debug::SUPERVISOR_UART.base as u32) & !4095) as *mut u8, ((debug::SUPERVISOR_UART_ADDR as u32) & !4095) as *mut u8,
4096, 4096,
PID::new(1).unwrap(), PID::new(1).unwrap(),
MemoryFlags::R | MemoryFlags::W, MemoryFlags::R | MemoryFlags::W,
@ -74,7 +74,7 @@ pub extern "C" fn init(arg_offset: *const u32, init_offset: *const u32, rpt_offs
.expect("unable to map serial port") .expect("unable to map serial port")
}); });
println!("KMAIN: Supervisor mode started..."); println!("KMAIN: Supervisor mode started...");
debug::SUPERVISOR_UART.enable_rx(); debug::Uart{}.enable_rx();
println!("Claiming IRQ {} via syscall...", utra::uart::UART_IRQ); println!("Claiming IRQ {} via syscall...", utra::uart::UART_IRQ);
xous_kernel::claim_interrupt(utra::uart::UART_IRQ, debug::irq, 0 as *mut usize) xous_kernel::claim_interrupt(utra::uart::UART_IRQ, debug::irq, 0 as *mut usize)
.expect("Couldn't claim debug interrupt"); .expect("Couldn't claim debug interrupt");