3 * ================================================================
4 * SourcePawn, Copyright (C) 2004-2007 AlliedModders LLC.
6 * ================================================================
8 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
9 * used or modified under the Terms and Conditions of its License Agreement,
10 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
11 * works must be licensed under the GNU General Public License (version 2 or
12 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
14 * To view the latest information, see: http://www.sourcemod.net/license.php
19 #ifndef _INCLUDE_SPFILE_HEADERS_H
20 #define _INCLUDE_SPFILE_HEADERS_H
23 * @file sp_file_headers.h
24 * @brief Defines the structure present in a SourcePawn compiled binary.
26 * Note: These structures should be 1-byte packed to match the file format.
30 #if defined __GNUC__ || defined HAVE_STDINT_
33 #if !defined HAVE_STDINT_H
34 typedef unsigned __int64 uint64_t; /**< 64bit unsigned integer */
35 typedef __int64 int64_t; /**< 64bit signed integer */
36 typedef unsigned __int32 uint32_t; /**< 32bit unsigned integer */
37 typedef __int32 int32_t; /**< 32bit signed integer */
38 typedef unsigned __int16 uint16_t; /**< 16bit unsigned integer */
39 typedef __int16 int16_t; /**< 16bit signed integer */
40 typedef unsigned __int8 uint8_t; /**< 8bit unsigned integer */
41 typedef __int8 int8_t; /**< 8bit signed integer */
46 #define SPFILE_MAGIC 0x53504646 /**< Source Pawn File Format (SPFF) */
47 #define SPFILE_VERSION 0x0101 /**< Uncompressed bytecode */
49 //:TODO: better compiler/nix support
51 #pragma pack(1) /* structures must be packed (byte-aligned) */
54 #pragma pack(1) /* structures must be packed (byte-aligned) */
57 #define SPFILE_COMPRESSION_NONE 0 /**< No compression in file */
58 #define SPFILE_COMPRESSION_GZ 1 /**< GZ compression */
61 * @brief File section header format.
63 typedef struct sp_file_section_s
65 uint32_t nameoffs; /**< Relative offset into global string table */
66 uint32_t dataoffs; /**< Offset into the data section of the file */
67 uint32_t size; /**< Size of the section's entry in the data section */
71 * @brief File header format. If compression is 0, then disksize may be 0
72 * to mean that only the imagesize is needed.
74 typedef struct sp_file_hdr_s
76 uint32_t magic; /**< Magic number */
77 uint16_t version; /**< Version code */
78 uint8_t compression;/**< Compression algorithm */
79 uint32_t disksize; /**< Size on disk */
80 uint32_t imagesize; /**< Size in memory */
81 uint8_t sections; /**< Number of sections */
82 uint32_t stringtab; /**< Offset to string table */
83 uint32_t dataoffs; /**< Offset to file proper (any compression starts here) */
86 #define SP_FLAG_DEBUG (1<<0) /**< Debug information is present in the file */
89 * @brief File-encoded format of the ".code" section.
91 typedef struct sp_file_code_s
93 uint32_t codesize; /**< Codesize in bytes */
94 uint8_t cellsize; /**< Cellsize in bytes */
95 uint8_t codeversion; /**< Version of opcodes supported */
96 uint16_t flags; /**< Flags */
97 uint32_t main; /**< Address to "main," if any */
98 uint32_t code; /**< Relative offset to code */
102 * @brief File-encoded format of the ".data" section.
104 typedef struct sp_file_data_s
106 uint32_t datasize; /**< Size of data section in memory */
107 uint32_t memsize; /**< Total mem required (includes data) */
108 uint32_t data; /**< File offset to data (helper) */
112 * @brief File-encoded format of the ".publics" section.
114 typedef struct sp_file_publics_s
116 uint32_t address; /**< Address relative to code section */
117 uint32_t name; /**< Index into nametable */
121 * @brief File-encoded format of the ".natives" section.
123 typedef struct sp_file_natives_s
125 uint32_t name; /**< Index into nametable */
129 * @brief File-encoded format of the ".pubvars" section.
131 typedef struct sp_file_pubvars_s
133 uint32_t address; /**< Address relative to the DAT section */
134 uint32_t name; /**< Index into nametable */
137 #if defined __linux__
138 #pragma pack() /* reset default packing */
140 #pragma pack(pop) /* reset previous packing */
144 * @brief File-encoded debug information table.
146 typedef struct sp_fdbg_info_s
148 uint32_t num_files; /**< number of files */
149 uint32_t num_lines; /**< number of lines */
150 uint32_t num_syms; /**< number of symbols */
151 uint32_t num_arrays; /**< number of symbols which are arrays */
155 * @brief File-encoded debug file table.
157 typedef struct sp_fdbg_file_s
159 uint32_t addr; /**< Address into code */
160 uint32_t name; /**< Offset into debug nametable */
164 * @brief File-encoded debug line table.
166 typedef struct sp_fdbg_line_s
168 uint32_t addr; /**< Address into code */
169 uint32_t line; /**< Line number */
172 #define SP_SYM_VARIABLE 1 /**< Cell that has an address and that can be fetched directly (lvalue) */
173 #define SP_SYM_REFERENCE 2 /**< VARIABLE, but must be dereferenced */
174 #define SP_SYM_ARRAY 3 /**< Symbol is an array */
175 #define SP_SYM_REFARRAY 4 /**< An array passed by reference (i.e. a pointer) */
176 #define SP_SYM_FUNCTION 9 /**< Symbol is a function */
179 * @brief File-encoded debug symbol information.
181 typedef struct sp_fdbg_symbol_s
183 int32_t addr; /**< Address rel to DAT or stack frame */
184 int16_t tagid; /**< Tag id */
185 uint32_t codestart; /**< Start scope validity in code */
186 uint32_t codeend; /**< End scope validity in code */
187 uint8_t ident; /**< Variable type */
188 uint8_t vclass; /**< Scope class (local vs global) */
189 uint16_t dimcount; /**< Dimension count (for arrays) */
190 uint32_t name; /**< Offset into debug nametable */
194 * @brief File-encoded debug symbol array dimension info.
196 typedef struct sp_fdbg_arraydim_s
198 int16_t tagid; /**< Tag id */
199 uint32_t size; /**< Size of dimension */
200 } sp_fdbg_arraydim_t;
202 /** Typedef for .names table */
203 typedef char * sp_file_nametab_t;
205 #endif //_INCLUDE_SPFILE_HEADERS_H