2002-06-17 05:29:20 +00:00
|
|
|
/*
|
|
|
|
obj_file.h
|
|
|
|
|
|
|
|
object file support
|
|
|
|
|
2002-07-05 20:02:10 +00:00
|
|
|
Copyright (C) 2002 Bill Currie <bill@taniwha.org>
|
2002-06-17 05:29:20 +00:00
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2002/6/16
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __obj_file_h
|
|
|
|
#define __obj_file_h
|
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** \defgroup qfcc_qfo Object file functions
|
|
|
|
\ingroup qfcc
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2008-08-01 00:47:38 +00:00
|
|
|
|
2022-01-08 15:26:52 +00:00
|
|
|
#include "QF/progs/pr_comp.h"
|
|
|
|
#include "QF/progs/pr_debug.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakeio.h"
|
2002-06-21 20:46:56 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** Identifier string for qfo object files (includes terminating nul)
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2002-06-18 21:00:41 +00:00
|
|
|
#define QFO "QFO"
|
2011-02-21 01:32:20 +00:00
|
|
|
/** QFO object file format version (MMmmmRRR 0.001.006 (hex))
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-01-07 08:56:05 +00:00
|
|
|
#define QFO_VERSION 0x00001007
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** Header block of QFO object files. The sections of the object file
|
|
|
|
come immediately after the header, and are always in the order given by
|
|
|
|
the struct.
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2011-02-21 01:32:20 +00:00
|
|
|
All indices to records are 0-based from the beginning of the relevant
|
2008-08-01 00:47:38 +00:00
|
|
|
section.
|
|
|
|
*/
|
2002-06-17 05:29:20 +00:00
|
|
|
typedef struct qfo_header_s {
|
2008-08-01 00:47:38 +00:00
|
|
|
int8_t qfo[4]; ///< identifier string (includes nul) (#QFO)
|
2020-03-14 16:33:25 +00:00
|
|
|
pr_uint_t version; ///< QFO format version (#QFO_VERSION)
|
|
|
|
pr_uint_t num_spaces;
|
|
|
|
pr_uint_t num_relocs; ///< number of relocation records
|
|
|
|
pr_uint_t num_defs; ///< number of def records
|
|
|
|
pr_uint_t num_funcs; ///< number of function records
|
|
|
|
pr_uint_t num_lines; ///< number of line records
|
|
|
|
pr_uint_t num_loose_relocs; ///< number of loose relocation records
|
2012-12-04 03:48:52 +00:00
|
|
|
///< (included in num_relocs)
|
2022-01-07 08:56:05 +00:00
|
|
|
pr_uint_t progs_version; ///< version of compatible VM
|
|
|
|
pr_uint_t reserved[3];
|
2002-06-17 05:29:20 +00:00
|
|
|
} qfo_header_t;
|
|
|
|
|
2011-02-17 06:02:09 +00:00
|
|
|
typedef enum qfos_type_e {
|
|
|
|
qfos_null, ///< null space. no data or defs. first in qfo
|
|
|
|
qfos_code, ///< progs code. dstatement_t data
|
|
|
|
qfos_data, ///< progs data. pr_type_t data
|
|
|
|
qfos_string, ///< strings. char data
|
|
|
|
qfos_entity, ///< entity field defs. no data
|
|
|
|
qfos_type, ///< type encodings
|
2020-04-03 05:27:22 +00:00
|
|
|
qfos_debug, ///< debug data
|
2011-02-17 06:02:09 +00:00
|
|
|
} qfos_type_t;
|
|
|
|
|
|
|
|
/** Representation of a space in the object file.
|
|
|
|
*/
|
|
|
|
typedef struct qfo_space_s {
|
|
|
|
pr_int_t type; ///< code, string, data, entity...
|
2018-09-08 10:45:19 +00:00
|
|
|
pr_uint_t defs; ///< index of first def
|
|
|
|
pr_uint_t num_defs; ///< zero for code or string spaces
|
|
|
|
pr_uint_t data; ///< byte offset in qfo
|
2012-12-21 12:53:13 +00:00
|
|
|
pr_uint_t data_size; ///< in elements. zero for entity spaces
|
2018-09-08 10:45:19 +00:00
|
|
|
pr_uint_t id;
|
2011-02-23 01:40:35 +00:00
|
|
|
pr_int_t reserved[2];
|
2011-02-17 06:02:09 +00:00
|
|
|
} qfo_space_t;
|
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** Representation of a def in the object file.
|
|
|
|
*/
|
2002-06-17 05:29:20 +00:00
|
|
|
typedef struct qfo_def_s {
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t type; ///< offset in type space
|
|
|
|
pr_string_t name; ///< def name
|
|
|
|
pr_ptr_t offset; ///< def offset (address)
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2018-09-08 10:45:19 +00:00
|
|
|
pr_uint_t relocs; ///< index of first reloc record
|
|
|
|
pr_uint_t num_relocs; ///< number of reloc records
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
pr_uint_t flags; ///< \ref qfcc_qfo_QFOD "QFOD flags"
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t file; ///< source file name
|
2018-09-08 10:45:19 +00:00
|
|
|
pr_uint_t line; ///< source line number
|
2002-06-17 05:29:20 +00:00
|
|
|
} qfo_def_t;
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** \defgroup qfcc_qfo_QFOD QFOD flags
|
|
|
|
\ingroup qfcc_qfo
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** The def has been initialized.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2002-06-18 21:00:41 +00:00
|
|
|
#define QFOD_INITIALIZED (1u<<0)
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** The def is a shared constant and must not be modified.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2002-06-18 21:00:41 +00:00
|
|
|
#define QFOD_CONSTANT (1u<<1)
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** The def offset is an absolute address.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2002-06-28 17:59:32 +00:00
|
|
|
#define QFOD_ABSOLUTE (1u<<2)
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** The def is visible to other object files.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2002-06-28 17:59:32 +00:00
|
|
|
#define QFOD_GLOBAL (1u<<3)
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** The def is undefined and need to be supplied by another object file.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2002-06-28 17:59:32 +00:00
|
|
|
#define QFOD_EXTERNAL (1u<<4)
|
2002-06-18 21:00:41 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** The def is local to a function and is not visible to other functions or
|
|
|
|
object files.
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define QFOD_LOCAL (1u<<5)
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** The def is a system def and needs to be allocated before other defs
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define QFOD_SYSTEM (1u<<6)
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** The def does not need to be saved when saving game state.
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define QFOD_NOSAVE (1u<<7)
|
2012-11-20 08:50:59 +00:00
|
|
|
|
|
|
|
/** The def is a parameter to a function and is considered to be initialized.
|
|
|
|
QFOD_LOCAL will be set too.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define QFOD_PARAM (1u<<8)
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2002-06-21 20:46:56 +00:00
|
|
|
|
2010-08-11 23:42:14 +00:00
|
|
|
/** \addtogroup qfcc_qfo
|
2010-08-11 23:41:30 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2010-08-11 23:41:30 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** Representation of a function in the object file.
|
|
|
|
*/
|
|
|
|
typedef struct qfo_func_s {
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t name; ///< function name
|
|
|
|
pr_ptr_t type; ///< function type (in type data space)
|
|
|
|
pr_string_t file; ///< source file name
|
2018-09-08 10:45:19 +00:00
|
|
|
pr_uint_t line; ///< source line number
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** \name Function code location.
|
2011-02-23 01:40:35 +00:00
|
|
|
If #code is negative, then the function is a VM builtin function.
|
|
|
|
If #code is 0, then the function is a VM builtin function and the
|
|
|
|
VM resolves the function number using the function name.
|
|
|
|
If #code is positive, then the function is in progs and #code is
|
|
|
|
the first statement of the function.
|
2008-08-01 00:47:38 +00:00
|
|
|
*/
|
2011-02-23 01:40:35 +00:00
|
|
|
pr_int_t code;
|
2008-08-01 00:47:38 +00:00
|
|
|
|
2018-09-08 10:45:19 +00:00
|
|
|
pr_uint_t def; ///< def that references this function. Index
|
2008-08-01 00:47:38 +00:00
|
|
|
///< to ::qfo_def_t. The data word pointed to
|
|
|
|
///< by the def stores the index of this
|
|
|
|
///< function.
|
|
|
|
|
2018-09-08 10:45:19 +00:00
|
|
|
pr_uint_t locals_space; ///< space holding the function's local data
|
2008-08-01 00:47:38 +00:00
|
|
|
|
2018-09-08 10:45:19 +00:00
|
|
|
pr_uint_t line_info; ///< Index to first ::pr_lineno_t line record.
|
2008-08-01 00:47:38 +00:00
|
|
|
///< Zero if there are no records.
|
|
|
|
|
|
|
|
/** \name Function relocation records.
|
|
|
|
XXX not sure how these work
|
|
|
|
*/
|
2010-08-11 23:42:14 +00:00
|
|
|
//@{
|
2018-09-08 10:45:19 +00:00
|
|
|
pr_uint_t relocs; ///< Index to first ::qfo_reloc_t reloc record.
|
|
|
|
pr_uint_t num_relocs; ///< Number of reloc records.
|
2010-08-11 23:42:14 +00:00
|
|
|
//@}
|
2011-02-23 01:40:35 +00:00
|
|
|
pr_int_t reserved[2];
|
2002-07-15 21:37:52 +00:00
|
|
|
} qfo_func_t;
|
2002-06-17 05:29:20 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** Evil source of many headaches. The whole reason I've started writing this
|
|
|
|
documentation.
|
2008-08-01 13:54:24 +00:00
|
|
|
relocs are always in the order:
|
|
|
|
referenced relocs
|
|
|
|
unreferenced relocs
|
|
|
|
|
2022-01-07 06:59:06 +00:00
|
|
|
For \c ref_op_* relocation types, \c offset is the code section address
|
|
|
|
of the statement that needs to be adjusted.
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2022-01-07 06:59:06 +00:00
|
|
|
For \c rel_def_* relocation types, \c offset refers to the data section
|
|
|
|
address of the word that needs to be adjusted.
|
2008-08-01 13:54:24 +00:00
|
|
|
|
2022-01-07 06:59:06 +00:00
|
|
|
For \c ref_*_def(_ofs) relocation types, \c target is the index of the
|
2008-08-01 13:54:24 +00:00
|
|
|
referenced def.
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2022-01-07 06:59:06 +00:00
|
|
|
For \c ref_*_op relocation types, \c target is the address of the
|
|
|
|
referenced statement.
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2022-01-07 06:59:06 +00:00
|
|
|
For \c ref_*_string relocation types, \c target is always 0.
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2022-01-07 06:59:06 +00:00
|
|
|
For \c ref_*_field(_ofs) relocation types, \c target is the index of
|
2008-08-01 13:54:24 +00:00
|
|
|
the referenced field def.
|
2008-08-01 00:47:38 +00:00
|
|
|
*/
|
2002-06-22 05:10:34 +00:00
|
|
|
typedef struct qfo_reloc_s {
|
2018-09-08 10:45:19 +00:00
|
|
|
pr_uint_t space; ///< index of space holding data to be adjusted
|
|
|
|
pr_uint_t offset; ///< offset of the relocation
|
2008-08-01 13:54:24 +00:00
|
|
|
pr_int_t type; ///< type of the relocation (::reloc_type)
|
2012-12-21 12:53:13 +00:00
|
|
|
pr_uint_t target; ///< def/func/etc this relocation is for
|
2002-06-22 05:10:34 +00:00
|
|
|
} qfo_reloc_t;
|
|
|
|
|
2011-02-17 06:02:09 +00:00
|
|
|
/** In-memory representation of a QFO space
|
|
|
|
*/
|
|
|
|
typedef struct qfo_mspace_s {
|
|
|
|
qfos_type_t type;
|
|
|
|
qfo_def_t *defs;
|
2018-09-08 10:45:19 +00:00
|
|
|
unsigned num_defs;
|
2011-02-17 06:02:09 +00:00
|
|
|
union {
|
|
|
|
dstatement_t *code;
|
|
|
|
pr_type_t *data;
|
|
|
|
char *strings;
|
2021-12-26 11:37:01 +00:00
|
|
|
};
|
2012-12-21 12:53:13 +00:00
|
|
|
unsigned data_size;
|
2018-09-08 10:45:19 +00:00
|
|
|
unsigned id;
|
2011-02-17 06:02:09 +00:00
|
|
|
} qfo_mspace_t;
|
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** In-memory representation of a QFO object file.
|
|
|
|
*/
|
2002-06-22 05:10:34 +00:00
|
|
|
typedef struct qfo_s {
|
2022-01-07 08:56:05 +00:00
|
|
|
pr_uint_t progs_version; ///< version of compatible VM
|
2011-02-23 09:10:38 +00:00
|
|
|
void *data; ///< data buffer holding qfo file when read
|
2011-02-21 01:32:20 +00:00
|
|
|
qfo_mspace_t *spaces;
|
2018-09-08 10:45:19 +00:00
|
|
|
unsigned num_spaces;
|
2002-06-22 05:10:34 +00:00
|
|
|
qfo_reloc_t *relocs;
|
2018-09-08 10:45:19 +00:00
|
|
|
unsigned num_relocs; // includes num_loose_relocs
|
2002-06-22 05:10:34 +00:00
|
|
|
qfo_def_t *defs;
|
2018-09-08 10:45:19 +00:00
|
|
|
unsigned num_defs;
|
2002-07-15 21:37:52 +00:00
|
|
|
qfo_func_t *funcs;
|
2018-09-08 10:45:19 +00:00
|
|
|
unsigned num_funcs;
|
2002-06-24 22:36:04 +00:00
|
|
|
pr_lineno_t *lines;
|
2018-09-08 10:45:19 +00:00
|
|
|
unsigned num_lines;
|
|
|
|
unsigned num_loose_relocs; // included in num_relocs
|
2002-06-22 05:10:34 +00:00
|
|
|
} qfo_t;
|
2011-02-23 09:10:38 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
qfo_null_space,
|
|
|
|
qfo_strings_space,
|
|
|
|
qfo_code_space,
|
|
|
|
qfo_near_data_space,
|
|
|
|
qfo_far_data_space,
|
|
|
|
qfo_entity_space,
|
|
|
|
qfo_type_space,
|
2020-04-03 05:27:22 +00:00
|
|
|
qfo_debug_space,
|
2011-02-23 09:10:38 +00:00
|
|
|
|
|
|
|
qfo_num_spaces
|
|
|
|
};
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2002-06-21 20:46:56 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** \defgroup qfcc_qfo_data_access QFO Data Acess
|
|
|
|
\ingroup qfcc_qfo
|
|
|
|
Macros for accessing data in the QFO address space
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** \internal
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param s space index
|
2008-08-01 00:47:38 +00:00
|
|
|
\param t typename prefix (see pr_type_u)
|
|
|
|
\param o offset into object file data space
|
|
|
|
\return lvalue of the appropriate type
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2021-12-26 11:37:01 +00:00
|
|
|
#define QFO_var(q, s, t, o) ((q)->spaces[s].data[o].t##_var)
|
2008-08-01 00:47:38 +00:00
|
|
|
|
2020-02-14 09:15:34 +00:00
|
|
|
/** Access a double variable in the object file. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c double
|
|
|
|
\param q pointer to ::qfo_t struct
|
|
|
|
\param s space index
|
|
|
|
\param o offset into object file data space
|
|
|
|
\return double lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2021-12-26 11:37:01 +00:00
|
|
|
#define QFO_DOUBLE(q, s, o) (*(double *) ((q)->spaces[s].data + o))
|
2020-02-14 09:15:34 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** Access a float variable in the object file. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c float
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param s space index
|
2008-08-01 00:47:38 +00:00
|
|
|
\param o offset into object file data space
|
|
|
|
\return float lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2011-02-25 00:38:22 +00:00
|
|
|
#define QFO_FLOAT(q, s, o) QFO_var (q, s, float, o)
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** Access a integer variable in the object file. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c integer
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param s space index
|
2008-08-01 00:47:38 +00:00
|
|
|
\param o offset into object file data space
|
|
|
|
\return int lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2011-02-25 00:38:22 +00:00
|
|
|
#define QFO_INT(q, s, o) QFO_var (q, s, integer, o)
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** Access a vector variable in the object file. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c vector
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param s space index
|
2008-08-01 00:47:38 +00:00
|
|
|
\param o offset into object file data space
|
|
|
|
\return vec3_t lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2011-02-25 00:38:22 +00:00
|
|
|
#define QFO_VECTOR(q, s, o) QFO_var (q, s, vector, o)
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** Access a string index variable in the object file. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c string
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param s space index
|
2008-08-01 00:47:38 +00:00
|
|
|
\param o offset into object file data space
|
2022-01-18 03:11:14 +00:00
|
|
|
\return pr_string_t lvalue
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2011-02-25 00:38:22 +00:00
|
|
|
#define QFO_STRING(q, s, o) QFO_var (q, s, string, o)
|
2008-08-01 13:54:24 +00:00
|
|
|
|
|
|
|
/** Retrieve a string from the object file, converting it to a C string.
|
|
|
|
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param s space index
|
2008-08-01 13:54:24 +00:00
|
|
|
\return (char *)
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2021-12-26 11:37:01 +00:00
|
|
|
#define QFO_GETSTR(q, s) ((q)->spaces[qfo_strings_space].strings + (s))
|
2008-08-01 13:54:24 +00:00
|
|
|
|
2012-11-13 12:45:54 +00:00
|
|
|
#define QFO_TYPE(q, t) ((qfot_type_t *) (char *) \
|
2021-12-26 11:37:01 +00:00
|
|
|
((q)->spaces[qfo_type_space].data + (t)))
|
2012-11-13 12:45:54 +00:00
|
|
|
|
2008-08-01 13:54:24 +00:00
|
|
|
/** Retrieve a type string from the object file, converting it to a C string.
|
|
|
|
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param t offset to type encoding
|
2008-08-01 13:54:24 +00:00
|
|
|
\return (char *)
|
|
|
|
|
2011-03-01 06:18:12 +00:00
|
|
|
\note Assumes standard space order.
|
2008-08-01 13:54:24 +00:00
|
|
|
\hideinitializer
|
|
|
|
*/
|
2011-02-25 00:38:22 +00:00
|
|
|
#define QFO_TYPESTR(q, t) QFO_GSTRING (q, qfo_type_space, (t) + 2)
|
2008-08-01 13:54:24 +00:00
|
|
|
|
2011-03-01 06:18:12 +00:00
|
|
|
#define QFO_TYPEMETA(q, t) QFO_INT (q, qfo_type_space, (t) + 0)
|
|
|
|
#define QFO_TYPETYPE(q, t) QFO_INT (q, qfo_type_space, (t) + 3)
|
|
|
|
|
2021-12-26 11:37:01 +00:00
|
|
|
#define QFO_STATEMENT(q, s) ((q)->spaces[qfo_code_space].code + (s))
|
2011-03-04 23:41:14 +00:00
|
|
|
|
2008-08-01 13:54:24 +00:00
|
|
|
/** Access a string global, converting it to a C string.
|
|
|
|
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param s space index
|
2008-08-01 13:54:24 +00:00
|
|
|
\param o offset into object file data space
|
|
|
|
\return (char *)
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2011-02-25 00:38:22 +00:00
|
|
|
#define QFO_GSTRING(q, s, o) (QFO_GETSTR (q, QFO_STRING (q, s, o)))
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** Access a function variable in the object file. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c void ()
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param s space index
|
2008-08-01 00:47:38 +00:00
|
|
|
\param o offset into object file data space
|
|
|
|
\return func_t lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2011-02-25 00:38:22 +00:00
|
|
|
#define QFO_FUNCTION(q, s, o) QFO_var (q, s, func, o)
|
2008-08-01 00:47:38 +00:00
|
|
|
|
2012-11-14 08:13:14 +00:00
|
|
|
/** Access a block of memory in the object file as a C struct.
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c void []
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param s space index
|
2010-08-11 23:41:30 +00:00
|
|
|
\param t C type of the structure
|
2008-08-01 00:47:38 +00:00
|
|
|
\param o offset into object file data space
|
2012-11-14 08:13:14 +00:00
|
|
|
\return C pointer to the struct at space:offset
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2011-02-26 15:31:52 +00:00
|
|
|
#define QFO_POINTER(q, s, t, o) ((t *)(char *)&QFO_var (q, s, integer, o))
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** Access a structure variable in the object file. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c void [](?)
|
|
|
|
\param q pointer to ::qfo_t struct
|
2011-02-25 00:38:22 +00:00
|
|
|
\param s space index
|
2008-08-01 00:47:38 +00:00
|
|
|
\param t C type of the structure
|
|
|
|
\param o offset into object file data space
|
|
|
|
\return structure lvalue. use & to make a pointer of the appropriate type.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2011-02-25 00:38:22 +00:00
|
|
|
#define QFO_STRUCT(q, s, t, o) (*QFO_POINTER (q, s, t, o))
|
2002-07-03 20:16:32 +00:00
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2008-08-01 00:47:38 +00:00
|
|
|
|
2010-08-11 23:42:14 +00:00
|
|
|
/** \addtogroup qfcc_qfo
|
2010-08-11 23:41:30 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2010-08-11 23:41:30 +00:00
|
|
|
|
2002-07-11 20:17:26 +00:00
|
|
|
struct pr_info_s;
|
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** Convert ::pr_info_t structure to ::qfo_t.
|
|
|
|
\param pr pointer to ::pr_info_t struct
|
|
|
|
\return pointer to new ::qfo_t struct, or 0 on error.
|
|
|
|
*/
|
2002-07-11 20:17:26 +00:00
|
|
|
qfo_t *qfo_from_progs (struct pr_info_s *pr);
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** Write a ::qfo_t struct to the named file.
|
|
|
|
\param qfo pointer to ::qfo_t struct to write
|
|
|
|
\param filename name of the file to write
|
|
|
|
\return 0 for success, -1 for error.
|
|
|
|
*/
|
2002-07-11 20:17:26 +00:00
|
|
|
int qfo_write (qfo_t *qfo, const char *filename);
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** Read a ::qfo_t strcut from a ::QFile stream.
|
|
|
|
\param file ::QFile stream to read from
|
|
|
|
\return pointer to new ::qfo_t struct, or 0 on error.
|
|
|
|
*/
|
2002-08-27 07:16:28 +00:00
|
|
|
qfo_t *qfo_read (QFile *file);
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** Wrapper around qfo_read() to allow reading from a named file.
|
|
|
|
\param filename name of the file to read
|
|
|
|
\return pointer to new ::qfo_t struct, or 0 on error.
|
|
|
|
*/
|
2002-07-21 07:12:17 +00:00
|
|
|
qfo_t *qfo_open (const char *filename);
|
2008-08-01 00:47:38 +00:00
|
|
|
|
2021-12-26 15:25:08 +00:00
|
|
|
dprograms_t *qfo_to_progs (qfo_t *in_qfo, int *size);
|
2011-03-04 09:44:02 +00:00
|
|
|
pr_debug_header_t *qfo_to_sym (qfo_t *qfo, int *size);
|
2002-07-11 20:17:26 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** Create a new ::qfo_t struct
|
|
|
|
\return pointer to new ::qfo_t struct, or 0 on error.
|
|
|
|
*/
|
2002-07-11 17:06:15 +00:00
|
|
|
qfo_t *qfo_new (void);
|
2008-08-01 00:47:38 +00:00
|
|
|
|
|
|
|
/** Delete a ::qfo_t struct, as well as any substructure data.
|
|
|
|
\param qfo ::qfo_t struct to delete
|
|
|
|
*/
|
2002-07-11 17:06:15 +00:00
|
|
|
void qfo_delete (qfo_t *qfo);
|
2002-06-21 20:46:56 +00:00
|
|
|
|
2020-02-16 08:10:43 +00:00
|
|
|
__attribute__((const)) int qfo_log2 (unsigned x);
|
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2008-08-01 00:47:38 +00:00
|
|
|
|
2002-06-17 05:29:20 +00:00
|
|
|
#endif//__obj_file_h
|