⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asm.h

📁 window下的c编译器。
💻 H
📖 第 1 页 / 共 2 页
字号:
 * represent code fragments, for that sub-segment, forward chained.
 */

struct frchain			/* control building of a frag chain */
{				/* FRCH = FRagment CHain control */
  struct frag *	frch_root;	/* 1st struct frag in chain, or NULL */
  struct frag *	frch_last;	/* last struct frag in chain, or NULL */
  struct frchain * frch_next;	/* next in chain of struct frchain-s */
  segT		frch_seg;	/* SEG_TEXT or SEG_DATA. */
  subsegT	frch_subseg;	/* subsegment number of this chain */
};

typedef struct frchain frchainS;
/*
 * A code fragment (frag) is some known number of chars, followed by some
 * unknown number of chars. Typically the unknown number of chars is an
 * instruction address whose size is yet unknown. We always know the greatest
 * possible size the unknown number of chars may become, and reserve that
 * much room at the end of the frag.
 * Once created, frags do not change address during assembly.
 * We chain the frags in (a) forward-linked list(s). The object-file address
 * of the 1st char of a frag is generally not known until after relax().
 * Many things at assembly time describe an address by {object-file-address
 * of a particular frag}+offset.

 BUG: it may be smarter to have a single pointer off to various different
notes for different frag kinds. See how code pans out.
 */
struct frag			/* a code fragment */
{
	long unsigned int fr_address; /* Object file address. */
	struct frag *fr_next;	/* Chain forward; ascending address order. */
				/* Rooted in frch_root. */

	long int fr_fix;	/* (Fixed) number of chars we know we have. */
				/* May be 0. */
	long int fr_var;	/* (Variable) number of chars after above. */
				/* May be 0. */
	struct AsmSymbol *fr_symbol; /* For variable-length tail. */
	long int fr_offset;	/* For variable-length tail. */
	char	*fr_opcode;	/*->opcode low addr byte,for relax()ation*/
	relax_stateT fr_type;   /* What state is my tail in? */
	relax_substateT	fr_subtype;
	char	fr_literal [1];	/* Chars begin here. */
				/* One day we will compile fr_literal[0]. */
};
#define SIZEOF_STRUCT_FRAG \
 ((int)zero_address_frag.fr_literal-(int)&zero_address_frag)
				/* We want to say fr_literal[0] above. */

typedef struct frag fragS;

#define N_UNDF 0
#define N_ABS 2
#define N_TEXT 4
#define N_DATA 6
#define N_BSS 8
#define N_FN 15

#define N_EXT 1
#define N_TYPE 036
#define N_STAB 0340
struct relocation_info
{
  /* Address (within segment) to be relocated.  */
  int r_address;
  unsigned int r_pcrel:1;
};

struct AsmSymbol
{
  struct AsmSymbol 		*Next;		/* forward chain, or NULL */
  char					*Name;
  unsigned long 		SymbolValue;
  struct frag			*sy_frag;	/* NULL or -> frag this symbol attaches to. */
  struct AsmSymbol 		*sy_forward;/* value is really that of this other symbol */
  int					SectionNumber;
  int					Type;
  int					StorageClass;
  int					NumberOfAuxSymbols;
  int					OrdinalNumber;
  int					StartLine;
  int					EndLine;
  int					Flags;
  struct tagCoffReloc 	*Relocations;
  struct tagCoffLine 	*Lines;
  struct tagCoffFn 		*FnInfo;
  unsigned char 		sy_type;
};

typedef struct AsmSymbol symbolS;

typedef unsigned valueT;	/* The type of n_value. Helps casting. */

typedef struct {
  char *	poc_name;	/* assembler mnemonic, lower case, no '.' */
  void		(*poc_handler)(void);	/* Do the work */
}
pseudo_typeS;

typedef struct
{
	long	rlx_forward;	/* Forward  reach. Signed number. > 0. */
	long	rlx_backward;	/* Backward reach. Signed number. < 0. */
	unsigned char rlx_length;	/* Bytes length of this address. */
	relax_substateT rlx_more;	/* Next longer relax-state. */
				/* 0 means there is no 'next' relax-state. */
}
relax_typeS;


/*
 * FixSs may be built up in any order.
 */

