1 #ifndef _INCLUDE_SOURCEPAWN_VM_TYPES_H
2 #define _INCLUDE_SOURCEPAWN_VM_TYPES_H
4 #include "sp_file_headers.h"
6 typedef uint32_t ucell_t;
7 typedef int32_t cell_t;
13 #define SP_ERR_FILE_FORMAT 1 /* File format unrecognized */
14 #define SP_ERR_DECOMPRESSOR 2 /* A decompressor was not found */
15 #define SP_ERR_HEAPLOW 3 /* Not enough space left on the heap */
16 #define SP_ERR_PARAM 4 /* Invalid parameter */
17 #define SP_ERR_INVALID_ADDRESS 5 /* A memory address was not valid */
18 #define SP_ERR_NOT_FOUND 6 /* The object in question was not found */
20 /**********************************************
21 *** The following structures are reference structures.
22 *** They are not essential to the API, but are used
23 *** to hold the backend database format of the plugin
25 **********************************************/
28 * Information about the core plugin tables.
29 * These may or may not be present!
31 typedef struct sp_plugin_infotab_s
33 const char *stringbase; /* base of string table */
34 uint32_t publics_num; /* number of publics */
35 sp_file_publics_t *publics; /* public table */
36 uint32_t natives_num; /* number of natives */
37 sp_file_natives_t *natives; /* native table */
38 uint32_t pubvars_num; /* number of pubvars */
39 sp_file_pubvars_t *pubvars; /* pubvars table */
40 } sp_plugin_infotab_t;
43 * Information about the plugin's debug tables.
44 * These are all present if one is present.
46 typedef struct sp_plugin_debug_s
48 const char *stringbase; /* base of string table */
49 uint32_t files_num; /* number of files */
50 sp_fdbg_file_t *files; /* files table */
51 uint32_t lines_num; /* number of lines */
52 sp_fdbg_line_t *lines; /* lines table */
53 uint32_t syms_num; /* number of symbols */
54 sp_fdbg_symbol_t *symbols; /* symbol table */
57 #define SP_FA_SELF_EXTERNAL (1<<0)
58 #define SP_FA_BASE_EXTERNAL (1<<1)
61 * The rebased, in-memory format of a plugin.
62 * This differs from the on-disk structure to ensure
63 * that the format is properly read.
65 typedef struct sp_plugin_s
67 uint8_t *base; /* base of memory */
68 uint8_t *pcode; /* p-code */
69 uint32_t pcode_size; /* size of p-code */
70 uint8_t *data; /* data size */
71 uint32_t data_size; /* size of data */
72 uint32_t memory; /* required memory */
73 uint16_t flags; /* code flags */
74 uint32_t allocflags; /* allocation flags */
75 sp_plugin_infotab_t *info; /* base info table */
76 sp_plugin_debug_t *debug; /* debug info table */
80 typedef int (*SPVM_NATIVE_FUNC)(struct sp_context_s *, cell_t *);
82 /**********************************************
83 *** The following structures are bound to the VM/JIT.
84 *** Changing them will result in necessary recompilation.
85 **********************************************/
88 * Offsets and names to a public function.
89 * By default, these point back to the string table
90 * in the sp_plugin_infotab_t structure.
92 typedef struct sp_public_s
94 uint32_t offs; /* code offset */
95 const char *name; /* name */
99 * Offsets and names to public variables.
100 * The offset is relocated and the name by default
101 * points back to the sp_plugin_infotab_t structure.
103 typedef struct sp_pubvar_s
105 cell_t *offs; /* pointer to data */
106 const char *name; /* name */
109 #define SP_NATIVE_NONE (0) /* Native is not yet found */
110 #define SP_NATIVE_OKAY (1) /* Native has been added */
111 #define SP_NATIVE_PENDING (2) /* Native is marked as usable but replaceable */
114 * Native lookup table, by default names
115 * point back to the sp_plugin_infotab_t structure.
116 * A native is NULL if unit
118 typedef struct sp_native_s
120 SPVM_NATIVE_FUNC pfn; /* function pointer */
121 const char * name; /* name of function */
122 uint32_t status; /* status flags */
128 typedef struct sp_debug_file_s
130 uint32_t addr; /* address into code */
131 const char * name; /* name of file */
135 * Note that line is missing. It is not necessary since
136 * this can be retrieved from the base plugin info.
138 typedef struct sp_debug_line_s
140 uint32_t addr; /* address into code */
141 uint32_t line; /* line no. */
144 typedef sp_fdbg_arraydim_t sp_debug_arraydim_t;
147 * The majority of this struct is already located in the parent
148 * block. Thus, only the relocated portions are required.
150 typedef struct sp_debug_symbol_s
152 uint32_t codestart; /* relocated code address */
153 uint32_t codeend; /* relocated code end address */
154 const char * name; /* relocated name */
155 sp_debug_arraydim_t *dims; /* relocated dimension struct, if any */
156 sp_fdbg_symbol_t *sym; /* pointer to original symbol */
160 * Executes a Context.
161 * @sp_context_s - Execution Context
162 * @uint32_t - Offset from code pointer
163 * @res - return value of function
164 * @return - error code (0=none)
166 typedef int (*SPVM_EXEC)(struct sp_context_s *,
170 #define SP_CONTEXT_DEBUG (1<<0) /* in debug mode */
171 #define SP_CONTEXT_INHERIT_MEMORY (1<<1) /* inherits memory pointers */
172 #define SP_CONTEXT_INHERIT_CODE (1<<2) /* inherits code pointers */
175 * This is the heart of the VM. It contains all of the runtime
176 * information about a plugin context.
177 * It is split into three sections.
179 typedef struct sp_context_s
181 /* parent information */
182 void *base; /* base of generated code and memory */
183 sp_plugin_t *plugin; /* pointer back to parent information */
184 struct sp_context_s *parent; /* pointer to parent context */
185 uint32_t flags; /* context flags */
186 /* execution specific data */
187 SPVM_EXEC exec; /* execution base */
188 cell_t pri; /* PRI register */
189 cell_t alt; /* ALT register */
190 uint8_t *data; /* data chunk */
191 cell_t heapbase; /* heap base */
192 cell_t hp; /* heap pointer */
193 cell_t sp; /* stack pointer */
194 ucell_t memory; /* total memory size; */
195 int32_t err; /* error code */
196 uint32_t pushcount; /* push count */
197 /* context rebased database */
198 sp_public_t *publics; /* public functions table */
199 sp_pubvar_t *pubvars; /* public variables table */
200 sp_native_t *natives; /* natives table */
201 sp_debug_file_t *files; /* files */
202 sp_debug_line_t *lines; /* lines */
203 sp_debug_symbol_t *symbols; /* symbols */
206 #endif //_INCLUDE_SOURCEPAWN_VM_TYPES_H