145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \file libyasm/coretype.h 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \brief YASM core types and utility functions. 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \license 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (C) 2001-2007 Peter Johnson 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Redistribution and use in source and binary forms, with or without 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * modification, are permitted provided that the following conditions 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are met: 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * - Redistributions of source code must retain the above copyright 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer. 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * - Redistributions in binary form must reproduce the above copyright 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer in the 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * documentation and/or other materials provided with the distribution. 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE. 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \endlicense 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_CORETYPE_H 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_CORETYPE_H 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_LIB_DECL 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LIB_DECL 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Architecture instance (mostly opaque type). \see arch.h for details. */ 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_arch yasm_arch; 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Preprocessor interface. \see preproc.h for details. */ 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_preproc yasm_preproc; 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Parser instance (mostly opaque type). \see parser.h for details. */ 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_parser yasm_parser; 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Object format interface. \see objfmt.h for details. */ 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_objfmt yasm_objfmt; 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Debug format interface. \see dbgfmt.h for details. */ 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_dbgfmt yasm_dbgfmt; 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** List format interface. \see listfmt.h for details. */ 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_listfmt yasm_listfmt; 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Object format module interface. \see objfmt.h for details. */ 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_objfmt_module yasm_objfmt_module; 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Debug format module interface. \see dbgfmt.h for details. */ 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_dbgfmt_module yasm_dbgfmt_module; 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Standard macro structure for modules that allows association of a set of 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * standard macros with a parser/preprocessor combination. 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * A NULL-terminated array of these structures is used in a number of module 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * interfaces. 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_stdmac { 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const char *parser; /**< Parser keyword */ 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const char *preproc; /**< Preprocessor keyword */ 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** NULL-terminated array of standard macros. May be NULL if no standard 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * macros should be added for this preprocessor. 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const char **macros; 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_stdmac; 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** YASM associated data callback structure. Many data structures can have 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * arbitrary data associated with them. 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_assoc_data_callback { 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Free memory allocated for associated data. 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param data associated data 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org void (*destroy) (/*@only@*/ void *data); 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Print a description of allocated data. For debugging purposes. 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param data associated data 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f output file 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param indent_level indentation level 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org void (*print) (void *data, FILE *f, int indent_level); 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_assoc_data_callback; 8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Set of collected error/warnings (opaque type). 8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \see errwarn.h for details. 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_errwarns yasm_errwarns; 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Bytecode. \see bytecode.h for details and related functions. */ 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_bytecode yasm_bytecode; 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Object. \see section.h for details and related functions. */ 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_object yasm_object; 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Section (opaque type). \see section.h for related functions. */ 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_section yasm_section; 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Symbol table (opaque type). \see symrec.h for related functions. */ 10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_symtab yasm_symtab; 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Symbol record (opaque type). \see symrec.h for related functions. */ 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_symrec yasm_symrec; 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Expression. \see expr.h for details and related functions. */ 10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_expr yasm_expr; 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Integer value (opaque type). \see intnum.h for related functions. */ 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_intnum yasm_intnum; 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Floating point value (opaque type). 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \see floatnum.h for related functions. 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_floatnum yasm_floatnum; 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** A value. May be absolute or relative. Outside the parser, yasm_expr 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * should only be used for absolute exprs. Anything that could contain 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * a relocatable value should use this structure instead. 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \see value.h for related functions. 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_value { 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** The absolute portion of the value. May contain *differences* between 12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * symrecs but not standalone symrecs. May be NULL if there is no 12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * absolute portion (e.g. the absolute portion is 0). 12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@null@*/ /*@only@*/ yasm_expr *abs; 12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** The relative portion of the value. This is the portion that may 12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * need to generate a relocation. May be NULL if no relative portion. 13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@null@*/ /*@dependent@*/ yasm_symrec *rel; 13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** What the relative portion is in reference to. NULL if the default. */ 13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@null@*/ /*@dependent@*/ yasm_symrec *wrt; 13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** If the segment of the relative portion should be used, not the 13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * relative portion itself. Boolean. 13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int seg_of : 1; 14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** If the relative portion of the value should be shifted right 14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * (supported only by a few object formats). If just the absolute portion 14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * should be shifted, that must be in the abs expr, not here! 14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int rshift : 7; 14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Indicates the relative portion of the value should be relocated 14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * relative to the current assembly position rather than relative to the 14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * section start. "Current assembly position" here refers to the starting 15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * address of the bytecode containing this value. Boolean. 15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int curpos_rel : 1; 15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Indicates that curpos_rel was set due to IP-relative relocation; 15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * in some objfmt/arch combinations (e.g. win64/x86-amd64) this info 15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * is needed to generate special relocations. 15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int ip_rel : 1; 15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Indicates the value is a jump target address (rather than a simple 16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * data address). In some objfmt/arch combinations (e.g. macho/amd64) 16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * this info is needed to generate special relocations. 16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int jump_target : 1; 16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Indicates the relative portion of the value should be relocated 16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * relative to its own section start rather than relative to the 16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * section start of the bytecode containing this value. E.g. the value 16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * resulting from the relative portion should be the offset from its 17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * section start. Boolean. 17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int section_rel : 1; 17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Indicates overflow warnings have been disabled for this value. */ 17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int no_warn : 1; 17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Sign of the value. Nonzero if the final value should be treated as 17845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * signed, 0 if it should be treated as signed. 17945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 18045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int sign : 1; 18145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 18245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Size of the value, in bits. */ 18345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int size : 8; 18445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_value; 18545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 18645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Maximum value of #yasm_value.rshift */ 18745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_VALUE_RSHIFT_MAX 127 18845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 18945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Line number mapping repository (opaque type). \see linemap.h for related 19045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * functions. 19145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 19245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_linemap yasm_linemap; 19345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 19445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Value/parameter pair (opaque type). 19545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \see valparam.h for related functions. 19645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 19745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_valparam yasm_valparam; 19845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** List of value/parameters (opaque type). 19945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \see valparam.h for related functions. 20045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 20145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_valparamhead yasm_valparamhead; 20245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Directive list entry. 20345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \see valparam.h for details and related functions. 20445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 20545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_directive yasm_directive; 20645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 20745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** An effective address. 20845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \see insn.h for related functions. 20945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 21045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_effaddr yasm_effaddr; 21145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 21245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** An instruction. 21345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \see insn.h for related functions. 21445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 21545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_insn yasm_insn; 21645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 21745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Expression operators usable in #yasm_expr expressions. */ 21845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum yasm_expr_op { 21945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_IDENT, /**< No operation, just a value. */ 22045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_ADD, /**< Arithmetic addition (+). */ 22145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_SUB, /**< Arithmetic subtraction (-). */ 22245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_MUL, /**< Arithmetic multiplication (*). */ 22345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_DIV, /**< Arithmetic unsigned division. */ 22445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_SIGNDIV, /**< Arithmetic signed division. */ 22545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_MOD, /**< Arithmetic unsigned modulus. */ 22645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_SIGNMOD, /**< Arithmetic signed modulus. */ 22745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_NEG, /**< Arithmetic negation (-). */ 22845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_NOT, /**< Bitwise negation. */ 22945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_OR, /**< Bitwise OR. */ 23045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_AND, /**< Bitwise AND. */ 23145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_XOR, /**< Bitwise XOR. */ 23245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_XNOR, /**< Bitwise XNOR. */ 23345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_NOR, /**< Bitwise NOR. */ 23445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_SHL, /**< Shift left (logical). */ 23545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_SHR, /**< Shift right (logical). */ 23645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_LOR, /**< Logical OR. */ 23745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_LAND, /**< Logical AND. */ 23845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_LNOT, /**< Logical negation. */ 23945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_LXOR, /**< Logical XOR. */ 24045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_LXNOR, /**< Logical XNOR. */ 24145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_LNOR, /**< Logical NOR. */ 24245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_LT, /**< Less than comparison. */ 24345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_GT, /**< Greater than comparison. */ 24445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_EQ, /**< Equality comparison. */ 24545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_LE, /**< Less than or equal to comparison. */ 24645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_GE, /**< Greater than or equal to comparison. */ 24745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_NE, /**< Not equal comparison. */ 24845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_NONNUM, /**< Start of non-numeric operations (not an op). */ 24945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_SEG, /**< SEG operator (gets segment portion of address). */ 25045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_WRT, /**< WRT operator (gets offset of address relative to 25145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * some other segment). */ 25245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YASM_EXPR_SEGOFF /**< The ':' in segment:offset. */ 25345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_expr_op; 25445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 25545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Convert yasm_value to its byte representation. Usually implemented by 25645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * object formats to keep track of relocations and verify legal expressions. 25745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Must put the value into the least significant bits of the destination, 25845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * unless shifted into more significant bits by the shift parameter. The 25945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * destination bits must be cleared before being set. 26045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param value value 26145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param buf buffer for byte representation 26245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param destsize destination size (in bytes) 26345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param offset offset (in bytes) of the expr contents from the start 26445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * of the bytecode (needed for relative) 26545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param bc current bytecode (usually passed into higher-level 26645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * calling function) 26745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param warn enables standard warnings: zero for none; 26845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * nonzero for overflow/underflow floating point warnings 26945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param d objfmt-specific data (passed into higher-level calling 27045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * function) 27145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Nonzero if an error occurred, 0 otherwise. 27245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 27345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef int (*yasm_output_value_func) 27445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (yasm_value *value, /*@out@*/ unsigned char *buf, unsigned int destsize, 27545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned long offset, yasm_bytecode *bc, int warn, /*@null@*/ void *d); 27645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 27745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Convert a symbol reference to its byte representation. Usually implemented 27845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * by object formats and debug formats to keep track of relocations generated 27945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * by themselves. 28045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param sym symbol 28145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param bc current bytecode (usually passed into higher-level 28245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * calling function) 28345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param buf buffer for byte representation 28445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param destsize destination size (in bytes) 28545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param valsize size (in bits) 28645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param warn enables standard warnings: zero for none; 28745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * nonzero for overflow/underflow floating point warnings; 28845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * negative for signed integer warnings, 28945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * positive for unsigned integer warnings 29045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param d objfmt-specific data (passed into higher-level calling 29145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * function) 29245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Nonzero if an error occurred, 0 otherwise. 29345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 29445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef int (*yasm_output_reloc_func) 29545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (yasm_symrec *sym, yasm_bytecode *bc, unsigned char *buf, 29645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int destsize, unsigned int valsize, int warn, void *d); 29745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 29845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Sort an array using merge sort algorithm. 29945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 30045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param base base of array 30145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param nmemb number of elements in array 30245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param size size of each array element 30345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param compar element comparison function 30445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 30545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 30645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm__mergesort(void *base, size_t nmemb, size_t size, 30745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int (*compar)(const void *, const void *)); 30845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 30945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Separate string by delimiters. 31045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 31145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param stringp string 31245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param delim set of 1 or more delimiters 31345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return First/next substring. 31445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 31545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 31645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@null@*/ char *yasm__strsep(char **stringp, const char *delim); 31745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 31845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Compare two strings, ignoring case differences. 31945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 32045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param s1 string 1 32145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param s2 string 2 32245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return 0 if strings are equal, -1 if s1<s2, 1 if s1>s2. 32345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 32445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 32545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm__strcasecmp(const char *s1, const char *s2); 32645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 32745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Compare portion of two strings, ignoring case differences. 32845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 32945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param s1 string 1 33045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param s2 string 2 33145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param n maximum number of characters to compare 33245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return 0 if strings are equal, -1 if s1<s2, 1 if s1>s2. 33345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 33445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 33545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm__strncasecmp(const char *s1, const char *s2, size_t n); 33645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 33745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** strdup() implementation using yasm_xmalloc(). 33845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 33945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param str string 34045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated duplicate string. 34145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 34245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 34345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ char *yasm__xstrdup(const char *str); 34445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 34545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** strndup() implementation using yasm_xmalloc(). 34645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 34745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param str string 34845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param max maximum number of characters to copy 34945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated duplicate string. 35045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 35145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 35245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ char *yasm__xstrndup(const char *str, size_t max); 35345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 35445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Error-checking memory allocation. A default implementation is provided 35545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * that calls yasm_fatal() on allocation errors. 35645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * A replacement should \em never return NULL. 35745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param size number of bytes to allocate 35845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Allocated memory block. 35945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 36045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 36145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern /*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size); 36245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 36345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Error-checking memory allocation (with clear-to-0). A default 36445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * implementation is provided that calls yasm_fatal() on allocation errors. 36545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * A replacement should \em never return NULL. 36645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param size number of elements to allocate 36745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param elsize size (in bytes) of each element 36845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Allocated and cleared memory block. 36945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 37045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 37145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern /*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize); 37245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 37345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Error-checking memory reallocation. A default implementation is provided 37445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * that calls yasm_fatal() on allocation errors. A replacement should 37545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \em never return NULL. 37645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param oldmem memory block to resize 37745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param elsize new size, in bytes 37845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Re-allocated memory block. 37945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 38045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 38145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern /*@only@*/ void * (*yasm_xrealloc) 38245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size) 38345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@modifies oldmem@*/; 38445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 38545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Error-checking memory deallocation. A default implementation is provided 38645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * that calls yasm_fatal() on allocation errors. 38745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param p memory block to free 38845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 38945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 39045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p) 39145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@modifies p@*/; 39245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 39345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 394