Code fixes to support x64.

This commit is contained in:
Artem Kharytoniuk 2014-06-22 19:35:07 +03:00
parent 45f0e016d2
commit eae0ddcccc
13 changed files with 50 additions and 273 deletions

View File

@ -83,7 +83,7 @@ typedef struct {
byte file[65536]; byte file[65536];
short sqrTable[256]; short sqrTable[256];
unsigned int mcomp[256]; int mcomp[256];
byte *qStatus[2][32768]; byte *qStatus[2][32768];
long oldXOff, oldYOff, oldysize, oldxsize; long oldXOff, oldYOff, oldysize, oldxsize;

View File

@ -881,9 +881,7 @@ void QDECL Com_sprintf( char *dest, int size, const char *fmt, ...) {
if (len >= size) { if (len >= size) {
Com_Printf ("Com_sprintf: overflow of %i in %i\n", len, size); Com_Printf ("Com_sprintf: overflow of %i in %i\n", len, size);
#ifdef _DEBUG #ifdef _DEBUG
__asm { __debugbreak();
int 3;
}
#endif #endif
} }
Q_strncpyz (dest, bigbuffer, size ); Q_strncpyz (dest, bigbuffer, size );

View File

@ -138,20 +138,7 @@ float FloatSwap (const float *f);
#undef QDECL #undef QDECL
#define QDECL __cdecl #define QDECL __cdecl
// buildstring will be incorporated into the version string #define CPUSTRING "generic"
#ifdef NDEBUG
#ifdef _M_IX86
#define CPUSTRING "win-x86"
#elif defined _M_ALPHA
#define CPUSTRING "win-AXP"
#endif
#else
#ifdef _M_IX86
#define CPUSTRING "win-x86-debug"
#elif defined _M_ALPHA
#define CPUSTRING "win-AXP-debug"
#endif
#endif
#define ID_INLINE __inline #define ID_INLINE __inline

View File

@ -238,9 +238,7 @@ void QDECL Com_Error( int code, const char *fmt, ... ) {
#if defined(_WIN32) && defined(_DEBUG) #if defined(_WIN32) && defined(_DEBUG)
if ( code != ERR_DISCONNECT && code != ERR_NEED_CD ) { if ( code != ERR_DISCONNECT && code != ERR_NEED_CD ) {
if (!com_noErrorInterrupt->integer) { if (!com_noErrorInterrupt->integer) {
__asm { __debugbreak();
int 0x03
}
} }
} }
#endif #endif

View File

@ -2503,7 +2503,7 @@ static void FS_AddGameDirectory( const char *path, const char *dir ) {
sorted[i] = pakfiles[i]; sorted[i] = pakfiles[i];
} }
qsort( sorted, numfiles, 4, paksort ); qsort( sorted, numfiles, sizeof(void*), paksort );
for ( i = 0 ; i < numfiles ; i++ ) { for ( i = 0 ; i < numfiles ; i++ ) {
pakfile = FS_BuildOSPath( path, dir, sorted[i] ); pakfile = FS_BuildOSPath( path, dir, sorted[i] );

View File

@ -676,15 +676,6 @@ extern char cl_cdkey[34];
// returnbed by Sys_GetProcessorId // returnbed by Sys_GetProcessorId
#define CPUID_GENERIC 0 // any unrecognized processor #define CPUID_GENERIC 0 // any unrecognized processor
#define CPUID_AXP 0x10
#define CPUID_INTEL_UNSUPPORTED 0x20 // Intel 386/486
#define CPUID_INTEL_PENTIUM 0x21 // Intel Pentium or PPro
#define CPUID_INTEL_MMX 0x22 // Intel Pentium/MMX or P2/MMX
#define CPUID_INTEL_KATMAI 0x23 // Intel Katmai
#define CPUID_AMD_3DNOW 0x30 // AMD K6 3DNOW!
// TTimo // TTimo
// centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated) // centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
#define MAXPRINTMSG 4096 #define MAXPRINTMSG 4096

View File

@ -325,7 +325,7 @@ Dlls will call this directly
============ ============
*/ */
int QDECL VM_DllSyscall( int arg, ... ) { int QDECL VM_DllSyscall( int arg, ... ) {
#if ((defined __linux__) && (defined __powerpc__)) #ifdef _WIN64
// rcg010206 - see commentary above // rcg010206 - see commentary above
int args[16]; int args[16];
int i; int i;
@ -541,6 +541,10 @@ vm_t *VM_Create( const char *module, int (*systemCalls)(int *),
// copy or compile the instructions // copy or compile the instructions
vm->codeLength = header->codeLength; vm->codeLength = header->codeLength;
#ifdef _WIN64
vm->compiled = qfalse;
VM_PrepareInterpreter( vm, header );
#else
if ( interpret >= VMI_COMPILED ) { if ( interpret >= VMI_COMPILED ) {
vm->compiled = qtrue; vm->compiled = qtrue;
VM_Compile( vm, header ); VM_Compile( vm, header );
@ -548,6 +552,7 @@ vm_t *VM_Create( const char *module, int (*systemCalls)(int *),
vm->compiled = qfalse; vm->compiled = qfalse;
VM_PrepareInterpreter( vm, header ); VM_PrepareInterpreter( vm, header );
} }
#endif
// free the original file // free the original file
FS_FreeFile( header ); FS_FreeFile( header );
@ -698,10 +703,27 @@ int QDECL VM_Call( vm_t *vm, int callnum, ... ) {
args[4], args[5], args[6], args[7], args[4], args[5], args[6], args[7],
args[8], args[9], args[10], args[11], args[8], args[9], args[10], args[11],
args[12], args[13], args[14], args[15]); args[12], args[13], args[14], args[15]);
} else if ( vm->compiled ) { }
#ifndef _WIN64
else if ( vm->compiled )
{
r = VM_CallCompiled( vm, &callnum ); r = VM_CallCompiled( vm, &callnum );
} else { }
r = VM_CallInterpreted( vm, &callnum ); #endif
else
{
struct {
int callnum;
int args[10];
} a;
a.callnum = callnum;
va_start(ap, callnum);
for (i = 0; i < sizeof (a.args) / sizeof (a.args[i]); i++) {
a.args[i] = va_arg(ap, int);
}
va_end(ap);
r = VM_CallInterpreted( vm, &a );
} }
if ( oldVM != NULL ) // bk001220 - assert(currentVM!=NULL) for oldVM==NULL if ( oldVM != NULL ) // bk001220 - assert(currentVM!=NULL) for oldVM==NULL

View File

@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
// vm_x86.c -- load time compiler and execution environment for x86 // vm_x86.c -- load time compiler and execution environment for x86
#ifndef _WIN64
#include "vm_local.h" #include "vm_local.h"
#ifdef __FreeBSD__ // rb0101023 #ifdef __FreeBSD__ // rb0101023
@ -1208,4 +1210,4 @@ int VM_CallCompiled( vm_t *vm, int *args ) {
} }
#endif // !DLL_ONLY #endif // !DLL_ONLY
#endif // _WIN64

View File

@ -1003,7 +1003,13 @@ qsort replacement
================= =================
*/ */
#define SWAP_DRAW_SURF(a,b) temp=((int *)a)[0];((int *)a)[0]=((int *)b)[0];((int *)b)[0]=temp; temp=((int *)a)[1];((int *)a)[1]=((int *)b)[1];((int *)b)[1]=temp; ID_INLINE void SWAP_DRAW_SURF(void* a, void* b) {
char buf[sizeof(drawSurf_t)];
Com_Memcpy(buf, a, sizeof(drawSurf_t));
Com_Memcpy(a, b, sizeof(drawSurf_t));
Com_Memcpy(b, buf, sizeof(drawSurf_t));
}
/* this parameter defines the cutoff between using quick sort and /* this parameter defines the cutoff between using quick sort and
insertion sort for arrays; arrays with lengths shorter or equal to the insertion sort for arrays; arrays with lengths shorter or equal to the
@ -1013,7 +1019,6 @@ qsort replacement
static void shortsort( drawSurf_t *lo, drawSurf_t *hi ) { static void shortsort( drawSurf_t *lo, drawSurf_t *hi ) {
drawSurf_t *p, *max; drawSurf_t *p, *max;
int temp;
while (hi > lo) { while (hi > lo) {
max = lo; max = lo;
@ -1044,11 +1049,6 @@ void qsortFast (
unsigned size; /* size of the sub-array */ unsigned size; /* size of the sub-array */
char *lostk[30], *histk[30]; char *lostk[30], *histk[30];
int stkptr; /* stack for saving sub-array to be processed */ int stkptr; /* stack for saving sub-array to be processed */
int temp;
if ( sizeof(drawSurf_t) != 8 ) {
ri.Error( ERR_DROP, "change SWAP_DRAW_SURF macro" );
}
/* Note: the number of stack entries required is no more than /* Note: the number of stack entries required is no more than
1 + log2(size), so 30 is sufficient for any array */ 1 + log2(size), so 30 is sufficient for any array */

View File

@ -566,7 +566,7 @@ static qboolean GLW_CreateWindow( const char *drivername, int width, int height,
memset( &wc, 0, sizeof( wc ) ); memset( &wc, 0, sizeof( wc ) );
wc.style = 0; wc.style = 0;
wc.lpfnWndProc = (WNDPROC) glw_state.wndproc; wc.lpfnWndProc = glw_state.wndproc;
wc.cbClsExtra = 0; wc.cbClsExtra = 0;
wc.cbWndExtra = 0; wc.cbWndExtra = 0;
wc.hInstance = g_wv.hInstance; wc.hInstance = g_wv.hInstance;
@ -1186,10 +1186,10 @@ void GLimp_Init( void )
// save off hInstance and wndproc // save off hInstance and wndproc
cv = ri.Cvar_Get( "win_hinstance", "", 0 ); cv = ri.Cvar_Get( "win_hinstance", "", 0 );
sscanf( cv->string, "%i", (int *)&g_wv.hInstance ); sscanf( cv->string, "%p", (void *)&g_wv.hInstance );
cv = ri.Cvar_Get( "win_wndproc", "", 0 ); cv = ri.Cvar_Get( "win_wndproc", "", 0 );
sscanf( cv->string, "%i", (int *)&glw_state.wndproc ); sscanf( cv->string, "%p", (void *)&glw_state.wndproc );
r_allowSoftwareGL = ri.Cvar_Get( "r_allowSoftwareGL", "0", CVAR_LATCH ); r_allowSoftwareGL = ri.Cvar_Get( "r_allowSoftwareGL", "0", CVAR_LATCH );
r_maskMinidriver = ri.Cvar_Get( "r_maskMinidriver", "0", CVAR_LATCH ); r_maskMinidriver = ri.Cvar_Get( "r_maskMinidriver", "0", CVAR_LATCH );

View File

@ -1089,8 +1089,8 @@ void Sys_Init( void ) {
} }
// save out a couple things in rom cvars for the renderer to access // save out a couple things in rom cvars for the renderer to access
Cvar_Get( "win_hinstance", va("%i", (int)g_wv.hInstance), CVAR_ROM ); Cvar_Get( "win_hinstance", va("%p", (void*)g_wv.hInstance), CVAR_ROM );
Cvar_Get( "win_wndproc", va("%i", (int)MainWndProc), CVAR_ROM ); Cvar_Get( "win_wndproc", va("%p", (void*)MainWndProc), CVAR_ROM );
// //
// figure out our CPU // figure out our CPU
@ -1107,24 +1107,6 @@ void Sys_Init( void ) {
case CPUID_GENERIC: case CPUID_GENERIC:
Cvar_Set( "sys_cpustring", "generic" ); Cvar_Set( "sys_cpustring", "generic" );
break; break;
case CPUID_INTEL_UNSUPPORTED:
Cvar_Set( "sys_cpustring", "x86 (pre-Pentium)" );
break;
case CPUID_INTEL_PENTIUM:
Cvar_Set( "sys_cpustring", "x86 (P5/PPro, non-MMX)" );
break;
case CPUID_INTEL_MMX:
Cvar_Set( "sys_cpustring", "x86 (P5/Pentium2, MMX)" );
break;
case CPUID_INTEL_KATMAI:
Cvar_Set( "sys_cpustring", "Intel Pentium III" );
break;
case CPUID_AMD_3DNOW:
Cvar_Set( "sys_cpustring", "AMD w/ 3DNow!" );
break;
case CPUID_AXP:
Cvar_Set( "sys_cpustring", "Alpha AXP" );
break;
default: default:
Com_Error( ERR_FATAL, "Unknown cpu type %d\n", cpuid ); Com_Error( ERR_FATAL, "Unknown cpu type %d\n", cpuid );
break; break;
@ -1137,26 +1119,6 @@ void Sys_Init( void ) {
{ {
cpuid = CPUID_GENERIC; cpuid = CPUID_GENERIC;
} }
else if ( !Q_stricmp( Cvar_VariableString( "sys_cpustring" ), "x87" ) )
{
cpuid = CPUID_INTEL_PENTIUM;
}
else if ( !Q_stricmp( Cvar_VariableString( "sys_cpustring" ), "mmx" ) )
{
cpuid = CPUID_INTEL_MMX;
}
else if ( !Q_stricmp( Cvar_VariableString( "sys_cpustring" ), "3dnow" ) )
{
cpuid = CPUID_AMD_3DNOW;
}
else if ( !Q_stricmp( Cvar_VariableString( "sys_cpustring" ), "PentiumIII" ) )
{
cpuid = CPUID_INTEL_KATMAI;
}
else if ( !Q_stricmp( Cvar_VariableString( "sys_cpustring" ), "axp" ) )
{
cpuid = CPUID_AXP;
}
else else
{ {
Com_Printf( "WARNING: unknown sys_cpustring '%s'\n", Cvar_VariableString( "sys_cpustring" ) ); Com_Printf( "WARNING: unknown sys_cpustring '%s'\n", Cvar_VariableString( "sys_cpustring" ) );

View File

@ -58,39 +58,11 @@ int Sys_Milliseconds (void)
Sys_SnapVector Sys_SnapVector
================ ================
*/ */
long fastftol( float f ) {
static int tmp;
__asm fld f
__asm fistp tmp
__asm mov eax, tmp
}
void Sys_SnapVector( float *v ) void Sys_SnapVector( float *v )
{ {
int i; v[0] = (int)v[0];
float f; v[1] = (int)v[1];
v[2] = (int)v[2];
f = *v;
__asm fld f;
__asm fistp i;
*v = i;
v++;
f = *v;
__asm fld f;
__asm fistp i;
*v = i;
v++;
f = *v;
__asm fld f;
__asm fistp i;
*v = i;
/*
*v = fastftol(*v);
v++;
*v = fastftol(*v);
v++;
*v = fastftol(*v);
*/
} }
@ -108,165 +80,10 @@ void Sys_SnapVector( float *v )
** **
** -------------------------------------------------------------------------------- ** --------------------------------------------------------------------------------
*/ */
static void CPUID( int func, unsigned regs[4] )
{
unsigned regEAX, regEBX, regECX, regEDX;
#ifndef __VECTORC
__asm mov eax, func
__asm __emit 00fh
__asm __emit 0a2h
__asm mov regEAX, eax
__asm mov regEBX, ebx
__asm mov regECX, ecx
__asm mov regEDX, edx
regs[0] = regEAX;
regs[1] = regEBX;
regs[2] = regECX;
regs[3] = regEDX;
#else
regs[0] = 0;
regs[1] = 0;
regs[2] = 0;
regs[3] = 0;
#endif
}
static int IsPentium( void )
{
__asm
{
pushfd // save eflags
pop eax
test eax, 0x00200000 // check ID bit
jz set21 // bit 21 is not set, so jump to set_21
and eax, 0xffdfffff // clear bit 21
push eax // save new value in register
popfd // store new value in flags
pushfd
pop eax
test eax, 0x00200000 // check ID bit
jz good
jmp err // cpuid not supported
set21:
or eax, 0x00200000 // set ID bit
push eax // store new value
popfd // store new value in EFLAGS
pushfd
pop eax
test eax, 0x00200000 // if bit 21 is on
jnz good
jmp err
}
err:
return qfalse;
good:
return qtrue;
}
static int Is3DNOW( void )
{
unsigned regs[4];
char pstring[16];
char processorString[13];
// get name of processor
CPUID( 0, ( unsigned int * ) pstring );
processorString[0] = pstring[4];
processorString[1] = pstring[5];
processorString[2] = pstring[6];
processorString[3] = pstring[7];
processorString[4] = pstring[12];
processorString[5] = pstring[13];
processorString[6] = pstring[14];
processorString[7] = pstring[15];
processorString[8] = pstring[8];
processorString[9] = pstring[9];
processorString[10] = pstring[10];
processorString[11] = pstring[11];
processorString[12] = 0;
// REMOVED because you can have 3DNow! on non-AMD systems
// if ( strcmp( processorString, "AuthenticAMD" ) )
// return qfalse;
// check AMD-specific functions
CPUID( 0x80000000, regs );
if ( regs[0] < 0x80000000 )
return qfalse;
// bit 31 of EDX denotes 3DNOW! support
CPUID( 0x80000001, regs );
if ( regs[3] & ( 1 << 31 ) )
return qtrue;
return qfalse;
}
static int IsKNI( void )
{
unsigned regs[4];
// get CPU feature bits
CPUID( 1, regs );
// bit 25 of EDX denotes KNI existence
if ( regs[3] & ( 1 << 25 ) )
return qtrue;
return qfalse;
}
static int IsMMX( void )
{
unsigned regs[4];
// get CPU feature bits
CPUID( 1, regs );
// bit 23 of EDX denotes MMX existence
if ( regs[3] & ( 1 << 23 ) )
return qtrue;
return qfalse;
}
int Sys_GetProcessorId( void ) int Sys_GetProcessorId( void )
{ {
#if defined _M_ALPHA
return CPUID_AXP;
#elif !defined _M_IX86
return CPUID_GENERIC; return CPUID_GENERIC;
#else
// verify we're at least a Pentium or 486 w/ CPUID support
if ( !IsPentium() )
return CPUID_INTEL_UNSUPPORTED;
// check for MMX
if ( !IsMMX() )
{
// Pentium or PPro
return CPUID_INTEL_PENTIUM;
}
// see if we're an AMD 3DNOW! processor
if ( Is3DNOW() )
{
return CPUID_AMD_3DNOW;
}
// see if we're an Intel Katmai
if ( IsKNI() )
{
return CPUID_INTEL_KATMAI;
}
// by default we're functionally a vanilla Pentium/MMX or P2/MMX
return CPUID_INTEL_MMX;
#endif
} }
/* /*

View File

@ -416,7 +416,7 @@ void Sys_CreateConsole( void )
g_wv.hInstance, NULL ); g_wv.hInstance, NULL );
SendMessage( s_wcd.hwndBuffer, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 ); SendMessage( s_wcd.hwndBuffer, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );
s_wcd.SysInputLineWndProc = ( WNDPROC ) SetWindowLong( s_wcd.hwndInputLine, GWL_WNDPROC, ( long ) InputLineWndProc ); s_wcd.SysInputLineWndProc = (WNDPROC)SetWindowLongPtr(s_wcd.hwndInputLine, GWLP_WNDPROC, (LONG_PTR)InputLineWndProc);
SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 ); SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );
ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT); ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT);