1 //! Implementations for the MIPS architecture.
2 
3 use gdbstub::arch::Arch;
4 
5 pub mod reg;
6 
7 /// MIPS-specific breakpoint kinds.
8 ///
9 /// Extracted from the GDB documentation at
10 /// [E.5.1.1 MIPS Breakpoint Kinds](https://sourceware.org/gdb/current/onlinedocs/gdb/MIPS-Breakpoint-Kinds.html#MIPS-Breakpoint-Kinds)
11 #[derive(Debug)]
12 pub enum MipsBreakpointKind {
13     /// 16-bit MIPS16 mode breakpoint.
14     Mips16,
15 
16     /// 16-bit microMIPS mode breakpoint.
17     MicroMips16,
18 
19     /// 32-bit standard MIPS mode breakpoint.
20     Mips32,
21 
22     /// 32-bit microMIPS mode breakpoint.
23     MicroMips32,
24 }
25 
26 impl gdbstub::arch::BreakpointKind for MipsBreakpointKind {
from_usize(kind: usize) -> Option<Self>27     fn from_usize(kind: usize) -> Option<Self> {
28         let kind = match kind {
29             2 => MipsBreakpointKind::Mips16,
30             3 => MipsBreakpointKind::MicroMips16,
31             4 => MipsBreakpointKind::Mips32,
32             5 => MipsBreakpointKind::MicroMips32,
33             _ => return None,
34         };
35         Some(kind)
36     }
37 }
38 
39 /// Implements `Arch` for 32-bit MIPS.
40 pub enum Mips {}
41 
42 /// Implements `Arch` for 32-bit MIPS, with the DSP feature enabled.
43 pub enum MipsWithDsp {}
44 
45 /// Implements `Arch` for 64-bit MIPS.
46 ///
47 /// **NOTE:** Due to GDB client behavior, this arch does _not_ include a
48 /// built-in `target.xml` implementation. Consider manually implementing
49 /// [`TargetDescriptionXmlOverride`].
50 ///
51 /// See [daniel5151/gdbstub#97](https://github.com/daniel5151/gdbstub/issues/97).
52 ///
53 /// [`TargetDescriptionXmlOverride`]: gdbstub::target::ext::target_description_xml_override::TargetDescriptionXmlOverride
54 pub enum Mips64 {}
55 
56 /// Implements `Arch` for 64-bit MIPS, with the DSP feature enabled.
57 ///
58 /// **NOTE:** Due to GDB client behavior, this arch does _not_ include a
59 /// built-in `target.xml` implementation. Consider manually implementing
60 /// [`TargetDescriptionXmlOverride`].
61 ///
62 /// See [daniel5151/gdbstub#97](https://github.com/daniel5151/gdbstub/issues/97).
63 ///
64 /// [`TargetDescriptionXmlOverride`]: gdbstub::target::ext::target_description_xml_override::TargetDescriptionXmlOverride
65 pub enum Mips64WithDsp {}
66 
67 impl Arch for Mips {
68     type Usize = u32;
69     type Registers = reg::MipsCoreRegs<u32>;
70     type RegId = reg::id::MipsRegId<u32>;
71     type BreakpointKind = MipsBreakpointKind;
72 
target_description_xml() -> Option<&'static str>73     fn target_description_xml() -> Option<&'static str> {
74         Some(r#"<target version="1.0"><architecture>mips</architecture></target>"#)
75     }
76 }
77 
78 impl Arch for MipsWithDsp {
79     type Usize = u32;
80     type Registers = reg::MipsCoreRegsWithDsp<u32>;
81     type RegId = reg::id::MipsRegId<u32>;
82     type BreakpointKind = MipsBreakpointKind;
83 
target_description_xml() -> Option<&'static str>84     fn target_description_xml() -> Option<&'static str> {
85         Some(
86             r#"<target version="1.0"><architecture>mips</architecture><feature name="org.gnu.gdb.mips.dsp"></feature></target>"#,
87         )
88     }
89 }
90 
91 #[allow(deprecated)]
92 impl Arch for Mips64 {
93     type Usize = u64;
94     type Registers = reg::MipsCoreRegs<u64>;
95     type RegId = reg::id::MipsRegId<u64>;
96     type BreakpointKind = MipsBreakpointKind;
97 
target_description_xml() -> Option<&'static str>98     fn target_description_xml() -> Option<&'static str> {
99         None
100     }
101 }
102 
103 #[allow(deprecated)]
104 impl Arch for Mips64WithDsp {
105     type Usize = u64;
106     type Registers = reg::MipsCoreRegsWithDsp<u64>;
107     type RegId = reg::id::MipsRegId<u64>;
108     type BreakpointKind = MipsBreakpointKind;
109 
target_description_xml() -> Option<&'static str>110     fn target_description_xml() -> Option<&'static str> {
111         None
112     }
113 }
114