Atomic Instruction Emulation

Xin Tong <[email protected]>
Newsgroups gmane.comp.emulators.bochs.devel
Message-ID <CALKntY0s+XJ+EcATj3XSLkja7L+7MpEh5OshWE0+EOeWY5w_tQ@mail.gmail.com>
I am looking at how atomic instructions are emulated in bochs. it
seems they are not emulated in an "atomic" way. i.e. for
CMPXCHG_EdGdM. CMPXCHG_EdGdM is not atomic by itself, but with a lock
prefix, it is atomic. but i do not see the lock prefix being checked
here.  Maybe this works under the assumption that bochs emulated CPUs
are multiplexed onto physical CPUs in a serial fashion.

BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::CMPXCHG_EdGdM(bxInstruction_c *i)
{
  bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));

  Bit32u op1_32 = read_RMW_virtual_dword(i->seg(), eaddr);
  Bit32u diff_32 = EAX - op1_32;
  SET_FLAGS_OSZAPC_SUB_32(EAX, op1_32, diff_32);

  if (diff_32 == 0) {  // if accumulator == dest
    // dest <-- src
    write_RMW_virtual_dword(BX_READ_32BIT_REG(i->nnn()));
  }
  else {
    // accumulator <-- dest
    RAX = op1_32;
  }

  BX_NEXT_INSTR(i);
}

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.