From 8545d631d6b89950530e8bdb756e1ddda9e77316 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Thu, 20 Mar 2025 18:54:12 +0100 Subject: [PATCH 01/15] emacstbl.pl: Add proper header and footer --- misc/emacstbl.pl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/misc/emacstbl.pl b/misc/emacstbl.pl index 341810d8..74476f86 100755 --- a/misc/emacstbl.pl +++ b/misc/emacstbl.pl @@ -187,13 +187,14 @@ sub write_output($) { my($vol,$dir,$file) = File::Spec->splitpath($outfile); - print $out ";;; ${file} --- lists of NASM assembler tokens\n"; - print $out ";;;\n"; - print $out ";;; This file contains list of tokens from the NASM x86\n"; - print $out ";;; assembler, automatically extracted from NASM ${version}.\n"; - print $out ";;;\n"; - print $out ";;; This file is intended to be (require)d from a `nasm-mode\'\n"; - print $out ";;; major mode definition.\n"; + print $out ";;; ${file} --- lists of NASM assembler tokens\n\n"; + print $out ";;; Commentary:\n\n"; + print $out ";; This file contains list of tokens from the NASM x86\n"; + print $out ";; assembler, automatically extracted from NASM ${version}.\n"; + print $out ";;\n"; + print $out ";; This file is intended to be (require)d from a `nasm-mode\'\n"; + print $out ";; major mode definition.\n\n"; + print $out ";;; Code:\n"; foreach my $type (sort keys(%tokens)) { print $out "\n(defconst nasm-${type}\n"; @@ -204,6 +205,9 @@ sub write_output($) { print $out " \"NASM ${version} ${type} tokens for `nasm-mode\'.\")\n"; } + print $out "\n(provide 'nasmtok)\n"; + print $out ";;; nasmtok.el ends here\n"; + close($out); } From 37d8ee576805ff8c3e1fdc21fb91a664e06db21c Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 12:47:39 -0700 Subject: [PATCH 02/15] nasmlib/rlimit.c: fix broken comment A comment that apparently was mangled during SPDX conversion. Signed-off-by: H. Peter Anvin (Intel) --- nasmlib/rlimit.c | 1 - 1 file changed, 1 deletion(-) diff --git a/nasmlib/rlimit.c b/nasmlib/rlimit.c index e3d578bd..9e926a14 100644 --- a/nasmlib/rlimit.c +++ b/nasmlib/rlimit.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* Copyright 2020 The NASM Authors - All Rights Reserved */ - /* ----------------------------------------------------------------------- * #include "compiler.h" #include "nasmlib.h" From 80cea0baa38662c9021241a1be9c29b9950f6359 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 12:39:59 -0700 Subject: [PATCH 03/15] mkdep.pl: don't get confused by messed up line endings Just strip any whitespace at the end of a line. Signed-off-by: H. Peter Anvin (Intel) --- tools/mkdep.pl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/mkdep.pl b/tools/mkdep.pl index 80815a12..13c024a3 100755 --- a/tools/mkdep.pl +++ b/tools/mkdep.pl @@ -19,7 +19,7 @@ use File::Temp; use Fcntl; my $barrier = - "#-- Everything below is generated by mkdep.pl - do not edit --#\n"; + '#-- Everything below is generated by mkdep.pl - do not edit --#'; # This converts from filenames to full pathnames for our dependencies # These are arrays of [full path, Makefile path] @@ -61,7 +61,7 @@ sub scandeps { } while ( defined($line = <$fh>) ) { - chomp $line; + $line =~ s/\s+$//; $line =~ s:/\*.*\*/::g; $line =~ s://.*$::; if ( $line =~ /^\s*\#\s*include\s+\"(.*)\"\s*$/ ) { @@ -159,13 +159,14 @@ sub insert_deps($) { my $is_external = 0; while ( defined($line = <$in>) ) { + $line =~ s/\s+$//; if ( $line =~ /^([^\s\#\$\:]+\.h):/ ) { # Note: we trust the first Makefile given best my $fpath = $1; my $fbase = basename($fpath); if (!defined($dep_path{$fbase})) { $dep_path{$fbase} = [$fpath, $fpath]; - print STDERR "Makefile: $fbase -> $fpath\n"; + print STDERR "Makefile: $fbase -> $fpath\n" if ( $debug ); } } elsif ( $line =~ /^\s*\#\s*@([a-z0-9-]+):\s*\"([^\"]*)\"/ ) { $parm = $1; $val = $2; @@ -190,12 +191,12 @@ sub insert_deps($) { } elsif ( $line =~ /^(\s*\#?\s*EXTERNAL_DEPENDENCIES\s*=\s*)([01])\s*$/ ) { # If this line is not present, we cannot externalize $is_external = $externalize ? 1 : $force_inline ? 0 : $2+0; - $line = $1.$is_external."\n"; + $line = $1.$is_external; } elsif ( $line eq $barrier ) { last; # Stop reading at barrier line } - push @outfile, $line; + push @outfile, $line."\n"; } close($in); @@ -214,7 +215,7 @@ sub insert_deps($) { $out = File::Temp->new(DIR => dirname($outpath = $external)); } - print $out $barrier; + print $out $barrier, "\n"; if ( $externalize ) { # Just strip internal file dependency information From a54a902f4ecc74e936adc9e5e72b555ea4ce9dfc Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 12:40:48 -0700 Subject: [PATCH 04/15] Makefile: unbreak msvc.mak With these changes msvc.mak works on Visual Studio 2022. Signed-off-by: H. Peter Anvin (Intel) --- Makefile.in | 4 +++- Mkfiles/msvc.mak | 33 +++++++++++++++++++-------------- Mkfiles/openwcom.mak | 3 +++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Makefile.in b/Makefile.in index 30886f5a..a861f719 100644 --- a/Makefile.in +++ b/Makefile.in @@ -120,8 +120,11 @@ PROGOBJ = $(NASM) $(NDISASM) PROGS = nasm$(X) ndisasm$(X) # Files dependent on extracted warnings +# WARNTIMES is explicit to avoid breaking some apparently problematic make +# versions, e.g. Microsoft NMAKE WARNOBJ = asm/warnings.$(O) WARNFILES = asm/warnings_c.h include/warnings.h doc/warnings.src +WARNTIMES = asm/warnings_c.h.time include/warnings.h.time doc/warnings.src.time OUTPUTOBJ = \ output/outform.$(O) output/outlib.$(O) \ @@ -243,7 +246,6 @@ ndisasm$(X): $(NDISASM) $(MANIFEST) $(DISLIB) $(NASMLIB) $(DISLIB) $(NASMLIB) $(LIBS) # These are specific to certain Makefile syntaxes... -WARNTIMES = $(WARNFILES:=.time) WARNSRCS = $(ALLOBJ_W:.$(O)=.c) # Make sure we have subdirectories set up... diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index a8fe93ad..086bd81f 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -18,29 +18,32 @@ exec_prefix = $(prefix) bindir = $(prefix)/bin mandir = $(prefix)/man -MANIFEST_FLAGS = /MANIFEST:EMBED /MANIFESTFILE:$(MANIFEST) +MANIFEST_FLAGS = /manifest:embed /manifestfile:$(MANIFEST) !IF "$(DEBUG)" == "1" -CFLAGS = /Od /Zi -LDFLAGS = /DEBUG +OPTFLAGS = /Od /Zi +LDFLAGS = /debug !ELSE CFLAGS = /O2 /Zi # /OPT:REF and /OPT:ICF two undo /DEBUG harm -LDFLAGS = /DEBUG /OPT:REF /OPT:ICF +LDFLAGS = /debug /opt:ref /opt:icf !ENDIF CC = cl AR = lib +ARFLAGS = /nologo + BUILD_CFLAGS = $(CFLAGS) /W2 INTERNAL_CFLAGS = /I$(srcdir) /I. \ /I$(srcdir)/include /I./include \ /I$(srcdir)/x86 /I./x86 \ /I$(srcdir)/asm /I./asm \ /I$(srcdir)/disasm /I./disasm \ - /I$(srcdir)/output /I./output + /I$(srcdir)/output /I./output \ + /I$(srcdir)/zlib ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS) -MANIFEST_FLAGS = /MANIFEST:EMBED /MANIFESTINPUT:$(MANIFEST) -ALL_LDFLAGS = /link $(LDFLAGS) $(MANIFEST_FLAGS) /SUBSYSTEM:CONSOLE /RELEASE +MANIFEST_FLAGS = /manifest:embed /manifestinput:$(MANIFEST) +ALL_LDFLAGS = /link $(LDFLAGS) $(MANIFEST_FLAGS) /subsystem:console /release LIBS = PERL = perl @@ -60,7 +63,7 @@ X = .exe .SUFFIXES: $(X) .$(A) .obj .c .i .s .1 .man .c.obj: - $(CC) /c $(ALL_CFLAGS) /Fo$@ $< + $(CC) /c $(ALL_CFLAGS) /Fo:$@ $< MANIFEST = win/manifest.xml @@ -77,8 +80,11 @@ PROGOBJ = $(NASM) $(NDISASM) PROGS = nasm$(X) ndisasm$(X) # Files dependent on extracted warnings +# WARNTIMES is explicit to avoid breaking some apparently problematic make +# versions, e.g. Microsoft NMAKE WARNOBJ = asm\warnings.obj WARNFILES = asm\warnings_c.h include\warnings.h doc\warnings.src +WARNTIMES = asm\warnings_c.h.time include\warnings.h.time doc\warnings.src.time OUTPUTOBJ = \ output\outform.obj output\outlib.obj \ @@ -178,20 +184,19 @@ NDISLIB = libndis.$(A) all: nasm$(X) ndisasm$(X) nasm$(X): $(NASM) $(MANIFEST) $(NASMLIB) - $(CC) /Fe$@ $(NASM) $(ALL_LDFLAGS) $(NASMLIB) $(LIBS) + $(CC) /Fe:$@ $(NASM) $(NASMLIB) $(LIBS) $(ALL_LDFLAGS) ndisasm$(X): $(NDISASM) $(MANIFEST) $(NDISLIB) $(NASMLIB) - $(CC) /Fe$@ $(NDISASM) $(ALL_LDFLAGS) $(NDISLIB) $(NASMLIB) $(LIBS) + $(CC) /Fe:$@ $(NDISASM) $(NDISLIB) $(NASMLIB) $(LIBS) $(ALL_LDFLAGS) $(NASMLIB): $(LIBOBJ) - $(AR) $(ARFLAGS) /OUT:$@ $** + $(AR) $(ARFLAGS) /out:$@ $** $(NDISLIB): $(LIBOBJ_DIS) - $(AR) $(ARFLAGS) /OUT:$@ $** + $(AR) $(ARFLAGS) /out:$@ $** # These are specific to certain Makefile syntaxes... -WARNTIMES = $(patsubst %,%.time,$(WARNFILES)) -WARNSRCS = $(patsubst %.obj,%.c,$(LIBOBJ_NW)) +WARNSRCS = $(LIBOBJ_NW:.c=.obj) #-- Begin Generated File Rules --# # Edit in Makefile.in, not here! diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index 135c64f7..22b70aa9 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -65,8 +65,11 @@ PROGOBJ = $(NASM) $(NDISASM) PROGS = nasm$(X) ndisasm$(X) # Files dependent on extracted warnings +# WARNTIMES is explicit to avoid breaking some apparently problematic make +# versions, e.g. Microsoft NMAKE WARNOBJ = asm\warnings.obj WARNFILES = asm\warnings_c.h include\warnings.h doc\warnings.src +WARNTIMES = asm\warnings_c.h.time include\warnings.h.time doc\warnings.src.time OUTPUTOBJ = & output\outform.obj output\outlib.obj & From 205512f3c07c60b6a8493a464f4aa61b08886ca5 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 13:15:34 -0700 Subject: [PATCH 05/15] Makefile: a few more portability improvements Define macros for generating an empty file and for a dummy (side effect) target. Tweak MSVC compiler options. Signed-off-by: H. Peter Anvin (Intel) --- Makefile.in | 7 ++++--- Mkfiles/msvc.mak | 17 ++++++++++------- Mkfiles/openwcom.mak | 17 ++++++++++++----- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Makefile.in b/Makefile.in index a861f719..3c5be883 100644 --- a/Makefile.in +++ b/Makefile.in @@ -47,6 +47,7 @@ PERLFLAGS = -I$(top_srcdir)/perllib -I$(srcdir) RUNPERL = $(PERL) $(PERLFLAGS) EMPTY = : > +SIDE = @: Generated by side effect PYTHON3 = python3 @@ -360,7 +361,7 @@ asm/warnings_c.h.time: asm/warnings.pl asm/warnings.time $(EMPTY) asm/warnings_c.h.time asm/warnings_c.h: asm/warnings_c.h.time - @: Side effect + $(SIDE) include/warnings.h.time: asm/warnings.pl asm/warnings.time $(RUNPERL) $(srcdir)/asm/warnings.pl h include/warnings.h \ @@ -368,7 +369,7 @@ include/warnings.h.time: asm/warnings.pl asm/warnings.time $(EMPTY) include/warnings.h.time include/warnings.h: include/warnings.h.time - @: Side effect + $(SIDE) doc/warnings.src.time: asm/warnings.pl asm/warnings.time $(RUNPERL) $(srcdir)/asm/warnings.pl doc doc/warnings.src \ @@ -376,7 +377,7 @@ doc/warnings.src.time: asm/warnings.pl asm/warnings.time $(EMPTY) doc/warnings.src.time doc/warnings.src : doc/warnings.src.time - @: Side effect + $(SIDE) # Assembler token hash asm/tokhash.c: x86/insns.xda x86/insnsn.c asm/tokens.dat asm/tokhash.pl \ diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index 086bd81f..6f9a8f06 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -21,10 +21,10 @@ mandir = $(prefix)/man MANIFEST_FLAGS = /manifest:embed /manifestfile:$(MANIFEST) !IF "$(DEBUG)" == "1" -OPTFLAGS = /Od /Zi +OPTFLAGS = /Od LDFLAGS = /debug !ELSE -CFLAGS = /O2 /Zi +OPTFLAGS = /O2 # /OPT:REF and /OPT:ICF two undo /DEBUG harm LDFLAGS = /debug /opt:ref /opt:icf !ENDIF @@ -33,6 +33,7 @@ CC = cl AR = lib ARFLAGS = /nologo +CFLAGS = $(OPTFLAGS) /Zi /nologo /std:c11 /bigobj BUILD_CFLAGS = $(CFLAGS) /W2 INTERNAL_CFLAGS = /I$(srcdir) /I. \ /I$(srcdir)/include /I./include \ @@ -52,8 +53,10 @@ RUNPERL = $(PERL) $(PERLFLAGS) MAKENSIS = makensis -RM_F = -del /f -LN_S = copy +RM_F = -del /s /f /q +LN_S = copy /y +EMPTY = copy /y nul: +SIDE = @rem Created by side effect # Binary suffixes O = obj @@ -308,7 +311,7 @@ asm\warnings_c.h.time: asm\warnings.pl asm\warnings.time $(EMPTY) asm\warnings_c.h.time asm\warnings_c.h: asm\warnings_c.h.time - @: Side effect + $(SIDE) include\warnings.h.time: asm\warnings.pl asm\warnings.time $(RUNPERL) $(srcdir)\asm\warnings.pl h include\warnings.h \ @@ -316,7 +319,7 @@ include\warnings.h.time: asm\warnings.pl asm\warnings.time $(EMPTY) include\warnings.h.time include\warnings.h: include\warnings.h.time - @: Side effect + $(SIDE) doc\warnings.src.time: asm\warnings.pl asm\warnings.time $(RUNPERL) $(srcdir)\asm\warnings.pl doc doc\warnings.src \ @@ -324,7 +327,7 @@ doc\warnings.src.time: asm\warnings.pl asm\warnings.time $(EMPTY) doc\warnings.src.time doc\warnings.src : doc\warnings.src.time - @: Side effect + $(SIDE) # Assembler token hash asm\tokhash.c: x86\insns.xda x86\insnsn.c asm\tokens.dat asm\tokhash.pl \ diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index 22b70aa9..d27412cf 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -28,12 +28,19 @@ PERL = perl PERLFLAGS = -I$(srcdir)\perllib -I$(srcdir) RUNPERL = $(PERL) $(PERLFLAGS) -EMPTY = $(RUNPERL) -e "" +.BEFORE + set COPYCMD=/y + +RM_F = -del /f +LN_S = copy +EMPTY = copy nul: +SIDE = @rem Created by side effect MAKENSIS = makensis # Binary suffixes O = obj +A = lib X = .exe # WMAKE errors out if a suffix is declared more than once, including @@ -41,7 +48,7 @@ X = .exe # first. Also, WMAKE only allows implicit rules that point "to the left" # in this list! .SUFFIXES: -.SUFFIXES: .man .1 .obj .i .c +.SUFFIXES: .man .1 .obj .i .c .lib .exe # Needed to find C files anywhere but in the current directory .c : $(VPATH) @@ -319,7 +326,7 @@ asm\warnings_c.h.time: asm\warnings.pl asm\warnings.time $(EMPTY) asm\warnings_c.h.time asm\warnings_c.h: asm\warnings_c.h.time - @: Side effect + $(SIDE) include\warnings.h.time: asm\warnings.pl asm\warnings.time $(RUNPERL) $(srcdir)\asm\warnings.pl h include\warnings.h & @@ -327,7 +334,7 @@ include\warnings.h.time: asm\warnings.pl asm\warnings.time $(EMPTY) include\warnings.h.time include\warnings.h: include\warnings.h.time - @: Side effect + $(SIDE) doc\warnings.src.time: asm\warnings.pl asm\warnings.time $(RUNPERL) $(srcdir)\asm\warnings.pl doc doc\warnings.src & @@ -335,7 +342,7 @@ doc\warnings.src.time: asm\warnings.pl asm\warnings.time $(EMPTY) doc\warnings.src.time doc\warnings.src : doc\warnings.src.time - @: Side effect + $(SIDE) # Assembler token hash asm\tokhash.c: x86\insns.xda x86\insnsn.c asm\tokens.dat asm\tokhash.pl & From dfacf9a3d7620e64b82c4ea203e992bf5e245abe Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 13:45:03 -0700 Subject: [PATCH 06/15] Makefiles: remove warnings generation from auxiliary Makefiles The .time trick doesn't seem to work in general, and auxiliary Makefiles aren't guaranteed to build modified sources anyway. Signed-off-by: H. Peter Anvin (Intel) --- Makefile.in | 85 +++++++++++++++++++++++--------------------- Mkfiles/msvc.mak | 40 --------------------- Mkfiles/openwcom.mak | 40 --------------------- 3 files changed, 45 insertions(+), 120 deletions(-) diff --git a/Makefile.in b/Makefile.in index 3c5be883..c75fa660 100644 --- a/Makefile.in +++ b/Makefile.in @@ -121,11 +121,8 @@ PROGOBJ = $(NASM) $(NDISASM) PROGS = nasm$(X) ndisasm$(X) # Files dependent on extracted warnings -# WARNTIMES is explicit to avoid breaking some apparently problematic make -# versions, e.g. Microsoft NMAKE WARNOBJ = asm/warnings.$(O) WARNFILES = asm/warnings_c.h include/warnings.h doc/warnings.src -WARNTIMES = asm/warnings_c.h.time include/warnings.h.time doc/warnings.src.time OUTPUTOBJ = \ output/outform.$(O) output/outlib.$(O) \ @@ -341,43 +338,6 @@ x86/regs.h: x86/regs.dat x86/regs.pl $(RUNPERL) $(srcdir)/x86/regs.pl h \ $(srcdir)/x86/regs.dat > x86/regs.h -# Extract warnings from source code. This is done automatically if any -# C files have changed; the script is fast enough that that is -# reasonable, but doesn't update the time stamp if the files aren't -# changed, to avoid rebuilding everything every time. Track the actual -# dependency by the empty file asm/warnings.time. -.PHONY: warnings -warnings: - $(RM_F) $(WARNFILES) $(WARNTIMES) asm/warnings.time - $(MAKE) asm/warnings.time - -asm/warnings.time: $(WARNSRCS) asm/warnings.pl - $(EMPTY) asm/warnings.time - $(MAKE) $(WARNTIMES) - -asm/warnings_c.h.time: asm/warnings.pl asm/warnings.time - $(RUNPERL) $(srcdir)/asm/warnings.pl c asm/warnings_c.h \ - $(srcdir) $(WARNSRCS) - $(EMPTY) asm/warnings_c.h.time - -asm/warnings_c.h: asm/warnings_c.h.time - $(SIDE) - -include/warnings.h.time: asm/warnings.pl asm/warnings.time - $(RUNPERL) $(srcdir)/asm/warnings.pl h include/warnings.h \ - $(srcdir) $(WARNSRCS) - $(EMPTY) include/warnings.h.time - -include/warnings.h: include/warnings.h.time - $(SIDE) - -doc/warnings.src.time: asm/warnings.pl asm/warnings.time - $(RUNPERL) $(srcdir)/asm/warnings.pl doc doc/warnings.src \ - $(srcdir) $(WARNSRCS) - $(EMPTY) doc/warnings.src.time - -doc/warnings.src : doc/warnings.src.time - $(SIDE) # Assembler token hash asm/tokhash.c: x86/insns.xda x86/insnsn.c asm/tokens.dat asm/tokhash.pl \ @@ -422,6 +382,51 @@ misc/nasmtok.el: misc/emacstbl.pl asm/tokhash.c asm/pptok.c \ #-- End Generated File Rules --# +# Extract warnings from source code. This is done automatically if any +# C files have changed; the script is fast enough that that is +# reasonable, but doesn't update the time stamp if the files aren't +# changed, to avoid rebuilding everything every time. Track the actual +# dependency by the empty file asm/warnings.time. +# +# This doesn't seem to work for non-Unix Makefile variants, so don't +# export those rules here (non-Unix Makefiles only guaranteed to build +# a distribution ball anyway.) + +WARNTIMES = $(WARNFILES:=.time) + +.PHONY: warnings +warnings: + $(RM_F) $(WARNFILES) $(WARNTIMES) asm/warnings.time + $(MAKE) asm/warnings.time + +asm/warnings.time: $(WARNSRCS) asm/warnings.pl + $(EMPTY) asm/warnings.time + $(MAKE) $(WARNTIMES) + +asm/warnings_c.h.time: asm/warnings.pl asm/warnings.time + $(RUNPERL) $(srcdir)/asm/warnings.pl c asm/warnings_c.h \ + $(srcdir) $(WARNSRCS) + $(EMPTY) asm/warnings_c.h.time + +asm/warnings_c.h: asm/warnings_c.h.time + $(SIDE) + +include/warnings.h.time: asm/warnings.pl asm/warnings.time + $(RUNPERL) $(srcdir)/asm/warnings.pl h include/warnings.h \ + $(srcdir) $(WARNSRCS) + $(EMPTY) include/warnings.h.time + +include/warnings.h: include/warnings.h.time + $(SIDE) + +doc/warnings.src.time: asm/warnings.pl asm/warnings.time + $(RUNPERL) $(srcdir)/asm/warnings.pl doc doc/warnings.src \ + $(srcdir) $(WARNSRCS) + $(EMPTY) doc/warnings.src.time + +doc/warnings.src : doc/warnings.src.time + $(SIDE) + $(PERLREQ): $(DIRS) perlreq: $(PERLREQ) diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index 6f9a8f06..d0ebcaac 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -83,11 +83,8 @@ PROGOBJ = $(NASM) $(NDISASM) PROGS = nasm$(X) ndisasm$(X) # Files dependent on extracted warnings -# WARNTIMES is explicit to avoid breaking some apparently problematic make -# versions, e.g. Microsoft NMAKE WARNOBJ = asm\warnings.obj WARNFILES = asm\warnings_c.h include\warnings.h doc\warnings.src -WARNTIMES = asm\warnings_c.h.time include\warnings.h.time doc\warnings.src.time OUTPUTOBJ = \ output\outform.obj output\outlib.obj \ @@ -291,43 +288,6 @@ x86\regs.h: x86\regs.dat x86\regs.pl $(RUNPERL) $(srcdir)\x86\regs.pl h \ $(srcdir)\x86\regs.dat > x86\regs.h -# Extract warnings from source code. This is done automatically if any -# C files have changed; the script is fast enough that that is -# reasonable, but doesn't update the time stamp if the files aren't -# changed, to avoid rebuilding everything every time. Track the actual -# dependency by the empty file asm\warnings.time. -.PHONY: warnings -warnings: - $(RM_F) $(WARNFILES) $(WARNTIMES) asm\warnings.time - $(MAKE) asm\warnings.time - -asm\warnings.time: $(WARNSRCS) asm\warnings.pl - $(EMPTY) asm\warnings.time - $(MAKE) $(WARNTIMES) - -asm\warnings_c.h.time: asm\warnings.pl asm\warnings.time - $(RUNPERL) $(srcdir)\asm\warnings.pl c asm\warnings_c.h \ - $(srcdir) $(WARNSRCS) - $(EMPTY) asm\warnings_c.h.time - -asm\warnings_c.h: asm\warnings_c.h.time - $(SIDE) - -include\warnings.h.time: asm\warnings.pl asm\warnings.time - $(RUNPERL) $(srcdir)\asm\warnings.pl h include\warnings.h \ - $(srcdir) $(WARNSRCS) - $(EMPTY) include\warnings.h.time - -include\warnings.h: include\warnings.h.time - $(SIDE) - -doc\warnings.src.time: asm\warnings.pl asm\warnings.time - $(RUNPERL) $(srcdir)\asm\warnings.pl doc doc\warnings.src \ - $(srcdir) $(WARNSRCS) - $(EMPTY) doc\warnings.src.time - -doc\warnings.src : doc\warnings.src.time - $(SIDE) # Assembler token hash asm\tokhash.c: x86\insns.xda x86\insnsn.c asm\tokens.dat asm\tokhash.pl \ diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index d27412cf..0638623f 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -72,11 +72,8 @@ PROGOBJ = $(NASM) $(NDISASM) PROGS = nasm$(X) ndisasm$(X) # Files dependent on extracted warnings -# WARNTIMES is explicit to avoid breaking some apparently problematic make -# versions, e.g. Microsoft NMAKE WARNOBJ = asm\warnings.obj WARNFILES = asm\warnings_c.h include\warnings.h doc\warnings.src -WARNTIMES = asm\warnings_c.h.time include\warnings.h.time doc\warnings.src.time OUTPUTOBJ = & output\outform.obj output\outlib.obj & @@ -306,43 +303,6 @@ x86\regs.h: x86\regs.dat x86\regs.pl $(RUNPERL) $(srcdir)\x86\regs.pl h & $(srcdir)\x86\regs.dat > x86\regs.h -# Extract warnings from source code. This is done automatically if any -# C files have changed; the script is fast enough that that is -# reasonable, but doesn't update the time stamp if the files aren't -# changed, to avoid rebuilding everything every time. Track the actual -# dependency by the empty file asm\warnings.time. -.PHONY: warnings -warnings: - $(RM_F) $(WARNFILES) $(WARNTIMES) asm\warnings.time - $(MAKE) asm\warnings.time - -asm\warnings.time: $(WARNSRCS) asm\warnings.pl - $(EMPTY) asm\warnings.time - $(MAKE) $(WARNTIMES) - -asm\warnings_c.h.time: asm\warnings.pl asm\warnings.time - $(RUNPERL) $(srcdir)\asm\warnings.pl c asm\warnings_c.h & - $(srcdir) $(WARNSRCS) - $(EMPTY) asm\warnings_c.h.time - -asm\warnings_c.h: asm\warnings_c.h.time - $(SIDE) - -include\warnings.h.time: asm\warnings.pl asm\warnings.time - $(RUNPERL) $(srcdir)\asm\warnings.pl h include\warnings.h & - $(srcdir) $(WARNSRCS) - $(EMPTY) include\warnings.h.time - -include\warnings.h: include\warnings.h.time - $(SIDE) - -doc\warnings.src.time: asm\warnings.pl asm\warnings.time - $(RUNPERL) $(srcdir)\asm\warnings.pl doc doc\warnings.src & - $(srcdir) $(WARNSRCS) - $(EMPTY) doc\warnings.src.time - -doc\warnings.src : doc\warnings.src.time - $(SIDE) # Assembler token hash asm\tokhash.c: x86\insns.xda x86\insnsn.c asm\tokens.dat asm\tokhash.pl & From 0b3c971f5b4879aab6741e3dc63e7eb3a38d856d Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 13:51:20 -0700 Subject: [PATCH 07/15] portability: "const macros_t" is redundant Some C compilers don't like that... Signed-off-by: H. Peter Anvin (Intel) --- asm/uncompress.c | 2 +- include/macros.h | 2 +- macros/macros.pl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/asm/uncompress.c b/asm/uncompress.c index 9481c873..646b04d3 100644 --- a/asm/uncompress.c +++ b/asm/uncompress.c @@ -27,7 +27,7 @@ static void nasm_z_free(void *opaque, void *ptr) nasm_free(ptr); } -char *uncompress_stdmac(const macros_t *sm) +char *uncompress_stdmac(macros_t *sm) { z_stream zs; void *buf = nasm_malloc(sm->dsize); diff --git a/include/macros.h b/include/macros.h index 4e113c05..42022a6f 100644 --- a/include/macros.h +++ b/include/macros.h @@ -17,7 +17,7 @@ struct builtin_macros { }; typedef const struct builtin_macros macros_t; -char *uncompress_stdmac(const macros_t *sm); +char *uncompress_stdmac(macros_t *sm); /* --- From standard.mac via macros.pl -> macros.c --- */ diff --git a/macros/macros.pl b/macros/macros.pl index 962719ed..6e1880c0 100755 --- a/macros/macros.pl +++ b/macros/macros.pl @@ -116,7 +116,7 @@ sub flush_mac($$) printf $out "static const unsigned char %s_blob[%d] = {\n", $name, $zlen; print_data($out, $zblob); - printf $out "\n%sconst macros_t %s = {\n %d, %d, %s_blob\n};\n", + printf $out "\n%smacros_t %s = {\n %d, %d, %s_blob\n};\n", $mac->{'static'} ? 'static ' : '', $name, $dlen, $zlen, $name; From 72118a9ff60edb68ca952534daa27b2749225c7c Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 14:25:04 -0700 Subject: [PATCH 08/15] emacstbl.pl: a few minor tweaks to the emacs token table generator Hopefully this will be useful to someone. Signed-off-by: H. Peter Anvin (Intel) --- misc/emacstbl.pl | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/misc/emacstbl.pl b/misc/emacstbl.pl index 341810d8..3e7fc644 100755 --- a/misc/emacstbl.pl +++ b/misc/emacstbl.pl @@ -34,7 +34,8 @@ my %override = ( 'id' => 'special', 'insn' => 'instruction', 'reg' => 'register', 'seg' => 'special', - 'wrt' => 'special' ); + 'wrt' => 'special', + 'times' => 'special'); sub read_tokhash_c($) { my($tokhash_c) = @_; @@ -54,13 +55,19 @@ sub read_tokhash_c($) { last if ($l =~ /\}\;/); - if ($l =~ /^\s*\{\s*\"(.*?)\",.*?,\s*TOKEN_(\w+),.*\}/) { + if ($l =~ /^\s*\{\s*\"(.*?)\",.*?,\s*TOKEN_(\w+),(.*)\}/) { my $token = $1; my $type = lc($2); + my $flags = $3; + + $token = "{${token}}" if ($flags =~ /\bTFLAG_BRC\b/); + + # Parametric token: omit the actual parameter versions + next if ($token =~ /^\{\w+=.+\}$/); if ($override{$type}) { $type = $override{$type}; - } elsif ($token !~ /^\w/) { + } elsif ($token !~ /^(\{\w+=?\}|\w+)$/) { $type = 'operator'; } elsif ($token =~ /^__\?masm_.*\?__$/) { next; @@ -194,9 +201,19 @@ sub write_output($) { print $out ";;;\n"; print $out ";;; This file is intended to be (require)d from a `nasm-mode\'\n"; print $out ";;; major mode definition.\n"; + print $out ";;;\n"; + print $out ";;; Tokens that are only recognized inside curly braces are\n"; + print $out ";;; noted as such. Tokens of the form {xxx=} are parametric\n"; + print $out ";;; tokens, where the token may contain additional text on\n"; + print $out ";;; the right side of the = sign. For example,\n"; + print $out ";;; {dfv=} should be matched by {dfv=cf,zf}.\n"; + print $out ";;;\n"; + my @types = sort keys(%tokens); + + # Write the individual token type lists foreach my $type (sort keys(%tokens)) { - print $out "\n(defconst nasm-${type}\n"; + print $out "\n(defconst nasm-token-${type}\n"; print $out " \'("; print $out make_lines(78, 4, quote_for_emacs(sort @{$tokens{$type}})); @@ -204,6 +221,13 @@ sub write_output($) { print $out " \"NASM ${version} ${type} tokens for `nasm-mode\'.\")\n"; } + # Generate a list of all the token type lists. + print $out "\n(defconst nasm-token-lists\n"; + print $out " \'("; + print $out make_lines(78, 4, map { "'nasm-token-$_" } sort keys(%tokens)); + print $out ")\n"; + print $out " \"List of all NASM token type lists.\")\n"; + close($out); } From d021e86def9db8808b92c97b2e243bc1f896dd1d Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 14:25:54 -0700 Subject: [PATCH 09/15] NASM 3.00rc18 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 78b25073..efb3a26b 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.00rc17 +3.00rc18 From 094cc54cd35270f51b7e2085c032473e3b149805 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 15:11:40 -0700 Subject: [PATCH 10/15] emacstbl.pl: extract build-in macro names Extract builtin macro names into emacstbl.pl, and avoid duplicated tokens. Signed-off-by: H. Peter Anvin (Intel) --- misc/emacstbl.pl | 87 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 22 deletions(-) diff --git a/misc/emacstbl.pl b/misc/emacstbl.pl index 56eeee18..60939cdc 100755 --- a/misc/emacstbl.pl +++ b/misc/emacstbl.pl @@ -6,6 +6,7 @@ use integer; use strict; use File::Spec; +use File::Find; my($outfile, $srcdir, $objdir) = @ARGV; @@ -16,7 +17,8 @@ if (!defined($outfile)) { $srcdir = File::Spec->curdir() unless (defined($srcdir)); $objdir = $srcdir unless (defined($objdir)); -my %tokens = (); +my %tokens = (); # Token lists per category +my %token_category = (); # Tokens to category map sub xpush($@) { my $ref = shift @_; @@ -26,16 +28,28 @@ sub xpush($@) { } # Combine some specific token types -my %override = ( 'id' => 'special', - 'float' => 'function', - 'floatize' => 'function', - 'strfunc' => 'function', - 'ifunc' => 'function', - 'insn' => 'instruction', - 'reg' => 'register', - 'seg' => 'special', - 'wrt' => 'special', - 'times' => 'special'); +my %override = ( + 'brcconst' => 'special-constant', + 'id' => 'special', + 'float' => 'function', + 'floatize' => 'function', + 'strfunc' => 'function', + 'ifunc' => 'function', + 'insn' => 'instruction', + 'reg' => 'register', + 'seg' => 'special', + 'wrt' => 'special', + 'times' => 'special'); + +sub addtoken($$) { + my($type, $token) = @_; + + unless (defined($token_category{$token})) { + $type = $override{$type} if (defined($override{$type})); + xpush(\$tokens{$type}, $token); + $token_category{$token} = $type; + } +} sub read_tokhash_c($) { my($tokhash_c) = @_; @@ -62,20 +76,18 @@ sub read_tokhash_c($) { $token = "{${token}}" if ($flags =~ /\bTFLAG_BRC\b/); - # Parametric token: omit the actual parameter versions - next if ($token =~ /^\{\w+=.+\}$/); + # Parametric token: omit the actual parameter(s) + $token =~ s/^(\{[\w-]+=).+(\})$/$1$2/; - if ($override{$type}) { - $type = $override{$type}; - } elsif ($token !~ /^(\{\w+=?\}|\w+)$/) { + if ($token !~ /^(\{[\w-]+=?\}|\w+)$/) { $type = 'operator'; } elsif ($token =~ /^__\?masm_.*\?__$/) { next; } - xpush(\$tokens{$type}, $token); + addtoken($type, $token); if ($token =~ /^__\?(.*)\?__$/) { # Also encode the "user" (macro) form without __?...?__ - xpush(\$tokens{$type}, $1); + addtoken($type, $1); } } } @@ -102,7 +114,7 @@ sub read_pptok_c($) { last if ($l =~ /\}\;/); if ($l =~ /^\s*\"(.*?)\"/) { - xpush(\$tokens{'pp-directive'}, $1); + addtoken('pp-directive', $1); } } close($pt); @@ -126,7 +138,7 @@ sub read_directiv_dat($) { } if ($l =~ /^\s*(\w+)/) { - xpush(\$tokens{'directive'}, $1); + addtoken('directive', $1); } } @@ -145,6 +157,36 @@ sub read_version($) { close($v); } +sub read_macros($$) { + my($srcdir, $objdir) = @_; + my @dirs; + push(@dirs, $objdir); + push(@dirs, File::Spec->catdir($srcdir, 'macros')); + push(@dirs, File::Spec->catdir($srcdir, 'output')); + foreach my $dir (@dirs) { + opendir(my $dh, $dir) or die; + while (defined(my $fn = readdir($dh))) { + next unless ($fn =~ /\.mac$/); + + open(my $fh, '<', File::Spec->catfile($dir, $fn)) or die; + while (defined(my $l = <$fh>)) { + next unless ($l =~ /^\s*\%/); + my @f = split(/\s+/, $l); + next unless (scalar(@f) >= 2); + $f[1] =~ s/\(.*$//; # Strip argument list if any + next if ($f[1] =~ /^[\%\$]/); # Internal use only + $f[1] = lc($f[1]) if ($f[0] =~ /^\%i/); + if ($f[0] =~ /^\%(i)?(assign|defalias|define|defstr|substr|xdefine)\b/) { + addtoken('smacro', $f[1]); + } elsif ($f[0] =~ /^\%i?macro$/) { + addtoken('mmacro', $f[1]); + } + } + close($fh); + } + } +} + sub make_lines($$@) { my $maxline = shift @_; my $indent = shift @_; @@ -200,9 +242,9 @@ sub write_output($) { print $out ";; assembler, automatically extracted from NASM ${version}.\n"; print $out ";;\n"; print $out ";; This file is intended to be (require)d from a `nasm-mode\'\n"; - print $out ";; major mode definition.\n\n"; + print $out ";; major mode definition.\n"; print $out ";;\n"; - print $out ";;; Tokens that are only recognized inside curly braces are\n"; + print $out ";; Tokens that are only recognized inside curly braces are\n"; print $out ";; noted as such. Tokens of the form {xxx=} are parametric\n"; print $out ";; tokens, where the token may contain additional text on\n"; print $out ";; the right side of the = sign. For example,\n"; @@ -241,5 +283,6 @@ read_tokhash_c(File::Spec->catfile($objdir, 'asm', 'tokhash.c')); read_pptok_c(File::Spec->catfile($objdir, 'asm', 'pptok.c')); read_directiv_dat(File::Spec->catfile($srcdir, 'asm', 'directiv.dat')); read_version(File::Spec->catfile($srcdir, 'version')); +read_macros($srcdir, $objdir); write_output($outfile); From 03391e61ecb70a65bc77d213a4e480b7ada07883 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 16:06:40 -0700 Subject: [PATCH 11/15] nasmtok.el: include builtin macros and macro functions Use a really hacky way to run the NASM binary and extract automatic builtin macros. As this is not something normally supported during the NASM build process, the output is canned and will need to be run manually. Signed-off-by: H. Peter Anvin (Intel) --- misc/builtin.mac | 161 ++++++++++++++++++++++++++++++++++++++++++++ misc/dumpbuiltin.sh | 20 ++++++ misc/emacstbl.pl | 39 ++++++----- 3 files changed, 204 insertions(+), 16 deletions(-) create mode 100644 misc/builtin.mac create mode 100755 misc/dumpbuiltin.sh diff --git a/misc/builtin.mac b/misc/builtin.mac new file mode 100644 index 00000000..aabce07f --- /dev/null +++ b/misc/builtin.mac @@ -0,0 +1,161 @@ +;;; Automatically generated list of builtin macros +%define __?FILE?__ +%define __?LINE?__ +%define __?BITS?__ +%define __?PTR?__ +%define __?DEFAULT?__ +%idefine %abs(=) +%idefine %chr(=+) +%idefine %count(+) +%idefine %depend() +%idefine %eval(=+) +%idefine %hs2b(&&+) +%idefine %map(+) +%idefine %null(+) +%idefine %pathsearch() +%idefine %realpath() +%idefine %str(&+) +%idefine %strcat(&&+) +%idefine %strlen(&&) +%idefine %tok(&&) +%idefine %is(+) +%idefine %isctx(+) +%idefine %isdef(+) +%idefine %isdefalias(+) +%idefine %isdifi(+) +%idefine %isdirective(+) +%idefine %isempty(+) +%idefine %isenv(+) +%idefine %isfile(+) +%idefine %isid(+) +%idefine %isidn(+) +%idefine %isidni(+) +%idefine %ismacro(+) +%idefine %isnum(+) +%idefine %isstr(+) +%idefine %istoken(+) +%idefine %isusable(+) +%idefine %isusing(+) +%idefine %isn(+) +%idefine %isnctx(+) +%idefine %isndef(+) +%idefine %isndefalias(+) +%idefine %isndifi(+) +%idefine %isndirective(+) +%idefine %isnempty(+) +%idefine %isnenv(+) +%idefine %isnfile(+) +%idefine %isnid(+) +%idefine %isnidn(+) +%idefine %isnidni(+) +%idefine %isnmacro(+) +%idefine %isnnum(+) +%idefine %isnstr(+) +%idefine %isntoken(+) +%idefine %isnusable(+) +%idefine %isnusing(+) +%idefine %hex(=+/ux) +%idefine %sel(=,+) +%idefine %cond(=,,) +%idefine %num(=,=,=) +%idefine %substr(&&,=,=) +%idefine %ord(&&,=,=) +%idefine %b2hs(&&,&&) +%idefine %findi(&&,+) +%idefine %find(&&,+) +%define __?PASS?__ +%define __?SECT?__ +%defalias __SECT__ +%define __?SECTALIGN_ALIGN_UPDATES_SECTION?__ +%defalias __SECTALIGN_ALIGN_UPDATES_SECTION__ +%define __?FLOAT_DAZ?__ +%define __?FLOAT_ROUND?__ +%define __?FLOAT?__ +%defalias __FLOAT_DAZ__ +%defalias __FLOAT_ROUND__ +%defalias __FLOAT__ +%defalias __NASM_MAJOR__ +%defalias __NASM_MINOR__ +%defalias __NASM_SUBMINOR__ +%defalias __NASM_PATCHLEVEL__ +%defalias __NASM_SNAPSHOT__ +%defalias __NASM_VERSION_ID__ +%defalias __NASM_VER__ +%defalias __OUTPUT_FORMAT__ +%defalias __DEBUG_FORMAT__ +%defalias __DATE__ +%defalias __DATE_NUM__ +%defalias __TIME__ +%defalias __TIME_NUM__ +%defalias __UTC_DATE__ +%defalias __UTC_DATE_NUM__ +%defalias __UTC_TIME__ +%defalias __UTC_TIME_NUM__ +%defalias __POSIX_TIME__ +%defalias __FILE__ +%defalias __LINE__ +%defalias __BITS__ +%defalias __PTR__ +%defalias __PASS__ +%idefine __?infinity?__ +%idefine __?nan?__ +%idefine __?qnan?__ +%idefine __?snan?__ +%idefine __?float8?__ +%idefine __?float16?__ +%idefine __?float32?__ +%idefine __?float64?__ +%idefine __?float80m?__ +%idefine __?float80e?__ +%idefine __?float128l?__ +%idefine __?float128h?__ +%idefine __?utf16?__ +%idefine __?utf16le?__ +%idefine __?utf16be?__ +%idefine __?utf32?__ +%idefine __?utf32le?__ +%idefine __?utf32be?__ +%idefine __?ilog2e?__ +%idefine __?ilog2w?__ +%idefine __?ilog2f?__ +%idefine __?ilog2c?__ +%idefalias __infinity__ +%idefalias __nan__ +%idefalias __qnan__ +%idefalias __snan__ +%idefalias __float8__ +%idefalias __float16__ +%idefalias __float32__ +%idefalias __float64__ +%idefalias __float80m__ +%idefalias __float80e__ +%idefalias __float128l__ +%idefalias __float128h__ +%idefalias __utf16__ +%idefalias __utf16le__ +%idefalias __utf16be__ +%idefalias __utf32__ +%idefalias __utf32le__ +%idefalias __utf32be__ +%idefalias __ilog2e__ +%idefalias __ilog2w__ +%idefalias __ilog2f__ +%idefalias __ilog2c__ +%define __?NASM_HAS_IFDIRECTIVE?__ +%define __?NASM_MAJOR?__ +%define __?NASM_MINOR?__ +%define __?NASM_SUBMINOR?__ +%define __?NASM_PATCHLEVEL?__ +%define __?NASM_VERSION_ID?__ +%define __?NASM_VER?__ +%define __?SECT?__ +%define __?DATE?__ +%define __?DATE_NUM?__ +%define __?TIME?__ +%define __?TIME_NUM?__ +%define __?UTC_DATE?__ +%define __?UTC_DATE_NUM?__ +%define __?UTC_TIME?__ +%define __?UTC_TIME_NUM?__ +%define __?POSIX_TIME?__ +%define __?OUTPUT_FORMAT?__ diff --git a/misc/dumpbuiltin.sh b/misc/dumpbuiltin.sh new file mode 100755 index 00000000..de9139ee --- /dev/null +++ b/misc/dumpbuiltin.sh @@ -0,0 +1,20 @@ +#!/bin/sh - +# Copyright 1996-20xx The NASM Authors - All Rights Reserved +# SPDX-License-Identifier: BSD-2-Clause + +# +# Run the nasm binary and extract the list of macros that may or may +# not be defined in .mac files. +# + +tmp="$(mktemp -d)" +[ -n "$tmp" ] || exit 1 + +NASM="${NASM:-../nasm}" + +: > "$tmp/junk.asm" +"$NASM" -f bin -o "$tmp/junk.bin" -Lsb -l "$tmp/junk.lst" "$tmp/junk.asm" +printf ';;; Automatically generated list of builtin macros\n' +sed -n -E -e 's/^[^;]*;;; *(%i?(define|defalias|macro)) ([^ ]*) .*$/\1 \3/p'\ + < "$tmp/junk.lst" +rm -rf "$tmp" diff --git a/misc/emacstbl.pl b/misc/emacstbl.pl index 60939cdc..237b9a33 100755 --- a/misc/emacstbl.pl +++ b/misc/emacstbl.pl @@ -157,6 +157,26 @@ sub read_version($) { close($v); } +sub read_macro_file($) { + my($file) = @_; + + open(my $fh, '<', $file) or die; + while (defined(my $l = <$fh>)) { + next unless ($l =~ /^\s*\%/); + my @f = split(/\s+/, $l); + next unless (scalar(@f) >= 2); + next if ($f[1] =~ /^[\%\$][^\(]+$/); # Internal use only + $f[1] =~ s/\(.*$//; # Strip argument list if any + $f[1] = lc($f[1]) if ($f[0] =~ /^\%i/); + if ($f[0] =~ /^\%(i)?(assign|defalias|define|defstr|substr|xdefine)\b/) { + addtoken('smacro', $f[1]); + } elsif ($f[0] =~ /^\%i?macro$/) { + addtoken('mmacro', $f[1]); + } + } + close($fh); +} + sub read_macros($$) { my($srcdir, $objdir) = @_; my @dirs; @@ -167,24 +187,11 @@ sub read_macros($$) { opendir(my $dh, $dir) or die; while (defined(my $fn = readdir($dh))) { next unless ($fn =~ /\.mac$/); - - open(my $fh, '<', File::Spec->catfile($dir, $fn)) or die; - while (defined(my $l = <$fh>)) { - next unless ($l =~ /^\s*\%/); - my @f = split(/\s+/, $l); - next unless (scalar(@f) >= 2); - $f[1] =~ s/\(.*$//; # Strip argument list if any - next if ($f[1] =~ /^[\%\$]/); # Internal use only - $f[1] = lc($f[1]) if ($f[0] =~ /^\%i/); - if ($f[0] =~ /^\%(i)?(assign|defalias|define|defstr|substr|xdefine)\b/) { - addtoken('smacro', $f[1]); - } elsif ($f[0] =~ /^\%i?macro$/) { - addtoken('mmacro', $f[1]); - } - } - close($fh); + read_macro_file(File::Spec->catdir($dir, $fn)); } } + # Don't read the whole misc directory! + read_macro_file(File::Spec->catdir($srcdir, 'misc/builtin.mac')); } sub make_lines($$@) { From 959644a01787f81659ad63e734bc3f2790e9ddb3 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 1 Oct 2025 19:20:37 -0700 Subject: [PATCH 12/15] msvc.mak: make sure perl is only run if it exists Only try to run a Perl interpreter if the system actually has one available. Because timestamps on Windows are apparently not preserved on archive extraction, otherwise it might happen that nmake will try to rebuild files even through they already exist. Signed-off-by: H. Peter Anvin (Intel) --- Mkfiles/msvc.mak | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index d0ebcaac..1f4a2671 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -49,7 +49,11 @@ LIBS = PERL = perl PERLFLAGS = -I$(srcdir)/perllib -I$(srcdir) +!IF [$(PERL) $(PERLFLAGS) -e "exit 0;"] == 0 RUNPERL = $(PERL) $(PERLFLAGS) +!ELSE +RUNPERL = : +!ENDIF MAKENSIS = makensis @@ -184,10 +188,12 @@ NDISLIB = libndis.$(A) all: nasm$(X) ndisasm$(X) nasm$(X): $(NASM) $(MANIFEST) $(NASMLIB) - $(CC) /Fe:$@ $(NASM) $(NASMLIB) $(LIBS) $(ALL_LDFLAGS) + $(CC) /Fe:$@ $(ALL_CFLAGS) $(NASM) $(NASMLIB) $(LIBS) \ + $(ALL_LDFLAGS) ndisasm$(X): $(NDISASM) $(MANIFEST) $(NDISLIB) $(NASMLIB) - $(CC) /Fe:$@ $(NDISASM) $(NDISLIB) $(NASMLIB) $(LIBS) $(ALL_LDFLAGS) + $(CC) /Fe:$@ $(ALL_CFLAGS) $(NDISASM) $(NDISLIB) $(NASMLIB) $(LIBS) \ + $(ALL_LDFLAGS) $(NASMLIB): $(LIBOBJ) $(AR) $(ARFLAGS) /out:$@ $** From 01e40a9aeb4059b8ca5d2d7e7342d545883fc8fb Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 2 Oct 2025 13:47:20 -0700 Subject: [PATCH 13/15] Move editor help files to editors/, add NASM version number Move the editor help files (currently nasmtok.el) to the editors/ subdirectory in anticipation of having more such files. Signed-off-by: H. Peter Anvin (Intel) --- .gitignore | 2 +- Makefile.in | 26 ++-- {misc => editors}/builtin.mac | 0 {misc => editors}/dumpbuiltin.sh | 0 misc/emacstbl.pl => editors/nasmtok.pl | 162 ++++++++++++++++++------- misc/Makefile.in | 5 +- version.pl | 10 +- 7 files changed, 147 insertions(+), 58 deletions(-) rename {misc => editors}/builtin.mac (100%) rename {misc => editors}/dumpbuiltin.sh (100%) rename misc/emacstbl.pl => editors/nasmtok.pl (61%) diff --git a/.gitignore b/.gitignore index 58949b48..999e04dc 100644 --- a/.gitignore +++ b/.gitignore @@ -78,9 +78,9 @@ TAGS /doc/pptok.src /doc/fontpath /doc/Fontmap +/editors/nasmtok.el /include/warnings.h /macros/macros.c -/misc/nasmtok.el /misc/omfdump /misc/Makefile /nasm diff --git a/Makefile.in b/Makefile.in index c75fa660..58e5df78 100644 --- a/Makefile.in +++ b/Makefile.in @@ -15,6 +15,7 @@ exec_prefix = @exec_prefix@ bindir = @bindir@ mandir = @mandir@ datarootdir = @datarootdir@ +datadir = @datadir@ CC = @CC@ CFLAGS = @CFLAGS@ @@ -94,7 +95,7 @@ endif .PHONY: all doc misc install clean distclean cleaner spotless test .PHONY: install_doc everything install_everything strip perlreq dist tags TAGS -.PHONY: nothing manpages nsis +.PHONY: nothing manpages nsis editors .c.$(O): $(CC) -c $(ALL_CFLAGS) -o $@ $< @@ -212,8 +213,11 @@ ALLOBJ_W = $(NASM) $(LIBOBJ_W) ALLOBJ = $(PROGOBJ) $(LIBOBJ) SUBDIRS = stdlib nasmlib include config output asm disasm x86 \ common zlib macros misc -XSUBDIRS = nsis win test doc +XSUBDIRS = nsis win test doc editors DEPDIRS = . $(SUBDIRS) + +EDITORS = editors/nasmtok.el + #-- End File Lists --# all: $(PROGS) @@ -264,7 +268,6 @@ PERLREQ_CLEANABLE = \ macros/macros.c \ asm/pptok.ph asm/directbl.c asm/directiv.h \ $(WARNFILES) \ - misc/nasmtok.el \ version.h version.mac version.mak nsis/version.nsh PERLREQ = $(PERLREQ_CLEANABLE) @@ -376,9 +379,12 @@ asm/directbl.c: asm/directiv.dat nasmlib/perfhash.pl perllib/phash.ph $(srcdir)/asm/directiv.dat asm/directbl.c # Emacs token files -misc/nasmtok.el: misc/emacstbl.pl asm/tokhash.c asm/pptok.c \ - asm/directiv.dat version - $(RUNPERL) $(srcdir)/misc/emacstbl.pl $@ $(srcdir) $(objdir) +editors/nasmtok.el: editors/nasmtok.pl asm/tokhash.c asm/pptok.c \ + asm/directiv.dat macros/macros.c editors/builtin.mac \ + version.mak + $(RUNPERL) $(srcdir)/editors/nasmtok.pl -el $@ $(srcdir) $(objdir) + +editors: $(EDITORS) #-- End Generated File Rules --# @@ -461,6 +467,10 @@ install: $(PROGS) $(INSTALL_DATA) $(srcdir)/nasm.1 $(DESTDIR)$(mandir)/man1/nasm.1 $(INSTALL_DATA) $(srcdir)/ndisasm.1 $(DESTDIR)$(mandir)/man1/ndisasm.1 +install_editors: $(EDITORS) + $(MKDIR_P) $(DESTDIR)$(datadir) + $(INSTALL_DATA) $(EDITORS) $(DESTDIR)$(datadir) + clean: for d in . $(SUBDIRS) $(XSUBDIRS); do \ $(RM_F) "$$d"/*.$(O) "$$d"/*.s "$$d"/*.i "$$d"/*.$(A) ; \ @@ -481,7 +491,7 @@ distclean: clean -$(SHELL) autoconf/clean.sh || $(SHELL) $(srcdir)/autoconf/clean.sh cleaner: - $(RM_F) $(PERLREQ_CL) *.1 nasm.spec + $(RM_F) $(PERLREQ_CL) $(EDITORS) *.1 nasm.spec $(MAKE) -C doc clean $(MAKE) -C misc clean $(MAKE) distclean @@ -529,7 +539,7 @@ always_everything: $(DIRS) everything: always_everything $(MAKE) $(MANPAGES) $(NSIS) nothing -install_everything: everything install install_doc +install_everything: everything install install_doc install_editors dist: $(MAKE) alldeps diff --git a/misc/builtin.mac b/editors/builtin.mac similarity index 100% rename from misc/builtin.mac rename to editors/builtin.mac diff --git a/misc/dumpbuiltin.sh b/editors/dumpbuiltin.sh similarity index 100% rename from misc/dumpbuiltin.sh rename to editors/dumpbuiltin.sh diff --git a/misc/emacstbl.pl b/editors/nasmtok.pl similarity index 61% rename from misc/emacstbl.pl rename to editors/nasmtok.pl index 237b9a33..274b2043 100755 --- a/misc/emacstbl.pl +++ b/editors/nasmtok.pl @@ -8,14 +8,25 @@ use strict; use File::Spec; use File::Find; +my $format = 'el'; + +if ($ARGV[0] =~ /^-(\S+)$/) { + $format = $1; + shift @ARGV; +} + my($outfile, $srcdir, $objdir) = @ARGV; if (!defined($outfile)) { - die "Usage: $0 outfile srcdir objdir\n"; + die "Usage: $0 [-format] outfile srcdir objdir\n"; } -$srcdir = File::Spec->curdir() unless (defined($srcdir)); -$objdir = $srcdir unless (defined($objdir)); +my @vpath; + +$srcdir = $srcdir || File::Spec->curdir(); +$objdir = $objdir || $srcdir; +push(@vpath, $objdir) if ($objdir ne $srcdir); +push(@vpath, $srcdir); my %tokens = (); # Token lists per category my %token_category = (); # Tokens to category map @@ -27,6 +38,32 @@ sub xpush($@) { return push(@$$ref, @_); } +# Search for a file, and return a file handle if successfully opened +sub open_vpath($$) { + my($mode, $file) = @_; + my %tried; + + # For simplicity, allow filenames to be specified + # with Unix / syntax internally + $file = File::Spec->catfile(split(/\//, $file)); + + foreach my $d (@vpath) { + my $fn = File::Spec->catfile($d, $file); + next if ($tried{$fn}); + $tried{$fn}++; + my $fh; + return $fh if (open($fh, $mode, $fn)); + } + return undef; +} + +sub must_open($) { + my($file) = @_; + my $fh = open_vpath('<', $file); + return $fh if (defined($fh)); + die "$0:$file: $!\n"; +} + # Combine some specific token types my %override = ( 'brcconst' => 'special-constant', @@ -54,8 +91,7 @@ sub addtoken($$) { sub read_tokhash_c($) { my($tokhash_c) = @_; - open(my $th, '<', $tokhash_c) - or die "$0:$tokhash_c: $!\n"; + my $th = must_open($tokhash_c); my $l; my $tokendata = 0; @@ -97,8 +133,7 @@ sub read_tokhash_c($) { sub read_pptok_c($) { my($pptok_c) = @_; - open(my $pt, '<', $pptok_c) - or die "$0:$pptok_c: $!\n"; + my $pt = must_open($pptok_c); my $l; my $pp_dir = 0; @@ -123,8 +158,7 @@ sub read_pptok_c($) { sub read_directiv_dat($) { my($directiv_dat) = @_; - open(my $dd, '<', $directiv_dat) - or die "$0:$directiv_dat: $!\n"; + my $dd = must_open($directiv_dat); my $l; my $directiv = 0; @@ -145,22 +179,25 @@ sub read_directiv_dat($) { close($dd); } -my $version; +my %version; sub read_version($) { my($vfile) = @_; - open(my $v, '<', $vfile) - or die "$0:$vfile: $!\n"; - - $version = <$v>; - chomp $version; + my $v = must_open($vfile); + while (defined(my $vl = <$v>)) { + if ($vl =~ /^NASM_(\w+)=(\S+)\s*$/) { + $version{lc($1)} = $2; + } + } close($v); } +# This is called from the directory search in read_macros(), so +# don't use must_open() here. sub read_macro_file($) { my($file) = @_; - open(my $fh, '<', $file) or die; + open(my $fh, '<', $file) or die "$0:$file: $!\n"; while (defined(my $l = <$fh>)) { next unless ($l =~ /^\s*\%/); my @f = split(/\s+/, $l); @@ -177,21 +214,20 @@ sub read_macro_file($) { close($fh); } -sub read_macros($$) { - my($srcdir, $objdir) = @_; - my @dirs; - push(@dirs, $objdir); - push(@dirs, File::Spec->catdir($srcdir, 'macros')); - push(@dirs, File::Spec->catdir($srcdir, 'output')); +sub read_macros(@) { + my %visited; + my @dirs = (File::Spec->curdir(), qw(macros output editors)); + @dirs = map { my $od = $_; map { File::Spec->catdir($od, $_) } @dirs } @_; foreach my $dir (@dirs) { - opendir(my $dh, $dir) or die; + next if ($visited{$dir}); + $visited{$dir}++; + next unless opendir(my $dh, $dir); while (defined(my $fn = readdir($dh))) { - next unless ($fn =~ /\.mac$/); - read_macro_file(File::Spec->catdir($dir, $fn)); + next unless ($fn =~ /\.mac$/i); + read_macro_file(File::Spec->catfile($dir, $fn)); } + closedir($dh); } - # Don't read the whole misc directory! - read_macro_file(File::Spec->catdir($srcdir, 'misc/builtin.mac')); } sub make_lines($$@) { @@ -235,18 +271,15 @@ sub quote_for_emacs(@) { return map { s/[\\\"\']/\\$1/g; '"'.$_.'"' } @_; } -sub write_output($) { - my($outfile) = @_; - - open(my $out, '>', $outfile) - or die "$0:$outfile: $!\n"; - - my($vol,$dir,$file) = File::Spec->splitpath($outfile); +# Emacs LISP +sub write_output_el { + my($out, $outfile, $file) = @_; + my $whoami = 'NASM '.$version{'ver'}; print $out ";;; ${file} --- lists of NASM assembler tokens\n\n"; print $out ";;; Commentary:\n\n"; print $out ";; This file contains list of tokens from the NASM x86\n"; - print $out ";; assembler, automatically extracted from NASM ${version}.\n"; + print $out ";; assembler, automatically extracted from ${whoami}.\n"; print $out ";;\n"; print $out ";; This file is intended to be (require)d from a `nasm-mode\'\n"; print $out ";; major mode definition.\n"; @@ -268,7 +301,7 @@ sub write_output($) { print $out make_lines(78, 4, quote_for_emacs(sort @{$tokens{$type}})); print $out ")\n"; - print $out " \"NASM ${version} ${type} tokens for `nasm-mode\'.\")\n"; + print $out " \"${whoami} ${type} tokens for `nasm-mode\'.\")\n"; } # Generate a list of all the token type lists. @@ -276,20 +309,61 @@ sub write_output($) { print $out " \'("; print $out make_lines(78, 4, map { "'nasm-$_" } sort keys(%tokens)); print $out ")\n"; - print $out " \"List of all NASM token type lists.\")\n"; + print $out " \"List of all ${whoami} token type lists.\")\n"; + # The NASM token extracted version + printf $out "\n(defconst nasm-token-version %s\n", + quote_for_emacs($version{'ver'}); + print $out " \"Version of NASM from which tokens were extracted,\n"; + print $out "as a human-readable string.\")\n"; + + printf $out "\n(defconst nasm-token-version-id #x%08x\n", + $version{'version_id'}; + print $out " \"Version of NASM from which tokens were extracted,\n"; + print $out "as numeric identifier, for comparisons. Equivalent to the\n"; + print $out "__?NASM_VERSION_ID?__ NASM macro value.\")\n"; + + printf $out "\n(defconst nasm-token-version-snapshot %s\n", + $version{'snapshot'} || 'nil'; + print $out " \"Daily NASM snapshot build from which tokens were extracted,\n"; + print $out "as a decimal number in YYYYMMDD format, or nil if not a\n"; + print $out "daily snapshot build.\")\n"; # Footer print $out "\n(provide 'nasmtok)\n"; print $out ";;; nasmtok.el ends here\n"; - close($out); + return 0; } -read_tokhash_c(File::Spec->catfile($objdir, 'asm', 'tokhash.c')); -read_pptok_c(File::Spec->catfile($objdir, 'asm', 'pptok.c')); -read_directiv_dat(File::Spec->catfile($srcdir, 'asm', 'directiv.dat')); -read_version(File::Spec->catfile($srcdir, 'version')); -read_macros($srcdir, $objdir); +sub write_output($$) { + my($format, $outfile) = @_; + my %formats = ( + 'el' => \&write_output_el + ); -write_output($outfile); + my $outfunc = $formats{$format}; + if (!defined($outfunc)) { + die "$0: unknown output format: $format\n"; + } + + open(my $out, '>', $outfile) + or die "$0:$outfile: $!\n"; + + my($vol,$dir,$file) = File::Spec->splitpath($outfile); + + my $err = $outfunc->($out, $outfile, $file); + close($out); + + if ($err) { + unlink($outfile); + die "$0:$outfile: error writing output\n"; + } +} + +read_tokhash_c('asm/tokhash.c'); +read_pptok_c('asm/pptok.c'); +read_directiv_dat('asm/directiv.dat'); +read_version('version.mak'); +read_macros(@vpath); +write_output($format, $outfile); diff --git a/misc/Makefile.in b/misc/Makefile.in index fecd4cf6..09a0c643 100644 --- a/misc/Makefile.in +++ b/misc/Makefile.in @@ -51,7 +51,7 @@ CP_F = cp -f CP_UF = cp -uf PROGS = omfdump$(X) -GENDATA = nasmtok.el +GENDATA = SRCDATA = README \ c16.mac c32.mac exebin.mac exebin2.mac \ myC32.mac scitech.mac \ @@ -85,9 +85,6 @@ all: $(PROGS) $(GENDATA) omfdump$(X): omfdump.$(O) $(CC) $(ALL_LDFLAGS) -o $@ $< $(LIBS) -nasmtok.el: - $(MAKE) -C .. - install-prog: $(PROGS) $(MKDIR_P) $(DESTDIR)$(bindir) $(INSTALL_PROGRAM) $(PROGS) $(DESTDIR)$(bindir)/ diff --git a/version.pl b/version.pl index f061c23e..26cea13a 100755 --- a/version.pl +++ b/version.pl @@ -134,7 +134,7 @@ if ( $what eq 'h' ) { printf "s/\@\@NASM_PATCHLEVEL\@\@/%d/g\n", $nplvl; printf "s/\@\@NASM_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty printf "s/\@\@NASM_VERSION_ID\@\@/%d/g\n", $nasm_id; - printf "s/\@\@NASM_VERSION_XID\@\@/0x%08x/g\n", $nasm_id; + printf "s/\@\@NASM_VERSION_XID\@\@/%08x/g\n", $nasm_id; printf "s/\@\@NASM_VER\@\@/%s/g\n", $line; printf "s/\@\@NASM_MANGLED_VER\@\@/%s/g\n", $mangled_ver; } elsif ( $what eq 'make' ) { @@ -143,12 +143,20 @@ if ( $what eq 'h' ) { printf "NASM_MINOR_VER=%d\n", $nmin; printf "NASM_SUBMINOR_VER=%d\n", $nsmin; printf "NASM_PATCHLEVEL_VER=%d\n", $nplvl; + printf "NASM_VERSION_ID=%d\n", $nasm_id; + printf "NASM_VERSION_XID=%08x\n", $nasm_id; + if (defined($snapshot)) { + printf "NASM_SNAPSHOT=%d\n", $snapshot; + } } elsif ( $what eq 'nsis' ) { printf "!define VERSION \"%s\"\n", $line; printf "!define MAJOR_VER %d\n", $nmin; printf "!define MINOR_VER %d\n", $nmin; printf "!define SUBMINOR_VER %d\n", $nsmin; printf "!define PATCHLEVEL_VER %d\n", $nplvl; + if (defined($snapshot)) { + printf "!define SNAPSHOT_VER=%d\n", $snapshot; + } } elsif ( $what eq 'id' ) { print $nasm_id, "\n"; # Print ID in decimal } elsif ( $what eq 'xid' ) { From 02042dae1c4242f3b096e743c95d98647de6e87d Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 2 Oct 2025 13:50:38 -0700 Subject: [PATCH 14/15] nasmtok.el: use ${file} to end, to match the start Use ${file} in both places, in case someone uses a different output filename for some reason. Signed-off-by: H. Peter Anvin (Intel) --- editors/nasmtok.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editors/nasmtok.pl b/editors/nasmtok.pl index 274b2043..b9755752 100755 --- a/editors/nasmtok.pl +++ b/editors/nasmtok.pl @@ -331,7 +331,7 @@ sub write_output_el { # Footer print $out "\n(provide 'nasmtok)\n"; - print $out ";;; nasmtok.el ends here\n"; + print $out ";;; ${file} ends here\n"; return 0; } From c6c67f30115b38d6f6a43cc33f296bfe1c917ede Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 2 Oct 2025 13:57:15 -0700 Subject: [PATCH 15/15] editors: add explicit special case handing The automatic extraction procedure can only do so much. At some point it is simpler to add explicit special case handling. Signed-off-by: H. Peter Anvin (Intel) --- editors/nasmtok.pl | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/editors/nasmtok.pl b/editors/nasmtok.pl index b9755752..d77ef9c3 100755 --- a/editors/nasmtok.pl +++ b/editors/nasmtok.pl @@ -78,13 +78,15 @@ my %override = ( 'wrt' => 'special', 'times' => 'special'); -sub addtoken($$) { - my($type, $token) = @_; +sub addtoken($@) { + my $type = shift @_; - unless (defined($token_category{$token})) { - $type = $override{$type} if (defined($override{$type})); - xpush(\$tokens{$type}, $token); - $token_category{$token} = $type; + foreach my $token (@_) { + unless (defined($token_category{$token})) { + $type = $override{$type} if (defined($override{$type})); + xpush(\$tokens{$type}, $token); + $token_category{$token} = $type; + } } } @@ -230,6 +232,14 @@ sub read_macros(@) { } } +# Handle special tokens which may not have been picked up by the automatic +# process, because they depend on the build parameters, or are buried +# deep in C code... +sub add_special_cases() { + # Not defined in non-snapshot builds + addtoken('smacro', '__NASM_SNAPSHOT__', '__?NASM_SNAPSHOT?__'); +} + sub make_lines($$@) { my $maxline = shift @_; my $indent = shift @_; @@ -361,6 +371,7 @@ sub write_output($$) { } } +add_special_cases(); read_tokhash_c('asm/tokhash.c'); read_pptok_c('asm/pptok.c'); read_directiv_dat('asm/directiv.dat');