]>
git.saurik.com Git - apple/boot.git/blob - i386/nasm/nasmlib.h
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
24 /* nasmlib.c header file for nasmlib.h
26 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
27 * Julian Hall. All rights reserved. The software is
28 * redistributable under the licence given in the file "Licence"
29 * distributed in the NASM archive.
32 #ifndef NASM_NASMLIB_H
33 #define NASM_NASMLIB_H
36 * If this is defined, the wrappers around malloc et al will
37 * transform into logging variants, which will cause NASM to create
38 * a file called `malloc.log' when run, and spew details of all its
39 * memory management into that. That can then be analysed to detect
40 * memory leaks and potentially other problems too.
42 /* #define LOGALLOC */
45 * Wrappers around malloc, realloc and free. nasm_malloc will
46 * fatal-error and die rather than return NULL; nasm_realloc will
47 * do likewise, and will also guarantee to work right on being
48 * passed a NULL pointer; nasm_free will do nothing if it is passed
51 #ifdef NASM_NASM_H /* need efunc defined for this */
52 void nasm_set_malloc_error (efunc
);
54 void *nasm_malloc (size_t);
55 void *nasm_realloc (void *, size_t);
56 void nasm_free (void *);
57 char *nasm_strdup (char *);
58 char *nasm_strndup (char *, size_t);
60 void *nasm_malloc_log (char *, int, size_t);
61 void *nasm_realloc_log (char *, int, void *, size_t);
62 void nasm_free_log (char *, int, void *);
63 char *nasm_strdup_log (char *, int, char *);
64 char *nasm_strndup_log (char *, int, char *, size_t);
65 #define nasm_malloc(x) nasm_malloc_log(__FILE__,__LINE__,x)
66 #define nasm_realloc(x,y) nasm_realloc_log(__FILE__,__LINE__,x,y)
67 #define nasm_free(x) nasm_free_log(__FILE__,__LINE__,x)
68 #define nasm_strdup(x) nasm_strdup_log(__FILE__,__LINE__,x)
69 #define nasm_strndup(x,y) nasm_strndup_log(__FILE__,__LINE__,x,y)
74 * ANSI doesn't guarantee the presence of `stricmp' or
77 int nasm_stricmp (char *, char *);
78 int nasm_strnicmp (char *, char *, int);
81 * Convert a string into a number, using NASM number rules. Sets
82 * `*error' to TRUE if an error occurs, and FALSE otherwise.
84 long readnum(char *str
, int *error
);
87 * seg_init: Initialise the segment-number allocator.
88 * seg_alloc: allocate a hitherto unused segment number.
94 * many output formats will be able to make use of this: a standard
95 * function to add an extension to the name of the input file
98 void standard_extension (char *inname
, char *outname
, char *extension
,
103 * some handy macros that will probably be of use in more than one
104 * output format: convert integers into little-endian byte packed
108 #define WRITELONG(p,v) \
110 *(p)++ = (v) & 0xFF; \
111 *(p)++ = ((v) >> 8) & 0xFF; \
112 *(p)++ = ((v) >> 16) & 0xFF; \
113 *(p)++ = ((v) >> 24) & 0xFF; \
116 #define WRITESHORT(p,v) \
118 *(p)++ = (v) & 0xFF; \
119 *(p)++ = ((v) >> 8) & 0xFF; \
123 * and routines to do the same thing to a file
125 void fwriteshort (int data
, FILE *fp
);
126 void fwritelong (long data
, FILE *fp
);
129 * Routines to manage a dynamic random access array of longs which
130 * may grow in size to be more than the largest single malloc'able
136 struct RAA
*raa_init (void);
137 void raa_free (struct RAA
*);
138 long raa_read (struct RAA
*, long);
139 struct RAA
*raa_write (struct RAA
*r
, long posn
, long value
);
142 * Routines to manage a dynamic sequential-access array, under the
143 * same restriction on maximum mallocable block. This array may be
144 * written to in two ways: a contiguous chunk can be reserved of a
145 * given size, and a pointer returned, or single-byte data may be
146 * written. The array can also be read back in the same two ways:
147 * as a series of big byte-data blocks or as a list of structures
153 struct SAA
*saa_init (long elem_len
); /* 1 == byte */
154 void saa_free (struct SAA
*);
155 void *saa_wstruct (struct SAA
*); /* return a structure of elem_len */
156 void saa_wbytes (struct SAA
*, void *, long); /* write arbitrary bytes */
157 void saa_rewind (struct SAA
*); /* for reading from beginning */
158 void *saa_rstruct (struct SAA
*); /* return NULL on EOA */
159 void *saa_rbytes (struct SAA
*, long *); /* return 0 on EOA */
160 void saa_rnbytes (struct SAA
*, void *, long); /* read a given no. of bytes */
161 void saa_fread (struct SAA
*s
, long posn
, void *p
, long len
); /* fixup */
162 void saa_fwrite (struct SAA
*s
, long posn
, void *p
, long len
); /* fixup */
163 void saa_fpwrite (struct SAA
*, FILE *);
169 extern char *stdscan_bufptr
;
170 void stdscan_reset(void);
171 int stdscan (void *private_data
, struct tokenval
*tv
);
176 * Library routines to manipulate expression data types.
178 int is_reloc(expr
*);
179 int is_simple(expr
*);
180 int is_really_simple (expr
*);
181 int is_unknown(expr
*);
182 int is_just_unknown(expr
*);
183 long reloc_value(expr
*);
184 long reloc_seg(expr
*);
185 long reloc_wrt(expr
*);
189 * Binary search routine. Returns index into `array' of an entry
190 * matching `string', or <0 if no match. `array' is taken to
191 * contain `size' elements.
193 int bsi (char *string
, char **array
, int size
);