diff options
author | polwex <polwex@sortug.com> | 2025-10-05 21:56:51 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-10-05 21:56:51 +0700 |
commit | fcedfddf00b3f994e4f4e40332ac7fc192c63244 (patch) | |
tree | 51d38e62c7bdfcc5f9a5e9435fe820c93cfc9a3d /vere/ext/nasm/include |
claude is gud
Diffstat (limited to 'vere/ext/nasm/include')
25 files changed, 5076 insertions, 0 deletions
diff --git a/vere/ext/nasm/include/bytesex.h b/vere/ext/nasm/include/bytesex.h new file mode 100644 index 0000000..186d561 --- /dev/null +++ b/vere/ext/nasm/include/bytesex.h @@ -0,0 +1,261 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2017 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * bytesex.h - byte order helper functions + * + * In this function, be careful about getting X86_MEMORY versus + * LITTLE_ENDIAN correct: X86_MEMORY also means we are allowed to + * do unaligned memory references, and is probabilistic. + */ + +#ifndef NASM_BYTEORD_H +#define NASM_BYTEORD_H + +#include "compiler.h" + +/* + * Some handy macros that will probably be of use in more than one + * output format: convert integers into little-endian byte packed + * format in memory. + */ + +#define WRITECHAR(p,v) \ + do { \ + uint8_t *_wc_p = (uint8_t *)(p); \ + *_wc_p++ = (v); \ + (p) = (void *)_wc_p; \ + } while (0) + +#if X86_MEMORY + +#define WRITESHORT(p,v) \ + do { \ + uint16_t *_ws_p = (uint16_t *)(p); \ + *_ws_p++ = (v); \ + (p) = (void *)_ws_p; \ + } while (0) + +#define WRITELONG(p,v) \ + do { \ + uint32_t *_wl_p = (uint32_t *)(p); \ + *_wl_p++ = (v); \ + (p) = (void *)_wl_p; \ + } while (0) + +#define WRITEDLONG(p,v) \ + do { \ + uint64_t *_wq_p = (uint64_t *)(p); \ + *_wq_p++ = (v); \ + (p) = (void *)_wq_p; \ + } while (0) + +#else /* !X86_MEMORY */ + +#define WRITESHORT(p,v) \ + do { \ + uint8_t *_ws_p = (uint8_t *)(p); \ + const uint16_t _ws_v = (v); \ + WRITECHAR(_ws_p, _ws_v); \ + WRITECHAR(_ws_p, _ws_v >> 8); \ + (p) = (void *)_ws_p; \ + } while (0) + +#define WRITELONG(p,v) \ + do { \ + uint8_t *_wl_p = (uint8_t *)(p); \ + const uint32_t _wl_v = (v); \ + WRITESHORT(_wl_p, _wl_v); \ + WRITESHORT(_wl_p, _wl_v >> 16); \ + (p) = (void *)_wl_p; \ + } while (0) + +#define WRITEDLONG(p,v) \ + do { \ + uint8_t *_wq_p = (uint8_t *)(p); \ + const uint64_t _wq_v = (v); \ + WRITELONG(_wq_p, _wq_v); \ + WRITELONG(_wq_p, _wq_v >> 32); \ + (p) = (void *)_wq_p; \ + } while (0) + +#endif /* X86_MEMORY */ + +/* + * Endian control functions which work on a single integer + */ +#ifdef WORDS_LITTLEENDIAN + +#ifndef HAVE_CPU_TO_LE16 +# define cpu_to_le16(v) ((uint16_t)(v)) +#endif +#ifndef HAVE_CPU_TO_LE32 +# define cpu_to_le32(v) ((uint32_t)(v)) +#endif +#ifndef HAVE_CPU_TO_LE64 +# define cpu_to_le64(v) ((uint64_t)(v)) +#endif + +#elif defined(WORDS_BIGENDIAN) + +#ifndef HAVE_CPU_TO_LE16 +static inline uint16_t cpu_to_le16(uint16_t v) +{ +# ifdef HAVE___CPU_TO_LE16 + return __cpu_to_le16(v); +# elif defined(HAVE_HTOLE16) + return htole16(v); +# elif defined(HAVE___BSWAP_16) + return __bswap_16(v); +# elif defined(HAVE___BUILTIN_BSWAP16) + return __builtin_bswap16(v); +# elif defined(HAVE__BYTESWAP_USHORT) && (USHRT_MAX == 0xffffU) + return _byteswap_ushort(v); +# else + return (v << 8) | (v >> 8); +# endif +} +#endif + +#ifndef HAVE_CPU_TO_LE32 +static inline uint32_t cpu_to_le32(uint32_t v) +{ +# ifdef HAVE___CPU_TO_LE32 + return __cpu_to_le32(v); +# elif defined(HAVE_HTOLE32) + return htole32(v); +# elif defined(HAVE___BSWAP_32) + return __bswap_32(v); +# elif defined(HAVE___BUILTIN_BSWAP32) + return __builtin_bswap32(v); +# elif defined(HAVE__BYTESWAP_ULONG) && (ULONG_MAX == 0xffffffffUL) + return _byteswap_ulong(v); +# else + v = ((v << 8) & 0xff00ff00 ) | + ((v >> 8) & 0x00ff00ff); + return (v << 16) | (v >> 16); +# endif +} +#endif + +#ifndef HAVE_CPU_TO_LE64 +static inline uint64_t cpu_to_le64(uint64_t v) +{ +# ifdef HAVE___CPU_TO_LE64 + return __cpu_to_le64(v); +# elif defined(HAVE_HTOLE64) + return htole64(v); +# elif defined(HAVE___BSWAP_64) + return __bswap_64(v); +# elif defined(HAVE___BUILTIN_BSWAP64) + return __builtin_bswap64(v); +# elif defined(HAVE__BYTESWAP_UINT64) + return _byteswap_uint64(v); +# else + v = ((v << 8) & 0xff00ff00ff00ff00ull) | + ((v >> 8) & 0x00ff00ff00ff00ffull); + v = ((v << 16) & 0xffff0000ffff0000ull) | + ((v >> 16) & 0x0000ffff0000ffffull); + return (v << 32) | (v >> 32); +# endif +} +#endif + +#else /* not WORDS_LITTLEENDIAN or WORDS_BIGENDIAN */ + +static inline uint16_t cpu_to_le16(uint16_t v) +{ + union u16 { + uint16_t v; + uint8_t c[2]; + } x; + uint8_t *cp = &x.c; + + WRITESHORT(cp, v); + return x.v; +} + +static inline uint32_t cpu_to_le32(uint32_t v) +{ + union u32 { + uint32_t v; + uint8_t c[4]; + } x; + uint8_t *cp = &x.c; + + WRITELONG(cp, v); + return x.v; +} + +static inline uint64_t cpu_to_le64(uint64_t v) +{ + union u64 { + uint64_t v; + uint8_t c[8]; + } x; + uint8_t *cp = &x.c; + + WRITEDLONG(cp, v); + return x.v; +} + +#endif + +#define WRITEADDR(p,v,s) \ + do { \ + switch (is_constant(s) ? (s) : 0) { \ + case 1: \ + WRITECHAR(p,v); \ + break; \ + case 2: \ + WRITESHORT(p,v); \ + break; \ + case 4: \ + WRITELONG(p,v); \ + break; \ + case 8: \ + WRITEDLONG(p,v); \ + break; \ + default: \ + { \ + const uint64_t _wa_v = cpu_to_le64(v); \ + const size_t _wa_s = (s); \ + uint8_t * const _wa_p = (uint8_t *)(p); \ + memcpy(_wa_p, &_wa_v, _wa_s); \ + (p) = (void *)(_wa_p + _wa_s); \ + } \ + break; \ + } \ + } while (0) + +#endif /* NASM_BYTESEX_H */ diff --git a/vere/ext/nasm/include/compiler.h b/vere/ext/nasm/include/compiler.h new file mode 100644 index 0000000..407c160 --- /dev/null +++ b/vere/ext/nasm/include/compiler.h @@ -0,0 +1,415 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2007-2020 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * compiler.h + * + * Compiler-specific macros for NASM. Feel free to add support for + * other compilers in here. + * + * This header file should be included before any other header. + */ + +#ifndef NASM_COMPILER_H +#define NASM_COMPILER_H 1 + +/* + * At least DJGPP and Cygwin have broken header files if __STRICT_ANSI__ + * is defined. + */ +#ifdef __GNUC__ +# undef __STRICT_ANSI__ +#endif + +/* On Microsoft platforms we support multibyte character sets in filenames */ +#define _MBCS 1 + +#ifdef HAVE_CONFIG_H +# include "config/config.h" +#else +# if defined(_MSC_VER) && (_MSC_VER >= 1310) +# include "config/msvc.h" +# elif defined(__WATCOMC__) +# include "config/watcom.h" +# else +# include "config/unknown.h" +# endif +/* This unconditionally defines some macros we really want */ +# include "config/unconfig.h" +#endif /* Configuration file */ + +/* This is required to get the standard <inttypes.h> macros when compiling + with a C++ compiler. This must be defined *before* <inttypes.h> is + included, directly or indirectly. */ +#define __STDC_CONSTANT_MACROS 1 +#define __STDC_LIMIT_MACROS 1 +#define __STDC_FORMAT_MACROS 1 + +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#else +# include "nasmint.h" +#endif + +#include <assert.h> +#include <stddef.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <errno.h> + +#ifdef HAVE_STRINGS_H +# include <strings.h> +#endif +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif + +#ifdef HAVE_ENDIAN_H +# include <endian.h> +#elif defined(HAVE_SYS_ENDIAN_H) +# include <sys/endian.h> +#elif defined(HAVE_MACHINE_ENDIAN_H) +# include <machine/endian.h> +#endif + +/* + * If we have BYTE_ORDER defined, or the compiler provides + * __BIG_ENDIAN__ or __LITTLE_ENDIAN__, trust it over what autoconf + * came up with, especially since autoconf obviously can't figure + * things out for a universal compiler. + */ +#if defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) +# undef WORDS_LITTLEENDIAN +# undef WORDS_BIGENDIAN +# define WORDS_BIGENDIAN 1 +#elif defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +# undef WORDS_LITTLEENDIAN +# undef WORDS_BIGENDIAN +# define WORDS_LITTLEENDIAN 1 +#elif defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) +# undef WORDS_LITTLEENDIAN +# undef WORDS_BIGENDIAN +# if BYTE_ORDER == LITTLE_ENDIAN +# define WORDS_LITTLEENDIAN 1 +# elif BYTE_ORDER == BIG_ENDIAN +# define WORDS_BIGENDIAN 1 +# endif +#endif + +/* + * Define this to 1 for faster performance if this is a littleendian + * platform *and* it can do arbitrary unaligned memory references. It + * is safe to leave it defined to 0 even if that is true. + */ +#if defined(__386__) || defined(__i386__) || defined(__x86_64__) \ + || defined(_M_IX86) || defined(_M_X64) +# define X86_MEMORY 1 +# undef WORDS_BIGENDIAN +# undef WORDS_LITTLEENDIAN +# define WORDS_LITTLEENDIAN 1 +#else +# define X86_MEMORY 0 +#endif + +/* Some versions of MSVC have these only with underscores in front */ +#ifndef HAVE_SNPRINTF +# ifdef HAVE__SNPRINTF +# define snprintf _snprintf +# else +int snprintf(char *, size_t, const char *, ...); +# endif +#endif + +#ifndef HAVE_VSNPRINTF +# ifdef HAVE__VSNPRINTF +# define vsnprintf _vsnprintf +# else +int vsnprintf(char *, size_t, const char *, va_list); +# endif +#endif + +#if !defined(HAVE_STRLCPY) || !HAVE_DECL_STRLCPY +size_t strlcpy(char *, const char *, size_t); +#endif + +#if !defined(HAVE_STRCHRNUL) || !HAVE_DECL_STRCHRNUL +char *strrchrnul(const char *, int); +#endif + +#ifndef __cplusplus /* C++ has false, true, bool as keywords */ +# ifdef HAVE_STDBOOL_H +# include <stdbool.h> +# elif defined(HAVE__BOOL) + typedef _Bool bool; +# define false 0 +# define true 1 +# else +/* This is sort of dangerous, since casts will behave different than + casting to the standard boolean type. Always use !!, not (bool). */ +typedef enum bool { false, true } bool; +# endif +#endif + +/* Create a NULL pointer of the same type as the address of + the argument, without actually evaluating said argument. */ +#define nullas(p) (0 ? &(p) : NULL) + +/* Convert an offsetted NULL pointer dereference to a size_t offset. + Technically non-portable as taking the offset from a NULL pointer + is undefined behavior, but... */ +#define null_offset(p) ((size_t)((const char *)&(p) - (const char *)NULL)) + +/* Provide a substitute for offsetof() if we don't have one. This + variant works on most (but not *all*) systems... */ +#ifndef offsetof +# define offsetof(t,m) null_offset(((t *)NULL)->m) +#endif + +/* If typeof is defined as a macro, assume we have typeof even if + HAVE_TYPEOF is not declared (e.g. due to not using autoconf.) */ +#ifdef typeof +# define HAVE_TYPEOF 1 +#endif + +/* This is like offsetof(), but takes an object rather than a type. */ +#ifndef offsetin +# ifdef HAVE_TYPEOF +# define offsetin(p,m) offsetof(typeof(p),m) +# else +# define offsetin(p,m) null_offset(nullas(p)->m) +# endif +#endif + +/* The container_of construct: if p is a pointer to member m of + container class c, then return a pointer to the container of which + *p is a member. */ +#ifndef container_of +# define container_of(p, c, m) ((c *)((char *)(p) - offsetof(c,m))) +#endif + +/* Some misguided platforms hide the defs for these */ +#if defined(HAVE_STRCASECMP) && !HAVE_DECL_STRCASECMP +int strcasecmp(const char *, const char *); +#endif + +#if defined(HAVE_STRICMP) && !HAVE_DECL_STRICMP +int stricmp(const char *, const char *); +#endif + +#if defined(HAVE_STRNCASECMP) && !HAVE_DECL_STRNCASECMP +int strncasecmp(const char *, const char *, size_t); +#endif + +#if defined(HAVE_STRNICMP) && !HAVE_DECL_STRNICMP +int strnicmp(const char *, const char *, size_t); +#endif + +#if defined(HAVE_STRSEP) && !HAVE_DECL_STRSEP +char *strsep(char **, const char *); +#endif + +#if !HAVE_DECL_STRNLEN +size_t strnlen(const char *s, size_t maxlen); +#endif + +#ifndef HAVE_MEMPCPY +static inline void *mempcpy(void *dst, const void *src, size_t n) +{ + return (char *)memcpy(dst, src, n) + n; +} +#endif + +#ifndef HAVE_MEMPSET +static inline void *mempset(void *dst, int c, size_t n) +{ + return (char *)memset(dst, c, n) + n; +} +#endif + +/* + * Hack to support external-linkage inline functions + */ +#ifndef HAVE_STDC_INLINE +# ifdef __GNUC__ +# ifdef __GNUC_STDC_INLINE__ +# define HAVE_STDC_INLINE +# else +# define HAVE_GNU_INLINE +# endif +# elif defined(__GNUC_GNU_INLINE__) +/* Some other compiler implementing only GNU inline semantics? */ +# define HAVE_GNU_INLINE +# elif defined(__STDC_VERSION__) +# if __STDC_VERSION__ >= 199901L +# define HAVE_STDC_INLINE +# endif +# endif +#endif + +#ifdef HAVE_STDC_INLINE +# define extern_inline inline +#elif defined(HAVE_GNU_INLINE) +# define extern_inline extern inline +# define inline_prototypes +#else +# define inline_prototypes +#endif + +/* + * Hints to the compiler that a particular branch of code is more or + * less likely to be taken. + */ +#if HAVE___BUILTIN_EXPECT +# define likely(x) __builtin_expect(!!(x), 1) +# define unlikely(x) __builtin_expect(!!(x), 0) +#else +# define likely(x) (!!(x)) +# define unlikely(x) (!!(x)) +#endif + +#define safe_alloc never_null malloc_func +#define safe_alloc_ptr never_null_ptr malloc_func_ptr + +#define safe_malloc(s) safe_alloc alloc_size_func1(s) +#define safe_malloc2(s1,s2) safe_alloc alloc_size_func2(s1,s2) +#define safe_realloc(s) never_null alloc_size_func1(s) +#define safe_malloc_ptr(s) safe_alloc_ptr alloc_size_func1_ptr(s) +#define safe_malloc2_ptr(s1,s2) safe_alloc_ptr alloc_size_func2_ptr(s1,s2) +#define safe_realloc_ptr(s) never_null_ptr alloc_size_func1_ptr(s) + +/* + * How to tell the compiler that a function doesn't return + */ +#ifdef HAVE_STDNORETURN_H +# include <stdnoreturn.h> +# define no_return noreturn void +#elif defined(_MSC_VER) +# define no_return __declspec(noreturn) void +#else +# define no_return void noreturn_func +#endif + +/* + * A fatal function is both unlikely and no_return + */ +#define fatal_func no_return unlikely_func +#define fatal_func_ptr no_return unlikely_func_ptr + +/* + * How to tell the compiler that a function takes a printf-like string + */ +#define printf_func(fmt, list) format_func3(printf,fmt,list) +#define printf_func_ptr(fmt, list) format_func3_ptr(printf,fmt,list) +#define vprintf_func(fmt) format_func3(printf,fmt,0) +#define vprintf_func_ptr(fmt) format_func3_ptr(printf,fmt,0) + +/* Determine probabilistically if something is a compile-time constant */ +#ifdef HAVE___BUILTIN_CONSTANT_P +# if defined(__GNUC__) && (__GNUC__ >= 5) +# define is_constant(x) __builtin_constant_p((x)) +# else +# define is_constant(x) false +# endif +#else +# define is_constant(x) false +#endif + +/* + * If we can guarantee that a particular expression is constant, use it, + * otherwise use a different version. + */ +#if defined(__GNUC__) && (__GNUC__ >= 3) +# define not_pedantic_start \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") +# define not_pedantic_end \ + _Pragma("GCC diagnostic pop") +#else +# define not_pedantic_start +# define not_pedantic_end +#endif + +#ifdef HAVE___BUILTIN_CHOOSE_EXPR +# define if_constant(x,y) __builtin_choose_expr(is_constant(x),(x),(y)) +#else +# define if_constant(x,y) (y) +#endif + +/* + * The autoconf documentation states: + * + * `va_copy' + * The C99 standard provides `va_copy' for copying `va_list' + * variables. It may be available in older environments too, though + * possibly as `__va_copy' (e.g., `gcc' in strict pre-C99 mode). + * These can be tested with `#ifdef'. A fallback to `memcpy (&dst, + * &src, sizeof (va_list))' gives maximum portability. + */ +#ifndef va_copy +# ifdef __va_copy +# define va_copy(dst,src) __va_copy(dst,src) +# else +# define va_copy(dst,src) memcpy(&(dst),&(src),sizeof(va_list)) +# endif +#endif + +/* + * If SIZE_MAX is not defined, rely on size_t being unsigned + */ +#ifndef SIZE_MAX +# define SIZE_MAX (((size_t)0) - 1) +#endif + +/* Watcom doesn't handle switch statements with 64-bit types, hack around it */ +#ifdef __WATCOMC__ +# define BOGUS_CASE 0x76543210 + +static inline unsigned int watcom_switch_hack(uint64_t x) +{ + if (x > (uint64_t)UINT_MAX) + return BOGUS_CASE; + else + return (unsigned int)x; +} + +# define switch(x) switch(sizeof(x) > sizeof(unsigned int) \ + ? watcom_switch_hack(x) : (unsigned int)(x)) + +/* This is to make sure BOGUS_CASE doesn't conflict with anything real... */ +# define default case BOGUS_CASE: default +#endif + +#endif /* NASM_COMPILER_H */ diff --git a/vere/ext/nasm/include/dbginfo.h b/vere/ext/nasm/include/dbginfo.h new file mode 100644 index 0000000..8584eda --- /dev/null +++ b/vere/ext/nasm/include/dbginfo.h @@ -0,0 +1,115 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2020 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * dbginfo.h - debugging info structures + */ + +#ifndef NASM_DBGINFO_H +#define NASM_DBGINFO_H + +#include "compiler.h" +#include "srcfile.h" +#include "rbtree.h" + +struct debug_macro_def; /* Definition */ +struct debug_macro_inv; /* Invocation */ +struct debug_macro_addr; /* Address range */ + +/* + * Definitions structure, one for each non-.nolist macro invoked + * anywhere in the program; unique for each macro, even if a macro is + * redefined and/or overloaded. + */ +struct debug_macro_def { + struct debug_macro_def *next; /* List of definitions */ + const char *name; /* Macro name */ + struct src_location where; /* Start of definition */ + size_t ninv; /* Call count */ +}; + +/* + * Invocation structure. One for each invocation of a non-.nolist macro. + */ +struct debug_macro_inv_list { + struct debug_macro_inv *l; + size_t n; +}; + +struct debug_macro_inv { + struct debug_macro_inv *next; /* List of same-level invocations */ + struct debug_macro_inv_list down; + struct debug_macro_inv *up; /* Parent invocation */ + struct debug_macro_def *def; /* Macro definition */ + struct src_location where; /* Start of invocation */ + struct { /* Address range pointers */ + struct rbtree *tree; /* rbtree of address ranges */ + struct debug_macro_addr *last; /* Quick lookup for latest section */ + } addr; + uint32_t naddr; /* Number of address ranges */ + int32_t lastseg; /* lastaddr segment number */ +}; + +/* + * Address range structure. An rbtree containing one address range for each + * section which this particular macro has generated code/data/space into. + */ +struct debug_macro_addr { + struct rbtree tree; /* rbtree; key = index, must be first */ + struct debug_macro_addr *up; /* same section in parent invocation */ + uint64_t start; /* starting offset */ + uint64_t len; /* length of range */ +}; + +/* + * Complete information structure */ +struct debug_macro_info { + struct debug_macro_inv_list inv; + struct debug_macro_def_list { + struct debug_macro_def *l; + size_t n; + } def; +}; + +static inline int32_t debug_macro_seg(const struct debug_macro_addr *dma) +{ + return dma->tree.key; +} + +/* Get/create a addr structure for the macro we are emitting for */ +struct debug_macro_addr *debug_macro_get_addr(int32_t seg); + +/* The macro we are currently emitting for, if any */ +extern struct debug_macro_inv *debug_current_macro; + +#endif /* NASM_DBGINFO_H */ diff --git a/vere/ext/nasm/include/disp8.h b/vere/ext/nasm/include/disp8.h new file mode 100644 index 0000000..fc18e4f --- /dev/null +++ b/vere/ext/nasm/include/disp8.h @@ -0,0 +1,45 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2013 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * disp8.h header file for disp8.c + */ + +#ifndef NASM_DISP8_H +#define NASM_DISP8_H + +#include "nasm.h" + +uint8_t get_disp8N(insn *ins); +bool is_disp8n(operand *input, insn *ins, int8_t *compdisp); +#endif /* NASM_DISP8_H */ diff --git a/vere/ext/nasm/include/error.h b/vere/ext/nasm/include/error.h new file mode 100644 index 0000000..e6338c9 --- /dev/null +++ b/vere/ext/nasm/include/error.h @@ -0,0 +1,162 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2020 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * Error reporting functions for the assembler + */ + +#ifndef NASM_ERROR_H +#define NASM_ERROR_H 1 + +#include "compiler.h" + +/* + * File pointer for error messages + */ +extern FILE *error_file; /* Error file descriptor */ + +/* + * Typedef for the severity field + */ +typedef uint32_t errflags; + +/* + * An error reporting function should look like this. + */ +void printf_func(2, 3) nasm_error(errflags severity, const char *fmt, ...); +void printf_func(1, 2) nasm_listmsg(const char *fmt, ...); +void printf_func(2, 3) nasm_listmsgf(errflags flags, const char *fmt, ...); +void printf_func(1, 2) nasm_debug(const char *fmt, ...); +void printf_func(2, 3) nasm_debugf(errflags flags, const char *fmt, ...); +void printf_func(1, 2) nasm_info(const char *fmt, ...); +void printf_func(2, 3) nasm_infof(errflags flags, const char *fmt, ...); +void printf_func(2, 3) nasm_warn(errflags flags, const char *fmt, ...); +void printf_func(1, 2) nasm_nonfatal(const char *fmt, ...); +void printf_func(2, 3) nasm_nonfatalf(errflags flags, const char *fmt, ...); +fatal_func printf_func(1, 2) nasm_fatal(const char *fmt, ...); +fatal_func printf_func(2, 3) nasm_fatalf(errflags flags, const char *fmt, ...); +fatal_func printf_func(1, 2) nasm_critical(const char *fmt, ...); +fatal_func printf_func(2, 3) nasm_criticalf(errflags flags, const char *fmt, ...); +fatal_func printf_func(1, 2) nasm_panic(const char *fmt, ...); +fatal_func printf_func(2, 3) nasm_panicf(errflags flags, const char *fmt, ...); +fatal_func nasm_panic_from_macro(const char *file, int line); +#define panic() nasm_panic_from_macro(__FILE__, __LINE__); + +void vprintf_func(2) nasm_verror(errflags severity, const char *fmt, va_list ap); +fatal_func vprintf_func(2) nasm_verror_critical(errflags severity, const char *fmt, va_list ap); + +/* + * These are the error severity codes which get passed as the first + * argument to an efunc. + */ +#define ERR_LISTMSG 0x00000000 /* for the listing file only */ +#define ERR_DEBUG 0x00000001 /* debugging message */ +#define ERR_INFO 0x00000002 /* information for the list file */ +#define ERR_WARNING 0x00000003 /* warn only: no further action */ +#define ERR_NONFATAL 0x00000004 /* terminate assembly after phase */ +#define ERR_FATAL 0x00000005 /* instantly fatal: exit with error */ +#define ERR_CRITICAL 0x00000006 /* fatal, but minimize code before exit */ +#define ERR_PANIC 0x00000007 /* internal error: panic instantly + * and dump core for reference */ +#define ERR_MASK 0x00000007 /* mask off the above codes */ +#define ERR_UNDEAD 0x00000008 /* skip if we already have errors */ +#define ERR_NOFILE 0x00000010 /* don't give source file name/line */ +#define ERR_HERE 0x00000020 /* point to a specific source location */ +#define ERR_USAGE 0x00000040 /* print a usage message */ +#define ERR_PASS2 0x00000100 /* ignore unless on pass_final */ + +#define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */ +#define ERR_PP_PRECOND 0x00000400 /* for preprocessor use */ +#define ERR_PP_LISTMACRO 0x00000800 /* from pp_error_list_macros() */ +#define ERR_HOLD 0x00001000 /* this error/warning can be held */ + +/* + * These codes define specific types of suppressible warning. + * They are assumed to occupy the most significant bits of the + * severity code. + */ +#define WARN_SHR 16 /* how far to shift right */ +#define WARN_IDX(x) (((errflags)(x)) >> WARN_SHR) +#define WARN_MASK ((~(errflags)0) << WARN_SHR) + +/* This is a bitmask */ +#define WARN_ST_ENABLED 1 /* Warning is currently enabled */ +#define WARN_ST_ERROR 2 /* Treat this warning as an error */ + +/* Possible initial state for warnings */ +#define WARN_INIT_OFF 0 +#define WARN_INIT_ON WARN_ST_ENABLED +#define WARN_INIT_ERR (WARN_ST_ENABLED|WARN_ST_ERROR) + +/* Process a warning option or directive */ +bool set_warning_status(const char *value); + +/* Warning stack management */ +void push_warnings(void); +void pop_warnings(void); +void init_warnings(void); +void reset_warnings(void); + +/* + * Tentative error hold for warnings/errors indicated with ERR_HOLD. + * + * This is a stack; the "hold" argument *must* + * match the value returned from nasm_error_hold_push(). + * If "issue" is true the errors are committed (or promoted to the next + * higher stack level), if false then they are discarded. + * + * Errors stronger than ERR_NONFATAL cannot be held. + */ +struct nasm_errhold; +typedef struct nasm_errhold *errhold; +errhold nasm_error_hold_push(void); +void nasm_error_hold_pop(errhold hold, bool issue); + +/* Should be included from within error.h only */ +#include "warnings.h" + +/* By defining MAX_DEBUG, we can compile out messages entirely */ +#ifndef MAX_DEBUG +# define MAX_DEBUG (~0U) +#endif + +/* Debug level checks */ +static inline bool debug_level(unsigned int level) +{ + extern unsigned int debug_nasm; + if (is_constant(level) && level > MAX_DEBUG) + return false; + return unlikely(level <= debug_nasm); +} + +#endif /* NASM_ERROR_H */ diff --git a/vere/ext/nasm/include/hashtbl.h b/vere/ext/nasm/include/hashtbl.h new file mode 100644 index 0000000..9ea94dc --- /dev/null +++ b/vere/ext/nasm/include/hashtbl.h @@ -0,0 +1,108 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2018 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * hashtbl.h + * + * Efficient dictionary hash table class. + */ + +#ifndef NASM_HASHTBL_H +#define NASM_HASHTBL_H + +#include "nasmlib.h" + +struct hash_node { + uint64_t hash; + const void *key; + size_t keylen; + void *data; +}; + +struct hash_table { + struct hash_node *table; + size_t load; + size_t size; + size_t max_load; +}; + +struct hash_insert { + struct hash_table *head; + struct hash_node *where; + struct hash_node node; +}; + +struct hash_iterator { + const struct hash_table *head; + const struct hash_node *next; +}; + +uint64_t crc64(uint64_t crc, const char *string); +uint64_t crc64i(uint64_t crc, const char *string); +uint64_t crc64b(uint64_t crc, const void *data, size_t len); +uint64_t crc64ib(uint64_t crc, const void *data, size_t len); +#define CRC64_INIT UINT64_C(0xffffffffffffffff) + +static inline uint64_t crc64_byte(uint64_t crc, uint8_t v) +{ + extern const uint64_t crc64_tab[256]; + return crc64_tab[(uint8_t)(v ^ crc)] ^ (crc >> 8); +} + +uint32_t crc32b(uint32_t crc, const void *data, size_t len); + +void **hash_find(struct hash_table *head, const char *string, + struct hash_insert *insert); +void **hash_findb(struct hash_table *head, const void *key, size_t keylen, + struct hash_insert *insert); +void **hash_findi(struct hash_table *head, const char *string, + struct hash_insert *insert); +void **hash_findib(struct hash_table *head, const void *key, size_t keylen, + struct hash_insert *insert); +void **hash_add(struct hash_insert *insert, const void *key, void *data); +static inline void hash_iterator_init(const struct hash_table *head, + struct hash_iterator *iterator) +{ + iterator->head = head; + iterator->next = head->table; +} +const struct hash_node *hash_iterate(struct hash_iterator *iterator); + +#define hash_for_each(_head,_it,_np) \ + for (hash_iterator_init((_head), &(_it)), (_np) = hash_iterate(&(_it)) ; \ + (_np) ; (_np) = hash_iterate(&(_it))) + +void hash_free(struct hash_table *head); +void hash_free_all(struct hash_table *head, bool free_keys); + +#endif /* NASM_HASHTBL_H */ diff --git a/vere/ext/nasm/include/iflag.h b/vere/ext/nasm/include/iflag.h new file mode 100644 index 0000000..31a0a98 --- /dev/null +++ b/vere/ext/nasm/include/iflag.h @@ -0,0 +1,134 @@ +#ifndef NASM_IFLAG_H +#define NASM_IFLAG_H + +#include "compiler.h" +#include "ilog2.h" + + +#include "iflaggen.h" + +#define IF_GENBIT(bit) (UINT32_C(1) << ((bit) & 31)) + +static inline int ifcomp(uint32_t a, uint32_t b) +{ + return (a > b) - (a < b); +} + +static inline bool iflag_test(const iflag_t *f, unsigned int bit) +{ + return !!(f->field[bit >> 5] & IF_GENBIT(bit)); +} + +static inline void iflag_set(iflag_t *f, unsigned int bit) +{ + f->field[bit >> 5] |= IF_GENBIT(bit); +} + +static inline void iflag_clear(iflag_t *f, unsigned int bit) +{ + f->field[bit >> 5] &= ~IF_GENBIT(bit); +} + +static inline void iflag_clear_all(iflag_t *f) +{ + memset(f, 0, sizeof(*f)); +} + +static inline void iflag_set_all(iflag_t *f) +{ + memset(f, ~0, sizeof(*f)); +} + +#define iflag_for_each_field(v) for ((v) = 0; (v) < IF_FIELD_COUNT; (v)++) + +static inline int iflag_cmp(const iflag_t *a, const iflag_t *b) +{ + int i; + + /* This is intentionally a reverse loop! */ + for (i = IF_FIELD_COUNT-1; i >= 0; i--) { + if (a->field[i] == b->field[i]) + continue; + + return ifcomp(a->field[i], b->field[i]); + } + + return 0; +} + +#define IF_GEN_HELPER(name, op) \ + static inline iflag_t iflag_##name(const iflag_t *a, const iflag_t *b) \ + { \ + unsigned int i; \ + iflag_t res; \ + \ + iflag_for_each_field(i) \ + res.field[i] = a->field[i] op b->field[i]; \ + \ + return res; \ + } + +IF_GEN_HELPER(xor, ^) + +/* Some helpers which are to work with predefined masks */ +#define IF_SMASK (IFM_SB|IFM_SW|IFM_SD|IFM_SQ|IFM_SO|IFM_SY|IFM_SZ|IFM_SIZE|IFM_ANYSIZE) +#define IF_ARMASK (IFM_AR0|IFM_AR1|IFM_AR2|IFM_AR3|IFM_AR4) + +#define _itemp_smask(idx) (insns_flags[(idx)].field[0] & IF_SMASK) +#define _itemp_armask(idx) (insns_flags[(idx)].field[0] & IF_ARMASK) +#define _itemp_arg(idx) ((_itemp_armask(idx) >> IF_AR0) - 1) + +#define itemp_smask(itemp) _itemp_smask((itemp)->iflag_idx) +#define itemp_arg(itemp) _itemp_arg((itemp)->iflag_idx) +#define itemp_armask(itemp) _itemp_armask((itemp)->iflag_idx) + +/* + * IF_ANY is the highest CPU level by definition + */ +#define IF_CPU_LEVEL_MASK ((IFM_ANY << 1) - 1) + +static inline int iflag_cmp_cpu(const iflag_t *a, const iflag_t *b) +{ + return ifcomp(a->field[IF_CPU_FIELD], b->field[IF_CPU_FIELD]); +} + +static inline uint32_t _iflag_cpu_level(const iflag_t *a) +{ + return a->field[IF_CPU_FIELD] & IF_CPU_LEVEL_MASK; +} + +static inline int iflag_cmp_cpu_level(const iflag_t *a, const iflag_t *b) +{ + return ifcomp(_iflag_cpu_level(a), _iflag_cpu_level(b)); +} + +/* Returns true if the CPU level is at least a certain value */ +static inline bool iflag_cpu_level_ok(const iflag_t *a, unsigned int bit) +{ + return _iflag_cpu_level(a) >= IF_GENBIT(bit); +} + +static inline void iflag_set_all_features(iflag_t *a) +{ + uint32_t *p = &a->field[IF_FEATURE_FIELD]; + + memset(p, -1, IF_FEATURE_NFIELDS * sizeof(uint32_t)); +} + +static inline iflag_t _iflag_pfmask(const iflag_t *a) +{ + iflag_t r; + + iflag_clear_all(&r); + + if (iflag_test(a, IF_CYRIX)) + iflag_set(&r, IF_CYRIX); + if (iflag_test(a, IF_AMD)) + iflag_set(&r, IF_AMD); + + return r; +} + +#define iflag_pfmask(itemp) _iflag_pfmask(&insns_flags[(itemp)->iflag_idx]) + +#endif /* NASM_IFLAG_H */ diff --git a/vere/ext/nasm/include/ilog2.h b/vere/ext/nasm/include/ilog2.h new file mode 100644 index 0000000..bba4595 --- /dev/null +++ b/vere/ext/nasm/include/ilog2.h @@ -0,0 +1,201 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2017 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +#ifndef ILOG2_H +#define ILOG2_H + +#include "compiler.h" + +#ifdef ILOG2_C /* For generating the out-of-line functions */ +# undef extern_inline +# define extern_inline +# define inline_prototypes +#endif + +#ifdef inline_prototypes +extern unsigned int const_func ilog2_32(uint32_t v); +extern unsigned int const_func ilog2_64(uint64_t v); +extern unsigned int const_func ilog2_64(uint64_t vv); +extern int const_func alignlog2_32(uint32_t v); +extern int const_func alignlog2_64(uint64_t v); +#endif + +#ifdef extern_inline + +#define ROUND(v, a, w) \ + do { \ + if (v & (((UINT32_C(1) << w) - 1) << w)) { \ + a += w; \ + v >>= w; \ + } \ + } while (0) + + +#if defined(HAVE___BUILTIN_CLZ) && INT_MAX == 2147483647 + +extern_inline unsigned int const_func ilog2_32(uint32_t v) +{ + if (!v) + return 0; + + return __builtin_clz(v) ^ 31; +} + +#elif defined(__GNUC__) && defined(__x86_64__) + +extern_inline unsigned int const_func ilog2_32(uint32_t v) +{ + unsigned int n; + + __asm__("bsrl %1,%0" + : "=r" (n) + : "rm" (v), "0" (0)); + return n; +} + +#elif defined(__GNUC__) && defined(__i386__) + +extern_inline unsigned int const_func ilog2_32(uint32_t v) +{ + unsigned int n; + +#ifdef __i686__ + __asm__("bsrl %1,%0 ; cmovz %2,%0\n" + : "=&r" (n) + : "rm" (v), "r" (0)); +#else + __asm__("bsrl %1,%0 ; jnz 1f ; xorl %0,%0\n" + "1:" + : "=&r" (n) + : "rm" (v)); +#endif + return n; +} + +#elif defined(HAVE__BITSCANREVERSE) + +extern_inline unsigned int const_func ilog2_32(uint32_t v) +{ + unsigned long ix; + return _BitScanReverse(&ix, v) ? v : 0; +} + +#else + +extern_inline unsigned int const_func ilog2_32(uint32_t v) +{ + unsigned int p = 0; + + ROUND(v, p, 16); + ROUND(v, p, 8); + ROUND(v, p, 4); + ROUND(v, p, 2); + ROUND(v, p, 1); + + return p; +} + +#endif + +#if defined(HAVE__BUILTIN_CLZLL) && LLONG_MAX == 9223372036854775807LL + +extern_inline unsigned int const_func ilog2_64(uint64_t v) +{ + if (!v) + return 0; + + return __builtin_clzll(v) ^ 63; +} + +#elif defined(__GNUC__) && defined(__x86_64__) + +extern_inline unsigned int const_func ilog2_64(uint64_t v) +{ + uint64_t n; + + __asm__("bsrq %1,%0" + : "=r" (n) + : "rm" (v), "0" (UINT64_C(0))); + return n; +} + +#elif defined(HAVE__BITSCANREVERSE64) + +extern_inline unsigned int const_func ilog2_64(uint64_t v) +{ + unsigned long ix; + return _BitScanReverse64(&ix, v) ? ix : 0; +} + +#else + +extern_inline unsigned int const_func ilog2_64(uint64_t vv) +{ + unsigned int p = 0; + uint32_t v; + + v = vv >> 32; + if (v) + p += 32; + else + v = vv; + + return p + ilog2_32(v); +} + +#endif + +/* + * v == 0 ? 0 : is_power2(x) ? ilog2_X(v) : -1 + */ +extern_inline int const_func alignlog2_32(uint32_t v) +{ + if (unlikely(v & (v-1))) + return -1; /* invalid alignment */ + + return ilog2_32(v); +} + +extern_inline int const_func alignlog2_64(uint64_t v) +{ + if (unlikely(v & (v-1))) + return -1; /* invalid alignment */ + + return ilog2_64(v); +} + +#undef ROUND + +#endif /* extern_inline */ + +#endif /* ILOG2_H */ diff --git a/vere/ext/nasm/include/insns.h b/vere/ext/nasm/include/insns.h new file mode 100644 index 0000000..00de288 --- /dev/null +++ b/vere/ext/nasm/include/insns.h @@ -0,0 +1,132 @@ +/* insns.h header file for insns.c + * + * The Netwide Assembler is copyright (C) 1996 Simon Tatham and + * Julian Hall. All rights reserved. The software is + * redistributable under the license given in the file "LICENSE" + * distributed in the NASM archive. + */ + +#ifndef NASM_INSNS_H +#define NASM_INSNS_H + +#include "nasm.h" +#include "tokens.h" +#include "iflag.h" + +/* if changed, ITEMPLATE_END should be also changed accordingly */ +struct itemplate { + enum opcode opcode; /* the token, passed from "parser.c" */ + int operands; /* number of operands */ + opflags_t opd[MAX_OPERANDS]; /* bit flags for operand types */ + decoflags_t deco[MAX_OPERANDS]; /* bit flags for operand decorators */ + const uint8_t *code; /* the code it assembles to */ + uint32_t iflag_idx; /* some flags referenced by index */ +}; + +/* Use this helper to test instruction template flags */ +static inline bool itemp_has(const struct itemplate *itemp, unsigned int bit) +{ + return iflag_test(&insns_flags[itemp->iflag_idx], bit); +} + +/* Disassembler table structure */ + +/* + * If n == -1, then p points to another table of 256 + * struct disasm_index, otherwise p points to a list of n + * struct itemplates to consider. + */ +struct disasm_index { + const void *p; + int n; +}; + +/* Tables for the assembler and disassembler, respectively */ +extern const struct itemplate * const nasm_instructions[]; +extern const struct disasm_index itable[256]; +extern const struct disasm_index * const itable_vex[NASM_VEX_CLASSES][32][4]; + +/* Common table for the byte codes */ +extern const uint8_t nasm_bytecodes[]; + +/* + * this define is used to signify the end of an itemplate + */ +#define ITEMPLATE_END {I_none,0,{0,},{0,},NULL,0} + +/* + * Pseudo-op tests + */ +/* DB-type instruction (DB, DW, ...) */ +static inline bool const_func opcode_is_db(enum opcode opcode) +{ + return opcode >= I_DB && opcode < I_RESB; +} + +/* RESB-type instruction (RESB, RESW, ...) */ +static inline bool const_func opcode_is_resb(enum opcode opcode) +{ + return opcode >= I_RESB && opcode < I_INCBIN; +} + +/* Width of Dx and RESx instructions */ + +/* + * initialized data bytes length from opcode + */ +static inline int const_func db_bytes(enum opcode opcode) +{ + switch (opcode) { + case I_DB: + return 1; + case I_DW: + return 2; + case I_DD: + return 4; + case I_DQ: + return 8; + case I_DT: + return 10; + case I_DO: + return 16; + case I_DY: + return 32; + case I_DZ: + return 64; + case I_none: + return -1; + default: + return 0; + } +} + +/* + * Uninitialized data bytes length from opcode + */ +static inline int const_func resb_bytes(enum opcode opcode) +{ + switch (opcode) { + case I_RESB: + return 1; + case I_RESW: + return 2; + case I_RESD: + return 4; + case I_RESQ: + return 8; + case I_REST: + return 10; + case I_RESO: + return 16; + case I_RESY: + return 32; + case I_RESZ: + return 64; + case I_none: + return -1; + default: + return 0; + } +} + +#endif /* NASM_INSNS_H */ diff --git a/vere/ext/nasm/include/labels.h b/vere/ext/nasm/include/labels.h new file mode 100644 index 0000000..a825d1f --- /dev/null +++ b/vere/ext/nasm/include/labels.h @@ -0,0 +1,79 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2018 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * labels.h header file for labels.c + */ + +#ifndef LABELS_H +#define LABELS_H + +#include "compiler.h" + +enum mangle_index { + LM_LPREFIX, /* Local variable prefix */ + LM_LSUFFIX, /* Local variable suffix */ + LM_GPREFIX, /* Global variable prefix */ + LM_GSUFFIX /* GLobal variable suffix */ +}; + +enum label_type { + LBL_none = -1, /* No label */ + LBL_LOCAL = 0, /* Must be zero */ + LBL_STATIC, + LBL_GLOBAL, + LBL_EXTERN, + LBL_REQUIRED, /* Like extern but emit even if unused */ + LBL_COMMON, + LBL_SPECIAL, /* Magic symbols like ..start */ + LBL_BACKEND /* Backend-defined symbols like ..got */ +}; + +enum label_type lookup_label(const char *label, int32_t *segment, int64_t *offset); +static inline bool is_extern(enum label_type type) +{ + return type == LBL_EXTERN || type == LBL_REQUIRED; +} +void define_label(const char *label, int32_t segment, int64_t offset, + bool normal); +void backend_label(const char *label, int32_t segment, int64_t offset); +bool declare_label(const char *label, enum label_type type, + const char *special); +void set_label_mangle(enum mangle_index which, const char *what); +int init_labels(void); +void cleanup_labels(void); +const char *local_scope(const char *label); + +extern uint64_t global_offset_changed; + +#endif /* LABELS_H */ diff --git a/vere/ext/nasm/include/md5.h b/vere/ext/nasm/include/md5.h new file mode 100644 index 0000000..cb77910 --- /dev/null +++ b/vere/ext/nasm/include/md5.h @@ -0,0 +1,21 @@ +#ifndef MD5_H +#define MD5_H + +#include "compiler.h" + +#define MD5_HASHBYTES 16 + +typedef struct MD5Context { + uint32_t buf[4]; + uint32_t bits[2]; + unsigned char in[64]; +} MD5_CTX; + +extern void MD5Init(MD5_CTX *context); +extern void MD5Update(MD5_CTX *context, unsigned char const *buf, + unsigned len); +extern void MD5Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context); +extern void MD5Transform(uint32_t buf[4], uint32_t const in[16]); +extern char * MD5End(MD5_CTX *, char *); + +#endif /* !MD5_H */ diff --git a/vere/ext/nasm/include/nasm.h b/vere/ext/nasm/include/nasm.h new file mode 100644 index 0000000..8b017f3 --- /dev/null +++ b/vere/ext/nasm/include/nasm.h @@ -0,0 +1,1461 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2022 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * nasm.h main header file for the Netwide Assembler: inter-module interface + */ + +#ifndef NASM_NASM_H +#define NASM_NASM_H + +#include "compiler.h" + +#include <time.h> + +#include "nasmlib.h" +#include "nctype.h" +#include "strlist.h" +#include "preproc.h" +#include "insnsi.h" /* For enum opcode */ +#include "directiv.h" /* For enum directive */ +#include "labels.h" /* For enum mangle_index, enum label_type */ +#include "opflags.h" +#include "regs.h" +#include "srcfile.h" +#include "error.h" + +/* Program name for error messages etc. */ +extern const char *_progname; + +/* Time stamp for the official start of compilation */ +struct compile_time { + time_t t; + bool have_local, have_gm, have_posix; + int64_t posix; + struct tm local; + struct tm gm; +}; +extern struct compile_time official_compile_time; + +/* POSIX timestamp if and only if we are not a reproducible build */ +extern bool reproducible; +static inline int64_t posix_timestamp(void) +{ + return reproducible ? 0 : official_compile_time.posix; +} + +#define NO_SEG INT32_C(-1) /* null segment value */ +#define SEG_ABS 0x40000000L /* mask for far-absolute segments */ + +#define IDLEN_MAX 4096 +#define DECOLEN_MAX 32 + +/* + * Name pollution problems: <time.h> on Digital UNIX pulls in some + * strange hardware header file which sees fit to define R_SP. We + * undefine it here so as not to break the enum below. + */ +#ifdef R_SP +#undef R_SP +#endif + +/* + * We must declare the existence of this structure type up here, + * since we have to reference it before we define it... + */ +struct ofmt; + +/* + * Values for the `type' parameter to an output function. + */ +enum out_type { + OUT_RAWDATA, /* Plain bytes */ + OUT_RESERVE, /* Reserved bytes (RESB et al) */ + OUT_ZERODATA, /* Initialized data, but all zero */ + OUT_ADDRESS, /* An address (symbol value) */ + OUT_RELADDR, /* A relative address */ + OUT_SEGMENT, /* A segment number */ + + /* + * These values are used by the legacy backend interface only; + * see output/legacy.c for more information. These should never + * be used otherwise. Once all backends have been migrated to the + * new interface they should be removed. + */ + OUT_REL1ADR, + OUT_REL2ADR, + OUT_REL4ADR, + OUT_REL8ADR +}; + +enum out_flags { + OUT_WRAP = 0, /* Undefined signedness (wraps) */ + OUT_SIGNED = 1, /* Value is signed */ + OUT_UNSIGNED = 2, /* Value is unsigned */ + OUT_SIGNMASK = 3 /* Mask for signedness bits */ +}; + +/* + * The data we send down to the backend. + * XXX: We still want to push down the base address symbol if + * available, and replace the segment numbers with a structure. + */ +struct out_data { + int64_t offset; /* Offset within segment */ + int32_t segment; /* Segment written to */ + enum out_type type; /* See above */ + enum out_flags flags; /* See above */ + int inslen; /* Length of instruction */ + int insoffs; /* Offset inside instruction */ + int bits; /* Bits mode of compilation */ + uint64_t size; /* Size of output */ + const struct itemplate *itemp; /* Instruction template */ + const void *data; /* Data for OUT_RAWDATA */ + uint64_t toffset; /* Target address offset for relocation */ + int32_t tsegment; /* Target segment for relocation */ + int32_t twrt; /* Relocation with respect to */ + int64_t relbase; /* Relative base for OUT_RELADDR */ + struct src_location where; /* Source file and line */ +}; + +/* + * And a label-definition function. The boolean parameter + * `is_norm' states whether the label is a `normal' label (which + * should affect the local-label system), or something odder like + * an EQU or a segment-base symbol, which shouldn't. + */ +typedef void (*ldfunc)(char *label, int32_t segment, int64_t offset, + char *special, bool is_norm); + +/* + * Token types returned by the scanner, in addition to ordinary + * ASCII character values, and zero for end-of-string. + */ +enum token_type { /* token types, other than chars */ + + /* Token values shared between assembler and preprocessor */ + + /* Special codes */ + TOKEN_INVALID = -1, /* a placeholder value */ + TOKEN_BLOCK = -2, /* used for storage management */ + TOKEN_FREE = -3, /* free token marker, use to catch leaks */ + TOKEN_EOS = 0, /* end of string */ + + /* + * Single-character operators. Enumerated here to keep strict + * compilers happy, and for documentation. + */ + TOKEN_WHITESPACE = ' ', /* Preprocessor use */ + TOKEN_BOOL_NOT = '!', + TOKEN_AND = '&', + TOKEN_OR = '|', + TOKEN_XOR = '^', + TOKEN_NOT = '~', + TOKEN_MULT = '*', + TOKEN_DIV = '/', + TOKEN_MOD = '%', + TOKEN_LPAR = '(', + TOKEN_RPAR = ')', + TOKEN_PLUS = '+', + TOKEN_MINUS = '-', + TOKEN_COMMA = ',', + TOKEN_LBRACE = '{', + TOKEN_RBRACE = '}', + TOKEN_LBRACKET = '[', + TOKEN_RBRACKET = ']', + TOKEN_QMARK = '?', + TOKEN_EQ = '=', /* = or == */ + TOKEN_GT = '>', + TOKEN_LT = '<', + + /* Multi-character operators */ + TOKEN_SHL = 256, /* << or <<< */ + TOKEN_SHR, /* >> */ + TOKEN_SAR, /* >>> */ + TOKEN_SDIV, /* // */ + TOKEN_SMOD, /* %% */ + TOKEN_GE, /* >= */ + TOKEN_LE, /* <= */ + TOKEN_NE, /* <> (!= is same as <>) */ + TOKEN_LEG, /* <=> */ + TOKEN_DBL_AND, /* && */ + TOKEN_DBL_OR, /* || */ + TOKEN_DBL_XOR, /* ^^ */ + + TOKEN_MAX_OPERATOR, + + TOKEN_NUM, /* numeric constant */ + TOKEN_ERRNUM, /* malformed numeric constant */ + TOKEN_STR, /* string constant */ + TOKEN_ERRSTR, /* unterminated string constant */ + TOKEN_ID, /* identifier */ + TOKEN_FLOAT, /* floating-point constant */ + TOKEN_HERE, /* $, not '$' because it is not an operator */ + TOKEN_BASE, /* $$ */ + + /* Token values only used by the assembler */ + TOKEN_START_ASM, + + TOKEN_SEG, /* SEG */ + TOKEN_WRT, /* WRT */ + TOKEN_FLOATIZE, /* __?floatX?__ */ + TOKEN_STRFUNC, /* __utf16*__, __utf32*__ */ + TOKEN_IFUNC, /* __ilog2*__ */ + TOKEN_DECORATOR, /* decorators such as {...} */ + TOKEN_MASM_PTR, /* __?masm_ptr?__ for the masm package */ + TOKEN_MASM_FLAT, /* __?masm_flat?__ for the masm package */ + TOKEN_OPMASK, /* translated token for opmask registers */ + TOKEN_SIZE, /* BYTE, WORD, DWORD, QWORD, etc */ + TOKEN_SPECIAL, /* REL, FAR, NEAR, STRICT, NOSPLIT, etc */ + TOKEN_PREFIX, /* A32, O16, LOCK, REPNZ, TIMES, etc */ + TOKEN_REG, /* register name */ + TOKEN_INSN, /* instruction name */ + + TOKEN_END_ASM, + + /* Token values only used by the preprocessor */ + + TOKEN_START_PP = TOKEN_END_ASM, + + TOKEN_OTHER, /* % sequence without (current) meaning */ + TOKEN_PREPROC_ID, /* Preprocessor ID, e.g. %symbol */ + TOKEN_MMACRO_PARAM, /* MMacro parameter, e.g. %1 */ + TOKEN_LOCAL_SYMBOL, /* Local symbol, e.g. %%symbol */ + TOKEN_LOCAL_MACRO, /* Context-local macro, e.g. %$symbol */ + TOKEN_ENVIRON, /* %! */ + TOKEN_INTERNAL_STR, /* Unquoted string that should remain so */ + TOKEN_NAKED_STR, /* Unquoted string that can be re-quoted */ + TOKEN_PREPROC_Q, /* %? */ + TOKEN_PREPROC_QQ, /* %?? */ + TOKEN_PREPROC_SQ, /* %*? */ + TOKEN_PREPROC_SQQ, /* %*?? */ + TOKEN_PASTE, /* %+ */ + TOKEN_COND_COMMA, /* %, */ + TOKEN_INDIRECT, /* %[...] */ + TOKEN_XDEF_PARAM, /* Used during %xdefine processing */ + /* smacro parameters starting here; an arbitrary number. */ + TOKEN_SMAC_START_PARAMS, /* MUST BE LAST IN THE LIST!!! */ + TOKEN_MAX = INT_MAX /* Keep compiler from reducing the range */ +}; + +/* Must match the fp_formats[] array in asm/floats.c */ +enum floatize { + FLOAT_8, + FLOAT_16, + FLOAT_B16, + FLOAT_32, + FLOAT_64, + FLOAT_80M, + FLOAT_80E, + FLOAT_128L, + FLOAT_128H, + FLOAT_ERR /* Invalid format, MUST BE LAST */ +}; + +/* Must match the list in string_transform(), in strfunc.c */ +enum strfunc { + STRFUNC_UTF16, + STRFUNC_UTF16LE, + STRFUNC_UTF16BE, + STRFUNC_UTF32, + STRFUNC_UTF32LE, + STRFUNC_UTF32BE +}; + +enum ifunc { + IFUNC_ILOG2E, + IFUNC_ILOG2W, + IFUNC_ILOG2F, + IFUNC_ILOG2C +}; + +size_t string_transform(char *, size_t, char **, enum strfunc); + +/* + * The expression evaluator must be passed a scanner function; a + * standard scanner is provided as part of nasmlib.c. The + * preprocessor will use a different one. Scanners, and the + * token-value structures they return, look like this. + * + * The return value from the scanner is always a copy of the + * `t_type' field in the structure. + */ +struct tokenval { + char *t_charptr; + int64_t t_integer; + int64_t t_inttwo; + enum token_type t_type; + int8_t t_flag; +}; +typedef int (*scanner)(void *private_data, struct tokenval *tv); + +struct location { + int64_t offset; + int32_t segment; + int known; +}; +extern struct location location; + +/* + * Expression-evaluator datatype. Expressions, within the + * evaluator, are stored as an array of these beasts, terminated by + * a record with type==0. Mostly, it's a vector type: each type + * denotes some kind of a component, and the value denotes the + * multiple of that component present in the expression. The + * exception is the WRT type, whose `value' field denotes the + * segment to which the expression is relative. These segments will + * be segment-base types, i.e. either odd segment values or SEG_ABS + * types. So it is still valid to assume that anything with a + * `value' field of zero is insignificant. + */ +typedef struct { + int32_t type; /* a register, or EXPR_xxx */ + int64_t value; /* must be >= 32 bits */ +} expr; + +/* + * Library routines to manipulate expression data types. + */ +bool is_reloc(const expr *vect); +bool is_simple(const expr *vect); +bool is_really_simple(const expr *vect); +bool is_unknown(const expr *vect); +bool is_just_unknown(const expr *vect); +int64_t reloc_value(const expr *vect); +int32_t reloc_seg(const expr *vect); +int32_t reloc_wrt(const expr *vect); +bool is_self_relative(const expr *vect); +void dump_expr(const expr *vect); + +/* + * 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. + */ +struct eval_hints { + int64_t base; + int type; +}; + +/* + * The actual expression evaluator function looks like this. When + * called, it expects the first token of its expression to already + * be in `*tv'; if it is not, set tv->t_type to TOKEN_INVALID and + * it will start by calling the scanner. + * + * If a forward reference happens during evaluation, the evaluator + * must set `*fwref' to true if `fwref' is non-NULL. + * + * `critical' is non-zero if the expression may not contain forward + * references. The evaluator will report its own error if this + * occurs; if `critical' is 1, the error will be "symbol not + * defined before use", whereas if `critical' is 2, the error will + * be "symbol undefined". + * + * If `critical' has bit 8 set (in addition to its main value: 0x101 + * and 0x102 correspond to 1 and 2) then an extended expression + * syntax is recognised, in which relational operators such as =, < + * and >= are accepted, as well as low-precedence logical operators + * &&, ^^ and ||. + * + * If `hints' is non-NULL, it gets filled in with some hints as to + * the base register in complex effective addresses. + */ +#define CRITICAL 0x100 +typedef expr *(*evalfunc)(scanner sc, void *scprivate, + struct tokenval *tv, int *fwref, int critical, + struct eval_hints *hints); + +/* + * Special values for expr->type. + * These come after EXPR_REG_END as defined in regs.h. + * Expr types : 0 ~ EXPR_REG_END, EXPR_UNKNOWN, EXPR_...., EXPR_RDSAE, + * EXPR_SEGBASE ~ EXPR_SEGBASE + SEG_ABS, ... + */ +#define EXPR_UNKNOWN (EXPR_REG_END+1) /* forward references */ +#define EXPR_SIMPLE (EXPR_REG_END+2) +#define EXPR_WRT (EXPR_REG_END+3) +#define EXPR_RDSAE (EXPR_REG_END+4) +#define EXPR_SEGBASE (EXPR_REG_END+5) + +/* + * preprocessors ought to look like this: + */ + +enum preproc_mode { + PP_NORMAL, /* Assembly */ + PP_DEPS, /* Dependencies only */ + PP_PREPROC /* Preprocessing only */ +}; + +enum preproc_opt { + PP_TRIVIAL = 1, /* Only %line or # directives */ + PP_NOLINE = 2, /* Ignore %line and # directives */ + PP_TASM = 4 /* TASM compatibility hacks */ +}; + +/* + * Called once at the very start of assembly. + */ +void pp_init(enum preproc_opt opt); + +/* + * Called at the start of a pass; given a file name, the number + * of the pass, an error reporting function, an evaluator + * function, and a listing generator to talk to. + */ +void pp_reset(const char *file, enum preproc_mode mode, + struct strlist *deplist); + +/* + * Called to fetch a line of preprocessed source. The line + * returned has been malloc'ed, and so should be freed after + * use. + */ +char *pp_getline(void); + +/* Called at the end of each pass. */ +void pp_cleanup_pass(void); + +/* + * Called at the end of the assembly session, + * after cleanup_pass() has been called for the + * last pass. + */ +void pp_cleanup_session(void); + +/* Additional macros specific to output format */ +void pp_extra_stdmac(macros_t *macros); + +/* Early definitions and undefinitions for macros */ +void pp_pre_define(char *definition); +void pp_pre_undefine(char *definition); + +/* Include file from command line */ +void pp_pre_include(char *fname); + +/* Add a command from the command line */ +void pp_pre_command(const char *what, char *str); + +/* Include path from command line */ +void pp_include_path(struct strlist *ipath); + +/* Unwind the macro stack when printing an error message */ +void pp_error_list_macros(errflags severity); + +/* Return true if an error message should be suppressed */ +bool pp_suppress_error(errflags severity); + +/* List of dependency files */ +extern struct strlist *depend_list; + +/* TASM mode changes some properties */ +extern bool tasm_compatible_mode; + +/* + * inline function to skip past an identifier; returns the first character past + * the identifier if valid, otherwise NULL. + */ +static inline char *nasm_skip_identifier(const char *str) +{ + const char *p = str; + + if (!nasm_isidstart(*p++)) { + p = NULL; + } else { + while (nasm_isidchar(*p++)) + ; + } + return (char *)p; +} + +/* + * Data-type flags that get passed to listing-file routines. + */ +enum { + LIST_READ, + LIST_MACRO, + LIST_INCLUDE, + LIST_INCBIN, + LIST_TIMES +}; + +/* + * ----------------------------------------------------------- + * Format of the `insn' structure returned from `parser.c' and + * passed into `assemble.c' + * ----------------------------------------------------------- + */ + +/* Verify value to be a valid register */ +static inline bool is_register(int reg) +{ + return reg >= EXPR_REG_START && reg < REG_ENUM_LIMIT; +} + +/* + * token flags + */ +#define TFLAG_BRC (1 << 0) /* valid only with braces. {1to8}, {rd-sae}, ...*/ +#define TFLAG_BRC_OPT (1 << 1) /* may or may not have braces. opmasks {k1} */ +#define TFLAG_BRC_ANY (TFLAG_BRC | TFLAG_BRC_OPT) +#define TFLAG_BRDCAST (1 << 2) /* broadcasting decorator */ +#define TFLAG_WARN (1 << 3) /* warning only, treat as ID */ +#define TFLAG_DUP (1 << 4) /* valid ID but also has context-specific use */ + +/* + * REX flags + */ +#define REX_MASK 0x4f /* Actual REX prefix bits */ +#define REX_B 0x01 /* ModRM r/m extension */ +#define REX_X 0x02 /* SIB index extension */ +#define REX_R 0x04 /* ModRM reg extension */ +#define REX_W 0x08 /* 64-bit operand size */ +#define REX_L 0x20 /* Use LOCK prefix instead of REX.R */ +#define REX_P 0x40 /* REX prefix present/required */ +#define REX_H 0x80 /* High register present, REX forbidden */ +#define REX_V 0x0100 /* Instruction uses VEX/XOP instead of REX */ +#define REX_NH 0x0200 /* Instruction which doesn't use high regs */ +#define REX_EV 0x0400 /* Instruction uses EVEX instead of REX */ + +/* + * EVEX bit field + */ +#define EVEX_P0MM 0x0f /* EVEX P[3:0] : Opcode map */ +#define EVEX_P0RP 0x10 /* EVEX P[4] : High-16 reg */ +#define EVEX_P0X 0x40 /* EVEX P[6] : High-16 rm */ +#define EVEX_P1PP 0x03 /* EVEX P[9:8] : Legacy prefix */ +#define EVEX_P1VVVV 0x78 /* EVEX P[14:11] : NDS register */ +#define EVEX_P1W 0x80 /* EVEX P[15] : Osize extension */ +#define EVEX_P2AAA 0x07 /* EVEX P[18:16] : Embedded opmask */ +#define EVEX_P2VP 0x08 /* EVEX P[19] : High-16 NDS reg */ +#define EVEX_P2B 0x10 /* EVEX P[20] : Broadcast / RC / SAE */ +#define EVEX_P2LL 0x60 /* EVEX P[22:21] : Vector length */ +#define EVEX_P2RC EVEX_P2LL /* EVEX P[22:21] : Rounding control */ +#define EVEX_P2Z 0x80 /* EVEX P[23] : Zeroing/Merging */ + +/* + * REX_V "classes" (prefixes which behave like VEX) + */ +enum vex_class { + RV_VEX = 0, /* C4/C5 */ + RV_XOP = 1, /* 8F */ + RV_EVEX = 2 /* 62 */ +}; + +/* + * Note that because segment registers may be used as instruction + * prefixes, we must ensure the enumerations for prefixes and + * register names do not overlap. + */ +enum prefixes { /* instruction prefixes */ + P_none = 0, + PREFIX_ENUM_START = REG_ENUM_LIMIT, + P_A16 = PREFIX_ENUM_START, + P_A32, + P_A64, + P_ASP, + P_LOCK, + P_O16, + P_O32, + P_O64, + P_OSP, + P_REP, + P_REPE, + P_REPNE, + P_REPNZ, + P_REPZ, + P_TIMES, + P_WAIT, + P_XACQUIRE, + P_XRELEASE, + P_BND, + P_NOBND, + P_REX, + P_EVEX, + P_VEX, + P_VEX3, + P_VEX2, + PREFIX_ENUM_LIMIT +}; + +enum ea_flags { /* special EA flags */ + EAF_BYTEOFFS = 1, /* force offset part to byte size */ + EAF_WORDOFFS = 2, /* force offset part to [d]word size */ + EAF_TIMESTWO = 4, /* really do EAX*2 not EAX+EAX */ + EAF_REL = 8, /* IP-relative addressing */ + EAF_ABS = 16, /* non-IP-relative addressing */ + EAF_FSGS = 32, /* fs/gs segment override present */ + EAF_MIB = 64, /* mib operand */ + EAF_SIB = 128 /* SIB encoding obligatory */ +}; + +enum eval_hint { /* values for `hinttype' */ + EAH_NOHINT = 0, /* no hint at all - our discretion */ + EAH_MAKEBASE = 1, /* try to make given reg the base */ + EAH_NOTBASE = 2, /* try _not_ to make reg the base */ + EAH_SUMMED = 3 /* base and index are summed into index */ +}; + +typedef struct operand { /* operand to an instruction */ + opflags_t type; /* type of operand */ + int disp_size; /* 0 means default; 16; 32; 64 */ + enum reg_enum basereg; + enum reg_enum indexreg; /* address registers */ + int scale; /* index scale */ + int hintbase; + enum eval_hint hinttype; /* hint as to real base register */ + int32_t segment; /* immediate segment, if needed */ + int64_t offset; /* any immediate number */ + int32_t wrt; /* segment base it's relative to */ + int eaflags; /* special EA flags */ + int opflags; /* see OPFLAG_* defines below */ + decoflags_t decoflags; /* decorator flags such as {...} */ +} operand; + +#define OPFLAG_FORWARD 1 /* operand is a forward reference */ +#define OPFLAG_EXTERN 2 /* operand is an external reference */ +#define OPFLAG_UNKNOWN 4 /* operand is an unknown reference + (always a forward reference also) */ +#define OPFLAG_RELATIVE 8 /* operand is self-relative, e.g. [foo - $] + where foo is not in the current segment */ + +enum extop_type { /* extended operand types */ + EOT_NOTHING = 0, + EOT_EXTOP, /* Subexpression */ + EOT_DB_STRING, /* Byte string */ + EOT_DB_FLOAT, /* Floating-pointer number (special byte string) */ + EOT_DB_STRING_FREE, /* Byte string which should be nasm_free'd*/ + EOT_DB_NUMBER, /* Integer */ + EOT_DB_RESERVE /* ? */ +}; + +typedef struct extop { /* extended operand */ + struct extop *next; /* linked list */ + union { + struct { /* text or byte string */ + char *data; + size_t len; + } string; + struct { /* numeric expression */ + int64_t offset; /* numeric value or address offset */ + int32_t segment; /* address segment */ + int32_t wrt; /* address wrt */ + bool relative; /* self-relative expression */ + } num; + struct extop *subexpr; /* actual expressions */ + } val; + size_t dup; /* duplicated? */ + enum extop_type type; /* defined above */ + int elem; /* element size override, if any (bytes) */ +} extop; + +enum ea_type { + EA_INVALID, /* Not a valid EA at all */ + EA_SCALAR, /* Scalar EA */ + EA_XMMVSIB, /* XMM vector EA */ + EA_YMMVSIB, /* YMM vector EA */ + EA_ZMMVSIB /* ZMM vector EA */ +}; + +/* + * Prefix positions: each type of prefix goes in a specific slot. + * This affects the final ordering of the assembled output, which + * shouldn't matter to the processor, but if you have stylistic + * preferences, you can change this. REX prefixes are handled + * differently for the time being. + * + * LOCK and REP used to be one slot; this is no longer the case since + * the introduction of HLE. + */ +enum prefix_pos { + PPS_TIMES = -1, /* TIMES (not a slot, handled separately) */ + PPS_WAIT = 0, /* WAIT (technically not a prefix!) */ + PPS_REP, /* REP/HLE prefix */ + PPS_LOCK, /* LOCK prefix */ + PPS_SEG, /* Segment override prefix */ + PPS_OSIZE, /* Operand size prefix */ + PPS_ASIZE, /* Address size prefix */ + PPS_REX, /* REX/VEX type */ + MAXPREFIX /* Total number of prefix slots */ +}; + +/* + * Tuple types that are used when determining Disp8*N eligibility + * The order must match with a hash %tuple_codes in insns.pl + */ +enum ttypes { + FV = 001, + HV = 002, + FVM = 003, + T1S8 = 004, + T1S16 = 005, + T1S = 006, + T1F32 = 007, + T1F64 = 010, + T2 = 011, + T4 = 012, + T8 = 013, + HVM = 014, + QVM = 015, + OVM = 016, + M128 = 017, + DUP = 020 +}; + +/* EVEX.L'L : Vector length on vector insns */ +enum vectlens { + VL128 = 0, + VL256 = 1, + VL512 = 2, + VLMAX = 3 +}; + +/* If you need to change this, also change it in insns.pl */ +#define MAX_OPERANDS 5 + +typedef struct insn { /* an instruction itself */ + char *label; /* the label defined, or NULL */ + int prefixes[MAXPREFIX]; /* instruction prefixes, if any */ + enum opcode opcode; /* the opcode - not just the string */ + int operands; /* how many operands? 0-3 (more if db et al) */ + int addr_size; /* address size */ + operand oprs[MAX_OPERANDS]; /* the operands, defined as above */ + extop *eops; /* extended operands */ + int eops_float; /* true if DD and floating */ + int32_t times; /* repeat count (TIMES prefix) */ + bool forw_ref; /* is there a forward reference? */ + bool rex_done; /* REX prefix emitted? */ + int rex; /* Special REX Prefix */ + int vexreg; /* Register encoded in VEX prefix */ + int vex_cm; /* Class and M field for VEX prefix */ + int vex_wlp; /* W, P and L information for VEX prefix */ + uint8_t evex_p[3]; /* EVEX.P0: [RXB,R',00,mm], P1: [W,vvvv,1,pp] */ + /* EVEX.P2: [z,L'L,b,V',aaa] */ + enum ttypes evex_tuple; /* Tuple type for compressed Disp8*N */ + int evex_rm; /* static rounding mode for AVX512 (EVEX) */ + int8_t evex_brerop; /* BR/ER/SAE operand position */ +} insn; + +/* Instruction flags type: IF_* flags are defined in insns.h */ +typedef uint64_t iflags_t; + +/* + * What to return from a directive- or pragma-handling function. + * Currently DIRR_OK and DIRR_ERROR are treated the same way; + * in both cases the backend is expected to produce the appropriate + * error message on its own. + * + * DIRR_BADPARAM causes a generic error message to be printed. Note + * that it is an error, not a warning, even in the case of pragmas; + * don't use it where forward compatibility would be compromised + * (instead consider adding a DIRR_WARNPARAM.) + */ +enum directive_result { + DIRR_UNKNOWN, /* Directive not handled by backend */ + DIRR_OK, /* Directive processed */ + DIRR_ERROR, /* Directive processed unsuccessfully */ + DIRR_BADPARAM /* Print bad argument error message */ +}; + +/* + * A pragma facility: this structure is used to request passing a + * parsed pragma directive for a specific facility. If the handler is + * NULL then this pragma facility is recognized but ignored; pragma + * processing stops at that point. + * + * Note that the handler is passed a pointer to the facility structure + * as part of the struct pragma. + */ +struct pragma; +typedef enum directive_result (*pragma_handler)(const struct pragma *); + +struct pragma_facility { + const char *name; + pragma_handler handler; +}; + +/* + * This structure defines how a pragma directive is passed to a + * facility. This structure may be augmented in the future. + * + * Any facility MAY, but is not required to, add its operations + * keywords or a subset thereof into asm/directiv.dat, in which case + * the "opcode" field will be set to the corresponding D_ constant + * from directiv.h; otherwise it will be D_unknown. + */ +struct pragma { + const struct pragma_facility *facility; + const char *facility_name; /* Facility name exactly as entered by user */ + const char *opname; /* First word after the facility name */ + const char *tail; /* Anything after the operation */ + enum directive opcode; /* Operation as a D_ directives constant */ +}; + +/* + * These are semi-arbitrary limits to keep the assembler from going + * into a black hole on certain kinds of bugs. They can be overridden + * by command-line options or %pragma. + */ +enum nasm_limit { + LIMIT_PASSES, + LIMIT_STALLED, + LIMIT_MACRO_LEVELS, + LIMIT_MACRO_TOKENS, + LIMIT_MMACROS, + LIMIT_REP, + LIMIT_EVAL, + LIMIT_LINES +}; +#define LIMIT_MAX LIMIT_LINES +extern int64_t nasm_limit[LIMIT_MAX+1]; +extern enum directive_result nasm_set_limit(const char *, const char *); + +/* + * The data structure defining an output format driver, and the + * interfaces to the functions therein. + */ +struct ofmt { + /* + * This is a short (one-liner) description of the type of + * output generated by the driver. + */ + const char *fullname; + + /* + * This is a single keyword used to select the driver. + */ + const char *shortname; + + /* + * Default output filename extension, or a null string + */ + const char *extension; + + /* + * Output format flags. + */ +#define OFMT_TEXT 1 /* Text file format */ +#define OFMT_KEEP_ADDR 2 /* Keep addr; no conversion to data */ + + unsigned int flags; + + int maxbits; /* Maximum segment bits supported */ + + /* + * this is a pointer to the first element of the debug information + */ + const struct dfmt * const *debug_formats; + + /* + * the default debugging format if -F is not specified + */ + const struct dfmt *default_dfmt; + + /* + * This, if non-NULL, is a NULL-terminated list of `char *'s + * pointing to extra standard macros supplied by the object + * format (e.g. a sensible initial default value of __?SECT?__, + * and user-level equivalents for any format-specific + * directives). + */ + macros_t *stdmac; + + /* + * This procedure is called at the start of an output session to set + * up internal parameters. + */ + void (*init)(void); + + /* + * This procedure is called at the start of each pass. + */ + void (*reset)(void); + + /* + * This is the modern output function, which gets passed + * a struct out_data with much more information. See the + * definition of struct out_data. + */ + void (*output)(const struct out_data *data); + + /* + * This procedure is called by assemble() to write actual + * generated code or data to the object file. Typically it + * doesn't have to actually _write_ it, just store it for + * later. + * + * The `type' argument specifies the type of output data, and + * usually the size as well: its contents are described below. + * + * This is used for backends which have not yet been ported to + * the new interface, and should be NULL on ported backends. + * To use this entry point, set the output pointer to + * nasm_do_legacy_output. + */ + void (*legacy_output)(int32_t segto, const void *data, + enum out_type type, uint64_t size, + int32_t segment, int32_t wrt); + + /* + * This procedure is called once for every symbol defined in + * the module being assembled. It gives the name and value of + * the symbol, in NASM's terms, and indicates whether it has + * been declared to be global. Note that the parameter "name", + * when passed, will point to a piece of static storage + * allocated inside the label manager - it's safe to keep using + * that pointer, because the label manager doesn't clean up + * until after the output driver has. + * + * Values of `is_global' are: 0 means the symbol is local; 1 + * means the symbol is global; 2 means the symbol is common (in + * which case `offset' holds the _size_ of the variable). + * Anything else is available for the output driver to use + * internally. + * + * This routine explicitly _is_ allowed to call the label + * manager to define further symbols, if it wants to, even + * though it's been called _from_ the label manager. That much + * re-entrancy is guaranteed in the label manager. However, the + * label manager will in turn call this routine, so it should + * be prepared to be re-entrant itself. + * + * The `special' parameter contains special information passed + * through from the command that defined the label: it may have + * been an EXTERN, a COMMON or a GLOBAL. The distinction should + * be obvious to the output format from the other parameters. + */ + void (*symdef)(char *name, int32_t segment, int64_t offset, + int is_global, char *special); + + /* + * This procedure is called when the source code requests a + * segment change. It should return the corresponding segment + * _number_ for the name, or NO_SEG if the name is not a valid + * segment name. + * + * It may also be called with NULL, in which case it is to + * return the _default_ section number for starting assembly in. + * + * It is allowed to modify the string it is given a pointer to. + * + * It is also allowed to specify a default instruction size for + * the segment, by setting `*bits' to 16, 32 or 64. Or, if it + * doesn't wish to define a default, it can leave `bits' alone. + */ + int32_t (*section)(char *name, int *bits); + + /* + * This function is called when a label is defined + * in the source code. It is allowed to change the section + * number as a result, but not the bits value. + * This is *only* called if the symbol defined is at the + * current offset, i.e. "foo:" or "foo equ $". + * The offset isn't passed; and may not be stable at this point. + * The subsection number is a field available for use by the + * backend. It is initialized to NO_SEG. + * + * If "copyoffset" is set by the backend then the offset is + * copied from the previous segment, otherwise the new segment + * is treated as a new segment the normal way. + */ + int32_t (*herelabel)(const char *name, enum label_type type, + int32_t seg, int32_t *subsection, + bool *copyoffset); + + /* + * This procedure is called to modify section alignment, + * note there is a trick, the alignment can only increase + */ + void (*sectalign)(int32_t seg, unsigned int value); + + /* + * This procedure is called to modify the segment base values + * returned from the SEG operator. It is given a segment base + * value (i.e. a segment value with the low bit set), and is + * required to produce in return a segment value which may be + * different. It can map segment bases to absolute numbers by + * means of returning SEG_ABS types. + * + * It should return NO_SEG if the segment base cannot be + * determined; the evaluator (which calls this routine) is + * responsible for throwing an error condition if that occurs + * in pass two or in a critical expression. + */ + int32_t (*segbase)(int32_t segment); + + /* + * This procedure is called to allow the output driver to + * process its own specific directives. When called, it has the + * directive word in `directive' and the parameter string in + * `value'. + * + * The following values are (currently) possible for + * directive_result: + * + * 0 - DIRR_UNKNOWN - directive not recognized by backend + * 1 - DIRR_OK - directive processed ok + * 2 - DIRR_ERROR - backend printed its own error message + * 3 - DIRR_BADPARAM - print the generic message + * "invalid parameter to [*] directive" + */ + enum directive_result + (*directive)(enum directive directive, char *value); + + /* + * This procedure is called after assembly finishes, to allow + * the output driver to clean itself up and free its memory. + * Typically, it will also be the point at which the object + * file actually gets _written_. + * + * One thing the cleanup routine should always do is to close + * the output file pointer. + */ + void (*cleanup)(void); + + /* + * List of pragma facility names that apply to this backend. + */ + const struct pragma_facility *pragmas; +}; + +/* + * Output format driver alias + */ +struct ofmt_alias { + const char *shortname; + const struct ofmt *ofmt; +}; + +extern const struct ofmt *ofmt; +extern FILE *ofile; + +/* + * ------------------------------------------------------------ + * The data structure defining a debug format driver, and the + * interfaces to the functions therein. + * ------------------------------------------------------------ + */ +struct debug_macro_info; + +struct dfmt { + /* + * This is a short (one-liner) description of the type of + * output generated by the driver. + */ + const char *fullname; + + /* + * This is a single keyword used to select the driver. + */ + const char *shortname; + + /* + * init - called initially to set up local pointer to object format. + */ + void (*init)(void); + + /* + * linenum - called any time there is output with a change of + * line number or file. + */ + void (*linenum)(const char *filename, int32_t linenumber, int32_t segto); + + /* + * debug_deflabel - called whenever a label is defined. Parameters + * are the same as to 'symdef()' in the output format. This function + * is called after the output format version. + */ + + void (*debug_deflabel)(char *name, int32_t segment, int64_t offset, + int is_global, char *special); + + /* + * debug_smacros - called when an smacro is defined or undefined + * during the code-generation pass. The definition string contains + * the macro name, any arguments, a single space, and the macro + * definition; this is what is expected by e.g. DWARF. + * + * The definition is provided even for an undef. + */ + void (*debug_smacros)(bool define, const char *def); + + /* + * debug_include - called when a file is included or the include + * is finished during the code-generation pass. The filename is + * kept by the srcfile system and so can be compared for pointer + * equality. + * + * A filename of NULL means builtin (initial or %use) or command + * line statements. + */ + void (*debug_include)(bool start, struct src_location outer, + struct src_location inner); + + /* + * debug_mmacros - called once at the end with a definition for each + * non-.nolist macro that has been invoked at least once in the program, + * and the corresponding address ranges. See dbginfo.h. + */ + void (*debug_mmacros)(const struct debug_macro_info *); + + /* + * debug_directive - called whenever a DEBUG directive other than 'LINE' + * is encountered. 'directive' contains the first parameter to the + * DEBUG directive, and params contains the rest. For example, + * 'DEBUG VAR _somevar:int' would translate to a call to this + * function with 'directive' equal to "VAR" and 'params' equal to + * "_somevar:int". + */ + void (*debug_directive)(const char *directive, const char *params); + + /* + * typevalue - called whenever the assembler wishes to register a type + * for the last defined label. This routine MUST detect if a type was + * already registered and not re-register it. + */ + void (*debug_typevalue)(int32_t type); + + /* + * debug_output - called whenever output is required + * 'type' is the type of info required, and this is format-specific + */ + void (*debug_output)(int type, void *param); + + /* + * cleanup - called after processing of file is complete + */ + void (*cleanup)(void); + + /* + * List of pragma facility names that apply to this backend. + */ + const struct pragma_facility *pragmas; +}; + +extern const struct dfmt *dfmt; + +/* + * The type definition macros + * for debugging + * + * low 3 bits: reserved + * next 5 bits: type + * next 24 bits: number of elements for arrays (0 for labels) + */ + +#define TY_UNKNOWN 0x00 +#define TY_LABEL 0x08 +#define TY_BYTE 0x10 +#define TY_WORD 0x18 +#define TY_DWORD 0x20 +#define TY_FLOAT 0x28 +#define TY_QWORD 0x30 +#define TY_TBYTE 0x38 +#define TY_OWORD 0x40 +#define TY_YWORD 0x48 +#define TY_ZWORD 0x50 +#define TY_COMMON 0xE0 +#define TY_SEG 0xE8 +#define TY_EXTERN 0xF0 +#define TY_EQU 0xF8 + +#define TYM_TYPE(x) ((x) & 0xF8) +#define TYM_ELEMENTS(x) (((x) & 0xFFFFFF00) >> 8) + +#define TYS_ELEMENTS(x) ((x) << 8) + +/* Sizes corresponding to various tokens */ +enum byte_sizes { + SIZE_BYTE = 1, + SIZE_WORD = 2, + SIZE_DWORD = 4, + SIZE_QWORD = 8, + SIZE_TWORD = 10, + SIZE_OWORD = 16, + SIZE_YWORD = 32, + SIZE_ZWORD = 64 +}; + +enum special_tokens { + SIZE_ENUM_START = PREFIX_ENUM_LIMIT, + S_BYTE = SIZE_ENUM_START, + S_WORD, + S_DWORD, + S_QWORD, + S_TWORD, + S_OWORD, + S_YWORD, + S_ZWORD, + SIZE_ENUM_LIMIT, + + SPECIAL_ENUM_START = SIZE_ENUM_LIMIT, + S_ABS = SPECIAL_ENUM_START, + S_FAR, + S_LONG, + S_NEAR, + S_NOSPLIT, + S_REL, + S_SHORT, + S_STRICT, + S_TO, + SPECIAL_ENUM_LIMIT +}; + +enum decorator_tokens { + DECORATOR_ENUM_START = SPECIAL_ENUM_LIMIT, + BRC_1TO2 = DECORATOR_ENUM_START, + BRC_1TO4, + BRC_1TO8, + BRC_1TO16, + BRC_1TO32, + BRC_RN, + BRC_RD, + BRC_RU, + BRC_RZ, + BRC_SAE, + BRC_Z, + DECORATOR_ENUM_LIMIT +}; + +/* + * AVX512 Decorator (decoflags_t) bits distribution (counted from 0) + * 3 2 1 + * 10987654321098765432109876543210 + * | + * | word boundary + * ............................1111 opmask + * ...........................1.... zeroing / merging + * ..........................1..... broadcast + * .........................1...... static rounding + * ........................1....... SAE + * ....................1111........ broadcast element size + * .................111............ number of broadcast elements + */ +#define OP_GENVAL(val, bits, shift) (((val) & ((UINT64_C(1) << (bits)) - 1)) << (shift)) + +/* + * Opmask register number + * identical to EVEX.aaa + * + * Bits: 0 - 3 + */ +#define OPMASK_SHIFT (0) +#define OPMASK_BITS (4) +#define OPMASK_MASK OP_GENMASK(OPMASK_BITS, OPMASK_SHIFT) +#define GEN_OPMASK(bit) OP_GENBIT(bit, OPMASK_SHIFT) +#define VAL_OPMASK(val) OP_GENVAL(val, OPMASK_BITS, OPMASK_SHIFT) + +/* + * zeroing / merging control available + * matching to EVEX.z + * + * Bits: 4 + */ +#define Z_SHIFT (4) +#define Z_BITS (1) +#define Z_MASK OP_GENMASK(Z_BITS, Z_SHIFT) +#define GEN_Z(bit) OP_GENBIT(bit, Z_SHIFT) + +/* + * broadcast - Whether this operand can be broadcasted + * + * Bits: 5 + */ +#define BRDCAST_SHIFT (5) +#define BRDCAST_BITS (1) +#define BRDCAST_MASK OP_GENMASK(BRDCAST_BITS, BRDCAST_SHIFT) +#define GEN_BRDCAST(bit) OP_GENBIT(bit, BRDCAST_SHIFT) + +/* + * Whether this instruction can have a static rounding mode. + * It goes with the last simd operand because the static rounding mode + * decorator is located between the last simd operand and imm8 (if any). + * + * Bits: 6 + */ +#define STATICRND_SHIFT (6) +#define STATICRND_BITS (1) +#define STATICRND_MASK OP_GENMASK(STATICRND_BITS, STATICRND_SHIFT) +#define GEN_STATICRND(bit) OP_GENBIT(bit, STATICRND_SHIFT) + +/* + * SAE(Suppress all exception) available + * + * Bits: 7 + */ +#define SAE_SHIFT (7) +#define SAE_BITS (1) +#define SAE_MASK OP_GENMASK(SAE_BITS, SAE_SHIFT) +#define GEN_SAE(bit) OP_GENBIT(bit, SAE_SHIFT) + +/* + * Broadcasting element size. + * + * Bits: 8 - 11 + */ +#define BRSIZE_SHIFT (8) +#define BRSIZE_BITS (4) +#define BRSIZE_MASK OP_GENMASK(BRSIZE_BITS, BRSIZE_SHIFT) +#define GEN_BRSIZE(bit) OP_GENBIT(bit, BRSIZE_SHIFT) + +#define BR_BITS8 GEN_BRSIZE(0) /* For potential future use */ +#define BR_BITS16 GEN_BRSIZE(1) +#define BR_BITS32 GEN_BRSIZE(2) +#define BR_BITS64 GEN_BRSIZE(3) + +/* + * Number of broadcasting elements + * + * Bits: 12 - 14 + */ +#define BRNUM_SHIFT (12) +#define BRNUM_BITS (3) +#define BRNUM_MASK OP_GENMASK(BRNUM_BITS, BRNUM_SHIFT) +#define VAL_BRNUM(val) OP_GENVAL(val, BRNUM_BITS, BRNUM_SHIFT) + +#define BR_1TO2 VAL_BRNUM(0) +#define BR_1TO4 VAL_BRNUM(1) +#define BR_1TO8 VAL_BRNUM(2) +#define BR_1TO16 VAL_BRNUM(3) +#define BR_1TO32 VAL_BRNUM(4) +#define BR_1TO64 VAL_BRNUM(5) /* For potential future use */ + +#define MASK OPMASK_MASK /* Opmask (k1 ~ 7) can be used */ +#define Z Z_MASK +#define B16 (BRDCAST_MASK|BR_BITS16) /* {1to32} : broadcast 16b * 32 to zmm(512b) */ +#define B32 (BRDCAST_MASK|BR_BITS32) /* {1to16} : broadcast 32b * 16 to zmm(512b) */ +#define B64 (BRDCAST_MASK|BR_BITS64) /* {1to8} : broadcast 64b * 8 to zmm(512b) */ +#define ER STATICRND_MASK /* ER(Embedded Rounding) == Static rounding mode */ +#define SAE SAE_MASK /* SAE(Suppress All Exception) */ + +/* + * Broadcast flags (BR_BITS*) to sizes (BITS*) + */ +static inline opflags_t brsize_to_size(opflags_t brbits) +{ + return (brbits & BRSIZE_MASK) << (SIZE_SHIFT - BRSIZE_SHIFT); +} + +/* + * Global modes + */ + +/* + * flag to disable optimizations selectively + * this is useful to turn-off certain optimizations + */ +enum optimization_disable_flag { + OPTIM_ALL_ENABLED = 0, + OPTIM_DISABLE_JMP_MATCH = 1 +}; + +struct optimization { + int level; + int flag; +}; + +/* + * Various types of compiler passes we may execute. + * If these are changed, you need to also change _pass_types[] + * in asm/nasm.c. + */ +enum pass_type { + PASS_INIT, /* Initialization, not doing anything yet */ + PASS_PREPROC, /* Preprocess-only mode (similar to PASS_FIRST) */ + PASS_FIRST, /* The very first pass over the code */ + PASS_OPT, /* Optimization pass */ + PASS_STAB, /* Stabilization pass (original pass 1) */ + PASS_FINAL /* Code generation pass (original pass 2) */ +}; +extern const char * const _pass_types[]; +extern enum pass_type _pass_type; +static inline enum pass_type pass_type(void) +{ + return _pass_type; +} +static inline const char *pass_type_name(void) +{ + return _pass_types[_pass_type]; +} +/* True during initialization, no code read yet */ +static inline bool not_started(void) +{ + return pass_type() == PASS_INIT; +} +/* True for the initial pass and setup (old "pass2 < 2") */ +static inline bool pass_first(void) +{ + return pass_type() <= PASS_FIRST; +} +/* At this point we better have stable definitions */ +static inline bool pass_stable(void) +{ + return pass_type() >= PASS_STAB; +} +/* True for the code generation pass only, (old "pass1 >= 2") */ +static inline bool pass_final(void) +{ + return pass_type() >= PASS_FINAL; +} +/* True for code generation *or* preprocess-only mode */ +static inline bool pass_final_or_preproc(void) +{ + return pass_type() >= PASS_FINAL || pass_type() == PASS_PREPROC; +} + +/* + * The actual pass number. 0 is used during initialization, the very + * first pass is 1, and then it is simply increasing numbers until we are + * done. + */ +extern int64_t _passn; /* Actual pass number */ +static inline int64_t pass_count(void) +{ + return _passn; +} + +extern struct optimization optimizing; +extern int globalbits; /* 16, 32 or 64-bit mode */ +extern int globalrel; /* default to relative addressing? */ +extern int globalbnd; /* default to using bnd prefix? */ + +extern const char *inname; /* primary input filename */ +extern const char *outname; /* output filename */ + +/* + * Switch to a different segment and return the current offset + */ +int64_t switch_segment(int32_t segment); + +#endif /* NASM_NASM_H */ diff --git a/vere/ext/nasm/include/nasmint.h b/vere/ext/nasm/include/nasmint.h new file mode 100644 index 0000000..6be623b --- /dev/null +++ b/vere/ext/nasm/include/nasmint.h @@ -0,0 +1,219 @@ +/* + * nasmint.h + * + * Small ersatz subset of <inttypes.h>, deriving the types from + * <limits.h>. + * + * Important: the preprocessor may truncate numbers too large for it. + * Therefore, test the signed types only ... truncation won't generate + * a 01111111... bit pattern. + */ + +#ifndef NASM_NASMINT_H +#define NASM_NASMINT_H + +#include <limits.h> + +/*** 64-bit type: __int64, long or long long ***/ + +/* Some old versions of gcc <limits.h> omit LLONG_MAX */ +#ifndef LLONG_MAX +# ifdef __LONG_LONG_MAX__ +# define LLONG_MAX __LONG_LONG_MAX__ +# else +# define LLONG_MAX 0 /* Assume long long is unusable */ +# endif +#endif + +#ifndef _I64_MAX +# ifdef _MSC_VER +# define _I64_MAX 9223372036854775807 +# else +# define _I64_MAX 0 +# endif +#endif + +#if _I64_MAX == 9223372036854775807 + +/* Windows-based compiler: use __int64 */ +typedef signed __int64 int64_t; +typedef unsigned __int64 uint64_t; +#define _scn64 "I64" +#define _pri64 "I64" +#define INT64_C(x) x ## i64 +#define UINT64_C(x) x ## ui64 + +#elif LONG_MAX == 9223372036854775807L + +/* long is 64 bits */ +typedef signed long int64_t; +typedef unsigned long uint64_t; +#define _scn64 "l" +#define _pri64 "l" +#define INT64_C(x) x ## L +#define UINT64_C(x) x ## UL + +#elif LLONG_MAX == 9223372036854775807LL + +/* long long is 64 bits */ +typedef signed long long int64_t; +typedef unsigned long long uint64_t; +#define _scn64 "ll" +#define _pri64 "ll" +#define INT64_C(x) x ## LL +#define UINT64_C(x) x ## ULL + +#else + +#error "Neither long nor long long is 64 bits in size" + +#endif + +/*** 32-bit type: int or long ***/ + +#if INT_MAX == 2147483647 + +/* int is 32 bits */ +typedef signed int int32_t; +typedef unsigned int uint32_t; +#define _scn32 "" +#define _pri32 "" +#define INT32_C(x) x +#define UINT32_C(x) x ## U + +#elif LONG_MAX == 2147483647L + +/* long is 32 bits */ +typedef signed long int32_t; +typedef unsigned long uint32_t; +#define _scn32 "l" +#define _pri32 "l" +#define INT32_C(x) x ## L +#define UINT32_C(x) x ## UL + +#else + +#error "Neither int nor long is 32 bits in size" + +#endif + +/*** 16-bit size: int or short ***/ + +#if INT_MAX == 32767 + +/* int is 16 bits */ +typedef signed int int16_t; +typedef unsigned int uint16_t; +#define _scn16 "" +#define _pri16 "" +#define INT16_C(x) x +#define UINT16_C(x) x ## U + +#elif SHRT_MAX == 32767 + +/* short is 16 bits */ +typedef signed short int16_t; +typedef unsigned short uint16_t; +#define _scn16 "h" +#define _pri16 "" +#define INT16_C(x) x +#define UINT16_C(x) x ## U + +#else + +#error "Neither short nor int is 16 bits in size" + +#endif + +/*** 8-bit size: char ***/ + +#if SCHAR_MAX == 127 + +/* char is 8 bits */ +typedef signed char int8_t; +typedef unsigned char uint8_t; +#define _scn8 "hh" +#define _pri8 "" +#define INT8_C(x) x +#define UINT8_C(x) x ## U + +#else + +#error "char is not 8 bits in size" + +#endif + +/* The rest of this is common to all models */ + +#define PRId8 _pri8 "d" +#define PRId16 _pri16 "d" +#define PRId32 _pri32 "d" +#define PRId64 _pri64 "d" + +#define PRIi8 _pri8 "i" +#define PRIi16 _pri16 "i" +#define PRIi32 _pri32 "i" +#define PRIi64 _pri64 "i" + +#define PRIo8 _pri8 "o" +#define PRIo16 _pri16 "o" +#define PRIo32 _pri32 "o" +#define PRIo64 _pri64 "o" + +#define PRIu8 _pri8 "u" +#define PRIu16 _pri16 "u" +#define PRIu32 _pri32 "u" +#define PRIu64 _pri64 "u" + +#define PRIx8 _pri8 "x" +#define PRIx16 _pri16 "x" +#define PRIx32 _pri32 "x" +#define PRIx64 _pri64 "x" + +#define PRIX8 _pri8 "X" +#define PRIX16 _pri16 "X" +#define PRIX32 _pri32 "X" +#define PRIX64 _pri64 "X" + +#define SCNd8 _scn8 "d" +#define SCNd16 _scn16 "d" +#define SCNd32 _scn32 "d" +#define SCNd64 _scn64 "d" + +#define SCNi8 _scn8 "i" +#define SCNi16 _scn16 "i" +#define SCNi32 _scn32 "i" +#define SCNi64 _scn64 "i" + +#define SCNo8 _scn8 "o" +#define SCNo16 _scn16 "o" +#define SCNo32 _scn32 "o" +#define SCNo64 _scn64 "o" + +#define SCNu8 _scn8 "u" +#define SCNu16 _scn16 "u" +#define SCNu32 _scn32 "u" +#define SCNu64 _scn64 "u" + +#define SCNx8 _scn8 "x" +#define SCNx16 _scn16 "x" +#define SCNx32 _scn32 "x" +#define SCNx64 _scn64 "x" + +#define INT8_MIN INT8_C(-128) +#define INT8_MAX INT8_C(127) +#define UINT8_MAX UINT8_C(255) + +#define INT16_MIN INT16_C(-32768) +#define INT16_MAX INT16_C(32767) +#define UINT16_MAX UINT16_C(65535) + +#define INT32_MIN INT32_C(-2147483648) +#define INT32_MAX INT32_C(2147483647) +#define UINT32_MAX UINT32_C(4294967295) + +#define INT64_MIN INT64_C(-9223372036854775808) +#define INT64_MAX INT64_C(9223372036854775807) +#define UINT64_MAX UINT64_C(18446744073709551615) + +#endif /* NASM_NASMINT_H */ diff --git a/vere/ext/nasm/include/nasmlib.h b/vere/ext/nasm/include/nasmlib.h new file mode 100644 index 0000000..87a7fc6 --- /dev/null +++ b/vere/ext/nasm/include/nasmlib.h @@ -0,0 +1,467 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2020 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * nasmlib.h header file for nasmlib.c + */ + +#ifndef NASM_NASMLIB_H +#define NASM_NASMLIB_H + +#include "compiler.h" +#include "bytesex.h" + +/* + * Useful construct for private values + */ +union intorptr { + int64_t i; + uint64_t u; + size_t s; + void *p; + const void *cp; + uintptr_t up; +}; +typedef union intorptr intorptr; + +/* + * Wrappers around malloc, realloc, free and a few more. 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. + */ +void * safe_malloc(1) nasm_malloc(size_t); +void * safe_malloc(1) nasm_zalloc(size_t); +void * safe_malloc2(1,2) nasm_calloc(size_t, size_t); +void * safe_realloc(2) nasm_realloc(void *, size_t); +void nasm_free(void *); +char * safe_alloc nasm_strdup(const char *); +char * safe_alloc nasm_strndup(const char *, size_t); +char * safe_alloc nasm_strcat(const char *one, const char *two); +char * safe_alloc end_with_null nasm_strcatn(const char *one, ...); + +/* + * nasm_[v]asprintf() are variants of the semi-standard [v]asprintf() + * functions, except that we return the pointer instead of a count. + * The size of the string (including the final NUL!) is available + * by calling nasm_aprintf_size() afterwards. + * + * nasm_[v]axprintf() are similar, but allocates a user-defined amount + * of storage before the string, and returns a pointer to the + * allocated buffer. The value of nasm_aprintf_size() does *not* include + * this additional storage. + */ +char * safe_alloc printf_func(1, 2) nasm_asprintf(const char *fmt, ...); +char * safe_alloc vprintf_func(1) nasm_vasprintf(const char *fmt, va_list ap); +void * safe_alloc printf_func(2, 3) nasm_axprintf(size_t extra, const char *fmt, ...); +void * safe_alloc vprintf_func(2) nasm_vaxprintf(size_t extra, const char *fmt, va_list ap); + +/* + * nasm_last_string_len() returns the length of the last string allocated + * by [v]asprintf, nasm_strdup, nasm_strcat, or nasm_strcatn. + * + * nasm_last_string_size() returns the equivalent size including the + * final NUL. + */ +static inline size_t nasm_last_string_len(void) +{ + extern size_t _nasm_last_string_size; + return _nasm_last_string_size - 1; +} +static inline size_t nasm_last_string_size(void) +{ + extern size_t _nasm_last_string_size; + return _nasm_last_string_size; +} + +/* Assert the argument is a pointer without evaluating it */ +#define nasm_assert_pointer(p) ((void)sizeof(*(p))) + +#define nasm_new(p) ((p) = nasm_zalloc(sizeof(*(p)))) +#define nasm_newn(p,n) ((p) = nasm_calloc((n), sizeof(*(p)))) +/* + * This is broken on platforms where there are pointers which don't + * match void * in their internal layout. It unfortunately also + * loses any "const" part of the argument, although hopefully the + * compiler will warn in that case. + */ +#define nasm_delete(p) \ + do { \ + void **_pp = (void **)&(p); \ + nasm_assert_pointer(p); \ + nasm_free(*_pp); \ + *_pp = NULL; \ + } while (0) +#define nasm_zero(x) (memset(&(x), 0, sizeof(x))) +#define nasm_zeron(p,n) (memset((p), 0, (n)*sizeof(*(p)))) + +/* + * Wrappers around fread()/fwrite() which fatal-errors on failure. + * For fread(), only use this if EOF is supposed to be a fatal error! + */ +void nasm_read(void *, size_t, FILE *); +void nasm_write(const void *, size_t, FILE *); + +/* + * NASM failure at build time if the argument is false + */ +#ifdef static_assert +# define nasm_static_assert(x) static_assert((x), #x) +#elif defined(HAVE_FUNC_ATTRIBUTE_ERROR) && defined(__OPTIMIZE__) +# define nasm_static_assert(x) \ + do { \ + if (!(x)) { \ + extern void __attribute__((error("assertion " #x " failed"))) \ + _nasm_static_fail(void); \ + _nasm_static_fail(); \ + } \ + } while (0) +#else +/* See http://www.drdobbs.com/compile-time-assertions/184401873 */ +# define nasm_static_assert(x) \ + do { enum { _static_assert_failed = 1/(!!(x)) }; } while (0) +#endif + +/* + * conditional static assert, if we know it is possible to determine + * the assert value at compile time. Since if_constant triggers + * pedantic warnings on gcc, turn them off explicitly around this code. + */ +#ifdef static_assert +# define nasm_try_static_assert(x) \ + do { \ + not_pedantic_start \ + static_assert(if_constant(x, true), #x); \ + not_pedantic_end \ + } while (0) +#elif defined(HAVE_FUNC_ATTRIBUTE_ERROR) && defined(__OPTIMIZE__) +# define nasm_try_static_assert(x) \ + do { \ + if (!if_constant(x, true)) { \ + extern void __attribute__((error("assertion " #x " failed"))) \ + _nasm_static_fail(void); \ + _nasm_static_fail(); \ + } \ + } while (0) +#else +# define nasm_try_static_assert(x) ((void)0) +#endif + +/* + * NASM assert failure + */ +fatal_func nasm_assert_failed(const char *, int, const char *); +#define nasm_assert(x) \ + do { \ + nasm_try_static_assert(x); \ + if (unlikely(!(x))) \ + nasm_assert_failed(__FILE__,__LINE__,#x); \ + } while (0) + +/* Utility function to generate a string for an invalid enum */ +const char *invalid_enum_str(int); + +/* + * ANSI doesn't guarantee the presence of `stricmp' or + * `strcasecmp'. + */ +#if defined(HAVE_STRCASECMP) +#define nasm_stricmp strcasecmp +#elif defined(HAVE_STRICMP) +#define nasm_stricmp stricmp +#else +int pure_func nasm_stricmp(const char *, const char *); +#endif + +#if defined(HAVE_STRNCASECMP) +#define nasm_strnicmp strncasecmp +#elif defined(HAVE_STRNICMP) +#define nasm_strnicmp strnicmp +#else +int pure_func nasm_strnicmp(const char *, const char *, size_t); +#endif + +int pure_func nasm_memicmp(const char *, const char *, size_t); + +#if defined(HAVE_STRSEP) +#define nasm_strsep strsep +#else +char *nasm_strsep(char **stringp, const char *delim); +#endif + +#ifndef HAVE_DECL_STRNLEN +size_t pure_func strnlen(const char *, size_t); +#endif + +/* This returns the numeric value of a given 'digit'; no check for validity */ +static inline unsigned int numvalue(unsigned char c) +{ + c |= 0x20; + return c >= 'a' ? c - 'a' + 10 : c - '0'; +} + +/* + * Convert a string into a number, using NASM number rules. Sets + * `*error' to true if an error occurs, and false otherwise. + */ +int64_t readnum(const char *str, bool *error); + +/* + * Convert a character constant into a number. Sets + * `*warn' to true if an overflow occurs, and false otherwise. + * str points to and length covers the middle of the string, + * without the quotes. + */ +int64_t readstrnum(char *str, int length, bool *warn); + +/* + * seg_alloc: allocate a hitherto unused segment number. + */ +int32_t seg_alloc(void); + +/* + * Add/replace or remove an extension to the end of a filename + */ +const char *filename_set_extension(const char *inname, const char *extension); + +/* + * Utility macros... + * + * This is a useful #define which I keep meaning to use more often: + * the number of elements of a statically defined array. + */ +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +/* + * List handling + * + * list_for_each - regular iterator over list + * list_for_each_safe - the same but safe against list items removal + * list_last - find the last element in a list + * list_reverse - reverse the order of a list + * + * Arguments named with _ + single letter should be temp variables + * of the appropriate pointer type. + */ +#define list_for_each(pos, head) \ + for (pos = head; pos; pos = pos->next) +#define list_for_each_safe(pos, _n, head) \ + for (pos = head, _n = (pos ? pos->next : NULL); pos; \ + pos = _n, _n = (_n ? _n->next : NULL)) +#define list_last(pos, head) \ + for (pos = head; pos && pos->next; pos = pos->next) \ + ; +#define list_reverse(head) \ + do { \ + void *_p, *_n; \ + if (!head || !head->next) \ + break; \ + _p = NULL; \ + while (head) { \ + _n = head->next; \ + head->next = _p; \ + _p = head; \ + head = _n; \ + } \ + head = _p; \ + } while (0) + +/* + * Power of 2 align helpers + */ +#undef ALIGN_MASK /* Some BSD flavors define these in system headers */ +#undef ALIGN +#define ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask)) +#define ALIGN(v, a) ALIGN_MASK(v, (a) - 1) +#define IS_ALIGNED(v, a) (((v) & ((a) - 1)) == 0) + +/* + * Routines to write littleendian data to a file + */ +#define fwriteint8_t(d,f) putc(d,f) +void fwriteint16_t(uint16_t data, FILE * fp); +void fwriteint32_t(uint32_t data, FILE * fp); +void fwriteint64_t(uint64_t data, FILE * fp); +void fwriteaddr(uint64_t data, int size, FILE * fp); + +/* + * Binary search routine. Returns index into `array' of an entry + * matching `string', or <0 if no match. `array' is taken to + * contain `size' elements. + * + * bsi() is case sensitive, bsii() is case insensitive. + */ +int bsi(const char *string, const char **array, int size); +int bsii(const char *string, const char **array, int size); + +/* + * Convenient string processing helper routines + */ +char *nasm_skip_spaces(const char *p); +char *nasm_skip_word(const char *p); +char *nasm_zap_spaces_fwd(char *p); +char *nasm_zap_spaces_rev(char *p); +char *nasm_trim_spaces(char *p); +char *nasm_get_word(char *p, char **tail); +char *nasm_opt_val(char *p, char **opt, char **val); + +/* + * Converts a relative pathname rel_path into an absolute path name. + * + * The buffer returned must be freed by the caller + */ +char * safe_alloc nasm_realpath(const char *rel_path); + +/* + * Path-splitting and merging functions + */ +char * safe_alloc nasm_dirname(const char *path); +char * safe_alloc nasm_basename(const char *path); +char * safe_alloc nasm_catfile(const char *dir, const char *path); + +const char * pure_func prefix_name(int); + +/* + * Wrappers around fopen()... for future change to a dedicated structure + */ +enum file_flags { + NF_BINARY = 0x00000000, /* Binary file (default) */ + NF_TEXT = 0x00000001, /* Text file */ + NF_NONFATAL = 0x00000000, /* Don't die on open failure (default) */ + NF_FATAL = 0x00000002, /* Die on open failure */ + NF_FORMAP = 0x00000004, /* Intended to use nasm_map_file() */ + NF_IONBF = 0x00000010, /* Force unbuffered stdio */ + NF_IOLBF = 0x00000020, /* Force line buffered stdio */ + NF_IOFBF = 0000000030 /* Force fully buffered stdio */ +}; +#define NF_BUF_MASK 0x30 + +FILE *nasm_open_read(const char *filename, enum file_flags flags); +FILE *nasm_open_write(const char *filename, enum file_flags flags); + +void nasm_set_binary_mode(FILE *f); + +/* Probe for existence of a file */ +bool nasm_file_exists(const char *filename); + +#define ZERO_BUF_SIZE 65536 /* Default value */ +#if defined(BUFSIZ) && (BUFSIZ > ZERO_BUF_SIZE) +# undef ZERO_BUF_SIZE +# define ZERO_BUF_SIZE BUFSIZ +#endif +extern const uint8_t zero_buffer[ZERO_BUF_SIZE]; + +/* Missing fseeko/ftello */ +#ifndef HAVE_FSEEKO +# undef off_t /* Just in case it is a macro */ +# ifdef HAVE__FSEEKI64 +# define fseeko _fseeki64 +# define ftello _ftelli64 +# define off_t int64_t +# else +# define fseeko fseek +# define ftello ftell +# define off_t long +# endif +#endif + +const void *nasm_map_file(FILE *fp, off_t start, off_t len); +void nasm_unmap_file(const void *p, size_t len); +off_t nasm_file_size(FILE *f); +off_t nasm_file_size_by_path(const char *pathname); +bool nasm_file_time(time_t *t, const char *pathname); +void fwritezero(off_t bytes, FILE *fp); + +static inline bool const_func overflow_general(int64_t value, int bytes) +{ + int sbit; + int64_t vmax, vmin; + + if (bytes >= 8) + return false; + + sbit = (bytes << 3) - 1; + vmax = ((int64_t)2 << sbit) - 1; + vmin = -((int64_t)2 << sbit); + + return value < vmin || value > vmax; +} + +static inline bool const_func overflow_signed(int64_t value, int bytes) +{ + int sbit; + int64_t vmax, vmin; + + if (bytes >= 8) + return false; + + sbit = (bytes << 3) - 1; + vmax = ((int64_t)1 << sbit) - 1; + vmin = -((int64_t)1 << sbit); + + return value < vmin || value > vmax; +} + +static inline bool const_func overflow_unsigned(int64_t value, int bytes) +{ + int sbit; + int64_t vmax, vmin; + + if (bytes >= 8) + return false; + + sbit = (bytes << 3) - 1; + vmax = ((int64_t)2 << sbit) - 1; + vmin = 0; + + return value < vmin || value > vmax; +} + +static inline int64_t const_func signed_bits(int64_t value, int bits) +{ + if (bits < 64) { + value &= ((int64_t)1 << bits) - 1; + if (value & (int64_t)1 << (bits - 1)) + value |= (int64_t)((uint64_t)-1 << bits); + } + return value; +} + +/* check if value is power of 2 */ +#define is_power2(v) ((v) && ((v) & ((v) - 1)) == 0) + +/* try to get the system stack size */ +extern size_t nasm_get_stack_size_limit(void); + +#endif diff --git a/vere/ext/nasm/include/nctype.h b/vere/ext/nasm/include/nctype.h new file mode 100644 index 0000000..ba594b9 --- /dev/null +++ b/vere/ext/nasm/include/nctype.h @@ -0,0 +1,127 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2018 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * ctype-like functions specific to NASM + */ +#ifndef NASM_NCTYPE_H +#define NASM_NCTYPE_H + +#include "compiler.h" + +void nasm_ctype_init(void); + +extern unsigned char nasm_tolower_tab[256]; +static inline char nasm_tolower(char x) +{ + return nasm_tolower_tab[(unsigned char)x]; +} + +/* + * NASM ctype table + */ +enum nasm_ctype { + NCT_CTRL = 0x0001, + NCT_SPACE = 0x0002, + NCT_ASCII = 0x0004, + NCT_LOWER = 0x0008, /* isalpha(x) && tolower(x) == x */ + NCT_UPPER = 0x0010, /* isalpha(x) && tolower(x) != x */ + NCT_DIGIT = 0x0020, + NCT_HEX = 0x0040, + NCT_ID = 0x0080, + NCT_IDSTART = 0x0100, + NCT_MINUS = 0x0200, /* - */ + NCT_DOLLAR = 0x0400, /* $ */ + NCT_UNDER = 0x0800, /* _ */ + NCT_QUOTE = 0x1000 /* " ' ` */ +}; + +extern uint16_t nasm_ctype_tab[256]; +static inline bool nasm_ctype(unsigned char x, enum nasm_ctype mask) +{ + return (nasm_ctype_tab[x] & mask) != 0; +} + +static inline bool nasm_isspace(char x) +{ + return nasm_ctype(x, NCT_SPACE); +} + +static inline bool nasm_isalpha(char x) +{ + return nasm_ctype(x, NCT_LOWER|NCT_UPPER); +} + +static inline bool nasm_isdigit(char x) +{ + return nasm_ctype(x, NCT_DIGIT); +} +static inline bool nasm_isalnum(char x) +{ + return nasm_ctype(x, NCT_LOWER|NCT_UPPER|NCT_DIGIT); +} +static inline bool nasm_isxdigit(char x) +{ + return nasm_ctype(x, NCT_HEX); +} +static inline bool nasm_isidstart(char x) +{ + return nasm_ctype(x, NCT_IDSTART); +} +static inline bool nasm_isidchar(char x) +{ + return nasm_ctype(x, NCT_ID); +} +static inline bool nasm_isbrcchar(char x) +{ + return nasm_ctype(x, NCT_ID|NCT_MINUS); +} +static inline bool nasm_isnumstart(char x) +{ + return nasm_ctype(x, NCT_DIGIT|NCT_DOLLAR); +} +static inline bool nasm_isnumchar(char x) +{ + return nasm_ctype(x, NCT_DIGIT|NCT_LOWER|NCT_UPPER|NCT_UNDER); +} +static inline bool nasm_isquote(char x) +{ + return nasm_ctype(x, NCT_QUOTE); +} + +static inline void nasm_ctype_tasm_mode(void) +{ + /* No differences at the present moment */ +} + +#endif /* NASM_NCTYPE_H */ diff --git a/vere/ext/nasm/include/opflags.h b/vere/ext/nasm/include/opflags.h new file mode 100644 index 0000000..179b1e0 --- /dev/null +++ b/vere/ext/nasm/include/opflags.h @@ -0,0 +1,301 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2018 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * opflags.h - operand flags + */ + +#ifndef NASM_OPFLAGS_H +#define NASM_OPFLAGS_H + +#include "compiler.h" +#include "tables.h" /* for opflags_t and nasm_reg_flags[] */ +#include "regs.h" + +/* + * Here we define the operand types. These are implemented as bit + * masks, since some are subsets of others; e.g. AX in a MOV + * instruction is a special operand type, whereas AX in other + * contexts is just another 16-bit register. (Also, consider CL in + * shift instructions, DX in OUT, etc.) + * + * The basic concept here is that + * (class & ~operand) == 0 + * + * if and only if "operand" belongs to class type "class". + */ + +#define OP_GENMASK(bits, shift) (((UINT64_C(1) << (bits)) - 1) << (shift)) +#define OP_GENBIT(bit, shift) (UINT64_C(1) << ((shift) + (bit))) + +/* + * Type of operand: memory reference, register, etc. + * + * Bits: 0 - 3 + */ +#define OPTYPE_SHIFT (0) +#define OPTYPE_BITS (4) +#define OPTYPE_MASK OP_GENMASK(OPTYPE_BITS, OPTYPE_SHIFT) +#define GEN_OPTYPE(bit) OP_GENBIT(bit, OPTYPE_SHIFT) + +/* + * Modifiers. + * + * Bits: 4 - 6 + */ +#define MODIFIER_SHIFT (4) +#define MODIFIER_BITS (3) +#define MODIFIER_MASK OP_GENMASK(MODIFIER_BITS, MODIFIER_SHIFT) +#define GEN_MODIFIER(bit) OP_GENBIT(bit, MODIFIER_SHIFT) + +/* + * Register classes. + * + * Bits: 7 - 17 + */ +#define REG_CLASS_SHIFT (7) +#define REG_CLASS_BITS (11) +#define REG_CLASS_MASK OP_GENMASK(REG_CLASS_BITS, REG_CLASS_SHIFT) +#define GEN_REG_CLASS(bit) OP_GENBIT(bit, REG_CLASS_SHIFT) + +/* + * Subclasses. Depends on type of operand. + * + * Bits: 18 - 25 + */ +#define SUBCLASS_SHIFT (18) +#define SUBCLASS_BITS (8) +#define SUBCLASS_MASK OP_GENMASK(SUBCLASS_BITS, SUBCLASS_SHIFT) +#define GEN_SUBCLASS(bit) OP_GENBIT(bit, SUBCLASS_SHIFT) + +/* + * Special flags. Context dependent. + * + * Bits: 26 - 32 + */ +#define SPECIAL_SHIFT (26) +#define SPECIAL_BITS (7) +#define SPECIAL_MASK OP_GENMASK(SPECIAL_BITS, SPECIAL_SHIFT) +#define GEN_SPECIAL(bit) OP_GENBIT(bit, SPECIAL_SHIFT) + +/* + * Sizes of the operands and attributes. + * + * Bits: 33 - 43 + */ +#define SIZE_SHIFT (33) +#define SIZE_BITS (11) +#define SIZE_MASK OP_GENMASK(SIZE_BITS, SIZE_SHIFT) +#define GEN_SIZE(bit) OP_GENBIT(bit, SIZE_SHIFT) + +/* + * Register set count + * + * Bits: 44 - 48 + */ +#define REGSET_SHIFT (44) +#define REGSET_BITS (5) +#define REGSET_MASK OP_GENMASK(REGSET_BITS, REGSET_SHIFT) +#define GEN_REGSET(bit) OP_GENBIT(bit, REGSET_SHIFT) + +/* + * Bits distribution (counted from 0) + * + * 6 5 4 3 2 1 + * 3210987654321098765432109876543210987654321098765432109876543210 + * | + * | dword bound + * + * ............................................................1111 optypes + * .........................................................111.... modifiers + * ..............................................11111111111....... register classes + * ......................................11111111.................. subclasses + * ...............................1111111.......................... specials + * ....................11111111111................................. sizes + * ...............11111............................................ regset count + */ + +#define REGISTER GEN_OPTYPE(0) /* register number in 'basereg' */ +#define IMMEDIATE GEN_OPTYPE(1) +#define REGMEM GEN_OPTYPE(2) /* for r/m, ie EA, operands */ +#define MEMORY (GEN_OPTYPE(3) | REGMEM) + +#define BITS8 GEN_SIZE(0) /* 8 bits (BYTE) */ +#define BITS16 GEN_SIZE(1) /* 16 bits (WORD) */ +#define BITS32 GEN_SIZE(2) /* 32 bits (DWORD) */ +#define BITS64 GEN_SIZE(3) /* 64 bits (QWORD), x64 and FPU only */ +#define BITS80 GEN_SIZE(4) /* 80 bits (TWORD), FPU only */ +#define BITS128 GEN_SIZE(5) /* 128 bits (OWORD) */ +#define BITS256 GEN_SIZE(6) /* 256 bits (YWORD) */ +#define BITS512 GEN_SIZE(7) /* 512 bits (ZWORD) */ +#define FAR GEN_SIZE(8) /* grotty: this means 16:16 or 16:32, like in CALL/JMP */ +#define NEAR GEN_SIZE(9) +#define SHORT GEN_SIZE(10) /* and this means what it says :) */ + +#define TO GEN_MODIFIER(0) /* reverse effect in FADD, FSUB &c */ +#define COLON GEN_MODIFIER(1) /* operand is followed by a colon */ +#define STRICT GEN_MODIFIER(2) /* do not optimize this operand */ + +#define REG_CLASS_CDT GEN_REG_CLASS(0) +#define REG_CLASS_GPR GEN_REG_CLASS(1) +#define REG_CLASS_SREG GEN_REG_CLASS(2) +#define REG_CLASS_FPUREG GEN_REG_CLASS(3) +#define REG_CLASS_RM_MMX GEN_REG_CLASS(4) +#define REG_CLASS_RM_XMM GEN_REG_CLASS(5) +#define REG_CLASS_RM_YMM GEN_REG_CLASS(6) +#define REG_CLASS_RM_ZMM GEN_REG_CLASS(7) +#define REG_CLASS_OPMASK GEN_REG_CLASS(8) +#define REG_CLASS_BND GEN_REG_CLASS(9) +#define REG_CLASS_RM_TMM GEN_REG_CLASS(10) + +static inline bool is_class(opflags_t class, opflags_t op) +{ + return !(class & ~op); +} + +static inline bool is_reg_class(opflags_t class, opflags_t reg) +{ + if (reg >= EXPR_REG_START && reg <= EXPR_REG_END) + return is_class(class, nasm_reg_flags[reg]); + return false; +} + +#define IS_SREG(reg) is_reg_class(REG_SREG, (reg)) +#define IS_FSGS(reg) is_reg_class(REG_FSGS, (reg)) + +/* Register classes */ +#define REG_EA ( REGMEM | REGISTER) /* 'normal' reg, qualifies as EA */ +#define RM_GPR ( REG_CLASS_GPR | REGMEM) /* integer operand */ +#define REG_GPR ( REG_CLASS_GPR | REGMEM | REGISTER) /* integer register */ +#define REG8 ( REG_CLASS_GPR | BITS8 | REGMEM | REGISTER) /* 8-bit GPR */ +#define REG16 ( REG_CLASS_GPR | BITS16 | REGMEM | REGISTER) /* 16-bit GPR */ +#define REG32 ( REG_CLASS_GPR | BITS32 | REGMEM | REGISTER) /* 32-bit GPR */ +#define REG64 ( REG_CLASS_GPR | BITS64 | REGMEM | REGISTER) /* 64-bit GPR */ +#define FPUREG ( REG_CLASS_FPUREG | REGISTER) /* floating point stack registers */ +#define FPU0 (GEN_SUBCLASS(1) | REG_CLASS_FPUREG | REGISTER) /* FPU stack register zero */ +#define RM_MMX ( REG_CLASS_RM_MMX | REGMEM) /* MMX operand */ +#define MMXREG ( REG_CLASS_RM_MMX | REGMEM | REGISTER) /* MMX register */ +#define RM_XMM ( REG_CLASS_RM_XMM | REGMEM) /* XMM (SSE) operand */ +#define XMMREG ( REG_CLASS_RM_XMM | REGMEM | REGISTER) /* XMM (SSE) register */ +#define RM_YMM ( REG_CLASS_RM_YMM | REGMEM) /* YMM (AVX) operand */ +#define YMMREG ( REG_CLASS_RM_YMM | REGMEM | REGISTER) /* YMM (AVX) register */ +#define RM_ZMM ( REG_CLASS_RM_ZMM | REGMEM) /* ZMM (AVX512) operand */ +#define ZMMREG ( REG_CLASS_RM_ZMM | REGMEM | REGISTER) /* ZMM (AVX512) register */ +#define RM_OPMASK ( REG_CLASS_OPMASK | REGMEM) /* Opmask operand */ +#define OPMASKREG ( REG_CLASS_OPMASK | REGMEM | REGISTER) /* Opmask register */ +#define OPMASK0 (GEN_SUBCLASS(1) | REG_CLASS_OPMASK | REGMEM | REGISTER) /* Opmask register zero (k0) */ +#define RM_K RM_OPMASK +#define KREG OPMASKREG +#define RM_BND ( REG_CLASS_BND | REGMEM) /* Bounds operand */ +#define BNDREG ( REG_CLASS_BND | REGMEM | REGISTER) /* Bounds register */ +#define TMMREG ( REG_CLASS_RM_TMM | REGMEM | REGISTER) /* TMM (AMX) register */ +#define REG_CDT ( REG_CLASS_CDT | BITS32 | REGISTER) /* CRn, DRn and TRn */ +#define REG_CREG (GEN_SUBCLASS(1) | REG_CLASS_CDT | BITS32 | REGISTER) /* CRn */ +#define REG_DREG (GEN_SUBCLASS(2) | REG_CLASS_CDT | BITS32 | REGISTER) /* DRn */ +#define REG_TREG (GEN_SUBCLASS(3) | REG_CLASS_CDT | BITS32 | REGISTER) /* TRn */ +#define REG_SREG ( REG_CLASS_SREG | BITS16 | REGISTER) /* any segment register */ + +/* Segment registers */ +#define REG_ES (GEN_SUBCLASS(0) | GEN_SUBCLASS(2) | REG_CLASS_SREG | BITS16 | REGISTER) /* ES */ +#define REG_CS (GEN_SUBCLASS(1) | GEN_SUBCLASS(2) | REG_CLASS_SREG | BITS16 | REGISTER) /* CS */ +#define REG_SS (GEN_SUBCLASS(0) | GEN_SUBCLASS(3) | REG_CLASS_SREG | BITS16 | REGISTER) /* SS */ +#define REG_DS (GEN_SUBCLASS(1) | GEN_SUBCLASS(3) | REG_CLASS_SREG | BITS16 | REGISTER) /* DS */ +#define REG_FS (GEN_SUBCLASS(0) | GEN_SUBCLASS(4) | REG_CLASS_SREG | BITS16 | REGISTER) /* FS */ +#define REG_GS (GEN_SUBCLASS(1) | GEN_SUBCLASS(4) | REG_CLASS_SREG | BITS16 | REGISTER) /* GS */ +#define REG_FSGS ( GEN_SUBCLASS(4) | REG_CLASS_SREG | BITS16 | REGISTER) /* FS or GS */ +#define REG_SEG67 ( GEN_SUBCLASS(5) | REG_CLASS_SREG | BITS16 | REGISTER) /* Unimplemented segment registers */ + +/* Special GPRs */ +#define REG_SMASK SUBCLASS_MASK /* a mask for the following */ +#define REG_ACCUM (GEN_SUBCLASS(1) | REG_CLASS_GPR | REGMEM | REGISTER) /* accumulator: AL, AX, EAX, RAX */ +#define REG_AL (GEN_SUBCLASS(1) | REG_CLASS_GPR | BITS8 | REGMEM | REGISTER) +#define REG_AX (GEN_SUBCLASS(1) | REG_CLASS_GPR | BITS16 | REGMEM | REGISTER) +#define REG_EAX (GEN_SUBCLASS(1) | REG_CLASS_GPR | BITS32 | REGMEM | REGISTER) +#define REG_RAX (GEN_SUBCLASS(1) | REG_CLASS_GPR | BITS64 | REGMEM | REGISTER) +#define REG_COUNT (GEN_SUBCLASS(5) | GEN_SUBCLASS(2) | REG_CLASS_GPR | REGMEM | REGISTER) /* counter: CL, CX, ECX, RCX */ +#define REG_CL (GEN_SUBCLASS(5) | GEN_SUBCLASS(2) | REG_CLASS_GPR | BITS8 | REGMEM | REGISTER) +#define REG_CX (GEN_SUBCLASS(5) | GEN_SUBCLASS(2) | REG_CLASS_GPR | BITS16 | REGMEM | REGISTER) +#define REG_ECX (GEN_SUBCLASS(5) | GEN_SUBCLASS(2) | REG_CLASS_GPR | BITS32 | REGMEM | REGISTER) +#define REG_RCX (GEN_SUBCLASS(5) | GEN_SUBCLASS(2) | REG_CLASS_GPR | BITS64 | REGMEM | REGISTER) +#define REG_DL (GEN_SUBCLASS(5) | GEN_SUBCLASS(3) | REG_CLASS_GPR | BITS8 | REGMEM | REGISTER) /* data: DL, DX, EDX, RDX */ +#define REG_DX (GEN_SUBCLASS(5) | GEN_SUBCLASS(3) | REG_CLASS_GPR | BITS16 | REGMEM | REGISTER) +#define REG_EDX (GEN_SUBCLASS(5) | GEN_SUBCLASS(3) | REG_CLASS_GPR | BITS32 | REGMEM | REGISTER) +#define REG_RDX (GEN_SUBCLASS(5) | GEN_SUBCLASS(3) | REG_CLASS_GPR | BITS64 | REGMEM | REGISTER) +#define REG_HIGH (GEN_SUBCLASS(5) | GEN_SUBCLASS(4) | REG_CLASS_GPR | BITS8 | REGMEM | REGISTER) /* high regs: AH, CH, DH, BH */ +#define REG_NOTACC GEN_SUBCLASS(5) /* non-accumulator register */ +#define REG8NA (GEN_SUBCLASS(5) | REG_CLASS_GPR | BITS8 | REGMEM | REGISTER) /* 8-bit non-acc GPR */ +#define REG16NA (GEN_SUBCLASS(5) | REG_CLASS_GPR | BITS16 | REGMEM | REGISTER) /* 16-bit non-acc GPR */ +#define REG32NA (GEN_SUBCLASS(5) | REG_CLASS_GPR | BITS32 | REGMEM | REGISTER) /* 32-bit non-acc GPR */ +#define REG64NA (GEN_SUBCLASS(5) | REG_CLASS_GPR | BITS64 | REGMEM | REGISTER) /* 64-bit non-acc GPR */ + +/* special types of EAs */ +#define MEM_OFFS (GEN_SUBCLASS(1) | MEMORY) /* simple [address] offset - absolute! */ +#define IP_REL (GEN_SUBCLASS(2) | MEMORY) /* IP-relative offset */ +#define XMEM (GEN_SUBCLASS(3) | MEMORY) /* 128-bit vector SIB */ +#define YMEM (GEN_SUBCLASS(4) | MEMORY) /* 256-bit vector SIB */ +#define ZMEM (GEN_SUBCLASS(5) | MEMORY) /* 512-bit vector SIB */ + +/* memory which matches any type of r/m operand */ +#define MEMORY_ANY (MEMORY | RM_GPR | RM_MMX | RM_XMM_L16 | RM_YMM_L16 | RM_ZMM_L16 | RM_OPMASK | RM_BND) + +/* special immediate values */ +#define UNITY (GEN_SUBCLASS(0) | IMMEDIATE) /* operand equals 1 */ +#define SBYTEWORD (GEN_SUBCLASS(1) | IMMEDIATE) /* operand is in the range -128..127 mod 2^16 */ +#define SBYTEDWORD (GEN_SUBCLASS(2) | IMMEDIATE) /* operand is in the range -128..127 mod 2^32 */ +#define SDWORD (GEN_SUBCLASS(3) | IMMEDIATE) /* operand is in the range -0x80000000..0x7FFFFFFF */ +#define UDWORD (GEN_SUBCLASS(4) | IMMEDIATE) /* operand is in the range 0..0xFFFFFFFF */ + +/* + * Subset of vector registers: register 0 only and registers 0-15. + * Avoid conflicts in subclass bitfield with any of special EA types! + */ +#define RM_XMM_L16 (GEN_SUBCLASS(6) | RM_XMM) /* XMM r/m operand 0 ~ 15 */ +#define XMM0 (GEN_SUBCLASS(1) | GEN_SUBCLASS(6) | XMMREG) /* XMM register zero */ +#define XMM_L16 ( GEN_SUBCLASS(6) | XMMREG) /* XMM register 0 ~ 15 */ + +#define RM_YMM_L16 (GEN_SUBCLASS(6) | RM_YMM) /* YMM r/m operand 0 ~ 15 */ +#define YMM0 (GEN_SUBCLASS(1) | GEN_SUBCLASS(6) | YMMREG) /* YMM register zero */ +#define YMM_L16 ( GEN_SUBCLASS(6) | YMMREG) /* YMM register 0 ~ 15 */ + +#define RM_ZMM_L16 (GEN_SUBCLASS(6) | RM_ZMM) /* ZMM r/m operand 0 ~ 15 */ +#define ZMM0 (GEN_SUBCLASS(1) | GEN_SUBCLASS(6) | ZMMREG) /* ZMM register zero */ +#define ZMM_L16 ( GEN_SUBCLASS(6) | ZMMREG) /* ZMM register 0 ~ 15 */ + +/* Register set sizes */ +#define RS2 GEN_REGSET(0) +#define RS4 GEN_REGSET(1) +#define RS8 GEN_REGSET(2) +#define RS16 GEN_REGSET(3) +#define RS32 GEN_REGSET(4) + +#endif /* NASM_OPFLAGS_H */ diff --git a/vere/ext/nasm/include/perfhash.h b/vere/ext/nasm/include/perfhash.h new file mode 100644 index 0000000..43e536c --- /dev/null +++ b/vere/ext/nasm/include/perfhash.h @@ -0,0 +1,52 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2017 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +#ifndef PERFHASH_H +#define PERFHASH_H 1 + +#include "compiler.h" +#include "nasmlib.h" /* For invalid_enum_str() */ + +struct perfect_hash { + uint64_t crcinit; + uint32_t hashmask; + uint32_t tbllen; + int tbloffs; + int errval; + const int16_t *hashvals; + const char * const *strings; +}; + +int perfhash_find(const struct perfect_hash *, const char *); + +#endif /* PERFHASH_H */ diff --git a/vere/ext/nasm/include/raa.h b/vere/ext/nasm/include/raa.h new file mode 100644 index 0000000..e08d90b --- /dev/null +++ b/vere/ext/nasm/include/raa.h @@ -0,0 +1,49 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2009 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +#ifndef NASM_RAA_H +#define NASM_RAA_H 1 + +#include "compiler.h" + +struct RAA; +typedef uint64_t raaindex; + +#define raa_init() NULL +void raa_free(struct RAA *); +int64_t raa_read(struct RAA *, raaindex); +void *raa_read_ptr(struct RAA *, raaindex); +struct RAA * never_null raa_write(struct RAA *r, raaindex posn, int64_t value); +struct RAA * never_null raa_write_ptr(struct RAA *r, raaindex posn, void *value); + +#endif /* NASM_RAA_H */ diff --git a/vere/ext/nasm/include/rbtree.h b/vere/ext/nasm/include/rbtree.h new file mode 100644 index 0000000..39d45af --- /dev/null +++ b/vere/ext/nasm/include/rbtree.h @@ -0,0 +1,108 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2020 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +#ifndef NASM_RBTREE_H +#define NASM_RBTREE_H + +#include "compiler.h" + +/* + * This structure should be embedded in a larger data structure; + * the final output from rb_search() can then be converted back + * to the larger data structure via container_of(). + * + * An empty tree is simply represented by a NULL pointer. + */ + +/* Note: the values of these flags is significant */ +enum rbtree_node_flags { + RBTREE_NODE_BLACK = 1, /* Node color is black */ + RBTREE_NODE_PRED = 2, /* Left pointer is an uplink */ + RBTREE_NODE_SUCC = 4 /* Right pointer is an uplink */ +}; + +struct rbtree { + uint64_t key; + struct rbtree_metadata { + struct rbtree *left, *right; + enum rbtree_node_flags flags; + } m; +}; + +/* + * Add a node to a tree. Returns the new root pointer. + * The key value in the structure needs to be preinitialized; + * the rest of the structure should be zero. + */ +struct rbtree *rb_insert(struct rbtree *, struct rbtree *); + +/* + * Find a node in the tree corresponding to the key immediately + * <= the passed-in key value. + */ +struct rbtree *rb_search(const struct rbtree *, uint64_t); + +/* + * Find a node in the tree exactly matching the key value. + */ +struct rbtree *rb_search_exact(const struct rbtree *, uint64_t); + +/* + * Return the immediately previous or next node in key order. + * Returns NULL if this node is the end of the tree. + * These operations are safe for complee (but not partial!) + * tree walk-with-destruction in key order. + */ +struct rbtree *rb_prev(const struct rbtree *); +struct rbtree *rb_next(const struct rbtree *); + +/* + * Return the very first or very last node in key order. + */ +struct rbtree *rb_first(const struct rbtree *); +struct rbtree *rb_last(const struct rbtree *); + +/* + * Left and right nodes, if real. These operations are + * safe for tree destruction, but not for splitting a tree. + */ +static inline struct rbtree *rb_left(const struct rbtree *rb) +{ + return (rb->m.flags & RBTREE_NODE_PRED) ? NULL : rb->m.left; +} +static inline struct rbtree *rb_right(const struct rbtree *rb) +{ + return (rb->m.flags & RBTREE_NODE_SUCC) ? NULL : rb->m.right; +} + +#endif /* NASM_RBTREE_H */ diff --git a/vere/ext/nasm/include/rdoff.h b/vere/ext/nasm/include/rdoff.h new file mode 100644 index 0000000..973be8c --- /dev/null +++ b/vere/ext/nasm/include/rdoff.h @@ -0,0 +1,169 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2017 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * rdoff.h RDOFF Object File manipulation routines header file + */ + +#ifndef RDOFF_H +#define RDOFF_H 1 + +/* + * RDOFF definitions. They are used by RDOFF utilities and by NASM's + * 'outrdf2.c' output module. + */ + +/* RDOFF format revision (currently used only when printing the version) */ +#define RDOFF2_REVISION "0.6.1" + +/* RDOFF2 file signature */ +#define RDOFF2_SIGNATURE "RDOFF2" + +/* Maximum size of an import/export label (including trailing zero) */ +#define EXIM_LABEL_MAX 256 + +/* Maximum size of library or module name (including trailing zero) */ +#define MODLIB_NAME_MAX 128 + +/* Maximum number of segments that we can handle in one file */ +#define RDF_MAXSEGS 64 + +/* Record types that may present the RDOFF header */ +#define RDFREC_GENERIC 0 +#define RDFREC_RELOC 1 +#define RDFREC_IMPORT 2 +#define RDFREC_GLOBAL 3 +#define RDFREC_DLL 4 +#define RDFREC_BSS 5 +#define RDFREC_SEGRELOC 6 +#define RDFREC_FARIMPORT 7 +#define RDFREC_MODNAME 8 +#define RDFREC_COMMON 10 + +/* + * Generic record - contains the type and length field, plus a 128 byte + * array 'data' + */ +struct GenericRec { + uint8_t type; + uint8_t reclen; + char data[128]; +}; + +/* + * Relocation record + */ +struct RelocRec { + uint8_t type; /* must be 1 */ + uint8_t reclen; /* content length */ + uint8_t segment; /* only 0 for code, or 1 for data supported, + but add 64 for relative refs (ie do not require + reloc @ loadtime, only linkage) */ + int32_t offset; /* from start of segment in which reference is loc'd */ + uint8_t length; /* 1 2 or 4 bytes */ + uint16_t refseg; /* segment to which reference refers to */ +}; + +/* + * Extern/import record + */ +struct ImportRec { + uint8_t type; /* must be 2 */ + uint8_t reclen; /* content length */ + uint8_t flags; /* SYM_* flags (see below) */ + uint16_t segment; /* segment number allocated to the label for reloc + records - label is assumed to be at offset zero + in this segment, so linker must fix up with offset + of segment and of offset within segment */ + char label[EXIM_LABEL_MAX]; /* zero terminated, should be written to file + until the zero, but not after it */ +}; + +/* + * Public/export record + */ +struct ExportRec { + uint8_t type; /* must be 3 */ + uint8_t reclen; /* content length */ + uint8_t flags; /* SYM_* flags (see below) */ + uint8_t segment; /* segment referred to (0/1/2) */ + int32_t offset; /* offset within segment */ + char label[EXIM_LABEL_MAX]; /* zero terminated as in import */ +}; + +/* + * DLL record + */ +struct DLLRec { + uint8_t type; /* must be 4 */ + uint8_t reclen; /* content length */ + char libname[MODLIB_NAME_MAX]; /* name of library to link with at load time */ +}; + +/* + * BSS record + */ +struct BSSRec { + uint8_t type; /* must be 5 */ + uint8_t reclen; /* content length */ + int32_t amount; /* number of bytes BSS to reserve */ +}; + +/* + * Module name record + */ +struct ModRec { + uint8_t type; /* must be 8 */ + uint8_t reclen; /* content length */ + char modname[MODLIB_NAME_MAX]; /* module name */ +}; + +/* + * Common variable record + */ +struct CommonRec { + uint8_t type; /* must be 10 */ + uint8_t reclen; /* equals 7+label length */ + uint16_t segment; /* segment number */ + int32_t size; /* size of common variable */ + uint16_t align; /* alignment (power of two) */ + char label[EXIM_LABEL_MAX]; /* zero terminated as in import */ +}; + +/* Flags for ExportRec */ +#define SYM_DATA 1 +#define SYM_FUNCTION 2 +#define SYM_GLOBAL 4 +#define SYM_IMPORT 8 + +#endif /* RDOFF_H */ diff --git a/vere/ext/nasm/include/saa.h b/vere/ext/nasm/include/saa.h new file mode 100644 index 0000000..9d939ef --- /dev/null +++ b/vere/ext/nasm/include/saa.h @@ -0,0 +1,94 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2017 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +#ifndef NASM_SAA_H +#define NASM_SAA_H + +#include "compiler.h" + +/* + * Routines to manage a dynamic sequential-access array, under the + * same restriction on maximum mallocable block. This array may be + * written to in two ways: a contiguous chunk can be reserved of a + * given size with a pointer returned OR single-byte data may be + * written. The array can also be read back in the same two ways: + * as a series of big byte-data blocks or as a list of structures + * of a given size. + */ + +struct SAA { + /* + * members `end' and `elem_len' are only valid in first link in + * list; `rptr' and `rpos' are used for reading + */ + size_t elem_len; /* Size of each element */ + size_t blk_len; /* Size of each allocation block */ + size_t nblks; /* Total number of allocated blocks */ + size_t nblkptrs; /* Total number of allocation block pointers */ + size_t length; /* Total allocated length of the array */ + size_t datalen; /* Total data length of the array */ + char **wblk; /* Write block pointer */ + size_t wpos; /* Write position inside block */ + size_t wptr; /* Absolute write position */ + char **rblk; /* Read block pointer */ + size_t rpos; /* Read position inside block */ + size_t rptr; /* Absolute read position */ + char **blk_ptrs; /* Pointer to pointer blocks */ +}; + +struct SAA * never_null saa_init(size_t elem_len); /* 1 == byte */ +void saa_free(struct SAA *); +void *saa_wstruct(struct SAA *); /* return a structure of elem_len */ +void saa_wbytes(struct SAA *, const void *, size_t); /* write arbitrary bytes */ +size_t saa_wcstring(struct SAA *s, const char *str); /* write a C string */ +void saa_rewind(struct SAA *); /* for reading from beginning */ +void *saa_rstruct(struct SAA *); /* return NULL on EOA */ +const void *saa_rbytes(struct SAA *, size_t *); /* return 0 on EOA */ +void saa_rnbytes(struct SAA *, void *, size_t); /* read a given no. of bytes */ +/* random access */ +void saa_fread(struct SAA *, size_t, void *, size_t); +void saa_fwrite(struct SAA *, size_t, const void *, size_t); + +/* dump to file */ +void saa_fpwrite(struct SAA *, FILE *); + +/* Write specific-sized values */ +void saa_write8(struct SAA *s, uint8_t v); +void saa_write16(struct SAA *s, uint16_t v); +void saa_write32(struct SAA *s, uint32_t v); +void saa_write64(struct SAA *s, uint64_t v); +void saa_wleb128u(struct SAA *, int); /* write unsigned LEB128 value */ +void saa_wleb128s(struct SAA *, int); /* write signed LEB128 value */ +void saa_writeaddr(struct SAA *, uint64_t, size_t); + +#endif /* NASM_SAA_H */ diff --git a/vere/ext/nasm/include/strlist.h b/vere/ext/nasm/include/strlist.h new file mode 100644 index 0000000..faf70e2 --- /dev/null +++ b/vere/ext/nasm/include/strlist.h @@ -0,0 +1,93 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2020 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * strlist.h - list of unique, ordered strings + */ + +#ifndef NASM_STRLIST_H +#define NASM_STRLIST_H + +#include "compiler.h" +#include "nasmlib.h" +#include "hashtbl.h" + +struct strlist_entry { + struct strlist_entry *next; + size_t offset; + size_t size; + intorptr pvt; + char str[1]; +}; + +struct strlist { + struct hash_table hash; + struct strlist_entry *head, **tailp; + size_t nstr, size; + bool uniq; +}; + +static inline const struct strlist_entry * +strlist_head(const struct strlist *list) +{ + return list ? list->head : NULL; +} +static inline struct strlist_entry *strlist_tail(struct strlist *list) +{ + if (!list || !list->head) + return NULL; + return container_of(list->tailp, struct strlist_entry, next); +} +static inline size_t strlist_count(const struct strlist *list) +{ + return list ? list->nstr : 0; +} +static inline size_t strlist_size(const struct strlist *list) +{ + return list ? list->size : 0; +} + +struct strlist * safe_alloc strlist_alloc(bool uniq); +const struct strlist_entry *strlist_add(struct strlist *list, const char *str); +const struct strlist_entry * printf_func(2, 3) + strlist_printf(struct strlist *list, const char *fmt, ...); +const struct strlist_entry * vprintf_func(2) + strlist_vprintf(struct strlist *list, const char *fmt, va_list ap); +const struct strlist_entry * +strlist_find(const struct strlist *list, const char *str); +void * safe_alloc strlist_linearize(const struct strlist *list, char sep); +void strlist_write(const struct strlist *list, const char *sep, FILE *f); +void strlist_free(struct strlist **listp); +#define strlist_for_each(p,h) list_for_each((p), strlist_head(h)) + +#endif /* NASM_STRLIST_H */ diff --git a/vere/ext/nasm/include/tables.h b/vere/ext/nasm/include/tables.h new file mode 100644 index 0000000..2b36357 --- /dev/null +++ b/vere/ext/nasm/include/tables.h @@ -0,0 +1,77 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2016 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * tables.h + * + * Declarations for auto-generated tables + */ + +#ifndef NASM_TABLES_H +#define NASM_TABLES_H + +#include "compiler.h" +#include "insnsi.h" /* For enum opcode */ + +/* --- From standard.mac via macros.pl: --- */ + +/* macros.c */ +extern const unsigned char nasm_stdmac_tasm[]; +extern const unsigned char nasm_stdmac_nasm[]; +extern const unsigned char nasm_stdmac_version[]; + +struct use_package { + const char *package; + const unsigned char *macros; + int index; +}; +extern const struct use_package *nasm_find_use_package(const char *); +extern const int use_package_count; + +/* --- From insns.dat via insns.pl: --- */ + +/* insnsn.c */ +extern const char * const nasm_insn_names[]; + +/* --- From regs.dat via regs.pl: --- */ + +/* regs.c */ +extern const char * const nasm_reg_names[]; +/* regflags.c */ +typedef uint64_t opflags_t; +typedef uint16_t decoflags_t; +extern const opflags_t nasm_reg_flags[]; +/* regvals.c */ +extern const int nasm_regvals[]; + +#endif /* NASM_TABLES_H */ diff --git a/vere/ext/nasm/include/ver.h b/vere/ext/nasm/include/ver.h new file mode 100644 index 0000000..a5bbf38 --- /dev/null +++ b/vere/ext/nasm/include/ver.h @@ -0,0 +1,55 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2020 The NASM Authors - All Rights Reserved + * See the file AUTHORS included with the NASM distribution for + * the specific copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ----------------------------------------------------------------------- */ + +/* + * NASM version strings, defined in ver.c + */ + +#ifndef NASM_VER_H +#define NASM_VER_H + +#include "compiler.h" + +extern const char nasm_version[]; +extern const char nasm_date[]; +extern const char nasm_compile_options[]; + +extern bool reproducible; + +extern const char *nasm_comment(void); +extern size_t nasm_comment_len(void); + +extern const char *nasm_signature(void); +extern size_t nasm_signature_len(void); + +#endif /* NASM_VER_H */ diff --git a/vere/ext/nasm/include/warnings.h b/vere/ext/nasm/include/warnings.h new file mode 100644 index 0000000..3707515 --- /dev/null +++ b/vere/ext/nasm/include/warnings.h @@ -0,0 +1,131 @@ +#ifndef NASM_WARNINGS_H +#define NASM_WARNINGS_H + +#ifndef WARN_SHR +# error "warnings.h should only be included from within error.h" +#endif + +enum warn_index { + WARN_IDX_NONE = 0, /* not suppressible */ + WARN_IDX_DB_EMPTY = 1, /* no operand for data declaration */ + WARN_IDX_EA_ABSOLUTE = 2, /* absolute address cannot be RIP-relative */ + WARN_IDX_EA_DISPSIZE = 3, /* displacement size ignored on absolute address */ + WARN_IDX_FLOAT_DENORM = 4, /* floating point denormal */ + WARN_IDX_FLOAT_OVERFLOW = 5, /* floating point overflow */ + WARN_IDX_FLOAT_TOOLONG = 6, /* too many digits in floating-point number */ + WARN_IDX_FLOAT_UNDERFLOW = 7, /* floating point underflow */ + WARN_IDX_FORWARD = 8, /* forward reference may have unpredictable results */ + WARN_IDX_LABEL_ORPHAN = 9, /* labels alone on lines without trailing `:' */ + WARN_IDX_LABEL_REDEF = 10, /* label redefined to an identical value */ + WARN_IDX_LABEL_REDEF_LATE = 11, /* label (re)defined during code generation */ + WARN_IDX_NUMBER_OVERFLOW = 12, /* numeric constant does not fit */ + WARN_IDX_OBSOLETE_NOP = 13, /* instruction obsolete and is a noop on the target CPU */ + WARN_IDX_OBSOLETE_REMOVED = 14, /* instruction obsolete and removed on the target CPU */ + WARN_IDX_OBSOLETE_VALID = 15, /* instruction obsolete but valid on the target CPU */ + WARN_IDX_PHASE = 16, /* phase error during stabilization */ + WARN_IDX_PP_ELSE_ELIF = 17, /* %elif after %else */ + WARN_IDX_PP_ELSE_ELSE = 18, /* %else after %else */ + WARN_IDX_PP_EMPTY_BRACES = 19, /* empty %{} construct */ + WARN_IDX_PP_ENVIRONMENT = 20, /* nonexistent environment variable */ + WARN_IDX_PP_MACRO_DEF_CASE_SINGLE = 21, /* single-line macro defined both case sensitive and insensitive */ + WARN_IDX_PP_MACRO_DEF_GREEDY_SINGLE = 22, /* single-line macro */ + WARN_IDX_PP_MACRO_DEF_PARAM_SINGLE = 23, /* single-line macro defined with and without parameters */ + WARN_IDX_PP_MACRO_DEFAULTS = 24, /* macros with more default than optional parameters */ + WARN_IDX_PP_MACRO_PARAMS_LEGACY = 25, /* improperly calling multi-line macro for legacy support */ + WARN_IDX_PP_MACRO_PARAMS_MULTI = 26, /* multi-line macro calls with wrong parameter count */ + WARN_IDX_PP_MACRO_PARAMS_SINGLE = 27, /* single-line macro calls with wrong parameter count */ + WARN_IDX_PP_MACRO_REDEF_MULTI = 28, /* redefining multi-line macro */ + WARN_IDX_PP_OPEN_BRACES = 29, /* unterminated %{...} */ + WARN_IDX_PP_OPEN_BRACKETS = 30, /* unterminated %[...] */ + WARN_IDX_PP_OPEN_STRING = 31, /* unterminated string */ + WARN_IDX_PP_REP_NEGATIVE = 32, /* regative %rep count */ + WARN_IDX_PP_SEL_RANGE = 33, /* %sel() argument out of range */ + WARN_IDX_PP_TRAILING = 34, /* trailing garbage ignored */ + WARN_IDX_PRAGMA_BAD = 35, /* malformed %pragma */ + WARN_IDX_PRAGMA_EMPTY = 36, /* empty %pragma directive */ + WARN_IDX_PRAGMA_NA = 37, /* %pragma not applicable to this compilation */ + WARN_IDX_PRAGMA_UNKNOWN = 38, /* unknown %pragma facility or directive */ + WARN_IDX_PREFIX_BND = 39, /* invalid BND prefix */ + WARN_IDX_PREFIX_HLE = 40, /* invalid HLE prefix */ + WARN_IDX_PREFIX_LOCK = 41, /* LOCK prefix on unlockable instructions */ + WARN_IDX_PREFIX_OPSIZE = 42, /* invalid operand size prefix */ + WARN_IDX_PREFIX_SEG = 43, /* segment prefix ignored in 64-bit mode */ + WARN_IDX_PTR = 44, /* non-NASM keyword used in other assemblers */ + WARN_IDX_REGSIZE = 45, /* register size specification ignored */ + WARN_IDX_UNKNOWN_WARNING = 46, /* unknown warning in -W/-w or warning directive */ + WARN_IDX_USER = 47, /* %warning directives */ + WARN_IDX_WARN_STACK_EMPTY = 48, /* warning stack empty */ + WARN_IDX_ZEROING = 49, /* RESx in initialized section becomes zero */ + WARN_IDX_ZEXT_RELOC = 50, /* relocation zero-extended to match output format */ + WARN_IDX_OTHER = 51, /* any warning not specifically mentioned above */ + WARN_IDX_ALL = 52 /* all possible warnings */ +}; + +enum warn_const { + WARN_NONE = 0 << WARN_SHR, + WARN_DB_EMPTY = 1 << WARN_SHR, + WARN_EA_ABSOLUTE = 2 << WARN_SHR, + WARN_EA_DISPSIZE = 3 << WARN_SHR, + WARN_FLOAT_DENORM = 4 << WARN_SHR, + WARN_FLOAT_OVERFLOW = 5 << WARN_SHR, + WARN_FLOAT_TOOLONG = 6 << WARN_SHR, + WARN_FLOAT_UNDERFLOW = 7 << WARN_SHR, + WARN_FORWARD = 8 << WARN_SHR, + WARN_LABEL_ORPHAN = 9 << WARN_SHR, + WARN_LABEL_REDEF = 10 << WARN_SHR, + WARN_LABEL_REDEF_LATE = 11 << WARN_SHR, + WARN_NUMBER_OVERFLOW = 12 << WARN_SHR, + WARN_OBSOLETE_NOP = 13 << WARN_SHR, + WARN_OBSOLETE_REMOVED = 14 << WARN_SHR, + WARN_OBSOLETE_VALID = 15 << WARN_SHR, + WARN_PHASE = 16 << WARN_SHR, + WARN_PP_ELSE_ELIF = 17 << WARN_SHR, + WARN_PP_ELSE_ELSE = 18 << WARN_SHR, + WARN_PP_EMPTY_BRACES = 19 << WARN_SHR, + WARN_PP_ENVIRONMENT = 20 << WARN_SHR, + WARN_PP_MACRO_DEF_CASE_SINGLE = 21 << WARN_SHR, + WARN_PP_MACRO_DEF_GREEDY_SINGLE = 22 << WARN_SHR, + WARN_PP_MACRO_DEF_PARAM_SINGLE = 23 << WARN_SHR, + WARN_PP_MACRO_DEFAULTS = 24 << WARN_SHR, + WARN_PP_MACRO_PARAMS_LEGACY = 25 << WARN_SHR, + WARN_PP_MACRO_PARAMS_MULTI = 26 << WARN_SHR, + WARN_PP_MACRO_PARAMS_SINGLE = 27 << WARN_SHR, + WARN_PP_MACRO_REDEF_MULTI = 28 << WARN_SHR, + WARN_PP_OPEN_BRACES = 29 << WARN_SHR, + WARN_PP_OPEN_BRACKETS = 30 << WARN_SHR, + WARN_PP_OPEN_STRING = 31 << WARN_SHR, + WARN_PP_REP_NEGATIVE = 32 << WARN_SHR, + WARN_PP_SEL_RANGE = 33 << WARN_SHR, + WARN_PP_TRAILING = 34 << WARN_SHR, + WARN_PRAGMA_BAD = 35 << WARN_SHR, + WARN_PRAGMA_EMPTY = 36 << WARN_SHR, + WARN_PRAGMA_NA = 37 << WARN_SHR, + WARN_PRAGMA_UNKNOWN = 38 << WARN_SHR, + WARN_PREFIX_BND = 39 << WARN_SHR, + WARN_PREFIX_HLE = 40 << WARN_SHR, + WARN_PREFIX_LOCK = 41 << WARN_SHR, + WARN_PREFIX_OPSIZE = 42 << WARN_SHR, + WARN_PREFIX_SEG = 43 << WARN_SHR, + WARN_PTR = 44 << WARN_SHR, + WARN_REGSIZE = 45 << WARN_SHR, + WARN_UNKNOWN_WARNING = 46 << WARN_SHR, + WARN_USER = 47 << WARN_SHR, + WARN_WARN_STACK_EMPTY = 48 << WARN_SHR, + WARN_ZEROING = 49 << WARN_SHR, + WARN_ZEXT_RELOC = 50 << WARN_SHR, + WARN_OTHER = 51 << WARN_SHR +}; + +struct warning_alias { + const char *name; + enum warn_index warning; +}; + +#define NUM_WARNING_ALIAS 68 +extern const char * const warning_name[53]; +extern const char * const warning_help[53]; +extern const struct warning_alias warning_alias[NUM_WARNING_ALIAS]; +extern const uint8_t warning_default[52]; +extern uint8_t warning_state[52]; + +#endif /* NASM_WARNINGS_H */ |