├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── asm ├── assemble.c ├── assemble.h ├── directbl.c ├── directiv.c ├── directiv.dat ├── directiv.h ├── error.c ├── eval.c ├── eval.h ├── exprdump.c ├── exprlib.c ├── floats.c ├── floats.h ├── labels.c ├── listing.c ├── listing.h ├── nasm.c ├── parser.c ├── parser.h ├── pptok.c ├── pptok.dat ├── pptok.h ├── pptok.pl ├── pragma.c ├── preproc.c ├── preproc.h ├── quote.c ├── quote.h ├── rdstrnum.c ├── segalloc.c ├── srcfile.c ├── srcfile.h ├── stdscan.c ├── stdscan.h ├── strfunc.c ├── tokens.dat ├── tokens.h ├── tokhash.c ├── tokhash.pl ├── warnings.c └── warnings.pl ├── build.zig ├── build.zig.zon ├── common └── common.c ├── config ├── config.h.in ├── msvc.h ├── unconfig.h ├── unknown.h └── watcom.h ├── disasm ├── disasm.c ├── disasm.h ├── ndisasm.c ├── sync.c └── sync.h ├── headers ├── c ├── doc ├── mac └── perl ├── include ├── bytesex.h ├── compiler.h ├── dbginfo.h ├── disp8.h ├── error.h ├── hashtbl.h ├── iflag.h ├── ilog2.h ├── insns.h ├── labels.h ├── md5.h ├── nasm.h ├── nasmint.h ├── nasmlib.h ├── nctype.h ├── opflags.h ├── perfhash.h ├── raa.h ├── rbtree.h ├── rdoff.h ├── saa.h ├── strlist.h ├── tables.h ├── ver.h └── warnings.h ├── macros ├── altreg.mac ├── fp.mac ├── ifunc.mac ├── macros.c ├── macros.pl ├── masm.mac ├── smartalign.mac └── standard.mac ├── misc ├── Doxyfile ├── Nindent ├── README ├── c16.mac ├── c32.mac ├── crcgen.c ├── emacstbl.pl ├── exebin.mac ├── exebin2.mac ├── fmtinsns.pl ├── genfma.pl ├── hints.txt ├── magic ├── myC32.mac ├── nasm.sl ├── nasmstab ├── omfdump.c ├── pmw.bat ├── proc32.ash ├── scitech.mac └── xcrcgen.c ├── nasmlib ├── alloc.c ├── alloc.h ├── asprintf.c ├── badenum.c ├── bsi.c ├── crc32.c ├── crc64.c ├── errfile.c ├── file.c ├── file.h ├── filename.c ├── hashtbl.c ├── ilog2.c ├── md5c.c ├── mmap.c ├── nctype.c ├── path.c ├── perfhash.c ├── perfhash.pl ├── raa.c ├── rbtree.c ├── readnum.c ├── realpath.c ├── rlimit.c ├── saa.c ├── string.c ├── strlist.c ├── ver.c └── zerobuf.c ├── output ├── codeview.c ├── dwarf.h ├── elf.h ├── legacy.c ├── macho.h ├── nulldbg.c ├── nullout.c ├── outaout.c ├── outaout.mac ├── outas86.c ├── outas86.mac ├── outbin.c ├── outbin.mac ├── outcoff.c ├── outcoff.mac ├── outdbg.c ├── outdbg.mac ├── outelf.c ├── outelf.h ├── outelf.mac ├── outform.c ├── outform.h ├── outieee.c ├── outlib.c ├── outlib.h ├── outmacho.c ├── outmacho.mac ├── outobj.c ├── outobj.mac ├── pecoff.h └── stabs.h ├── perllib ├── crc64.ph ├── gensv.pl ├── phash.ph └── random_sv_vectors.ph ├── stdlib ├── snprintf.c ├── strlcpy.c ├── strnlen.c ├── strrchrnul.c └── vsnprintf.c └── x86 ├── disp8.c ├── iflag.c ├── iflaggen.h ├── iflags.ph ├── insns-iflags.ph ├── insns.dat ├── insns.pl ├── insnsa.c ├── insnsb.c ├── insnsd.c ├── insnsi.h ├── insnsn.c ├── regdis.c ├── regflags.c ├── regs.c ├── regs.dat ├── regs.h ├── regs.pl └── regvals.c /.gitattributes: -------------------------------------------------------------------------------- 1 | /version -merge 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.zig-cache/ 2 | /zig-out/ 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | NASM is now licensed under the 2-clause BSD license, also known as the 2 | simplified BSD license. 3 | 4 | Copyright 1996-2010 the NASM Authors - All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following 8 | conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials provided 15 | with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 18 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a fork of [NASM](https://nasm.us/), packaged for Zig. Unnecessary files 2 | have been deleted, and the build system has been replaced with `build.zig`. 3 | 4 | Original README follows: 5 | 6 | ---------------------------------------------------------------------------- 7 | 8 | NASM, the Netwide Assembler 9 | =========================== 10 | 11 | [![master](https://travis-ci.org/netwide-assembler/nasm.svg?branch=master)](https://travis-ci.org/netwide-assembler/nasm) 12 | 13 | Many many developers all over the net respect NASM for what it is: 14 | a widespread (thus netwide), portable (thus netwide!), very flexible 15 | and mature assembler tool with support for many output formats (thus netwide!!). 16 | 17 | Now we have good news for you: NASM is licensed under the "simplified" 18 | [(2-clause) BSD license](https://opensource.org/licenses/BSD-2-Clause). 19 | This means its development is open to even wider society of programmers 20 | wishing to improve their lovely assembler. 21 | 22 | Visit our [nasm.us](https://www.nasm.us/) website for more details. 23 | 24 | With best regards, the NASM crew. 25 | -------------------------------------------------------------------------------- /asm/assemble.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2017 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * assemble.h - header file for stuff private to the assembler 36 | */ 37 | 38 | #ifndef NASM_ASSEMBLE_H 39 | #define NASM_ASSEMBLE_H 40 | 41 | #include "nasm.h" 42 | #include "iflag.h" 43 | 44 | extern iflag_t cpu, cmd_cpu; 45 | void set_cpu(const char *cpuspec); 46 | 47 | extern bool in_absolute; /* Are we in an absolute segment? */ 48 | extern struct location absolute; 49 | 50 | int64_t insn_size(int32_t segment, int64_t offset, int bits, insn *instruction); 51 | int64_t assemble(int32_t segment, int64_t offset, int bits, insn *instruction); 52 | 53 | bool process_directives(char *); 54 | void process_pragma(char *); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /asm/directbl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is generated from ./asm/directiv.dat 3 | * by perfhash.pl; do not edit. 4 | */ 5 | 6 | #include "directiv.h" 7 | 8 | const char * const directive_tbl[40] = { 9 | "absolute", 10 | "bits", 11 | "common", 12 | "cpu", 13 | "debug", 14 | "default", 15 | "extern", 16 | "float", 17 | "global", 18 | "static", 19 | "list", 20 | "section", 21 | "segment", 22 | "warning", 23 | "sectalign", 24 | "pragma", 25 | "required", 26 | "export", 27 | "group", 28 | "import", 29 | "library", 30 | "map", 31 | "module", 32 | "org", 33 | "osabi", 34 | "safeseh", 35 | "uppercase", 36 | "prefix", 37 | "suffix", 38 | "gprefix", 39 | "gsuffix", 40 | "lprefix", 41 | "lsuffix", 42 | "limit", 43 | "options", 44 | "subsections_via_symbols", 45 | "no_dead_strip", 46 | "maxdump", 47 | "nodepend", 48 | "noseclabels" 49 | }; 50 | 51 | #define INVALID_HASH_ENTRY (65536/3) 52 | 53 | static const int16_t directive_hashvals[128] = { 54 | 0, 55 | INVALID_HASH_ENTRY, 56 | 0, 57 | INVALID_HASH_ENTRY, 58 | 0, 59 | INVALID_HASH_ENTRY, 60 | 0, 61 | 6, 62 | 0, 63 | 0, 64 | INVALID_HASH_ENTRY, 65 | 0, 66 | INVALID_HASH_ENTRY, 67 | INVALID_HASH_ENTRY, 68 | 0, 69 | 3, 70 | INVALID_HASH_ENTRY, 71 | 0, 72 | 0, 73 | 0, 74 | 32, 75 | 0, 76 | 4, 77 | 0, 78 | 0, 79 | INVALID_HASH_ENTRY, 80 | INVALID_HASH_ENTRY, 81 | INVALID_HASH_ENTRY, 82 | 12, 83 | INVALID_HASH_ENTRY, 84 | INVALID_HASH_ENTRY, 85 | 0, 86 | INVALID_HASH_ENTRY, 87 | 0, 88 | INVALID_HASH_ENTRY, 89 | INVALID_HASH_ENTRY, 90 | 1, 91 | INVALID_HASH_ENTRY, 92 | 0, 93 | 33, 94 | INVALID_HASH_ENTRY, 95 | 0, 96 | INVALID_HASH_ENTRY, 97 | INVALID_HASH_ENTRY, 98 | 0, 99 | 0, 100 | 0, 101 | INVALID_HASH_ENTRY, 102 | INVALID_HASH_ENTRY, 103 | INVALID_HASH_ENTRY, 104 | INVALID_HASH_ENTRY, 105 | 25, 106 | 38, 107 | 1, 108 | 9, 109 | INVALID_HASH_ENTRY, 110 | 31, 111 | INVALID_HASH_ENTRY, 112 | 0, 113 | INVALID_HASH_ENTRY, 114 | INVALID_HASH_ENTRY, 115 | INVALID_HASH_ENTRY, 116 | -12, 117 | 0, 118 | INVALID_HASH_ENTRY, 119 | 34, 120 | INVALID_HASH_ENTRY, 121 | INVALID_HASH_ENTRY, 122 | 0, 123 | INVALID_HASH_ENTRY, 124 | INVALID_HASH_ENTRY, 125 | 29, 126 | INVALID_HASH_ENTRY, 127 | 13, 128 | INVALID_HASH_ENTRY, 129 | INVALID_HASH_ENTRY, 130 | INVALID_HASH_ENTRY, 131 | INVALID_HASH_ENTRY, 132 | 0, 133 | INVALID_HASH_ENTRY, 134 | INVALID_HASH_ENTRY, 135 | 27, 136 | INVALID_HASH_ENTRY, 137 | 7, 138 | 22, 139 | 0, 140 | INVALID_HASH_ENTRY, 141 | INVALID_HASH_ENTRY, 142 | 19, 143 | INVALID_HASH_ENTRY, 144 | 37, 145 | 5, 146 | -11, 147 | INVALID_HASH_ENTRY, 148 | INVALID_HASH_ENTRY, 149 | INVALID_HASH_ENTRY, 150 | INVALID_HASH_ENTRY, 151 | INVALID_HASH_ENTRY, 152 | INVALID_HASH_ENTRY, 153 | INVALID_HASH_ENTRY, 154 | 16, 155 | 15, 156 | 11, 157 | INVALID_HASH_ENTRY, 158 | 23, 159 | INVALID_HASH_ENTRY, 160 | INVALID_HASH_ENTRY, 161 | 0, 162 | 36, 163 | 12, 164 | INVALID_HASH_ENTRY, 165 | INVALID_HASH_ENTRY, 166 | INVALID_HASH_ENTRY, 167 | 27, 168 | INVALID_HASH_ENTRY, 169 | 21, 170 | 26, 171 | 10, 172 | 5, 173 | 29, 174 | 35, 175 | INVALID_HASH_ENTRY, 176 | INVALID_HASH_ENTRY, 177 | 30, 178 | INVALID_HASH_ENTRY, 179 | 28, 180 | 4, 181 | INVALID_HASH_ENTRY 182 | }; 183 | 184 | const struct perfect_hash directive_hash = { 185 | UINT64_C(0x076259c3e291c26c), 186 | UINT32_C(0x7e), 187 | UINT32_C(40), 188 | 3, 189 | (D_unknown), 190 | directive_hashvals, 191 | directive_tbl 192 | }; 193 | -------------------------------------------------------------------------------- /asm/directiv.dat: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2017 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | ;; 34 | ;; List of global NASM directives and pragma operations codes 35 | ;; 36 | ;; ALL directives, including backend-specific, need to be added here. 37 | ;; 38 | ;; %pragma operation keywords (the second word, after facility) MAY 39 | ;; be added here too to assist in parsing, but it is not required. 40 | ;; See the definition of struct pragma in include/nasm.h. 41 | ;; 42 | ;; The same keyword can be used as a directive and as a pragma 43 | ;; operation, or as pragma operations in different namespaces. The 44 | ;; same D_ constant will be used for both, and this is perfectly 45 | ;; acceptable. 46 | ;; 47 | ;; In the future, this will be turned into a general list of keywords 48 | ;; to be parsed in special contexts. 49 | ;; 50 | 51 | ; --- General configuration 52 | #name directive 53 | #prefix D_ 54 | #errval D_unknown 55 | #header directiv.h 56 | 57 | ; --- Special enum values 58 | #special none = 0 ; Must be zero 59 | #special unknown 60 | #special corrupt 61 | 62 | ; --- Global directives 63 | absolute 64 | bits 65 | common 66 | cpu 67 | debug 68 | default 69 | extern 70 | float 71 | global 72 | static 73 | list 74 | section 75 | segment 76 | warning 77 | sectalign 78 | pragma 79 | required 80 | 81 | ; --- Format-specific directives 82 | export ; outcoff, outobj 83 | group ; outobj 84 | import ; outobj 85 | library ; outrdf2 86 | map ; outbin 87 | module ; outrdf2 88 | org ; outbin 89 | osabi ; outelf 90 | safeseh ; outcoff 91 | uppercase ; outieee, outobj 92 | 93 | ; --- Assembler pragmas 94 | prefix 95 | suffix 96 | gprefix 97 | gsuffix 98 | lprefix 99 | lsuffix 100 | limit 101 | 102 | ; --- Listing pragmas 103 | options 104 | 105 | ; --- Backend pragmas 106 | subsections_via_symbols ; macho 107 | no_dead_strip ; macho 108 | maxdump ; dbg 109 | nodepend ; obj 110 | noseclabels ; dbg 111 | -------------------------------------------------------------------------------- /asm/directiv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is generated from ./asm/directiv.dat 3 | * by perfhash.pl; do not edit. 4 | */ 5 | 6 | #ifndef DIRECTIV_H 7 | #define DIRECTIV_H 1 8 | 9 | #include "perfhash.h" 10 | 11 | enum directive { 12 | D_none, 13 | D_unknown, 14 | D_corrupt, 15 | D_ABSOLUTE, 16 | D_BITS, 17 | D_COMMON, 18 | D_CPU, 19 | D_DEBUG, 20 | D_DEFAULT, 21 | D_EXTERN, 22 | D_FLOAT, 23 | D_GLOBAL, 24 | D_STATIC, 25 | D_LIST, 26 | D_SECTION, 27 | D_SEGMENT, 28 | D_WARNING, 29 | D_SECTALIGN, 30 | D_PRAGMA, 31 | D_REQUIRED, 32 | D_EXPORT, 33 | D_GROUP, 34 | D_IMPORT, 35 | D_LIBRARY, 36 | D_MAP, 37 | D_MODULE, 38 | D_ORG, 39 | D_OSABI, 40 | D_SAFESEH, 41 | D_UPPERCASE, 42 | D_PREFIX, 43 | D_SUFFIX, 44 | D_GPREFIX, 45 | D_GSUFFIX, 46 | D_LPREFIX, 47 | D_LSUFFIX, 48 | D_LIMIT, 49 | D_OPTIONS, 50 | D_SUBSECTIONS_VIA_SYMBOLS, 51 | D_NO_DEAD_STRIP, 52 | D_MAXDUMP, 53 | D_NODEPEND, 54 | D_NOSECLABELS 55 | }; 56 | 57 | extern const struct perfect_hash directive_hash; 58 | extern const char * const directive_tbl[40]; 59 | 60 | static inline enum directive directive_find(const char *str) 61 | { 62 | return perfhash_find(&directive_hash, str); 63 | } 64 | 65 | static inline const char * directive_name(enum directive x) 66 | { 67 | size_t ix = (size_t)x - (3); 68 | if (ix >= 40) 69 | return NULL; 70 | return directive_tbl[ix]; 71 | } 72 | 73 | static inline const char * directive_dname(enum directive x) 74 | { 75 | const char *y = directive_name(x); 76 | return y ? y : invalid_enum_str(x); 77 | } 78 | 79 | #endif /* DIRECTIV_H */ 80 | -------------------------------------------------------------------------------- /asm/eval.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * eval.h header file for eval.c 36 | */ 37 | 38 | #ifndef NASM_EVAL_H 39 | #define NASM_EVAL_H 40 | 41 | /* 42 | * The evaluator itself. 43 | */ 44 | expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv, 45 | int *fwref, bool critical, struct eval_hints *hints); 46 | 47 | void eval_cleanup(void); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /asm/exprdump.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2017 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * exprdump.c 36 | * 37 | * Debugging code to dump the contents of an expression vector to stdout 38 | */ 39 | 40 | #include "nasm.h" 41 | 42 | static const char *expr_type(int32_t type) 43 | { 44 | static char seg_str[64]; 45 | 46 | switch (type) { 47 | case 0: 48 | return "null"; 49 | case EXPR_UNKNOWN: 50 | return "unknown"; 51 | case EXPR_SIMPLE: 52 | return "simple"; 53 | case EXPR_WRT: 54 | return "wrt"; 55 | case EXPR_RDSAE: 56 | return "sae"; 57 | default: 58 | break; 59 | } 60 | 61 | if (type >= EXPR_REG_START && type <= EXPR_REG_END) { 62 | return nasm_reg_names[type - EXPR_REG_START]; 63 | } else if (type >= EXPR_SEGBASE) { 64 | snprintf(seg_str, sizeof seg_str, "%sseg %d", 65 | (type - EXPR_SEGBASE) == location.segment ? "this " : "", 66 | type - EXPR_SEGBASE); 67 | return seg_str; 68 | } else { 69 | return "ERR"; 70 | } 71 | } 72 | 73 | void dump_expr(const expr *e) 74 | { 75 | printf("["); 76 | for (; e->type; e++) 77 | printf("<%s(%d),%"PRId64">", expr_type(e->type), e->type, e->value); 78 | printf("]\n"); 79 | } 80 | -------------------------------------------------------------------------------- /asm/floats.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2020 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * floats.h header file for the floating-point constant module of 36 | * the Netwide Assembler 37 | */ 38 | 39 | #ifndef NASM_FLOATS_H 40 | #define NASM_FLOATS_H 41 | 42 | #include "nasm.h" 43 | 44 | enum float_round { 45 | FLOAT_RC_NEAR, 46 | FLOAT_RC_ZERO, 47 | FLOAT_RC_DOWN, 48 | FLOAT_RC_UP 49 | }; 50 | 51 | /* Note: enum floatize and FLOAT_ERR are defined in nasm.h */ 52 | 53 | /* Floating-point format description */ 54 | struct ieee_format { 55 | int bytes; /* Total bytes */ 56 | int mantissa; /* Fractional bits in the mantissa */ 57 | int explicit; /* Explicit integer */ 58 | int exponent; /* Bits in the exponent */ 59 | int offset; /* Offset into byte array for floatize op */ 60 | }; 61 | extern const struct ieee_format fp_formats[FLOAT_ERR]; 62 | 63 | int float_const(const char *str, int s, uint8_t *result, enum floatize ffmt); 64 | enum floatize float_deffmt(int bytes); 65 | int float_option(const char *option); 66 | 67 | #endif /* NASM_FLOATS_H */ 68 | -------------------------------------------------------------------------------- /asm/parser.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * parser.h header file for the parser module of the Netwide 36 | * Assembler 37 | */ 38 | 39 | #ifndef NASM_PARSER_H 40 | #define NASM_PARSER_H 41 | 42 | insn *parse_line(char *buffer, insn *result); 43 | void cleanup_insn(insn *instruction); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /asm/pptok.dat: -------------------------------------------------------------------------------- 1 | ## -------------------------------------------------------------------------- 2 | ## 3 | ## Copyright 1996-2019 The NASM Authors - All Rights Reserved 4 | ## See the file AUTHORS included with the NASM distribution for 5 | ## the specific copyright holders. 6 | ## 7 | ## Redistribution and use in source and binary forms, with or without 8 | ## modification, are permitted provided that the following 9 | ## conditions are met: 10 | ## 11 | ## * Redistributions of source code must retain the above copyright 12 | ## notice, this list of conditions and the following disclaimer. 13 | ## * Redistributions in binary form must reproduce the above 14 | ## copyright notice, this list of conditions and the following 15 | ## disclaimer in the documentation and/or other materials provided 16 | ## with the distribution. 17 | ## 18 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ## 32 | ## -------------------------------------------------------------------------- 33 | 34 | # 35 | # A * at the end indicates a condition; the list of conditions are 36 | # on lines starting with *; the negatives are auto-generated 37 | # 38 | 39 | # Condition stems. %if MUST BE FIRST in this list. 40 | %if* 41 | %elif* 42 | 43 | # Condition tests. 44 | * 45 | *ctx 46 | *def 47 | *defalias 48 | *difi 49 | *empty 50 | *env 51 | *id 52 | *idn 53 | *idni 54 | *macro 55 | *num 56 | *str 57 | *token 58 | *usable 59 | *using 60 | 61 | # Directives with -i- versions for case insensitive 62 | %!assign 63 | %!defalias 64 | %!define 65 | %!defstr 66 | %!deftok 67 | %!macro 68 | %!pathsearch 69 | %!rmacro 70 | %!strcat 71 | %!strlen 72 | %!substr 73 | %!xdefine 74 | %un!macro 75 | 76 | # Other directives 77 | %aliases 78 | %arg 79 | %clear 80 | %depend 81 | %else 82 | %endif 83 | %endm 84 | %endmacro 85 | %endrep 86 | %error 87 | %exitmacro 88 | %exitrep 89 | %fatal 90 | %include 91 | %line 92 | %local 93 | %null 94 | %pop 95 | %pragma 96 | %push 97 | %rep 98 | %repl 99 | %require 100 | %rotate 101 | %stacksize 102 | %undef 103 | %undefalias 104 | %use 105 | %warning 106 | 107 | # These directives do not require % in TASM-compatible mode 108 | @arg 109 | @elif 110 | @else 111 | @endif 112 | @if 113 | @ifdef 114 | @ifdifi 115 | @ifndef 116 | @include 117 | @local 118 | -------------------------------------------------------------------------------- /asm/preproc.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2020 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * preproc.h header file for preproc.c 36 | */ 37 | 38 | #ifndef NASM_PREPROC_H 39 | #define NASM_PREPROC_H 40 | 41 | #include "nasmlib.h" 42 | #include "pptok.h" 43 | 44 | extern const char * const pp_directives[]; 45 | extern const uint8_t pp_directives_len[]; 46 | 47 | /* Pointer to a macro chain */ 48 | typedef const unsigned char macros_t; 49 | 50 | enum preproc_token pp_token_hash(const char *token); 51 | enum preproc_token pp_tasm_token_hash(const char *token); 52 | 53 | /* Opens an include file or input file. This uses the include path. */ 54 | FILE *pp_input_fopen(const char *filename, enum file_flags mode); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /asm/quote.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #ifndef NASM_QUOTE_H 35 | #define NASM_QUOTE_H 36 | 37 | #include "compiler.h" 38 | 39 | char *nasm_quote(const char *str, size_t *len); 40 | char *nasm_quote_cstr(const char *str, size_t *len); 41 | size_t nasm_unquote_anystr(char *str, char **endptr, 42 | uint32_t badctl, char qstart); 43 | size_t nasm_unquote(char *str, char **endptr); 44 | size_t nasm_unquote_cstr(char *str, char **endptr); 45 | char *nasm_skip_string(const char *str); 46 | 47 | /* Arguments used with nasm_quote_anystr() */ 48 | 49 | /* 50 | * These are the only control characters when we produce a C string: 51 | * BEL BS TAB ESC 52 | */ 53 | #define OKCTL ((1U << '\a') | (1U << '\b') | (1U << '\t') | (1U << 27)) 54 | #define BADCTL (~(uint32_t)OKCTL) 55 | 56 | /* Initial quotation mark */ 57 | #define STR_C '\"' 58 | #define STR_NASM '`' 59 | 60 | #endif /* NASM_QUOTE_H */ 61 | 62 | -------------------------------------------------------------------------------- /asm/rdstrnum.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2016 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * rdstrnum.c 36 | * 37 | * This converts a NASM string to an integer, used when a string 38 | * is used in an integer constant context. This is a binary conversion, 39 | * not a conversion from a numeric constant in text form. 40 | */ 41 | 42 | #include "compiler.h" 43 | #include "nasmlib.h" 44 | #include "nasm.h" 45 | 46 | int64_t readstrnum(char *str, int length, bool *warn) 47 | { 48 | int64_t charconst = 0; 49 | int i; 50 | 51 | *warn = false; 52 | 53 | str += length; 54 | if (globalbits == 64) { 55 | for (i = 0; i < length; i++) { 56 | if (charconst & UINT64_C(0xFF00000000000000)) 57 | *warn = true; 58 | charconst &= ~UINT64_C(0xFF00000000000000); 59 | charconst = (charconst << 8) + (uint8_t)*--str; 60 | } 61 | } else { 62 | for (i = 0; i < length; i++) { 63 | if (charconst & UINT32_C(0xFF000000)) 64 | *warn = true; 65 | charconst &= ~UINT32_C(0xFF000000); 66 | charconst = (charconst << 8) + (uint8_t)*--str; 67 | } 68 | } 69 | return charconst; 70 | } 71 | -------------------------------------------------------------------------------- /asm/segalloc.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2018 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * nasmlib.c library routines for the Netwide Assembler 36 | */ 37 | 38 | #include "compiler.h" 39 | #include "nasm.h" 40 | #include "nasmlib.h" 41 | #include "insns.h" 42 | 43 | static int32_t next_seg = 2; 44 | 45 | int32_t seg_alloc(void) 46 | { 47 | int32_t this_seg = next_seg; 48 | 49 | next_seg += 2; 50 | return this_seg; 51 | } 52 | -------------------------------------------------------------------------------- /asm/srcfile.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2020 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * srcfile.c - keep track of the current position in the input stream. 36 | * 37 | * This is used for error messages, listing, and debug information. In 38 | * both cases we also want to understand where inside a non-nolist 39 | * macro we may be. 40 | * 41 | * This hierarchy is a stack that is kept as a doubly-linked list, as 42 | * we want to traverse it in either top-down order or bottom-up. 43 | */ 44 | 45 | #include "compiler.h" 46 | 47 | 48 | #include "nasmlib.h" 49 | #include "hashtbl.h" 50 | #include "srcfile.h" 51 | 52 | struct src_location_stack _src_top; 53 | struct src_location_stack *_src_bottom = &_src_top; 54 | struct src_location_stack *_src_error = &_src_top; 55 | 56 | static struct hash_table filename_hash; 57 | 58 | void src_init(void) 59 | { 60 | } 61 | 62 | void src_free(void) 63 | { 64 | hash_free_all(&filename_hash, false); 65 | } 66 | 67 | /* 68 | * Set the current filename, returning the old one. The input 69 | * filename is duplicated if needed. 70 | */ 71 | const char *src_set_fname(const char *newname) 72 | { 73 | struct hash_insert hi; 74 | const char *oldname; 75 | void **dp; 76 | 77 | if (newname) { 78 | dp = hash_find(&filename_hash, newname, &hi); 79 | if (dp) { 80 | newname = (const char *)(*dp); 81 | } else { 82 | newname = nasm_strdup(newname); 83 | hash_add(&hi, newname, (void *)newname); 84 | } 85 | } 86 | 87 | oldname = _src_bottom->l.filename; 88 | _src_bottom->l.filename = newname; 89 | return oldname; 90 | } 91 | 92 | void src_set(int32_t line, const char *fname) 93 | { 94 | src_set_fname(fname); 95 | src_set_linnum(line); 96 | } 97 | 98 | void src_macro_push(const void *macro, struct src_location where) 99 | { 100 | struct src_location_stack *sl; 101 | 102 | nasm_new(sl); 103 | sl->l = where; 104 | sl->macro = macro; 105 | sl->up = _src_bottom; 106 | _src_bottom->down = sl; 107 | _src_bottom = sl; 108 | } 109 | 110 | void src_macro_pop(void) 111 | { 112 | struct src_location_stack *sl = _src_bottom; 113 | 114 | _src_bottom = sl->up; 115 | _src_bottom->down = NULL; 116 | 117 | nasm_free(sl); 118 | } 119 | -------------------------------------------------------------------------------- /asm/stdscan.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * stdscan.h header file for stdscan.c 36 | */ 37 | 38 | #ifndef NASM_STDSCAN_H 39 | #define NASM_STDSCAN_H 40 | 41 | /* Standard scanner */ 42 | void stdscan_set(char *str); 43 | char *stdscan_get(void); 44 | void stdscan_reset(void); 45 | int stdscan(void *private_data, struct tokenval *tv); 46 | int nasm_token_hash(const char *token, struct tokenval *tv); 47 | void stdscan_cleanup(void); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /asm/tokens.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is generated from insns.dat, regs.dat and token.dat 3 | * by tokhash.pl; do not edit. 4 | */ 5 | 6 | #ifndef NASM_TOKENS_H 7 | #define NASM_TOKENS_H 8 | 9 | #define MAX_KEYWORD 17 /* length of longest keyword */ 10 | 11 | #endif /* NASM_TOKENS_H */ 12 | -------------------------------------------------------------------------------- /build.zig.zon: -------------------------------------------------------------------------------- 1 | .{ 2 | .name = .nasm, 3 | .version = "2.16.1-4", 4 | .fingerprint = 0x84b9c9eb77047d27, 5 | .minimum_zig_version = "0.14.0", 6 | .paths = .{ 7 | "LICENSE", 8 | "README.md", 9 | "asm", 10 | "build.zig", 11 | "build.zig.zon", 12 | "common", 13 | "config", 14 | "disasm", 15 | "headers", 16 | "include", 17 | "macros", 18 | "misc", 19 | "nasmlib", 20 | "output", 21 | "perllib", 22 | "stdlib", 23 | "x86", 24 | }, 25 | } 26 | -------------------------------------------------------------------------------- /common/common.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2021 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * common.c - code common to nasm and ndisasm 36 | */ 37 | 38 | #include "compiler.h" 39 | #include "nasm.h" 40 | #include "nasmlib.h" 41 | #include "insns.h" 42 | 43 | /* 44 | * The current bit size of the CPU 45 | */ 46 | int globalbits = 0; 47 | /* 48 | * Common list of prefix names; ideally should be auto-generated 49 | * from tokens.dat. This MUST match the enum in include/nasm.h. 50 | */ 51 | const char *prefix_name(int token) 52 | { 53 | static const char *prefix_names[] = { 54 | "a16", "a32", "a64", "asp", "lock", "o16", "o32", "o64", "osp", 55 | "rep", "repe", "repne", "repnz", "repz", "times", "wait", 56 | "xacquire", "xrelease", "bnd", "nobnd", "{rex}", "{evex}", "{vex}", 57 | "{vex3}", "{vex2}" 58 | }; 59 | unsigned int prefix = token-PREFIX_ENUM_START; 60 | 61 | if (prefix >= ARRAY_SIZE(prefix_names)) 62 | return NULL; 63 | 64 | return prefix_names[prefix]; 65 | } 66 | -------------------------------------------------------------------------------- /config/unknown.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 2016 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * config/unknown.h 36 | * 37 | * Compiler definitions for an unknown compiler. Assume the worst. 38 | */ 39 | 40 | #ifndef NASM_CONFIG_UNKNOWN_H 41 | #define NASM_CONFIG_UNKNOWN_H 42 | 43 | /* Assume these don't exist */ 44 | #ifndef inline 45 | # define inline 46 | #endif 47 | #ifndef restrict 48 | # define restrict 49 | #endif 50 | 51 | #endif /* NASM_CONFIG_UNKNOWN_H */ 52 | -------------------------------------------------------------------------------- /config/watcom.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 2016 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * config/watcom.h 36 | * 37 | * Compiler definitions for OpenWatcom instead of config.h.in. 38 | * See config.h.in for the variables which can be defined here. 39 | * 40 | * This was taken from openwcom.mak and needs to be actually validated. 41 | */ 42 | 43 | #ifndef NASM_CONFIG_WATCOM_H 44 | #define NASM_CONFIG_WATCOM_H 45 | 46 | #define HAVE_DECL_STRCASECMP 1 47 | #define HAVE_DECL_STRICMP 1 48 | #define HAVE_DECL_STRLCPY 1 49 | #define HAVE_DECL_STRNCASECMP 1 50 | #define HAVE_DECL_STRNICMP 1 51 | #ifndef __LINUX__ 52 | #define HAVE_IO_H 1 53 | #endif 54 | #define HAVE_LIMITS_H 1 55 | #define HAVE_MEMORY_H 1 56 | #define HAVE_SNPRINTF 1 57 | #if (__WATCOMC__ >= 1230) 58 | #undef HAVE__BOOL /* need stdbool.h */ 59 | #define HAVE_STDBOOL_H 1 60 | #define HAVE_INTTYPES_H 1 61 | #define HAVE_STDINT_H 1 62 | #define HAVE_UINTPTR_T 1 63 | #endif 64 | #define HAVE_STDLIB_H 1 65 | #define HAVE_STRCSPN 1 66 | #define HAVE_STRICMP 1 67 | #define HAVE_STRNICMP 1 68 | #define HAVE_STRSPN 1 69 | #define HAVE_STRING_H 1 70 | #if (__WATCOMC__ >= 1240) 71 | #define HAVE_STRCASECMP 1 72 | #define HAVE_STRNCASECMP 1 73 | #define HAVE_STRLCPY 1 74 | #define HAVE_STRINGS_H 1 75 | #endif 76 | #define HAVE_SYS_STAT_H 1 77 | #define HAVE_SYS_TYPES_H 1 78 | #define HAVE_FCNTL_H 1 79 | #define HAVE_UNISTD_H 1 80 | #define HAVE_VSNPRINTF 1 81 | #define STDC_HEADERS 1 82 | 83 | #define HAVE__FULLPATH 1 84 | #define HAVE_ACCESS 85 | #define HAVE_STRUCT_STAT 86 | #define HAVE_STAT 87 | #define HAVE_FSTAT 88 | #define HAVE_FILENO 89 | #ifdef __LINUX__ 90 | #define HAVE_FTRUNCATE 91 | #else 92 | #define HAVE_CHSIZE 93 | #define HAVE__CHSIZE 94 | #endif 95 | #define HAVE_ISASCII 96 | #define HAVE_ISCNTRL 97 | 98 | #if (__WATCOMC__ >= 1250) 99 | #define restrict __restrict 100 | #else 101 | #define restrict 102 | #endif 103 | #define inline __inline 104 | 105 | #endif /* NASM_CONFIG_WATCOM_H */ 106 | -------------------------------------------------------------------------------- /disasm/disasm.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * disasm.h header file for disasm.c 36 | */ 37 | 38 | #ifndef NASM_DISASM_H 39 | #define NASM_DISASM_H 40 | 41 | #include "iflag.h" 42 | 43 | #define INSN_MAX 32 /* one instruction can't be longer than this */ 44 | 45 | int32_t disasm(uint8_t *data, int32_t data_size, char *output, int outbufsize, int segsize, 46 | int64_t offset, int autosync, iflag_t *prefer); 47 | int32_t eatbyte(uint8_t *data, char *output, int outbufsize, int segsize); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /disasm/sync.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * sync.c the Netwide Disassembler synchronisation processing module 36 | */ 37 | 38 | #include "compiler.h" 39 | 40 | 41 | #include "nasmlib.h" 42 | #include "sync.h" 43 | 44 | #define SYNC_MAX_SHIFT 31 45 | #define SYNC_MAX_SIZE (1U << SYNC_MAX_SHIFT) 46 | 47 | /* initial # of sync points (*must* be power of two)*/ 48 | #define SYNC_INITIAL_CHUNK (1U << 12) 49 | 50 | /* 51 | * This lot manages the current set of sync points by means of a 52 | * heap (priority queue) structure. 53 | */ 54 | 55 | static struct Sync { 56 | uint64_t pos; 57 | uint32_t length; 58 | } *synx; 59 | 60 | static uint32_t max_synx, nsynx; 61 | 62 | static inline void swap_sync(uint32_t dst, uint32_t src) 63 | { 64 | struct Sync t = synx[dst]; 65 | synx[dst] = synx[src]; 66 | synx[src] = t; 67 | } 68 | 69 | void init_sync(void) 70 | { 71 | max_synx = SYNC_INITIAL_CHUNK; 72 | synx = nasm_malloc((max_synx + 1) * sizeof(*synx)); 73 | nsynx = 0; 74 | } 75 | 76 | void add_sync(uint64_t pos, uint32_t length) 77 | { 78 | uint32_t i; 79 | 80 | if (nsynx >= max_synx) { 81 | if (max_synx >= SYNC_MAX_SIZE) /* too many sync points! */ 82 | return; 83 | max_synx = (max_synx << 1); 84 | synx = nasm_realloc(synx, (max_synx + 1) * sizeof(*synx)); 85 | } 86 | 87 | nsynx++; 88 | synx[nsynx].pos = pos; 89 | synx[nsynx].length = length; 90 | 91 | for (i = nsynx; i > 1; i /= 2) { 92 | if (synx[i / 2].pos > synx[i].pos) 93 | swap_sync(i / 2, i); 94 | } 95 | } 96 | 97 | uint64_t next_sync(uint64_t position, uint32_t *length) 98 | { 99 | while (nsynx > 0 && synx[1].pos + synx[1].length <= position) { 100 | uint32_t i, j; 101 | 102 | swap_sync(nsynx, 1); 103 | nsynx--; 104 | 105 | i = 1; 106 | while (i * 2 <= nsynx) { 107 | j = i * 2; 108 | if (synx[j].pos < synx[i].pos && 109 | (j + 1 > nsynx || synx[j + 1].pos > synx[j].pos)) { 110 | swap_sync(j, i); 111 | i = j; 112 | } else if (j + 1 <= nsynx && synx[j + 1].pos < synx[i].pos) { 113 | swap_sync(j + 1, i); 114 | i = j + 1; 115 | } else 116 | break; 117 | } 118 | } 119 | 120 | if (nsynx > 0) { 121 | if (length) 122 | *length = synx[1].length; 123 | return synx[1].pos; 124 | } else { 125 | if (length) 126 | *length = 0L; 127 | return 0; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /disasm/sync.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * sync.h header file for sync.c 36 | */ 37 | 38 | #ifndef NASM_SYNC_H 39 | #define NASM_SYNC_H 40 | 41 | void init_sync(void); 42 | void add_sync(uint64_t position, uint32_t length); 43 | uint64_t next_sync(uint64_t position, uint32_t *length); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /headers/c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2010 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | -------------------------------------------------------------------------------- /headers/doc: -------------------------------------------------------------------------------- 1 | \# -------------------------------------------------------------------------- 2 | \# 3 | \# Copyright 1996-2010 The NASM Authors - All Rights Reserved 4 | \# See the file AUTHORS included with the NASM distribution for 5 | \# the specific copyright holders. 6 | \# 7 | \# Redistribution and use in source and binary forms, with or without 8 | \# modification, are permitted provided that the following 9 | \# conditions are met: 10 | \# 11 | \# * Redistributions of source code must retain the above copyright 12 | \# notice, this list of conditions and the following disclaimer. 13 | \# * Redistributions in binary form must reproduce the above 14 | \# copyright notice, this list of conditions and the following 15 | \# disclaimer in the documentation and/or other materials provided 16 | \# with the distribution. 17 | \# 18 | \# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | \# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | \# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | \# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | \# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | \# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | \# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | \# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | \# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | \# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | \# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | \# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | \# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | \# 32 | \# -------------------------------------------------------------------------- 33 | 34 | -------------------------------------------------------------------------------- /headers/mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2010 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | -------------------------------------------------------------------------------- /headers/perl: -------------------------------------------------------------------------------- 1 | ## -------------------------------------------------------------------------- 2 | ## 3 | ## Copyright 1996-2010 The NASM Authors - All Rights Reserved 4 | ## See the file AUTHORS included with the NASM distribution for 5 | ## the specific copyright holders. 6 | ## 7 | ## Redistribution and use in source and binary forms, with or without 8 | ## modification, are permitted provided that the following 9 | ## conditions are met: 10 | ## 11 | ## * Redistributions of source code must retain the above copyright 12 | ## notice, this list of conditions and the following disclaimer. 13 | ## * Redistributions in binary form must reproduce the above 14 | ## copyright notice, this list of conditions and the following 15 | ## disclaimer in the documentation and/or other materials provided 16 | ## with the distribution. 17 | ## 18 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ## 32 | ## -------------------------------------------------------------------------- 33 | 34 | -------------------------------------------------------------------------------- /include/disp8.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2013 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * disp8.h header file for disp8.c 36 | */ 37 | 38 | #ifndef NASM_DISP8_H 39 | #define NASM_DISP8_H 40 | 41 | #include "nasm.h" 42 | 43 | uint8_t get_disp8N(insn *ins); 44 | bool is_disp8n(operand *input, insn *ins, int8_t *compdisp); 45 | #endif /* NASM_DISP8_H */ 46 | -------------------------------------------------------------------------------- /include/hashtbl.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2018 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * hashtbl.h 36 | * 37 | * Efficient dictionary hash table class. 38 | */ 39 | 40 | #ifndef NASM_HASHTBL_H 41 | #define NASM_HASHTBL_H 42 | 43 | #include "nasmlib.h" 44 | 45 | struct hash_node { 46 | uint64_t hash; 47 | const void *key; 48 | size_t keylen; 49 | void *data; 50 | }; 51 | 52 | struct hash_table { 53 | struct hash_node *table; 54 | size_t load; 55 | size_t size; 56 | size_t max_load; 57 | }; 58 | 59 | struct hash_insert { 60 | struct hash_table *head; 61 | struct hash_node *where; 62 | struct hash_node node; 63 | }; 64 | 65 | struct hash_iterator { 66 | const struct hash_table *head; 67 | const struct hash_node *next; 68 | }; 69 | 70 | uint64_t crc64(uint64_t crc, const char *string); 71 | uint64_t crc64i(uint64_t crc, const char *string); 72 | uint64_t crc64b(uint64_t crc, const void *data, size_t len); 73 | uint64_t crc64ib(uint64_t crc, const void *data, size_t len); 74 | #define CRC64_INIT UINT64_C(0xffffffffffffffff) 75 | 76 | static inline uint64_t crc64_byte(uint64_t crc, uint8_t v) 77 | { 78 | extern const uint64_t crc64_tab[256]; 79 | return crc64_tab[(uint8_t)(v ^ crc)] ^ (crc >> 8); 80 | } 81 | 82 | uint32_t crc32b(uint32_t crc, const void *data, size_t len); 83 | 84 | void **hash_find(struct hash_table *head, const char *string, 85 | struct hash_insert *insert); 86 | void **hash_findb(struct hash_table *head, const void *key, size_t keylen, 87 | struct hash_insert *insert); 88 | void **hash_findi(struct hash_table *head, const char *string, 89 | struct hash_insert *insert); 90 | void **hash_findib(struct hash_table *head, const void *key, size_t keylen, 91 | struct hash_insert *insert); 92 | void **hash_add(struct hash_insert *insert, const void *key, void *data); 93 | static inline void hash_iterator_init(const struct hash_table *head, 94 | struct hash_iterator *iterator) 95 | { 96 | iterator->head = head; 97 | iterator->next = head->table; 98 | } 99 | const struct hash_node *hash_iterate(struct hash_iterator *iterator); 100 | 101 | #define hash_for_each(_head,_it,_np) \ 102 | for (hash_iterator_init((_head), &(_it)), (_np) = hash_iterate(&(_it)) ; \ 103 | (_np) ; (_np) = hash_iterate(&(_it))) 104 | 105 | void hash_free(struct hash_table *head); 106 | void hash_free_all(struct hash_table *head, bool free_keys); 107 | 108 | #endif /* NASM_HASHTBL_H */ 109 | -------------------------------------------------------------------------------- /include/iflag.h: -------------------------------------------------------------------------------- 1 | #ifndef NASM_IFLAG_H 2 | #define NASM_IFLAG_H 3 | 4 | #include "compiler.h" 5 | #include "ilog2.h" 6 | 7 | 8 | #include "iflaggen.h" 9 | 10 | #define IF_GENBIT(bit) (UINT32_C(1) << ((bit) & 31)) 11 | 12 | static inline int ifcomp(uint32_t a, uint32_t b) 13 | { 14 | return (a > b) - (a < b); 15 | } 16 | 17 | static inline bool iflag_test(const iflag_t *f, unsigned int bit) 18 | { 19 | return !!(f->field[bit >> 5] & IF_GENBIT(bit)); 20 | } 21 | 22 | static inline void iflag_set(iflag_t *f, unsigned int bit) 23 | { 24 | f->field[bit >> 5] |= IF_GENBIT(bit); 25 | } 26 | 27 | static inline void iflag_clear(iflag_t *f, unsigned int bit) 28 | { 29 | f->field[bit >> 5] &= ~IF_GENBIT(bit); 30 | } 31 | 32 | static inline void iflag_clear_all(iflag_t *f) 33 | { 34 | memset(f, 0, sizeof(*f)); 35 | } 36 | 37 | static inline void iflag_set_all(iflag_t *f) 38 | { 39 | memset(f, ~0, sizeof(*f)); 40 | } 41 | 42 | #define iflag_for_each_field(v) for ((v) = 0; (v) < IF_FIELD_COUNT; (v)++) 43 | 44 | static inline int iflag_cmp(const iflag_t *a, const iflag_t *b) 45 | { 46 | int i; 47 | 48 | /* This is intentionally a reverse loop! */ 49 | for (i = IF_FIELD_COUNT-1; i >= 0; i--) { 50 | if (a->field[i] == b->field[i]) 51 | continue; 52 | 53 | return ifcomp(a->field[i], b->field[i]); 54 | } 55 | 56 | return 0; 57 | } 58 | 59 | #define IF_GEN_HELPER(name, op) \ 60 | static inline iflag_t iflag_##name(const iflag_t *a, const iflag_t *b) \ 61 | { \ 62 | unsigned int i; \ 63 | iflag_t res; \ 64 | \ 65 | iflag_for_each_field(i) \ 66 | res.field[i] = a->field[i] op b->field[i]; \ 67 | \ 68 | return res; \ 69 | } 70 | 71 | IF_GEN_HELPER(xor, ^) 72 | 73 | /* Some helpers which are to work with predefined masks */ 74 | #define IF_SMASK (IFM_SB|IFM_SW|IFM_SD|IFM_SQ|IFM_SO|IFM_SY|IFM_SZ|IFM_SIZE|IFM_ANYSIZE) 75 | #define IF_ARMASK (IFM_AR0|IFM_AR1|IFM_AR2|IFM_AR3|IFM_AR4) 76 | 77 | #define _itemp_smask(idx) (insns_flags[(idx)].field[0] & IF_SMASK) 78 | #define _itemp_armask(idx) (insns_flags[(idx)].field[0] & IF_ARMASK) 79 | #define _itemp_arg(idx) ((_itemp_armask(idx) >> IF_AR0) - 1) 80 | 81 | #define itemp_smask(itemp) _itemp_smask((itemp)->iflag_idx) 82 | #define itemp_arg(itemp) _itemp_arg((itemp)->iflag_idx) 83 | #define itemp_armask(itemp) _itemp_armask((itemp)->iflag_idx) 84 | 85 | /* 86 | * IF_ANY is the highest CPU level by definition 87 | */ 88 | #define IF_CPU_LEVEL_MASK ((IFM_ANY << 1) - 1) 89 | 90 | static inline int iflag_cmp_cpu(const iflag_t *a, const iflag_t *b) 91 | { 92 | return ifcomp(a->field[IF_CPU_FIELD], b->field[IF_CPU_FIELD]); 93 | } 94 | 95 | static inline uint32_t _iflag_cpu_level(const iflag_t *a) 96 | { 97 | return a->field[IF_CPU_FIELD] & IF_CPU_LEVEL_MASK; 98 | } 99 | 100 | static inline int iflag_cmp_cpu_level(const iflag_t *a, const iflag_t *b) 101 | { 102 | return ifcomp(_iflag_cpu_level(a), _iflag_cpu_level(b)); 103 | } 104 | 105 | /* Returns true if the CPU level is at least a certain value */ 106 | static inline bool iflag_cpu_level_ok(const iflag_t *a, unsigned int bit) 107 | { 108 | return _iflag_cpu_level(a) >= IF_GENBIT(bit); 109 | } 110 | 111 | static inline void iflag_set_all_features(iflag_t *a) 112 | { 113 | uint32_t *p = &a->field[IF_FEATURE_FIELD]; 114 | 115 | memset(p, -1, IF_FEATURE_NFIELDS * sizeof(uint32_t)); 116 | } 117 | 118 | static inline iflag_t _iflag_pfmask(const iflag_t *a) 119 | { 120 | iflag_t r; 121 | 122 | iflag_clear_all(&r); 123 | 124 | if (iflag_test(a, IF_CYRIX)) 125 | iflag_set(&r, IF_CYRIX); 126 | if (iflag_test(a, IF_AMD)) 127 | iflag_set(&r, IF_AMD); 128 | 129 | return r; 130 | } 131 | 132 | #define iflag_pfmask(itemp) _iflag_pfmask(&insns_flags[(itemp)->iflag_idx]) 133 | 134 | #endif /* NASM_IFLAG_H */ 135 | -------------------------------------------------------------------------------- /include/insns.h: -------------------------------------------------------------------------------- 1 | /* insns.h header file for insns.c 2 | * 3 | * The Netwide Assembler is copyright (C) 1996 Simon Tatham and 4 | * Julian Hall. All rights reserved. The software is 5 | * redistributable under the license given in the file "LICENSE" 6 | * distributed in the NASM archive. 7 | */ 8 | 9 | #ifndef NASM_INSNS_H 10 | #define NASM_INSNS_H 11 | 12 | #include "nasm.h" 13 | #include "tokens.h" 14 | #include "iflag.h" 15 | 16 | /* if changed, ITEMPLATE_END should be also changed accordingly */ 17 | struct itemplate { 18 | enum opcode opcode; /* the token, passed from "parser.c" */ 19 | int operands; /* number of operands */ 20 | opflags_t opd[MAX_OPERANDS]; /* bit flags for operand types */ 21 | decoflags_t deco[MAX_OPERANDS]; /* bit flags for operand decorators */ 22 | const uint8_t *code; /* the code it assembles to */ 23 | uint32_t iflag_idx; /* some flags referenced by index */ 24 | }; 25 | 26 | /* Use this helper to test instruction template flags */ 27 | static inline bool itemp_has(const struct itemplate *itemp, unsigned int bit) 28 | { 29 | return iflag_test(&insns_flags[itemp->iflag_idx], bit); 30 | } 31 | 32 | /* Disassembler table structure */ 33 | 34 | /* 35 | * If n == -1, then p points to another table of 256 36 | * struct disasm_index, otherwise p points to a list of n 37 | * struct itemplates to consider. 38 | */ 39 | struct disasm_index { 40 | const void *p; 41 | int n; 42 | }; 43 | 44 | /* Tables for the assembler and disassembler, respectively */ 45 | extern const struct itemplate * const nasm_instructions[]; 46 | extern const struct disasm_index itable[256]; 47 | extern const struct disasm_index * const itable_vex[NASM_VEX_CLASSES][32][4]; 48 | 49 | /* Common table for the byte codes */ 50 | extern const uint8_t nasm_bytecodes[]; 51 | 52 | /* 53 | * this define is used to signify the end of an itemplate 54 | */ 55 | #define ITEMPLATE_END {I_none,0,{0,},{0,},NULL,0} 56 | 57 | /* 58 | * Pseudo-op tests 59 | */ 60 | /* DB-type instruction (DB, DW, ...) */ 61 | static inline bool const_func opcode_is_db(enum opcode opcode) 62 | { 63 | return opcode >= I_DB && opcode < I_RESB; 64 | } 65 | 66 | /* RESB-type instruction (RESB, RESW, ...) */ 67 | static inline bool const_func opcode_is_resb(enum opcode opcode) 68 | { 69 | return opcode >= I_RESB && opcode < I_INCBIN; 70 | } 71 | 72 | /* Width of Dx and RESx instructions */ 73 | 74 | /* 75 | * initialized data bytes length from opcode 76 | */ 77 | static inline int const_func db_bytes(enum opcode opcode) 78 | { 79 | switch (opcode) { 80 | case I_DB: 81 | return 1; 82 | case I_DW: 83 | return 2; 84 | case I_DD: 85 | return 4; 86 | case I_DQ: 87 | return 8; 88 | case I_DT: 89 | return 10; 90 | case I_DO: 91 | return 16; 92 | case I_DY: 93 | return 32; 94 | case I_DZ: 95 | return 64; 96 | case I_none: 97 | return -1; 98 | default: 99 | return 0; 100 | } 101 | } 102 | 103 | /* 104 | * Uninitialized data bytes length from opcode 105 | */ 106 | static inline int const_func resb_bytes(enum opcode opcode) 107 | { 108 | switch (opcode) { 109 | case I_RESB: 110 | return 1; 111 | case I_RESW: 112 | return 2; 113 | case I_RESD: 114 | return 4; 115 | case I_RESQ: 116 | return 8; 117 | case I_REST: 118 | return 10; 119 | case I_RESO: 120 | return 16; 121 | case I_RESY: 122 | return 32; 123 | case I_RESZ: 124 | return 64; 125 | case I_none: 126 | return -1; 127 | default: 128 | return 0; 129 | } 130 | } 131 | 132 | #endif /* NASM_INSNS_H */ 133 | -------------------------------------------------------------------------------- /include/labels.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2018 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * labels.h header file for labels.c 36 | */ 37 | 38 | #ifndef LABELS_H 39 | #define LABELS_H 40 | 41 | #include "compiler.h" 42 | 43 | enum mangle_index { 44 | LM_LPREFIX, /* Local variable prefix */ 45 | LM_LSUFFIX, /* Local variable suffix */ 46 | LM_GPREFIX, /* Global variable prefix */ 47 | LM_GSUFFIX /* GLobal variable suffix */ 48 | }; 49 | 50 | enum label_type { 51 | LBL_none = -1, /* No label */ 52 | LBL_LOCAL = 0, /* Must be zero */ 53 | LBL_STATIC, 54 | LBL_GLOBAL, 55 | LBL_EXTERN, 56 | LBL_REQUIRED, /* Like extern but emit even if unused */ 57 | LBL_COMMON, 58 | LBL_SPECIAL, /* Magic symbols like ..start */ 59 | LBL_BACKEND /* Backend-defined symbols like ..got */ 60 | }; 61 | 62 | enum label_type lookup_label(const char *label, int32_t *segment, int64_t *offset); 63 | static inline bool is_extern(enum label_type type) 64 | { 65 | return type == LBL_EXTERN || type == LBL_REQUIRED; 66 | } 67 | void define_label(const char *label, int32_t segment, int64_t offset, 68 | bool normal); 69 | void backend_label(const char *label, int32_t segment, int64_t offset); 70 | bool declare_label(const char *label, enum label_type type, 71 | const char *special); 72 | void set_label_mangle(enum mangle_index which, const char *what); 73 | int init_labels(void); 74 | void cleanup_labels(void); 75 | const char *local_scope(const char *label); 76 | 77 | extern uint64_t global_offset_changed; 78 | 79 | #endif /* LABELS_H */ 80 | -------------------------------------------------------------------------------- /include/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef MD5_H 2 | #define MD5_H 3 | 4 | #include "compiler.h" 5 | 6 | #define MD5_HASHBYTES 16 7 | 8 | typedef struct MD5Context { 9 | uint32_t buf[4]; 10 | uint32_t bits[2]; 11 | unsigned char in[64]; 12 | } MD5_CTX; 13 | 14 | extern void MD5Init(MD5_CTX *context); 15 | extern void MD5Update(MD5_CTX *context, unsigned char const *buf, 16 | unsigned len); 17 | extern void MD5Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context); 18 | extern void MD5Transform(uint32_t buf[4], uint32_t const in[16]); 19 | extern char * MD5End(MD5_CTX *, char *); 20 | 21 | #endif /* !MD5_H */ 22 | -------------------------------------------------------------------------------- /include/nctype.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2018 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * ctype-like functions specific to NASM 36 | */ 37 | #ifndef NASM_NCTYPE_H 38 | #define NASM_NCTYPE_H 39 | 40 | #include "compiler.h" 41 | 42 | void nasm_ctype_init(void); 43 | 44 | extern unsigned char nasm_tolower_tab[256]; 45 | static inline char nasm_tolower(char x) 46 | { 47 | return nasm_tolower_tab[(unsigned char)x]; 48 | } 49 | 50 | /* 51 | * NASM ctype table 52 | */ 53 | enum nasm_ctype { 54 | NCT_CTRL = 0x0001, 55 | NCT_SPACE = 0x0002, 56 | NCT_ASCII = 0x0004, 57 | NCT_LOWER = 0x0008, /* isalpha(x) && tolower(x) == x */ 58 | NCT_UPPER = 0x0010, /* isalpha(x) && tolower(x) != x */ 59 | NCT_DIGIT = 0x0020, 60 | NCT_HEX = 0x0040, 61 | NCT_ID = 0x0080, 62 | NCT_IDSTART = 0x0100, 63 | NCT_MINUS = 0x0200, /* - */ 64 | NCT_DOLLAR = 0x0400, /* $ */ 65 | NCT_UNDER = 0x0800, /* _ */ 66 | NCT_QUOTE = 0x1000 /* " ' ` */ 67 | }; 68 | 69 | extern uint16_t nasm_ctype_tab[256]; 70 | static inline bool nasm_ctype(unsigned char x, enum nasm_ctype mask) 71 | { 72 | return (nasm_ctype_tab[x] & mask) != 0; 73 | } 74 | 75 | static inline bool nasm_isspace(char x) 76 | { 77 | return nasm_ctype(x, NCT_SPACE); 78 | } 79 | 80 | static inline bool nasm_isalpha(char x) 81 | { 82 | return nasm_ctype(x, NCT_LOWER|NCT_UPPER); 83 | } 84 | 85 | static inline bool nasm_isdigit(char x) 86 | { 87 | return nasm_ctype(x, NCT_DIGIT); 88 | } 89 | static inline bool nasm_isalnum(char x) 90 | { 91 | return nasm_ctype(x, NCT_LOWER|NCT_UPPER|NCT_DIGIT); 92 | } 93 | static inline bool nasm_isxdigit(char x) 94 | { 95 | return nasm_ctype(x, NCT_HEX); 96 | } 97 | static inline bool nasm_isidstart(char x) 98 | { 99 | return nasm_ctype(x, NCT_IDSTART); 100 | } 101 | static inline bool nasm_isidchar(char x) 102 | { 103 | return nasm_ctype(x, NCT_ID); 104 | } 105 | static inline bool nasm_isbrcchar(char x) 106 | { 107 | return nasm_ctype(x, NCT_ID|NCT_MINUS); 108 | } 109 | static inline bool nasm_isnumstart(char x) 110 | { 111 | return nasm_ctype(x, NCT_DIGIT|NCT_DOLLAR); 112 | } 113 | static inline bool nasm_isnumchar(char x) 114 | { 115 | return nasm_ctype(x, NCT_DIGIT|NCT_LOWER|NCT_UPPER|NCT_UNDER); 116 | } 117 | static inline bool nasm_isquote(char x) 118 | { 119 | return nasm_ctype(x, NCT_QUOTE); 120 | } 121 | 122 | static inline void nasm_ctype_tasm_mode(void) 123 | { 124 | /* No differences at the present moment */ 125 | } 126 | 127 | #endif /* NASM_NCTYPE_H */ 128 | -------------------------------------------------------------------------------- /include/perfhash.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 2017 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #ifndef PERFHASH_H 35 | #define PERFHASH_H 1 36 | 37 | #include "compiler.h" 38 | #include "nasmlib.h" /* For invalid_enum_str() */ 39 | 40 | struct perfect_hash { 41 | uint64_t crcinit; 42 | uint32_t hashmask; 43 | uint32_t tbllen; 44 | int tbloffs; 45 | int errval; 46 | const int16_t *hashvals; 47 | const char * const *strings; 48 | }; 49 | 50 | int perfhash_find(const struct perfect_hash *, const char *); 51 | 52 | #endif /* PERFHASH_H */ 53 | -------------------------------------------------------------------------------- /include/raa.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #ifndef NASM_RAA_H 35 | #define NASM_RAA_H 1 36 | 37 | #include "compiler.h" 38 | 39 | struct RAA; 40 | typedef uint64_t raaindex; 41 | 42 | #define raa_init() NULL 43 | void raa_free(struct RAA *); 44 | int64_t raa_read(struct RAA *, raaindex); 45 | void *raa_read_ptr(struct RAA *, raaindex); 46 | struct RAA * never_null raa_write(struct RAA *r, raaindex posn, int64_t value); 47 | struct RAA * never_null raa_write_ptr(struct RAA *r, raaindex posn, void *value); 48 | 49 | #endif /* NASM_RAA_H */ 50 | -------------------------------------------------------------------------------- /include/rbtree.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2020 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #ifndef NASM_RBTREE_H 35 | #define NASM_RBTREE_H 36 | 37 | #include "compiler.h" 38 | 39 | /* 40 | * This structure should be embedded in a larger data structure; 41 | * the final output from rb_search() can then be converted back 42 | * to the larger data structure via container_of(). 43 | * 44 | * An empty tree is simply represented by a NULL pointer. 45 | */ 46 | 47 | /* Note: the values of these flags is significant */ 48 | enum rbtree_node_flags { 49 | RBTREE_NODE_BLACK = 1, /* Node color is black */ 50 | RBTREE_NODE_PRED = 2, /* Left pointer is an uplink */ 51 | RBTREE_NODE_SUCC = 4 /* Right pointer is an uplink */ 52 | }; 53 | 54 | struct rbtree { 55 | uint64_t key; 56 | struct rbtree_metadata { 57 | struct rbtree *left, *right; 58 | enum rbtree_node_flags flags; 59 | } m; 60 | }; 61 | 62 | /* 63 | * Add a node to a tree. Returns the new root pointer. 64 | * The key value in the structure needs to be preinitialized; 65 | * the rest of the structure should be zero. 66 | */ 67 | struct rbtree *rb_insert(struct rbtree *, struct rbtree *); 68 | 69 | /* 70 | * Find a node in the tree corresponding to the key immediately 71 | * <= the passed-in key value. 72 | */ 73 | struct rbtree *rb_search(const struct rbtree *, uint64_t); 74 | 75 | /* 76 | * Find a node in the tree exactly matching the key value. 77 | */ 78 | struct rbtree *rb_search_exact(const struct rbtree *, uint64_t); 79 | 80 | /* 81 | * Return the immediately previous or next node in key order. 82 | * Returns NULL if this node is the end of the tree. 83 | * These operations are safe for complee (but not partial!) 84 | * tree walk-with-destruction in key order. 85 | */ 86 | struct rbtree *rb_prev(const struct rbtree *); 87 | struct rbtree *rb_next(const struct rbtree *); 88 | 89 | /* 90 | * Return the very first or very last node in key order. 91 | */ 92 | struct rbtree *rb_first(const struct rbtree *); 93 | struct rbtree *rb_last(const struct rbtree *); 94 | 95 | /* 96 | * Left and right nodes, if real. These operations are 97 | * safe for tree destruction, but not for splitting a tree. 98 | */ 99 | static inline struct rbtree *rb_left(const struct rbtree *rb) 100 | { 101 | return (rb->m.flags & RBTREE_NODE_PRED) ? NULL : rb->m.left; 102 | } 103 | static inline struct rbtree *rb_right(const struct rbtree *rb) 104 | { 105 | return (rb->m.flags & RBTREE_NODE_SUCC) ? NULL : rb->m.right; 106 | } 107 | 108 | #endif /* NASM_RBTREE_H */ 109 | -------------------------------------------------------------------------------- /include/strlist.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2020 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * strlist.h - list of unique, ordered strings 36 | */ 37 | 38 | #ifndef NASM_STRLIST_H 39 | #define NASM_STRLIST_H 40 | 41 | #include "compiler.h" 42 | #include "nasmlib.h" 43 | #include "hashtbl.h" 44 | 45 | struct strlist_entry { 46 | struct strlist_entry *next; 47 | size_t offset; 48 | size_t size; 49 | intorptr pvt; 50 | char str[1]; 51 | }; 52 | 53 | struct strlist { 54 | struct hash_table hash; 55 | struct strlist_entry *head, **tailp; 56 | size_t nstr, size; 57 | bool uniq; 58 | }; 59 | 60 | static inline const struct strlist_entry * 61 | strlist_head(const struct strlist *list) 62 | { 63 | return list ? list->head : NULL; 64 | } 65 | static inline struct strlist_entry *strlist_tail(struct strlist *list) 66 | { 67 | if (!list || !list->head) 68 | return NULL; 69 | return container_of(list->tailp, struct strlist_entry, next); 70 | } 71 | static inline size_t strlist_count(const struct strlist *list) 72 | { 73 | return list ? list->nstr : 0; 74 | } 75 | static inline size_t strlist_size(const struct strlist *list) 76 | { 77 | return list ? list->size : 0; 78 | } 79 | 80 | struct strlist * safe_alloc strlist_alloc(bool uniq); 81 | const struct strlist_entry *strlist_add(struct strlist *list, const char *str); 82 | const struct strlist_entry * printf_func(2, 3) 83 | strlist_printf(struct strlist *list, const char *fmt, ...); 84 | const struct strlist_entry * vprintf_func(2) 85 | strlist_vprintf(struct strlist *list, const char *fmt, va_list ap); 86 | const struct strlist_entry * 87 | strlist_find(const struct strlist *list, const char *str); 88 | void * safe_alloc strlist_linearize(const struct strlist *list, char sep); 89 | void strlist_write(const struct strlist *list, const char *sep, FILE *f); 90 | void strlist_free(struct strlist **listp); 91 | #define strlist_for_each(p,h) list_for_each((p), strlist_head(h)) 92 | 93 | #endif /* NASM_STRLIST_H */ 94 | -------------------------------------------------------------------------------- /include/tables.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2016 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * tables.h 36 | * 37 | * Declarations for auto-generated tables 38 | */ 39 | 40 | #ifndef NASM_TABLES_H 41 | #define NASM_TABLES_H 42 | 43 | #include "compiler.h" 44 | #include "insnsi.h" /* For enum opcode */ 45 | 46 | /* --- From standard.mac via macros.pl: --- */ 47 | 48 | /* macros.c */ 49 | extern const unsigned char nasm_stdmac_tasm[]; 50 | extern const unsigned char nasm_stdmac_nasm[]; 51 | extern const unsigned char nasm_stdmac_version[]; 52 | 53 | struct use_package { 54 | const char *package; 55 | const unsigned char *macros; 56 | int index; 57 | }; 58 | extern const struct use_package *nasm_find_use_package(const char *); 59 | extern const int use_package_count; 60 | 61 | /* --- From insns.dat via insns.pl: --- */ 62 | 63 | /* insnsn.c */ 64 | extern const char * const nasm_insn_names[]; 65 | 66 | /* --- From regs.dat via regs.pl: --- */ 67 | 68 | /* regs.c */ 69 | extern const char * const nasm_reg_names[]; 70 | /* regflags.c */ 71 | typedef uint64_t opflags_t; 72 | typedef uint16_t decoflags_t; 73 | extern const opflags_t nasm_reg_flags[]; 74 | /* regvals.c */ 75 | extern const int nasm_regvals[]; 76 | 77 | #endif /* NASM_TABLES_H */ 78 | -------------------------------------------------------------------------------- /include/ver.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2020 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * NASM version strings, defined in ver.c 36 | */ 37 | 38 | #ifndef NASM_VER_H 39 | #define NASM_VER_H 40 | 41 | #include "compiler.h" 42 | 43 | extern const char nasm_version[]; 44 | extern const char nasm_date[]; 45 | extern const char nasm_compile_options[]; 46 | 47 | extern bool reproducible; 48 | 49 | extern const char *nasm_comment(void); 50 | extern size_t nasm_comment_len(void); 51 | 52 | extern const char *nasm_signature(void); 53 | extern size_t nasm_signature_len(void); 54 | 55 | #endif /* NASM_VER_H */ 56 | -------------------------------------------------------------------------------- /macros/altreg.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | ;; 35 | ;; altreg.mac 36 | ;; 37 | ;; Alternate register names for 64-bit mode 38 | ;; 39 | 40 | USE: altreg 41 | 42 | ;; 43 | ;; Intel documents R8L-R15L instead of R8B-R15B 44 | ;; (Warning: this may confuse people with an AT&T-style assembly 45 | ;; background, where "r8l" means R8D, etc.) 46 | ;; 47 | %idefine r8l r8b 48 | %idefine r9l r9b 49 | %idefine r10l r10b 50 | %idefine r11l r11b 51 | %idefine r12l r12b 52 | %idefine r13l r13b 53 | %idefine r14l r14b 54 | %idefine r15l r15b 55 | 56 | ;; 57 | ;; Numeric register names for the lower 8 registers 58 | ;; 59 | %idefine r0 rax 60 | %idefine r1 rcx 61 | %idefine r2 rdx 62 | %idefine r3 rbx 63 | %idefine r4 rsp 64 | %idefine r5 rbp 65 | %idefine r6 rsi 66 | %idefine r7 rdi 67 | 68 | %idefine r0d eax 69 | %idefine r1d ecx 70 | %idefine r2d edx 71 | %idefine r3d ebx 72 | %idefine r4d esp 73 | %idefine r5d ebp 74 | %idefine r6d esi 75 | %idefine r7d edi 76 | 77 | %idefine r0w ax 78 | %idefine r1w cx 79 | %idefine r2w dx 80 | %idefine r3w bx 81 | %idefine r4w sp 82 | %idefine r5w bp 83 | %idefine r6w si 84 | %idefine r7w di 85 | 86 | %idefine r0b al 87 | %idefine r1b cl 88 | %idefine r2b dl 89 | %idefine r3b bl 90 | %idefine r4b spl 91 | %idefine r5b bpl 92 | %idefine r6b sil 93 | %idefine r7b dil 94 | 95 | %idefine r0l al 96 | %idefine r1l cl 97 | %idefine r2l dl 98 | %idefine r3l bl 99 | %idefine r4l spl 100 | %idefine r5l bpl 101 | %idefine r6l sil 102 | %idefine r7l dil 103 | 104 | %idefine r0h ah 105 | %idefine r1h ch 106 | %idefine r2h dh 107 | %idefine r3h bh 108 | -------------------------------------------------------------------------------- /macros/fp.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 2010-2020 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | ;; 35 | ;; fp.mac 36 | ;; 37 | ;; Floating-point utility macros 38 | ;; 39 | 40 | USE: fp 41 | 42 | %define Inf __?Infinity?__ 43 | %define NaN __?QNaN?__ 44 | %define QNaN __?QNaN?__ 45 | %define SNaN __?SNaN?__ 46 | 47 | %define float8(x) __?float8?__(x) 48 | %define float16(x) __?float16?__(x) 49 | %define bfloat16(x) __?bfloat16?__(x) 50 | %define float32(x) __?float32?__(x) 51 | %define float64(x) __?float64?__(x) 52 | %define float80m(x) __?float80m?__(x) 53 | %define float80e(x) __?float80e?__(x) 54 | %define float128l(x) __?float128l?__(x) 55 | %define float128h(x) __?float128h?__(x) 56 | 57 | %imacro bf16 1-*.nolist 58 | %rep %0 59 | dw __?bfloat16?__(%1) 60 | %rotate 1 61 | %endrep 62 | %endmacro 63 | -------------------------------------------------------------------------------- /macros/ifunc.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 2012-2016 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | ;; 35 | ;; ifunc.mac 36 | ;; 37 | ;; Integer function utility macros 38 | ;; 39 | 40 | USE: ifunc 41 | 42 | %idefine ilog2(x) (__?ilog2e?__(x)) 43 | %idefine ilog2e(x) (__?ilog2e?__(x)) 44 | %idefine ilog2w(x) (__?ilog2w?__(x)) 45 | %idefine ilog2fw(x) (__?ilog2w?__(x)) 46 | %idefine ilog2f(x) (__?ilog2f?__(x)) 47 | %idefine ilog2cw(x) (__?ilog2w?__(x) * 0 + __?ilog2c?__(x)) 48 | %idefine ilog2c(x) (__?ilog2c?__(x)) 49 | -------------------------------------------------------------------------------- /macros/masm.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 2019 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | ;; 35 | ;; masm.mac 36 | ;; 37 | ;; Very limited MASM compatibility package; intended to be used 38 | ;; primarily with machine-generated code. It does not include any 39 | ;; "programmer friendly" shortcuts, nor does it in any way support 40 | ;; ASSUME, symbol typing, or MASM-style structures. 41 | ;; 42 | 43 | USE: masm 44 | 45 | %unimacro segment 1+ 46 | 47 | %imacro segment 0-1+.nolist 48 | %define __?SECT?__ [segment %00 %1] 49 | __?SECT?__ 50 | %endmacro 51 | 52 | %imacro ends 0+.nolist 53 | %null ends %00 54 | %endmacro 55 | 56 | %imacro proc 0-*.nolist 57 | %rep %0 58 | %ifidni %1,far 59 | %idefine ret retf 60 | %else 61 | %idefine ret retn 62 | %endif 63 | %rotate 1 64 | %endrep 65 | %endmacro 66 | 67 | %imacro endp 0.nolist 68 | %null endp %00 69 | %undef ret 70 | %endmacro 71 | 72 | %idefine ptr __?masm_ptr?__ 73 | %idefine flat __?masm_flat?__ ; is %idefine really correct here? 74 | %idefine offset 75 | 76 | %imacro end 0+.nolist 77 | ; Nothing 78 | %endmacro 79 | 80 | %idefine tbyte tword 81 | 82 | default rel 83 | -------------------------------------------------------------------------------- /misc/Nindent: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1" 3 | RES=`indent --version` 4 | V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1` 5 | V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2` 6 | V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3` 7 | if [ $V1 -gt 2 ]; then 8 | PARAM="$PARAM -il0" 9 | elif [ $V1 -eq 2 ]; then 10 | if [ $V2 -gt 2 ]; then 11 | PARAM="$PARAM -il0"; 12 | elif [ $V2 -eq 2 ]; then 13 | if [ $V3 -ge 10 ]; then 14 | PARAM="$PARAM -il0" 15 | fi 16 | fi 17 | fi 18 | exec indent $PARAM "$@" 19 | -------------------------------------------------------------------------------- /misc/README: -------------------------------------------------------------------------------- 1 | There are various helpful bits and pieces for NASM, 2 | including but not limited to Simon photograph =) 3 | -------------------------------------------------------------------------------- /misc/c16.mac: -------------------------------------------------------------------------------- 1 | ; NASM macro set to make interfacing to 16-bit programs easier -*- nasm -*- 2 | 3 | 4 | 5 | %imacro proc 1 ; begin a procedure definition 6 | 7 | %push proc 8 | 9 | global %1 10 | 11 | %1: push bp 12 | 13 | mov bp,sp 14 | 15 | %ifdef FARCODE PASCAL ; arguments may start at bp+4 or bp+6 16 | 17 | %assign %$arg 6 18 | 19 | %define %$firstarg 6 20 | 21 | %else 22 | 23 | %assign %$arg 4 24 | 25 | %define %$firstarg 4 26 | 27 | %endif 28 | 29 | %define %$procname %1 30 | 31 | %endmacro 32 | 33 | 34 | 35 | %imacro arg 0-1 2 ; used with the argument name as a label 36 | 37 | %00 equ %$arg 38 | 39 | ; we could possibly be adding some 40 | 41 | ; debug information at this point...? 42 | 43 | %assign %$arg %1+%$arg 44 | 45 | %endmacro 46 | 47 | 48 | 49 | %imacro endproc 0 50 | 51 | %ifnctx proc 52 | 53 | %error Mismatched `endproc'/`proc' 54 | 55 | %else 56 | 57 | mov sp,bp 58 | 59 | pop bp 60 | 61 | %ifdef PASCAL 62 | 63 | retf %$arg - %$firstarg 64 | 65 | %elifdef FARCODE 66 | 67 | retf 68 | 69 | %else 70 | 71 | retn 72 | 73 | %endif 74 | 75 | __end_%$procname: ; useful for calculating function size 76 | 77 | %pop 78 | 79 | %endif 80 | 81 | %endmacro 82 | 83 | -------------------------------------------------------------------------------- /misc/c32.mac: -------------------------------------------------------------------------------- 1 | ; NASM macro set to make interfacing to 32-bit programs easier -*- nasm -*- 2 | 3 | 4 | 5 | %imacro proc 1 ; begin a procedure definition 6 | 7 | %push proc 8 | 9 | global %1 10 | 11 | %1: push ebp 12 | 13 | mov ebp,esp 14 | 15 | %assign %$arg 8 16 | 17 | %define %$procname %1 18 | 19 | %endmacro 20 | 21 | 22 | 23 | %imacro arg 0-1 4 ; used with the argument name as a label 24 | 25 | %00 equ %$arg 26 | 27 | %assign %$arg %1+%$arg 28 | 29 | %endmacro 30 | 31 | 32 | 33 | %imacro endproc 0 34 | 35 | %ifnctx proc 36 | 37 | %error Mismatched `endproc'/`proc' 38 | 39 | %else 40 | 41 | leave 42 | 43 | ret 44 | 45 | __end_%$procname: ; useful for calculating function size 46 | 47 | %pop 48 | 49 | %endif 50 | 51 | %endmacro 52 | 53 | -------------------------------------------------------------------------------- /misc/crcgen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | /* Polynomial in bit-reversed notation */ 7 | uint64_t poly; 8 | uint64_t crctab[256], v; 9 | int i, j; 10 | 11 | poly = strtoumax(argv[1], NULL, 0); 12 | 13 | printf("/* C */\n"); 14 | printf("static const uint64_t crc64_tab[256] = {\n"); 15 | for (i = 0; i < 256; i++) { 16 | v = i; 17 | for (j = 0; j < 8; j++) 18 | v = (v >> 1) ^ ((v & 1) ? poly : 0); 19 | crctab[i] = v; 20 | } 21 | 22 | for (i = 0; i < 256; i += 2) { 23 | printf(" /* %02x */ UINT64_C(0x%016"PRIx64"), " 24 | "UINT64_C(0x%016"PRIx64")%s\n", 25 | i, crctab[i], crctab[i+1], (i == 254) ? "" : ","); 26 | } 27 | printf("};\n\n"); 28 | 29 | printf("# perl\n"); 30 | printf("@crc64_tab = (\n"); 31 | for (i = 0; i < 256; i += 2) { 32 | printf(" [0x%08"PRIx32", 0x%08"PRIx32"], " 33 | "[0x%08"PRIx32", 0x%08"PRIx32"]%-1s # %02x\n", 34 | (uint32_t)(crctab[i] >> 32), 35 | (uint32_t)(crctab[i]), 36 | (uint32_t)(crctab[i+1] >> 32), 37 | (uint32_t)(crctab[i+1]), 38 | (i == 254) ? "" : ",", 39 | i); 40 | } 41 | printf(");\n"); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /misc/exebin.mac: -------------------------------------------------------------------------------- 1 | ; -*- nasm -*- 2 | ; NASM macro file to allow the `bin' output format to generate 3 | ; simple .EXE files by constructing the EXE header by hand. 4 | ; Adapted from a contribution by Yann Guidon 5 | 6 | %define EXE_stack_size EXE_realstacksize 7 | 8 | %macro EXE_begin 0 9 | ORG 0E0h 10 | section .text 11 | 12 | header_start: 13 | db 4Dh,5Ah ; EXE file signature 14 | dw EXE_allocsize % 512 15 | dw (EXE_allocsize + 511) / 512 16 | dw 0 ; relocation information: none 17 | dw (header_end-header_start)/16 ; header size in paragraphs 18 | dw (EXE_absssize + EXE_realstacksize) / 16 ; min extra mem 19 | dw (EXE_absssize + EXE_realstacksize) / 16 ; max extra mem 20 | dw -10h ; Initial SS (before fixup) 21 | dw EXE_endbss + EXE_realstacksize ; Initial SP (1K DPMI+1K STACK) 22 | dw 0 ; (no) Checksum 23 | dw 100h ; Initial IP - start just after the header 24 | dw -10h ; Initial CS (before fixup) 25 | dw 0 ; file offset to relocation table: none 26 | dw 0 ; (no overlay) 27 | align 16,db 0 28 | header_end: 29 | 30 | EXE_startcode: 31 | section .data 32 | EXE_startdata: 33 | section .bss 34 | EXE_startbss: 35 | %endmacro 36 | 37 | %macro EXE_stack 1 38 | EXE_realstacksize equ %1 39 | %define EXE_stack_size EXE_bogusstacksize ; defeat EQU in EXE_end 40 | %endmacro 41 | 42 | %macro EXE_end 0 43 | section .text 44 | EXE_endcode: 45 | section .data 46 | EXE_enddata: 47 | section .bss 48 | alignb 4 49 | EXE_endbss: 50 | 51 | EXE_acodesize equ (EXE_endcode-EXE_startcode+3) & (~3) 52 | EXE_datasize equ EXE_enddata-EXE_startdata 53 | EXE_absssize equ (EXE_endbss-EXE_startbss+3) & (~3) 54 | EXE_allocsize equ EXE_acodesize + EXE_datasize 55 | 56 | EXE_stack_size equ 0x800 ; default if nothing else was used 57 | %endmacro 58 | -------------------------------------------------------------------------------- /misc/exebin2.mac: -------------------------------------------------------------------------------- 1 | ; -*- nasm -*- 2 | 3 | ; NASM macro file to allow the `bin' output format to generate 4 | 5 | ; simple .EXE files by constructing the EXE header by hand. 6 | 7 | ; Adapted from a contribution by Yann Guidon 8 | 9 | 10 | 11 | %define EXE_stack_size EXE_realstacksize 12 | 13 | 14 | 15 | %macro EXE_begin 0 16 | 17 | ORG 0E0h 18 | 19 | section .text 20 | 21 | 22 | 23 | header_start: 24 | 25 | db 4Dh,5Ah ; EXE file signature 26 | 27 | dw EXE_allocsize % 512 28 | 29 | dw (EXE_allocsize + 511) / 512 30 | 31 | dw 0 ; relocation information: none 32 | 33 | dw (header_end-header_start)/16 ; header size in paragraphs 34 | 35 | dw (EXE_absssize + EXE_realstacksize) / 16 ; min extra mem 36 | 37 | dw (EXE_absssize + EXE_realstacksize) / 16 ; max extra mem 38 | 39 | dw -10h ; Initial SS (before fixup) 40 | 41 | dw EXE_endbss + EXE_realstacksize ; Initial SP (1K DPMI+1K STACK) 42 | 43 | dw 0 ; (no) Checksum 44 | 45 | dw 100h ; Initial IP - start just after the header 46 | 47 | dw -10h ; Initial CS (before fixup) 48 | 49 | dw 0 ; file offset to relocation table: none 50 | 51 | dw 0 ; (no overlay) 52 | 53 | align 16,db 0 54 | 55 | header_end: 56 | 57 | 58 | 59 | EXE_startcode: 60 | 61 | section .data 62 | 63 | EXE_startdata: 64 | 65 | section .bss 66 | 67 | EXE_startbss: 68 | 69 | %endmacro 70 | 71 | 72 | 73 | %macro EXE_stack 1 74 | 75 | EXE_realstacksize equ %1 76 | 77 | %define EXE_stack_size EXE_bogusstacksize ; defeat EQU in EXE_end 78 | 79 | %endmacro 80 | 81 | 82 | 83 | %macro EXE_end 0 84 | 85 | section .text 86 | 87 | EXE_endcode: 88 | 89 | section .data 90 | 91 | EXE_enddata: 92 | 93 | section .bss 94 | 95 | alignb 4 96 | 97 | EXE_endbss: 98 | 99 | 100 | 101 | EXE_acodesize equ (EXE_endcode-EXE_startcode+3) & (~3) 102 | 103 | EXE_datasize equ EXE_enddata-EXE_startdata 104 | 105 | EXE_absssize equ (EXE_endbss-EXE_startbss+3) & (~3) 106 | 107 | EXE_allocsize equ EXE_acodesize + EXE_datasize 108 | 109 | 110 | 111 | EXE_stack_size equ 0x800 ; default if nothing else was used 112 | 113 | %endmacro 114 | 115 | -------------------------------------------------------------------------------- /misc/fmtinsns.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # Re-align the columns in insns.dat, and enforce case conventions 4 | # 5 | 6 | @cols = (0, 16, 48, 96); 7 | 8 | while ($line = ) { 9 | chomp $line; 10 | if ($line !~ /^\s*(\;.*|)$/) { 11 | ($ln = $line) =~ s/\s+$//; 12 | if ($line =~ /^\s*(\S+)\s+(\S+)\s+(\S+|\[.*\])\s+(\S+)\s*$/) { 13 | @fields = ($1, $2, $3, $4); 14 | $fields[0] = "\U$fields[0]" unless ($fields[0] =~ /^[^a-z]+cc$/); 15 | $fields[3] =~ s/\,+$//; 16 | $fields[3] = "\U$fields[3]" unless ($fields[3] eq 'ignore'); 17 | $c = 0; 18 | $line = ''; 19 | for ($i = 0; $i < scalar(@fields); $i++) { 20 | if ($i > 0 && $c >= $cols[$i]) { 21 | $line .= ' '; 22 | $c++; 23 | } 24 | while ($c < $cols[$i]) { 25 | $line .= "\t"; 26 | $c = ($c+8) & ~7; 27 | } 28 | $line .= $fields[$i]; 29 | for ($j = 0; $j < length($fields[$i]); $j++) { 30 | if (substr($fields[$i], $j, 1) eq "\t") { 31 | $c = ($c+8) & ~7; 32 | } else { 33 | $c++; 34 | } 35 | } 36 | } 37 | } 38 | } 39 | print $line, "\n"; 40 | } 41 | -------------------------------------------------------------------------------- /misc/genfma.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | %packed_insns = ( 3 | 'vfmadd' => 0x98, 4 | 'vfmaddsub' => 0x96, 5 | 'vfmsubadd' => 0x97, 6 | 'vfmsub' => 0x9a, 7 | 'vfnmadd' => 0x9c, 8 | 'vfnmsub' => 0x9e 9 | ); 10 | 11 | %scalar_insns = ( 12 | 'vfmadd' => 0x99, 13 | 'vfmsub' => 0x9b, 14 | 'vfnmadd' => 0x9d, 15 | 'vfnmsub' => 0x9f 16 | ); 17 | 18 | foreach $pi ( sort(keys(%packed_insns)) ) { 19 | $op = $packed_insns{$pi}; 20 | foreach $order ('132', '213', '231') { 21 | $xorder = substr($order,1,1).substr($order,0,1).substr($order,2,1); 22 | foreach $o ($order, $xorder) { 23 | for ($w = 0; $w < 2; $w++) { 24 | $suf = $w ? 'pd' : 'ps'; 25 | for ($l = 128; $l <= 256; $l <<= 1) { 26 | $sx = ($l == 256) ? 'SY' : 'SO'; 27 | $mm = ($l == 256) ? 'ymm' : 'xmm'; 28 | printf "%-15s %-31s %-8s%-39s %s\n", 29 | "\U${pi}${o}${suf}", 30 | "${mm}reg,${mm}reg,${mm}rm", 31 | "[rvm:", 32 | sprintf("vex.dds.%d.66.0f38.w%d %02x /r]", 33 | $l, $w, $op), 34 | "FMA,FUTURE,${sx}"; 35 | } 36 | } 37 | } 38 | $op += 0x10; 39 | } 40 | } 41 | 42 | foreach $si ( sort(keys(%scalar_insns)) ) { 43 | $op = $scalar_insns{$si}; 44 | foreach $order ('132', '213', '231') { 45 | $xorder = substr($order,1,1).substr($order,0,1).substr($order,2,1); 46 | foreach $o ($order, $xorder) { 47 | for ($w = 0; $w < 2; $w++) { 48 | $suf = $w ? 'sd' : 'ss'; 49 | $sx = $w ? 'SQ' : 'SD'; 50 | $l = 128; 51 | $mm = 'xmm'; 52 | printf "%-15s %-31s %-8s%-39s %s\n", 53 | "\U${si}${o}${suf}", 54 | "${mm}reg,${mm}reg,${mm}rm", 55 | '[rvm:', 56 | sprintf("vex.dds.%d.66.0f38.w%d %02x /r]", 57 | $l, $w, $op), 58 | "FMA,FUTURE,${sx}"; 59 | } 60 | } 61 | $op += 0x10; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /misc/hints.txt: -------------------------------------------------------------------------------- 1 | Subject: Re: [nasm-devel] P4 insns 2 | Date: Sat, 05 May 2001 11:39:36 -0500 3 | From: Kyle Markley 4 | Reply-To: nasm-devel@yahoogroups.com 5 | To: nasm-devel@yahoogroups.com 6 | 7 | berkus wrote: 8 | > 9 | > Use The Source, NASM! 10 | > 11 | > Do we have the P4 'probable branch taken' (3e) and 'probable branch 12 | > not taken' (2e) prefixes opcodes? 13 | 14 | They're just segment override prefixes: 2e is CS, 3e is DS. You can just 15 | say 16 | "cs jnz foo" for a not-taken hint, "ds jnz foo" for a taken hint. 17 | 18 | Maybe it would be nice to have a more suggestive name, but you could just 19 | %define one. 20 | 21 | --- 22 | Kyle Markley 23 | 24 | 25 | 26 | Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 27 | -------------------------------------------------------------------------------- /misc/magic: -------------------------------------------------------------------------------- 1 | # Put the following lines in your /etc/magic file to get 'file' to recognise 2 | # RDOFF Object Files 3 | 4 | 0 string RDOFF RDOFF Object File 5 | >5 byte >32 version %c (little endian) 6 | >5 byte <32 version %d (big endian) 7 | -------------------------------------------------------------------------------- /misc/myC32.mac: -------------------------------------------------------------------------------- 1 | ; NASM macro set to make interfacing to 32-bit programs easier 2 | ; Also cool little macros to make NASM emulate some MASM things. 3 | ; 4 | ; Originally included in NASM. Modifications by Peter Johnson, 1999. 5 | ; 6 | 7 | %imacro proc 1 ; begin a procedure definition 8 | %push proc 9 | global %1 10 | %1: push ebp 11 | mov ebp, esp 12 | %assign %$arg 8 13 | ;%assign %$argnum 0 14 | %define %$procname %1 15 | %endmacro 16 | 17 | %imacro arg 0-1 4 ; used with the argument name as a label 18 | %00 equ %$arg 19 | ;%assign %$argnum %$argnum+1 20 | ;.arg%$argnum equ %1 21 | %assign %$arg %1+%$arg 22 | %endmacro 23 | 24 | %imacro endproc 0 25 | %ifnctx proc 26 | %error Mismatched `endproc'/`proc' 27 | %else 28 | ; mov esp, ebp 29 | ; pop ebp 30 | %ifdef LEGACY_ENDPROC 31 | ret 32 | %endif 33 | ;__end_%$procname: ; useful for calculating function size 34 | ; global %{$procname}_arglen 35 | ;%{$procname}_arglen equ %$arg-8 36 | ;%assign %$i 1 37 | ;%rep %$argnum 38 | ; global %{$procname}_arg%$i 39 | ;%{$procname}_arg%$i equ %{$procname}.arg%$i 40 | ;%assign %$i %$i+1 41 | ;%endrep 42 | %pop 43 | %endif 44 | %endmacro 45 | 46 | ; redefine ret instructions for in-proc cases 47 | %imacro ret 0-1 48 | %ifnctx proc 49 | ret %1 50 | %else 51 | mov esp, ebp 52 | pop ebp 53 | ret %1 54 | %endif 55 | %endmacro 56 | 57 | %imacro retf 0-1 58 | %ifnctx proc 59 | retf %1 60 | %else 61 | mov esp, ebp 62 | pop ebp 63 | retf %1 64 | %endif 65 | %endmacro 66 | 67 | %imacro retn 0-1 68 | %ifnctx proc 69 | retn %1 70 | %else 71 | mov esp, ebp 72 | pop ebp 73 | retn %1 74 | %endif 75 | %endmacro 76 | 77 | ; invoke calls a C function 78 | ; defaults to word (16 bit) size parameters 79 | %macro invoke 1-* 80 | %rotate -1 81 | ;%define invoketype word 82 | %rep (%0-1) 83 | ; %ifidni %1,dword 84 | ; %define invoketype dword 85 | ; %elifidni %1,word 86 | ; %define invoketype word 87 | ; %elifidni %1,byte 88 | ; %define invoketype byte 89 | ; %else 90 | %ifidni %1, cs 91 | o16 push %1 92 | %elifidni %1, ds 93 | o16 push %1 94 | %elifidni %1, es 95 | o16 push %1 96 | %elifidni %1, fs 97 | o16 push %1 98 | %elifidni %1, gs 99 | o16 push %1 100 | %elifidni %1, word cs 101 | o16 push %1 102 | %elifidni %1, word ds 103 | o16 push %1 104 | %elifidni %1, word es 105 | o16 push %1 106 | %elifidni %1, word fs 107 | o16 push %1 108 | %elifidni %1, word gs 109 | o16 push %1 110 | %else 111 | push %1 112 | %endif 113 | ; %endif 114 | %rotate -1 115 | %endrep 116 | call %1 117 | %if (%0!=1) 118 | add esp, byte %{1}_arglen 119 | %endif 120 | %endmacro 121 | 122 | -------------------------------------------------------------------------------- /misc/pmw.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem some batch file to bind nasm and ndisasm with pmode/w 3 | rem a mega cool dos extender for watcom done by tran 4 | rem 5 | rem max 8 megs, dpmi stack 256*16=4096, no banner 6 | pmwlite.exe nasm.exe 7 | pmwsetup.exe /X8388608 /P256 /B0 nasm.exe 8 | pmwlite.exe ndisasm.exe 9 | pmwsetup.exe /X8388608 /P256 /B0 ndisasm.exe 10 | -------------------------------------------------------------------------------- /misc/xcrcgen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Produce a "generalized CRC" table. Assumes a platform with 3 | * /dev/urandom -- otherwise reimplement get_random_byte(). 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | static uint8_t get_random_byte(void) 14 | { 15 | static int fd = -1; 16 | uint8_t buf; 17 | int rv; 18 | 19 | if (fd < 0) 20 | fd = open("/dev/urandom", O_RDONLY); 21 | 22 | do { 23 | errno = 0; 24 | rv = read(fd, &buf, 1); 25 | if (rv < 1 && errno != EAGAIN) 26 | abort(); 27 | } while (rv < 1); 28 | 29 | return buf; 30 | } 31 | 32 | static void random_permute(uint8_t *buf) 33 | { 34 | int i, j, k; 35 | int m; 36 | 37 | for (i = 0; i < 256; i++) 38 | buf[i] = i; 39 | 40 | m = 255; 41 | for (i = 255; i > 0; i--) { 42 | if (i <= (m >> 1)) 43 | m >>= 1; 44 | do { 45 | j = get_random_byte() & m; 46 | } while (j > i); 47 | k = buf[i]; 48 | buf[i] = buf[j]; 49 | buf[j] = k; 50 | } 51 | } 52 | 53 | static void xcrc_table(uint64_t *buf) 54 | { 55 | uint8_t perm[256]; 56 | int i, j; 57 | 58 | memset(buf, 0, 8*256); /* Make static checkers happy */ 59 | 60 | for (i = 0; i < 8; i++) { 61 | random_permute(perm); 62 | for (j = 0; j < 256; j++) 63 | buf[j] = (buf[j] << 8) | perm[j]; 64 | } 65 | } 66 | 67 | int main(void) 68 | { 69 | int i; 70 | uint64_t buf[256]; 71 | 72 | xcrc_table(buf); 73 | 74 | for (i = 0; i < 256; i++) { 75 | printf("%016"PRIx64"\n", buf[i]); 76 | } 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /nasmlib/alloc.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2018 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #ifndef NASMLIB_ALLOC_H 35 | #define NASMLIB_ALLOC_H 36 | 37 | #include "compiler.h" 38 | 39 | fatal_func nasm_alloc_failed(void); 40 | 41 | static inline void *validate_ptr(void *p) 42 | { 43 | if (unlikely(!p)) 44 | nasm_alloc_failed(); 45 | return p; 46 | } 47 | 48 | extern size_t _nasm_last_string_size; 49 | 50 | #endif /* NASMLIB_ALLOC_H */ 51 | -------------------------------------------------------------------------------- /nasmlib/asprintf.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2018 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #include "compiler.h" 35 | #include "nasmlib.h" 36 | #include "alloc.h" 37 | 38 | /* 39 | * nasm_[v]asprintf() are variants of the semi-standard [v]asprintf() 40 | * functions, except that we return the pointer instead of a count. 41 | * The length of the string (with or without the final NUL) is available 42 | * by calling nasm_last_string_{len,size}() afterwards. 43 | * 44 | * nasm_[v]axprintf() are similar, but allocates a user-defined amount 45 | * of storage before the string, and returns a pointer to the 46 | * allocated buffer. The size of that area is not included in the value 47 | * returned by nasm_last_string_size(). 48 | */ 49 | 50 | void *nasm_vaxprintf(size_t extra, const char *fmt, va_list ap) 51 | { 52 | char *strp; 53 | va_list xap; 54 | size_t bytes; 55 | 56 | va_copy(xap, ap); 57 | bytes = vsnprintf(NULL, 0, fmt, xap) + 1; 58 | _nasm_last_string_size = bytes; 59 | va_end(xap); 60 | 61 | strp = nasm_malloc(extra+bytes); 62 | memset(strp, 0, extra); 63 | vsnprintf(strp+extra, bytes, fmt, ap); 64 | return strp; 65 | } 66 | 67 | char *nasm_vasprintf(const char *fmt, va_list ap) 68 | { 69 | return nasm_vaxprintf(0, fmt, ap); 70 | } 71 | 72 | void *nasm_axprintf(size_t extra, const char *fmt, ...) 73 | { 74 | va_list ap; 75 | void *strp; 76 | 77 | va_start(ap, fmt); 78 | strp = nasm_vaxprintf(extra, fmt, ap); 79 | va_end(ap); 80 | 81 | return strp; 82 | } 83 | 84 | char *nasm_asprintf(const char *fmt, ...) 85 | { 86 | va_list ap; 87 | char *strp; 88 | 89 | va_start(ap, fmt); 90 | strp = nasm_vaxprintf(0, fmt, ap); 91 | va_end(ap); 92 | 93 | return strp; 94 | } 95 | -------------------------------------------------------------------------------- /nasmlib/badenum.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 2017 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #include "nasmlib.h" 35 | 36 | /* Used to avoid returning NULL to a debug printing function */ 37 | const char *invalid_enum_str(int x) 38 | { 39 | static char buf[64]; 40 | 41 | snprintf(buf, sizeof buf, "", x); 42 | return buf; 43 | } 44 | -------------------------------------------------------------------------------- /nasmlib/bsi.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2016 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * nasmlib.c library routines for the Netwide Assembler 36 | */ 37 | 38 | #include "compiler.h" 39 | 40 | 41 | #include "nasmlib.h" 42 | 43 | /* 44 | * Binary search. 45 | */ 46 | int bsi(const char *string, const char **array, int size) 47 | { 48 | int i = -1, j = size; /* always, i < index < j */ 49 | while (j - i >= 2) { 50 | int k = (i + j) / 2; 51 | int l = strcmp(string, array[k]); 52 | if (l < 0) /* it's in the first half */ 53 | j = k; 54 | else if (l > 0) /* it's in the second half */ 55 | i = k; 56 | else /* we've got it :) */ 57 | return k; 58 | } 59 | return -1; /* we haven't got it :( */ 60 | } 61 | 62 | int bsii(const char *string, const char **array, int size) 63 | { 64 | int i = -1, j = size; /* always, i < index < j */ 65 | while (j - i >= 2) { 66 | int k = (i + j) / 2; 67 | int l = nasm_stricmp(string, array[k]); 68 | if (l < 0) /* it's in the first half */ 69 | j = k; 70 | else if (l > 0) /* it's in the second half */ 71 | i = k; 72 | else /* we've got it :) */ 73 | return k; 74 | } 75 | return -1; /* we haven't got it :( */ 76 | } 77 | -------------------------------------------------------------------------------- /nasmlib/errfile.c: -------------------------------------------------------------------------------- 1 | #include "compiler.h" 2 | 3 | FILE *error_file; 4 | 5 | -------------------------------------------------------------------------------- /nasmlib/filename.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2017 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * nasmlib.c library routines for the Netwide Assembler 36 | */ 37 | 38 | #include "compiler.h" 39 | #include "nasmlib.h" 40 | #include "error.h" 41 | 42 | /* 43 | * Add/modify a filename extension, assumed to be a period-delimited 44 | * field at the very end of the filename. Returns a newly allocated 45 | * string buffer. 46 | */ 47 | const char *filename_set_extension(const char *inname, const char *extension) 48 | { 49 | const char *q = inname; 50 | char *p; 51 | size_t elen = strlen(extension); 52 | size_t baselen; 53 | 54 | q = strrchrnul(inname, '.'); /* find extension or end of string */ 55 | baselen = q - inname; 56 | 57 | p = nasm_malloc(baselen + elen + 1); 58 | 59 | memcpy(p, inname, baselen); 60 | memcpy(p+baselen, extension, elen+1); 61 | 62 | return p; 63 | } 64 | -------------------------------------------------------------------------------- /nasmlib/ilog2.c: -------------------------------------------------------------------------------- 1 | #define ILOG2_C 2 | #include "ilog2.h" 3 | -------------------------------------------------------------------------------- /nasmlib/nctype.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2018 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #include "nctype.h" 35 | #include 36 | 37 | /* 38 | * Table of tolower() results. This avoids function calls 39 | * on some platforms. 40 | */ 41 | unsigned char nasm_tolower_tab[256]; 42 | 43 | static void tolower_tab_init(void) 44 | { 45 | int i; 46 | 47 | for (i = 0; i < 256; i++) 48 | nasm_tolower_tab[i] = tolower(i); 49 | } 50 | 51 | /* 52 | * Table of character type flags; some are simply , 53 | * some are NASM-specific. 54 | */ 55 | 56 | uint16_t nasm_ctype_tab[256]; 57 | 58 | #if !defined(HAVE_ISCNTRL) && !defined(iscntrl) 59 | # define iscntrl(x) ((x) < 32) 60 | #endif 61 | #if !defined(HAVE_ISASCII) && !defined(isascii) 62 | # define isascii(x) ((x) < 128) 63 | #endif 64 | 65 | static void ctype_tab_init(void) 66 | { 67 | int i; 68 | 69 | for (i = 0; i < 256; i++) { 70 | enum nasm_ctype ct = 0; 71 | 72 | if (iscntrl(i)) 73 | ct |= NCT_CTRL; 74 | 75 | if (isascii(i)) 76 | ct |= NCT_ASCII; 77 | 78 | if (isspace(i) && i != '\n') 79 | ct |= NCT_SPACE; 80 | 81 | if (isalpha(i)) { 82 | ct |= (nasm_tolower(i) == i) ? NCT_LOWER : NCT_UPPER; 83 | ct |= NCT_ID|NCT_IDSTART; 84 | } 85 | 86 | if (isdigit(i)) 87 | ct |= NCT_DIGIT|NCT_ID; 88 | 89 | if (isxdigit(i)) 90 | ct |= NCT_HEX; 91 | 92 | /* Non-ASCII character, but no ctype returned (e.g. Unicode) */ 93 | if (!ct && !ispunct(i)) 94 | ct |= NCT_ID|NCT_IDSTART; 95 | 96 | nasm_ctype_tab[i] = ct; 97 | } 98 | 99 | nasm_ctype_tab['-'] |= NCT_MINUS; 100 | nasm_ctype_tab['$'] |= NCT_DOLLAR|NCT_ID; 101 | nasm_ctype_tab['_'] |= NCT_UNDER|NCT_ID|NCT_IDSTART; 102 | nasm_ctype_tab['.'] |= NCT_ID|NCT_IDSTART; 103 | nasm_ctype_tab['@'] |= NCT_ID|NCT_IDSTART; 104 | nasm_ctype_tab['?'] |= NCT_ID|NCT_IDSTART; 105 | nasm_ctype_tab['#'] |= NCT_ID; 106 | nasm_ctype_tab['~'] |= NCT_ID; 107 | nasm_ctype_tab['\''] |= NCT_QUOTE; 108 | nasm_ctype_tab['\"'] |= NCT_QUOTE; 109 | nasm_ctype_tab['`'] |= NCT_QUOTE; 110 | } 111 | 112 | void nasm_ctype_init(void) 113 | { 114 | tolower_tab_init(); 115 | ctype_tab_init(); 116 | } 117 | -------------------------------------------------------------------------------- /nasmlib/perfhash.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 2017 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #include "perfhash.h" 35 | #include "hashtbl.h" /* For crc64i() */ 36 | 37 | int perfhash_find(const struct perfect_hash *hash, const char *str) 38 | { 39 | uint32_t k1, k2; 40 | uint64_t crc; 41 | uint16_t ix; 42 | 43 | crc = crc64i(hash->crcinit, str); 44 | k1 = (uint32_t)crc & hash->hashmask; 45 | k2 = ((uint32_t)(crc >> 32) & hash->hashmask) + 1; 46 | 47 | ix = hash->hashvals[k1] + hash->hashvals[k2]; 48 | 49 | if (ix >= hash->tbllen || 50 | !hash->strings[ix] || 51 | nasm_stricmp(str, hash->strings[ix])) 52 | return hash->errval; 53 | 54 | return hash->tbloffs + ix; 55 | } 56 | -------------------------------------------------------------------------------- /nasmlib/realpath.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 2016 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * realpath.c As system-independent as possible implementation of realpath() 36 | */ 37 | 38 | #include "compiler.h" 39 | 40 | #include 41 | #ifdef HAVE_UNISTD_H 42 | # include 43 | #endif 44 | #ifdef HAVE_SYS_PARAM_H 45 | # include 46 | #endif 47 | 48 | #include "nasmlib.h" 49 | 50 | #ifdef HAVE_CANONICALIZE_FILE_NAME 51 | 52 | /* 53 | * GNU-specific, but avoids the realpath(..., NULL) 54 | * portability problem if it exists. 55 | */ 56 | char *nasm_realpath(const char *rel_path) 57 | { 58 | char *rp = canonicalize_file_name(rel_path); 59 | return rp ? rp : nasm_strdup(rel_path); 60 | } 61 | 62 | #elif defined(HAVE_REALPATH) 63 | 64 | /* 65 | * POSIX.1-2008 defines realpath(..., NULL); POSIX.1-2001 doesn't guarantee 66 | * that a NULL second argument is supported. 67 | */ 68 | 69 | char *nasm_realpath(const char *rel_path) 70 | { 71 | char *rp; 72 | 73 | rp = realpath(rel_path, NULL); 74 | 75 | /* Not all implementations of realpath() support a NULL second argument */ 76 | if (!rp && errno == EINVAL) { 77 | long path_max = -1; 78 | char *rp; 79 | 80 | #if defined(HAVE_PATHCONF) && defined(_PC_PATH_MAX) 81 | path_max = pathconf(rel_path, _PC_PATH_MAX); /* POSIX */ 82 | #endif 83 | 84 | if (path_max < 0) { 85 | #ifdef PATH_MAX 86 | path_max = PATH_MAX; /* SUSv2 */ 87 | #elif defined(MAXPATHLEN) 88 | path_max = MAXPATHLEN; /* Solaris */ 89 | #else 90 | path_max = 65536; /* Crazily high, we hope */ 91 | #endif 92 | } 93 | 94 | rp = nasm_malloc(path_max); 95 | 96 | if (!realpath(rel_path, rp)) { 97 | nasm_free(rp); 98 | rp = NULL; 99 | } else { 100 | /* On some systems, pathconf() can return a very large value */ 101 | 102 | rp[path_max - 1] = '\0'; /* Just in case overrun is possible */ 103 | rp = nasm_realloc(rp, strlen(rp) + 1); 104 | } 105 | } 106 | 107 | return rp ? rp : nasm_strdup(rel_path); 108 | } 109 | 110 | #elif defined(HAVE__FULLPATH) 111 | 112 | /* 113 | * win32/win64 API 114 | */ 115 | 116 | char *nasm_realpath(const char *rel_path) 117 | { 118 | char *rp = _fullpath(NULL, rel_path, 0); 119 | return rp ? rp : nasm_strdup(rel_path); 120 | } 121 | 122 | #else 123 | 124 | /* 125 | * There is nothing we know how to do here, so hope it just works anyway. 126 | */ 127 | 128 | char *nasm_realpath(const char *rel_path) 129 | { 130 | return nasm_strdup(rel_path); 131 | } 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /nasmlib/rlimit.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 2020 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #include "compiler.h" 35 | #include "nasmlib.h" 36 | 37 | #ifdef HAVE_SYS_RESOURCE_H 38 | # include 39 | #endif 40 | 41 | #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_STACK) 42 | 43 | size_t nasm_get_stack_size_limit(void) 44 | { 45 | struct rlimit rl; 46 | 47 | if (getrlimit(RLIMIT_STACK, &rl)) 48 | return SIZE_MAX; 49 | 50 | # ifdef RLIM_SAVED_MAX 51 | if (rl.rlim_cur == RLIM_SAVED_MAX) 52 | rl.rlim_cur = rl.rlim_max; 53 | # endif 54 | 55 | if ( 56 | # ifdef RLIM_INFINITY 57 | rl.rlim_cur >= RLIM_INFINITY || 58 | # endif 59 | # ifdef RLIM_SAVED_CUR 60 | rl.rlim_cur == RLIM_SAVED_CUR || 61 | # endif 62 | # ifdef RLIM_SAVED_MAX 63 | rl.rlim_cur == RLIM_SAVED_MAX || 64 | # endif 65 | (size_t)rl.rlim_cur != rl.rlim_cur) 66 | return SIZE_MAX; 67 | 68 | return rl.rlim_cur; 69 | } 70 | 71 | #else 72 | 73 | size_t nasm_get_stack_size_limit(void) 74 | { 75 | return SIZE_MAX; 76 | } 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /nasmlib/ver.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2020 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #include "ver.h" 35 | #include "version.h" 36 | 37 | /* This is printed when entering nasm -v */ 38 | const char nasm_version[] = NASM_VER; 39 | const char nasm_date[] = ""; 40 | const char nasm_compile_options[] = "" 41 | #ifdef DEBUG 42 | " with -DDEBUG" 43 | #endif 44 | ; 45 | 46 | bool reproducible; /* Reproducible output */ 47 | 48 | /* These are used by some backends. For a reproducible build, 49 | * these cannot contain version numbers. 50 | */ 51 | static const char * const _nasm_comment[2] = 52 | { 53 | "The Netwide Assembler " NASM_VER, 54 | "The Netwide Assembler" 55 | }; 56 | 57 | static const char * const _nasm_signature[2] = { 58 | "NASM " NASM_VER, 59 | "NASM" 60 | }; 61 | 62 | const char *nasm_comment(void) 63 | { 64 | return _nasm_comment[reproducible]; 65 | } 66 | 67 | size_t nasm_comment_len(void) 68 | { 69 | return strlen(nasm_comment()); 70 | } 71 | 72 | const char *nasm_signature(void) 73 | { 74 | return _nasm_signature[reproducible]; 75 | } 76 | 77 | size_t nasm_signature_len(void) 78 | { 79 | return strlen(nasm_signature()); 80 | } 81 | -------------------------------------------------------------------------------- /nasmlib/zerobuf.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2016 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * nasmlib.c library routines for the Netwide Assembler 36 | */ 37 | 38 | #include "compiler.h" 39 | #include "nasmlib.h" 40 | 41 | /* Uninitialized -> all zero by C spec */ 42 | const uint8_t zero_buffer[ZERO_BUF_SIZE]; 43 | -------------------------------------------------------------------------------- /output/legacy.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 2016-2022 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * output/legacy.c 36 | * 37 | * Mangle a struct out_data to match the rather bizarre legacy 38 | * backend interface. 39 | * 40 | * The "data" parameter for the output function points to a "int64_t", 41 | * containing the address of the target in question, unless the type is 42 | * OUT_RAWDATA, in which case it points to an "uint8_t" 43 | * array. 44 | * 45 | * Exceptions are OUT_RELxADR, which denote an x-byte relocation 46 | * which will be a relative jump. For this we need to know the 47 | * distance in bytes from the start of the relocated record until 48 | * the end of the containing instruction. _This_ is what is stored 49 | * in the size part of the parameter, in this case. 50 | * 51 | * Also OUT_RESERVE denotes reservation of N bytes of BSS space, 52 | * and the contents of the "data" parameter is irrelevant. 53 | */ 54 | 55 | #include "nasm.h" 56 | #include "outlib.h" 57 | 58 | void nasm_do_legacy_output(const struct out_data *data) 59 | { 60 | const void *dptr = data->data; 61 | enum out_type type = data->type; 62 | int32_t tsegment = data->tsegment; 63 | int32_t twrt = data->twrt; 64 | uint64_t size = data->size; 65 | 66 | switch (data->type) { 67 | case OUT_RELADDR: 68 | switch (data->size) { 69 | case 1: 70 | type = OUT_REL1ADR; 71 | break; 72 | case 2: 73 | type = OUT_REL2ADR; 74 | break; 75 | case 4: 76 | type = OUT_REL4ADR; 77 | break; 78 | case 8: 79 | type = OUT_REL8ADR; 80 | break; 81 | default: 82 | panic(); 83 | break; 84 | } 85 | 86 | dptr = &data->toffset; 87 | size = data->relbase - data->offset; 88 | break; 89 | 90 | case OUT_SEGMENT: 91 | type = OUT_ADDRESS; 92 | tsegment |= 1; 93 | /* fall through */ 94 | 95 | case OUT_ADDRESS: 96 | dptr = &data->toffset; 97 | size = (data->flags & OUT_SIGNED) ? -data->size : data->size; 98 | break; 99 | 100 | case OUT_RAWDATA: 101 | case OUT_RESERVE: 102 | tsegment = twrt = NO_SEG; 103 | break; 104 | 105 | case OUT_ZERODATA: 106 | tsegment = twrt = NO_SEG; 107 | type = OUT_RAWDATA; 108 | dptr = zero_buffer; 109 | while (size > ZERO_BUF_SIZE) { 110 | ofmt->legacy_output(data->segment, dptr, type, 111 | ZERO_BUF_SIZE, tsegment, twrt); 112 | size -= ZERO_BUF_SIZE; 113 | } 114 | break; 115 | 116 | default: 117 | panic(); 118 | break; 119 | } 120 | 121 | ofmt->legacy_output(data->segment, dptr, type, size, tsegment, twrt); 122 | } 123 | -------------------------------------------------------------------------------- /output/nulldbg.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2014 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #include "nasm.h" 35 | #include "nasmlib.h" 36 | #include "outlib.h" 37 | 38 | void null_debug_init(void) 39 | { 40 | } 41 | 42 | void null_debug_linenum(const char *filename, int32_t linenumber, int32_t segto) 43 | { 44 | (void)filename; 45 | (void)linenumber; 46 | (void)segto; 47 | } 48 | 49 | void null_debug_deflabel(char *name, int32_t segment, int64_t offset, 50 | int is_global, char *special) 51 | { 52 | (void)name; 53 | (void)segment; 54 | (void)offset; 55 | (void)is_global; 56 | (void)special; 57 | } 58 | 59 | void null_debug_directive(const char *directive, const char *params) 60 | { 61 | (void)directive; 62 | (void)params; 63 | } 64 | 65 | void null_debug_typevalue(int32_t type) 66 | { 67 | (void)type; 68 | } 69 | 70 | void null_debug_output(int type, void *param) 71 | { 72 | (void)type; 73 | (void)param; 74 | } 75 | 76 | void null_debug_cleanup(void) 77 | { 78 | } 79 | 80 | const struct dfmt null_debug_form = { 81 | "Null", 82 | "null", 83 | null_debug_init, 84 | null_debug_linenum, 85 | null_debug_deflabel, 86 | NULL, /* .debug_smacros */ 87 | NULL, /* .debug_include */ 88 | NULL, /* .debug_mmacros */ 89 | null_debug_directive, 90 | null_debug_typevalue, 91 | null_debug_output, 92 | null_debug_cleanup, 93 | NULL /* pragma list */ 94 | }; 95 | 96 | const struct dfmt * const null_debug_arr[2] = { &null_debug_form, NULL }; 97 | -------------------------------------------------------------------------------- /output/nullout.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2018 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #include "nasm.h" 35 | #include "nasmlib.h" 36 | #include "outlib.h" 37 | 38 | enum directive_result 39 | null_directive(enum directive directive, char *value) 40 | { 41 | (void)directive; 42 | (void)value; 43 | return DIRR_UNKNOWN; 44 | } 45 | 46 | void null_sectalign(int32_t seg, unsigned int value) 47 | { 48 | (void)seg; 49 | (void)value; 50 | } 51 | 52 | void null_reset(void) 53 | { 54 | /* Nothing to do */ 55 | } 56 | 57 | int32_t null_segbase(int32_t segment) 58 | { 59 | return segment; 60 | } 61 | -------------------------------------------------------------------------------- /output/outaout.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | OUT: aout aoutb 35 | %define __?SECT?__ [section .text] 36 | %macro __?NASM_CDecl?__ 1 37 | %endmacro 38 | -------------------------------------------------------------------------------- /output/outas86.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | OUT: as86 35 | %define __?SECT?__ [section .text] 36 | %macro __?NASM_CDecl?__ 1 37 | %endmacro 38 | -------------------------------------------------------------------------------- /output/outbin.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | OUT: bin 35 | %define __?SECT?__ [section .text] 36 | %imacro org 1+.nolist 37 | [org %1] 38 | %endmacro 39 | %macro __?NASM_CDecl?__ 1 40 | %endmacro 41 | -------------------------------------------------------------------------------- /output/outcoff.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | OUT: coff win32 win64 35 | %define __?SECT?__ [section .text] 36 | %macro __?NASM_CDecl?__ 1 37 | %endmacro 38 | %imacro export 1+.nolist 39 | [export %1] 40 | %endmacro 41 | %imacro safeseh 1.nolist 42 | [safeseh %1] 43 | %endmacro 44 | -------------------------------------------------------------------------------- /output/outdbg.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2017 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | ; 35 | ; Define a few macros which lets the dbg format process files intended 36 | ; for the .obj and .bin formats. 37 | ; 38 | OUT: dbg 39 | %define __?SECT?__ [section .text] 40 | %imacro group 1+.nolist 41 | [group %1] 42 | %endmacro 43 | %imacro uppercase 0+.nolist 44 | %pragma dbg uppercase %1 45 | %endmacro 46 | %imacro export 1+.nolist 47 | %pragma dbg export %1 48 | %endmacro 49 | %imacro import 1+.nolist 50 | %pragma dbg import %1 51 | %endmacro 52 | %imacro org 1+.nolist 53 | %pragma dbg org %1 54 | %endmacro 55 | %macro __?NASM_CDecl?__ 1 56 | %endmacro 57 | -------------------------------------------------------------------------------- /output/outelf.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2017 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | OUT: elf elf32 elf64 35 | %define __?SECT?__ [section .text] 36 | %macro __?NASM_CDecl?__ 1 37 | %define $_%1 $%1 38 | %endmacro 39 | %imacro osabi 1+.nolist 40 | [%? %1] 41 | %endmacro 42 | -------------------------------------------------------------------------------- /output/outmacho.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2017 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | OUT: macho macho32 macho64 35 | %define __?SECT?__ [section .text] 36 | %macro __?NASM_CDecl?__ 1 37 | %endmacro 38 | 39 | ; This directive sets the MH_SUBSECTIONS_VIA_SYMBOLS header flag 40 | %imacro subsections_via_symbols 0.nolist 41 | %pragma __?OUTPUT_FORMAT?__ %? 42 | %endmacro 43 | 44 | %imacro no_dead_strip 1-*.nolist 45 | %rep %0 46 | %pragma __?OUTPUT_FORMAT?__ %? %1 47 | %rotate 1 48 | %endrep 49 | %endmacro 50 | -------------------------------------------------------------------------------- /output/outobj.mac: -------------------------------------------------------------------------------- 1 | ;; -------------------------------------------------------------------------- 2 | ;; 3 | ;; Copyright 1996-2009 The NASM Authors - All Rights Reserved 4 | ;; See the file AUTHORS included with the NASM distribution for 5 | ;; the specific copyright holders. 6 | ;; 7 | ;; Redistribution and use in source and binary forms, with or without 8 | ;; modification, are permitted provided that the following 9 | ;; conditions are met: 10 | ;; 11 | ;; * Redistributions of source code must retain the above copyright 12 | ;; notice, this list of conditions and the following disclaimer. 13 | ;; * Redistributions in binary form must reproduce the above 14 | ;; copyright notice, this list of conditions and the following 15 | ;; disclaimer in the documentation and/or other materials provided 16 | ;; with the distribution. 17 | ;; 18 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | ;; 32 | ;; -------------------------------------------------------------------------- 33 | 34 | OUT: obj 35 | %define __?SECT?__ [section .text] 36 | %imacro group 1+.nolist 37 | [group %1] 38 | %endmacro 39 | %imacro uppercase 0+.nolist 40 | [uppercase %1] 41 | %endmacro 42 | %imacro export 1+.nolist 43 | [export %1] 44 | %endmacro 45 | %imacro import 1+.nolist 46 | [import %1] 47 | %endmacro 48 | %macro __?NASM_CDecl?__ 1 49 | %endmacro 50 | -------------------------------------------------------------------------------- /perllib/gensv.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # Generate a list of rotation vectors so we always use the same set. 4 | # This needs to be run on a platform with /dev/urandom. 5 | # 6 | 7 | ($n) = @ARGV; 8 | 9 | sysopen(UR, '/dev/urandom', O_RDONLY) or die; 10 | 11 | $maxlen = 78; 12 | 13 | print "\@random_sv_vectors = (\n"; 14 | $outl = ' '; 15 | 16 | for ($i = 0; $i < $n; $i++) { 17 | 18 | die if (sysread(UR, $x8, 8) != 8); 19 | @n = unpack("V*", $x8); 20 | 21 | $xl = sprintf(" [0x%08x, 0x%08x]%s", 22 | $n[0], $n[1], 23 | ($i == $n-1) ? '' : ','); 24 | if (length($outl.$xl) > $maxlen) { 25 | print $outl, "\n"; 26 | $outl = ' '; 27 | } 28 | $outl .= $xl; 29 | } 30 | close(UR); 31 | 32 | print $outl, "\n"; 33 | print ");\n"; 34 | print "1;\n"; 35 | -------------------------------------------------------------------------------- /perllib/random_sv_vectors.ph: -------------------------------------------------------------------------------- 1 | @random_sv_vectors = ( 2 | [0x076259c3, 0xe291c26c], [0xaee7ac5c, 0xcabdec91], 3 | [0x5d3862fb, 0x2e8a3060], [0x6fb3635c, 0x4783593a], 4 | [0x13f0eafb, 0x407e486a], [0x7436afdd, 0xd04c4829], 5 | [0xace2d0e4, 0x80575791], [0x2dd9a392, 0xdc1e869e], 6 | [0x199c3e38, 0x026a9d67], [0x9f911c85, 0x3a489c87], 7 | [0x9ac31028, 0x0b6e14b2], [0x2ccfbcf9, 0x3f9f2308], 8 | [0x2e0210fb, 0x392f380f], [0x14ab403a, 0x81a11065], 9 | [0xd496f63c, 0x53196b13], [0x48a34d7f, 0x2ffc6036], 10 | [0x34ea8e9d, 0xcd1ed098], [0x2da1a3f2, 0x3d6c23f2], 11 | [0xca7374da, 0x06054f89], [0xc909a0bb, 0x31d6c0d2], 12 | [0x87454496, 0x15b360d7], [0x9eebbd12, 0x89532131], 13 | [0x1119c65b, 0xd9e49705], [0x60c3be0b, 0xd6cc7c8a], 14 | [0x117723cd, 0x40af090f], [0xfc284f51, 0x3dcf4c06], 15 | [0xb41fcda4, 0xec03644c], [0xd99e1ea7, 0x84eaf76d], 16 | [0x534b956a, 0x06d3fb8d], [0x2da4bb09, 0x078092eb], 17 | [0x6a5be463, 0xbfa51a88], [0xc4e8be95, 0xe7eec27c], 18 | [0x15a1fbb9, 0xfadc08cd], [0x0bcfab08, 0xbccade0f], 19 | [0x629f1f6c, 0x90ccede7], [0x5c2b26aa, 0x1f0b1fce], 20 | [0xdfe0e3fd, 0xbd7c3cfb], [0xa1628ca9, 0x90a05686], 21 | [0xbf0267f2, 0xd2964139], [0x8009a9b9, 0xd2195918], 22 | [0xfcc7b5f8, 0xc108c643], [0xf447d4b0, 0x71953863], 23 | [0x95d091ed, 0xdbe01948], [0x81dec325, 0x2bfecda2], 24 | [0x2ed2acaa, 0x7eeaa0d0], [0xb7b0a20e, 0x8bf5c01b], 25 | [0x75eb3917, 0xfd2f758f], [0xb33a5b49, 0x8a8cedf6], 26 | [0x3aaf2757, 0x69b319a9], [0x32cfa41b, 0xeba36f19], 27 | [0xf54209dd, 0x941f3a08], [0x232703bb, 0x786a6f84], 28 | [0x4937b242, 0xc9f07398], [0x74dc5d39, 0x550a58e8], 29 | [0x6c9aebdc, 0x8fda5069], [0x5ae6d62a, 0x05cd24a3], 30 | [0x8111e50a, 0xc1c6d19b], [0xb980a92b, 0x448b4d1f], 31 | [0x568cf58a, 0x8bcb93ca], [0xfe96002f, 0x410cd2f1], 32 | [0xaf511e45, 0x99e4872f], [0x822c20bc, 0x3db49ddd], 33 | [0x184fec4e, 0xbb82ec52], [0x30ca5326, 0xf3180297], 34 | [0x97962aa4, 0x7d4bc6d4], [0x9199a315, 0x8e9f18c6], 35 | [0xead69a7e, 0x3262a683], [0xe261ec00, 0x81edc47a], 36 | [0x06080c0e, 0x6d18fa9f], [0x1771ec43, 0x6747ed66], 37 | [0xe71fe587, 0xe81ad0f3], [0xf083e80c, 0x0898bcd8], 38 | [0x30328c5a, 0x2efb4ee7], [0xd04fa5d7, 0xec9c9f18], 39 | [0x87820480, 0x48932224], [0xb1f18815, 0x1b27e3e3], 40 | [0x79aa440c, 0xdf17a8fc], [0x8a83d404, 0x10fdec8c], 41 | [0x7d4dfe60, 0x573561ee], [0x60315c7d, 0xa0692af6], 42 | [0xb3ca4d52, 0x89ca832f], [0x9ebc5c79, 0xa84a28fc], 43 | [0xdfa76008, 0x7772cf7c], [0xb0e3a15f, 0xbdc35aee], 44 | [0x6e252b03, 0x32b2107d], [0x20dcc2a3, 0x21987229], 45 | [0x848e3ad8, 0xe692a0c6], [0xdd07fa50, 0x0b64e1ae], 46 | [0xc4072bc2, 0x2f120bba], [0xdb3af26e, 0xacab0c48], 47 | [0xd7d4b59a, 0xcf72a7a7], [0x4628de45, 0x4dfb2750], 48 | [0x7519211f, 0x4798b536], [0x19984af3, 0xffd2aa19], 49 | [0x1372d9c0, 0x7512153a], [0x295d19da, 0x497416e5], 50 | [0x70932c73, 0x8a9bf591], [0xa0960860, 0xfaa7dc61], 51 | [0xd425f548, 0x43aeda4d], [0xaa2573c7, 0x01a2553d], 52 | [0x988e71d7, 0xd3c004a4], [0x3da87545, 0x2197af10], 53 | [0x2f89e592, 0xa686e2fc], [0x7b88018a, 0xae66d575], 54 | [0x93215591, 0xed69e6ea], [0x4fcacc4a, 0x4d2aba97], 55 | [0xbedb923b, 0x500b2f1a], [0x0b6d8aa0, 0x232511b0], 56 | [0x282fb3ee, 0x23695de0], [0x0c455dfe, 0x820cca3f], 57 | [0xe893868c, 0x87f698f6], [0xb6428730, 0x56e576ce], 58 | [0xf3843ee7, 0xba79bc28], [0xa1c9ca45, 0x30c479c1], 59 | [0xbfc244c2, 0xa9af65f0], [0x6eeb88eb, 0x62b4479c], 60 | [0xcc328fe5, 0x60f5c9bf], [0x31aa2c21, 0xc55575fb], 61 | [0x9429492d, 0x8e80612a], [0xb12fe59e, 0xf0e1e97b], 62 | [0xc2501dad, 0x4a9f4bbf], [0x65ae8366, 0x3e8b0983], 63 | [0xd5fc062a, 0xba74f808], [0x7398cc0a, 0x39a6a269], 64 | [0x5581dd60, 0xff79d28c], [0xea5e52b3, 0x9be66c71], 65 | [0x8f6e02a4, 0xe27318b5], [0xe8bceb99, 0xa48a7f2c], 66 | ); 67 | 1; 68 | -------------------------------------------------------------------------------- /stdlib/snprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * snprintf() 3 | * 4 | * Implement snprintf() in terms of vsnprintf() 5 | */ 6 | 7 | #include "compiler.h" 8 | 9 | 10 | #include "nasmlib.h" 11 | 12 | #if !defined(HAVE_SNPRINTF) && !defined(HAVE__SNPRINTF) 13 | 14 | int snprintf(char *str, size_t size, const char *format, ...) 15 | { 16 | va_list ap; 17 | int rv; 18 | 19 | va_start(ap, format); 20 | rv = vsnprintf(str, size, format, ap); 21 | va_end(ap); 22 | 23 | return rv; 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /stdlib/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998 Todd C. Miller 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "compiler.h" 18 | 19 | /* 20 | * Copy src to string dst of size siz. At most siz-1 characters 21 | * will be copied. Always NUL terminates (unless siz == 0). 22 | * Returns strlen(src); if retval >= siz, truncation occurred. 23 | */ 24 | #ifndef HAVE_STRLCPY 25 | 26 | size_t strlcpy(char *dst, const char *src, size_t siz) 27 | { 28 | char *d = dst; 29 | const char *s = src; 30 | size_t n = siz; 31 | 32 | /* Copy as many bytes as will fit */ 33 | if (n != 0) { 34 | while (--n != 0) { 35 | if ((*d++ = *s++) == '\0') 36 | break; 37 | } 38 | } 39 | 40 | /* Not enough room in dst, add NUL and traverse rest of src */ 41 | if (n == 0) { 42 | if (siz != 0) 43 | *d = '\0'; /* NUL-terminate dst */ 44 | while (*s++) 45 | ; 46 | } 47 | 48 | return(s - src - 1); /* count does not include NUL */ 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /stdlib/strnlen.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2016 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #include "compiler.h" 35 | 36 | #ifndef HAVE_STRNLEN 37 | 38 | size_t strnlen(const char *s, size_t maxlen) 39 | { 40 | const char *end = memchr(s, 0, maxlen); 41 | 42 | return end ? (size_t)(end - s) : maxlen; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /stdlib/strrchrnul.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 2017 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | #include "compiler.h" 35 | 36 | #ifndef HAVE_STRRCHRNUL 37 | 38 | char *strrchrnul(const char *s, int c) 39 | { 40 | char *p; 41 | 42 | p = strrchr(s, c); 43 | if (!p) 44 | p = strchr(s, '\0'); 45 | 46 | return p; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /stdlib/vsnprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * vsnprintf() 3 | * 4 | * Poor substitute for a real vsnprintf() function for systems 5 | * that don't have them... 6 | */ 7 | 8 | #include "compiler.h" 9 | 10 | 11 | #include "nasmlib.h" 12 | #include "error.h" 13 | 14 | #if !defined(HAVE_VSNPRINTF) && !defined(HAVE__VSNPRINTF) 15 | 16 | #define BUFFER_SIZE 65536 /* Bigger than any string we might print... */ 17 | 18 | static char snprintf_buffer[BUFFER_SIZE]; 19 | 20 | int vsnprintf(char *str, size_t size, const char *format, va_list ap) 21 | { 22 | int rv, bytes; 23 | 24 | if (size > BUFFER_SIZE) { 25 | nasm_panic("vsnprintf: size (%llu) > BUFFER_SIZE (%d)", 26 | (unsigned long long)size, BUFFER_SIZE); 27 | size = BUFFER_SIZE; 28 | } 29 | 30 | rv = vsprintf(snprintf_buffer, format, ap); 31 | if (rv >= BUFFER_SIZE) 32 | nasm_panic("vsnprintf buffer overflow"); 33 | 34 | if (size > 0) { 35 | if ((size_t)rv < size-1) 36 | bytes = rv; 37 | else 38 | bytes = size-1; 39 | memcpy(str, snprintf_buffer, bytes); 40 | str[bytes] = '\0'; 41 | } 42 | 43 | return rv; 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /x86/disp8.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- * 2 | * 3 | * Copyright 1996-2013 The NASM Authors - All Rights Reserved 4 | * See the file AUTHORS included with the NASM distribution for 5 | * the specific copyright holders. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following 9 | * conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * ----------------------------------------------------------------------- */ 33 | 34 | /* 35 | * disp8.c : Contains a common logic for EVEX compressed displacement 36 | */ 37 | 38 | #include "disp8.h" 39 | 40 | /* 41 | * Find N value for compressed displacement (disp8 * N) 42 | */ 43 | uint8_t get_disp8N(insn *ins) 44 | { 45 | static const uint8_t fv_n[2][2][VLMAX] = {{{16, 32, 64}, {4, 4, 4}}, 46 | {{16, 32, 64}, {8, 8, 8}}}; 47 | static const uint8_t hv_n[2][VLMAX] = {{8, 16, 32}, {4, 4, 4}}; 48 | static const uint8_t dup_n[VLMAX] = {8, 32, 64}; 49 | 50 | bool evex_b = (ins->evex_p[2] & EVEX_P2B) >> 4; 51 | enum ttypes tuple = ins->evex_tuple; 52 | enum vectlens vectlen = (ins->evex_p[2] & EVEX_P2LL) >> 5; 53 | bool evex_w = (ins->evex_p[1] & EVEX_P1W) >> 7; 54 | uint8_t n = 0; 55 | 56 | switch(tuple) { 57 | case FV: 58 | n = fv_n[evex_w][evex_b][vectlen]; 59 | break; 60 | case HV: 61 | n = hv_n[evex_b][vectlen]; 62 | break; 63 | 64 | case FVM: 65 | /* 16, 32, 64 for VL 128, 256, 512 respectively*/ 66 | n = 1 << (vectlen + 4); 67 | break; 68 | case T1S8: /* N = 1 */ 69 | case T1S16: /* N = 2 */ 70 | n = tuple - T1S8 + 1; 71 | break; 72 | case T1S: 73 | /* N = 4 for 32bit, 8 for 64bit */ 74 | n = evex_w ? 8 : 4; 75 | break; 76 | case T1F32: 77 | case T1F64: 78 | /* N = 4 for 32bit, 8 for 64bit */ 79 | n = (tuple == T1F32 ? 4 : 8); 80 | break; 81 | case T2: 82 | case T4: 83 | case T8: 84 | if (vectlen + 7 <= (evex_w + 5) + (tuple - T2 + 1)) 85 | n = 0; 86 | else 87 | n = 1 << (tuple - T2 + evex_w + 3); 88 | break; 89 | case HVM: 90 | case QVM: 91 | case OVM: 92 | n = 1 << (OVM - tuple + vectlen + 1); 93 | break; 94 | case M128: 95 | n = 16; 96 | break; 97 | case DUP: 98 | n = dup_n[vectlen]; 99 | break; 100 | 101 | default: 102 | break; 103 | } 104 | 105 | return n; 106 | } 107 | 108 | /* 109 | * Check if offset is a multiple of N with corresponding tuple type 110 | * if Disp8*N is available, compressed displacement is stored in compdisp 111 | */ 112 | bool is_disp8n(operand *input, insn *ins, int8_t *compdisp) 113 | { 114 | int32_t off = input->offset; 115 | uint8_t n; 116 | int32_t disp8; 117 | 118 | n = get_disp8N(ins); 119 | 120 | if (n && !(off & (n - 1))) { 121 | disp8 = off / n; 122 | /* if it fits in Disp8 */ 123 | if (disp8 >= -128 && disp8 <= 127) { 124 | *compdisp = disp8; 125 | return true; 126 | } 127 | } 128 | 129 | *compdisp = 0; 130 | return false; 131 | } 132 | -------------------------------------------------------------------------------- /x86/regdis.c: -------------------------------------------------------------------------------- 1 | /* automatically generated from ./x86/regs.dat - do not edit */ 2 | 3 | #include "regdis.h" 4 | 5 | const enum reg_enum nasm_rd_bndreg [ 4] = {R_BND0,R_BND1,R_BND2,R_BND3}; 6 | const enum reg_enum nasm_rd_creg [16] = {R_CR0,R_CR1,R_CR2,R_CR3,R_CR4,R_CR5,R_CR6,R_CR7,R_CR8,R_CR9,R_CR10,R_CR11,R_CR12,R_CR13,R_CR14,R_CR15}; 7 | const enum reg_enum nasm_rd_dreg [16] = {R_DR0,R_DR1,R_DR2,R_DR3,R_DR4,R_DR5,R_DR6,R_DR7,R_DR8,R_DR9,R_DR10,R_DR11,R_DR12,R_DR13,R_DR14,R_DR15}; 8 | const enum reg_enum nasm_rd_fpureg [ 8] = {R_ST0,R_ST1,R_ST2,R_ST3,R_ST4,R_ST5,R_ST6,R_ST7}; 9 | const enum reg_enum nasm_rd_mmxreg [ 8] = {R_MM0,R_MM1,R_MM2,R_MM3,R_MM4,R_MM5,R_MM6,R_MM7}; 10 | const enum reg_enum nasm_rd_opmaskreg[ 8] = {R_K0,R_K1,R_K2,R_K3,R_K4,R_K5,R_K6,R_K7}; 11 | const enum reg_enum nasm_rd_reg16 [16] = {R_AX,R_CX,R_DX,R_BX,R_SP,R_BP,R_SI,R_DI,R_R8W,R_R9W,R_R10W,R_R11W,R_R12W,R_R13W,R_R14W,R_R15W}; 12 | const enum reg_enum nasm_rd_reg32 [16] = {R_EAX,R_ECX,R_EDX,R_EBX,R_ESP,R_EBP,R_ESI,R_EDI,R_R8D,R_R9D,R_R10D,R_R11D,R_R12D,R_R13D,R_R14D,R_R15D}; 13 | const enum reg_enum nasm_rd_reg64 [16] = {R_RAX,R_RCX,R_RDX,R_RBX,R_RSP,R_RBP,R_RSI,R_RDI,R_R8,R_R9,R_R10,R_R11,R_R12,R_R13,R_R14,R_R15}; 14 | const enum reg_enum nasm_rd_reg8 [ 8] = {R_AL,R_CL,R_DL,R_BL,R_AH,R_CH,R_DH,R_BH}; 15 | const enum reg_enum nasm_rd_reg8_rex[16] = {R_AL,R_CL,R_DL,R_BL,R_SPL,R_BPL,R_SIL,R_DIL,R_R8B,R_R9B,R_R10B,R_R11B,R_R12B,R_R13B,R_R14B,R_R15B}; 16 | const enum reg_enum nasm_rd_sreg [ 8] = {R_ES,R_CS,R_SS,R_DS,R_FS,R_GS,R_SEGR6,R_SEGR7}; 17 | const enum reg_enum nasm_rd_tmmreg [ 8] = {R_TMM0,R_TMM1,R_TMM2,R_TMM3,R_TMM4,R_TMM5,R_TMM6,R_TMM7}; 18 | const enum reg_enum nasm_rd_treg [ 8] = {R_TR0,R_TR1,R_TR2,R_TR3,R_TR4,R_TR5,R_TR6,R_TR7}; 19 | const enum reg_enum nasm_rd_xmmreg [32] = {R_XMM0,R_XMM1,R_XMM2,R_XMM3,R_XMM4,R_XMM5,R_XMM6,R_XMM7,R_XMM8,R_XMM9,R_XMM10,R_XMM11,R_XMM12,R_XMM13,R_XMM14,R_XMM15,R_XMM16,R_XMM17,R_XMM18,R_XMM19,R_XMM20,R_XMM21,R_XMM22,R_XMM23,R_XMM24,R_XMM25,R_XMM26,R_XMM27,R_XMM28,R_XMM29,R_XMM30,R_XMM31}; 20 | const enum reg_enum nasm_rd_ymmreg [32] = {R_YMM0,R_YMM1,R_YMM2,R_YMM3,R_YMM4,R_YMM5,R_YMM6,R_YMM7,R_YMM8,R_YMM9,R_YMM10,R_YMM11,R_YMM12,R_YMM13,R_YMM14,R_YMM15,R_YMM16,R_YMM17,R_YMM18,R_YMM19,R_YMM20,R_YMM21,R_YMM22,R_YMM23,R_YMM24,R_YMM25,R_YMM26,R_YMM27,R_YMM28,R_YMM29,R_YMM30,R_YMM31}; 21 | const enum reg_enum nasm_rd_zmmreg [32] = {R_ZMM0,R_ZMM1,R_ZMM2,R_ZMM3,R_ZMM4,R_ZMM5,R_ZMM6,R_ZMM7,R_ZMM8,R_ZMM9,R_ZMM10,R_ZMM11,R_ZMM12,R_ZMM13,R_ZMM14,R_ZMM15,R_ZMM16,R_ZMM17,R_ZMM18,R_ZMM19,R_ZMM20,R_ZMM21,R_ZMM22,R_ZMM23,R_ZMM24,R_ZMM25,R_ZMM26,R_ZMM27,R_ZMM28,R_ZMM29,R_ZMM30,R_ZMM31}; 22 | -------------------------------------------------------------------------------- /x86/regs.c: -------------------------------------------------------------------------------- 1 | /* automatically generated from ./x86/regs.dat - do not edit */ 2 | 3 | #include "tables.h" 4 | 5 | const char * const nasm_reg_names[] = { 6 | "ah", 7 | "al", 8 | "ax", 9 | "bh", 10 | "bl", 11 | "bnd0", 12 | "bnd1", 13 | "bnd2", 14 | "bnd3", 15 | "bp", 16 | "bpl", 17 | "bx", 18 | "ch", 19 | "cl", 20 | "cr0", 21 | "cr1", 22 | "cr10", 23 | "cr11", 24 | "cr12", 25 | "cr13", 26 | "cr14", 27 | "cr15", 28 | "cr2", 29 | "cr3", 30 | "cr4", 31 | "cr5", 32 | "cr6", 33 | "cr7", 34 | "cr8", 35 | "cr9", 36 | "cs", 37 | "cx", 38 | "dh", 39 | "di", 40 | "dil", 41 | "dl", 42 | "dr0", 43 | "dr1", 44 | "dr10", 45 | "dr11", 46 | "dr12", 47 | "dr13", 48 | "dr14", 49 | "dr15", 50 | "dr2", 51 | "dr3", 52 | "dr4", 53 | "dr5", 54 | "dr6", 55 | "dr7", 56 | "dr8", 57 | "dr9", 58 | "ds", 59 | "dx", 60 | "eax", 61 | "ebp", 62 | "ebx", 63 | "ecx", 64 | "edi", 65 | "edx", 66 | "es", 67 | "esi", 68 | "esp", 69 | "fs", 70 | "gs", 71 | "k0", 72 | "k1", 73 | "k2", 74 | "k3", 75 | "k4", 76 | "k5", 77 | "k6", 78 | "k7", 79 | "mm0", 80 | "mm1", 81 | "mm2", 82 | "mm3", 83 | "mm4", 84 | "mm5", 85 | "mm6", 86 | "mm7", 87 | "r10", 88 | "r10b", 89 | "r10d", 90 | "r10w", 91 | "r11", 92 | "r11b", 93 | "r11d", 94 | "r11w", 95 | "r12", 96 | "r12b", 97 | "r12d", 98 | "r12w", 99 | "r13", 100 | "r13b", 101 | "r13d", 102 | "r13w", 103 | "r14", 104 | "r14b", 105 | "r14d", 106 | "r14w", 107 | "r15", 108 | "r15b", 109 | "r15d", 110 | "r15w", 111 | "r8", 112 | "r8b", 113 | "r8d", 114 | "r8w", 115 | "r9", 116 | "r9b", 117 | "r9d", 118 | "r9w", 119 | "rax", 120 | "rbp", 121 | "rbx", 122 | "rcx", 123 | "rdi", 124 | "rdx", 125 | "rsi", 126 | "rsp", 127 | "segr6", 128 | "segr7", 129 | "si", 130 | "sil", 131 | "sp", 132 | "spl", 133 | "ss", 134 | "st0", 135 | "st1", 136 | "st2", 137 | "st3", 138 | "st4", 139 | "st5", 140 | "st6", 141 | "st7", 142 | "tmm0", 143 | "tmm1", 144 | "tmm2", 145 | "tmm3", 146 | "tmm4", 147 | "tmm5", 148 | "tmm6", 149 | "tmm7", 150 | "tr0", 151 | "tr1", 152 | "tr2", 153 | "tr3", 154 | "tr4", 155 | "tr5", 156 | "tr6", 157 | "tr7", 158 | "xmm0", 159 | "xmm1", 160 | "xmm10", 161 | "xmm11", 162 | "xmm12", 163 | "xmm13", 164 | "xmm14", 165 | "xmm15", 166 | "xmm16", 167 | "xmm17", 168 | "xmm18", 169 | "xmm19", 170 | "xmm2", 171 | "xmm20", 172 | "xmm21", 173 | "xmm22", 174 | "xmm23", 175 | "xmm24", 176 | "xmm25", 177 | "xmm26", 178 | "xmm27", 179 | "xmm28", 180 | "xmm29", 181 | "xmm3", 182 | "xmm30", 183 | "xmm31", 184 | "xmm4", 185 | "xmm5", 186 | "xmm6", 187 | "xmm7", 188 | "xmm8", 189 | "xmm9", 190 | "ymm0", 191 | "ymm1", 192 | "ymm10", 193 | "ymm11", 194 | "ymm12", 195 | "ymm13", 196 | "ymm14", 197 | "ymm15", 198 | "ymm16", 199 | "ymm17", 200 | "ymm18", 201 | "ymm19", 202 | "ymm2", 203 | "ymm20", 204 | "ymm21", 205 | "ymm22", 206 | "ymm23", 207 | "ymm24", 208 | "ymm25", 209 | "ymm26", 210 | "ymm27", 211 | "ymm28", 212 | "ymm29", 213 | "ymm3", 214 | "ymm30", 215 | "ymm31", 216 | "ymm4", 217 | "ymm5", 218 | "ymm6", 219 | "ymm7", 220 | "ymm8", 221 | "ymm9", 222 | "zmm0", 223 | "zmm1", 224 | "zmm10", 225 | "zmm11", 226 | "zmm12", 227 | "zmm13", 228 | "zmm14", 229 | "zmm15", 230 | "zmm16", 231 | "zmm17", 232 | "zmm18", 233 | "zmm19", 234 | "zmm2", 235 | "zmm20", 236 | "zmm21", 237 | "zmm22", 238 | "zmm23", 239 | "zmm24", 240 | "zmm25", 241 | "zmm26", 242 | "zmm27", 243 | "zmm28", 244 | "zmm29", 245 | "zmm3", 246 | "zmm30", 247 | "zmm31", 248 | "zmm4", 249 | "zmm5", 250 | "zmm6", 251 | "zmm7", 252 | "zmm8", 253 | "zmm9" 254 | }; 255 | --------------------------------------------------------------------------------