struct fix
{
  struct fix   *fx_next;	/* NULL or -> next fixS. */
  fragS  	   *fx_frag;	/* Which frag? */
  long int		fx_where;	/* Where is the 1st byte to fix up? */
  symbolS      *fx_addsy; /* NULL or Symbol whose value we add in. */
  symbolS      *fx_subsy; /* NULL or Symbol whose value we subtract. */
  long int		fx_offset;	/* Absolute number we add in. */
  short int		fx_size;	/* How many bytes are involved? */
  char			fx_pcrel;	/* TRUE: pc-relative. */
  struct        tagCoffReloc *CoffReloc;
};

typedef struct fix	fixS;

struct HASH_LIST {
	struct HASH_LIST *Next;
	char *Name;
	char *Data;
	short len;
};

typedef struct tagCoffReloc {
	struct tagCoffReloc *Next;
	int       Offset;
	symbolS *Symbol;
	fixS *pfixS;
	int Flags;
	short int Type;
	int TargetSegment;
} COFF_RELOC;

typedef struct tagCoffFn {
	int Tag;
	int Size;
	int NrOfLines;
	symbolS *Start;
	symbolS *End;
	int LineNumbersFileOffset;
	int NextFnIdx;
} COFF_FN;

typedef struct tagCoffLine {
	struct tagCoffLine *Next;
	fragS *Frag;
	int Line;
	int fragOffset;
} COFF_LINE;

#define IS_PCRELATIVE 1
#define IS_TEXT       2
#define IS_DATA       4
#define IS_BSS        8
#define IS_FUNCTION	  16
#define COUNTED		  32

#define SECTION_TEXT	1
#define SECTION_DATA	2
#define SECTION_BSS		3

typedef struct tagString {
	struct tagString *Next;
	int len;
	char *String;
} STRING;

typedef struct tagStringTable {
	int Size;
	STRING *Strings;
} STRING_TABLE;

/*
 * A macro to speed up appending exactly 1 char
 * to current frag.
 */
#define FRAG_APPEND_1_CHAR(datum)	\
{					\
	if (obstack_room( &frags ) <= 1) {\
		frag_wane (frag_now);	\
		frag_new (0);		\
	}				\
	obstack_1grow( &frags, datum );	\
}
#define hash_control HASH_LIST

#define symbol_table_lookup(name) ((symbolS *)(hash_find (sy_hash,name)))

/*#define SKIP_WHITESPACE() ASSERT( * InputPointer != ' ' )*/
#define SKIP_WHITESPACE() while (*InputPointer == ' ' || *InputPointer == '\t') InputPointer++;
#define	LEX_NAME	(1)	/* may continue a name */
#define LEX_BEGIN_NAME	(2)	/* may begin a name */

#define is_name_beginner(c)     ( lex_type[c] & LEX_BEGIN_NAME )
#define is_part_of_name(c)      ( lex_type[c] & LEX_NAME       )

/*
 * Abbreviations (mnemonics).
 *
 *	O	operator
 *	Q	quantity,  operand
 *	X	eXpression
  * By popular demand, we define a struct to represent an expression.
 * This will no doubt mutate as expressions become baroque.
 *
 * Currently, we support expressions like "foo-bar+42".
 * In other words we permit a (possibly undefined) minuend, a
 * (possibly undefined) subtrahend and an (absolute) augend.
 * RMS says this is so we can have 1-pass assembly for any compiler
 * emmissions, and a 'case' statement might emit 'undefined1 - undefined2'.
 *
 * To simplify table-driven dispatch, we also have a "segment" for the
 * entire expression. That way we don't require complex reasoning about
 * whether particular components are defined; and we can change component
 * semantics without re-working all the dispatch tables in the assembler.
 * In other words the "type" of an expression is its segment.
 */
typedef struct
{
	symbolS *X_add_symbol;		/* foo */
	symbolS *X_subtract_symbol;	/* bar */
	long int X_add_number;		/* 42.    Must be signed. */
	segT	X_seg;			/* What segment (expr type)? */
}
expressionS;

typedef struct tagNewSection {
	struct tagNewSection *Next;
	char Name[10];
	int HeaderPosition;
	int Number;
	int DataSize;
	char *data;
} NewSection;

				/* result should be type (expressionS *). */
#define expression(result) AsmExpression(0,result)

#endif				/* #ifdef asH */


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -