libyasm
Data Structures | Typedefs | Enumerations | Functions
arch.h File Reference

YASM architecture interface. More...

Go to the source code of this file.

Data Structures

struct  yasm_arch_machine
 YASM machine subtype. More...
 
struct  yasm_arch_module
 YASM architecture module interface. More...
 

Typedefs

typedef enum yasm_arch_create_error yasm_arch_create_error
 Errors that may be returned by yasm_arch_module::create(). More...
 
typedef enum yasm_arch_insnprefix yasm_arch_insnprefix
 Return values for yasm_arch_module::parse_check_insnprefix(). More...
 
typedef enum yasm_arch_regtmod yasm_arch_regtmod
 Types of registers / target modifiers that may be returned by yasm_arch_module::parse_check_regtmod().
 
typedef struct yasm_arch_machine yasm_arch_machine
 YASM machine subtype. More...
 
typedef struct yasm_arch_module yasm_arch_module
 YASM architecture module interface. More...
 

Enumerations

enum  yasm_arch_create_error { YASM_ARCH_CREATE_OK = 0, YASM_ARCH_CREATE_BAD_MACHINE, YASM_ARCH_CREATE_BAD_PARSER }
 Errors that may be returned by yasm_arch_module::create(). More...
 
enum  yasm_arch_insnprefix { YASM_ARCH_NOTINSNPREFIX = 0, YASM_ARCH_INSN, YASM_ARCH_PREFIX }
 Return values for yasm_arch_module::parse_check_insnprefix(). More...
 
enum  yasm_arch_regtmod {
  YASM_ARCH_NOTREGTMOD = 0, YASM_ARCH_REG, YASM_ARCH_REGGROUP, YASM_ARCH_SEGREG,
  YASM_ARCH_TARGETMOD
}
 Types of registers / target modifiers that may be returned by yasm_arch_module::parse_check_regtmod(). More...
 

Functions

const char * yasm_arch_name (const yasm_arch *arch)
 Get the one-line description of an architecture. More...
 
const char * yasm_arch_keyword (const yasm_arch *arch)
 Get the keyword used to select an architecture. More...
 
unsigned int yasm_arch_wordsize (const yasm_arch *arch)
 Get the word size of an architecture. More...
 
unsigned int yasm_arch_min_insn_len (const yasm_arch *arch)
 Get the minimum instruction length of an architecture. More...
 
yasm_archyasm_arch_create (const yasm_arch_module *module, const char *machine, const char *parser, yasm_arch_create_error *error)
 Create architecture. More...
 
void yasm_arch_destroy (yasm_arch *arch)
 Clean up, free any architecture-allocated memory. More...
 
const char * yasm_arch_get_machine (const yasm_arch *arch)
 Get architecture's active machine name. More...
 
unsigned int yasm_arch_get_address_size (const yasm_arch *arch)
 Get architecture's active address size, in bits. More...
 
int yasm_arch_set_var (yasm_arch *arch, const char *var, unsigned long val)
 Set any arch-specific variables. More...
 
yasm_arch_insnprefix yasm_arch_parse_check_insnprefix (yasm_arch *arch, const char *id, size_t id_len, unsigned long line, yasm_bytecode **bc, uintptr_t *prefix)
 Check an generic identifier to see if it matches architecture specific names for instructions or instruction prefixes. More...
 
yasm_arch_regtmod yasm_arch_parse_check_regtmod (yasm_arch *arch, const char *id, size_t id_len, uintptr_t *data)
 Check an generic identifier to see if it matches architecture specific names for registers or target modifiers. More...
 
const unsigned char ** yasm_arch_get_fill (const yasm_arch *arch)
 Get NOP fill patterns for 1-15 bytes of fill. More...
 
int yasm_arch_floatnum_tobytes (yasm_arch *arch, const yasm_floatnum *flt, unsigned char *buf, size_t destsize, size_t valsize, size_t shift, int warn)
 Output yasm_floatnum to buffer. More...
 
int yasm_arch_intnum_tobytes (yasm_arch *arch, const yasm_intnum *intn, unsigned char *buf, size_t destsize, size_t valsize, int shift, const yasm_bytecode *bc, int warn)
 Output yasm_intnum to buffer. More...
 
unsigned int yasm_arch_get_reg_size (yasm_arch *arch, uintptr_t reg)
 Get the equivalent size of a register in bits. More...
 
uintptr_t yasm_arch_reggroup_get_reg (yasm_arch *arch, uintptr_t reggroup, unsigned long regindex)
 Get a specific register of a register group, based on the register group and the index within the group. More...
 
void yasm_arch_reg_print (yasm_arch *arch, uintptr_t reg, FILE *f)
 Print a register. More...
 
void yasm_arch_segreg_print (yasm_arch *arch, uintptr_t segreg, FILE *f)
 Print a segment register. More...
 
yasm_effaddryasm_arch_ea_create (yasm_arch *arch, yasm_expr *e)
 Create an effective address from an expression. More...
 
void yasm_arch_ea_destroy (yasm_arch *arch, yasm_effaddr *ea)
 Delete (free allocated memory for) an effective address. More...
 
void yasm_arch_ea_print (const yasm_arch *arch, const yasm_effaddr *ea, FILE *f, int indent_level)
 Print an effective address. More...
 
yasm_bytecodeyasm_arch_create_empty_insn (yasm_arch *arch, unsigned long line)
 Create a bytecode that represents a single empty (0 length) instruction. More...
 

Detailed Description

YASM architecture interface.

Definition in file arch.h.

Typedef Documentation

Errors that may be returned by yasm_arch_module::create().

YASM machine subtype.

A number of different machine types may be associated with a single architecture. These may be specific CPU's, but the ABI used to interface with the architecture should be the primary differentiator between machines. Some object formats (ELF) use the machine to determine parameters within the generated output.

YASM architecture module interface.

Note
All "data" in parser-related functions (yasm_arch_parse_*) needs to start the parse initialized to 0 to make it okay for a parser-related function to use/check previously stored data to see if it's been called before on the same piece of data.

Enumeration Type Documentation

Errors that may be returned by yasm_arch_module::create().

Enumerator
YASM_ARCH_CREATE_OK 

No error.

YASM_ARCH_CREATE_BAD_MACHINE 

Unrecognized machine name.

YASM_ARCH_CREATE_BAD_PARSER 

Unrecognized parser name.

Definition at line 34 of file arch.h.

Return values for yasm_arch_module::parse_check_insnprefix().

Enumerator
YASM_ARCH_NOTINSNPREFIX 

Unrecognized.

YASM_ARCH_INSN 

An instruction.

YASM_ARCH_PREFIX 

An instruction prefix.

Definition at line 41 of file arch.h.

Types of registers / target modifiers that may be returned by yasm_arch_module::parse_check_regtmod().

Enumerator
YASM_ARCH_NOTREGTMOD 

Unrecognized.

YASM_ARCH_REG 

A "normal" register.

YASM_ARCH_REGGROUP 

A group of indexable registers.

YASM_ARCH_SEGREG 

A segment register.

YASM_ARCH_TARGETMOD 

A target modifier (for jumps)

Definition at line 50 of file arch.h.

Function Documentation

yasm_arch* yasm_arch_create ( const yasm_arch_module module,
const char *  machine,
const char *  parser,
yasm_arch_create_error error 
)

Create architecture.

Parameters
modulearchitecture module
machinekeyword of machine in use (must be one listed in yasm_arch_module.machines)
parserkeyword of parser in use
errorerror return value
Returns
NULL on error (error returned in error parameter), otherwise new architecture.
yasm_bytecode* yasm_arch_create_empty_insn ( yasm_arch arch,
unsigned long  line 
)

Create a bytecode that represents a single empty (0 length) instruction.

This is used for handling solitary prefixes.

Parameters
archarchitecture
linevirtual line (from yasm_linemap)
Returns
Newly allocated bytecode.
void yasm_arch_destroy ( yasm_arch arch)

Clean up, free any architecture-allocated memory.

Parameters
archarchitecture
yasm_effaddr* yasm_arch_ea_create ( yasm_arch arch,
yasm_expr e 
)

Create an effective address from an expression.

Parameters
archarchitecture
eexpression (kept, do not delete)
Returns
Newly allocated effective address.
void yasm_arch_ea_destroy ( yasm_arch arch,
yasm_effaddr ea 
)

Delete (free allocated memory for) an effective address.

Parameters
archarchitecture
eaeffective address (only pointer to it).
void yasm_arch_ea_print ( const yasm_arch arch,
const yasm_effaddr ea,
FILE *  f,
int  indent_level 
)

Print an effective address.

For debugging purposes.

Parameters
archarchitecture
eaeffective address
ffile
indent_levelindentation level
int yasm_arch_floatnum_tobytes ( yasm_arch arch,
const yasm_floatnum flt,
unsigned char *  buf,
size_t  destsize,
size_t  valsize,
size_t  shift,
int  warn 
)

Output yasm_floatnum to buffer.

Puts the value into the least significant bits of the destination, or may be shifted into more significant bits by the shift parameter. The destination bits are cleared before being set. Architecture-specific because of endianness.

Parameters
archarchitecture
fltfloating point value
bufbuffer to write into
destsizedestination size (in bytes)
valsizesize (in bits)
shiftleft shift (in bits)
warnenables standard overflow/underflow warnings
Returns
Nonzero on error.
unsigned int yasm_arch_get_address_size ( const yasm_arch arch)

Get architecture's active address size, in bits.

