public/sourcepawn/sp_file_headers.h
author David Anderson <dvander@alliedmods.net>
Wed Apr 11 16:07:44 2007 +0000 (2007-04-11)
changeset 679 aa756b3f37a3
parent 381 6cdf2043513c
child 1231 17badaf66ce4
permissions -rw-r--r--
removed unused libraries section
added tag section for sawce
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourcePawn, Copyright (C) 2004-2007 AlliedModders LLC. 
     5  * All rights reserved.
     6  * ================================================================
     7  *
     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.
    13  * 
    14  * To view the latest information, see: http://www.sourcemod.net/license.php
    15  *
    16  * Version: $Id$
    17  */
    18 
    19 #ifndef _INCLUDE_SPFILE_HEADERS_H
    20 #define _INCLUDE_SPFILE_HEADERS_H
    21 
    22 /** 
    23  * @file sp_file_headers.h
    24  * @brief Defines the structure present in a SourcePawn compiled binary.
    25  *
    26  * Note: These structures should be 1-byte packed to match the file format.
    27  */
    28 
    29 #include <stddef.h>
    30 #if defined __GNUC__ || defined HAVE_STDINT_
    31 #include <stdint.h>
    32 #else
    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 */
    42  #define HAVE_STDINT_H
    43  #endif
    44 #endif
    45 
    46 #define SPFILE_MAGIC	0x53504646		/**< Source Pawn File Format (SPFF) */
    47 #define SPFILE_VERSION	0x0101			/**< Uncompressed bytecode */
    48 
    49 //:TODO: better compiler/nix support
    50 #if defined __linux__
    51 	#pragma pack(1)         /* structures must be packed (byte-aligned) */
    52 #else
    53 	#pragma pack(push)
    54 	#pragma pack(1)         /* structures must be packed (byte-aligned) */
    55 #endif
    56 
    57 #define SPFILE_COMPRESSION_NONE		0		/**< No compression in file */
    58 #define SPFILE_COMPRESSION_GZ		1		/**< GZ compression */
    59 
    60 /**
    61  * @brief File section header format.
    62  */
    63 typedef struct sp_file_section_s
    64 {
    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 */
    68 } sp_file_section_t;
    69 
    70 /**
    71  * @brief File header format.  If compression is 0, then disksize may be 0 
    72  * to mean that only the imagesize is needed.
    73  */
    74 typedef struct sp_file_hdr_s
    75 {
    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) */
    84 } sp_file_hdr_t;
    85 
    86 #define SP_FLAG_DEBUG	(1<<0)		/**< Debug information is present in the file */
    87 
    88 /**
    89  * @brief File-encoded format of the ".code" section.
    90  */
    91 typedef struct sp_file_code_s
    92 {
    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 */
    99 } sp_file_code_t;
   100 
   101 /** 
   102  * @brief File-encoded format of the ".data" section.
   103  */
   104 typedef struct sp_file_data_s
   105 {
   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) */
   109 } sp_file_data_t;
   110 
   111 /**
   112  * @brief File-encoded format of the ".publics" section.
   113  */
   114 typedef struct sp_file_publics_s
   115 {
   116 	uint32_t	address;		/**< Address relative to code section */
   117 	uint32_t	name;			/**< Index into nametable */
   118 } sp_file_publics_t;
   119 
   120 /**
   121  * @brief File-encoded format of the ".natives" section.
   122  */
   123 typedef struct sp_file_natives_s
   124 {
   125 	uint32_t	name;			/**< Index into nametable */
   126 } sp_file_natives_t;
   127 
   128 /**
   129  * @brief File-encoded format of the ".pubvars" section.
   130  */
   131 typedef struct sp_file_pubvars_s
   132 {
   133 	uint32_t	address;		/**< Address relative to the DAT section */
   134 	uint32_t	name;			/**< Index into nametable */
   135 } sp_file_pubvars_t;
   136 
   137 /**
   138  * @brief File-encoded tag info.
   139  */
   140 typedef struct sp_file_tag_s
   141 {
   142 	uint32_t	tag_id;			/**< Tag ID from compiler */
   143 	uint32_t	name;			/**< Index into nametable */
   144 } sp_file_tag_t;
   145 
   146 #if defined __linux__
   147 	#pragma pack()    /* reset default packing */
   148 #else
   149 	#pragma pack(pop) /* reset previous packing */
   150 #endif
   151 
   152 /**
   153  * @brief File-encoded debug information table.
   154  */
   155 typedef struct sp_fdbg_info_s
   156 {
   157 	uint32_t	num_files;	/**< number of files */
   158 	uint32_t	num_lines;	/**< number of lines */
   159 	uint32_t	num_syms;	/**< number of symbols */
   160 	uint32_t	num_arrays;	/**< number of symbols which are arrays */
   161 } sp_fdbg_info_t;
   162 
   163 /**
   164  * @brief File-encoded debug file table.
   165  */
   166 typedef struct sp_fdbg_file_s
   167 {
   168 	uint32_t	addr;		/**< Address into code */
   169 	uint32_t	name;		/**< Offset into debug nametable */
   170 } sp_fdbg_file_t;
   171 
   172 /**
   173  * @brief File-encoded debug line table.
   174  */
   175 typedef struct sp_fdbg_line_s
   176 {
   177 	uint32_t	addr;		/**< Address into code */
   178 	uint32_t	line;		/**< Line number */
   179 } sp_fdbg_line_t;
   180 
   181 #define SP_SYM_VARIABLE  1  /**< Cell that has an address and that can be fetched directly (lvalue) */
   182 #define SP_SYM_REFERENCE 2  /**< VARIABLE, but must be dereferenced */
   183 #define SP_SYM_ARRAY     3	/**< Symbol is an array */
   184 #define SP_SYM_REFARRAY  4  /**< An array passed by reference (i.e. a pointer) */
   185 #define SP_SYM_FUNCTION	 9  /**< Symbol is a function */
   186 
   187 /**
   188  * @brief File-encoded debug symbol information.
   189  */
   190 typedef struct sp_fdbg_symbol_s
   191 {
   192 	int32_t		addr;		/**< Address rel to DAT or stack frame */
   193 	int16_t		tagid;		/**< Tag id */
   194 	uint32_t	codestart;	/**< Start scope validity in code */
   195 	uint32_t	codeend;	/**< End scope validity in code */
   196 	uint8_t		ident;		/**< Variable type */
   197 	uint8_t		vclass;		/**< Scope class (local vs global) */
   198 	uint16_t	dimcount;	/**< Dimension count (for arrays) */
   199 	uint32_t	name;		/**< Offset into debug nametable */
   200 } sp_fdbg_symbol_t;
   201 
   202 /**
   203  * @brief File-encoded debug symbol array dimension info.
   204  */
   205 typedef struct sp_fdbg_arraydim_s
   206 {
   207 	int16_t		tagid;		/**< Tag id */
   208 	uint32_t	size;		/**< Size of dimension */
   209 } sp_fdbg_arraydim_t;
   210 
   211 /** Typedef for .names table */
   212 typedef char * sp_file_nametab_t;
   213 
   214 #endif //_INCLUDE_SPFILE_HEADERS_H