sourcepawn/jit/x86/opcode_helpers.h
author Scott Ehlert <ds@alliedmods.net>
Sun Jul 15 08:00:26 2007 +0000 (2007-07-15)
changeset 1116 40cc5e9f0f1b
parent 853 0bca7912df0e
child 1330 ab94316bb52b
permissions -rw-r--r--
Removed strange debugging code
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourcePawn (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ================================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEPAWN_JIT_X86_OPCODE_INFO_H_
    16 #define _INCLUDE_SOURCEPAWN_JIT_X86_OPCODE_INFO_H_
    17 
    18 #include "../jit_helpers.h"
    19 
    20 /**
    21  * This outputs the execution function for a plugin.
    22  * It also returns the 'return' offset, which is used for 
    23  * breaking out of the JIT during runtime.
    24  */
    25 jitoffs_t Write_Execute_Function(JitWriter *jit);
    26 
    27 /**
    28  * Writes the Sysreq.* opcodes as a function call.
    29  */
    30 void WriteOp_Sysreq_N_Function(JitWriter *jit);
    31 void WriteOp_Sysreq_C_Function(JitWriter *jit);
    32 
    33 /**
    34  * Write the GENARRAY intrinsic function.
    35  */
    36 void WriteIntrinsic_GenArray(JitWriter *jit);
    37 
    38 /**
    39  * Generates code to set an error state in the VM and return.
    40  * This is used for generating the error set points in the VM.
    41  * GetError writes the error from the context. SetError hardcodes.
    42  */
    43 void Write_GetError(JitWriter *jit);
    44 void Write_SetError(JitWriter *jit, int error);
    45 
    46 /**
    47  * Checks the stacks for min and low errors.
    48  * :TODO: Should a variation of this go in the pushN opcodes?
    49  */
    50 void Write_CheckStack_Min(JitWriter *jit);
    51 void Write_CheckStack_Low(JitWriter *jit);
    52 
    53 /**
    54  * Checks the heap for min and low errors.
    55  */
    56 void Write_CheckHeap_Min(JitWriter *jit);
    57 void Write_CheckHeap_Low(JitWriter *jit);
    58 
    59 /**
    60  * Verifies an address by register.  The address must reside
    61  * between DAT and HP and SP and STP.
    62  */
    63 void Write_Check_VerifyAddr(JitWriter *jit, jit_uint8_t reg);
    64 
    65 /**
    66  * Checks for division by zero.
    67  */
    68 void Write_Check_DivZero(JitWriter *jit, jit_uint8_t reg);
    69 
    70 /**
    71  * Writes the break debug function.
    72  */
    73 void Write_BreakDebug(JitWriter *jit);
    74 
    75 /** 
    76  * These are for writing the PushN opcodes.
    77  */
    78 void Macro_PushN_Addr(JitWriter *jit, int i);
    79 void Macro_PushN_S(JitWriter *jit, int i);
    80 void Macro_PushN_C(JitWriter *jit, int i);
    81 void Macro_PushN(JitWriter *jit, int i);
    82 
    83 /** 
    84 * Bound checking for the tracker stack,
    85 */
    86 int JIT_VerifyLowBoundTracker(sp_context_t *ctx);
    87 int JIT_VerifyOrAllocateTracker(sp_context_t *ctx);
    88 
    89 /** 
    90 * Writes the push into tracker function.
    91 */
    92 void WriteOp_Tracker_Push_Reg(JitWriter *jit, uint8_t reg);
    93 
    94 /** 
    95 * Writes the rounding table for the float compare opcode.
    96 */
    97 void Write_RoundingTable(JitWriter *jit);
    98 
    99 /** 
   100 * Aligns the current code position to 16 bytes.
   101 */
   102 void AlignMe(JitWriter *jit);
   103 
   104 /**
   105  * Legend for Statuses:
   106  * ****** *** ********
   107  * DONE       -> code generation is done
   108  * !GEN       -> code generation is deliberate skipped because:
   109  *                 (default): compiler does not generate
   110  *                DEPRECATED: this feature no longer exists/supported
   111  *               UNSUPPORTED: this opcode is not supported
   112  *                      TODO: done in case needed
   113  * VERIFIED   -> code generation is checked as run-time working.  prefixes:
   114  *                ! errors are not checked yet.
   115  *                - non-inline errors are not checked yet.
   116  *                ~ assumed checked because of related variation, but not actually checked
   117  */
   118 
   119 typedef enum
   120 {
   121 	OP_NONE,              /* invalid opcode */
   122 	OP_LOAD_PRI,			//!VERIFIED
   123 	OP_LOAD_ALT,			//~!VERIFIED (load.pri)
   124 	OP_LOAD_S_PRI,			//VERIFIED
   125 	OP_LOAD_S_ALT,			//VERIFIED
   126 	OP_LREF_PRI,			// !GEN :TODO: we will need this for dynarrays
   127 	OP_LREF_ALT,			// !GEN :TODO: we will need this for dynarrays
   128 	OP_LREF_S_PRI,			//VERIFIED
   129 	OP_LREF_S_ALT,			//~VERIFIED (lref.s.pri)
   130 	OP_LOAD_I,				//VERIFIED
   131 	OP_LODB_I,				//VERIFIED
   132 	OP_CONST_PRI,			//VERIFIED
   133 	OP_CONST_ALT,			//~VERIFIED (const.pri)
   134 	OP_ADDR_PRI,			//VERIFIED
   135 	OP_ADDR_ALT,			//VERIFIED
   136 	OP_STOR_PRI,			//VERIFIED
   137 	OP_STOR_ALT,			//~VERIFIED (stor.pri)
   138 	OP_STOR_S_PRI,			//VERIFIED
   139 	OP_STOR_S_ALT,			//~VERIFIED (stor.s.pri)
   140 	OP_SREF_PRI,			// !GEN :TODO: we will need this for dynarrays
   141 	OP_SREF_ALT,			// !GEN :TODO: we will need this for dynarrays
   142 	OP_SREF_S_PRI,			//VERIFIED
   143 	OP_SREF_S_ALT,			//~VERIFIED (stor.s.alt)
   144 	OP_STOR_I,				//VERIFIED
   145 	OP_STRB_I,				//VERIFIED
   146 	OP_LIDX,				//VERIFIED
   147 	OP_LIDX_B,				//DONE
   148 	OP_IDXADDR,				//VERIFIED
   149 	OP_IDXADDR_B,			//DONE
   150 	OP_ALIGN_PRI,			// !GEN :TODO: - only used for pack access, drop support in compiler first
   151 	OP_ALIGN_ALT,			// !GEN :TODO: - only used for pack access, drop support in compiler first
   152 	OP_LCTRL,				// !GEN
   153 	OP_SCTRL,				// !GEN
   154 	OP_MOVE_PRI,			//~VERIFIED (move.alt)
   155 	OP_MOVE_ALT,			//VERIFIED
   156 	OP_XCHG,				//DONE
   157 	OP_PUSH_PRI,			//DONE
   158 	OP_PUSH_ALT,			//DONE
   159 	OP_PUSH_R,				// !GEN DEPRECATED
   160 	OP_PUSH_C,				//VERIFIED
   161 	OP_PUSH,				//DONE
   162 	OP_PUSH_S,				//VERIFIED
   163 	OP_POP_PRI,				//VERIFIED
   164 	OP_POP_ALT,				//VERIFIED
   165 	OP_STACK,				//VERIFIED
   166 	OP_HEAP,				//VERIFIED
   167 	OP_PROC,				//VERIFIED
   168 	OP_RET,					// !GEN
   169 	OP_RETN,				//VERIFIED
   170 	OP_CALL,				//VERIFIED
   171 	OP_CALL_PRI,			// !GEN
   172 	OP_JUMP,				//VERIFIED
   173 	OP_JREL,				// !GEN
   174 	OP_JZER,				//VERIFIED
   175 	OP_JNZ,					//DONE
   176 	OP_JEQ,					//VERIFIED
   177 	OP_JNEQ,				//VERIFIED
   178 	OP_JLESS,				// !GEN
   179 	OP_JLEQ,				// !GEN
   180 	OP_JGRTR,				// !GEN
   181 	OP_JGEQ,				// !GEN
   182 	OP_JSLESS,				//VERIFIED
   183 	OP_JSLEQ,				//VERIFIED
   184 	OP_JSGRTR,				//VERIFIED
   185 	OP_JSGEQ,				//VERIFIED
   186 	OP_SHL,					//VERIFIED
   187 	OP_SHR,					//VERIFIED (Note: operator >>>)
   188 	OP_SSHR,				//VERIFIED (Note: operator >>)
   189 	OP_SHL_C_PRI,			//DONE
   190 	OP_SHL_C_ALT,			//DONE
   191 	OP_SHR_C_PRI,			//DONE
   192 	OP_SHR_C_ALT,			//DONE
   193 	OP_SMUL,				//VERIFIED
   194 	OP_SDIV,				//DONE
   195 	OP_SDIV_ALT,			//VERIFIED
   196 	OP_UMUL,				// !GEN
   197 	OP_UDIV,				// !GEN
   198 	OP_UDIV_ALT,			// !GEN
   199 	OP_ADD,					//VERIFIED
   200 	OP_SUB,					//DONE
   201 	OP_SUB_ALT,				//VERIFIED
   202 	OP_AND,					//VERIFIED
   203 	OP_OR,					//VERIFIED
   204 	OP_XOR,					//VERIFIED
   205 	OP_NOT,					//VERIFIED
   206 	OP_NEG,					//VERIFIED
   207 	OP_INVERT,				//VERIFIED
   208 	OP_ADD_C,				//VERIFIED
   209 	OP_SMUL_C,				//VERIFIED
   210 	OP_ZERO_PRI,			//VERIFIED
   211 	OP_ZERO_ALT,			//~VERIFIED
   212 	OP_ZERO,				//VERIFIED
   213 	OP_ZERO_S,				//VERIFIED
   214 	OP_SIGN_PRI,			//DONE
   215 	OP_SIGN_ALT,			//DONE
   216 	OP_EQ,					//VERIFIED
   217 	OP_NEQ,					//VERIFIED
   218 	OP_LESS,				// !GEN
   219 	OP_LEQ,					// !GEN
   220 	OP_GRTR,				// !GEN
   221 	OP_GEQ,					// !GEN
   222 	OP_SLESS,				//VERIFIED
   223 	OP_SLEQ,				//VERIFIED
   224 	OP_SGRTR,				//VERIFIED
   225 	OP_SGEQ,				//VERIFIED
   226 	OP_EQ_C_PRI,			//DONE
   227 	OP_EQ_C_ALT,			//DONE
   228 	OP_INC_PRI,				//VERIFIED
   229 	OP_INC_ALT,				//~VERIFIED (inc.pri)
   230 	OP_INC,					//VERIFIED
   231 	OP_INC_S,				//VERIFIED
   232 	OP_INC_I,				//VERIFIED
   233 	OP_DEC_PRI,				//VERIFIED
   234 	OP_DEC_ALT,				//~VERIFIED (dec.pri)
   235 	OP_DEC,					//VERIFIED
   236 	OP_DEC_S,				//VERIFIED
   237 	OP_DEC_I,				//VERIFIED
   238 	OP_MOVS,				//VERIFIED
   239 	OP_CMPS,				// !GEN
   240 	OP_FILL,				//VERIFIED
   241 	OP_HALT,				//DONE
   242 	OP_BOUNDS,				//VERIFIED
   243 	OP_SYSREQ_PRI,			// !GEN
   244 	OP_SYSREQ_C,			//VERIFIED
   245 	OP_FILE,				// !GEN DEPRECATED
   246 	OP_LINE,				// !GEN DEPRECATED
   247 	OP_SYMBOL,				// !GEN DEPRECATED
   248 	OP_SRANGE,				// !GEN DEPRECATED
   249 	OP_JUMP_PRI,			// !GEN
   250 	OP_SWITCH,				//VERIFIED
   251 	OP_CASETBL,				//VERIFIED
   252 	OP_SWAP_PRI,			//VERIFIED
   253 	OP_SWAP_ALT,			//~VERIFIED (swap.alt)
   254 	OP_PUSH_ADR,			//VERIFIED
   255 	OP_NOP,					//VERIFIED (lol)
   256 	OP_SYSREQ_N,			//VERIFIED
   257 	OP_SYMTAG,				// !GEN DEPRECATED
   258 	OP_BREAK,				//DONE
   259 	OP_PUSH2_C,				//~VERIFIED (push3.c)
   260 	OP_PUSH2,				//VERIFIED
   261 	OP_PUSH2_S,				//VERIFIED
   262 	OP_PUSH2_ADR,			//VERIFIED
   263 	OP_PUSH3_C,				//VERIFIED
   264 	OP_PUSH3,				//~VERIFIED (push2)
   265 	OP_PUSH3_S,				//~VERIFIED (push2.s)
   266 	OP_PUSH3_ADR,			//~VERIFIED (push2.adr)
   267 	OP_PUSH4_C,				//~VERIFIED (push3.c)
   268 	OP_PUSH4,				//~VERIFIED (push2)
   269 	OP_PUSH4_S,				//~VERIFIED (push2.s)
   270 	OP_PUSH4_ADR,			//~VERIFIED (push2.adr)
   271 	OP_PUSH5_C,				//~VERIFIED (push3.c)
   272 	OP_PUSH5,				//~VERIFIED (push2)
   273 	OP_PUSH5_S,				//~VERIFIED (push2.s)
   274 	OP_PUSH5_ADR,			//~VERIFIED (push2.adr)
   275 	OP_LOAD_BOTH,			//VERIFIED
   276 	OP_LOAD_S_BOTH,			//VERIFIED
   277 	OP_CONST,				//VERIFIED
   278 	OP_CONST_S,				//DONE
   279 	/* ----- */
   280 	OP_SYSREQ_D,			// !GEN UNSUPPORT
   281 	OP_SYSREQ_ND,			// !GEN UNSUPPORT
   282 	/* ----- */
   283 	OP_TRACKER_PUSH_C,		//DONE
   284 	OP_TRACKER_POP_SETHEAP,	//VERIFIED
   285 	OP_GENARRAY,			//VERIFIED
   286 	OP_GENARRAY_Z,			//-VERIFIED (not tested for 1D arrays)
   287 	OP_STRADJUST_PRI,		//VERIFIED
   288 	OP_FABS,				//VERIFIED
   289 	OP_FLOAT,				//VERIFIED
   290 	OP_FLOATADD,			//VERIFIED
   291 	OP_FLOATSUB,			//VERIFIED
   292 	OP_FLOATMUL,			//VERIFIED
   293 	OP_FLOATDIV,			//VERIFIED
   294 	OP_RND_TO_NEAREST,		//VERIFIED
   295 	OP_RND_TO_FLOOR,		//VERIFIED
   296 	OP_RND_TO_CEIL,			//VERIFIED
   297 	OP_RND_TO_ZERO,			//VERIFIED
   298 	OP_FLOATCMP,			//VERIFIED
   299 	/* ----- */
   300 	OP_NUM_OPCODES
   301 } OPCODE;
   302 
   303 /*
   304 * :TODO: List of ASM Opts
   305 *	from jit_x86.cpp 
   306 *       DONE: Rest of opcodes including the SYSREQ.N inlined version (rev2)
   307 *			  Including genarray and the 2 tracker ones
   308 *       DONE: ALL ungen opcodes (rev1)
   309 *	from opcode_helpers.cpp
   310 *       DONE: SYSREQ.N .C (rev2)
   311 *			  MACRO OPCODES (rev2)
   312 *             ERROR CHECKS\{VERIFY ADDR} (rev2)
   313 *			  ARRAY STUFF
   314 *		TODO: BrkDebug
   315 *			  EXEC FUNCTION
   316 *			  VERIFY ADDR
   317 *
   318 *	Oh and ALIGN to 16BYTES all stuff that is called via CALL and frequently used jump labels like what's done with PROC.
   319 */
   320 
   321 #endif //_INCLUDE_SOURCEPAWN_JIT_X86_OPCODE_INFO_H_