From af7a0cf9b65d6fee20029fe67c95c494f4b402a7 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 24 Jul 2025 03:41:39 -0400 Subject: 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 --- usr.bin/oasm/lex.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'usr.bin/oasm/lex.c') 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) { -- cgit v1.2.3