]> Witch of Git - jade-mouse/blob - toolchain/src/inst.rs
Minor ISA changes
[jade-mouse] / toolchain / src / inst.rs
1 mod decode;
2 mod encode;
3
4 use std::cmp::PartialEq;
5
6 #[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq)]
7 pub enum Reg {
8 R0,
9 R1,
10 R2,
11 R3,
12 }
13
14 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
15 #[repr(u8)]
16 pub enum LdSt {
17 Ld,
18 St,
19 }
20
21 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
22 pub enum Op1 {
23 Inc,
24 Dec,
25 Neg,
26 Compl,
27 }
28
29 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
30 pub enum OpI {
31 Add(I8),
32 Lsl(U4),
33 Lsr(U4),
34 Asr(U4),
35 Rol(U4),
36 }
37
38 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
39 pub enum Op2 {
40 Add,
41 Sub,
42 And,
43 Or,
44 Xor,
45 // These are preliminary
46 Lsl,
47 Rol,
48 Bic,
49 }
50
51 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
52 pub struct U4(i8);
53 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
54 pub struct I5(i8);
55 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
56 pub struct I7(i8);
57 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
58 pub struct U7(u8);
59 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
60 pub struct U8(u8);
61 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
62 pub struct I8(i8);
63
64 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
65 #[repr(u8)]
66 pub enum Size {
67 Byte,
68 Word,
69 }
70
71 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
72 #[repr(u8)]
73 pub enum Half {
74 Low,
75 High,
76 }
77
78 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
79 pub enum Addr {
80 Fixed(U7),
81 Reg(Reg),
82 Extended{
83 base: Reg,
84 offset: I5,
85 stack: bool,
86 size: Size,
87 },
88 }
89
90 #[derive(Clone, Copy, Debug, Eq)]
91 pub enum Cond {
92 Eq(Reg, Reg),
93 Ne(Reg, Reg),
94 Test(Reg ,Reg),
95 TestNot(Reg, Reg),
96 Lt(Reg, Reg),
97 Ult(Reg, Reg),
98 }
99
100 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
101 pub enum Inst {
102 Halt,
103 Nope,
104 Alu2(Reg, Op2, Reg),
105 Jalr(Reg),
106 Move(Reg, Reg),
107 Alu1(Reg, Op1),
108 Mem(LdSt, Reg, Addr),
109 Branch(Cond, I7),
110 JumpI(I8),
111 AluI(Reg, OpI),
112 LdImm(Half, Reg, U8),
113 }
114
115 impl PartialEq for Cond {
116 fn eq(&self, other: &Cond) -> bool {
117 use Cond::*;
118 match (self, other) {
119 (Eq(a1, b1), Eq(a2, b2)) => (a1, b1) == (a2, b2) || (a1, b1) == (b2, a2),
120 (Ne(a1, b1), Ne(a2, b2)) => (a1, b1) == (a2, b2) || (a1, b1) == (b2, a2),
121 (Test(a1, b1), Test(a2, b2)) => (a1, b1) == (a2, b2) || (a1, b1) == (b2, a2),
122 (TestNot(a1, b1), TestNot(a2, b2)) => (a1, b1) == (a2, b2) || (a1, b1) == (b2, a2),
123 (Lt(a1, b1), Lt(a2, b2)) => (a1, b1) == (a2, b2),
124 (Ult(a1, b1), Ult(a2, b2)) => (a1, b1) == (a2, b2),
125 _ => false,
126 }
127 }
128 }