Next Generation Emulation banner

1 - 6 of 6 Posts

·
Registered
Joined
·
80 Posts
Discussion Starter #1
Hi,

Have taken a look at blueshogun96's xenoborg, in a similar way to my recent work on cxbx, and have proposed two fixes to the underlying libemu code (which is used for x86 LLE emulation).

These have both been reported to Paul Baecher & Markus Koetter, the original authors of libemu.

1. Switch statement 'fall-through' in get_operand(), libdasm.c
There is a switch statement inside this function, within which the case for AM_J appears to have missed a break. Alternatively, the fall-through to the AM_I case is intended however op->type = OPERAND_TYPE_IMMEDIATE; is then done twice.

Code:
Index: source/x86/src/libdasm.c
===================================================================
--- source/x86/src/libdasm.c (revision 19)
+++ source/x86/src/libdasm.c (working copy)
@@ -490,6 +490,7 @@
    op->type = OPERAND_TYPE_IMMEDIATE;
    // Always sign-extend
    oflags |= F_s;
+   break;
   case AM_I:
    op->type = OPERAND_TYPE_IMMEDIATE;
    index  = (inst->modrm) ? 1 : 0;

2. Odd for() loop in instr_popad_61(), pop.c
There are two for() loops inside this function that seem odd, as they start the loop setting j = 7, then decrement until such time as j = 8. i.e. they will cycle completely through the unsigned 32bit int j, wrapping around until hitting 8.

Paul and Markus will know better than me what these two sections of code are trying to do, but their current operation appears very odd, and likely incorrect.

I've attached what may be the correct approach, avoiding an unsigned int wrapping, but there could easily be a better solution.

Code:
Index: source/x86/src/functions/pop.c
===================================================================
--- source/x86/src/functions/pop.c (revision 19)
+++ source/x86/src/functions/pop.c (working copy)
@@ -127,7 +127,7 @@
  
  if( i->prefixes & PREFIX_OPSIZE )
  {
-  for( j = 7; j < 8; j-- )
+  for( j = 7; j >= 0; j-- )
   {
    if( j != 4 )
    {
@@ -141,7 +141,7 @@
  }
  else
  {
-  for( j = 7; j < 8; j-- )
+  for( j = 7; j >= 0; j-- )
   {
    if( j != 4 )
    {
 

·
Premium Member
Joined
·
6,071 Posts
Thanks. My mind is a bit fried atm due to some major IRL stress so I'll consider these in the future.
 

·
Registered
Joined
·
80 Posts
Discussion Starter #3
Hmmm, I was a bit too quick with the second patch.

Should read like this on the replacement line:
Code:
+  for( j = 7; j = 0; j-- )
 

·
Premium Member
Joined
·
6,071 Posts
I probably should have used Ville Linde's x86 core from MAME instead. I didn't know that P6 and NetBurst support was added.
 
1 - 6 of 6 Posts
Top