summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-27 23:13:06 -0400
committerIan Moffett <ian@osmora.org>2025-07-28 03:31:01 -0400
commiteffbb5ce401d3c8f78ff5465683a1bcd4a68c0b6 (patch)
tree0db7c50ddad509c340c6b51a7cbc48bd1669d210 /usr.bin
parent5e746b367abd36c3057130940dfad61636f5e925 (diff)
oasm: Introduce OR mnemonic
Implement mnemonic for the OR instruction: -- or x2, #3 ! x2 = x2 | 3 -- Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/oasm/emit.c8
-rw-r--r--usr.bin/oasm/include/oasm/lex.h1
-rw-r--r--usr.bin/oasm/lex.c3
-rw-r--r--usr.bin/oasm/parse.c5
4 files changed, 17 insertions, 0 deletions
diff --git a/usr.bin/oasm/emit.c b/usr.bin/oasm/emit.c
index ea14cce..ebbd824 100644
--- a/usr.bin/oasm/emit.c
+++ b/usr.bin/oasm/emit.c
@@ -393,6 +393,13 @@ emit_encode_bitw(struct emit_state *state, struct oasm_token *tok)
uint8_t opcode = OSMX64_AND;
char *inst_str = "and";
+ switch (tok->type) {
+ case TT_OR:
+ opcode = OSMX64_OR;
+ inst_str = "or";
+ break;
+ }
+
/* Next token should be a register */
tok = TAILQ_NEXT(tok, link);
if (tok == NULL) {
@@ -519,6 +526,7 @@ emit_process(struct oasm_state *oasm, struct emit_state *emit)
curtok = emit_encode_arith(emit, curtok);
break;
case TT_AND:
+ case TT_OR:
curtok = emit_encode_bitw(emit, curtok);
break;
case TT_BR:
diff --git a/usr.bin/oasm/include/oasm/lex.h b/usr.bin/oasm/include/oasm/lex.h
index 69e98ff..c542c72 100644
--- a/usr.bin/oasm/include/oasm/lex.h
+++ b/usr.bin/oasm/include/oasm/lex.h
@@ -104,6 +104,7 @@ typedef enum {
TT_MROD, /* 'mrod' */
TT_MROQ, /* 'mroq' */
TT_AND, /* 'and' */
+ TT_OR, /* 'or' */
/* Register ops */
TT_MOV, /* 'mov' */
diff --git a/usr.bin/oasm/lex.c b/usr.bin/oasm/lex.c
index 220cdb4..4c402be 100644
--- a/usr.bin/oasm/lex.c
+++ b/usr.bin/oasm/lex.c
@@ -55,6 +55,7 @@ static char putback = '\0';
#define S_IMN_MROD "mrod"
#define S_IMN_MROQ "mroq"
#define S_IMN_AND "and"
+#define S_IMN_OR "or"
/* Instruction length */
#define OSMX64_INST_LEN 4
@@ -245,6 +246,8 @@ token_bitw_mro(char *p)
return TT_MROQ;
} else if (strcmp(p, S_IMN_AND) == 0) {
return TT_AND;
+ } else if (strcmp(p, S_IMN_OR) == 0) {
+ return TT_OR;
}
return TT_UNKNOWN;
diff --git a/usr.bin/oasm/parse.c b/usr.bin/oasm/parse.c
index 523058b..b4bb7be 100644
--- a/usr.bin/oasm/parse.c
+++ b/usr.bin/oasm/parse.c
@@ -59,6 +59,7 @@ static const char *tokstr[] = {
[ TT_MROD ] = "mrod",
[ TT_MROQ ] = "mroq",
[ TT_AND ] = "and",
+ [ TT_OR ] = "or",
/* X<n> registers */
[ TT_X0 ] = "x0",
@@ -171,6 +172,10 @@ parse_tok(struct oasm_state *state, struct oasm_token *tok)
state->last = tok->type;
emit_osmx64(&emit_state, tok);
break;
+ case TT_OR:
+ state->last = tok->type;
+ emit_osmx64(&emit_state, tok);
+ break;
case TT_HLT:
state->last = tok->type;
emit_osmx64(&emit_state, tok);