📄 asm.h
字号:
/* asm.h - global header file */
#pragma warning(disable:4057)
#pragma warning(disable:4244)
#ifndef asmH
#define asmH /* Don't declare things twice. */
#include <stdio.h>
#include <ctype.h>
//#include <assert.h>
#include <time.h>
#ifndef __PTR_TO_INT
#define __PTR_TO_INT(P) ((P) - (char *)0)
#endif
#ifndef __INT_TO_PTR
#define __INT_TO_PTR(P) ((P) + (char *)0)
#endif
extern int atoi(char *);
extern void qsort(void *,int,int,int(*compare)(const void *,const void *));
#define index strchr
struct _obstack_chunk /* Lives at front of each chunk. */
{
char *limit; /* 1 past end of this chunk */
struct _obstack_chunk *prev; /* address of prior chunk or NULL */
char contents[4]; /* objects begin here */
};
struct obstack /* control current object in current chunk */
{
long chunk_size; /* preferred size to allocate chunks in */
struct _obstack_chunk* chunk; /* address of current struct obstack_chunk */
char *object_base; /* address of object we are building */
unsigned char *next_free; /* where to add next char to current object */
char *chunk_limit; /* address of char after current chunk */
int temp; /* Temporary for some macros. */
int alignment_mask; /* Mask of alignment for each object. */
struct _obstack_chunk *(*chunkfun) (int); /* User's fcn to allocate a chunk. */
void (*freefun) (void *); /* User's function to free a chunk. */
};
/* Do the function-declarations after the structs
but before defining the macros. */
void obstack_init (struct obstack *obstack);
void * obstack_alloc (struct obstack *obstack, int size);
void * obstack_copy (struct obstack *obstack, void *address, int size);
void * obstack_copy0 (struct obstack *obstack, void *address, int size);
static void obstack_free (struct obstack *obstack, void *block);
void obstack_blank (struct obstack *obstack, int size);
void obstack_grow (struct obstack *obstack, void *data, int size);
void obstack_grow0 (struct obstack *obstack, void *data, int size);
void obstack_1grow (struct obstack *obstack, int data_char);
void obstack_ptr_grow (struct obstack *obstack, void *data);
void obstack_int_grow (struct obstack *obstack, int data);
void * obstack_finish (struct obstack *obstack);
int obstack_object_size (struct obstack *obstack);
int obstack_room (struct obstack *obstack);
void obstack_1grow_fast (struct obstack *obstack, int data_char);
void obstack_ptr_grow_fast (struct obstack *obstack, void *data);
void obstack_int_grow_fast (struct obstack *obstack, int data);
void obstack_blank_fast (struct obstack *obstack, int size);
void * obstack_base (struct obstack *obstack);
void * obstack_next_free (struct obstack *obstack);
int obstack_alignment_mask (struct obstack *obstack);
int obstack_chunk_size (struct obstack *obstack);
/* Non-ANSI C cannot really support alternative functions for these macros,
so we do not declare them. */
/* Pointer to beginning of object being allocated or to be allocated next.
Note that this might not be the final address of the object
because a new chunk might be needed to hold the final size. */
#define obstack_base(h) ((h)->object_base)
/* Size for allocating ordinary chunks. */
#define obstack_chunk_size(h) ((h)->chunk_size)
/* Pointer to next byte not yet allocated in current chunk. */
#define obstack_next_free(h) ((h)->next_free)
/* Mask specifying low bits that should be clear in address of an object. */
#define obstack_alignment_mask(h) ((h)->alignment_mask)
#define obstack_init(h) \
_obstack_begin ((h), 0, 0, \
(void *(*) (int)) obstack_chunk_alloc, obstack_chunk_free)
#define obstack_begin(h, size) \
_obstack_begin ((h), (size), 0, \
(void *(*) (int)) obstack_chunk_alloc, obstack_chunk_free)
#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = achar)
#define obstack_blank_fast(h,n) ((h)->next_free += (n))
#define obstack_room(h) \
(unsigned) ((h)->chunk_limit - (h)->next_free)
#define obstack_grow(h,where,length) \
( (h)->temp = (length), \
(((h)->next_free + (h)->temp > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
bcopy (where, (h)->next_free, (h)->temp), \
(h)->next_free += (h)->temp)
#define obstack_1grow(h,datum) \
( (((h)->next_free + 1 > (h)->chunk_limit) \
? (_obstack_newchunk ((h), 1), 0) : 0), \
*((h)->next_free)++ = (datum))
#define obstack_ptr_grow_fast(h,aptr) (*((char **)(h)->next_free)++ = (char *)aptr)
#define obstack_int_grow_fast(h,aint) (*((int *)(h)->next_free)++ = (int)aint)
#define obstack_blank(h,length) \
( (h)->temp = (length), \
(((h)->chunk_limit - (h)->next_free < (h)->temp) \
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
(h)->next_free += (h)->temp)
#define obstack_alloc(h,length) \
(obstack_blank ((h), (length)), obstack_finish ((h)))
#define obstack_copy(h,where,length) \
(obstack_grow ((h), (where), (length)), obstack_finish ((h)))
#define obstack_finish(h) \
( (h)->temp = __PTR_TO_INT ((h)->object_base), \
(h)->next_free \
= __INT_TO_PTR ((__PTR_TO_INT ((h)->next_free)+(h)->alignment_mask) \
& ~ ((h)->alignment_mask)), \
(((h)->next_free - (char *)(h)->chunk \
> (h)->chunk_limit - (char *)(h)->chunk) \
? ((h)->next_free = (h)->chunk_limit) : 0), \
(h)->object_base = (h)->next_free, \
__INT_TO_PTR ((h)->temp))
#define bcopy(from,to,n) memcpy((to),(from),(n))
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
/* These defines are potentially useful */
#define FALSE (0)
#define TRUE (!FALSE)
#define ASSERT assert
#ifdef SUSPECT
#define register /* no registers: helps debugging */
#define know(p) ASSERT(p) /* know() is less ugly than #ifdef SUSPECT/ */
/* assert()/#endif. */
#else
#define know(p) /* know() checks are no-op.ed */
#endif /* #ifdef SUSPECT */
/* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
/*
* This table describes the use of segments as EXPRESSION types.
*
* X_seg X_add_symbol X_subtract_symbol X_add_number
* SEG_NONE no (legal) expression
* SEG_PASS1 no (defined) "
* SEG_BIG * > 32 bits const.
* SEG_ABSOLUTE 0
* SEG_DATA * 0
* SEG_TEXT * 0
* SEG_BSS * 0
* SEG_UNKNOWN * 0
* SEG_DIFFERENCE 0 * 0
*
* The blank fields MUST be 0, and are nugatory.
* The '0' fields MAY be 0. The '*' fields MAY NOT be 0.
*
* SEG_BIG: X_add_number is < 0 if the result is in
* generic_floating_point_number. The value is -'c' where c is the
* character that introduced the constant. e.g. "0f6.9" will have -'f'
* as a X_add_number value.
* X_add_number > 0 is a count of how many littlenums it took to
* represent a bignum.
* SEG_DIFFERENCE:
* If segments of both symbols are known, they are the same segment.
* X_add_symbol != X_sub_symbol (then we just cancel them, => SEG_ABSOLUTE).
*/
typedef enum
{
SEG_ABSOLUTE,
SEG_TEXT,
SEG_DATA,
SEG_BSS,
SEG_UNKNOWN,
SEG_NONE, /* Mythical Segment: NO expression seen. */
SEG_PASS1, /* Mythical Segment: Need another pass. */
SEG_GOOF, /* Only happens if AS has a logic error. */
/* Invented so we don't crash printing */
/* error message involving weird segment. */
SEG_BIG, /* Bigger than 32 bits constant. */
SEG_DIFFERENCE /* Mythical Segment: absolute difference. */
} segT;
#define SEG_MAXIMUM_ORDINAL (SEG_DIFFERENCE)
typedef unsigned char subsegT;
typedef enum
{
rs_fill, /* Variable chars to be repeated fr_offset */
/* times. Fr_symbol unused. */
/* Used with fr_offset == 0 for a constant */
/* length frag. */
rs_align, /* Align: Fr_offset: power of 2. */
/* 1 variable char: fill character. */
rs_org, /* Org: Fr_offset, fr_symbol: address. */
/* 1 variable char: fill character. */
rs_machine_dependent,
}
relax_stateT;
typedef unsigned long int relax_substateT;
typedef unsigned long int relax_addressT;/* Enough bits for address. */
/* Still an integer type. */
/* subsegs.h -> subsegs.c
* For every sub-segment the user mentions in the ASsembler program,
* we make one struct frchain. Each sub-segment has exactly one struct frchain
* and vice versa.
*
* Struct frchain's are forward chained (in ascending order of sub-segment
* code number). The chain runs through frch_next of each subsegment.
* This makes it hard to find a subsegment's frags
* if programmer uses a lot of them. Most programs only use text0 and
* data0, so they don't suffer. At least this way:
* (1) There are no "arbitrary" restrictions on how many subsegments
* can be programmed;
* (2) Subsegments' frchain-s are (later) chained together in the order in
* which they are emitted for object file viz text then data.
*
* From each struct frchain dangles a chain of struct frags. The frags
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -