aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnssi Hannula <anssi@mandriva.org>2009-09-06 11:46:02 +0000
committerAnssi Hannula <anssi@mandriva.org>2009-09-06 11:46:02 +0000
commita2e81eb2b00365d83f5ed484017aa0170764e23d (patch)
treeaa5ce5bae9abf24529aa3c444814bfe4a0eab2a4
parent323c42fd8fcce9575f20e8e93e38df3e1ba5d43a (diff)
downloadmonitor-edid-a2e81eb2b00365d83f5ed484017aa0170764e23d.tar
monitor-edid-a2e81eb2b00365d83f5ed484017aa0170764e23d.tar.gz
monitor-edid-a2e81eb2b00365d83f5ed484017aa0170764e23d.tar.bz2
monitor-edid-a2e81eb2b00365d83f5ed484017aa0170764e23d.tar.xz
monitor-edid-a2e81eb2b00365d83f5ed484017aa0170764e23d.zip
monitor-get-edid-using-vbe:
update x86emu from xserver git (fixes issues at least with newish NVIDIA cards)
-rw-r--r--NEWS4
-rw-r--r--int10/emu_vm86.c2
-rw-r--r--x86emu/LICENSE17
-rw-r--r--x86emu/Makefile3
-rw-r--r--x86emu/debug.c7
-rw-r--r--x86emu/decode.c3
-rw-r--r--x86emu/fpu.c1
-rw-r--r--x86emu/ops.c6
-rw-r--r--x86emu/ops2.c164
-rw-r--r--x86emu/prim_ops.c72
-rw-r--r--x86emu/sys.c73
-rw-r--r--x86emu/x86emu.h (renamed from x86emu/include/x86emu.h)1
-rw-r--r--x86emu/x86emu/debug.h1
-rw-r--r--x86emu/x86emu/decode.h1
-rw-r--r--x86emu/x86emu/fpu_regs.h (renamed from x86emu/include/x86emu/fpu_regs.h)1
-rw-r--r--x86emu/x86emu/prim_asm.h1
-rw-r--r--x86emu/x86emu/prim_ops.h3
-rw-r--r--x86emu/x86emu/prim_x86_gcc.h79
-rw-r--r--x86emu/x86emu/regs.h (renamed from x86emu/include/x86emu/regs.h)1
-rw-r--r--x86emu/x86emu/types.h (renamed from x86emu/include/x86emu/types.h)8
-rw-r--r--x86emu/x86emu/x86emui.h5
21 files changed, 302 insertions, 151 deletions
diff --git a/NEWS b/NEWS
index 0e9e560..26590ab 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+- monitor-get-edid-using-vbe:
+ o update x86emu from xserver git (fixes issues at least with newish
+ NVIDIA cards)
+
Version 2.2 - 16 August 2009
- monitor-edid, monitor-get-edid:
diff --git a/int10/emu_vm86.c b/int10/emu_vm86.c
index 890f762..8cd69b2 100644
--- a/int10/emu_vm86.c
+++ b/int10/emu_vm86.c
@@ -4,7 +4,7 @@
#define INT2PTR(a) ((a) + (unsigned char *) 0)
-#include "../x86emu/include/x86emu.h"
+#include "../x86emu/x86emu.h"
#include "AsmMacros.h"
int emu_vm86_ret;
diff --git a/x86emu/LICENSE b/x86emu/LICENSE
deleted file mode 100644
index a3ede4a..0000000
--- a/x86emu/LICENSE
+++ /dev/null
@@ -1,17 +0,0 @@
- License information
- -------------------
-
-The x86emu library is under a BSD style license, comaptible
-with the XFree86 and X licenses used by XFree86. The
-original x86emu libraries were under the GNU General Public
-License. Due to license incompatibilities between the GPL
-and the XFree86 license, the original authors of the code
-decided to allow a license change. If you have submitted
-code to the original x86emu project, and you don't agree
-with the license change, please contact us and let you
-know. Your code will be removed to comply with your wishes.
-
-If you have any questions about this, please send email to
-x86emu@linuxlabs.com or KendallB@scitechsoft.com for
-clarification.
-
diff --git a/x86emu/Makefile b/x86emu/Makefile
index 6d4cfd6..afebf97 100644
--- a/x86emu/Makefile
+++ b/x86emu/Makefile
@@ -48,8 +48,7 @@ $(TARGETLIB): $(OBJS)
# prefix objects with x86emu_
@for i in $? ; do cp -p $$i x86emu_$$i ; ar rv $@ x86emu_$$i || exit ; rm -f x86emu_$$i ; done
-INCS = -I. -Ix86emu -Iinclude
-CFLAGS += -D__DRIVER__ -DFORCE_POST -D_CEXPORT= -DNO_LONG_LONG
+INCS = -I. -Ix86emu
%.o: %.c
$(CC) $(CFLAGS) $(INCS) -c $< -o $@
diff --git a/x86emu/debug.c b/x86emu/debug.c
index ed8f2f0..5eda908 100644
--- a/x86emu/debug.c
+++ b/x86emu/debug.c
@@ -36,12 +36,11 @@
* emulator.
*
****************************************************************************/
-/* $XFree86: xc/extras/x86emu/src/x86emu/debug.c,v 1.2 2000/04/05 18:13:14 dawes Exp $ */
#include "x86emu/x86emui.h"
-#ifdef IN_MODULE
-#include "xf86_ansic.h"
-#else
+#include <stdio.h>
+#include <string.h>
+#ifndef NO_SYS_HEADERS
#include <stdarg.h>
#include <stdlib.h>
#endif
diff --git a/x86emu/decode.c b/x86emu/decode.c
index a4c5013..9339f4c 100644
--- a/x86emu/decode.c
+++ b/x86emu/decode.c
@@ -37,8 +37,7 @@
*
****************************************************************************/
-/* $XFree86: xc/extras/x86emu/src/x86emu/decode.c,v 1.11 2002/07/23 20:20:43 tsi Exp $ */
-
+#include <stdlib.h>
#include "x86emu/x86emui.h"
/*----------------------------- Implementation ----------------------------*/
diff --git a/x86emu/fpu.c b/x86emu/fpu.c
index 4b801dc..b72de1e 100644
--- a/x86emu/fpu.c
+++ b/x86emu/fpu.c
@@ -36,7 +36,6 @@
* emulation of the FPU instructions.
*
****************************************************************************/
-/* $XFree86$ */
#include "x86emu/x86emui.h"
diff --git a/x86emu/ops.c b/x86emu/ops.c
index 6fc936b..37ae2c9 100644
--- a/x86emu/ops.c
+++ b/x86emu/ops.c
@@ -70,8 +70,6 @@
*
****************************************************************************/
-/* $XFree86: xc/extras/x86emu/src/x86emu/ops.c,v 1.8tsi Exp $ */
-
#include "x86emu/x86emui.h"
/*----------------------------- Implementation ----------------------------*/
@@ -90,8 +88,8 @@ static void x86emuOp_illegal_op(
if (M.x86.R_SP != 0) {
DECODE_PRINTF("ILLEGAL X86 OPCODE\n");
TRACE_REGS();
- printk("%04x:%04x: %02X ILLEGAL X86 OPCODE!\n",
- M.x86.R_CS, M.x86.R_IP-1,op1);
+ DB( printk("%04x:%04x: %02X ILLEGAL X86 OPCODE!\n",
+ M.x86.R_CS, M.x86.R_IP-1,op1));
HALT_SYS();
}
else {
diff --git a/x86emu/ops2.c b/x86emu/ops2.c
index 7cb585b..39bd041 100644
--- a/x86emu/ops2.c
+++ b/x86emu/ops2.c
@@ -37,10 +37,15 @@
* instructions.
*
****************************************************************************/
-/* $XFree86: xc/extras/x86emu/src/x86emu/ops2.c,v 1.6tsi Exp $ */
#include "x86emu/x86emui.h"
+#undef bswap_32
+#define bswap_32(x) (((x & 0xff000000) >> 24) | \
+ ((x & 0x00ff0000) >> 8) | \
+ ((x & 0x0000ff00) << 8) | \
+ ((x & 0x000000ff) << 24))
+
/*----------------------------- Implementation ----------------------------*/
/****************************************************************************
@@ -66,12 +71,46 @@ static void x86emuOp2_illegal_op(
/****************************************************************************
REMARKS:
+Handles opcode 0x0f,0x31
+****************************************************************************/
+static void x86emuOp2_rdtsc(u8 X86EMU_UNUSED(op2))
+{
+#ifdef __HAS_LONG_LONG__
+ static u64 counter = 0;
+#else
+ static u32 counter = 0;
+#endif
+
+ counter += 0x10000;
+
+ /* read timestamp counter */
+ /*
+ * Note that instead of actually trying to accurately measure this, we just
+ * increase the counter by a fixed amount every time we hit one of these
+ * instructions. Feel free to come up with a better method.
+ */
+ START_OF_INSTR();
+ DECODE_PRINTF("RDTSC\n");
+ TRACE_AND_STEP();
+#ifdef __HAS_LONG_LONG__
+ M.x86.R_EAX = counter & 0xffffffff;
+ M.x86.R_EDX = counter >> 32;
+#else
+ M.x86.R_EAX = counter;
+ M.x86.R_EDX = 0;
+#endif
+ DECODE_CLEAR_SEGOVR();
+ END_OF_INSTR();
+}
+
+/****************************************************************************
+REMARKS:
Handles opcode 0x0f,0x80-0x8F
****************************************************************************/
static void x86emuOp2_long_jump(u8 op2)
{
s32 target;
- char *name = 0;
+ char *name = NULL;
int cond = 0;
/* conditional jump to word offset. */
@@ -131,7 +170,7 @@ static void x86emuOp2_long_jump(u8 op2)
break;
case 0x8d:
name = "JNL\t";
- cond = xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF));
+ cond = !(xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)));
break;
case 0x8e:
name = "JLE\t";
@@ -165,7 +204,7 @@ static void x86emuOp2_set_byte(u8 op2)
int mod, rl, rh;
uint destoffset;
u8 *destreg;
- char *name = 0;
+ char *name = NULL;
int cond = 0;
START_OF_INSTR();
@@ -295,6 +334,20 @@ static void x86emuOp2_pop_FS(u8 X86EMU_UNUSED(op2))
}
/****************************************************************************
+REMARKS: CPUID takes EAX/ECX as inputs, writes EAX/EBX/ECX/EDX as output
+Handles opcode 0x0f,0xa2
+****************************************************************************/
+static void x86emuOp2_cpuid(u8 X86EMU_UNUSED(op2))
+{
+ START_OF_INSTR();
+ DECODE_PRINTF("CPUID\n");
+ TRACE_AND_STEP();
+ cpuid();
+ DECODE_CLEAR_SEGOVR();
+ END_OF_INSTR();
+}
+
+/****************************************************************************
REMARKS:
Handles opcode 0x0f,0xa3
****************************************************************************/
@@ -700,10 +753,9 @@ static void x86emuOp2_pop_GS(u8 X86EMU_UNUSED(op2))
END_OF_INSTR();
}
-#if 0
/****************************************************************************
REMARKS:
-Handles opcode 0x0f,0xaa
+Handles opcode 0x0f,0xab
****************************************************************************/
static void x86emuOp2_bts_R(u8 X86EMU_UNUSED(op2))
{
@@ -839,7 +891,6 @@ static void x86emuOp2_bts_R(u8 X86EMU_UNUSED(op2))
DECODE_CLEAR_SEGOVR();
END_OF_INSTR();
}
-#endif
/****************************************************************************
REMARKS:
@@ -2132,7 +2183,7 @@ static void x86emuOp2_bsf(u8 X86EMU_UNUSED(op2))
uint srcoffset;
START_OF_INSTR();
- DECODE_PRINTF("BSF\n");
+ DECODE_PRINTF("BSF\t");
FETCH_DECODE_MODRM(mod, rh, rl);
switch(mod) {
case 0:
@@ -2212,25 +2263,25 @@ static void x86emuOp2_bsf(u8 X86EMU_UNUSED(op2))
break;
case 3: /* register to register */
if (M.x86.mode & SYSMODE_PREFIX_DATA) {
- u32 *srcreg, *dstreg;
+ u32 srcval, *dstreg;
- srcreg = DECODE_RM_LONG_REGISTER(rl);
+ srcval = *DECODE_RM_LONG_REGISTER(rl);
DECODE_PRINTF(",");
dstreg = DECODE_RM_LONG_REGISTER(rh);
TRACE_AND_STEP();
- CONDITIONAL_SET_FLAG(*srcreg == 0, F_ZF);
+ CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
for(*dstreg = 0; *dstreg < 32; (*dstreg)++)
- if ((*srcreg >> *dstreg) & 1) break;
+ if ((srcval >> *dstreg) & 1) break;
} else {
- u16 *srcreg, *dstreg;
+ u16 srcval, *dstreg;
- srcreg = DECODE_RM_WORD_REGISTER(rl);
+ srcval = *DECODE_RM_WORD_REGISTER(rl);
DECODE_PRINTF(",");
dstreg = DECODE_RM_WORD_REGISTER(rh);
TRACE_AND_STEP();
- CONDITIONAL_SET_FLAG(*srcreg == 0, F_ZF);
+ CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
for(*dstreg = 0; *dstreg < 16; (*dstreg)++)
- if ((*srcreg >> *dstreg) & 1) break;
+ if ((srcval >> *dstreg) & 1) break;
}
break;
}
@@ -2248,7 +2299,7 @@ static void x86emuOp2_bsr(u8 X86EMU_UNUSED(op2))
uint srcoffset;
START_OF_INSTR();
- DECODE_PRINTF("BSF\n");
+ DECODE_PRINTF("BSR\t");
FETCH_DECODE_MODRM(mod, rh, rl);
switch(mod) {
case 0:
@@ -2328,25 +2379,25 @@ static void x86emuOp2_bsr(u8 X86EMU_UNUSED(op2))
break;
case 3: /* register to register */
if (M.x86.mode & SYSMODE_PREFIX_DATA) {
- u32 *srcreg, *dstreg;
+ u32 srcval, *dstreg;
- srcreg = DECODE_RM_LONG_REGISTER(rl);
+ srcval = *DECODE_RM_LONG_REGISTER(rl);
DECODE_PRINTF(",");
dstreg = DECODE_RM_LONG_REGISTER(rh);
TRACE_AND_STEP();
- CONDITIONAL_SET_FLAG(*srcreg == 0, F_ZF);
+ CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
for(*dstreg = 31; *dstreg > 0; (*dstreg)--)
- if ((*srcreg >> *dstreg) & 1) break;
+ if ((srcval >> *dstreg) & 1) break;
} else {
- u16 *srcreg, *dstreg;
+ u16 srcval, *dstreg;
- srcreg = DECODE_RM_WORD_REGISTER(rl);
+ srcval = *DECODE_RM_WORD_REGISTER(rl);
DECODE_PRINTF(",");
dstreg = DECODE_RM_WORD_REGISTER(rh);
TRACE_AND_STEP();
- CONDITIONAL_SET_FLAG(*srcreg == 0, F_ZF);
+ CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
for(*dstreg = 15; *dstreg > 0; (*dstreg)--)
- if ((*srcreg >> *dstreg) & 1) break;
+ if ((srcval >> *dstreg) & 1) break;
}
break;
}
@@ -2526,6 +2577,47 @@ static void x86emuOp2_movsx_word_R_RM(u8 X86EMU_UNUSED(op2))
END_OF_INSTR();
}
+/* Handles opcodes 0xc8-0xcf */
+static void x86emuOp2_bswap(u8 X86EMU_UNUSED(op2))
+{
+ START_OF_INSTR();
+ DECODE_PRINTF("BSWAP\n");
+ TRACE_AND_STEP();
+
+ switch (op2) {
+ case 0xc8:
+ M.x86.R_EAX = bswap_32(M.x86.R_EAX);
+ break;
+ case 0xc9:
+ M.x86.R_ECX = bswap_32(M.x86.R_ECX);
+ break;
+ case 0xca:
+ M.x86.R_EDX = bswap_32(M.x86.R_EDX);
+ break;
+ case 0xcb:
+ M.x86.R_EBX = bswap_32(M.x86.R_EBX);
+ break;
+ case 0xcc:
+ M.x86.R_ESP = bswap_32(M.x86.R_ESP);
+ break;
+ case 0xcd:
+ M.x86.R_EBP = bswap_32(M.x86.R_EBP);
+ break;
+ case 0xce:
+ M.x86.R_ESI = bswap_32(M.x86.R_ESI);
+ break;
+ case 0xcf:
+ M.x86.R_EDI = bswap_32(M.x86.R_EDI);
+ break;
+ default:
+ /* can't happen */
+ break;
+ }
+
+ DECODE_CLEAR_SEGOVR();
+ END_OF_INSTR();
+}
+
/***************************************************************************
* Double byte operation code table:
**************************************************************************/
@@ -2583,7 +2675,7 @@ void (*x86emu_optab2[256])(u8) =
/* 0x2f */ x86emuOp2_illegal_op,
/* 0x30 */ x86emuOp2_illegal_op,
-/* 0x31 */ x86emuOp2_illegal_op,
+/* 0x31 */ x86emuOp2_rdtsc,
/* 0x32 */ x86emuOp2_illegal_op,
/* 0x33 */ x86emuOp2_illegal_op,
/* 0x34 */ x86emuOp2_illegal_op,
@@ -2703,7 +2795,7 @@ void (*x86emu_optab2[256])(u8) =
/* 0xa0 */ x86emuOp2_push_FS,
/* 0xa1 */ x86emuOp2_pop_FS,
-/* 0xa2 */ x86emuOp2_illegal_op,
+/* 0xa2 */ x86emuOp2_cpuid,
/* 0xa3 */ x86emuOp2_bt_R,
/* 0xa4 */ x86emuOp2_shld_IMM,
/* 0xa5 */ x86emuOp2_shld_CL,
@@ -2712,7 +2804,7 @@ void (*x86emu_optab2[256])(u8) =
/* 0xa8 */ x86emuOp2_push_GS,
/* 0xa9 */ x86emuOp2_pop_GS,
/* 0xaa */ x86emuOp2_illegal_op,
-/* 0xab */ x86emuOp2_bt_R,
+/* 0xab */ x86emuOp2_bts_R,
/* 0xac */ x86emuOp2_shrd_IMM,
/* 0xad */ x86emuOp2_shrd_CL,
/* 0xae */ x86emuOp2_illegal_op,
@@ -2743,14 +2835,14 @@ void (*x86emu_optab2[256])(u8) =
/* 0xc5 */ x86emuOp2_illegal_op,
/* 0xc6 */ x86emuOp2_illegal_op,
/* 0xc7 */ x86emuOp2_illegal_op,
-/* 0xc8 */ x86emuOp2_illegal_op, /* TODO: bswap */
-/* 0xc9 */ x86emuOp2_illegal_op, /* TODO: bswap */
-/* 0xca */ x86emuOp2_illegal_op, /* TODO: bswap */
-/* 0xcb */ x86emuOp2_illegal_op, /* TODO: bswap */
-/* 0xcc */ x86emuOp2_illegal_op, /* TODO: bswap */
-/* 0xcd */ x86emuOp2_illegal_op, /* TODO: bswap */
-/* 0xce */ x86emuOp2_illegal_op, /* TODO: bswap */
-/* 0xcf */ x86emuOp2_illegal_op, /* TODO: bswap */
+/* 0xc8 */ x86emuOp2_bswap,
+/* 0xc9 */ x86emuOp2_bswap,
+/* 0xca */ x86emuOp2_bswap,
+/* 0xcb */ x86emuOp2_bswap,
+/* 0xcc */ x86emuOp2_bswap,
+/* 0xcd */ x86emuOp2_bswap,
+/* 0xce */ x86emuOp2_bswap,
+/* 0xcf */ x86emuOp2_bswap,
/* 0xd0 */ x86emuOp2_illegal_op,
/* 0xd1 */ x86emuOp2_illegal_op,
diff --git a/x86emu/prim_ops.c b/x86emu/prim_ops.c
index 56ab8cc..4a6ac5d 100644
--- a/x86emu/prim_ops.c
+++ b/x86emu/prim_ops.c
@@ -97,9 +97,17 @@
*
****************************************************************************/
+#include <stdlib.h>
+
#define PRIM_OPS_NO_REDEFINE_ASM
#include "x86emu/x86emui.h"
+#if defined(__GNUC__)
+# if defined (__i386__) || defined(__i386) || defined(__AMD64__) || defined(__amd64__)
+# include "x86emu/prim_x86_gcc.h"
+# endif
+#endif
+
/*------------------------- Global Variables ------------------------------*/
static u32 x86emu_parity_tab[8] =
@@ -2080,7 +2088,7 @@ Implements the IMUL instruction and side effects.
void imul_long_direct(u32 *res_lo, u32* res_hi,u32 d, u32 s)
{
#ifdef __HAS_LONG_LONG__
- s64 res = (s32)d * (s32)s;
+ s64 res = (s64)(s32)d * (s32)s;
*res_lo = (u32)res;
*res_hi = (u32)(res >> 32);
@@ -2172,7 +2180,7 @@ Implements the MUL instruction and side effects.
void mul_long(u32 s)
{
#ifdef __HAS_LONG_LONG__
- u64 res = (u32)M.x86.R_EAX * (u32)s;
+ u64 res = (u64)M.x86.R_EAX * s;
M.x86.R_EAX = (u32)res;
M.x86.R_EDX = (u32)(res >> 32);
@@ -2652,3 +2660,63 @@ DB( if (CHECK_SP_ACCESS())
return res;
}
+/****************************************************************************
+REMARKS:
+CPUID takes EAX/ECX as inputs, writes EAX/EBX/ECX/EDX as output
+****************************************************************************/
+void cpuid (void)
+{
+ u32 feature = M.x86.R_EAX;
+
+#ifdef X86EMU_HAS_HW_CPUID
+ /* If the platform allows it, we will base our values on the real
+ * results from the CPUID instruction. We limit support to the
+ * first two features, and the results of those are sanitized.
+ */
+ if (feature <= 1)
+ hw_cpuid(&M.x86.R_EAX, &M.x86.R_EBX, &M.x86.R_ECX, &M.x86.R_EDX);
+#endif
+
+ switch (feature) {
+ case 0:
+ /* Regardless if we have real data from the hardware, the emulator
+ * will only support upto feature 1, which we set in register EAX.
+ * Registers EBX:EDX:ECX contain a string identifying the CPU.
+ */
+ M.x86.R_EAX = 1;
+#ifndef X86EMU_HAS_HW_CPUID
+ /* EBX:EDX:ECX = "GenuineIntel" */
+ M.x86.R_EBX = 0x756e6547;
+ M.x86.R_EDX = 0x49656e69;
+ M.x86.R_ECX = 0x6c65746e;
+#endif
+ break;
+ case 1:
+#ifndef X86EMU_HAS_HW_CPUID
+ /* If we don't have x86 compatible hardware, we return values from an
+ * Intel 486dx4; which was one of the first processors to have CPUID.
+ */
+ M.x86.R_EAX = 0x00000480;
+ M.x86.R_EBX = 0x00000000;
+ M.x86.R_ECX = 0x00000000;
+ M.x86.R_EDX = 0x00000002; /* VME */
+#else
+ /* In the case that we have hardware CPUID instruction, we make sure
+ * that the features reported are limited to TSC and VME.
+ */
+ M.x86.R_EDX &= 0x00000012;
+#endif
+ break;
+ default:
+ /* Finally, we don't support any additional features. Most CPUs
+ * return all zeros when queried for invalid or unsupported feature
+ * numbers.
+ */
+ M.x86.R_EAX = 0;
+ M.x86.R_EBX = 0;
+ M.x86.R_ECX = 0;
+ M.x86.R_EDX = 0;
+ break;
+ }
+}
+
diff --git a/x86emu/sys.c b/x86emu/sys.c
index cf13517..e15fb09 100644
--- a/x86emu/sys.c
+++ b/x86emu/sys.c
@@ -39,16 +39,13 @@
* user library.
*
****************************************************************************/
-/* $XFree86: xc/extras/x86emu/src/x86emu/sys.c,v 1.6 2002/09/16 18:05:18 eich Exp $ */
#include "x86emu.h"
#include "x86emu/x86emui.h"
#include "x86emu/regs.h"
#include "x86emu/debug.h"
#include "x86emu/prim_ops.h"
-#ifdef IN_MODULE
-#include "xf86_ansic.h"
-#else
+#ifndef NO_SYS_HEADERS
#include <string.h>
#endif
/*------------------------- Global Variables ------------------------------*/
@@ -71,7 +68,7 @@ X86EMU_intrFuncs _X86EMU_intrTab[256];
* packed structures to talk about such things with.
*/
-#if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+#if defined(__GNUC__)
struct __una_u64 { unsigned long x __attribute__((packed)); };
struct __una_u32 { unsigned int x __attribute__((packed)); };
struct __una_u16 { unsigned short x __attribute__((packed)); };
@@ -79,7 +76,7 @@ struct __una_u16 { unsigned short x __attribute__((packed)); };
static __inline__ unsigned long ldq_u(unsigned long * r11)
{
-#if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+#if defined(__GNUC__)
const struct __una_u64 *ptr = (const struct __una_u64 *) r11;
return ptr->x;
#else
@@ -98,7 +95,7 @@ static __inline__ unsigned long ldq_u(unsigned long * r11)
static __inline__ unsigned long ldl_u(unsigned int * r11)
{
-#if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+#if defined(__GNUC__)
const struct __una_u32 *ptr = (const struct __una_u32 *) r11;
return ptr->x;
#else
@@ -117,7 +114,7 @@ static __inline__ unsigned long ldl_u(unsigned int * r11)
static __inline__ unsigned long ldw_u(unsigned short * r11)
{
-#if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+#if defined(__GNUC__)
const struct __una_u16 *ptr = (const struct __una_u16 *) r11;
return ptr->x;
#else
@@ -140,7 +137,7 @@ static __inline__ unsigned long ldw_u(unsigned short * r11)
static __inline__ void stq_u(unsigned long r5, unsigned long * r11)
{
-#if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+#if defined(__GNUC__)
struct __una_u64 *ptr = (struct __una_u64 *) r11;
ptr->x = r5;
#else
@@ -165,7 +162,7 @@ static __inline__ void stq_u(unsigned long r5, unsigned long * r11)
static __inline__ void stl_u(unsigned long r5, unsigned int * r11)
{
-#if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+#if defined(__GNUC__)
struct __una_u32 *ptr = (struct __una_u32 *) r11;
ptr->x = r5;
#else
@@ -190,7 +187,7 @@ static __inline__ void stl_u(unsigned long r5, unsigned int * r11)
static __inline__ void stw_u(unsigned long r5, unsigned short * r11)
{
-#if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+#if defined(__GNUC__)
struct __una_u16 *ptr = (struct __una_u16 *) r11;
ptr->x = r5;
#else
@@ -212,60 +209,6 @@ static __inline__ void stw_u(unsigned long r5, unsigned short * r11)
:"r" (r5), "r" (r11));
#endif
}
-
-#elif defined(__GNUC__) && ((__GNUC__ < 3)) && \
- (defined (__ia64__) || defined (ia64__))
-#define IA64_UALOADS
-/*
- * EGCS 1.1 knows about arbitrary unaligned loads. Define some
- * packed structures to talk about such things with.
- */
-struct __una_u64 { unsigned long x __attribute__((packed)); };
-struct __una_u32 { unsigned int x __attribute__((packed)); };
-struct __una_u16 { unsigned short x __attribute__((packed)); };
-
-static __inline__ unsigned long
-__uldq (const unsigned long * r11)
-{
- const struct __una_u64 *ptr = (const struct __una_u64 *) r11;
- return ptr->x;
-}
-
-static __inline__ unsigned long
-uldl (const unsigned int * r11)
-{
- const struct __una_u32 *ptr = (const struct __una_u32 *) r11;
- return ptr->x;
-}
-
-static __inline__ unsigned long
-uldw (const unsigned short * r11)
-{
- const struct __una_u16 *ptr = (const struct __una_u16 *) r11;
- return ptr->x;
-}
-
-static __inline__ void
-ustq (unsigned long r5, unsigned long * r11)
-{
- struct __una_u64 *ptr = (struct __una_u64 *) r11;
- ptr->x = r5;
-}
-
-static __inline__ void
-ustl (unsigned long r5, unsigned int * r11)
-{
- struct __una_u32 *ptr = (struct __una_u32 *) r11;
- ptr->x = r5;
-}
-
-static __inline__ void
-ustw (unsigned long r5, unsigned short * r11)
-{
- struct __una_u16 *ptr = (struct __una_u16 *) r11;
- ptr->x = r5;
-}
-
#endif
/****************************************************************************
diff --git a/x86emu/include/x86emu.h b/x86emu/x86emu.h
index d9150f0..795e2d6 100644
--- a/x86emu/include/x86emu.h
+++ b/x86emu/x86emu.h
@@ -37,7 +37,6 @@
* include this header
*
****************************************************************************/
-/* $XFree86$ */
#ifndef __X86EMU_X86EMU_H
#define __X86EMU_X86EMU_H
diff --git a/x86emu/x86emu/debug.h b/x86emu/x86emu/debug.h
index 8abedf6..47aacb6 100644
--- a/x86emu/x86emu/debug.h
+++ b/x86emu/x86emu/debug.h
@@ -35,7 +35,6 @@
* Description: Header file for debug definitions.
*
****************************************************************************/
-/* $XFree86: xc/extras/x86emu/src/x86emu/x86emu/debug.h,v 1.3 2000/04/19 15:48:15 tsi Exp $ */
#ifndef __X86EMU_DEBUG_H
#define __X86EMU_DEBUG_H
diff --git a/x86emu/x86emu/decode.h b/x86emu/x86emu/decode.h
index bb2bc0b..61cd4dc 100644
--- a/x86emu/x86emu/decode.h
+++ b/x86emu/x86emu/decode.h
@@ -35,7 +35,6 @@
* Description: Header file for instruction decoding logic.
*
****************************************************************************/
-/* $XFree86$ */
#ifndef __X86EMU_DECODE_H
#define __X86EMU_DECODE_H
diff --git a/x86emu/include/x86emu/fpu_regs.h b/x86emu/x86emu/fpu_regs.h
index a62b493..e59b807 100644
--- a/x86emu/include/x86emu/fpu_regs.h
+++ b/x86emu/x86emu/fpu_regs.h
@@ -35,7 +35,6 @@
* Description: Header file for FPU register definitions.
*
****************************************************************************/
-/* $XFree86: xc/extras/x86emu/include/x86emu/fpu_regs.h,v 1.2 2003/10/22 20:03:05 tsi Exp $ */
#ifndef __X86EMU_FPU_REGS_H
#define __X86EMU_FPU_REGS_H
diff --git a/x86emu/x86emu/prim_asm.h b/x86emu/x86emu/prim_asm.h
index 041255f..e023cf8 100644
--- a/x86emu/x86emu/prim_asm.h
+++ b/x86emu/x86emu/prim_asm.h
@@ -39,7 +39,6 @@
* platform.
*
****************************************************************************/
-/* $XFree86$ */
#ifndef __X86EMU_PRIM_ASM_H
#define __X86EMU_PRIM_ASM_H
diff --git a/x86emu/x86emu/prim_ops.h b/x86emu/x86emu/prim_ops.h
index 21ab145..6ac2a29 100644
--- a/x86emu/x86emu/prim_ops.h
+++ b/x86emu/x86emu/prim_ops.h
@@ -39,8 +39,6 @@
#ifndef __X86EMU_PRIM_OPS_H
#define __X86EMU_PRIM_OPS_H
-#include "x86emu/prim_asm.h"
-
#ifdef __cplusplus
extern "C" { /* Use "C" linkage when in C++ mode */
#endif
@@ -135,6 +133,7 @@ void push_word (u16 w);
void push_long (u32 w);
u16 pop_word (void);
u32 pop_long (void);
+void cpuid (void);
#ifdef __cplusplus
} /* End of "C" linkage for C++ */
diff --git a/x86emu/x86emu/prim_x86_gcc.h b/x86emu/x86emu/prim_x86_gcc.h
new file mode 100644
index 0000000..5530a3a
--- /dev/null
+++ b/x86emu/x86emu/prim_x86_gcc.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+*
+* Inline helpers for x86emu
+*
+* Copyright (C) 2008 Bart Trojanowski, Symbio Technologies, LLC
+*
+* ========================================================================
+*
+* Permission to use, copy, modify, distribute, and sell this software and
+* its documentation for any purpose is hereby granted without fee,
+* provided that the above copyright notice appear in all copies and that
+* both that copyright notice and this permission notice appear in
+* supporting documentation, and that the name of the authors not be used
+* in advertising or publicity pertaining to distribution of the software
+* without specific, written prior permission. The authors makes no
+* representations about the suitability of this software for any purpose.
+* It is provided "as is" without express or implied warranty.
+*
+* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+* PERFORMANCE OF THIS SOFTWARE.
+*
+* ========================================================================
+*
+* Language: GNU C
+* Environment: GCC on i386 or x86-64
+* Developer: Bart Trojanowski
+*
+* Description: This file defines a few x86 macros that can be used by the
+* emulator to execute native instructions.
+*
+* For PIC vs non-PIC code refer to:
+* http://sam.zoy.org/blog/2007-04-13-shlib-with-non-pic-code-have-inline-assembly-and-pic-mix-well
+*
+****************************************************************************/
+#ifndef __X86EMU_PRIM_X86_GCC_H
+#define __X86EMU_PRIM_X86_GCC_H
+
+#include "x86emu/types.h"
+
+#if !defined(__GNUC__) || !(defined (__i386__) || defined(__i386) || defined(__AMD64__) || defined(__amd64__))
+#error This file is intended to be used by gcc on i386 or x86-64 system
+#endif
+
+#if defined(__PIC__) && defined(__i386__)
+
+#define X86EMU_HAS_HW_CPUID 1
+static inline void hw_cpuid (u32 *a, u32 *b, u32 *c, u32 *d)
+{
+ __asm__ __volatile__ ("pushl %%ebx \n\t"
+ "cpuid \n\t"
+ "movl %%ebx, %1 \n\t"
+ "popl %%ebx \n\t"
+ : "=a" (*a), "=r" (*b),
+ "=c" (*c), "=d" (*d)
+ : "a" (*a), "c" (*c)
+ : "cc");
+}
+
+#else // ! (__PIC__ && __i386__)
+
+#define x86EMU_HAS_HW_CPUID 1
+static inline void hw_cpuid (u32 *a, u32 *b, u32 *c, u32 *d)
+{
+ __asm__ __volatile__ ("cpuid"
+ : "=a" (*a), "=b" (*b),
+ "=c" (*c), "=d" (*d)
+ : "a" (*a), "c" (*c)
+ : "cc");
+}
+
+#endif // __PIC__ && __i386__
+
+
+#endif // __X86EMU_PRIM_X86_GCC_H
diff --git a/x86emu/include/x86emu/regs.h b/x86emu/x86emu/regs.h
index 5d224ce..52cf8e4 100644
--- a/x86emu/include/x86emu/regs.h
+++ b/x86emu/x86emu/regs.h
@@ -35,7 +35,6 @@
* Description: Header file for x86 register definitions.
*
****************************************************************************/
-/* $XFree86: xc/extras/x86emu/include/x86emu/regs.h,v 1.5 2003/10/22 20:03:05 tsi Exp $ */
#ifndef __X86EMU_REGS_H
#define __X86EMU_REGS_H
diff --git a/x86emu/include/x86emu/types.h b/x86emu/x86emu/types.h
index f31d77f..c18e11c 100644
--- a/x86emu/include/x86emu/types.h
+++ b/x86emu/x86emu/types.h
@@ -36,12 +36,11 @@
*
****************************************************************************/
-/* $XFree86: xc/extras/x86emu/include/x86emu/types.h,v 1.6 2003/06/12 14:12:26 eich Exp $ */
#ifndef __X86EMU_TYPES_H
#define __X86EMU_TYPES_H
-#ifndef IN_MODULE
+#ifndef NO_SYS_HEADERS
#include <sys/types.h>
#endif
@@ -75,9 +74,8 @@
defined(__ia64__) || defined(ia64) || \
defined(__sparc64__) || \
defined(__s390x__) || \
- (defined(__hppa__) && defined(__LP64)) || \
- defined(__AMD64__) || defined(AMD64) || \
- (defined(__sgi) && (_MIPS_SZLONG == 64))
+ defined(__hppa__) && defined(__LP64) || \
+ defined(__amd64__) || defined(amd64)
#define NUM32 int
#else
#define NUM32 long
diff --git a/x86emu/x86emu/x86emui.h b/x86emu/x86emu/x86emui.h
index 3adf61e..112ee36 100644
--- a/x86emu/x86emu/x86emui.h
+++ b/x86emu/x86emu/x86emui.h
@@ -38,7 +38,6 @@
*
****************************************************************************/
-/* $XFree86: xc/extras/x86emu/src/x86emu/x86emu/x86emui.h,v 1.3 2000/04/17 16:29:47 eich Exp $ */
#ifndef __X86EMU_X86EMUI_H
#define __X86EMU_X86EMUI_H
@@ -71,9 +70,7 @@
#include "x86emu/fpu.h"
#include "x86emu/fpu_regs.h"
-#ifdef IN_MODULE
-#include <xf86_ansic.h>
-#else
+#ifndef NO_SYS_HEADERS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>