use core::fmt; use crate::operands::Word; // TODO: // typedef struct {int m3i1, m3i2; char *m3p1; char m3ca1[M3_STRING];} mess_3; // typedef struct {long m4l1, m4l2, m4l3, m4l4, m4l5;} mess_4; // typedef struct {char m5c1, m5c2; int m5i1, m5i2; long m5l1, m5l2, m5l3;}mess_5; // typedef struct {int m6i1, m6i2, m6i3; long m6l1; sighandler_t m6f1;} mess_6; #[derive(Debug, Clone)] // typedef struct {int m1i1, m1i2, m1i3; char *m1p1, *m1p2, *m1p3;} mess_1; pub struct Mess1 { pub i1: Word, pub i2: Word, pub i3: Word, pub p1: Word, pub p2: Word, pub p3: Word, } impl Mess1 { pub fn new(data: &Vec) -> Self { Self { i1: Word::from_le_bytes([data[4], data[5]]), i2: Word::from_le_bytes([data[6], data[7]]), i3: Word::from_le_bytes([data[8], data[9]]), p1: Word::from_le_bytes([data[10], data[11]]), p2: Word::from_le_bytes([data[12], data[13]]), p3: Word::from_le_bytes([data[14], data[15]]), } } } impl fmt::Display for Mess1 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "Mess1({} {} {} {} {} {})", self.i1, self.i2, self.i3, self.p1, self.p2, self.p3 ) } } #[derive(Debug, Clone)] // typedef struct {int m2i1, m2i2, m2i3; long m2l1, m2l2; char *m2p1;} mess_2; pub struct Mess2 { pub i1: Word, pub i2: Word, pub i3: Word, pub l1: Word, pub l2: Word, pub p1: Word, } impl Mess2 { pub fn new(data: &Vec) -> Self { Self { i1: Word::from_le_bytes([data[4], data[5]]), i2: Word::from_le_bytes([data[6], data[7]]), i3: Word::from_le_bytes([data[8], data[9]]), l1: Word::from_le_bytes([data[10], data[11]]), l2: Word::from_le_bytes([data[12], data[13]]), p1: Word::from_le_bytes([data[14], data[15]]), } } } impl fmt::Display for Mess2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "Mess1({} {} {} {} {} {})", self.i1, self.i2, self.i3, self.l1, self.l2, self.p1 ) } } #[derive(Debug, Clone)] /// First part of: include/minix/type.h:struct message /// The union-type will be handled differently, where I the data of each /// MessX type will be parsed, when needed for each specific interrupt. pub struct InterruptMessage { pub m_source: Word, pub m_type: Word, } impl InterruptMessage { pub fn new(data: &Vec) -> Self { Self { m_source: Word::from_le_bytes([data[0], data[1]]), m_type: Word::from_le_bytes([data[2], data[3]]), } } } impl fmt::Display for InterruptMessage { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Interrupt({}, {})", self.m_source, self.m_type) } }