Fixed bug with size of immediate values for emulator w/ S

This commit is contained in:
Themis Demetriades 2024-06-03 22:37:58 +01:00
parent be6b0cf429
commit efc8c087f9

View File

@ -29,7 +29,7 @@ static dword truncateValue(dword value, a64inst_regType regType) {
return value; return value;
} else { } else {
//return value & ~(dword)((1 << WORD_BITS) - 1) //return value & ~(dword)((1 << WORD_BITS) - 1)
return value & (((dword)1 << WORD_BITS) - 1); return value & (dword)(((dword)1 << WORD_BITS) - 1);
} }
} }
@ -67,10 +67,15 @@ static dword readRegister(Machine *state, a64inst_regSpecifier reg, a64inst_regT
} }
} }
// Read from processor register, ensuring that a valid register specifier is given // Write to a processor register, ensuring that a valid register specifier is given
// and truncating the value being written when it can't fit in the specified register. // and truncating the value being written when it can't fit in the specified register.
static void writeRegister(Machine *state, a64inst_regSpecifier reg, a64inst_regType regType, dword value) { static void writeRegister(Machine *state, a64inst_regSpecifier reg, a64inst_regType regType, dword value) {
assert(reg <= REGISTER_COUNT);
if (regType == a64inst_R) {
state->registers[reg] = truncateValue(value, regType); state->registers[reg] = truncateValue(value, regType);
} else {
*(word*)(state->registers + reg) = (word)truncateValue(value, regType);
}
} }
// Updates N and Z condition codes given the machine and a result value // Updates N and Z condition codes given the machine and a result value
@ -137,9 +142,10 @@ static void executeDPImmediate(Machine *state, a64inst_instruction *inst) {
// Execute a wide move data processing instruction // Execute a wide move data processing instruction
case a64inst_DPI_WIDEMOV:; case a64inst_DPI_WIDEMOV:;
uint8_t shiftScalar = inst->data.DPImmediateData.processOpData.wideMovData.shiftScalar; uint8_t shiftScalar = inst->data.DPImmediateData.processOpData.wideMovData.shiftScalar;
uint16_t wideMovImm = inst->data.DPImmediateData.processOpData.wideMovData.immediate; dword wideMovImm = inst->data.DPImmediateData.processOpData.wideMovData.immediate;
// NOTE: Not checking that shiftScalar has valid value for 32bit registers. Possibly add explicit error. // NOTE: Not checking that shiftScalar has valid value for 32bit registers. Possibly add explicit error.
//printf("%x\n", wideMovImm << (shiftScalar * DPI_WIDEMOV_SHIFT) & );
wideMovImm = truncateValue(wideMovImm << (shiftScalar * DPI_WIDEMOV_SHIFT), regType); wideMovImm = truncateValue(wideMovImm << (shiftScalar * DPI_WIDEMOV_SHIFT), regType);
switch(inst->data.DPImmediateData.processOp) { switch(inst->data.DPImmediateData.processOp) {