From e597f7d3ac8723fc1408ca724206492ab2cc78bb Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 30 Jul 2025 16:36:12 -0400 Subject: oemu: cpu: Add decoding for shiftinstruction Signed-off-by: Ian Moffett --- usr.bin/oemu/cpu.c | 29 +++++++++++++++++++++++++++++ usr.bin/oemu/include/oemu/osmx64.h | 2 ++ 2 files changed, 31 insertions(+) (limited to 'usr.bin') diff --git a/usr.bin/oemu/cpu.c b/usr.bin/oemu/cpu.c index 4aab553..de8b465 100644 --- a/usr.bin/oemu/cpu.c +++ b/usr.bin/oemu/cpu.c @@ -294,6 +294,31 @@ cpu_br(struct oemu_cpu *cpu, inst_t *inst) regs->ip = br_to; } +/* + * Decode a logical shift instruction: + * + * LSR r, r/imm + * LSL r, r/imm + */ +static void +cpu_lshift(struct oemu_cpu *cpu, inst_t *inst) +{ + struct cpu_regs *regs = &cpu->regs; + reg_t reg = inst->rd; + imm_t shift = inst->imm; + + switch (inst->opcode) { + case INST_LSR: + regs->xreg[reg] >>= shift; + printf("X%d >> %d -> %d\n", reg, shift, regs->xreg[reg]); + break; + case INST_LSL: + regs->xreg[reg] <<= shift; + printf("X%d << %d -> %d\n", reg, shift, regs->xreg[reg]); + break; + } +} + /* * Decode MRO type instructions */ @@ -463,6 +488,10 @@ cpu_kick(struct oemu_cpu *cpu, struct sysmem *mem) case INST_BR: cpu_br(cpu, inst); break; + case INST_LSL: + case INST_LSR: + cpu_lshift(cpu, inst); + break; default: if (cpu_is_mro(inst)) { cpu_mro(cpu, inst); diff --git a/usr.bin/oemu/include/oemu/osmx64.h b/usr.bin/oemu/include/oemu/osmx64.h index ffd6156..1e094d0 100644 --- a/usr.bin/oemu/include/oemu/osmx64.h +++ b/usr.bin/oemu/include/oemu/osmx64.h @@ -53,6 +53,8 @@ #define INST_MROW 0x11 /* Mask register over word */ #define INST_MROD 0x12 /* Mask register over dword */ #define INST_MROQ 0x13 /* Mask register over qword */ +#define INST_LSR 0x14 /* Logical shift right */ +#define INST_LSL 0x15 /* Logical shift left */ /* Registers */ #define REG_X0 0x00 -- cgit v1.2.3