Skip to content

Commit

Permalink
feat(arch-ops): holeybytes 16-bit relaxed relative offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
ondra05 committed Sep 29, 2023
1 parent 8a75480 commit 5b0f262
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 58 deletions.
12 changes: 11 additions & 1 deletion arch-ops/src/holeybytes/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use {
super::{Instruction, Operands},
crate::{
holeybytes::{
OpsA, OpsO, OpsRRA, OpsRRAH, OpsRRO, OpsRROH, OpsRRP, Relative16, Relative32,
OpsA, OpsO, OpsP, OpsRRA, OpsRRAH, OpsRRO, OpsRROH, OpsRRP, OpsRRPH, Relative16,
Relative32,
},
traits::InsnWrite,
},
Expand Down Expand Up @@ -92,6 +93,11 @@ impl<W: InsnWrite> HbEncoder<W> {
self.write_addr(32, addr, true)?;
self.write_all(&i0.to_le_bytes())
},
Operands::OpsRRPH(OpsRRPH(r0, r1, Relative16(addr), i0)) => {
self.write_all(&[r0.0, r1.0])?;
self.write_addr(16, addr, true)?;
self.write_all(&i0.to_le_bytes())
},
Operands::OpsRRO(OpsRRO(r0, r1, Relative32(addr))) => {
self.write_all(&[r0.0, r1.0])?;
self.write_addr(32, addr, true)
Expand All @@ -103,9 +109,13 @@ impl<W: InsnWrite> HbEncoder<W> {
Operands::OpsA(OpsA(addr)) => {
self.write_addr(64, addr, false)
},

Operands::OpsO(OpsO(Relative32(addr))) => {
self.write_addr(32, addr, true)
},
Operands::OpsP(OpsP(Relative16(addr))) => {
self.write_addr(16, addr, true)
},
};
}
}
Expand Down
119 changes: 62 additions & 57 deletions arch-ops/src/holeybytes/instructions.in
Original file line number Diff line number Diff line change
@@ -1,64 +1,69 @@
// OPCODE, MNEMONIC, TYPE, DOC;

0, UN, N, "Cause an unreachable code trap" ;
1, TX, N, "Termiante execution" ;
2, NOP, N, "Do nothing" ;
0, UN, N, "Cause an unreachable code trap" ;
1, TX, N, "Termiante execution" ;
2, NOP, N, "Do nothing" ;

3, ADD, RRR, "Addition" ;
4, SUB, RRR, "Subtraction" ;
5, MUL, RRR, "Multiplication" ;
6, AND, RRR, "Bitand" ;
7, OR, RRR, "Bitor" ;
8, XOR, RRR, "Bitxor" ;
9, SL, RRR, "Unsigned left bitshift" ;
10, SR, RRR, "Unsigned right bitshift" ;
11, SRS, RRR, "Signed right bitshift" ;
12, CMP, RRR, "Signed comparsion" ;
13, CMPU, RRR, "Unsigned comparsion" ;
14, DIR, RRRR, "Merged divide-remainder" ;
15, NOT, RR, "Logical negation" ;
16, ADDI, RRD, "Addition with immediate" ;
17, MULI, RRD, "Multiplication with immediate" ;
18, ANDI, RRD, "Bitand with immediate" ;
19, ORI, RRD, "Bitor with immediate" ;
20, XORI, RRD, "Bitxor with immediate" ;
21, SLI, RRW, "Unsigned left bitshift with immedidate";
22, SRI, RRW, "Unsigned right bitshift with immediate";
23, SRSI, RRW, "Signed right bitshift with immediate" ;
24, CMPI, RRD, "Signed compare with immediate" ;
25, CMPUI, RRD, "Unsigned compare with immediate" ;
3, ADD, RRR, "Addition" ;
4, SUB, RRR, "Subtraction" ;
5, MUL, RRR, "Multiplication" ;
6, AND, RRR, "Bitand" ;
7, OR, RRR, "Bitor" ;
8, XOR, RRR, "Bitxor" ;
9, SL, RRR, "Unsigned left bitshift" ;
10, SR, RRR, "Unsigned right bitshift" ;
11, SRS, RRR, "Signed right bitshift" ;
12, CMP, RRR, "Signed comparsion" ;
13, CMPU, RRR, "Unsigned comparsion" ;
14, DIR, RRRR, "Merged divide-remainder" ;
15, NOT, RR, "Logical negation" ;
16, ADDI, RRD, "Addition with immediate" ;
17, MULI, RRD, "Multiplication with immediate" ;
18, ANDI, RRD, "Bitand with immediate" ;
19, ORI, RRD, "Bitor with immediate" ;
20, XORI, RRD, "Bitxor with immediate" ;
21, SLI, RRW, "Unsigned left bitshift with immedidate";
22, SRI, RRW, "Unsigned right bitshift with immediate";
23, SRSI, RRW, "Signed right bitshift with immediate" ;
24, CMPI, RRD, "Signed compare with immediate" ;
25, CMPUI, RRD, "Unsigned compare with immediate" ;

