diff --git a/sourcepawn/jit/x86/Makefile b/sourcepawn/jit/x86/Makefile new file mode 100644 index 00000000..13bc56a1 --- /dev/null +++ b/sourcepawn/jit/x86/Makefile @@ -0,0 +1,65 @@ +#(C)2004-2006 SourceMM Development Team +# Makefile written by David "BAILOPAN" Anderson + +SRCDS = ~/srcds +SMSDK = ../../.. + +### EDIT BELOW FOR OTHER PROJECTS ### + +OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing +GCC4_FLAGS = -fvisibility=hidden -fvisibility-inlines-hidden +DEBUG_FLAGS = -g -ggdb3 +CPP = gcc-4.1 +BINARY = sourcepawn.jit.x86.so + +HL2PUB = $(HL2SDK)/public +HL2LIB = $(HL2SDK)/linux_sdk + +OBJECTS = dll_exports.cpp jit_x86.cpp opcode_helpers.cpp + +LINK = -static-libgcc + +INCLUDE = -I. -I.. -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn + +ifeq "$(DEBUG)" "true" + BIN_DIR = Debug + CFLAGS = $(DEBUG_FLAGS) +else + BIN_DIR = Release + CFLAGS = $(OPT_FLAGS) +endif + +GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) + +CFLAGS += -D_LINUX -DNDEBUG -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Wno-non-virtual-dtor -Werror -fPIC -fno-exceptions -fno-rtti -msse -DHAVE_STDINT_H + +ifeq "$(GCC_VERSION)" "4" + CFLAGS += $(GCC4_FLAGS) +endif + +OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) + +$(BIN_DIR)/%.o: %.cpp + $(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< + +all: + mkdir -p $(BIN_DIR) + ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so + ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so + $(MAKE) binary + rm -rf $(BINARY) + ln -sf $(BIN_DIR)/$(BINARY) $(BINARY) + +binary: $(OBJ_LINUX) + $(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + +debug: + $(MAKE) all DEBUG=true + +default: all + +clean: + rm -rf Release/*.o + rm -rf Release/$(BINARY) + rm -rf Debug/*.o + rm -rf Debug/$(BINARY) diff --git a/sourcepawn/jit/x86/dll_exports.cpp b/sourcepawn/jit/x86/dll_exports.cpp index 5df6e0b2..3e7ea3dd 100644 --- a/sourcepawn/jit/x86/dll_exports.cpp +++ b/sourcepawn/jit/x86/dll_exports.cpp @@ -1,4 +1,5 @@ #include +#include #include "jit_x86.h" #include "dll_exports.h" @@ -33,3 +34,30 @@ EXPORTFUNC SourcePawn::IVirtualMachine *GetExport(unsigned int exportnum) return &jit; } + +#if defined __linux__ +extern "C" void __cxa_pure_virtual(void) +{ +} + +void *operator new(size_t size) +{ + return malloc(size); +} + +void *operator new[](size_t size) +{ + return malloc(size); +} + +void operator delete(void *ptr) +{ + free(ptr); +} + +void operator delete[](void * ptr) +{ + free(ptr); +} +#endif + diff --git a/sourcepawn/jit/x86/jit_x86.cpp b/sourcepawn/jit/x86/jit_x86.cpp index 2483aadf..00a2276d 100644 --- a/sourcepawn/jit/x86/jit_x86.cpp +++ b/sourcepawn/jit/x86/jit_x86.cpp @@ -1622,9 +1622,9 @@ inline void WriteOp_Sysreq_N(JitWriter *jit) jitoffs_t call = IA32_Call_Imm32(jit, 0); if (!data->debug) { - IA32_Write_Jump32_Abs(jit, call, NativeCallback); + IA32_Write_Jump32_Abs(jit, call, (void *)NativeCallback); } else { - IA32_Write_Jump32_Abs(jit, call, NativeCallback_Debug); + IA32_Write_Jump32_Abs(jit, call, (void *)NativeCallback_Debug); } /* check for errors */ @@ -1676,7 +1676,7 @@ inline void WriteOp_Tracker_Push_C(JitWriter *jit) IA32_Mov_Reg_Rm_Disp8(jit, REG_EAX, AMX_REG_INFO, AMX_INFO_CONTEXT); IA32_Push_Reg(jit, REG_EAX); jitoffs_t call = IA32_Call_Imm32(jit, 0); - IA32_Write_Jump32_Abs(jit, call, JIT_VerifyOrAllocateTracker); + IA32_Write_Jump32_Abs(jit, call, (void *)JIT_VerifyOrAllocateTracker); /* Check for errors */ //cmp eax, 0 @@ -1722,7 +1722,7 @@ inline void WriteOp_Tracker_Pop_SetHeap(JitWriter *jit) IA32_Mov_Reg_Rm_Disp8(jit, REG_EAX, AMX_REG_INFO, AMX_INFO_CONTEXT); IA32_Push_Reg(jit, REG_EAX); jitoffs_t call = IA32_Call_Imm32(jit, 0); - IA32_Write_Jump32_Abs(jit, call, JIT_VerifyLowBoundTracker); + IA32_Write_Jump32_Abs(jit, call, (void *)JIT_VerifyLowBoundTracker); /* Check for errors */ //cmp eax, 0 @@ -2198,7 +2198,7 @@ void JITX86::FreeContext(sp_context_t *ctx) delete [] ctx->symbols; engine->BaseFree(ctx->vm[JITVARS_REBASE]); free(((tracker_t *)(ctx->vm[JITVARS_TRACKER]))->pBase); - delete ctx->vm[JITVARS_TRACKER]; + delete (tracker_t *)ctx->vm[JITVARS_TRACKER]; delete ctx; } diff --git a/sourcepawn/jit/x86/jit_x86.h b/sourcepawn/jit/x86/jit_x86.h index 51de2322..a3444a48 100644 --- a/sourcepawn/jit/x86/jit_x86.h +++ b/sourcepawn/jit/x86/jit_x86.h @@ -3,7 +3,7 @@ #include #include -#include "..\jit_helpers.h" +#include "../jit_helpers.h" using namespace SourcePawn; @@ -45,7 +45,11 @@ public: }; public: sp_plugin_t *plugin; /* plugin handle */ + bool debug; /* whether to compile debug mode */ + int inline_level; /* inline optimization level */ jitcode_t rebase; /* relocation map */ + int error_set; /* error code to halt process */ + unsigned int func_idx; /* current function index */ jitoffs_t jit_return; /* point in main call to return to */ jitoffs_t jit_verify_addr_eax; jitoffs_t jit_verify_addr_edx; @@ -63,10 +67,6 @@ public: jitoffs_t jit_extern_error; /* returning generic error */ jitoffs_t jit_sysreq_c; /* old version! */ uint32_t codesize; /* total codesize */ - unsigned int func_idx; /* current function index */ - int inline_level; /* inline optimization level */ - int error_set; /* error code to halt process */ - bool debug; /* whether to compile debug mode */ }; class JITX86 : public IVirtualMachine diff --git a/sourcepawn/jit/x86/opcode_helpers.cpp b/sourcepawn/jit/x86/opcode_helpers.cpp index fda9a347..6552b3e2 100644 --- a/sourcepawn/jit/x86/opcode_helpers.cpp +++ b/sourcepawn/jit/x86/opcode_helpers.cpp @@ -429,9 +429,9 @@ void WriteOp_Sysreq_C_Function(JitWriter *jit) jitoffs_t call = IA32_Call_Imm32(jit, 0); if (!data->debug) { - IA32_Write_Jump32_Abs(jit, call, NativeCallback); + IA32_Write_Jump32_Abs(jit, call, (void *)NativeCallback); } else { - IA32_Write_Jump32_Abs(jit, call, NativeCallback_Debug); + IA32_Write_Jump32_Abs(jit, call, (void *)NativeCallback_Debug); } /* Test for error */ @@ -656,9 +656,9 @@ void WriteOp_Sysreq_N_Function(JitWriter *jit) jitoffs_t call = IA32_Call_Imm32(jit, 0); if (!data->debug) { - IA32_Write_Jump32_Abs(jit, call, NativeCallback); + IA32_Write_Jump32_Abs(jit, call, (void *)NativeCallback); } else { - IA32_Write_Jump32_Abs(jit, call, NativeCallback_Debug); + IA32_Write_Jump32_Abs(jit, call, (void *)NativeCallback_Debug); } /* Test for error */ @@ -714,7 +714,7 @@ void WriteOp_Tracker_Push_Reg(JitWriter *jit, uint8_t reg) IA32_Mov_Reg_Rm_Disp8(jit, REG_EAX, AMX_REG_INFO, AMX_INFO_CONTEXT); IA32_Push_Reg(jit, REG_EAX); jitoffs_t call = IA32_Call_Imm32(jit, 0); - IA32_Write_Jump32_Abs(jit, call, JIT_VerifyOrAllocateTracker); + IA32_Write_Jump32_Abs(jit, call, (void *)JIT_VerifyOrAllocateTracker); /* Check for errors */ //cmp eax, 0 diff --git a/sourcepawn/jit/x86/opcode_helpers.h b/sourcepawn/jit/x86/opcode_helpers.h index 4ee72424..b19890d7 100644 --- a/sourcepawn/jit/x86/opcode_helpers.h +++ b/sourcepawn/jit/x86/opcode_helpers.h @@ -1,7 +1,7 @@ #ifndef _INCLUDE_SOURCEPAWN_JIT_X86_OPCODE_INFO_H_ #define _INCLUDE_SOURCEPAWN_JIT_X86_OPCODE_INFO_H_ -#include "..\jit_helpers.h" +#include "../jit_helpers.h" /** * This outputs the execution function for a plugin. diff --git a/sourcepawn/jit/x86/opcode_switch.inc b/sourcepawn/jit/x86/opcode_switch.inc index 69a3db23..51b8676b 100644 --- a/sourcepawn/jit/x86/opcode_switch.inc +++ b/sourcepawn/jit/x86/opcode_switch.inc @@ -686,4 +686,5 @@ data->error_set = SP_ERROR_INVALID_INSTRUCTION; break; } - \ No newline at end of file + +