From 335b6536eb415452a0086131bec396380d7c99f7 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 30 Apr 2002 20:58:55 +0000 Subject: [PATCH] NASM 0.98bf --- License | 119 ++++++++++++++++++++++++++++++++++++++ MODIFIED | 7 +++ README | 140 ++++++++++++++++++++++++++++++++++++++++++++ assemble.c | 2 +- doc/nasmdoc.src | 6 +- float.c | 3 +- insns.dat | 4 +- lcc/Readme | 13 +++-- listing.c | 3 +- misc/c16.mac | 49 +++++++++++++++- misc/c32.mac | 28 ++++++++- misc/exebin.mac | 57 ++++++++++++++++++ nasm.c | 16 +++--- nasm.h | 6 +- nasmlib.c | 2 +- nasmlib.h | 12 ++-- ndisasm.c | 11 +++- outaout.c | 4 +- outas86.c | 2 +- outcoff.c | 3 +- outelf.c | 27 ++++----- outobj.c | 27 ++++----- outrdf2.c | 2 +- preproc.c | 8 +-- rdoff/Makefile.sc | 169 ++++++++++++++++++++++++++++++++++++------------------ zoutieee.c | 16 ++++-- 26 files changed, 600 insertions(+), 136 deletions(-) create mode 100644 License create mode 100644 README diff --git a/License b/License new file mode 100644 index 00000000..c85c212e --- /dev/null +++ b/License @@ -0,0 +1,119 @@ + +Terms and Conditions for the use of the Netwide Assembler +========================================================= + +Can I have the gist without reading the legalese? +------------------------------------------------- + +Basically, NASM is free. You can't charge for it. You can copy it as +much as you like. You can incorporate it, or bits of it, into other +free programs if you want. (But we want to know about it if you do, +and we want to be mentioned in the credits.) We may well allow you +to incorporate it into commercial software too, but we'll probably +demand some money for it, and we'll certainly demand to be given +credit. And in extreme cases (although I can't immediately think of +a reason we might actually want to do this) we may refuse to let you +do it at all. + +NASM LICENCE AGREEMENT +====================== + +By "the Software" this licence refers to the complete contents of +the NASM archive, excluding this licence document itself, and +excluding the contents of the `test' directory. The Netwide +Disassembler, NDISASM, is specifically included under this licence. + +I. The Software is freely redistributable; anyone may copy the +Software, or parts of the Software, and give away as many copies as +they like to anyone, as long as this licence document is kept with +the Software. Charging a fee for the Software is prohibited, +although a fee may be charged for the act of transferring a copy, +and you can offer warranty protection and charge a fee for that. + +II. The Software, or parts thereof, may be incorporated into other +freely redistributable software (by which we mean software that may +be obtained free of charge) without requiring permission from the +authors, as long as due credit is given to the authors of the +Software in the resulting work, as long as the authors are informed +of this action if possible, and as long as those parts of the +Software that are used remain under this licence. + +III. Modified forms of the Software may be created and distributed +as long as the authors are informed of this action if possible, as +long as the resulting work remains under this licence, as long as +the modified form of the Software is distributed with documentation +which still gives credit to the original authors of the Software, +and as long as the modified form of the Software is distributed with +a clear statement that it is not the original form of the Software +in the form that it was distributed by the authors. + +IV. The Software, or parts thereof, may be incorporated into other +software which is not freely redistributable (i.e. software for +which a fee is charged), as long as permission is granted from the +authors of the Software. The authors reserve the right to grant this +permission only for a fee, which may at our option take the form of +royalty payments. The authors also reserve the right to refuse to +grant permission if they deem it necessary. For further information +about who exactly the authors are, see clause XI below. + +V. The Software may be incorporated, in its original archive form, +into software collections or archives which are not freely +redistributable, as long as it is clearly stated that the Software +itself remains freely redistributable and remains under this licence +and no other. Such collections are deemed not to fall under article +IV of this licence. + +VI. Object files or programs generated by the Software as output do +not fall under this licence at all, and may be placed under any +licence the author wishes. The authors explicitly lay no claim to, +and assert no rights over, any programs written by other people and +assembled into object form by the Software. + +VII. You may not copy, modify or distribute the Software except +under the terms given in this licence document. You may not +sublicense the Software or in any way place it under any other +licence than this one. Since you have not signed this licence, you +are not of course required to accept it; however, no other licence +applies to the Software, and nothing else grants you any permission +to copy, modify, sublicense or distribute the Software in any way. +These actions are therefore prohibited if you do not accept this +licence. + +VIII. There is no warranty for the Software, to the extent permitted +by applicable law. The authors provide the Software "as is" without +warranty of any kind, either expressed or implied, including but not +limited to the implied warranties of merchantability and fitness for +a particular purpose. The entire risk as to the quality and +performance of the Software is with you. Should the Software prove +defective, you assume the cost of all necessary servicing, repair or +correction. + +IX. In no event, unless required by applicable law or agreed to in +writing, will any of the authors be liable to you for damages, +including any general, special, incidental or consequential damages, +arising out of the use or the inability to use the Software, +including but not limited to loss of data or data being rendered +inaccurate or a failure of the Software to operate with any other +programs, even if you have been advised of the possibility of such +damages. + +X. In addition to what this Licence otherwise provides, the Software +may be distributed in such a way as to be compliant with the GNU +General Public Licence, as published by the Free Software Foundation, +Cambridge, MA, USA; version 2, or, at your option, any later version; +incorporated herein by reference. You must include a copy of this +Licence with such distribution. Furthermore, patches sent to the +authors for the purpose of inclusion in the official release version +are considered cleared for release under the full terms of this +Licence. + +XI. The authors of NASM are the original authors (Simon Tatham and +Julian Hall) and all those who the original authors feel have +contributed significantly to the overall project. If you wish to +contact the authors, Julian Hall (jules@earthcorp.com) should be your +first port of call. + +XII. Should any part of this agreement be deemed unenforcable, it is +intended that the remainder of the agreement be held in force. + +END OF LICENCE AGREEMENT diff --git a/MODIFIED b/MODIFIED index 58987e85..2571979d 100644 --- a/MODIFIED +++ b/MODIFIED @@ -1,3 +1,10 @@ +- 3/25/01 - fixed "%include bug" + - "elfso bug" (aout, too) + - "jecxz bug" (& docs) + - version "0.98bf" + - Frank Kotler . + (grep "/*bf*/" to find 'em) + This file details changes since NASM 0.98p3. All the releases in this file have been produced by H. Peter Anvin . diff --git a/README b/README new file mode 100644 index 00000000..cad5d9fe --- /dev/null +++ b/README @@ -0,0 +1,140 @@ +This is a distribution of NASM, the Netwide Assembler. NASM is a +prototype general-purpose x86 assembler. It will currently output +flat-form binary files, a.out, COFF and ELF Unix object files, +Microsoft Win32 and 16-bit DOS object files, OS/2 object files, the +as86 object format, and a home-grown format called RDF. + +Also included is NDISASM, a prototype x86 binary-file disassembler +which uses the same instruction table as NASM. + +To install NASM on Linux, type `make', and then when it has finished +copy the file `nasm' (and maybe `ndisasm') to a directory on your +search path (maybe /usr/local/bin, or ~/bin if you don't have root +access). You may also want to copy the man page `nasm.1' (and maybe +`ndisasm.1') to somewhere sensible. + +To install under DOS, if you don't need to rebuild from the sources, +you can just copy nasm.exe and ndisasm.exe (16-bit DOS executables), +or nasmw.exe and ndisasmw.exe (Win32 console applications - less +likely to run out of memory), to somewhere on your PATH. + +To rebuild the DOS sources, various makefiles are provided: + +- Makefile.dos, the one I build the standard 16-bit releases from, + designed for a hybrid system using Microsoft C and Borland Make + (don't ask why :-) +- Makefile.vc, for Microsoft Visual C++ compiling to a Win32 + command-line application. This is the one I build the standard + Win32 release binaries from. + +- Makefile.bor, for Borland C. +- Makefile.bc2, also for Borland C, contributed by Fox Cutter. + Reported to work better than Makefile.bor on some systems. + +- Makefile.sc, for Symantec C++, compiling to a 32-bit extended DOS + executable.. Contributed by Mark Junker. +- Makefile.scw, also for Symantec C++, compiling to a Win32 command- + line application. Also contributed by Mark Junker. + +- Makefile.wc, for Watcom C, compiling to a 32-bit extended DOS + executable. Contributed by Dominik Behr. +- Makefile.wcw, also for Watcom C, compiling to a Win32 command- + line application. Also contributed by Dominik Behr. + +- Makefile.dj, for DJGPP, compiling to a 32-bit extended DOS + executable. Contributed by Dominik Behr. + +- Makefile.lcc, for lcc-win32, compiling to a Win32 command line + application. (The lcc-win32 compiler and tools are available from + http://www.remcomp.com/lcc-win32/) + +I can't guarantee that all of those makefiles work, because I don't +have all of those compilers. However, Makefile.dos and Makefile.vc +work on my system, and so do Makefile.bor and Makefile.bc2. + +Be careful with Borland C: there have been various conflicting +reports about how reliable the Huge memory model is. If you try to +compile NASM in Large model, you may get DGROUP overflows due to the +vast quantity of data in the instruction tables. I've had reports +from some people that Huge model doesn't work at all (and also +reports from others that it works fine), so if you don't want to try +moving to Huge, you could try adding the option `-dc' to the +compiler command line instead, which causes string literals to be +moved from DGROUP to the code segments and might make Large model +start working. (Either solution works for me.) + +Dominik Behr has also contributed the file misc/pmw.bat, which is a +batch file to turn the output from Makefile.wc (NASM.EXE and +NDISASM.EXE) into standalone executables incorporating Tran's +PMODE/W DOS extender, rather than depending on an external extender +program. + +Some of the Windows makefiles produce executables called nasmw.exe +and ndisasmw.exe, and some don't. Be prepared for either... + +If you're trying to unpack the DOS (.ZIP format) archive under Unix +instead of using the .tar.gz version, you can save some time by +doing `unzip -aL', which will convert the DOS-format text files to +Unix and also convert all names to lower case. + +If you want to build a restricted version of NASM containing only +some of the object file formats, you can achieve this by adding +#defines to `outform.h' (see the file itself for documentation), or +equivalently by adding compiler command line options in the +Makefile. + +There is a machine description file for the `LCC' retargetable C +compiler (version 3.6), in the directory `lcc', along with +instructions for its use. This means that NASM can now be used as +the code-generator back end for a useful C compiler. + +Michael `Wuschel' Tippach has ported his DOS extender `WDOSX' to +enable it to work with the 32-bit binary files NASM can output: the +original extender and his port `WDOSX/N' are available from his web +page, http://www.geocities.com/SiliconValley/Park/4493. + +Matt Mastracci has written a document explaining how to write +assembly language modules in DJGPP programs using NASM: it's on his +web site at http://www.ucalgary.ca/~mmastrac/djgppasm.doc. + +The `misc' directory contains `nasm.sl', a NASM editing mode for the +JED programmers' editor (see http://space.mit.edu/~davis/jed.html +for details about JED). The comment at the start of the file gives +instructions on how to install the mode. This directory also +contains a file (`magic') containing lines to add to /etc/magic on +Unix systems to allow the `file' command to recognise RDF files, and +a zip file (`exasm.zip') containing the necessary files for syntax +highlighting in the Aurora DOS editor. (The Aurora files were +contributed by ; I haven't tested them as I +don't have Aurora.) + +The `rdoff' directory contains sources for a linker and loader for +the RDF object file format, to run under Linux, and also +documentation on the internal structure of RDF files. + +For information about how you can distribute and use NASM, see the +file Licence. We were tempted to put NASM under the GPL, but decided +that in many ways it was too restrictive for developers. + +For information about how to use NASM, see the various forms of +documentation in the `doc' directory: documentation is provided in +HTML, PostScript, plain text, Texinfo, and Windows Help formats. For +information about how to use NDISASM, see `ndisasm.doc'. For +information about the internal structure of NASM, see +`internal.doc'. (In particular, _please_ read `internal.doc' before +writing any code for us...) + +The NASM web page is at http://www.web-sites.co.uk/Nasm/ + +Bug reports (and patches if you can) should be sent to + or . + +-------------------------------------------- +This release prepared by the Nasm Development Team at: + + + +Please visit us - our chat forum works :) +---------------------------------------------- + + diff --git a/assemble.c b/assemble.c index fef2ab77..9d4d037b 100644 --- a/assemble.c +++ b/assemble.c @@ -267,7 +267,7 @@ long assemble (long segment, long offset, int bits, fseek (fp, base, SEEK_SET); l = len; while (l > 0) { - long m = fread (buf, 1, (l>sizeof(buf)?sizeof(buf):l), + long m = fread (buf, 1, (l>(int)sizeof(buf)?sizeof(buf):l), fp); if (!m) { /* diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index 29657073..b08e9836 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -7007,8 +7007,8 @@ on the default \c{BITS} setting at the time. \H{insJCXZ} \i\c{JCXZ}, \i\c{JECXZ}: Jump if CX/ECX Zero -\c JCXZ imm ; o16 E3 rb [8086] -\c JECXZ imm ; o32 E3 rb [386] +\c JCXZ imm ; a16 E3 rb [8086] +\c JECXZ imm ; a32 E3 rb [386] \c{JCXZ} performs a short jump (with maximum range 128 bytes) if and only if the contents of the \c{CX} register is 0. \c{JECXZ} does the @@ -7460,7 +7460,7 @@ operation on the 64-bit MMX registers. \c OUT DX,AX ; o16 EF [8086] \c OUT DX,EAX ; o32 EF [386] -\c{IN} writes the contents of the given source register to the +\c{OUT} writes the contents of the given source register to the specified I/O port. The port number may be specified as an immediate value if it is between 0 and 255, and otherwise must be stored in \c{DX}. See also \c{IN} (\k{insIN}). diff --git a/float.c b/float.c index 545ae773..a269bcf1 100644 --- a/float.c +++ b/float.c @@ -210,7 +210,8 @@ static int round(unsigned short *mant, int i) return 0; } -#define put(a,b) ( (*(a)=(b)), ((a)[1]=(b)>>8) ) +#define put(a,b) ( ((a)[0]=(unsigned char)((b) & 0xFF)), \ + ((a)[1]=(unsigned char)(((b) >> 8) & 0xFF)) ) static int to_double(char *str, long sign, unsigned char *result, efunc error) diff --git a/insns.dat b/insns.dat index 2df98934..977c37c1 100644 --- a/insns.dat +++ b/insns.dat @@ -455,8 +455,8 @@ INVLPG mem \300\2\x0F\x01\207 486,PRIV IRET void \322\1\xCF 8086 IRETD void \321\1\xCF 386 IRETW void \320\1\xCF 8086 -JCXZ imm \320\1\xE3\50 8086 -JECXZ imm \321\1\xE3\50 386 +JCXZ imm \310\1\xE3\50 8086 +JECXZ imm \311\1\xE3\50 386 JMP imm|short \1\xEB\50 8086 JMP imm \322\1\xE9\64 8086 JMP imm|near \322\1\xE9\64 8086,ND diff --git a/lcc/Readme b/lcc/Readme index 569b9be7..6e7c56c7 100644 --- a/lcc/Readme +++ b/lcc/Readme @@ -1,9 +1,10 @@ This directory contains the necessary files to port the C compiler ``LCC'' (available by FTP from sunsite.doc.ic.ac.uk in the directory -/computing/programming/languages/c/lcc) to compile for Linux (a.out -or ELF) by using NASM as a back-end code generator. +/computing/programming/languages/c/lcc) to compile for Linux (a.out or +ELF) or other supported operating systems by using NASM as a back-end +code generator. -This patch has been tested on lcc version 3.6. +This patch has been tested on lcc version 4.0. To install: @@ -11,9 +12,9 @@ To install: - Copy either `lin-elf.c' or `lin-aout.c' into the `etc' directory. -- If you're installing for a.out, edit `x86nasm.md' and change the - conditional after the comment reading "CHANGE THIS FOR a.out" in - the `defsymbol' function from `#if 0' to `#if 1'. +- With previous versions, you had to modify x86-nasm.md if you weren't + using ELF. There is now inbuilt support within NASM in the shape + of the __CDECL__ macro, so this modification is no longer necessary. - Make the following changes to `bind.c' in the `src' directory: diff --git a/listing.c b/listing.c index af8a9bf8..c37c15a7 100644 --- a/listing.c +++ b/listing.c @@ -122,7 +122,8 @@ static void list_out (long offset, char *str) static void list_output (long offset, void *data, unsigned long type) { - long typ, size; + unsigned long typ; + long size; if (!listp || suppress) return; diff --git a/misc/c16.mac b/misc/c16.mac index 86e6bf92..50b5d5ee 100644 --- a/misc/c16.mac +++ b/misc/c16.mac @@ -1,37 +1,82 @@ ; NASM macro set to make interfacing to 16-bit programs easier -*- nasm -*- + + %imacro proc 1 ; begin a procedure definition + %push proc + global %1 + %1: push bp + mov bp,sp + %ifdef FARCODE PASCAL ; arguments may start at bp+4 or bp+6 + %assign %$arg 6 + +%define %$firstarg 6 + %else + %assign %$arg 4 + +%define %$firstarg 4 + %endif + %define %$procname %1 + %endmacro + + %imacro arg 0-1 2 ; used with the argument name as a label - equ %$arg + +%00 equ %$arg + + ; we could possibly be adding some + + ; debug information at this point...? + %assign %$arg %1+%$arg + %endmacro + + %imacro endproc 0 + %ifnctx proc + %error Mismatched `endproc'/`proc' + %else + mov sp,bp + pop bp + %ifdef PASCAL - retf %$arg + + retf %$arg - %$firstarg + %elifdef FARCODE + retf + %else + retn + %endif + __end_%$procname: ; useful for calculating function size + %pop + %endif + %endmacro + diff --git a/misc/c32.mac b/misc/c32.mac index a59acfde..f0c116ba 100644 --- a/misc/c32.mac +++ b/misc/c32.mac @@ -1,26 +1,52 @@ ; NASM macro set to make interfacing to 32-bit programs easier -*- nasm -*- + + %imacro proc 1 ; begin a procedure definition + %push proc + global %1 + %1: push ebp + mov ebp,esp + %assign %$arg 8 + %define %$procname %1 + %endmacro + + %imacro arg 0-1 4 ; used with the argument name as a label - equ %$arg + +%00 equ %$arg + %assign %$arg %1+%$arg + %endmacro + + %imacro endproc 0 + %ifnctx proc + %error Mismatched `endproc'/`proc' + %else + leave + ret + __end_%$procname: ; useful for calculating function size + %pop + %endif + %endmacro + diff --git a/misc/exebin.mac b/misc/exebin.mac index 8d1eaf8c..89c68898 100644 --- a/misc/exebin.mac +++ b/misc/exebin.mac @@ -1,57 +1,114 @@ ; -*- nasm -*- + ; NASM macro file to allow the `bin' output format to generate + ; simple .EXE files by constructing the EXE header by hand. + ; Adapted from a contribution by Yann Guidon + + %define EXE_stack_size EXE_realstacksize + + %macro EXE_begin 0 + ORG 0E0h + section .text + + header_start: + db 4Dh,5Ah ; EXE file signature + dw EXE_allocsize % 512 + dw (EXE_allocsize + 511) / 512 + dw 0 ; relocation information: none + dw (header_end-header_start)/16 ; header size in paragraphs + dw (EXE_absssize + EXE_realstacksize) / 16 ; min extra mem + dw (EXE_absssize + EXE_realstacksize) / 16 ; max extra mem + dw -10h ; Initial SS (before fixup) + dw EXE_endbss + EXE_realstacksize ; Initial SP (1K DPMI+1K STACK) + dw 0 ; (no) Checksum + dw 100h ; Initial IP - start just after the header + dw -10h ; Initial CS (before fixup) + dw 0 ; file offset to relocation table: none + dw 0 ; (no overlay) + align 16,db 0 + header_end: + + EXE_startcode: + section .data + EXE_startdata: + section .bss + EXE_startbss: + %endmacro + + %macro EXE_stack 1 + EXE_realstacksize equ %1 + %define EXE_stack_size EXE_bogusstacksize ; defeat EQU in EXE_end + %endmacro + + %macro EXE_end 0 + section .text + EXE_endcode: + section .data + EXE_enddata: + section .bss + alignb 4 + EXE_endbss: + + EXE_acodesize equ (EXE_endcode-EXE_startcode+3) & (~3) + EXE_datasize equ EXE_enddata-EXE_startdata + EXE_absssize equ (EXE_endbss-EXE_startbss+3) & (~3) + EXE_allocsize equ EXE_acodesize + EXE_datasize + + EXE_stack_size equ 0x800 ; default if nothing else was used + %endmacro + diff --git a/nasm.c b/nasm.c index 3c5327a4..84316464 100644 --- a/nasm.c +++ b/nasm.c @@ -169,7 +169,7 @@ int main(int argc, char **argv) ofmt->filename (inname, outname, report_error); ofile = NULL; printf("%s: %s", outname, inname); - while ( (line = preproc->getline()) ) + while ( (line = preproc->getline()) != NULL ) nasm_free (line); preproc->cleanup(); putc('\n', stdout); @@ -194,7 +194,7 @@ int main(int argc, char **argv) location.known = FALSE; preproc->reset (inname, 2, report_error, evaluate, &nasmlist); - while ( (line = preproc->getline()) ) { + while ( (line = preproc->getline()) != NULL ) { /* * We generate %line directives if needed for later programs */ @@ -334,6 +334,7 @@ static int process_arg (char *p, char *q) case 'p': case 'd': case 'D': + case 'U': case 'i': case 'l': case 'E': @@ -531,7 +532,7 @@ static void process_respfile (FILE *rfile) if (process_arg (prevarg, p)) *p = '\0'; - if (strlen(p) > prevargsize-10) { + if ((int)strlen(p) > prevargsize-10) { prevargsize += ARG_BUF_DELTA; prevarg = nasm_realloc(prevarg, prevargsize); } @@ -542,7 +543,7 @@ static void process_respfile (FILE *rfile) static void parse_cmdline(int argc, char **argv) { FILE *rfile; - char *envreal, *envcopy=NULL, *p, *q, *arg, *prevarg; + char *envreal, *envcopy, *p, *q, *arg, *prevarg; char separator = ' '; *inname = *outname = *listname = '\0'; @@ -579,13 +580,14 @@ static void parse_cmdline(int argc, char **argv) int i; argv++; if (!stopoptions && argv[0][0] == '-' && argv[0][1] == '@') { - if ((p = get_param (argv[0], argc > 1 ? argv[1] : NULL, &i))) + if ((p = get_param (argv[0], argc > 1 ? argv[1] : NULL, &i))) { if ((rfile = fopen(p, "r"))) { process_respfile (rfile); fclose(rfile); } else report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, "unable to open response file `%s'", p); + } } else i = process_arg (argv[0], argc > 1 ? argv[1] : NULL); argv += i, argc -= i; @@ -616,7 +618,7 @@ static void assemble_file (char *fname) location.known = TRUE; location.offset = offs = get_curr_ofs; - while ( (line = preproc->getline()) ) + while ( (line = preproc->getline()) != NULL ) { globallineno++; @@ -934,7 +936,7 @@ static void assemble_file (char *fname) globallineno = 0; location.offset = offs = get_curr_ofs; - while ( (line = preproc->getline()) ) + while ( (line = preproc->getline()) != NULL ) { globallineno++; diff --git a/nasm.h b/nasm.h index 240d2d49..4196f5f9 100644 --- a/nasm.h +++ b/nasm.h @@ -12,8 +12,8 @@ #define NASM_NASM_H #define NASM_MAJOR_VER 0 -#define NASM_MINOR_VER 98 -#define NASM_VER "0.98" +#define NASM_MINOR_VER 98bf +#define NASM_VER "0.98bf" #ifndef NULL #define NULL 0 @@ -837,6 +837,6 @@ struct dfmt { * the number of elements of a statically defined array. */ -#define elements(x) ( sizeof(x) / sizeof(*(x)) ) +#define elements(x) ((int)(sizeof(x) / sizeof(*(x)))) #endif diff --git a/nasmlib.c b/nasmlib.c index 86ed6c47..27179eba 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -627,7 +627,7 @@ void saa_fpwrite (struct SAA *s, FILE *fp) long len; saa_rewind (s); - while ( (data = saa_rbytes (s, &len)) ) + while ( (data = saa_rbytes (s, &len)) != NULL ) fwrite (data, 1, len, fp); } diff --git a/nasmlib.h b/nasmlib.h index d2997b18..fe5be795 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -92,16 +92,16 @@ void standard_extension (char *inname, char *outname, char *extension, #define WRITELONG(p,v) \ do { \ - *(p)++ = (v) & 0xFF; \ - *(p)++ = ((v) >> 8) & 0xFF; \ - *(p)++ = ((v) >> 16) & 0xFF; \ - *(p)++ = ((v) >> 24) & 0xFF; \ + *(p)++ = (unsigned char)((v) & 0xFF); \ + *(p)++ = (unsigned char)(((v) >> 8) & 0xFF); \ + *(p)++ = (unsigned char)(((v) >> 16) & 0xFF); \ + *(p)++ = (unsigned char)(((v) >> 24) & 0xFF); \ } while (0) #define WRITESHORT(p,v) \ do { \ - *(p)++ = (v) & 0xFF; \ - *(p)++ = ((v) >> 8) & 0xFF; \ + *(p)++ = (unsigned char)((v) & 0xFF); \ + *(p)++ = (unsigned char)(((v) >> 8) & 0xFF); \ } while (0) /* diff --git a/ndisasm.c b/ndisasm.c index 354ea3c4..53de839c 100644 --- a/ndisasm.c +++ b/ndisasm.c @@ -42,7 +42,8 @@ int main(int argc, char **argv) char *pname = *argv; char *filename = NULL; unsigned long nextsync, synclen, initskip = 0L; - int lenread, lendis; + int lenread; + long lendis; int autosync = FALSE; int bits = 16; int eof = FALSE; @@ -181,6 +182,10 @@ int main(int argc, char **argv) } p = ""; /* force to next argument */ break; + default: /*bf*/ + fprintf(stderr, "%s: unrecognised option `-%c'\n", + pname, *p); + return 1; } } else if (!filename) { filename = p; @@ -227,7 +232,7 @@ int main(int argc, char **argv) } else lenread = 0; p += lenread; - if (offset == nextsync) { + if ((unsigned long)offset == nextsync) { if (synclen) { printf("%08lX skipping 0x%lX bytes\n", offset, synclen); offset += synclen; @@ -239,7 +244,7 @@ int main(int argc, char **argv) while (p > q && (p - q >= INSN_MAX || lenread == 0)) { lendis = disasm (q, outbuf, bits, offset, autosync, prefer); if (!lendis || lendis > (p - q) || - lendis > nextsync-offset) + (unsigned long)lendis > nextsync-offset) lendis = eatbyte (q, outbuf); output_ins (offset, q, lendis, outbuf); q += lendis; diff --git a/outaout.c b/outaout.c index b82109a9..5cd9d5ce 100644 --- a/outaout.c +++ b/outaout.c @@ -341,6 +341,7 @@ static void aout_deflabel (char *name, long segment, long offset, struct tokenval tokval; expr *e; int fwd = FALSE; + char *saveme=stdscan_bufptr; /*bf*/ if (!bsd) { error(ERR_NONFATAL, "Linux a.out does not support" @@ -369,6 +370,7 @@ static void aout_deflabel (char *name, long segment, long offset, sym->size = reloc_value(e); } } + stdscan_bufptr=saveme; /*bf*/ } special_used = TRUE; } @@ -823,7 +825,7 @@ static void aout_write_relocs (struct Reloc *r) static void aout_write_syms (void) { - int i; + unsigned long i; saa_rewind (syms); for (i=0; istrpos == -1 ? sym->name : NULL, sym->strpos, sym->value, sym->section, diff --git a/outelf.c b/outelf.c index 0b77c017..9391d36e 100644 --- a/outelf.c +++ b/outelf.c @@ -447,21 +447,16 @@ static void elf_deflabel (char *name, long segment, long offset, if (sym->type == SYM_GLOBAL) { /* - * There's a problem here that needs fixing. - * If sym->section == SHN_ABS, then the first line of the - * else section causes a core dump, because its a reference + * If sym->section == SHN_ABS, then the first line of the else + * section would cause a core dump, because it's a reference * beyond the end of the section array. - * This behaviour is exhibited by this code: - * GLOBAL crash_nasm - * crash_nasm equ 0 + * This case happens with code such as this: + * GLOBAL foo + * foo equ 0 * - * I'm not sure how to procede, because I haven't got the - * first clue about how ELF works, so I don't know what to - * do with it. Furthermore, I'm not sure what the rest of this - * section of code does. Help? - * - * For now, I'll see if doing absolutely nothing with it will - * work... + * We avoid the crash by skipping over the else section. It's + * a bit unclear whether or not this is the right thing to do, + * but it appears to work correctly. */ if (sym->section == SHN_UNDEF || sym->section == SHN_COMMON) { @@ -496,6 +491,7 @@ static void elf_deflabel (char *name, long segment, long offset, struct tokenval tokval; expr *e; int fwd = FALSE; + char *saveme=stdscan_bufptr; /*bf*/ while (special[n] && isspace(special[n])) n++; @@ -518,6 +514,7 @@ static void elf_deflabel (char *name, long segment, long offset, else sym->size = reloc_value(e); } + stdscan_bufptr=saveme; /*bf*/ } special_used = TRUE; } @@ -938,7 +935,7 @@ static struct SAA *elf_build_symtab (long *len, long *local) * Now the other local symbols. */ saa_rewind (syms); - while ( (sym = saa_rstruct (syms)) ) { + while ( (sym = saa_rstruct (syms)) != NULL ) { if (sym->type & SYM_GLOBAL) continue; p = entry; @@ -956,7 +953,7 @@ static struct SAA *elf_build_symtab (long *len, long *local) * Now the global symbols. */ saa_rewind (syms); - while ( (sym = saa_rstruct (syms)) ) { + while ( (sym = saa_rstruct (syms)) != NULL ) { if (!(sym->type & SYM_GLOBAL)) continue; p = entry; diff --git a/outobj.c b/outobj.c index 0a7544d6..bf433772 100644 --- a/outobj.c +++ b/outobj.c @@ -282,8 +282,8 @@ static ObjRecord *obj_byte(ObjRecord *orp, unsigned char val) static ObjRecord *obj_word(ObjRecord *orp, unsigned int val) { orp = obj_check(orp, 2); - orp->buf[orp->used] = val; - orp->buf[orp->used+1] = val >> 8; + orp->buf[orp->used] = (unsigned char)(val & 0xFF); + orp->buf[orp->used+1] = (unsigned char)((val >> 8) & 0xFF); orp->used += 2; return (orp); } @@ -294,8 +294,8 @@ static ObjRecord *obj_word(ObjRecord *orp, unsigned int val) static ObjRecord *obj_rword(ObjRecord *orp, unsigned int val) { orp = obj_check(orp, 2); - orp->buf[orp->used] = val >> 8; - orp->buf[orp->used+1] = val; + orp->buf[orp->used] = (unsigned char)((val >> 8) & 0xFF); + orp->buf[orp->used+1] = (unsigned char)(val & 0xFF); orp->used += 2; return (orp); } @@ -306,10 +306,10 @@ static ObjRecord *obj_rword(ObjRecord *orp, unsigned int val) static ObjRecord *obj_dword(ObjRecord *orp, unsigned long val) { orp = obj_check(orp, 4); - orp->buf[orp->used] = val; - orp->buf[orp->used+1] = val >> 8; - orp->buf[orp->used+2] = val >> 16; - orp->buf[orp->used+3] = val >> 24; + orp->buf[orp->used] = (unsigned char)(val & 0xFF); + orp->buf[orp->used+1] = (unsigned char)((val >> 8) & 0xFF); + orp->buf[orp->used+2] = (unsigned char)((val >> 16) & 0xFF); + orp->buf[orp->used+3] = (unsigned char)((val >> 24) & 0xFF); orp->used += 4; return (orp); } @@ -364,7 +364,7 @@ static ObjRecord *obj_index(ObjRecord *orp, unsigned int val) static ObjRecord *obj_value(ObjRecord *orp, unsigned long val) { if (val <= 128) - return ( obj_byte(orp, val) ); + return ( obj_byte(orp, (unsigned char)val) ); if (val <= 0xFFFF) { orp = obj_byte(orp, 129); return ( obj_word(orp, val) ); @@ -952,7 +952,8 @@ static void obj_deflabel (char *name, long segment, static void obj_out (long segto, void *data, unsigned long type, long segment, long wrt) { - long size, realtype; + long size; + unsigned long realtype; unsigned char *ucdata; long ldata; struct Segment *seg; @@ -998,7 +999,7 @@ static void obj_out (long segto, void *data, unsigned long type, unsigned int len; orp = obj_check(seg->orp, 1); len = RECORD_MAX - orp->used; - if (len > size) + if ((long)len > size) len = size; memcpy (orp->buf+orp->used, ucdata, len); orp->committed = orp->used += len; @@ -1931,7 +1932,7 @@ static void obj_write_file (int debuginfo) orp->parm[0] = 0; orp->parm[1] = 0; for (pub = fpubhead; pub; pub = pub->next) { /* pub-crawl :-) */ - if (orp->parm[2] != pub->segment) { + if ((long)orp->parm[2] != pub->segment) { obj_emit (orp); orp->parm[2] = pub->segment; } @@ -2316,7 +2317,7 @@ static void dbgbi_linnum (const char *lnfname, long lineno, long segto) if (!seg) error (ERR_PANIC, "lineno directed to nonexistent segment?"); - for (fn = fnhead; fn; fn = fnhead->next) + for (fn = fnhead; fn; fn = fn->next) /*bf*/ if (!nasm_stricmp(lnfname,fn->name)) break; if (!fn) { diff --git a/outrdf2.c b/outrdf2.c index 4ae6799b..6bbb989b 100644 --- a/outrdf2.c +++ b/outrdf2.c @@ -200,7 +200,7 @@ static long rdf2_section_names(char *name, int pass, int *bits) /* * see if we have an optional ',number' following the type code */ - if ((q = strchr(p, ','))) { + if ((q = strchr(p, ',')) != NULL) { *q++ = '\0'; reserved = readnum(q, &i); diff --git a/preproc.c b/preproc.c index 5286dd0c..dfac9eb4 100644 --- a/preproc.c +++ b/preproc.c @@ -403,7 +403,7 @@ static int hash(char *s) while (*s) { h += multipliers[i] * (unsigned char) (toupper(*s)); s++; - if (++i >= sizeof(multipliers)/sizeof(*multipliers)) + if (++i >= elements(multipliers)) i = 0; } h %= NHASH; @@ -579,7 +579,7 @@ static char *read_line (void) */ static Token *tokenise (char *line) { - char *p = line; + char *p; int type; Token *list = NULL; Token *t, **tail = &list; @@ -2745,7 +2745,7 @@ static int expand_mmacro (Token *tline) * If we had a label, push it on as the first line of * the macro expansion. */ - if (label) + if (label) { if (dont_prepend<0) free_tlist(startline); else { @@ -2764,7 +2764,7 @@ static int expand_mmacro (Token *tline) tt->text = nasm_strdup(":"); } } - + } list->uplevel (m->nolist ? LIST_MACRO_NOLIST : LIST_MACRO); return 1; diff --git a/rdoff/Makefile.sc b/rdoff/Makefile.sc index fca911ad..816cc98e 100644 --- a/rdoff/Makefile.sc +++ b/rdoff/Makefile.sc @@ -1,57 +1,112 @@ -# Makefile for RDOFF object file utils; part of the Netwide Assembler -# -# The Netwide Assembler is copyright (C) 1996 Simon Tatham and -# Julian Hall. All rights reserved. The software is -# redistributable under the licence given in the file "Licence" -# distributed in the NASM archive. -# -# This Makefile is designed for use under Unix (probably fairly -# portably). - -CC = sc -CCFLAGS = -I..\ -c -a1 -mn -Nc -w2 -w7 -o+time -5 -LINK = link -LINKFLAGS = /noi /exet:NT /su:console - -OBJ=obj -EXE=.exe - -NASMLIB = ..\nasmlib.$(OBJ) -NASMLIB_H = ..\nasmlib.h -LDRDFLIBS = rdoff.$(OBJ) $(NASMLIB) symtab.$(OBJ) collectn.$(OBJ) rdlib.$(OBJ) -RDXLIBS = rdoff.$(OBJ) rdfload.$(OBJ) symtab.$(OBJ) collectn.$(OBJ) - -.c.$(OBJ): - $(CC) $(CCFLAGS) $*.c - -all : rdfdump$(EXE) ldrdf$(EXE) rdx$(EXE) rdflib$(EXE) rdf2bin$(EXE) rdf2com$(EXE) - -rdfdump$(EXE) : rdfdump.$(OBJ) - $(LINK) $(LINKFLAGS) rdfdump.$(OBJ), rdfdump$(EXE); -ldrdf$(EXE) : ldrdf.$(OBJ) $(LDRDFLIBS) - $(LINK) $(LINKFLAGS) ldrdf.$(OBJ) $(LDRDFLIBS), ldrdf$(EXE); -rdx$(EXE) : rdx.$(OBJ) $(RDXLIBS) - $(LINK) $(LINKFLAGS) rdx.$(OBJ) $(RDXLIBS), rdx$(EXE); -rdflib$(EXE) : rdflib.$(OBJ) - $(LINK) $(LINKFLAGS) rdflib.$(OBJ), rdflib$(EXE); -rdf2bin$(EXE) : rdf2bin.$(OBJ) $(RDXLIBS) $(NASMLIB) - $(LINK) $(LINKFLAGS) rdf2bin.$(OBJ) $(RDXLIBS) $(NASMLIB), rdf2bin$(EXE); -rdf2com$(EXE) : rdf2bin$(EXE) - copy rdf2bin$(EXE) rdf2com$(EXE) - -rdf2bin.$(OBJ) : rdf2bin.c -rdfdump.$(OBJ) : rdfdump.c -rdoff.$(OBJ) : rdoff.c rdoff.h -ldrdf.$(OBJ) : ldrdf.c rdoff.h $(NASMLIB_H) symtab.h collectn.h rdlib.h -symtab.$(OBJ) : symtab.c symtab.h -collectn.$(OBJ) : collectn.c collectn.h -rdx.$(OBJ) : rdx.c rdoff.h rdfload.h symtab.h -rdfload.$(OBJ) : rdfload.c rdfload.h rdoff.h collectn.h symtab.h -rdlib.$(OBJ) : rdlib.c rdlib.h -rdflib.$(OBJ) : rdflib.c - -clean : - del *.$(OBJ) rdfdump$(EXE) ldrdf$(EXE) rdx$(EXE) rdflib$(EXE) rdf2bin$(EXE) - - - \ No newline at end of file +# Makefile for RDOFF object file utils; part of the Netwide Assembler + +# + +# The Netwide Assembler is copyright (C) 1996 Simon Tatham and + +# Julian Hall. All rights reserved. The software is + +# redistributable under the licence given in the file "Licence" + +# distributed in the NASM archive. + +# + +# This Makefile is designed for use under Unix (probably fairly + +# portably). + + + +CC = sc + +CCFLAGS = -I..\ -c -a1 -mn -Nc -w2 -w7 -o+time -5 + +LINK = link + +LINKFLAGS = /noi /exet:NT /su:console + + + +OBJ=obj + +EXE=.exe + + + +NASMLIB = ..\nasmlib.$(OBJ) + +NASMLIB_H = ..\nasmlib.h + +LDRDFLIBS = rdoff.$(OBJ) $(NASMLIB) symtab.$(OBJ) collectn.$(OBJ) rdlib.$(OBJ) + +RDXLIBS = rdoff.$(OBJ) rdfload.$(OBJ) symtab.$(OBJ) collectn.$(OBJ) + + + +.c.$(OBJ): + + $(CC) $(CCFLAGS) $*.c + + + +all : rdfdump$(EXE) ldrdf$(EXE) rdx$(EXE) rdflib$(EXE) rdf2bin$(EXE) rdf2com$(EXE) + + + +rdfdump$(EXE) : rdfdump.$(OBJ) + + $(LINK) $(LINKFLAGS) rdfdump.$(OBJ), rdfdump$(EXE); + +ldrdf$(EXE) : ldrdf.$(OBJ) $(LDRDFLIBS) + + $(LINK) $(LINKFLAGS) ldrdf.$(OBJ) $(LDRDFLIBS), ldrdf$(EXE); + +rdx$(EXE) : rdx.$(OBJ) $(RDXLIBS) + + $(LINK) $(LINKFLAGS) rdx.$(OBJ) $(RDXLIBS), rdx$(EXE); + +rdflib$(EXE) : rdflib.$(OBJ) + + $(LINK) $(LINKFLAGS) rdflib.$(OBJ), rdflib$(EXE); + +rdf2bin$(EXE) : rdf2bin.$(OBJ) $(RDXLIBS) $(NASMLIB) + + $(LINK) $(LINKFLAGS) rdf2bin.$(OBJ) $(RDXLIBS) $(NASMLIB), rdf2bin$(EXE); + +rdf2com$(EXE) : rdf2bin$(EXE) + + copy rdf2bin$(EXE) rdf2com$(EXE) + + + +rdf2bin.$(OBJ) : rdf2bin.c + +rdfdump.$(OBJ) : rdfdump.c + +rdoff.$(OBJ) : rdoff.c rdoff.h + +ldrdf.$(OBJ) : ldrdf.c rdoff.h $(NASMLIB_H) symtab.h collectn.h rdlib.h + +symtab.$(OBJ) : symtab.c symtab.h + +collectn.$(OBJ) : collectn.c collectn.h + +rdx.$(OBJ) : rdx.c rdoff.h rdfload.h symtab.h + +rdfload.$(OBJ) : rdfload.c rdfload.h rdoff.h collectn.h symtab.h + +rdlib.$(OBJ) : rdlib.c rdlib.h + +rdflib.$(OBJ) : rdflib.c + + + +clean : + + del *.$(OBJ) rdfdump$(EXE) ldrdf$(EXE) rdx$(EXE) rdflib$(EXE) rdf2bin$(EXE) + + + + + diff --git a/zoutieee.c b/zoutieee.c index 8475e95f..6532ea25 100644 --- a/zoutieee.c +++ b/zoutieee.c @@ -158,7 +158,7 @@ extern struct ofmt of_ieee; static void ieee_data_new(struct ieeeSection *); static void ieee_write_fixup (long, long, struct ieeeSection *, - int, long, long); + int, unsigned long, long); static void ieee_install_fixup(struct ieeeSection *, struct ieeeFixupp *); static long ieee_segment (char *, int, int *); static void ieee_write_file(int debuginfo); @@ -369,7 +369,8 @@ static void ieee_deflabel (char *name, long segment, */ static void ieee_out (long segto, void *data, unsigned long type, long segment, long wrt) { - long size, realtype; + long size; + unsigned long realtype; unsigned char *ucdata; long ldata; struct ieeeSection *seg; @@ -447,7 +448,7 @@ static void ieee_data_new(struct ieeeSection *segto) { * If anyone wants to optimize this is a good canditate! */ static void ieee_write_fixup (long segment, long wrt, struct ieeeSection * segto, - int size, long realtype, long offset) { + int size, unsigned long realtype, long offset) { struct ieeeSection *target; struct ieeeFixupp s; @@ -954,11 +955,12 @@ static void ieee_write_file (int debuginfo) { ieee_putascii("ASI%X,R%X,%lX,+.\r\n", i, pub->index,pub->offset); else ieee_putascii("ASI%X,%lX,%lX,+.\r\n", i, pub->segment*16,pub->offset); - if (debuginfo) + if (debuginfo) { if (pub->type >= 0x100) ieee_putascii("ATI%X,T%X.\r\n", i, pub->type - 0x100); else ieee_putascii("ATI%X,%X.\r\n", i, pub->type); + } i++; } } @@ -972,11 +974,12 @@ static void ieee_write_file (int debuginfo) { ieee_putascii("ASI%X,R%X,%lX,+.\r\n", i, pub->index,pub->offset); else ieee_putascii("ASI%X,%lX,%lX,+.\r\n", i, pub->segment*16,pub->offset); - if (debuginfo) + if (debuginfo) { if (pub->type >= 0x100) ieee_putascii("ATI%X,T%X.\r\n", i, pub->type - 0x100); else ieee_putascii("ATI%X,%X.\r\n", i, pub->type); + } i++; pub = pub->next; } @@ -1019,11 +1022,12 @@ static void ieee_write_file (int debuginfo) { ieee_putascii("ASN%X,R%X,%lX,+.\r\n", i, loc->index,loc->offset); else ieee_putascii("ASN%X,%lX,%lX,+.\r\n", i, loc->segment*16,loc->offset); - if (debuginfo) + if (debuginfo) { if (loc->type >= 0x100) ieee_putascii("ATN%X,T%X.\r\n", i, loc->type - 0x100); else ieee_putascii("ATN%X,%X.\r\n", i, loc->type); + } i++; } } -- 2.11.4.GIT