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::*;
#[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 {
use crate::debug::*;
pub const SUPERVISOR_UART: Uart = Uart {
// 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,
};
// 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_ADDR: *mut usize = 0xffcf_0000 as *mut usize;
#[macro_export]
macro_rules! print
{
($($args:tt)+) => ({
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")))]
pub use crate::debug::debug_print_hardware::SUPERVISOR_UART;
#[cfg(all(
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_rules! print {
($($args:tt)+) => {{
@ -49,19 +58,19 @@ macro_rules! println
#[cfg(baremetal)]
pub struct Uart {
pub base: *mut usize,
// pub base: *mut usize,
}
#[cfg(baremetal)]
impl Uart {
#[allow(dead_code)]
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);
}
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`
while uart_csr.r(utra::uart::TXFULL) != 0 {
()
@ -71,7 +80,7 @@ impl Uart {
#[allow(dead_code)]
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.
// Otherwise, return None.
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) {
println!(
"Interrupt {}: Key pressed: {}",
_irq_number,
SUPERVISOR_UART
Uart {}
.getc()
.expect("no character queued despite interrupt") as char
);
@ -123,8 +136,7 @@ macro_rules! klog
#[cfg(not(feature = "debug-print"))]
#[macro_export]
macro_rules! klog
{
macro_rules! klog {
($($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
.map_range(
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,
PID::new(1).unwrap(),
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")
});
println!("KMAIN: Supervisor mode started...");
debug::SUPERVISOR_UART.enable_rx();
debug::Uart{}.enable_rx();
println!("Claiming IRQ {} via syscall...", utra::uart::UART_IRQ);
xous_kernel::claim_interrupt(utra::uart::UART_IRQ, debug::irq, 0 as *mut usize)
.expect("Couldn't claim debug interrupt");