26, CP, RR, "Copy register" ;
27, SWA, RR, "Swap registers" ;
28, LI, RD, "Load immediate" ;
29, LRA, RRO, "Load relative address" ;
30, LD, RRAH, "Load from absolute address" ;
31, ST, RRAH, "Store to absolute address" ;
32, LDR, RROH, "Load from relative address" ;
33, STR, RROH, "Store to absolute address" ;
34, BMC, RRH, "Copy block of memory" ;
35, BRC, RRB, "Copy register block" ;
26, CP, RR, "Copy register" ;
27, SWA, RR, "Swap registers" ;
28, LI, RD, "Load immediate" ;
29, LRA, RRO, "Load relative address" ;
30, LD, RRAH, "Load from absolute address" ;
31, ST, RRAH, "Store to absolute address" ;
32, LDR, RROH, "Load from relative address" ;
33, STR, RROH, "Store to relative address" ;
34, BMC, RRH, "Copy block of memory" ;
35, BRC, RRB, "Copy register block" ;

36, JMP, A, "Absolute jump" ;
37, JMPR, O, "Relative jump" ;
38, JAL, RRA, "Linking absolute jump" ;
39, JALR, RRO, "Linking relative jump" ;
40, JEQ, RRP, "Branch on equal" ;
41, JNE, RRP, "Branch on nonequal" ;
42, JLT, RRP, "Branch on lesser-than (signed)" ;
43, JGT, RRP, "Branch on greater-than (signed)" ;
44, JLTU, RRP, "Branch on lesser-than (unsigned)" ;
45, JGTU, RRP, "Branch on greater-than (unsigned)" ;
46, ECALL, N, "Issue ecall trap" ;
36, JMP, A, "Absolute jump" ;
37, JMPR, O, "Relative jump" ;
38, JAL, RRA, "Linking absolute jump" ;
39, JALR, RRO, "Linking relative jump" ;
40, JEQ, RRP, "Branch on equal" ;
41, JNE, RRP, "Branch on nonequal" ;
42, JLT, RRP, "Branch on lesser-than (signed)" ;
43, JGT, RRP, "Branch on greater-than (signed)" ;
44, JLTU, RRP, "Branch on lesser-than (unsigned)" ;
45, JGTU, RRP, "Branch on greater-than (unsigned)" ;
46, ECALL, N, "Issue ecall trap" ;

47, ADDF, RRR, "Floating addition" ;
48, SUBF, RRR, "Floating subtraction" ;
49, MULF, RRR, "Floating multiply" ;
50, DIRF, RRRR, "Merged floating divide-remainder" ;
51, FMAF, RRRR, "Fused floating multiply-add" ;
52, NEGF, RR, "Floating sign negation" ;
53, ITF, RR, "Int to float" ;
54, FTI, RR, "Float to int" ;
47, ADDF, RRR, "Floating addition" ;
48, SUBF, RRR, "Floating subtraction" ;
49, MULF, RRR, "Floating multiply" ;
50, DIRF, RRRR, "Merged floating divide-remainder" ;
51, FMAF, RRRR, "Fused floating multiply-add" ;
52, NEGF, RR, "Floating sign negation" ;
53, ITF, RR, "Int to float" ;
54, FTI, RR, "Float to int" ;

55, ADDFI, RRD, "Floating addition with immediate" ;
56, MULFI, RRD, "Floating multiplication with immediate";
55, ADDFI, RRD, "Floating addition with immediate" ;
56, MULFI, RRD, "Floating multiplication with immediate";

57, LRA16 , RRP, "Load relative immediate (16 bit)" ;
58, LDR16 , RRPH, "Load from relative address (16 bit)" ;
59, STR16 , RRPH, "Store to relative address (16 bit)" ;
60, JMPR16, P, "Relative jump (16 bit)" ;
2 changes: 2 additions & 0 deletions arch-ops/src/holeybytes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ define_operands! {
+ OpsRRA (Register , Register, Address ),
+ OpsRRAH (Register , Register, Address , u16 ),
+ OpsRROH (Register , Register, Relative32, u16 ),
+ OpsRRPH (Register , Register, Relative16, u16 ),
+ OpsRRO (Register , Register, Relative32 ),
+ OpsRRP (Register , Register, Relative16 ),
+ OpsA (Address ),
+ OpsO (Relative32 ),
+ OpsP (Relative16 ),
= OpsN ( ),
}

Expand Down

0 comments on commit 5b0f262

Please sign in to comment.