00001 #ifndef _INCLUDE_SPFILE_HEADERS_H 00002 #define _INCLUDE_SPFILE_HEADERS_H 00003 00004 #include <stddef.h> 00005 #if defined __GNUC__ || defined HAVE_STDINT_ 00006 #include <stdint.h> 00007 #else 00008 #if !defined HAVE_STDINT_H 00009 typedef unsigned __int64 uint64_t; 00010 typedef __int64 int64_t; 00011 typedef unsigned __int32 uint32_t; 00012 typedef __int32 int32_t; 00013 typedef unsigned __int16 uint16_t; 00014 typedef __int16 int16_t; 00015 typedef unsigned __int8 uint8_t; 00016 typedef __int8 int8_t; 00017 #define HAVE_STDINT_H 00018 #endif 00019 #endif 00020 00021 #define SPFILE_MAGIC 0x53504646 /* Source Pawn File Format (SPFF) */ 00022 //#define SPFILE_VERSION 0x0100 00023 #define SPFILE_VERSION 0x0101 /* Uncompressed bytecode */ 00024 00025 //:TODO: better compiler/nix support 00026 #if defined __linux__ 00027 #pragma pack(1) /* structures must be packed (byte-aligned) */ 00028 #else 00029 #pragma pack(push) 00030 #pragma pack(1) /* structures must be packed (byte-aligned) */ 00031 #endif 00032 00033 #define SPFILE_COMPRESSION_NONE 0 00034 #define SPFILE_COMPRESSION_GZ 1 00035 00036 typedef struct sp_file_section_s 00037 { 00038 uint32_t nameoffs; /* rel offset into global string table */ 00039 uint32_t dataoffs; 00040 uint32_t size; 00041 } sp_file_section_t; 00042 00048 typedef struct sp_file_hdr_s 00049 { 00050 uint32_t magic; /* magic number */ 00051 uint16_t version; /* version code */ 00052 uint8_t compression;/* compression algorithm */ 00053 uint32_t disksize; /* size on disk */ 00054 uint32_t imagesize; /* size in memory */ 00055 uint8_t sections; /* number of sections */ 00056 uint32_t stringtab; /* offset to string table */ 00057 uint32_t dataoffs; /* offset to file proper (any compression starts here) */ 00058 } sp_file_hdr_t; 00059 00060 #define SP_FLAG_DEBUG (1<<0) 00061 00062 /* section is ".code" */ 00063 typedef struct sp_file_code_s 00064 { 00065 uint32_t codesize; /* codesize in bytes */ 00066 uint8_t cellsize; /* cellsize in bytes */ 00067 uint8_t codeversion; /* version of opcodes supported */ 00068 uint16_t flags; /* flags */ 00069 uint32_t main; /* address to "main" if any */ 00070 uint32_t code; /* rel offset to code */ 00071 } sp_file_code_t; 00072 00073 /* section is .data */ 00074 typedef struct sp_file_data_s 00075 { 00076 uint32_t datasize; /* size of data section in memory */ 00077 uint32_t memsize; /* total mem required (includes data) */ 00078 uint32_t data; /* file offset to data (helper) */ 00079 } sp_file_data_t; 00080 00081 /* section is .publics */ 00082 typedef struct sp_file_publics_s 00083 { 00084 uint32_t address; /* address rel to code section */ 00085 uint32_t name; /* index into nametable */ 00086 } sp_file_publics_t; 00087 00088 /* section is .natives */ 00089 typedef struct sp_file_natives_s 00090 { 00091 uint32_t name; /* name of native at index */ 00092 } sp_file_natives_t; 00093 00094 /* section is .libraries */ 00095 typedef struct sp_file_libraries_s 00096 { 00097 uint32_t name; /* index into nametable */ 00098 } sp_file_libraries_t; 00099 00100 /* section is .pubvars */ 00101 typedef struct sp_file_pubvars_s 00102 { 00103 uint32_t address; /* address rel to dat section */ 00104 uint32_t name; /* index into nametable */ 00105 } sp_file_pubvars_t; 00106 00107 #if defined __linux__ 00108 #pragma pack() /* reset default packing */ 00109 #else 00110 #pragma pack(pop) /* reset previous packing */ 00111 #endif 00112 00113 typedef struct sp_fdbg_info_s 00114 { 00115 uint32_t num_files; /* number of files */ 00116 uint32_t num_lines; /* number of lines */ 00117 uint32_t num_syms; /* number of symbols */ 00118 uint32_t num_arrays; /* number of symbols which are arrays */ 00119 } sp_fdbg_info_t; 00120 00124 typedef struct sp_fdbg_file_s 00125 { 00126 uint32_t addr; /* address into code */ 00127 uint32_t name; /* offset into debug nametable */ 00128 } sp_fdbg_file_t; 00129 00130 typedef struct sp_fdbg_line_s 00131 { 00132 uint32_t addr; /* address into code */ 00133 uint32_t line; /* line number */ 00134 } sp_fdbg_line_t; 00135 00136 #define SP_SYM_VARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */ 00137 #define SP_SYM_REFERENCE 2 /* VARIABLE, but must be dereferenced */ 00138 #define SP_SYM_ARRAY 3 00139 #define SP_SYM_REFARRAY 4 /* an array passed by reference (i.e. a pointer) */ 00140 #define SP_SYM_FUNCTION 9 00141 00142 typedef struct sp_fdbg_symbol_s 00143 { 00144 int32_t addr; /* address rel to DAT or stack frame */ 00145 int16_t tagid; /* tag id */ 00146 uint32_t codestart; /* start scope validity in code */ 00147 uint32_t codeend; /* end scope validity in code */ 00148 uint8_t ident; /* variable type */ 00149 uint8_t vclass; /* scope class (local vs global) */ 00150 uint16_t dimcount; /* dimension count (for arrays) */ 00151 uint32_t name; /* offset into debug nametable */ 00152 } sp_fdbg_symbol_t; 00153 00154 typedef struct sp_fdbg_arraydim_s 00155 { 00156 int16_t tagid; /* tag id */ 00157 uint32_t size; /* size of dimension */ 00158 } sp_fdbg_arraydim_t; 00159 00160 /* section is .names */ 00161 typedef char * sp_file_nametab_t; 00162 00163 #endif //_INCLUDE_SPFILE_HEADERS_H