2007-01-25 23:32:29 +01:00
|
|
|
/**
|
2007-01-25 23:39:12 +01:00
|
|
|
* ================================================================
|
|
|
|
* SourcePawn (C)2004-2007 AlliedModders LLC. All rights reserved.
|
|
|
|
* ================================================================
|
2007-01-25 23:32:29 +01:00
|
|
|
*
|
|
|
|
* This file is not open source and may not be copied without explicit
|
|
|
|
* written permission of AlliedModders LLC. This file may not be redistributed
|
|
|
|
* in whole or significant part.
|
|
|
|
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
2006-09-20 02:41:24 +02:00
|
|
|
#ifndef _INCLUDE_SOURCEPAWN_JIT_X86_H_
|
|
|
|
#define _INCLUDE_SOURCEPAWN_JIT_X86_H_
|
|
|
|
|
2006-09-20 04:56:20 +02:00
|
|
|
#include <sp_vm_types.h>
|
2006-09-20 02:41:24 +02:00
|
|
|
#include <sp_vm_api.h>
|
2007-01-25 09:31:52 +01:00
|
|
|
#include "../jit_helpers.h"
|
2006-09-20 02:41:24 +02:00
|
|
|
|
|
|
|
using namespace SourcePawn;
|
|
|
|
|
2006-09-20 10:44:21 +02:00
|
|
|
#define JIT_INLINE_ERRORCHECKS (1<<0)
|
|
|
|
#define JIT_INLINE_NATIVES (1<<1)
|
2006-11-11 06:47:00 +01:00
|
|
|
#define STACK_MARGIN 64 //8 parameters of safety, I guess
|
|
|
|
#define JIT_FUNCMAGIC 0x214D4148 //magic function offset
|
2006-09-20 10:44:21 +02:00
|
|
|
|
2006-11-02 21:23:14 +01:00
|
|
|
#define JITVARS_TRACKER 0 //important: don't change this to avoid trouble
|
2006-11-11 06:47:00 +01:00
|
|
|
#define JITVARS_FUNCINFO 1 //important: don't change this aWOAWOGJQG I LIKE HAM
|
2007-01-25 05:36:48 +01:00
|
|
|
#define JITVARS_REBASE 2 //important: hi, i'm bail
|
2006-11-02 21:23:14 +01:00
|
|
|
|
|
|
|
typedef struct tracker_s
|
|
|
|
{
|
|
|
|
size_t size;
|
|
|
|
ucell_t *pBase;
|
|
|
|
ucell_t *pCur;
|
|
|
|
} tracker_t;
|
|
|
|
|
2006-11-11 06:47:00 +01:00
|
|
|
typedef struct funcinfo_s
|
|
|
|
{
|
|
|
|
unsigned int magic;
|
|
|
|
unsigned int index;
|
|
|
|
} funcinfo_t;
|
|
|
|
|
|
|
|
typedef struct functracker_s
|
|
|
|
{
|
|
|
|
unsigned int num_functions;
|
|
|
|
unsigned int code_size;
|
|
|
|
} functracker_t;
|
|
|
|
|
2006-09-20 02:41:24 +02:00
|
|
|
class CompData : public ICompilation
|
|
|
|
{
|
|
|
|
public:
|
2006-09-20 17:51:05 +02:00
|
|
|
CompData() : plugin(NULL),
|
2006-10-12 02:27:18 +02:00
|
|
|
debug(false), inline_level(0), rebase(NULL),
|
2006-11-11 06:47:00 +01:00
|
|
|
error_set(SP_ERROR_NONE), func_idx(0)
|
2006-09-20 02:41:24 +02:00
|
|
|
{
|
|
|
|
};
|
|
|
|
public:
|
2006-10-12 02:27:18 +02:00
|
|
|
sp_plugin_t *plugin; /* plugin handle */
|
2007-01-25 09:31:52 +01:00
|
|
|
bool debug; /* whether to compile debug mode */
|
|
|
|
int inline_level; /* inline optimization level */
|
2006-10-12 02:27:18 +02:00
|
|
|
jitcode_t rebase; /* relocation map */
|
2007-01-25 09:31:52 +01:00
|
|
|
int error_set; /* error code to halt process */
|
|
|
|
unsigned int func_idx; /* current function index */
|
2006-10-12 02:27:18 +02:00
|
|
|
jitoffs_t jit_return; /* point in main call to return to */
|
2006-09-20 10:44:21 +02:00
|
|
|
jitoffs_t jit_verify_addr_eax;
|
|
|
|
jitoffs_t jit_verify_addr_edx;
|
2006-10-12 02:27:18 +02:00
|
|
|
jitoffs_t jit_break; /* call to op.break */
|
|
|
|
jitoffs_t jit_sysreq_n; /* call version of op.sysreq.n */
|
2006-10-16 06:10:01 +02:00
|
|
|
jitoffs_t jit_genarray; /* call to genarray intrinsic */
|
2006-10-10 03:55:08 +02:00
|
|
|
jitoffs_t jit_error_bounds;
|
|
|
|
jitoffs_t jit_error_divzero;
|
|
|
|
jitoffs_t jit_error_stacklow;
|
|
|
|
jitoffs_t jit_error_stackmin;
|
|
|
|
jitoffs_t jit_error_memaccess;
|
|
|
|
jitoffs_t jit_error_heaplow;
|
|
|
|
jitoffs_t jit_error_heapmin;
|
2006-10-17 00:25:18 +02:00
|
|
|
jitoffs_t jit_error_array_too_big;
|
2006-10-12 02:27:18 +02:00
|
|
|
jitoffs_t jit_extern_error; /* returning generic error */
|
|
|
|
jitoffs_t jit_sysreq_c; /* old version! */
|
|
|
|
uint32_t codesize; /* total codesize */
|
2006-09-20 02:41:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class JITX86 : public IVirtualMachine
|
|
|
|
{
|
|
|
|
public:
|
2006-09-24 20:04:18 +02:00
|
|
|
const char *GetVMName();
|
2006-09-20 02:41:24 +02:00
|
|
|
ICompilation *StartCompilation(sp_plugin_t *plugin);
|
2006-09-24 20:04:18 +02:00
|
|
|
bool SetCompilationOption(ICompilation *co, const char *key, const char *val);
|
2006-09-24 08:17:10 +02:00
|
|
|
sp_context_t *CompileToContext(ICompilation *co, int *err);
|
2006-09-20 02:41:24 +02:00
|
|
|
void AbortCompilation(ICompilation *co);
|
2006-09-24 08:17:10 +02:00
|
|
|
void FreeContext(sp_context_t *ctx);
|
2006-09-20 02:41:24 +02:00
|
|
|
int ContextExecute(sp_context_t *ctx, uint32_t code_idx, cell_t *result);
|
2006-11-11 06:47:00 +01:00
|
|
|
unsigned int GetAPIVersion();
|
|
|
|
bool FunctionLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result);
|
2007-01-25 05:36:48 +01:00
|
|
|
bool FunctionPLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result);
|
2006-11-11 06:47:00 +01:00
|
|
|
unsigned int FunctionCount(const sp_context_t *ctx);
|
2007-01-01 21:58:02 +01:00
|
|
|
const char *GetVersionString();
|
|
|
|
const char *GetCPUOptimizations();
|
2007-03-12 08:08:05 +01:00
|
|
|
SPVM_NATIVE_FUNC CreateFakeNative(SPVM_FAKENATIVE_FUNC callback, void *pData);
|
2007-03-12 21:40:30 +01:00
|
|
|
void DestroyFakeNative(SPVM_NATIVE_FUNC func);
|
2006-09-20 02:41:24 +02:00
|
|
|
};
|
|
|
|
|
2006-10-10 03:55:08 +02:00
|
|
|
cell_t NativeCallback(sp_context_t *ctx, ucell_t native_idx, cell_t *params);
|
2006-10-12 02:27:18 +02:00
|
|
|
cell_t NativeCallback_Debug(sp_context_t *ctx, ucell_t native_idx, cell_t *params);
|
2006-09-23 06:11:01 +02:00
|
|
|
jitoffs_t RelocLookup(JitWriter *jit, cell_t pcode_offs, bool relative=false);
|
|
|
|
|
2006-09-20 04:56:20 +02:00
|
|
|
#define AMX_REG_PRI REG_EAX
|
|
|
|
#define AMX_REG_ALT REG_EDX
|
2006-09-28 13:21:45 +02:00
|
|
|
#define AMX_REG_STK REG_EDI
|
|
|
|
#define AMX_REG_DAT REG_EBP
|
2006-09-20 04:56:20 +02:00
|
|
|
#define AMX_REG_TMP REG_ECX
|
|
|
|
#define AMX_REG_INFO REG_ESI
|
|
|
|
#define AMX_REG_FRM REG_EBX
|
|
|
|
|
2006-09-21 01:33:40 +02:00
|
|
|
#define AMX_INFO_FRM AMX_REG_INFO //not relocated
|
2006-09-21 07:04:51 +02:00
|
|
|
#define AMX_INFO_FRAME 0 //(same thing as above)
|
2006-09-21 01:33:40 +02:00
|
|
|
#define AMX_INFO_HEAP 4 //not relocated
|
|
|
|
#define AMX_INFO_RETVAL 8 //physical
|
|
|
|
#define AMX_INFO_CONTEXT 12 //physical
|
|
|
|
#define AMX_INFO_STACKTOP 16 //relocated
|
2006-09-20 03:59:56 +02:00
|
|
|
|
2006-09-23 06:11:01 +02:00
|
|
|
extern ISourcePawnEngine *engine;
|
|
|
|
|
2006-09-20 02:41:24 +02:00
|
|
|
#endif //_INCLUDE_SOURCEPAWN_JIT_X86_H_
|