Parameters
archarchitecture
Returns
Active address size (in bits).
const unsigned char** yasm_arch_get_fill ( const yasm_arch arch)

Get NOP fill patterns for 1-15 bytes of fill.

Parameters
archarchitecture
Returns
16-entry array of arrays; [0] is unused, [1] - [15] point to arrays of 1-15 bytes (respectively) in length.
const char* yasm_arch_get_machine ( const yasm_arch arch)

Get architecture's active machine name.

Parameters
archarchitecture
Returns
Active machine name.
unsigned int yasm_arch_get_reg_size ( yasm_arch arch,
uintptr_t  reg 
)

Get the equivalent size of a register in bits.

Parameters
archarchitecture
regregister
Returns
0 if there is no suitable equivalent size, otherwise the size.
int yasm_arch_intnum_tobytes ( yasm_arch arch,
const yasm_intnum intn,
unsigned char *  buf,
size_t  destsize,
size_t  valsize,
int  shift,
const yasm_bytecode bc,
int  warn 
)

Output yasm_intnum to buffer.

Puts the value into the least significant bits of the destination, or may be shifted into more significant bits by the shift parameter. The destination bits are cleared before being set.

Parameters
archarchitecture
intninteger value
bufbuffer to write into
destsizedestination size (in bytes)
valsizesize (in bits)
shiftleft shift (in bits); may be negative to specify right shift (standard warnings include truncation to boundary)
bcbytecode being output ("parent" of value)
warnenables standard warnings (value doesn't fit into valsize bits)
Returns
Nonzero on error.
const char* yasm_arch_keyword ( const yasm_arch arch)

Get the keyword used to select an architecture.

Parameters
archarchitecture
Returns
Architecture keyword.
unsigned int yasm_arch_min_insn_len ( const yasm_arch arch)

Get the minimum instruction length of an architecture.

Parameters
archarchitecture
Returns
Minimum instruction length (in bytes).
const char* yasm_arch_name ( const yasm_arch arch)

Get the one-line description of an architecture.

Parameters
archarchitecture
Returns
One-line description of architecture.
yasm_arch_insnprefix yasm_arch_parse_check_insnprefix ( yasm_arch arch,
const char *  id,
size_t  id_len,
unsigned long  line,
yasm_bytecode **  bc,
uintptr_t *  prefix 
)

Check an generic identifier to see if it matches architecture specific names for instructions or instruction prefixes.

Unrecognized identifiers should return YASM_ARCH_NOTINSNPREFIX so they can be treated as normal symbols. Any additional data beyond just the type (almost always necessary) should be returned into the space provided by the data parameter.

Parameters
archarchitecture
ididentifier as in the input file
id_lenlength of id string
linevirtual line
bcfor instructions, yasm_insn-based bytecode is returned (and NULL otherwise)
prefixfor prefixes, yasm_arch-specific value is returned (and 0 otherwise)
Returns
Identifier type (YASM_ARCH_NOTINSNPREFIX if unrecognized)
yasm_arch_regtmod yasm_arch_parse_check_regtmod ( yasm_arch arch,
const char *  id,
size_t  id_len,
uintptr_t *  data 
)

Check an generic identifier to see if it matches architecture specific names for registers or target modifiers.

Unrecognized identifiers should return YASM_ARCH_NOTREGTMOD. Any additional data beyond just the type (almost always necessary) should be returned into the space provided by the data parameter.

Parameters
archarchitecture
ididentifier as in the input file
id_lenlength of id string
dataextra identification information (yasm_arch-specific) [output]
Returns
Identifier type (YASM_ARCH_NOTREGTMOD if unrecognized)
void yasm_arch_reg_print ( yasm_arch arch,
uintptr_t  reg,
FILE *  f 
)

Print a register.

For debugging purposes.

Parameters
archarchitecture
regregister
ffile
uintptr_t yasm_arch_reggroup_get_reg ( yasm_arch arch,
uintptr_t  reggroup,
unsigned long  regindex 
)

Get a specific register of a register group, based on the register group and the index within the group.

Parameters
archarchitecture
reggroupregister group
regindexregister index
Returns
0 if regindex is not valid for that register group, otherwise the specific register value.
void yasm_arch_segreg_print ( yasm_arch arch,
uintptr_t  segreg,
FILE *  f 
)

Print a segment register.

For debugging purposes.

Parameters
archarchitecture
segregsegment register
ffile
int yasm_arch_set_var ( yasm_arch arch,
const char *  var,
unsigned long  val 
)

Set any arch-specific variables.

For example, "mode_bits" in x86.

Parameters
archarchitecture
varvariable name
valvalue to set
Returns
Zero on success, non-zero on failure (variable does not exist).
unsigned int yasm_arch_wordsize ( const yasm_arch arch)

Get the word size of an architecture.

Parameters
archarchitecture
Returns
Word size (in bits).