dvander@372: /**
dvander@375: * vim: set ts=4 :
ds@1330: * =============================================================================
dvander@1231: * SourcePawn
ds@1947: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
ds@1330: * =============================================================================
dvander@372: *
ds@1330: * This program is free software; you can redistribute it and/or modify it under
ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330: * Free Software Foundation.
dvander@379: *
ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1330: * details.
dvander@1231: *
ds@1330: * You should have received a copy of the GNU General Public License along with
ds@1330: * this program. If not, see .
dvander@1231: *
ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1330: * this exception to all derivative works. AlliedModders LLC defines further
ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330: * or .
dvander@372: *
dvander@372: * Version: $Id$
dvander@372: */
dvander@372:
dvander@324: #ifndef _INCLUDE_SOURCEPAWN_VM_TYPES_H
dvander@324: #define _INCLUDE_SOURCEPAWN_VM_TYPES_H
dvander@324:
dvander@372: /**
dvander@372: * @file sp_vm_types.h
dvander@372: * @brief Contains all run-time SourcePawn structures.
dvander@372: */
dvander@372:
dvander@324: #include "sp_file_headers.h"
dvander@324:
dvander@372: typedef uint32_t ucell_t; /**< Unsigned 32bit integer */
dvander@372: typedef int32_t cell_t; /**< Basic 32bit signed integer type for plugins */
dvander@372: typedef uint32_t funcid_t; /**< Function index code */
dvander@324:
dvander@324: #include "sp_typeutil.h"
dvander@324:
dvander@372: #define SP_MAX_EXEC_PARAMS 32 /**< Maximum number of parameters in a function */
dvander@324:
dvander@1908: #define SP_JITCONF_DEBUG "debug" /**< Configuration option for debugging. */
dvander@1908: #define SP_JITCONF_PROFILE "profile" /**< Configuration option for profiling. */
dvander@1908:
dvander@1908: #define SP_PROF_NATIVES (1<<0) /**< Profile natives. */
dvander@1908: #define SP_PROF_CALLBACKS (1<<1) /**< Profile callbacks. */
dvander@1908: #define SP_PROF_FUNCTIONS (1<<2) /**< Profile functions. */
dvander@1908:
dvander@324: /**
dvander@372: * @brief Error codes for SourcePawn routines.
dvander@324: */
dvander@372: #define SP_ERROR_NONE 0 /**< No error occurred */
dvander@372: #define SP_ERROR_FILE_FORMAT 1 /**< File format unrecognized */
dvander@372: #define SP_ERROR_DECOMPRESSOR 2 /**< A decompressor was not found */
dvander@372: #define SP_ERROR_HEAPLOW 3 /**< Not enough space left on the heap */
dvander@372: #define SP_ERROR_PARAM 4 /**< Invalid parameter or parameter type */
dvander@372: #define SP_ERROR_INVALID_ADDRESS 5 /**< A memory address was not valid */
dvander@372: #define SP_ERROR_NOT_FOUND 6 /**< The object in question was not found */
dvander@372: #define SP_ERROR_INDEX 7 /**< Invalid index parameter */
ds@729: #define SP_ERROR_STACKLOW 8 /**< Not enough space left on the stack */
dvander@372: #define SP_ERROR_NOTDEBUGGING 9 /**< Debug mode was not on or debug section not found */
dvander@372: #define SP_ERROR_INVALID_INSTRUCTION 10 /**< Invalid instruction was encountered */
dvander@372: #define SP_ERROR_MEMACCESS 11 /**< Invalid memory access */
dvander@372: #define SP_ERROR_STACKMIN 12 /**< Stack went beyond its minimum value */
dvander@372: #define SP_ERROR_HEAPMIN 13 /**< Heap went beyond its minimum value */
dvander@372: #define SP_ERROR_DIVIDE_BY_ZERO 14 /**< Division by zero */
dvander@372: #define SP_ERROR_ARRAY_BOUNDS 15 /**< Array index is out of bounds */
dvander@372: #define SP_ERROR_INSTRUCTION_PARAM 16 /**< Instruction had an invalid parameter */
dvander@372: #define SP_ERROR_STACKLEAK 17 /**< A native leaked an item on the stack */
dvander@372: #define SP_ERROR_HEAPLEAK 18 /**< A native leaked an item on the heap */
dvander@372: #define SP_ERROR_ARRAY_TOO_BIG 19 /**< A dynamic array is too big */
dvander@372: #define SP_ERROR_TRACKER_BOUNDS 20 /**< Tracker stack is out of bounds */
dvander@372: #define SP_ERROR_INVALID_NATIVE 21 /**< Native was pending or invalid */
dvander@372: #define SP_ERROR_PARAMS_MAX 22 /**< Maximum number of parameters reached */
dvander@372: #define SP_ERROR_NATIVE 23 /**< Error originates from a native */
dvander@372: #define SP_ERROR_NOT_RUNNABLE 24 /**< Function or plugin is not runnable */
dvander@560: #define SP_ERROR_ABORTED 25 /**< Function call was aborted */
dvander@2226: #define SP_ERROR_CODE_TOO_OLD 26 /**< Code is too old for this VM */
dvander@2226: #define SP_ERROR_CODE_TOO_NEW 27 /**< Code is too new for this VM */
dvander@372: //Hey you! Update the string table if you add to the end of me! */
dvander@324:
dvander@324: /**********************************************
dvander@324: *** The following structures are reference structures.
dvander@324: *** They are not essential to the API, but are used
dvander@324: *** to hold the back end database format of the plugin
dvander@324: *** binary.
dvander@324: **********************************************/
dvander@324:
dvander@324: namespace SourcePawn
dvander@324: {
dvander@324: class IPluginContext;
dvander@324: class IVirtualMachine;
dvander@1908: class IProfiler;
dvander@324: };
dvander@324:
dvander@324: struct sp_context_s;
dvander@324:
dvander@372: /**
dvander@372: * @brief Native callback prototype, passed a context and a parameter stack (0=count, 1+=args).
dvander@372: * A cell must be returned.
dvander@372: */
dvander@324: typedef cell_t (*SPVM_NATIVE_FUNC)(SourcePawn::IPluginContext *, const cell_t *);
dvander@324:
dvander@601: /**
dvander@601: * @brief Fake native callback prototype, passed a context, parameter stack, and private data.
dvander@601: * A cell must be returned.
dvander@601: */
dvander@601: typedef cell_t (*SPVM_FAKENATIVE_FUNC)(SourcePawn::IPluginContext *, const cell_t *, void *);
dvander@601:
dvander@324: /**********************************************
dvander@324: *** The following structures are bound to the VM/JIT.
dvander@324: *** Changing them will result in necessary recompilation.
dvander@324: **********************************************/
dvander@324:
dvander@324: /**
dvander@372: * @brief Offsets and names to a public function.
dvander@324: */
dvander@324: typedef struct sp_public_s
dvander@324: {
dvander@372: funcid_t funcid; /**< Encoded function id */
dvander@372: uint32_t code_offs; /**< Relocated code offset */
dvander@372: const char *name; /**< Name of function */
dvander@324: } sp_public_t;
dvander@324:
dvander@324: /**
dvander@372: * @brief Offsets and names to public variables.
dvander@372: *
dvander@372: * The offset is relocated and the name by default points back to the sp_plugin_infotab_t structure.
dvander@324: */
dvander@324: typedef struct sp_pubvar_s
dvander@324: {
dvander@372: cell_t *offs; /**< Pointer to data */
dvander@372: const char *name; /**< Name */
dvander@324: } sp_pubvar_t;
dvander@324:
dvander@372: #define SP_NATIVE_UNBOUND (0) /**< Native is undefined */
dvander@372: #define SP_NATIVE_BOUND (1) /**< Native is bound */
dvander@324:
faluco@1089: #define SP_NTVFLAG_OPTIONAL (1<<0) /**< Native is optional */
faluco@1089:
dvander@324: /**
dvander@372: * @brief Native lookup table, by default names point back to the sp_plugin_infotab_t structure.
dvander@324: */
dvander@324: typedef struct sp_native_s
dvander@324: {
dvander@372: SPVM_NATIVE_FUNC pfn; /**< Function pointer */
dvander@372: const char * name; /**< Name of function */
dvander@372: uint32_t status; /**< Status flags */
faluco@1089: uint32_t flags; /**< Native flags */
dvander@2086: void * user; /**< Host-specific data */
dvander@324: } sp_native_t;
dvander@324:
dvander@324: /**
dvander@372: * @brief Used for setting natives from modules/host apps.
dvander@324: */
dvander@324: typedef struct sp_nativeinfo_s
dvander@324: {
dvander@372: const char *name; /**< Name of the native */
dvander@372: SPVM_NATIVE_FUNC func; /**< Address of native implementation */
dvander@324: } sp_nativeinfo_t;
dvander@324:
dvander@324: /**
dvander@372: * @brief Run-time debug file table
dvander@324: */
dvander@324: typedef struct sp_debug_file_s
dvander@324: {
dvander@372: uint32_t addr; /**< Address into code */
dvander@372: const char * name; /**< Name of file */
dvander@324: } sp_debug_file_t;
dvander@324:
dvander@324: /**
dvander@372: * @brief Contains run-time debug line table.
dvander@324: */
dvander@324: typedef struct sp_debug_line_s
dvander@324: {
dvander@372: uint32_t addr; /**< Address into code */
dvander@372: uint32_t line; /**< Line number */
dvander@324: } sp_debug_line_t;
dvander@324:
dvander@372: /**
dvander@372: * @brief These structures are equivalent.
dvander@372: */
dvander@324: typedef sp_fdbg_arraydim_t sp_debug_arraydim_t;
dvander@324:
dvander@324: /**
dvander@372: * @brief The majority of this struct is already located in the parent
dvander@372: * block. Thus, only the relocated portions are required.
dvander@324: */
dvander@324: typedef struct sp_debug_symbol_s
dvander@324: {
dvander@372: uint32_t codestart; /**< Relocated code address */
ds@729: uint32_t codeend; /**< Relocated code end address */
dvander@372: const char * name; /**< Relocated name */
dvander@372: sp_debug_arraydim_t *dims; /**< Relocated dimension struct, if any */
dvander@372: sp_fdbg_symbol_t *sym; /**< Pointer to original symbol */
dvander@324: } sp_debug_symbol_t;
dvander@324:
dvander@324: #endif //_INCLUDE_SOURCEPAWN_VM_TYPES_H