From 3df46d197fa33907b5046db0034093178ec3450b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 21 Jan 2022 18:44:51 +0900 Subject: [PATCH] [gamecode] Add instructions for stack adjust, nop, and ldconst ldconst isn't implemented yet but the plan is to load various constants (eg, 0, 1, 2, pi, e, ...). Stack adjust is useful for adding an offset to the stack pointer without having to worry about finding it (and it checks for alignment). nop is just that :) --- libs/gamecode/opcodes.py | 30 ++++++++++++++++++++++++++++++ libs/gamecode/pr_exec.c | 12 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/libs/gamecode/opcodes.py b/libs/gamecode/opcodes.py index ac5aa5e51..d6cb80f6f 100644 --- a/libs/gamecode/opcodes.py +++ b/libs/gamecode/opcodes.py @@ -5,6 +5,9 @@ bitmap_txt = """ 0 0011 mmss pop 0 1ccc ttss compare 0 0000 00nn +0 0000 0000 noop +0 0000 0001 adjstk +0 0000 0010 constant 0 1011 nnnn 0 1111 nnnn @@ -75,6 +78,14 @@ etype_tt = ["ev_int", "ev_float", "ev_long", "ev_double"] unsigned_t = ["ev_uint", "ev_ulong"] float_t = ["ev_float", "ev_double"] +adjstk_formats = { + "opcode": "OP_ADJSTK", + "mnemonic": "adjstk", + "opname": "adjstk", + "format": "%sa, %sb", + "widths": "0, 0, 0", + "types": "ev_short, ev_short, ev_invalid", +} bitops_formats = { "opcode": "OP_{op_bit[oo].upper()}_{bit_type[t]}_{ss+1}", "mnemonic": "{op_bit[oo]}", @@ -157,6 +168,14 @@ compare2_formats = { "cmp_types": unsigned_t, }, } +constant_formats = { + "opcode": "OP_LDCONST", + "mnemonic": "ldconst", + "opname": "ldconst", + "format": "%sa, %sb, %gc", + "widths": "0, 0, -1", + "types": "ev_short, ev_short, ev_void", +} convert_formats = { "opcode": "OP_CONV", "mnemonic": "conv", @@ -268,6 +287,14 @@ move_formats = { ], }, } +noop_formats = { + "opcode": "OP_NOP", + "mnemonic": "nop", + "opname": "nop", + "format": "there were plums...", + "widths": "0, 0, 0", + "types": "ev_invalid, ev_invalid, ev_invalid", +} push_formats = { "opcode": "OP_PUSH_{op_mode[mm]}_{ss+1}", "mnemonic": "push", @@ -473,11 +500,13 @@ with_formats = { } group_map = { + "adjstk": adjstk_formats, "bitops": bitops_formats, "branch": branch_formats, "call": call_formats, "compare": compare_formats, "compare2": compare2_formats, + "constant": constant_formats, "convert": convert_formats, "hops": hops_formats, "jump": jump_formats, @@ -486,6 +515,7 @@ group_map = { "mathops": mathops_formats, "memset": memset_formats, "move": move_formats, + "noop": noop_formats, "push": push_formats, "pushregs": pushregs_formats, "pop": pop_formats, diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index 15885244c..a7581cbc4 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -2766,6 +2766,18 @@ pr_exec_ruamoko (progs_t *pr, int exitdepth) pr_opcode_e st_op = st->op & OP_MASK; switch (st_op) { // 0 0000 + case OP_NOP: + break; + case OP_ADJSTK: + if (st->a || (st->b & 3)) { + PR_RunError (pr, "invalid stack adjustment: %d, %d", + st->a, (short) st->b); + } + *pr->globals.stack += (short) st->b; + break; + case OP_LDCONST: + PR_RunError (pr, "OP_LDCONST not implemented"); + break; case OP_LOAD_B_1: case OP_LOAD_C_1: case OP_LOAD_D_1: