output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
output/outdbg.$(O) output/outieee.$(O) output/outmacho.$(O) \
preproc.$(O) pptok.$(O) \
- listing.$(O) eval.$(O) stdscan.$(O) tokhash.$(O)
+ listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) tokhash.$(O)
NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) insnsd.$(O)
nasm.h nasmlib.h pptok.h preproc.h regflags.c regs.h regvals.c version.h
crc64.$(O): crc64.c
disasm.$(O): disasm.c compiler.h config.h disasm.h insns.h insnsi.h insnsn.c \
- names.c nasm.h regdis.c regs.c regs.h sync.h version.h
+ names.c nasm.h nasmlib.h regdis.c regs.c regs.h sync.h version.h
eval.$(O): eval.c compiler.h config.h eval.h insnsi.h labels.h nasm.h \
nasmlib.h regs.h version.h
-float.$(O): float.c compiler.h config.h insnsi.h nasm.h regs.h version.h
-hashtbl.$(O): hashtbl.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
- nasmlib.h regs.h version.h
-insnsa.$(O): insnsa.c compiler.h config.h insns.h insnsi.h nasm.h regs.h \
+exprlib.$(O): exprlib.c compiler.h config.h insnsi.h nasm.h nasmlib.h regs.h \
version.h
-insnsd.$(O): insnsd.c compiler.h config.h insns.h insnsi.h nasm.h regs.h \
+float.$(O): float.c compiler.h config.h insnsi.h nasm.h nasmlib.h regs.h \
version.h
+hashtbl.$(O): hashtbl.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
+ nasmlib.h regs.h version.h
+insnsa.$(O): insnsa.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
+ regs.h version.h
+insnsd.$(O): insnsd.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
+ regs.h version.h
insnsn.$(O): insnsn.c
labels.$(O): labels.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
nasmlib.h regs.h version.h
nasmlib.h regs.h version.h
ndisasm.$(O): ndisasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \
nasmlib.h regs.h sync.h version.h
-outform.$(O): outform.c compiler.h config.h insnsi.h nasm.h outform.h regs.h \
- version.h
+outform.$(O): outform.c compiler.h config.h insnsi.h nasm.h nasmlib.h \
+ outform.h regs.h version.h
output/outaout.$(O): output/outaout.c compiler.h config.h insnsi.h nasm.h \
nasmlib.h outform.h regs.h stdscan.h version.h
output/outas86.$(O): output/outas86.c compiler.h config.h insnsi.h nasm.h \
regvals.$(O): regvals.c
stdscan.$(O): stdscan.c compiler.h config.h insns.h insnsi.h nasm.h \
nasmlib.h regs.h stdscan.h version.h
-sync.$(O): sync.c sync.h
-tokhash.$(O): tokhash.c compiler.h config.h insns.h insnsi.h nasm.h regs.h \
- version.h
+sync.$(O): sync.c compiler.h config.h nasmlib.h sync.h
+tokhash.$(O): tokhash.c compiler.h config.h insns.h insnsi.h nasm.h \
+ nasmlib.h regs.h version.h
output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
output/outdbg.$(O) output/outieee.$(O) output/outmacho.$(O) \
preproc.$(O) pptok.$(O) \
- listing.$(O) eval.$(O) stdscan.$(O) tokhash.$(O)
+ listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) tokhash.$(O)
NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) insnsd.$(O)
nasm.h nasmlib.h pptok.h preproc.h regflags.c regs.h regvals.c version.h
crc64.$(O): crc64.c
disasm.$(O): disasm.c compiler.h config.h disasm.h insns.h insnsi.h insnsn.c \
- names.c nasm.h regdis.c regs.c regs.h sync.h version.h
+ names.c nasm.h nasmlib.h regdis.c regs.c regs.h sync.h version.h
eval.$(O): eval.c compiler.h config.h eval.h insnsi.h labels.h nasm.h \
nasmlib.h regs.h version.h
-float.$(O): float.c compiler.h config.h insnsi.h nasm.h regs.h version.h
-hashtbl.$(O): hashtbl.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
- nasmlib.h regs.h version.h
-insnsa.$(O): insnsa.c compiler.h config.h insns.h insnsi.h nasm.h regs.h \
+exprlib.$(O): exprlib.c compiler.h config.h insnsi.h nasm.h nasmlib.h regs.h \
version.h
-insnsd.$(O): insnsd.c compiler.h config.h insns.h insnsi.h nasm.h regs.h \
+float.$(O): float.c compiler.h config.h insnsi.h nasm.h nasmlib.h regs.h \
version.h
+hashtbl.$(O): hashtbl.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
+ nasmlib.h regs.h version.h
+insnsa.$(O): insnsa.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
+ regs.h version.h
+insnsd.$(O): insnsd.c compiler.h config.h insns.h insnsi.h nasm.h nasmlib.h \
+ regs.h version.h
insnsn.$(O): insnsn.c
labels.$(O): labels.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
nasmlib.h regs.h version.h
nasmlib.h regs.h version.h
ndisasm.$(O): ndisasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \
nasmlib.h regs.h sync.h version.h
-outform.$(O): outform.c compiler.h config.h insnsi.h nasm.h outform.h regs.h \
- version.h
+outform.$(O): outform.c compiler.h config.h insnsi.h nasm.h nasmlib.h \
+ outform.h regs.h version.h
output/outaout.$(O): output/outaout.c compiler.h config.h insnsi.h nasm.h \
nasmlib.h outform.h regs.h stdscan.h version.h
output/outas86.$(O): output/outas86.c compiler.h config.h insnsi.h nasm.h \
regvals.$(O): regvals.c
stdscan.$(O): stdscan.c compiler.h config.h insns.h insnsi.h nasm.h \
nasmlib.h regs.h stdscan.h version.h
-sync.$(O): sync.c sync.h
-tokhash.$(O): tokhash.c compiler.h config.h insns.h insnsi.h nasm.h regs.h \
- version.h
+sync.$(O): sync.c compiler.h config.h nasmlib.h sync.h
+tokhash.$(O): tokhash.c compiler.h config.h insns.h insnsi.h nasm.h \
+ nasmlib.h regs.h version.h
--- /dev/null
+/*
+ * exprlib.c
+ *
+ * Library routines to manipulate expression data types.
+ */
+
+#include "nasm.h"
+
+/*
+ * Return TRUE if the argument is a simple scalar. (Or a far-
+ * absolute, which counts.)
+ */
+int is_simple(expr * vect)
+{
+ while (vect->type && !vect->value)
+ vect++;
+ if (!vect->type)
+ return 1;
+ if (vect->type != EXPR_SIMPLE)
+ return 0;
+ do {
+ vect++;
+ } while (vect->type && !vect->value);
+ if (vect->type && vect->type < EXPR_SEGBASE + SEG_ABS)
+ return 0;
+ return 1;
+}
+
+/*
+ * Return TRUE if the argument is a simple scalar, _NOT_ a far-
+ * absolute.
+ */
+int is_really_simple(expr * vect)
+{
+ while (vect->type && !vect->value)
+ vect++;
+ if (!vect->type)
+ return 1;
+ if (vect->type != EXPR_SIMPLE)
+ return 0;
+ do {
+ vect++;
+ } while (vect->type && !vect->value);
+ if (vect->type)
+ return 0;
+ return 1;
+}
+
+/*
+ * Return TRUE if the argument is relocatable (i.e. a simple
+ * scalar, plus at most one segment-base, plus possibly a WRT).
+ */
+int is_reloc(expr * vect)
+{
+ while (vect->type && !vect->value) /* skip initial value-0 terms */
+ vect++;
+ if (!vect->type) /* trivially return TRUE if nothing */
+ return 1; /* is present apart from value-0s */
+ if (vect->type < EXPR_SIMPLE) /* FALSE if a register is present */
+ return 0;
+ if (vect->type == EXPR_SIMPLE) { /* skip over a pure number term... */
+ do {
+ vect++;
+ } while (vect->type && !vect->value);
+ if (!vect->type) /* ...returning TRUE if that's all */
+ return 1;
+ }
+ if (vect->type == EXPR_WRT) { /* skip over a WRT term... */
+ do {
+ vect++;
+ } while (vect->type && !vect->value);
+ if (!vect->type) /* ...returning TRUE if that's all */
+ return 1;
+ }
+ if (vect->value != 0 && vect->value != 1)
+ return 0; /* segment base multiplier non-unity */
+ do { /* skip over _one_ seg-base term... */
+ vect++;
+ } while (vect->type && !vect->value);
+ if (!vect->type) /* ...returning TRUE if that's all */
+ return 1;
+ return 0; /* And return FALSE if there's more */
+}
+
+/*
+ * Return TRUE if the argument contains an `unknown' part.
+ */
+int is_unknown(expr * vect)
+{
+ while (vect->type && vect->type < EXPR_UNKNOWN)
+ vect++;
+ return (vect->type == EXPR_UNKNOWN);
+}
+
+/*
+ * Return TRUE if the argument contains nothing but an `unknown'
+ * part.
+ */
+int is_just_unknown(expr * vect)
+{
+ while (vect->type && !vect->value)
+ vect++;
+ return (vect->type == EXPR_UNKNOWN);
+}
+
+/*
+ * Return the scalar part of a relocatable vector. (Including
+ * simple scalar vectors - those qualify as relocatable.)
+ */
+int64_t reloc_value(expr * vect)
+{
+ while (vect->type && !vect->value)
+ vect++;
+ if (!vect->type)
+ return 0;
+ if (vect->type == EXPR_SIMPLE)
+ return vect->value;
+ else
+ return 0;
+}
+
+/*
+ * Return the segment number of a relocatable vector, or NO_SEG for
+ * simple scalars.
+ */
+int32_t reloc_seg(expr * vect)
+{
+ while (vect->type && (vect->type == EXPR_WRT || !vect->value))
+ vect++;
+ if (vect->type == EXPR_SIMPLE) {
+ do {
+ vect++;
+ } while (vect->type && (vect->type == EXPR_WRT || !vect->value));
+ }
+ if (!vect->type)
+ return NO_SEG;
+ else
+ return vect->type - EXPR_SEGBASE;
+}
+
+/*
+ * Return the WRT segment number of a relocatable vector, or NO_SEG
+ * if no WRT part is present.
+ */
+int32_t reloc_wrt(expr * vect)
+{
+ while (vect->type && vect->type < EXPR_WRT)
+ vect++;
+ if (vect->type == EXPR_WRT) {
+ return vect->value;
+ } else
+ return NO_SEG;
+}
+
#include <inttypes.h>
#include "version.h" /* generated NASM version macros */
#include "compiler.h"
+#include "nasmlib.h"
#include "insnsi.h" /* For enum opcode */
#ifndef NULL
struct ofmt;
/*
- * -------------------------
- * Error reporting functions
- * -------------------------
- */
-
-/*
- * An error reporting function should look like this.
- */
-typedef void (*efunc) (int severity, const char *fmt, ...);
-
-/*
- * These are the error severity codes which get passed as the first
- * argument to an efunc.
- */
-
-#define ERR_DEBUG 0x00000008 /* put out debugging message */
-#define ERR_WARNING 0x00000000 /* warn only: no further action */
-#define ERR_NONFATAL 0x00000001 /* terminate assembly after phase */
-#define ERR_FATAL 0x00000002 /* instantly fatal: exit with error */
-#define ERR_PANIC 0x00000003 /* internal error: panic instantly
- * and dump core for reference */
-#define ERR_MASK 0x0000000F /* mask off the above codes */
-#define ERR_NOFILE 0x00000010 /* don't give source file name/line */
-#define ERR_USAGE 0x00000020 /* print a usage message */
-#define ERR_PASS1 0x00000040 /* only print this error on pass one */
-
-/*
- * These codes define specific types of suppressible warning.
- */
-
-#define ERR_WARN_MASK 0x0000FF00 /* the mask for this feature */
-#define ERR_WARN_SHR 8 /* how far to shift right */
-
-#define ERR_WARN_MNP 0x00000100 /* macro-num-parameters warning */
-#define ERR_WARN_MSR 0x00000200 /* macro self-reference */
-#define ERR_WARN_OL 0x00000300 /* orphan label (no colon, and
- * alone on line) */
-#define ERR_WARN_NOV 0x00000400 /* numeric overflow */
-#define ERR_WARN_GNUELF 0x00000500 /* using GNU ELF extensions */
-#define ERR_WARN_MAX 5 /* the highest numbered one */
-
-/*
* -----------------------
* Other function typedefs
* -----------------------
} expr;
/*
+ * Library routines to manipulate expression data types.
+ */
+int is_reloc(expr *);
+int is_simple(expr *);
+int is_really_simple(expr *);
+int is_unknown(expr *);
+int is_just_unknown(expr *);
+int64_t reloc_value(expr *);
+int32_t reloc_seg(expr *);
+int32_t reloc_wrt(expr *);
+
+/*
* The evaluator can also return hints about which of two registers
* used in an expression should be the base register. See also the
* `operand' structure.
}
/*
- * Return TRUE if the argument is a simple scalar. (Or a far-
- * absolute, which counts.)
- */
-int is_simple(expr * vect)
-{
- while (vect->type && !vect->value)
- vect++;
- if (!vect->type)
- return 1;
- if (vect->type != EXPR_SIMPLE)
- return 0;
- do {
- vect++;
- } while (vect->type && !vect->value);
- if (vect->type && vect->type < EXPR_SEGBASE + SEG_ABS)
- return 0;
- return 1;
-}
-
-/*
- * Return TRUE if the argument is a simple scalar, _NOT_ a far-
- * absolute.
- */
-int is_really_simple(expr * vect)
-{
- while (vect->type && !vect->value)
- vect++;
- if (!vect->type)
- return 1;
- if (vect->type != EXPR_SIMPLE)
- return 0;
- do {
- vect++;
- } while (vect->type && !vect->value);
- if (vect->type)
- return 0;
- return 1;
-}
-
-/*
- * Return TRUE if the argument is relocatable (i.e. a simple
- * scalar, plus at most one segment-base, plus possibly a WRT).
- */
-int is_reloc(expr * vect)
-{
- while (vect->type && !vect->value) /* skip initial value-0 terms */
- vect++;
- if (!vect->type) /* trivially return TRUE if nothing */
- return 1; /* is present apart from value-0s */
- if (vect->type < EXPR_SIMPLE) /* FALSE if a register is present */
- return 0;
- if (vect->type == EXPR_SIMPLE) { /* skip over a pure number term... */
- do {
- vect++;
- } while (vect->type && !vect->value);
- if (!vect->type) /* ...returning TRUE if that's all */
- return 1;
- }
- if (vect->type == EXPR_WRT) { /* skip over a WRT term... */
- do {
- vect++;
- } while (vect->type && !vect->value);
- if (!vect->type) /* ...returning TRUE if that's all */
- return 1;
- }
- if (vect->value != 0 && vect->value != 1)
- return 0; /* segment base multiplier non-unity */
- do { /* skip over _one_ seg-base term... */
- vect++;
- } while (vect->type && !vect->value);
- if (!vect->type) /* ...returning TRUE if that's all */
- return 1;
- return 0; /* And return FALSE if there's more */
-}
-
-/*
- * Return TRUE if the argument contains an `unknown' part.
- */
-int is_unknown(expr * vect)
-{
- while (vect->type && vect->type < EXPR_UNKNOWN)
- vect++;
- return (vect->type == EXPR_UNKNOWN);
-}
-
-/*
- * Return TRUE if the argument contains nothing but an `unknown'
- * part.
- */
-int is_just_unknown(expr * vect)
-{
- while (vect->type && !vect->value)
- vect++;
- return (vect->type == EXPR_UNKNOWN);
-}
-
-/*
- * Return the scalar part of a relocatable vector. (Including
- * simple scalar vectors - those qualify as relocatable.)
- */
-int64_t reloc_value(expr * vect)
-{
- while (vect->type && !vect->value)
- vect++;
- if (!vect->type)
- return 0;
- if (vect->type == EXPR_SIMPLE)
- return vect->value;
- else
- return 0;
-}
-
-/*
- * Return the segment number of a relocatable vector, or NO_SEG for
- * simple scalars.
- */
-int32_t reloc_seg(expr * vect)
-{
- while (vect->type && (vect->type == EXPR_WRT || !vect->value))
- vect++;
- if (vect->type == EXPR_SIMPLE) {
- do {
- vect++;
- } while (vect->type && (vect->type == EXPR_WRT || !vect->value));
- }
- if (!vect->type)
- return NO_SEG;
- else
- return vect->type - EXPR_SEGBASE;
-}
-
-/*
- * Return the WRT segment number of a relocatable vector, or NO_SEG
- * if no WRT part is present.
- */
-int32_t reloc_wrt(expr * vect)
-{
- while (vect->type && vect->type < EXPR_WRT)
- vect++;
- if (vect->type == EXPR_WRT) {
- return vect->value;
- } else
- return NO_SEG;
-}
-
-/*
* Binary search.
*/
int bsi(char *string, const char **array, int size)
/* #define LOGALLOC */
/*
+ * -------------------------
+ * Error reporting functions
+ * -------------------------
+ */
+
+/*
+ * An error reporting function should look like this.
+ */
+typedef void (*efunc) (int severity, const char *fmt, ...);
+
+/*
+ * These are the error severity codes which get passed as the first
+ * argument to an efunc.
+ */
+
+#define ERR_DEBUG 0x00000008 /* put out debugging message */
+#define ERR_WARNING 0x00000000 /* warn only: no further action */
+#define ERR_NONFATAL 0x00000001 /* terminate assembly after phase */
+#define ERR_FATAL 0x00000002 /* instantly fatal: exit with error */
+#define ERR_PANIC 0x00000003 /* internal error: panic instantly
+ * and dump core for reference */
+#define ERR_MASK 0x0000000F /* mask off the above codes */
+#define ERR_NOFILE 0x00000010 /* don't give source file name/line */
+#define ERR_USAGE 0x00000020 /* print a usage message */
+#define ERR_PASS1 0x00000040 /* only print this error on pass one */
+
+/*
+ * These codes define specific types of suppressible warning.
+ */
+
+#define ERR_WARN_MASK 0x0000FF00 /* the mask for this feature */
+#define ERR_WARN_SHR 8 /* how far to shift right */
+
+#define ERR_WARN_MNP 0x00000100 /* macro-num-parameters warning */
+#define ERR_WARN_MSR 0x00000200 /* macro self-reference */
+#define ERR_WARN_OL 0x00000300 /* orphan label (no colon, and
+ * alone on line) */
+#define ERR_WARN_NOV 0x00000400 /* numeric overflow */
+#define ERR_WARN_GNUELF 0x00000500 /* using GNU ELF extensions */
+#define ERR_WARN_MAX 5 /* the highest numbered one */
+
+/*
* Wrappers around malloc, realloc and free. nasm_malloc will
* fatal-error and die rather than return NULL; nasm_realloc will
* do likewise, and will also guarantee to work right on being
* passed a NULL pointer; nasm_free will do nothing if it is passed
* a NULL pointer.
*/
-#ifdef NASM_NASM_H /* need efunc defined for this */
void nasm_set_malloc_error(efunc);
#ifndef LOGALLOC
void *nasm_malloc(size_t);
#define nasm_strdup(x) nasm_strdup_log(__FILE__,__LINE__,x)
#define nasm_strndup(x,y) nasm_strndup_log(__FILE__,__LINE__,x,y)
#endif
-#endif
/*
* ANSI doesn't guarantee the presence of `stricmp' or
void saa_fwrite(struct SAA *s, int32_t posn, void *p, int32_t len); /* fixup */
void saa_fpwrite(struct SAA *, FILE *);
-#ifdef NASM_NASM_H
-/*
- * Library routines to manipulate expression data types.
- */
-int is_reloc(expr *);
-int is_simple(expr *);
-int is_really_simple(expr *);
-int is_unknown(expr *);
-int is_just_unknown(expr *);
-int64_t reloc_value(expr *);
-int32_t reloc_seg(expr *);
-int32_t reloc_wrt(expr *);
-#endif
-
/*
* Binary search routine. Returns index into `array' of an entry
* matching `string', or <0 if no match. `array' is taken to
*/
#include <stdio.h>
+#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
static void output_ins(uint32_t, uint8_t *, int, char *);
static void skip(uint32_t dist, FILE * fp);
+static void ndisasm_error(int severity, const char *fmt, ...)
+{
+ va_list va;
+
+ va_start(va, fmt);
+ vfprintf(stderr, fmt, va);
+
+ if (severity & ERR_FATAL)
+ exit(1);
+}
+
int main(int argc, char **argv)
{
char buffer[INSN_MAX * 2], *p, *ep, *q;
int32_t offset;
FILE *fp;
+ nasm_set_malloc_error(ndisasm_error);
+
offset = 0;
init_sync();