ptitSeb / box64

Box64 - Linux Userspace x86_64 Emulator with a twist, targeted at ARM64 Linux devices
https://box86.org
MIT License
3.93k stars 290 forks source link

[LA64_DYNAREC] Fix LOCK ADC wrong ed (#2069) #2077

Closed xiangzhai closed 5 days ago

xiangzhai commented 6 days ago

Hi,

Sorry for introduced the issue!

Passed testcase for LOCK ADC:

#include <stdio.h>
#include <stdint.h>
#include <assert.h>

void test_lock_adc32(uint32_t n, uint32_t m, uint32_t expected_eax, uint32_t expected_edx) {
  uint32_t eax;
  uint32_t edx;
  __asm__ __volatile__ (
      "movl  %[n], %%edx\n"
      "movl  %[m], %%eax\n"
      "addl  %[m], %%eax\n"
      "lock; adcl  %[n], %%edx\n"
      "movl  %%eax, %[eax]\n"
      "movl  %%edx, %[edx]\n"
      : [eax] "=r" (eax), [edx] "=r" (edx)
      : [n] "r" (n), [m] "r" (m)
      : "eax", "edx", "memory");
  printf("eax=0x%x\n", eax);
  printf("edx=0x%x\n", edx);
  assert(eax == expected_eax && edx == expected_edx);
}

int main(int argc, char* argv[]) {
  test_lock_adc32(0x0, 0xFFFFFFFF, 0xFFFFFFFE, 0x1);
  return 0;
}

Please review my patch.

Thanks, Leslie Zhai

ksco commented 5 days ago

Just merge this fix into the other PR.