From caa652ae2b3da86de945fa8d5ece55ddbbb2cf31 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 30 Jul 2025 16:34:48 -0400 Subject: oasm: Introduce logical shift operations This commit introduces LSR/LSL which are used as bitwise shift operations. -- lsr x1, #1 !! x1 >>= 1 lsl x1, #1 !! x1 <<= 1 -- Signed-off-by: Ian Moffett --- usr.bin/oasm/emit.c | 10 ++++++++++ usr.bin/oasm/include/oasm/emit.h | 2 ++ usr.bin/oasm/include/oasm/lex.h | 2 ++ usr.bin/oasm/lex.c | 8 ++++++++ usr.bin/oasm/parse.c | 14 +++++++++++++- 5 files changed, 35 insertions(+), 1 deletion(-) (limited to 'usr.bin') diff --git a/usr.bin/oasm/emit.c b/usr.bin/oasm/emit.c index 63f716a..099f0b2 100644 --- a/usr.bin/oasm/emit.c +++ b/usr.bin/oasm/emit.c @@ -402,6 +402,14 @@ emit_encode_bitw(struct emit_state *state, struct oasm_token *tok) opcode = OSMX64_XOR; inst_str = "xor"; break; + case TT_LSR: + opcode = OSMX64_LSR; + inst_str = "lsr"; + break; + case TT_LSL: + opcode = OSMX64_LSL; + inst_str = "lsl"; + break; } /* Next token should be a register */ @@ -532,6 +540,8 @@ emit_process(struct oasm_state *oasm, struct emit_state *emit) case TT_AND: case TT_OR: case TT_XOR: + case TT_LSR: + case TT_LSL: curtok = emit_encode_bitw(emit, curtok); break; case TT_BR: diff --git a/usr.bin/oasm/include/oasm/emit.h b/usr.bin/oasm/include/oasm/emit.h index 3fc2674..57683a8 100644 --- a/usr.bin/oasm/include/oasm/emit.h +++ b/usr.bin/oasm/include/oasm/emit.h @@ -66,6 +66,8 @@ #define OSMX64_MROW 0x11 /* Mask register over word */ #define OSMX64_MROD 0x12 /* Mask register over dword */ #define OSMX64_MROQ 0x13 /* Mask register over qword */ +#define OSMX64_LSR 0x14 /* Logical shift right */ +#define OSMX64_LSL 0x15 /* Logical shift left */ /* * OSMX64 register definitions diff --git a/usr.bin/oasm/include/oasm/lex.h b/usr.bin/oasm/include/oasm/lex.h index 4c81bc4..93422a6 100644 --- a/usr.bin/oasm/include/oasm/lex.h +++ b/usr.bin/oasm/include/oasm/lex.h @@ -106,6 +106,8 @@ typedef enum { TT_AND, /* 'and' */ TT_OR, /* 'or' */ TT_XOR, /* 'xor' */ + TT_LSR, /* 'lsr' */ + TT_LSL, /* 'lsl' */ /* Register ops */ TT_MOV, /* 'mov' */ diff --git a/usr.bin/oasm/lex.c b/usr.bin/oasm/lex.c index ce97400..1f58d07 100644 --- a/usr.bin/oasm/lex.c +++ b/usr.bin/oasm/lex.c @@ -57,6 +57,8 @@ static char putback = '\0'; #define S_IMN_AND "and" #define S_IMN_OR "or" #define S_IMN_XOR "xor" +#define S_IMN_LSL "lsl" +#define S_IMN_LSR "lsr" /* Instruction length */ #define OSMX64_INST_LEN 4 @@ -269,6 +271,12 @@ token_bitw(char *p) return token; } + if (strcmp(p, S_IMN_LSL) == 0) { + return TT_LSL; + } else if (strcmp(p, S_IMN_LSR) == 0) { + return TT_LSR; + } + return TT_UNKNOWN; } diff --git a/usr.bin/oasm/parse.c b/usr.bin/oasm/parse.c index ce5a446..042cce8 100644 --- a/usr.bin/oasm/parse.c +++ b/usr.bin/oasm/parse.c @@ -51,7 +51,9 @@ static const char *tokstr[] = { [ TT_DEC ] = "dec", [ TT_MOV ] = "mov", [ TT_IMM ] = "", - [ TT_LABEL] = "