1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-24 03:10:28 +02:00

Implement Debug manually for IntId.

It's useful to say what kind of interrupt it is.
This commit is contained in:
Andrew Walbran 2023-04-12 16:43:57 +01:00
parent 2f442acda7
commit 011fbb3f5c

View File

@ -17,6 +17,7 @@
use bitflags::bitflags; use bitflags::bitflags;
use core::{ use core::{
arch::asm, arch::asm,
fmt::{self, Debug, Formatter},
hint::spin_loop, hint::spin_loop,
mem::size_of, mem::size_of,
ptr::{addr_of, addr_of_mut}, ptr::{addr_of, addr_of_mut},
@ -56,7 +57,7 @@ macro_rules! write_sysreg {
const SGI_OFFSET: usize = 0x10000; const SGI_OFFSET: usize = 0x10000;
/// An interrupt ID. /// An interrupt ID.
#[derive(Copy, Clone, Debug, Eq, Ord, PartialOrd, PartialEq)] #[derive(Copy, Clone, Eq, Ord, PartialOrd, PartialEq)]
pub struct IntId(u32); pub struct IntId(u32);
impl IntId { impl IntId {
@ -102,6 +103,20 @@ impl IntId {
} }
} }
impl Debug for IntId {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
if self.0 < Self::PPI_START {
write!(f, "SGI {}", self.0 - Self::SGI_START)
} else if self.0 < Self::SPI_START {
write!(f, "PPI {}", self.0 - Self::PPI_START)
} else if self.0 < Self::SPECIAL_START {
write!(f, "SPI {}", self.0 - Self::SPI_START)
} else {
write!(f, "Special IntId {}", self.0)
}
}
}
impl From<IntId> for u32 { impl From<IntId> for u32 {
fn from(intid: IntId) -> Self { fn from(intid: IntId) -> Self {
intid.0 intid.0