Skip to content

A couple of small accuracy improvements #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lkundrak
Copy link
Contributor

@lkundrak lkundrak commented Mar 2, 2025

While hunting out a suspected bug (which turned out to be a false alarm) while running OpenFirmware x86 Forth dictionaries, I've noticed some differences in libx86emu compared to my actual Intel processor. I've patched them to rule them out as culprits of my bug -- this branch contains the patches + test cases.

I don't think any of these are actually bugs, but it still might be useful for emulation to mimic actual hardware more closely.

lkundrak added 2 commits March 2, 2025 13:52
…tack

The segment registers are always 16-bit. Pushing them onto 32-bit stack
segment advances the stack pointer by 32 bits, but only writes 16 bits,
keeping the most significant 16 bits unchanged.

On an Intel Core i7 (stepping 12):

  $ cat pushseg.c
  #include <stdio.h>

  int
  main ()
  {
      long wrd;

      asm (
          "push $0x12345678\n\t"
          "pop %%eax\n\t"
          "push %%ss\n\t"
          "pop %0\n\t"
          : "=r" (wrd) :
      );

      printf ("0x%08x\n", wrd);
  }

  $ cc -m32 pushseg.c
  $ ./a.out
  0x1234002b
  $
Left shift is documented to leave AF undefined, but in reality it resets
the flag if the bit count is different from zero.

On an Intel Core i7 (stepping 12):

  $ cat shlaf.c
  #include <stdio.h>

  int
  main ()
  {
      long wrd;

      asm (
          "mov $0xffffffff, %%ecx\n\t"
          "push $0x210\n\t" // IF | AF
          "popf\n\t"
          "shl $1, %%ecx\n\t"
          "pushf\n\t"
          "pop %0\n\t"
          : "=r" (wrd) :
      );

      printf ("AF%c\n", wrd & 0x10 ? '+' : '-');
  }
  $ cc -m32 shlaf.c
  $ ./a.out
  AF-
  $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant