1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sourcepawn/include/sp_vm_types.h Sat Jul 29 21:02:28 2006 +0000
1.3 @@ -0,0 +1,202 @@
1.4 +#ifndef _INCLUDE_SOURCEPAWN_VM_TYPES_H
1.5 +#define _INCLUDE_SOURCEPAWN_VM_TYPES_H
1.6 +
1.7 +#include "sp_file_headers.h"
1.8 +
1.9 +typedef uint32_t ucell_t;
1.10 +typedef int32_t cell_t;
1.11 +
1.12 +/**
1.13 + * Error codes
1.14 + */
1.15 +#define SP_ERR_NONE 0
1.16 +#define SP_ERR_FILE_FORMAT 1 /* File format unrecognized */
1.17 +#define SP_ERR_DECOMPRESSOR 2 /* A decompressor was not found */
1.18 +
1.19 +/**********************************************
1.20 + *** The following structures are reference structures.
1.21 + *** They are not essential to the API, but are used
1.22 + *** to hold the backend database format of the plugin
1.23 + *** binary.
1.24 + **********************************************/
1.25 +
1.26 +/**
1.27 + * Information about the core plugin tables.
1.28 + * These may or may not be present!
1.29 + */
1.30 +typedef struct sp_plugin_infotab_t
1.31 +{
1.32 + const char *stringbase; /* base of string table */
1.33 + uint32_t publics_num; /* number of publics */
1.34 + sp_file_publics_t *publics; /* public table */
1.35 + uint32_t natives_num; /* number of natives */
1.36 + sp_file_natives_t *natives; /* native table */
1.37 + uint32_t pubvars_num; /* number of pubvars */
1.38 + sp_file_pubvars_t *pubvars; /* pubvars table */
1.39 +} sp_plugin_infotab_s;
1.40 +
1.41 +/**
1.42 + * Information about the plugin's debug tables.
1.43 + * These are all present if one is present.
1.44 + */
1.45 +typedef struct sp_plugin_debug_t
1.46 +{
1.47 + const char *stringbase; /* base of string table */
1.48 + uint32_t files_num; /* number of files */
1.49 + sp_fdbg_file_t *files; /* files table */
1.50 + uint32_t lines_num; /* number of lines */
1.51 + sp_fdbg_line_t *lines; /* lines table */
1.52 + uint32_t syms_num; /* number of symbols */
1.53 + sp_fdbg_symbol_t *symbols; /* symbol table */
1.54 +} sp_plugin_debug_s;
1.55 +
1.56 +#define SP_FA_SELF_EXTERNAL (1<<0)
1.57 +#define SP_FA_BASE_EXTERNAL (1<<1)
1.58 +
1.59 +/**
1.60 + * The rebased, in-memory format of a plugin.
1.61 + * This differs from the on-disk structure to ensure
1.62 + * that the format is properly read.
1.63 + */
1.64 +typedef struct sp_plugin_t
1.65 +{
1.66 + uint8_t *base; /* base of memory */
1.67 + uint8_t *pcode; /* p-code */
1.68 + uint32_t pcode_size; /* size of p-code */
1.69 + uint8_t *data; /* data size */
1.70 + uint32_t data_size; /* size of data */
1.71 + uint32_t memory; /* required memory */
1.72 + uint16_t flags; /* code flags */
1.73 + uint32_t allocflags; /* allocation flags */
1.74 + sp_plugin_infotab_t *info; /* base info table */
1.75 + sp_plugin_debug_t *debug; /* debug info table */
1.76 +} sp_plugin_s;
1.77 +
1.78 +struct sp_context_s;
1.79 +typedef int (*SPVM_NATIVE_FUNC)(sp_context_s *, cell_t *);
1.80 +
1.81 +/**********************************************
1.82 + *** The following structures are bound to the VM/JIT.
1.83 + *** Changing them will result in necessary recompilation.
1.84 + **********************************************/
1.85 +
1.86 +/**
1.87 + * Offsets and names to a public function.
1.88 + * By default, these point back to the string table
1.89 + * in the sp_plugin_infotab_t structure.
1.90 + */
1.91 +typedef struct sp_public_t
1.92 +{
1.93 + uint32_t offs; /* code offset */
1.94 + const char *name; /* name */
1.95 +} sp_publics_s;
1.96 +
1.97 +/**
1.98 + * Offsets and names to public variables.
1.99 + * The offset is relocated and the name by default
1.100 + * points back to the sp_plugin_infotab_t structure.
1.101 + */
1.102 +typedef struct sp_pubvar_t
1.103 +{
1.104 + cell_t *offs; /* pointer to data */
1.105 + const char *name; /* name */
1.106 +} sp_pubvar_t
1.107 +
1.108 +#define SP_NATIVE_NONE (0) /* Native is not yet found */
1.109 +#define SP_NATIVE_OKAY (1) /* Native has been added */
1.110 +#define SP_NATIVE_PENDING (2) /* Native is marked as usable but replaceable */
1.111 +
1.112 +/**
1.113 + * Native lookup table, by default names
1.114 + * point back to the sp_plugin_infotab_t structure.
1.115 + * A native is NULL if unit
1.116 + */
1.117 +typedef struct sp_native_t
1.118 +{
1.119 + SPVM_NATIVE_FUNC pfn; /* function pointer */
1.120 + const char * name; /* name of function */
1.121 + uint32_t status; /* status flags */
1.122 +} sp_native_t;
1.123 +
1.124 +/**
1.125 + * Debug file table
1.126 + */
1.127 +typedef struct sp_debug_file_s
1.128 +{
1.129 + uint32_t addr; /* address into code */
1.130 + const char * name; /* name of file */
1.131 +} sp_debug_file_t;
1.132 +
1.133 +/**
1.134 + * Note that line is missing. It is not necessary since
1.135 + * this can be retrieved from the base plugin info.
1.136 + */
1.137 +typedef struct sp_debug_line_s
1.138 +{
1.139 + uint32_t addr; /* address into code */
1.140 + uint32_t line; /* line no. */
1.141 +} sp_debug_line_t;
1.142 +
1.143 +typedef sp_fdbg_arraydim_t sp_debug_arraydim_t;
1.144 +
1.145 +/**
1.146 + * The majority of this struct is already located in the parent
1.147 + * block. Thus, only the relocated portions are required.
1.148 + */
1.149 +typedef struct sp_debug_symbol_s
1.150 +{
1.151 + uint32_t codestart; /* relocated code address */
1.152 + uint32_t codeend; /* relocated code end address */
1.153 + const char * name; /* relocated name */
1.154 + sp_debug_arraydim_t *dims; /* relocated dimension struct, if any */
1.155 + sp_fdbg_symbol_t *sym; /* pointer to original symbol */
1.156 +} sp_debug_symbol_t;
1.157 +
1.158 +/**
1.159 + * Executes a Context.
1.160 + * @sp_context_s - Execution Context
1.161 + * @uint32_t - Offset from code pointer
1.162 + * @res - return value of function
1.163 + * @return - error code (0=none)
1.164 + */
1.165 +typedef int (*SPVM_EXEC)(struct sp_context_s *,
1.166 + uint32_t,
1.167 + cell_t *res);
1.168 +
1.169 +#define SP_CONTEXT_DEBUG (1<<0) /* in debug mode */
1.170 +#define SP_CONTEXT_INHERIT_MEMORY (1<<1) /* inherits memory pointers */
1.171 +#define SP_CONTEXT_INHERIT_CODE (1<<2) /* inherits code pointers */
1.172 +
1.173 +/**
1.174 + * This is the heart of the VM. It contains all of the runtime
1.175 + * information about a plugin context.
1.176 + * It is split into three sections.
1.177 + */
1.178 +typedef struct sp_context_s
1.179 +{
1.180 + /* parent information */
1.181 + void *base; /* base of generated code and memory */
1.182 + sp_plugin_t *plugin; /* pointer back to parent information */
1.183 + struct sp_context_s *parent; /* pointer to parent context */
1.184 + uint32_t flags; /* context flags */
1.185 + /* execution specific data */
1.186 + SPVM_EXEC exec; /* execution base */
1.187 + cell_t pri; /* PRI register */
1.188 + cell_t alt; /* ALT register */
1.189 + cell_t *data; /* data chunk */
1.190 + cell_t *heap; /* pointer after data for start of heap */
1.191 + cell_t *sp; /* stack pointer */
1.192 + ucell_t memory; /* total memory size; */
1.193 + int32_t err; /* error code */
1.194 + uint32_t pushcount; /* push count */
1.195 + /* context rebased database */
1.196 + sp_public_t *publics /* public functions table */
1.197 + sp_pubvar_t *pubvars; /* public variables table */
1.198 + sp_native_t *natives; /* natives table */
1.199 + sp_debug_file_t *files; /* files */
1.200 + sp_debug_line_t *lines; /* lines */
1.201 + sp_debug_symbol_t *symbols; /* symbols */
1.202 +} sp_context_t;
1.203 +
1.204 +#endif //_INCLUDE_SOURCEPAWN_VM_TYPES_H
1.205 +