Skip to content

Commit 5a1d2a1

Browse files
committed
add 'rd8' and 'wr8' instrs
1 parent f1d6eea commit 5a1d2a1

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

impl.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
(((a) == (b)) << RVM_FEQBP) | \
2323
(((rvm_u64)(a) > (rvm_u64)(b)) << RVM_FABBP) | \
2424
(((rvm_i64)(a) > (rvm_i64)(b)) << RVM_FGTBP) );
25-
#define util_checkpc() do { \
26-
if (RVM_UNLIKELY(pc >= codesz)) { \
27-
inst = RVM_TRAP_EMEMV; \
28-
__RVM_DISPATCH; \
29-
} \
25+
#define util_checkpc() do { \
26+
if (RVM_UNLIKELY(pc >= codesz)) \
27+
return -RVM_EMEMV; \
28+
} while (0)
29+
#define util_checkaccs(addr, sz) do { \
30+
if (RVM_UNLIKELY((addr) > memsz - (sz))) \
31+
return -RVM_EMEMV; \
3032
} while (0)
3133
#define util_jmpif(expr, pcoff) do { \
3234
if ((expr)) { \
@@ -304,4 +306,18 @@ DEF(jbe) {
304306
vmnext;
305307
}
306308

309+
DEF(rd8) {
310+
rvm_reg_t addr = rgB + imm15s;
311+
util_checkaccs(addr, 1);
312+
rgA = RVM_DEC8(&mem[addr]);
313+
vmnext;
314+
}
315+
316+
DEF(wr8) {
317+
rvm_reg_t addr = rgB + imm15s;
318+
util_checkaccs(addr, 1);
319+
RVM_ENC8(rgA, &mem[addr]);
320+
vmnext;
321+
}
322+
307323
#endif /* impl.h */

opcodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,7 @@ DEF(jge, 45) /* [J] jump if gt or eq */
6767
DEF(jae, 46) /* [J] jump if ab or eq */
6868
DEF(jle, 47) /* [J] jump if not-gt */
6969
DEF(jbe, 48) /* [J] jump if not-ab */
70+
DEF(rd8, 49) /* [I] rgA = mem[rgB + imm15s] */
71+
DEF(wr8, 50) /* [I] mem[rgB + imm15s] = rgA */
7072

7173
#endif /* opcodes.h */

test/rd8_r0_r0_0_eq0x31

4 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)