R:/sourcemod/trunk/sourcepawn/include/sp_vm_types.h

00001 #ifndef _INCLUDE_SOURCEPAWN_VM_TYPES_H
00002 #define _INCLUDE_SOURCEPAWN_VM_TYPES_H
00003 
00004 #include "sp_file_headers.h"
00005 
00006 typedef uint32_t        ucell_t;
00007 typedef int32_t         cell_t;
00008 typedef uint32_t        funcid_t;
00009 
00010 #include "sp_typeutil.h"
00011 
00012 #define SP_MAX_EXEC_PARAMS                              32      /* Maximum number of parameters in a function */
00013 
00018 #define SP_ERROR_NONE                                   0
00019 #define SP_ERROR_FILE_FORMAT                    1       /* File format unrecognized */
00020 #define SP_ERROR_DECOMPRESSOR                   2       /* A decompressor was not found */
00021 #define SP_ERROR_HEAPLOW                                3       /* Not enough space left on the heap */
00022 #define SP_ERROR_PARAM                                  4       /* Invalid parameter or parameter type */
00023 #define SP_ERROR_INVALID_ADDRESS                5       /* A memory address was not valid */
00024 #define SP_ERROR_NOT_FOUND                              6       /* The object in question was not found */
00025 #define SP_ERROR_INDEX                                  7       /* Invalid index parameter */
00026 #define SP_ERROR_STACKLOW                               8       /* Nnot enough space left on the stack */
00027 #define SP_ERROR_NOTDEBUGGING                   9       /* Debug mode was not on or debug section not found */
00028 #define SP_ERROR_INVALID_INSTRUCTION    10      /* Invalid instruction was encountered */
00029 #define SP_ERROR_MEMACCESS                              11      /* Invalid memory access */
00030 #define SP_ERROR_STACKMIN                               12      /* Stack went beyond its minimum value */
00031 #define SP_ERROR_HEAPMIN                                13  /* Heap went beyond its minimum value */
00032 #define SP_ERROR_DIVIDE_BY_ZERO                 14      /* Division by zero */
00033 #define SP_ERROR_ARRAY_BOUNDS                   15      /* Array index is out of bounds */
00034 #define SP_ERROR_INSTRUCTION_PARAM              16      /* Instruction had an invalid parameter */
00035 #define SP_ERROR_STACKLEAK                              17  /* A native leaked an item on the stack */
00036 #define SP_ERROR_HEAPLEAK                               18  /* A native leaked an item on the heap */
00037 #define SP_ERROR_ARRAY_TOO_BIG                  19      /* A dynamic array is too big */
00038 #define SP_ERROR_TRACKER_BOUNDS                 20      /* Tracker stack is out of bounds */
00039 #define SP_ERROR_INVALID_NATIVE                 21      /* Native was pending or invalid */
00040 #define SP_ERROR_PARAMS_MAX                             22      /* Maximum number of parameters reached */
00041 #define SP_ERROR_NATIVE                                 23      /* Error originates from a native */
00042 
00043 /**********************************************
00044  *** The following structures are reference structures.
00045  *** They are not essential to the API, but are used
00046  ***  to hold the back end database format of the plugin
00047  ***  binary.
00048  **********************************************/
00049 
00054 typedef struct sp_plugin_infotab_s
00055 {
00056         const char *stringbase;         /* base of string table */
00057         uint32_t        publics_num;    /* number of publics */
00058         sp_file_publics_t *publics;     /* public table */
00059         uint32_t        natives_num;    /* number of natives */
00060         sp_file_natives_t *natives; /* native table */
00061         uint32_t        pubvars_num;    /* number of pubvars */
00062         sp_file_pubvars_t *pubvars;     /* pubvars table */     
00063         uint32_t libraries_num;         /* number of libraries */
00064         sp_file_libraries_t *lib;       /* library table */
00065 } sp_plugin_infotab_t;
00066 
00071 typedef struct sp_plugin_debug_s
00072 {
00073         const char *stringbase;         /* base of string table */
00074         uint32_t        files_num;              /* number of files */
00075         sp_fdbg_file_t *files;          /* files table */
00076         uint32_t        lines_num;              /* number of lines */
00077         sp_fdbg_line_t *lines;          /* lines table */
00078         uint32_t        syms_num;               /* number of symbols */
00079         sp_fdbg_symbol_t *symbols;      /* symbol table */
00080 } sp_plugin_debug_t;
00081 
00082 #define SP_FA_SELF_EXTERNAL             (1<<0)
00083 #define SP_FA_BASE_EXTERNAL             (1<<1)
00084 
00090 typedef struct sp_plugin_s
00091 {
00092         uint8_t         *base;                  /* base of memory */
00093         uint8_t         *pcode;                 /* p-code */
00094         uint32_t        pcode_size;             /* size of p-code */
00095         uint8_t         *data;                  /* data size */
00096         uint32_t        data_size;              /* size of data */
00097         uint32_t        memory;                 /* required memory */
00098         uint16_t        flags;                  /* code flags */
00099         uint32_t        allocflags;             /* allocation flags */
00100         sp_plugin_infotab_t info;       /* base info table */
00101         sp_plugin_debug_t   debug;      /* debug info table */
00102 } sp_plugin_t;
00103 
00106 namespace SourcePawn
00107 {
00108         class IPluginContext;
00109         class IVirtualMachine;
00110 };
00111 
00112 struct sp_context_s;
00113 
00114 typedef cell_t (*SPVM_NATIVE_FUNC)(SourcePawn::IPluginContext *, const cell_t *);
00115 
00116 /**********************************************
00117  *** The following structures are bound to the VM/JIT.
00118  *** Changing them will result in necessary recompilation.
00119  **********************************************/
00120 
00126 typedef struct sp_public_s
00127 {
00128         funcid_t        funcid;         /* encoded function id */
00129         uint32_t        code_offs;      /* code offset */
00130         const char *name;               /* name */
00131 } sp_public_t;
00132 
00138 typedef struct sp_pubvar_s
00139 {
00140         cell_t     *offs;               /* pointer to data */
00141         const char *name;               /* name */
00142 } sp_pubvar_t;
00143 
00144 #define SP_NATIVE_UNBOUND               (0)             /* Native is undefined */
00145 #define SP_NATIVE_BOUND                 (1)             /* Native is bound */
00146 
00152 typedef struct sp_native_s
00153 {
00154         SPVM_NATIVE_FUNC        pfn;    /* function pointer */
00155         const char *            name;   /* name of function */
00156         uint32_t                        status; /* status flags */
00157 } sp_native_t;
00158 
00162 typedef struct sp_nativeinfo_s
00163 {
00164         const char              *name;
00165         SPVM_NATIVE_FUNC func;
00166 } sp_nativeinfo_t;
00167 
00171 typedef struct sp_debug_file_s
00172 {
00173         uint32_t                addr;   /* address into code */
00174         const char *    name;   /* name of file */
00175 } sp_debug_file_t;
00176 
00181 typedef struct sp_debug_line_s
00182 {
00183         uint32_t                addr;   /* address into code */
00184         uint32_t                line;   /* line no. */
00185 } sp_debug_line_t;
00186 
00187 typedef sp_fdbg_arraydim_t      sp_debug_arraydim_t;
00188 
00193 typedef struct sp_debug_symbol_s
00194 {
00195         uint32_t                codestart;      /* relocated code address */
00196         uint32_t                codeend;        /* relocated code end address */
00197         const char *    name;           /* relocated name */
00198         sp_debug_arraydim_t *dims;      /* relocated dimension struct, if any */
00199         sp_fdbg_symbol_t        *sym;   /* pointer to original symbol */
00200 } sp_debug_symbol_t;
00201 
00209 typedef int (*SPVM_DEBUGBREAK)(struct sp_context_s *, uint32_t, uint32_t);
00210 
00211 #define SPFLAG_PLUGIN_DEBUG             (1<<0)          /* plugin is in debug mode */
00212 
00219 typedef struct sp_context_s
00220 {
00221         /* general/parent information */
00222         void                    *codebase;      /* base of generated code and memory */
00223         sp_plugin_t             *plugin;        /* pointer back to parent information */
00224         SourcePawn::IPluginContext *context;    /* pointer to IPluginContext */
00225         SourcePawn::IVirtualMachine *vmbase;    /* pointer to IVirtualMachine */
00226         void                    *user[4];       /* user specific pointers */
00227         void                    *vm[4];         /* VM specific pointers */
00228         uint32_t                flags;          /* compilation flags */
00229         SPVM_DEBUGBREAK dbreak;         /* debug break function */
00230         /* context runtime information */
00231         uint8_t                 *memory;        /* data chunk */
00232         ucell_t                 mem_size;       /* total memory size; */
00233         cell_t                  data_size;      /* data chunk size, always starts at 0 */
00234         cell_t                  heap_base;      /* where the heap starts */
00235         /* execution specific data */
00236         cell_t                  hp;                     /* heap pointer */
00237         cell_t                  sp;                     /* stack pointer */
00238         cell_t                  frm;            /* frame pointer */
00239         uint32_t                pushcount;      /* push count */
00240         int32_t                 n_err;          /* error code set by a native */
00241         uint32_t                n_idx;          /* current native index being executed */
00242         /* context rebased database */
00243         sp_public_t             *publics;       /* public functions table */
00244         sp_pubvar_t             *pubvars;       /* public variables table */
00245         sp_native_t             *natives;       /* natives table */
00246         sp_debug_file_t *files;         /* files */
00247         sp_debug_line_t *lines;         /* lines */
00248         sp_debug_symbol_t *symbols;     /* symbols */
00249 } sp_context_t;
00250 
00251 #endif //_INCLUDE_SOURCEPAWN_VM_TYPES_H

Generated on Thu Jan 4 13:34:37 2007 for SourcePawn JIT by  doxygen 1.5.1-p1