summaryrefslogtreecommitdiff
path: root/usr.bin/oasm/lex.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-24 03:41:39 -0400
committerIan Moffett <ian@osmora.org>2025-07-24 03:50:04 -0400
commitaf7a0cf9b65d6fee20029fe67c95c494f4b402a7 (patch)
treebef5ae96cde9bad9cad5f3350a92072f58d594dd /usr.bin/oasm/lex.c
parent2de38a06acd1f8a392f1c6ea74a7b0aaa0de3692 (diff)
oasm: Add encoding for MRO type instructions
This commit introduces encoding logic for 4 additional instructions: - MROB (Mask Register Over [byte]) - MROW (Mask Register Over [word]) - MROD (Mask Register Over [dword]) - MROQ (Mask Register Over [qword]) This instruction is used to fill a register with a specific length of zeros or ones. For example, to fill a register (e.g., x2) with 16-bits of 1s: -- !! !! Clear bits x2[7:0]... Mrrp,, !! mrow!! !! mrow x2, #1 -- Similarly, an operand of zero sets it to zero. For example, to clear an entire 64-bit register with zeros. Something like this can be done: -- mroq x1, #0 -- Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.bin/oasm/lex.c')
-rw-r--r--usr.bin/oasm/lex.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/usr.bin/oasm/lex.c b/usr.bin/oasm/lex.c
index 87ac464..dcd7c1f 100644
--- a/usr.bin/oasm/lex.c
+++ b/usr.bin/oasm/lex.c
@@ -49,6 +49,10 @@ static char putback = '\0';
#define S_IMN_DEC "dec"
#define S_IMN_HLT "hlt"
#define S_IMN_BR "br"
+#define S_IMN_MROB "mrob"
+#define S_IMN_MROW "mrow"
+#define S_IMN_MROD "mrod"
+#define S_IMN_MROQ "mroq"
/* Instruction length */
#define OSMX64_INST_LEN 4
@@ -223,6 +227,41 @@ token_cfi(char *p)
return TT_UNKNOWN;
}
+/*
+ * Bitwise MRO instructions
+ */
+static tt_t
+token_bitw_mro(char *p)
+{
+ if (strcmp(p, S_IMN_MROB) == 0) {
+ return TT_MROB;
+ } else if (strcmp(p, S_IMN_MROW) == 0) {
+ return TT_MROW;
+ } else if (strcmp(p, S_IMN_MROD) == 0) {
+ return TT_MROD;
+ } else if (strcmp(p, S_IMN_MROQ) == 0) {
+ return TT_MROQ;
+ }
+
+ return TT_UNKNOWN;
+}
+
+/*
+ * Bitwise instructions
+ */
+static tt_t
+token_bitw(char *p)
+{
+ tt_t token;
+
+ token = token_bitw_mro(p);
+ if (token != TT_UNKNOWN) {
+ return token;
+ }
+
+ return TT_UNKNOWN;
+}
+
static tt_t
token_xreg(char *p)
{
@@ -355,6 +394,12 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp)
return 0;
}
+ if ((tok = token_bitw(p)) != TT_UNKNOWN) {
+ ttp->type = tok;
+ ttp->raw = p;
+ return 0;
+ }
+
/* Immediate operand? */
if ((tok = token_operand(p)) != TT_UNKNOWN) {
if (tok == TT_IMM) {