Merge branch 'nasm-2.08.xx'
authorH. Peter Anvin <hpa@zytor.com>
Fri, 16 Jul 2010 05:45:04 +0000 (22:45 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 16 Jul 2010 05:45:04 +0000 (22:45 -0700)
Resolved Conflicts:
version

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
59 files changed:
.gitignore
Makefile.in
Mkfiles/msvc.mak
Mkfiles/netware.mak
Mkfiles/openwcom.mak
Mkfiles/owlinux.mak
assemble.c
directiv.dat [moved from directives.dat with 99% similarity]
directiv.pl [moved from directives.pl with 84% similarity]
doc/Makefile.in
doc/changes.src
doc/nasmdoc.src
headers/c
headers/doc
headers/mac
headers/perl
ilog2.c [new file with mode: 0644]
insns.dat
labels.c
lib/vsnprintf.c
listing.c
macros/fp.mac [new file with mode: 0644]
macros/smartalign.mac
nasm.c
nasm.h
nasmlib.c
nasmlib.h
output/elf.h
output/nullout.c
output/outaout.c
output/outas86.c
output/outbin.c
output/outcoff.c
output/outdbg.c
output/outelf.c
output/outelf.h
output/outelf32.c
output/outelf64.c
output/outform.c
output/outform.h
output/outieee.c
output/outlib.c
output/outlib.h
output/outmac32.c [moved from output/outmacho32.c with 97% similarity]
output/outmac64.c [moved from output/outmacho64.c with 98% similarity]
output/outobj.c
output/outrdf2.c
output/pecoff.h [new file with mode: 0644]
pptok.dat
preproc.c
standard.mac
test/br2496848.asm [new file with mode: 0644]
test/br3005117.asm [new file with mode: 0644]
test/br3026808.asm [new file with mode: 0644]
test/br3028880.asm [new file with mode: 0644]
test/lwp.asm [new file with mode: 0644]
test/newrdwr.asm [new file with mode: 0644]
test/paste.asm [new file with mode: 0644]
version

index 26f905d..f812e77 100644 (file)
@@ -19,8 +19,8 @@
 /config.log
 /config.status
 /configure
-/directives.c
-/directives.h
+/directiv.c
+/directiv.h
 /doc/*.dip
 /doc/*.hpj
 /doc/*.pdf
index 21e193b..ed93b44 100644 (file)
@@ -62,17 +62,18 @@ X               = @EXEEXT@
 NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
        raa.$(O) saa.$(O) rbtree.$(O) \
        float.$(O) insnsa.$(O) insnsb.$(O) \
-       directives.$(O) \
+       directiv.$(O) \
        assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
        output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \
        output/nullout.$(O) \
        output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) \
        output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \
        output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
-       output/outdbg.$(O) output/outieee.$(O) output/outmacho32.$(O) \
-       output/outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
+       output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) \
+       output/outmac64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
        macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \
        strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \
+       ilog2.$(O) \
        lib/strlcpy.$(O)
 
 NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
@@ -159,17 +160,17 @@ pptok.ph: pptok.dat pptok.pl perllib/phash.ph
        $(PERL) $(srcdir)/pptok.pl ph $(srcdir)/pptok.dat pptok.ph
 
 # Directives hash
-directives.h: directives.dat directives.pl perllib/phash.ph
-       $(PERL) $(srcdir)/directives.pl h $(srcdir)/directives.dat directives.h
-directives.c: directives.dat directives.pl perllib/phash.ph
-       $(PERL) $(srcdir)/directives.pl c $(srcdir)/directives.dat directives.c
+directiv.h: directiv.dat directiv.pl perllib/phash.ph
+       $(PERL) $(srcdir)/directiv.pl h $(srcdir)/directiv.dat directiv.h
+directiv.c: directiv.dat directiv.pl perllib/phash.ph
+       $(PERL) $(srcdir)/directiv.pl c $(srcdir)/directiv.dat directiv.c
 
 # This target generates all files that require perl.
 # This allows easier generation of distribution (see dist target).
 PERLREQ = macros.c insnsb.c insnsa.c insnsd.c insnsi.h insnsn.c \
          regs.c regs.h regflags.c regdis.c regdis.h regvals.c \
          tokhash.c tokens.h pptok.h pptok.c pptok.ph \
-         directives.c directives.h \
+         directiv.c directiv.h \
          version.h version.mac version.mak version.nsh
 perlreq: $(PERLREQ)
 
@@ -183,6 +184,7 @@ install: nasm$(X) ndisasm$(X)
 
 clean:
        $(RM) -f *.$(O) *.s *.i
+       $(RM) -f lib/*.$(O) lib/*.s lib/*.i
        $(RM) -f output/*.$(O) output/*.s output/*.i
        $(RM) -f nasm$(X) ndisasm$(X)
        cd rdoff && $(MAKE) clean
@@ -254,125 +256,124 @@ alldeps: perlreq
 # @object-ending: ".$(O)"
 # @path-separator: "/"
 #-- Everything below is generated by mkdep.pl - do not edit --#
-assemble.$(O): assemble.c assemble.h compiler.h config.h directives.h \
- insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h \
- tables.h tokens.h
+assemble.$(O): assemble.c assemble.h compiler.h config.h directiv.h insns.h \
+ insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h \
+ tokens.h
 crc64.$(O): crc64.c compiler.h config.h nasmlib.h
-directives.$(O): directives.c compiler.h config.h directives.h hashtbl.h \
insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-disasm.$(O): disasm.c compiler.h config.h directives.h disasm.h insns.h \
+directiv.$(O): directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
+disasm.$(O): disasm.c compiler.h config.h directiv.h disasm.h insns.h \
  insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regdis.h regs.h \
  sync.h tables.h tokens.h
-eval.$(O): eval.c compiler.h config.h directives.h eval.h float.h insnsi.h \
+eval.$(O): eval.c compiler.h config.h directiv.h eval.h float.h insnsi.h \
  labels.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-exprlib.$(O): exprlib.c compiler.h config.h directives.h insnsi.h nasm.h \
+exprlib.$(O): exprlib.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-float.$(O): float.c compiler.h config.h directives.h float.h insnsi.h nasm.h \
+float.$(O): float.c compiler.h config.h directiv.h float.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-hashtbl.$(O): hashtbl.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+hashtbl.$(O): hashtbl.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-insnsa.$(O): insnsa.c compiler.h config.h directives.h insns.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-insnsb.$(O): insnsb.c compiler.h config.h directives.h insns.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-insnsd.$(O): insnsd.c compiler.h config.h directives.h insns.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
+ilog2.$(O): ilog2.c compiler.h config.h nasmlib.h
+insnsa.$(O): insnsa.c compiler.h config.h directiv.h insns.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
+insnsb.$(O): insnsb.c compiler.h config.h directiv.h insns.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
+insnsd.$(O): insnsd.c compiler.h config.h directiv.h insns.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
 insnsn.$(O): insnsn.c compiler.h config.h insnsi.h opflags.h tables.h
-labels.$(O): labels.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+labels.$(O): labels.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
 lib/snprintf.$(O): lib/snprintf.c compiler.h config.h nasmlib.h
 lib/strlcpy.$(O): lib/strlcpy.c compiler.h config.h
 lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h config.h nasmlib.h
-listing.$(O): listing.c compiler.h config.h directives.h insnsi.h listing.h \
+listing.$(O): listing.c compiler.h config.h directiv.h insnsi.h listing.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-macros.$(O): macros.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+macros.$(O): macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h \
  tables.h
-nasm.$(O): nasm.c assemble.h compiler.h config.h directives.h eval.h float.h \
+nasm.$(O): nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h \
  insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h \
  output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \
  tokens.h
-nasmlib.$(O): nasmlib.c compiler.h config.h directives.h insns.h insnsi.h \
+nasmlib.$(O): nasmlib.c compiler.h config.h directiv.h insns.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-ndisasm.$(O): ndisasm.c compiler.h config.h directives.h disasm.h insns.h \
+ndisasm.$(O): ndisasm.c compiler.h config.h directiv.h disasm.h insns.h \
  insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h sync.h \
  tokens.h
-output/nulldbg.$(O): output/nulldbg.c compiler.h config.h directives.h \
+output/nulldbg.$(O): output/nulldbg.c compiler.h config.h directiv.h \
  insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-output/nullout.$(O): output/nullout.c compiler.h config.h directives.h \
+output/nullout.$(O): output/nullout.c compiler.h config.h directiv.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h \
  regs.h
-output/outaout.$(O): output/outaout.c compiler.h config.h directives.h \
eval.h insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
+output/outaout.$(O): output/outaout.c compiler.h config.h directiv.h eval.h \
+ insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h raa.h regs.h saa.h stdscan.h
-output/outas86.$(O): output/outas86.c compiler.h config.h directives.h \
+output/outas86.$(O): output/outas86.c compiler.h config.h directiv.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h raa.h regs.h saa.h
-output/outbin.$(O): output/outbin.c compiler.h config.h directives.h eval.h \
+output/outbin.$(O): output/outbin.c compiler.h config.h directiv.h eval.h \
  insnsi.h labels.h nasm.h nasmlib.h opflags.h output/outform.h \
  output/outlib.h pptok.h preproc.h regs.h saa.h stdscan.h
-output/outcoff.$(O): output/outcoff.c compiler.h config.h directives.h \
- eval.h insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
- pptok.h preproc.h raa.h regs.h saa.h
-output/outdbg.$(O): output/outdbg.c compiler.h config.h directives.h \
- insnsi.h nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h \
- regs.h
-output/outelf.$(O): output/outelf.c compiler.h config.h directives.h \
- insnsi.h nasm.h nasmlib.h opflags.h output/dwarf.h output/elf.h \
- output/outelf.h output/outform.h pptok.h preproc.h regs.h
-output/outelf32.$(O): output/outelf32.c compiler.h config.h directives.h \
+output/outcoff.$(O): output/outcoff.c compiler.h config.h directiv.h eval.h \
+ insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
+ output/pecoff.h pptok.h preproc.h raa.h regs.h saa.h
+output/outdbg.$(O): output/outdbg.c compiler.h config.h directiv.h insnsi.h \
+ nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h
+output/outelf.$(O): output/outelf.c compiler.h config.h directiv.h insnsi.h \
+ nasm.h nasmlib.h opflags.h output/dwarf.h output/elf.h output/outelf.h \
+ output/outform.h pptok.h preproc.h regs.h
+output/outelf32.$(O): output/outelf32.c compiler.h config.h directiv.h \
  eval.h insnsi.h nasm.h nasmlib.h opflags.h output/dwarf.h output/elf.h \
- output/outelf.h output/outform.h output/stabs.h output/outlib.h pptok.h \
+ output/outelf.h output/outform.h output/outlib.h output/stabs.h pptok.h \
  preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-output/outelf64.$(O): output/outelf64.c compiler.h config.h directives.h \
+output/outelf64.$(O): output/outelf64.c compiler.h config.h directiv.h \
  eval.h insnsi.h nasm.h nasmlib.h opflags.h output/dwarf.h output/elf.h \
- output/outelf.h output/outform.h output/stabs.h output/outlib.h pptok.h \
+ output/outelf.h output/outform.h output/outlib.h output/stabs.h pptok.h \
  preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-output/outform.$(O): output/outform.c compiler.h config.h directives.h \
+output/outform.$(O): output/outform.c compiler.h config.h directiv.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h \
  regs.h
-output/outieee.$(O): output/outieee.c compiler.h config.h directives.h \
+output/outieee.$(O): output/outieee.c compiler.h config.h directiv.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h regs.h
-output/outlib.$(O): output/outlib.c compiler.h config.h directives.h \
- insnsi.h nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h \
- regs.h
-output/outmacho32.$(O): output/outmacho32.c compiler.h config.h directives.h \
+output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h \
+ nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h
+output/outmac32.$(O): output/outmac32.c compiler.h config.h directiv.h \
  eval.h insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h raa.h regs.h saa.h
-output/outmacho64.$(O): output/outmacho64.c compiler.h config.h directives.h \
+output/outmac64.$(O): output/outmac64.c compiler.h config.h directiv.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h raa.h regs.h saa.h
-output/outobj.$(O): output/outobj.c compiler.h config.h directives.h eval.h \
+output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h regs.h stdscan.h
-output/outrdf2.$(O): output/outrdf2.c compiler.h config.h directives.h \
+output/outrdf2.$(O): output/outrdf2.c compiler.h config.h directiv.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h rdoff/rdoff.h regs.h saa.h
-parser.$(O): parser.c compiler.h config.h directives.h eval.h float.h \
- insns.h insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h preproc.h \
regs.h stdscan.h tables.h tokens.h
+parser.$(O): parser.c compiler.h config.h directiv.h eval.h float.h insns.h \
+ insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h preproc.h regs.h \
+ stdscan.h tables.h tokens.h
 pptok.$(O): pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h \
  preproc.h
-preproc.$(O): preproc.c compiler.h config.h directives.h eval.h hashtbl.h \
+preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \
  insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h \
  stdscan.h tables.h tokens.h
 quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h
 raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h
 rbtree.$(O): rbtree.c compiler.h config.h rbtree.h
 regdis.$(O): regdis.c regdis.h regs.h
-regflags.$(O): regflags.c compiler.h config.h directives.h insnsi.h nasm.h \
+regflags.$(O): regflags.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
 regs.$(O): regs.c compiler.h config.h insnsi.h opflags.h tables.h
 regvals.$(O): regvals.c compiler.h config.h insnsi.h opflags.h tables.h
 saa.$(O): saa.c compiler.h config.h nasmlib.h saa.h
-stdscan.$(O): stdscan.c compiler.h config.h directives.h insns.h insnsi.h \
+stdscan.$(O): stdscan.c compiler.h config.h directiv.h insns.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h \
  tokens.h
-strfunc.$(O): strfunc.c compiler.h config.h directives.h insnsi.h nasm.h \
+strfunc.$(O): strfunc.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
 sync.$(O): sync.c compiler.h config.h nasmlib.h sync.h
-tokhash.$(O): tokhash.c compiler.h config.h directives.h hashtbl.h insns.h \
+tokhash.$(O): tokhash.c compiler.h config.h directiv.h hashtbl.h insns.h \
  insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-ver.$(O): ver.c compiler.h config.h directives.h insnsi.h nasm.h nasmlib.h \
+ver.$(O): ver.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \
  opflags.h pptok.h preproc.h regs.h version.h
index 7bb1cfd..f0aeaa9 100644 (file)
@@ -37,17 +37,18 @@ X               = .exe
 NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
        raa.$(O) saa.$(O) rbtree.$(O) \
        float.$(O) insnsa.$(O) insnsb.$(O) \
-       directives.$(O) \
+       directiv.$(O) \
        assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
        output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \
        output/nullout.$(O) \
        output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) \
        output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \
        output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
-       output/outdbg.$(O) output/outieee.$(O) output/outmacho32.$(O) \
-       output/outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
+       output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) \
+       output/outmac64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
        macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \
        strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \
+       ilog2.$(O) \
        lib/strlcpy.$(O)
 
 NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
@@ -134,6 +135,9 @@ clean:
        -del /f *.$(O)
        -del /f *.s
        -del /f *.i
+       -del /f lib\*.$(O)
+       -del /f lib\*.s
+       -del /f lib\*.i
        -del /f output\*.$(O)
        -del /f output\*.s
        -del /f output\*.i
@@ -185,116 +189,116 @@ everything: all doc rdf
 # @path-separator: "/"
 # @exclude: "config.h"
 #-- Everything below is generated by mkdep.pl - do not edit --#
-assemble.$(O): assemble.c assemble.h compiler.h directives.h insns.h \
- insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h \
- tokens.h
+assemble.$(O): assemble.c assemble.h compiler.h directiv.h insns.h insnsi.h \
+ nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h tokens.h
 crc64.$(O): crc64.c compiler.h nasmlib.h
-directives.$(O): directives.c compiler.h directives.h hashtbl.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-disasm.$(O): disasm.c compiler.h directives.h disasm.h insns.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regdis.h regs.h sync.h \
- tables.h tokens.h
-eval.$(O): eval.c compiler.h directives.h eval.h float.h insnsi.h labels.h \
+directiv.$(O): directiv.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regs.h
+disasm.$(O): disasm.c compiler.h directiv.h disasm.h insns.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regdis.h regs.h sync.h tables.h \
+ tokens.h
+eval.$(O): eval.c compiler.h directiv.h eval.h float.h insnsi.h labels.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-exprlib.$(O): exprlib.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
+exprlib.$(O): exprlib.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \
  opflags.h pptok.h preproc.h regs.h
-float.$(O): float.c compiler.h directives.h float.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h
-hashtbl.$(O): hashtbl.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
+float.$(O): float.c compiler.h directiv.h float.h insnsi.h nasm.h nasmlib.h \
+ opflags.h pptok.h preproc.h regs.h
+hashtbl.$(O): hashtbl.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-insnsa.$(O): insnsa.c compiler.h directives.h insns.h insnsi.h nasm.h \
+ilog2.$(O): ilog2.c compiler.h nasmlib.h
+insnsa.$(O): insnsa.c compiler.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-insnsb.$(O): insnsb.c compiler.h directives.h insns.h insnsi.h nasm.h \
+insnsb.$(O): insnsb.c compiler.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-insnsd.$(O): insnsd.c compiler.h directives.h insns.h insnsi.h nasm.h \
+insnsd.$(O): insnsd.c compiler.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
 insnsn.$(O): insnsn.c compiler.h insnsi.h opflags.h tables.h
-labels.$(O): labels.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
+labels.$(O): labels.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
 lib/snprintf.$(O): lib/snprintf.c compiler.h nasmlib.h
 lib/strlcpy.$(O): lib/strlcpy.c compiler.h
 lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h nasmlib.h
-listing.$(O): listing.c compiler.h directives.h insnsi.h listing.h nasm.h \
+listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-macros.$(O): macros.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
+macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h tables.h
-nasm.$(O): nasm.c assemble.h compiler.h directives.h eval.h float.h insns.h \
+nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h insns.h \
  insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h output/outform.h \
  parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h tokens.h
-nasmlib.$(O): nasmlib.c compiler.h directives.h insns.h insnsi.h nasm.h \
+nasmlib.$(O): nasmlib.c compiler.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-ndisasm.$(O): ndisasm.c compiler.h directives.h disasm.h insns.h insnsi.h \
+ndisasm.$(O): ndisasm.c compiler.h directiv.h disasm.h insns.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h sync.h tokens.h
-output/nulldbg.$(O): output/nulldbg.c compiler.h directives.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-output/nullout.$(O): output/nullout.c compiler.h directives.h insnsi.h \
- nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h
-output/outaout.$(O): output/outaout.c compiler.h directives.h eval.h \
- insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
- pptok.h preproc.h raa.h regs.h saa.h stdscan.h
-output/outas86.$(O): output/outas86.c compiler.h directives.h insnsi.h \
+output/nulldbg.$(O): output/nulldbg.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regs.h
+output/nullout.$(O): output/nullout.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h
+output/outaout.$(O): output/outaout.c compiler.h directiv.h eval.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
- preproc.h raa.h regs.h saa.h
-output/outbin.$(O): output/outbin.c compiler.h directives.h eval.h insnsi.h \
+ preproc.h raa.h regs.h saa.h stdscan.h
+output/outas86.$(O): output/outas86.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h preproc.h \
+ raa.h regs.h saa.h
+output/outbin.$(O): output/outbin.c compiler.h directiv.h eval.h insnsi.h \
  labels.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h regs.h saa.h stdscan.h
-output/outcoff.$(O): output/outcoff.c compiler.h directives.h eval.h \
insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
+output/outcoff.$(O): output/outcoff.c compiler.h directiv.h eval.h insnsi.h \
nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h output/pecoff.h \
  pptok.h preproc.h raa.h regs.h saa.h
-output/outdbg.$(O): output/outdbg.c compiler.h directives.h insnsi.h nasm.h \
+output/outdbg.$(O): output/outdbg.c compiler.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h
-output/outelf.$(O): output/outelf.c compiler.h directives.h insnsi.h nasm.h \
+output/outelf.$(O): output/outelf.c compiler.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/dwarf.h output/elf.h output/outelf.h \
  output/outform.h pptok.h preproc.h regs.h
-output/outelf32.$(O): output/outelf32.c compiler.h directives.h eval.h \
+output/outelf32.$(O): output/outelf32.c compiler.h directiv.h eval.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/dwarf.h output/elf.h \
  output/outelf.h output/outform.h output/outlib.h output/stabs.h pptok.h \
  preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-output/outelf64.$(O): output/outelf64.c compiler.h directives.h eval.h \
+output/outelf64.$(O): output/outelf64.c compiler.h directiv.h eval.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/dwarf.h output/elf.h \
  output/outelf.h output/outform.h output/outlib.h output/stabs.h pptok.h \
  preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-output/outform.$(O): output/outform.c compiler.h directives.h insnsi.h \
- nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h
-output/outieee.$(O): output/outieee.c compiler.h directives.h insnsi.h \
- nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
preproc.h regs.h
-output/outlib.$(O): output/outlib.c compiler.h directives.h insnsi.h nasm.h \
+output/outform.$(O): output/outform.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h
+output/outieee.$(O): output/outieee.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h preproc.h \
+ regs.h
+output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h
-output/outmacho32.$(O): output/outmacho32.c compiler.h directives.h eval.h \
+output/outmac32.$(O): output/outmac32.c compiler.h directiv.h eval.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h raa.h regs.h saa.h
-output/outmacho64.$(O): output/outmacho64.c compiler.h directives.h insnsi.h \
+output/outmac64.$(O): output/outmac64.c compiler.h directiv.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
  preproc.h raa.h regs.h saa.h
-output/outobj.$(O): output/outobj.c compiler.h directives.h eval.h insnsi.h \
+output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
  preproc.h regs.h stdscan.h
-output/outrdf2.$(O): output/outrdf2.c compiler.h directives.h insnsi.h \
- nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
preproc.h rdoff/rdoff.h regs.h saa.h
-parser.$(O): parser.c compiler.h directives.h eval.h float.h insns.h \
insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h preproc.h regs.h \
stdscan.h tables.h tokens.h
+output/outrdf2.$(O): output/outrdf2.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h preproc.h \
+ rdoff/rdoff.h regs.h saa.h
+parser.$(O): parser.c compiler.h directiv.h eval.h float.h insns.h insnsi.h \
nasm.h nasmlib.h opflags.h parser.h pptok.h preproc.h regs.h stdscan.h \
+ tables.h tokens.h
 pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.$(O): preproc.c compiler.h directives.h eval.h hashtbl.h insnsi.h \
+preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h \
  tables.h tokens.h
 quote.$(O): quote.c compiler.h nasmlib.h quote.h
 raa.$(O): raa.c compiler.h nasmlib.h raa.h
 rbtree.$(O): rbtree.c compiler.h rbtree.h
 regdis.$(O): regdis.c regdis.h regs.h
-regflags.$(O): regflags.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
+regflags.$(O): regflags.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \
  opflags.h pptok.h preproc.h regs.h tables.h
 regs.$(O): regs.c compiler.h insnsi.h opflags.h tables.h
 regvals.$(O): regvals.c compiler.h insnsi.h opflags.h tables.h
 saa.$(O): saa.c compiler.h nasmlib.h saa.h
-stdscan.$(O): stdscan.c compiler.h directives.h insns.h insnsi.h nasm.h \
+stdscan.$(O): stdscan.c compiler.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
-strfunc.$(O): strfunc.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
+strfunc.$(O): strfunc.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \
  opflags.h pptok.h preproc.h regs.h
 sync.$(O): sync.c compiler.h nasmlib.h sync.h
-tokhash.$(O): tokhash.c compiler.h directives.h hashtbl.h insns.h insnsi.h \
+tokhash.$(O): tokhash.c compiler.h directiv.h hashtbl.h insns.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-ver.$(O): ver.c compiler.h directives.h insnsi.h nasm.h nasmlib.h opflags.h \
+ver.$(O): ver.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h opflags.h \
  pptok.h preproc.h regs.h version.h
index fbd19bf..bb8b715 100644 (file)
@@ -33,17 +33,18 @@ O = o
 NASM = nasm.o nasmlib.o ver.o \
        raa.o saa.o rbtree.o \
        float.o insnsa.o insnsb.o \
-       directives.o \
+       directiv.o \
        assemble.o labels.o hashtbl.o crc64.o parser.o \
        outform.o outlib.o nulldbg.o \
        nullout.o \
        outbin.o outaout.o outcoff.o \
        outelf.o outelf32.o outelf64.o \
        outobj.o outas86.o outrdf2.o \
-       outdbg.o outieee.o outmacho32.o \
-       outmacho64.o preproc.o quote.o pptok.o \
+       outdbg.o outieee.o outmac32.o \
+       outmac64.o preproc.o quote.o pptok.o \
        macros.o listing.o eval.o exprlib.o stdscan.o \
        strfunc.o tokhash.o regvals.o regflags.o \
+       ilog2.o \
        strlcpy.o
 
 NDISASM = ndisasm.o disasm.o sync.o nasmlib.o ver.o \
@@ -125,111 +126,110 @@ $(OBJDIR)/version.mak: $(PROOT)/version $(PROOT)/version.pl $(OBJDIR)
 # @path-separator: ""
 # @continuation: "\"
 #-- Everything below is generated by mkdep.pl - do not edit --#
-assemble.o: assemble.c assemble.h compiler.h config.h directives.h insns.h \
+assemble.o: assemble.c assemble.h compiler.h config.h directiv.h insns.h \
  insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h \
  tokens.h
 crc64.o: crc64.c compiler.h config.h nasmlib.h
-directives.o: directives.c compiler.h config.h directives.h hashtbl.h \
insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-disasm.o: disasm.c compiler.h config.h directives.h disasm.h insns.h \
insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regdis.h regs.h \
sync.h tables.h tokens.h
-eval.o: eval.c compiler.h config.h directives.h eval.h float.h insnsi.h \
+directiv.o: directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
+disasm.o: disasm.c compiler.h config.h directiv.h disasm.h insns.h insnsi.h \
nasm.h nasmlib.h opflags.h pptok.h preproc.h regdis.h regs.h sync.h \
+ tables.h tokens.h
+eval.o: eval.c compiler.h config.h directiv.h eval.h float.h insnsi.h \
  labels.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-exprlib.o: exprlib.c compiler.h config.h directives.h insnsi.h nasm.h \
+exprlib.o: exprlib.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-float.o: float.c compiler.h config.h directives.h float.h insnsi.h nasm.h \
+float.o: float.c compiler.h config.h directiv.h float.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-hashtbl.o: hashtbl.c compiler.h config.h directives.h hashtbl.h insnsi.h \
+hashtbl.o: hashtbl.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-insnsa.o: insnsa.c compiler.h config.h directives.h insns.h insnsi.h nasm.h \
+ilog2.o: ilog2.c compiler.h config.h nasmlib.h
+insnsa.o: insnsa.c compiler.h config.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-insnsb.o: insnsb.c compiler.h config.h directives.h insns.h insnsi.h nasm.h \
+insnsb.o: insnsb.c compiler.h config.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-insnsd.o: insnsd.c compiler.h config.h directives.h insns.h insnsi.h nasm.h \
+insnsd.o: insnsd.c compiler.h config.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
 insnsn.o: insnsn.c compiler.h config.h insnsi.h opflags.h tables.h
-labels.o: labels.c compiler.h config.h directives.h hashtbl.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
+labels.o: labels.c compiler.h config.h directiv.h hashtbl.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regs.h
 snprintf.o: snprintf.c compiler.h config.h nasmlib.h
 strlcpy.o: strlcpy.c compiler.h config.h
 vsnprintf.o: vsnprintf.c compiler.h config.h nasmlib.h
-listing.o: listing.c compiler.h config.h directives.h insnsi.h listing.h \
+listing.o: listing.c compiler.h config.h directiv.h insnsi.h listing.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-macros.o: macros.c compiler.h config.h directives.h hashtbl.h insnsi.h \
- nasm.h nasmlib.h opflags.h outform.h pptok.h preproc.h regs.h tables.h
-nasm.o: nasm.c assemble.h compiler.h config.h directives.h eval.h float.h \
+macros.o: macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h nasm.h \
+ nasmlib.h opflags.h outform.h pptok.h preproc.h regs.h tables.h
+nasm.o: nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h \
  insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h outform.h \
  parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h tokens.h
-nasmlib.o: nasmlib.c compiler.h config.h directives.h insns.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-ndisasm.o: ndisasm.c compiler.h config.h directives.h disasm.h insns.h \
+nasmlib.o: nasmlib.c compiler.h config.h directiv.h insns.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
+ndisasm.o: ndisasm.c compiler.h config.h directiv.h disasm.h insns.h \
  insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h sync.h \
  tokens.h
-nulldbg.o: nulldbg.c compiler.h config.h directives.h insnsi.h nasm.h \
+nulldbg.o: nulldbg.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-nullout.o: nullout.c compiler.h config.h directives.h insnsi.h nasm.h \
+nullout.o: nullout.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h outlib.h pptok.h preproc.h regs.h
-outaout.o: outaout.c compiler.h config.h directives.h eval.h insnsi.h nasm.h \
+outaout.o: outaout.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \
  nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h \
  stdscan.h
-outas86.o: outas86.c compiler.h config.h directives.h insnsi.h nasm.h \
+outas86.o: outas86.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h
-outbin.o: outbin.c compiler.h config.h directives.h eval.h insnsi.h labels.h \
+outbin.o: outbin.c compiler.h config.h directiv.h eval.h insnsi.h labels.h \
  nasm.h nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h regs.h \
  saa.h stdscan.h
-outcoff.o: outcoff.c compiler.h config.h directives.h eval.h insnsi.h nasm.h \
- nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h
-outdbg.o: outdbg.c compiler.h config.h directives.h insnsi.h nasm.h \
- nasmlib.h opflags.h outform.h pptok.h preproc.h regs.h
-outelf.o: outelf.c compiler.h config.h directives.h insnsi.h nasm.h \
- nasmlib.h opflags.h dwarf.h elf.h outelf.h outform.h pptok.h preproc.h \
- regs.h
-outelf32.o: outelf32.c compiler.h config.h directives.h eval.h insnsi.h \
- nasm.h nasmlib.h opflags.h dwarf.h elf.h outelf.h outform.h outlib.h \
stabs.h pptok.h preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-outelf64.o: outelf64.c compiler.h config.h directives.h eval.h insnsi.h \
- nasm.h nasmlib.h opflags.h dwarf.h elf.h outelf.h outform.h outlib.h \
stabs.h pptok.h preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-outform.o: outform.c compiler.h config.h directives.h insnsi.h nasm.h \
+outcoff.o: outcoff.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \
+ nasmlib.h opflags.h outform.h outlib.h pecoff.h pptok.h preproc.h raa.h \
+ regs.h saa.h
+outdbg.o: outdbg.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \
+ opflags.h outform.h pptok.h preproc.h regs.h
+outelf.o: outelf.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \
opflags.h dwarf.h elf.h outelf.h outform.h pptok.h preproc.h regs.h
+outelf32.o: outelf32.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \
+ nasmlib.h opflags.h dwarf.h elf.h outelf.h outform.h outlib.h stabs.h \
+ pptok.h preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
+outelf64.o: outelf64.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \
+ nasmlib.h opflags.h dwarf.h elf.h outelf.h outform.h outlib.h stabs.h \
+ pptok.h preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
+outform.o: outform.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h outform.h pptok.h preproc.h regs.h
-outieee.o: outieee.c compiler.h config.h directives.h insnsi.h nasm.h \
+outieee.o: outieee.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h regs.h
-outlib.o: outlib.c compiler.h config.h directives.h insnsi.h nasm.h \
- nasmlib.h opflags.h outlib.h pptok.h preproc.h regs.h
-outmacho32.o: outmacho32.c compiler.h config.h directives.h eval.h insnsi.h \
- nasm.h nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h \
- regs.h saa.h
-outmacho64.o: outmacho64.c compiler.h config.h directives.h insnsi.h nasm.h \
+outlib.o: outlib.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \
+ opflags.h outlib.h pptok.h preproc.h regs.h
+outmac32.o: outmac32.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \
  nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h
-outobj.o: outobj.c compiler.h config.h directives.h eval.h insnsi.h nasm.h \
+outmac64.o: outmac64.c compiler.h config.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h
+outobj.o: outobj.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \
  nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h regs.h stdscan.h
-outrdf2.o: outrdf2.c compiler.h config.h directives.h insnsi.h nasm.h \
+outrdf2.o: outrdf2.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h rdoff.h regs.h \
  saa.h
-parser.o: parser.c compiler.h config.h directives.h eval.h float.h insns.h \
+parser.o: parser.c compiler.h config.h directiv.h eval.h float.h insns.h \
  insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h preproc.h regs.h \
  stdscan.h tables.h tokens.h
 pptok.o: pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.o: preproc.c compiler.h config.h directives.h eval.h hashtbl.h \
+preproc.o: preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \
  insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h \
  stdscan.h tables.h tokens.h
 quote.o: quote.c compiler.h config.h nasmlib.h quote.h
 raa.o: raa.c compiler.h config.h nasmlib.h raa.h
 rbtree.o: rbtree.c compiler.h config.h rbtree.h
 regdis.o: regdis.c regdis.h regs.h
-regflags.o: regflags.c compiler.h config.h directives.h insnsi.h nasm.h \
+regflags.o: regflags.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
 regs.o: regs.c compiler.h config.h insnsi.h opflags.h tables.h
 regvals.o: regvals.c compiler.h config.h insnsi.h opflags.h tables.h
 saa.o: saa.c compiler.h config.h nasmlib.h saa.h
-stdscan.o: stdscan.c compiler.h config.h directives.h insns.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h \
- tokens.h
-strfunc.o: strfunc.c compiler.h config.h directives.h insnsi.h nasm.h \
+stdscan.o: stdscan.c compiler.h config.h directiv.h insns.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
+strfunc.o: strfunc.c compiler.h config.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
 sync.o: sync.c compiler.h config.h nasmlib.h sync.h
-tokhash.o: tokhash.c compiler.h config.h directives.h hashtbl.h insns.h \
+tokhash.o: tokhash.c compiler.h config.h directiv.h hashtbl.h insns.h \
  insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-ver.o: ver.c compiler.h config.h directives.h insnsi.h nasm.h nasmlib.h \
+ver.o: ver.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \
  opflags.h pptok.h preproc.h regs.h version.h
index 32a67c4..6dd2293 100644 (file)
@@ -49,17 +49,18 @@ X               = .exe
 NASM = nasm.$(O) nasmlib.$(O) ver.$(O) &
        raa.$(O) saa.$(O) rbtree.$(O) &
        float.$(O) insnsa.$(O) insnsb.$(O) &
-       directives.$(O) &
+       directiv.$(O) &
        assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) &
        output\outform.$(O) output\outlib.$(O) output\nulldbg.$(O) &
        output\nullout.$(O) &
        output\outbin.$(O) output\outaout.$(O) output\outcoff.$(O) &
        output\outelf.$(O) output\outelf32.$(O) output\outelf64.$(O) &
        output\outobj.$(O) output\outas86.$(O) output\outrdf2.$(O) &
-       output\outdbg.$(O) output\outieee.$(O) output\outmacho32.$(O) &
-       output\outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) &
+       output\outdbg.$(O) output\outieee.$(O) output\outmac32.$(O) &
+       output\outmac64.$(O) preproc.$(O) quote.$(O) pptok.$(O) &
        macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) &
        strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) &
+       ilog2.$(O) &
        lib\strlcpy.$(O)
 
 NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) &
@@ -158,42 +159,45 @@ PERLREQ = macros.c insnsb.c insnsa.c insnsd.c insnsi.h insnsn.c &
 perlreq: $(PERLREQ)
 
 clean: .SYMBOLIC
-       -del /f *.$(O)
-       -del /f *.s
-       -del /f *.i
-       -del /f output\*.$(O)
-       -del /f output\*.s
-       -del /f output\*.i
-       -del /f nasm$(X)
-       -del /f ndisasm$(X)
+       -del *.$(O)
+       -del *.s
+       -del *.i
+       -del lib\*.$(O)
+       -del lib\*.s
+       -del lib\*.i
+       -del output\*.$(O)
+       -del output\*.s
+       -del output\*.i
+       -del nasm$(X)
+       -del ndisasm$(X)
        rem cd rdoff && $(MAKE) clean
 
 distclean: clean .SYMBOLIC
-       -del /f config.h
-       -del /f config.log
-       -del /f config.status
-       -del /f Makefile
-       -del /f *~
-       -del /f *.bak
-       -del /f *.lst
-       -del /f *.bin
-       -del /f output\*~
-       -del /f output\*.bak
-       -del /f test\*.lst
-       -del /f test\*.bin
-       -del /f test\*.$(O)
-       -del /f test\*.bin
-       -del /f/s autom4te*.cache
+       -del config.h
+       -del config.log
+       -del config.status
+       -del Makefile
+       -del *~
+       -del *.bak
+       -del *.lst
+       -del *.bin
+       -del output\*~
+       -del output\*.bak
+       -del test\*.lst
+       -del test\*.bin
+       -del test\*.$(O)
+       -del test\*.bin
+       -del /s autom4te*.cache
        rem cd rdoff && $(MAKE) distclean
 
 cleaner: clean .SYMBOLIC
-       -del /f $(PERLREQ)
-       -del /f *.man
-       -del /f nasm.spec
+       -del $(PERLREQ)
+       -del *.man
+       -del nasm.spec
        rem cd doc && $(MAKE) clean
 
 spotless: distclean cleaner .SYMBOLIC
-       -del /f doc\Makefile
+       -del doc\Makefile
        -del doc\*~
        -del doc\*.bak
 
@@ -214,116 +218,116 @@ everything: all doc rdf
 # @exclude: "config.h"
 # @continuation: "&"
 #-- Everything below is generated by mkdep.pl - do not edit --#
-assemble.$(O): assemble.c assemble.h compiler.h directives.h insns.h &
- insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h &
- tokens.h
+assemble.$(O): assemble.c assemble.h compiler.h directiv.h insns.h insnsi.h &
+ nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h tokens.h
 crc64.$(O): crc64.c compiler.h nasmlib.h
-directives.$(O): directives.c compiler.h directives.h hashtbl.h insnsi.h &
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-disasm.$(O): disasm.c compiler.h directives.h disasm.h insns.h insnsi.h &
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regdis.h regs.h sync.h &
- tables.h tokens.h
-eval.$(O): eval.c compiler.h directives.h eval.h float.h insnsi.h labels.h &
+directiv.$(O): directiv.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h &
+ nasmlib.h opflags.h pptok.h preproc.h regs.h
+disasm.$(O): disasm.c compiler.h directiv.h disasm.h insns.h insnsi.h nasm.h &
+ nasmlib.h opflags.h pptok.h preproc.h regdis.h regs.h sync.h tables.h &
+ tokens.h
+eval.$(O): eval.c compiler.h directiv.h eval.h float.h insnsi.h labels.h &
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-exprlib.$(O): exprlib.c compiler.h directives.h insnsi.h nasm.h nasmlib.h &
+exprlib.$(O): exprlib.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h &
  opflags.h pptok.h preproc.h regs.h
-float.$(O): float.c compiler.h directives.h float.h insnsi.h nasm.h &
nasmlib.h opflags.h pptok.h preproc.h regs.h
-hashtbl.$(O): hashtbl.c compiler.h directives.h hashtbl.h insnsi.h nasm.h &
+float.$(O): float.c compiler.h directiv.h float.h insnsi.h nasm.h nasmlib.h &
+ opflags.h pptok.h preproc.h regs.h
+hashtbl.$(O): hashtbl.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h &
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-insnsa.$(O): insnsa.c compiler.h directives.h insns.h insnsi.h nasm.h &
+ilog2.$(O): ilog2.c compiler.h nasmlib.h
+insnsa.$(O): insnsa.c compiler.h directiv.h insns.h insnsi.h nasm.h &
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-insnsb.$(O): insnsb.c compiler.h directives.h insns.h insnsi.h nasm.h &
+insnsb.$(O): insnsb.c compiler.h directiv.h insns.h insnsi.h nasm.h &
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-insnsd.$(O): insnsd.c compiler.h directives.h insns.h insnsi.h nasm.h &
+insnsd.$(O): insnsd.c compiler.h directiv.h insns.h insnsi.h nasm.h &
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
 insnsn.$(O): insnsn.c compiler.h insnsi.h opflags.h tables.h
-labels.$(O): labels.c compiler.h directives.h hashtbl.h insnsi.h nasm.h &
+labels.$(O): labels.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h &
  nasmlib.h opflags.h pptok.h preproc.h regs.h
 lib\snprintf.$(O): lib\snprintf.c compiler.h nasmlib.h
 lib\strlcpy.$(O): lib\strlcpy.c compiler.h
 lib\vsnprintf.$(O): lib\vsnprintf.c compiler.h nasmlib.h
-listing.$(O): listing.c compiler.h directives.h insnsi.h listing.h nasm.h &
+listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h &
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-macros.$(O): macros.c compiler.h directives.h hashtbl.h insnsi.h nasm.h &
+macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h &
  nasmlib.h opflags.h output\outform.h pptok.h preproc.h regs.h tables.h
-nasm.$(O): nasm.c assemble.h compiler.h directives.h eval.h float.h insns.h &
+nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h insns.h &
  insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h output\outform.h &
  parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h tokens.h
-nasmlib.$(O): nasmlib.c compiler.h directives.h insns.h insnsi.h nasm.h &
+nasmlib.$(O): nasmlib.c compiler.h directiv.h insns.h insnsi.h nasm.h &
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-ndisasm.$(O): ndisasm.c compiler.h directives.h disasm.h insns.h insnsi.h &
+ndisasm.$(O): ndisasm.c compiler.h directiv.h disasm.h insns.h insnsi.h &
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h sync.h tokens.h
-output\nulldbg.$(O): output\nulldbg.c compiler.h directives.h insnsi.h &
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-output\nullout.$(O): output\nullout.c compiler.h directives.h insnsi.h &
- nasm.h nasmlib.h opflags.h output\outlib.h pptok.h preproc.h regs.h
-output\outaout.$(O): output\outaout.c compiler.h directives.h eval.h &
- insnsi.h nasm.h nasmlib.h opflags.h output\outform.h output\outlib.h &
- pptok.h preproc.h raa.h regs.h saa.h stdscan.h
-output\outas86.$(O): output\outas86.c compiler.h directives.h insnsi.h &
+output\nulldbg.$(O): output\nulldbg.c compiler.h directiv.h insnsi.h nasm.h &
+ nasmlib.h opflags.h pptok.h preproc.h regs.h
+output\nullout.$(O): output\nullout.c compiler.h directiv.h insnsi.h nasm.h &
+ nasmlib.h opflags.h output\outlib.h pptok.h preproc.h regs.h
+output\outaout.$(O): output\outaout.c compiler.h directiv.h eval.h insnsi.h &
  nasm.h nasmlib.h opflags.h output\outform.h output\outlib.h pptok.h &
- preproc.h raa.h regs.h saa.h
-output\outbin.$(O): output\outbin.c compiler.h directives.h eval.h insnsi.h &
+ preproc.h raa.h regs.h saa.h stdscan.h
+output\outas86.$(O): output\outas86.c compiler.h directiv.h insnsi.h nasm.h &
+ nasmlib.h opflags.h output\outform.h output\outlib.h pptok.h preproc.h &
+ raa.h regs.h saa.h
+output\outbin.$(O): output\outbin.c compiler.h directiv.h eval.h insnsi.h &
  labels.h nasm.h nasmlib.h opflags.h output\outform.h output\outlib.h &
  pptok.h preproc.h regs.h saa.h stdscan.h
-output\outcoff.$(O): output\outcoff.c compiler.h directives.h eval.h &
insnsi.h nasm.h nasmlib.h opflags.h output\outform.h output\outlib.h &
+output\outcoff.$(O): output\outcoff.c compiler.h directiv.h eval.h insnsi.h &
nasm.h nasmlib.h opflags.h output\outform.h output\outlib.h output\pecoff.h &
  pptok.h preproc.h raa.h regs.h saa.h
-output\outdbg.$(O): output\outdbg.c compiler.h directives.h insnsi.h nasm.h &
+output\outdbg.$(O): output\outdbg.c compiler.h directiv.h insnsi.h nasm.h &
  nasmlib.h opflags.h output\outform.h pptok.h preproc.h regs.h
-output\outelf.$(O): output\outelf.c compiler.h directives.h insnsi.h nasm.h &
+output\outelf.$(O): output\outelf.c compiler.h directiv.h insnsi.h nasm.h &
  nasmlib.h opflags.h output\dwarf.h output\elf.h output\outelf.h &
  output\outform.h pptok.h preproc.h regs.h
-output\outelf32.$(O): output\outelf32.c compiler.h directives.h eval.h &
+output\outelf32.$(O): output\outelf32.c compiler.h directiv.h eval.h &
  insnsi.h nasm.h nasmlib.h opflags.h output\dwarf.h output\elf.h &
  output\outelf.h output\outform.h output\outlib.h output\stabs.h pptok.h &
  preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-output\outelf64.$(O): output\outelf64.c compiler.h directives.h eval.h &
+output\outelf64.$(O): output\outelf64.c compiler.h directiv.h eval.h &
  insnsi.h nasm.h nasmlib.h opflags.h output\dwarf.h output\elf.h &
  output\outelf.h output\outform.h output\outlib.h output\stabs.h pptok.h &
  preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-output\outform.$(O): output\outform.c compiler.h directives.h insnsi.h &
- nasm.h nasmlib.h opflags.h output\outform.h pptok.h preproc.h regs.h
-output\outieee.$(O): output\outieee.c compiler.h directives.h insnsi.h &
- nasm.h nasmlib.h opflags.h output\outform.h output\outlib.h pptok.h &
preproc.h regs.h
-output\outlib.$(O): output\outlib.c compiler.h directives.h insnsi.h nasm.h &
+output\outform.$(O): output\outform.c compiler.h directiv.h insnsi.h nasm.h &
+ nasmlib.h opflags.h output\outform.h pptok.h preproc.h regs.h
+output\outieee.$(O): output\outieee.c compiler.h directiv.h insnsi.h nasm.h &
+ nasmlib.h opflags.h output\outform.h output\outlib.h pptok.h preproc.h &
+ regs.h
+output\outlib.$(O): output\outlib.c compiler.h directiv.h insnsi.h nasm.h &
  nasmlib.h opflags.h output\outlib.h pptok.h preproc.h regs.h
-output\outmacho32.$(O): output\outmacho32.c compiler.h directives.h eval.h &
+output\outmac32.$(O): output\outmac32.c compiler.h directiv.h eval.h &
  insnsi.h nasm.h nasmlib.h opflags.h output\outform.h output\outlib.h &
  pptok.h preproc.h raa.h regs.h saa.h
-output\outmacho64.$(O): output\outmacho64.c compiler.h directives.h insnsi.h &
+output\outmac64.$(O): output\outmac64.c compiler.h directiv.h insnsi.h &
  nasm.h nasmlib.h opflags.h output\outform.h output\outlib.h pptok.h &
  preproc.h raa.h regs.h saa.h
-output\outobj.$(O): output\outobj.c compiler.h directives.h eval.h insnsi.h &
+output\outobj.$(O): output\outobj.c compiler.h directiv.h eval.h insnsi.h &
  nasm.h nasmlib.h opflags.h output\outform.h output\outlib.h pptok.h &
  preproc.h regs.h stdscan.h
-output\outrdf2.$(O): output\outrdf2.c compiler.h directives.h insnsi.h &
- nasm.h nasmlib.h opflags.h output\outform.h output\outlib.h pptok.h &
preproc.h rdoff\rdoff.h regs.h saa.h
-parser.$(O): parser.c compiler.h directives.h eval.h float.h insns.h &
insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h preproc.h regs.h &
stdscan.h tables.h tokens.h
+output\outrdf2.$(O): output\outrdf2.c compiler.h directiv.h insnsi.h nasm.h &
+ nasmlib.h opflags.h output\outform.h output\outlib.h pptok.h preproc.h &
+ rdoff\rdoff.h regs.h saa.h
+parser.$(O): parser.c compiler.h directiv.h eval.h float.h insns.h insnsi.h &
nasm.h nasmlib.h opflags.h parser.h pptok.h preproc.h regs.h stdscan.h &
+ tables.h tokens.h
 pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.$(O): preproc.c compiler.h directives.h eval.h hashtbl.h insnsi.h &
+preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h &
  nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h &
  tables.h tokens.h
 quote.$(O): quote.c compiler.h nasmlib.h quote.h
 raa.$(O): raa.c compiler.h nasmlib.h raa.h
 rbtree.$(O): rbtree.c compiler.h rbtree.h
 regdis.$(O): regdis.c regdis.h regs.h
-regflags.$(O): regflags.c compiler.h directives.h insnsi.h nasm.h nasmlib.h &
+regflags.$(O): regflags.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h &
  opflags.h pptok.h preproc.h regs.h tables.h
 regs.$(O): regs.c compiler.h insnsi.h opflags.h tables.h
 regvals.$(O): regvals.c compiler.h insnsi.h opflags.h tables.h
 saa.$(O): saa.c compiler.h nasmlib.h saa.h
-stdscan.$(O): stdscan.c compiler.h directives.h insns.h insnsi.h nasm.h &
+stdscan.$(O): stdscan.c compiler.h directiv.h insns.h insnsi.h nasm.h &
  nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
-strfunc.$(O): strfunc.c compiler.h directives.h insnsi.h nasm.h nasmlib.h &
+strfunc.$(O): strfunc.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h &
  opflags.h pptok.h preproc.h regs.h
 sync.$(O): sync.c compiler.h nasmlib.h sync.h
-tokhash.$(O): tokhash.c compiler.h directives.h hashtbl.h insns.h insnsi.h &
+tokhash.$(O): tokhash.c compiler.h directiv.h hashtbl.h insns.h insnsi.h &
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-ver.$(O): ver.c compiler.h directives.h insnsi.h nasm.h nasmlib.h opflags.h &
+ver.$(O): ver.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h opflags.h &
  pptok.h preproc.h regs.h version.h
index a52a667..6979876 100644 (file)
@@ -60,17 +60,18 @@ X               = .exe
 NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
        raa.$(O) saa.$(O) rbtree.$(O) \
        float.$(O) insnsa.$(O) insnsb.$(O) \
-       directives.$(O) \
+       directiv.$(O) \
        assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
        output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \
        output/nullout.$(O) \
        output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) \
        output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \
        output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
-       output/outdbg.$(O) output/outieee.$(O) output/outmacho32.$(O) \
-       output/outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
+       output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) \
+       output/outmac64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
        macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \
        strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \
+       ilog2.$(O) \
        lib/strlcpy.$(O)
 
 NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
@@ -171,6 +172,9 @@ clean:
        -rm -f *.$(O)
        -rm -f *.s
        -rm -f *.i
+       -rm -f lib/*.$(O)
+       -rm -f lib/*.s
+       -rm -f lib/*.i
        -rm -f output/*.$(O)
        -rm -f output/*.s
        -rm -f output/*.i
@@ -224,116 +228,116 @@ everything: all doc rdf
 # @exclude: "config.h"
 # @continuation: "\"
 #-- Everything below is generated by mkdep.pl - do not edit --#
-assemble.$(O): assemble.c assemble.h compiler.h directives.h insns.h \
- insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h \
- tokens.h
+assemble.$(O): assemble.c assemble.h compiler.h directiv.h insns.h insnsi.h \
+ nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h tokens.h
 crc64.$(O): crc64.c compiler.h nasmlib.h
-directives.$(O): directives.c compiler.h directives.h hashtbl.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-disasm.$(O): disasm.c compiler.h directives.h disasm.h insns.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regdis.h regs.h sync.h \
- tables.h tokens.h
-eval.$(O): eval.c compiler.h directives.h eval.h float.h insnsi.h labels.h \
+directiv.$(O): directiv.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regs.h
+disasm.$(O): disasm.c compiler.h directiv.h disasm.h insns.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regdis.h regs.h sync.h tables.h \
+ tokens.h
+eval.$(O): eval.c compiler.h directiv.h eval.h float.h insnsi.h labels.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-exprlib.$(O): exprlib.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
+exprlib.$(O): exprlib.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \
  opflags.h pptok.h preproc.h regs.h
-float.$(O): float.c compiler.h directives.h float.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h
-hashtbl.$(O): hashtbl.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
+float.$(O): float.c compiler.h directiv.h float.h insnsi.h nasm.h nasmlib.h \
+ opflags.h pptok.h preproc.h regs.h
+hashtbl.$(O): hashtbl.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-insnsa.$(O): insnsa.c compiler.h directives.h insns.h insnsi.h nasm.h \
+ilog2.$(O): ilog2.c compiler.h nasmlib.h
+insnsa.$(O): insnsa.c compiler.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-insnsb.$(O): insnsb.c compiler.h directives.h insns.h insnsi.h nasm.h \
+insnsb.$(O): insnsb.c compiler.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-insnsd.$(O): insnsd.c compiler.h directives.h insns.h insnsi.h nasm.h \
+insnsd.$(O): insnsd.c compiler.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
 insnsn.$(O): insnsn.c compiler.h insnsi.h opflags.h tables.h
-labels.$(O): labels.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
+labels.$(O): labels.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
 lib/snprintf.$(O): lib/snprintf.c compiler.h nasmlib.h
 lib/strlcpy.$(O): lib/strlcpy.c compiler.h
 lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h nasmlib.h
-listing.$(O): listing.c compiler.h directives.h insnsi.h listing.h nasm.h \
+listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h
-macros.$(O): macros.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
+macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h tables.h
-nasm.$(O): nasm.c assemble.h compiler.h directives.h eval.h float.h insns.h \
+nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h insns.h \
  insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h output/outform.h \
  parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h tokens.h
-nasmlib.$(O): nasmlib.c compiler.h directives.h insns.h insnsi.h nasm.h \
+nasmlib.$(O): nasmlib.c compiler.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-ndisasm.$(O): ndisasm.c compiler.h directives.h disasm.h insns.h insnsi.h \
+ndisasm.$(O): ndisasm.c compiler.h directiv.h disasm.h insns.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h sync.h tokens.h
-output/nulldbg.$(O): output/nulldbg.c compiler.h directives.h insnsi.h \
- nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h
-output/nullout.$(O): output/nullout.c compiler.h directives.h insnsi.h \
- nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h
-output/outaout.$(O): output/outaout.c compiler.h directives.h eval.h \
- insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
- pptok.h preproc.h raa.h regs.h saa.h stdscan.h
-output/outas86.$(O): output/outas86.c compiler.h directives.h insnsi.h \
+output/nulldbg.$(O): output/nulldbg.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h pptok.h preproc.h regs.h
+output/nullout.$(O): output/nullout.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h
+output/outaout.$(O): output/outaout.c compiler.h directiv.h eval.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
- preproc.h raa.h regs.h saa.h
-output/outbin.$(O): output/outbin.c compiler.h directives.h eval.h insnsi.h \
+ preproc.h raa.h regs.h saa.h stdscan.h
+output/outas86.$(O): output/outas86.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h preproc.h \
+ raa.h regs.h saa.h
+output/outbin.$(O): output/outbin.c compiler.h directiv.h eval.h insnsi.h \
  labels.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h regs.h saa.h stdscan.h
-output/outcoff.$(O): output/outcoff.c compiler.h directives.h eval.h \
insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
+output/outcoff.$(O): output/outcoff.c compiler.h directiv.h eval.h insnsi.h \
nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h output/pecoff.h \
  pptok.h preproc.h raa.h regs.h saa.h
-output/outdbg.$(O): output/outdbg.c compiler.h directives.h insnsi.h nasm.h \
+output/outdbg.$(O): output/outdbg.c compiler.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h
-output/outelf.$(O): output/outelf.c compiler.h directives.h insnsi.h nasm.h \
+output/outelf.$(O): output/outelf.c compiler.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/dwarf.h output/elf.h output/outelf.h \
  output/outform.h pptok.h preproc.h regs.h
-output/outelf32.$(O): output/outelf32.c compiler.h directives.h eval.h \
+output/outelf32.$(O): output/outelf32.c compiler.h directiv.h eval.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/dwarf.h output/elf.h \
  output/outelf.h output/outform.h output/outlib.h output/stabs.h pptok.h \
  preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-output/outelf64.$(O): output/outelf64.c compiler.h directives.h eval.h \
+output/outelf64.$(O): output/outelf64.c compiler.h directiv.h eval.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/dwarf.h output/elf.h \
  output/outelf.h output/outform.h output/outlib.h output/stabs.h pptok.h \
  preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-output/outform.$(O): output/outform.c compiler.h directives.h insnsi.h \
- nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h
-output/outieee.$(O): output/outieee.c compiler.h directives.h insnsi.h \
- nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
preproc.h regs.h
-output/outlib.$(O): output/outlib.c compiler.h directives.h insnsi.h nasm.h \
+output/outform.$(O): output/outform.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h
+output/outieee.$(O): output/outieee.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h preproc.h \
+ regs.h
+output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h
-output/outmacho32.$(O): output/outmacho32.c compiler.h directives.h eval.h \
+output/outmac32.$(O): output/outmac32.c compiler.h directiv.h eval.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h raa.h regs.h saa.h
-output/outmacho64.$(O): output/outmacho64.c compiler.h directives.h insnsi.h \
+output/outmac64.$(O): output/outmac64.c compiler.h directiv.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
  preproc.h raa.h regs.h saa.h
-output/outobj.$(O): output/outobj.c compiler.h directives.h eval.h insnsi.h \
+output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
  preproc.h regs.h stdscan.h
-output/outrdf2.$(O): output/outrdf2.c compiler.h directives.h insnsi.h \
- nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
preproc.h rdoff/rdoff.h regs.h saa.h
-parser.$(O): parser.c compiler.h directives.h eval.h float.h insns.h \
insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h preproc.h regs.h \
stdscan.h tables.h tokens.h
+output/outrdf2.$(O): output/outrdf2.c compiler.h directiv.h insnsi.h nasm.h \
+ nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h preproc.h \
+ rdoff/rdoff.h regs.h saa.h
+parser.$(O): parser.c compiler.h directiv.h eval.h float.h insns.h insnsi.h \
nasm.h nasmlib.h opflags.h parser.h pptok.h preproc.h regs.h stdscan.h \
+ tables.h tokens.h
 pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.$(O): preproc.c compiler.h directives.h eval.h hashtbl.h insnsi.h \
+preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h \
  tables.h tokens.h
 quote.$(O): quote.c compiler.h nasmlib.h quote.h
 raa.$(O): raa.c compiler.h nasmlib.h raa.h
 rbtree.$(O): rbtree.c compiler.h rbtree.h
 regdis.$(O): regdis.c regdis.h regs.h
-regflags.$(O): regflags.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
+regflags.$(O): regflags.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \
  opflags.h pptok.h preproc.h regs.h tables.h
 regs.$(O): regs.c compiler.h insnsi.h opflags.h tables.h
 regvals.$(O): regvals.c compiler.h insnsi.h opflags.h tables.h
 saa.$(O): saa.c compiler.h nasmlib.h saa.h
-stdscan.$(O): stdscan.c compiler.h directives.h insns.h insnsi.h nasm.h \
+stdscan.$(O): stdscan.c compiler.h directiv.h insns.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h tokens.h
-strfunc.$(O): strfunc.c compiler.h directives.h insnsi.h nasm.h nasmlib.h \
+strfunc.$(O): strfunc.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \
  opflags.h pptok.h preproc.h regs.h
 sync.$(O): sync.c compiler.h nasmlib.h sync.h
-tokhash.$(O): tokhash.c compiler.h directives.h hashtbl.h insns.h insnsi.h \
+tokhash.$(O): tokhash.c compiler.h directiv.h hashtbl.h insns.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tokens.h
-ver.$(O): ver.c compiler.h directives.h insnsi.h nasm.h nasmlib.h opflags.h \
+ver.$(O): ver.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h opflags.h \
  pptok.h preproc.h regs.h version.h
index 81476db..3932ab0 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *
- *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
@@ -254,7 +254,7 @@ static void warn_overflow_const(int64_t data, int size)
 
 static void warn_overflow_opd(const struct operand *o, int size)
 {
-    if (size < 8 && o->wrt == NO_SEG && o->segment == NO_SEG) {
+    if (o->wrt == NO_SEG && o->segment == NO_SEG) {
         if (overflow_general(o->offset, size))
             warn_overflow(ERR_PASS2, size);
     }
@@ -365,23 +365,15 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, uint32_t cp,
         while (t--) {           /* repeat TIMES times */
             list_for_each(e, instruction->eops) {
                 if (e->type == EOT_DB_NUMBER) {
-                    if (wsize == 1) {
-                        if (e->segment != NO_SEG)
-                            errfunc(ERR_NONFATAL,
-                                    "one-byte relocation attempted");
-                        else {
-                            uint8_t out_byte = e->offset;
-                            out(offset, segment, &out_byte,
-                                OUT_RAWDATA, 1, NO_SEG, NO_SEG);
-                        }
-                    } else if (wsize > 8) {
+                   if (wsize > 8) {
                         errfunc(ERR_NONFATAL,
                                "integer supplied to a DT, DO or DY"
                                 " instruction");
-                    } else
+                    } else {
                         out(offset, segment, &e->offset,
                             OUT_ADDRESS, wsize, e->segment, e->wrt);
-                    offset += wsize;
+                       offset += wsize;
+                   }
                 } else if (e->type == EOT_DB_STRING ||
                           e->type == EOT_DB_STRING_FREE) {
                     int align;
@@ -722,7 +714,7 @@ int64_t insn_size(int32_t segment, int64_t offset, int bits, uint32_t cp,
        int64_t isize;
        const uint8_t *codes = temp->code;
        int j;
-       
+
        isize = calcsize(segment, offset, bits, instruction, codes);
        if (isize < 0)
            return -1;
@@ -1344,14 +1336,18 @@ static void gencode(int32_t segment, int64_t offset, int bits,
             break;
 
        case4(050):
-            if (opx->segment != segment)
-                errfunc(ERR_NONFATAL,
-                        "short relative jump outside segment");
-            data = opx->offset - insn_end;
-            if (data > 127 || data < -128)
-                errfunc(ERR_NONFATAL, "short jump is out of range");
-            bytes[0] = data;
-            out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG, NO_SEG);
+            if (opx->segment != segment) {
+                data = opx->offset;
+                out(offset, segment, &data,
+                    OUT_REL1ADR, insn_end - offset,
+                    opx->segment, opx->wrt);
+            } else {
+                data = opx->offset - insn_end;
+               if (data > 127 || data < -128)
+                   errfunc(ERR_NONFATAL, "short jump is out of range");
+                out(offset, segment, &data,
+                    OUT_ADDRESS, 1, NO_SEG, NO_SEG);
+            }
             offset += 1;
             break;
 
@@ -1858,18 +1854,25 @@ static void gencode(int32_t segment, int64_t offset, int bits,
                 case 4:
                 case 8:
                     data = opy->offset;
-                    warn_overflow_opd(opy, ea_data.bytes);
                     s += ea_data.bytes;
                    if (ea_data.rip) {
                        if (opy->segment == segment) {
                            data -= insn_end;
+                            if (overflow_signed(data, ea_data.bytes))
+                                warn_overflow(ERR_PASS2, ea_data.bytes);
                            out(offset, segment, &data, OUT_ADDRESS,
                                ea_data.bytes, NO_SEG, NO_SEG);
                        } else {
+                            /* overflow check in output/linker? */
                            out(offset, segment, &data, OUT_REL4ADR,
                                insn_end - offset, opy->segment, opy->wrt);
                        }
                    } else {
+                        if (overflow_general(opy->offset, ins->addr_size >> 3) ||
+                            signed_bits(opy->offset, ins->addr_size) !=
+                            signed_bits(opy->offset, ea_data.bytes * 8))
+                            warn_overflow(ERR_PASS2, ea_data.bytes);
+
                        type = OUT_ADDRESS;
                        out(offset, segment, &data, OUT_ADDRESS,
                            ea_data.bytes, opy->segment, opy->wrt);
@@ -2232,6 +2235,20 @@ static ea *process_ea(operand * input, ea * output, int bits,
         if (input->basereg == -1
             && (input->indexreg == -1 || input->scale == 0)) {
             /* it's a pure offset */
+
+            if (bits == 64 && ((input->type & IP_REL) == IP_REL) &&
+                input->segment == NO_SEG) {
+                nasm_error(ERR_WARNING | ERR_PASS1, "absolute address can not be RIP-relative");
+                input->type &= ~IP_REL;
+                input->type |= MEMORY;
+            }
+
+            if (input->eaflags & EAF_BYTEOFFS ||
+                (input->eaflags & EAF_WORDOFFS &&
+                 input->disp_size != (addrbits != 16 ? 32 : 16))) {
+                nasm_error(ERR_WARNING | ERR_PASS1, "displacement size ignored on absolute address");
+            }
+
             if (bits == 64 && (~input->type & IP_REL)) {
               int scale, index, base;
               output->sib_present = true;
@@ -2250,7 +2267,7 @@ static ea *process_ea(operand * input, ea * output, int bits,
             }
         } else {                /* it's an indirection */
             int i = input->indexreg, b = input->basereg, s = input->scale;
-            int32_t o = input->offset, seg = input->segment;
+            int32_t seg = input->segment;
             int hb = input->hintbase, ht = input->hinttype;
             int t, it, bt;             /* register numbers */
            opflags_t x, ix, bx;        /* register flags */
@@ -2278,7 +2295,7 @@ static ea *process_ea(operand * input, ea * output, int bits,
            if ((ix|bx) & (BITS32|BITS64)) {
                 /* it must be a 32/64-bit memory reference. Firstly we have
                  * to check that all registers involved are type E/Rxx. */
-               int32_t sok = BITS32|BITS64;
+               int32_t sok = BITS32|BITS64, o = input->offset;
 
                 if (it != -1) {
                    if (!(REG64 & ~ix) || !(REG32 & ~ix))
@@ -2417,6 +2434,7 @@ static ea *process_ea(operand * input, ea * output, int bits,
                 }
             } else {            /* it's 16-bit */
                 int mod, rm;
+                int16_t o = input->offset;
 
                 /* check for 64-bit long mode */
                 if (addrbits == 64)
similarity index 99%
rename from directives.dat
rename to directiv.dat
index b08d387..a8d9261 100644 (file)
@@ -48,6 +48,7 @@ list
 section
 segment
 warning
+sectalign
 
 ; --- Format-specific directives
 export                         ; outcoff, outobj
similarity index 84%
rename from directives.pl
rename to directiv.pl
index d8bc6e8..684f542 100755 (executable)
@@ -35,7 +35,7 @@
 #
 # Generate a perfect hash for directive parsing
 #
-# Usage: directives.pl directives.dat directives.c directives.h
+# Usage: directiv.pl directiv.dat directiv.c directiv.h
 #
 
 require 'phash.ph';
@@ -43,6 +43,7 @@ require 'phash.ph';
 my($output, $directives_dat, $outfile) = @ARGV;
 
 @directives = ();
+@specials   = ('none', 'unknown');
 
 open(DD, "< ${directives_dat}\0")
     or die "$0: cannot open: ${directives_dat}: $!\n";
@@ -59,8 +60,8 @@ if ($output eq 'h') {
        or die "$0: cannot create: ${outfile}: $!\n";
 
     print H "/*\n";
-    print H " * This    file is generated from directives.dat\n";
-    print H " * by directives.pl; do not edit.\n";
+    print H " * This    file is generated from directiv.dat\n";
+    print H " * by directiv.pl; do not edit.\n";
     print H " */\n";
     print H "\n";
 
@@ -68,14 +69,19 @@ if ($output eq 'h') {
     print H "#define NASM_DIRECTIVES_H\n";
     print H "\n";
 
-    print H "enum directives {\n";
-    print H "    D_NONE";
+    $c = '{';
+    print H "enum directives ";
+    foreach $d (@specials) {
+       print H "$c\n    D_$d";
+       $c = ',';
+    }
     foreach $d (@directives) {
-       print H ",\n    D_\U$d";
+       print H "$c\n    D_\U$d";
+       $c = ',';
     }
     print H "\n};\n\n";
     printf H "extern const char * const directives[%d];\n",
-        scalar(@directives)+1;
+        scalar(@directives)+scalar(@specials);
     print H "enum directives find_directive(const char *token);\n\n";
     print H "#endif /* NASM_DIRECTIVES_H */\n";
 } elsif ($output eq 'c') {
@@ -97,7 +103,6 @@ if ($output eq 'h') {
     verify_hash_table(\%directive, \@hashinfo);
 
     ($n, $sv, $g) = @hashinfo;
-    $sv2 = $sv+2;
 
     die if ($n & ($n-1));
 
@@ -105,8 +110,8 @@ if ($output eq 'h') {
        or die "$0: cannot create: ${directives_c}: $!\n";
 
     print C "/*\n";
-    print C " * This file is generated from directives.dat\n";
-    print C " * by directives.pl; do not edit.\n";
+    print C " * This file is generated from directiv.dat\n";
+    print C " * by directiv.pl; do not edit.\n";
     print C " */\n";
     print C "\n";
 
@@ -114,14 +119,19 @@ if ($output eq 'h') {
     print C "#include <string.h>\n";
     print C "#include \"nasm.h\"\n";
     print C "#include \"hashtbl.h\"\n";
-    print C "#include \"directives.h\"\n";
+    print C "#include \"directiv.h\"\n";
     print C "\n";
 
-    printf C "const char * const directives[%d] = {\n",
-        scalar(@directives)+1;
-    print C "    NULL";
+    printf C "const char * const directives[%d] = \n",
+        scalar(@directives)+scalar(@specials);
+    $c = '{';
+    foreach $d (@specials) {
+       print C "$c\n    NULL";
+       $c = ',';
+    }
     foreach $d (@directives) {
-       print C ",\n    \"$d\"";
+       print C "$c\n    \"$d\"";
+       $c = ',';
     }
     print C "\n};\n\n";
 
@@ -160,11 +170,11 @@ if ($output eq 'h') {
     print C  "\n";
     printf C "    ix = hash1[k1 & 0x%x] + hash2[k2 & 0x%x];\n", $n-1, $n-1;
     printf C "    if (ix >= %d)\n", scalar(@directives);
-    print C  "        return D_NONE;\n";
+    print C  "        return D_unknown;\n";
     print C  "\n";
-    print C  "    ix++;\n";    # Account for D_NONE
+    printf C "    ix += %d;\n", scalar(@specials);
     print C  "    if (nasm_stricmp(token, directives[ix]))\n";
-    print C  "        return D_NONE;\n";
+    print C  "        return D_unknown;\n";
     print C  "\n";
     print C  "    return ix;\n";
     print C  "}\n";
index a2ef4e3..4932869 100644 (file)
@@ -88,11 +88,12 @@ nasm.inf: nasmdoc.ipf
 clean:
        -rm -f *.rtf *.hpj *.texi *.gid *.ipf *.dip
        -rm -f *.aux *.cp *.fn *.ky *.pg *.log *.toc *.tp *.vr
+       -rm -f inslist.src
 
 spotless: clean
        -rm -rf html info
        -rm -f *.hlp nasmdoc.txt *.inf *.pdf *.dvi
-       -rm -f nasmdoc*.ps inslist.src
+       -rm -f nasmdoc*.ps
 
 install: all
        mkdir -p $(INSTALLROOT)$(infodir)
index 65d10c0..5f8cb2e 100644 (file)
@@ -7,6 +7,52 @@
 The NASM 2 series support x86-64, and is the production version of NASM
 since 2007.
 
+\S{cl-2.09} Version 2.09
+
+\b \c{%ifenv}, \c{%elifenv}, \c{%ifnenv}, and \c{%elifnenv} directives introduced.
+
+\b Fixed NULL dereference if environment variable is missed.
+
+\b Updates of new AVX v7 Intel instruciotns.
+
+\b \c{PUSH imm32} is now officially documented.
+
+\b Fix for encoding the LFS, LGS and LSS in 64-bit mode.
+
+\b Fixes for compatibility with OpenWatcom compiler and DOS 8.3 file format limitation.
+
+\b Macros parameters range expansion introduced. See \k{mlmacrange}.
+
+\b Backward compatibility on expanging of local sigle macros restored.
+
+\b 8 bit relocations for \c{elf} and \c{bin} output formats are introduced.
+
+\b Short intersegment jumps are permitted now.
+
+\b An alignment more then 64 bytes are allowed for \c{win32}, \c{win64} output formats.
+
+\b \c{SECTALIGN} directive introduced. In most cases invisible to user.
+
+\b \c{nojmp} option introduced in \c{smartalign} package. See \k{pkg_smartalign}.
+
+\b Short aliases \c{win}, \c{elf} and \c{macho} for output formats are introduced.
+  Each stands for \c{win32}, \c{elf32} and \c{macho32} accordingly.
+
+\b Faster handling of missing directives implemented.
+
+\b Various small improvements in documentation.
+
+\b No hang anymore if unable to open malloc.log file.
+
+\b The environments without vsnprintf function are able to build nasm again.
+
+\b AMD LWP instructions updated.
+
+\b Tighten EA checks. We warn a user if there overflow in EA addressing.
+
+\b Make \c{-Ox} the default optimization level.  For the legacy
+  behavior, specify \c{-O0} explicitly.  See \k{opt-O}.
+
 
 \S{cl-2.08.02} Version 2.08.02
 
index 75001c6..565b790 100644 (file)
@@ -1,5 +1,5 @@
 \# --------------------------------------------------------------------------
-\#   
+\#
 \#   Copyright 1996-2010 The NASM Authors - All Rights Reserved
 \#   See the file AUTHORS included with the NASM distribution for
 \#   the specific copyright holders.
@@ -14,7 +14,7 @@
 \#     copyright notice, this list of conditions and the following
 \#     disclaimer in the documentation and/or other materials provided
 \#     with the distribution.
-\#     
+\#
 \#     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 \#     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 \#     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -866,7 +866,8 @@ levels of optimization.  The syntax is:
         releases, the letter \c{x} may also be any number greater than
         one. This number has no effect on the actual number of passes.
 
-The \c{-Ox} mode is recommended for most uses.
+The \c{-Ox} mode is recommended for most uses, and is the default
+since NASM 2.09.
 
 Note that this is a capital \c{O}, and is different from a small \c{o}, which
 is used to specify the output file name. See \k{opt-o}.
@@ -1464,16 +1465,18 @@ character, string and floating-point.
 
 A numeric constant is simply a number. NASM allows you to specify
 numbers in a variety of number bases, in a variety of ways: you can
-suffix \c{H} or \c{X}, \c{Q} or \c{O}, and \c{B} for \i{hexadecimal},
-\i{octal} and \i{binary} respectively, or you can prefix \c{0x} for
-hexadecimal in the style of C, or you can prefix \c{$} for hexadecimal
-in the style of Borland Pascal. Note, though, that the \I{$,
+suffix \c{H} or \c{X}, \c{D} or \c{T}, \c{Q} or \c{O}, and \c{B} or
+\c{Y} for \i{hexadecimal}, \i{decimal}, \i{octal} and \i{binary}
+respectively, or you can prefix \c{0x}, for hexadecimal in the style
+of C, or you can prefix \c{$} for hexadecimal in the style of Borland
+Pascal or Motorola Assemblers. Note, though, that the \I{$,
 prefix}\c{$} prefix does double duty as a prefix on identifiers (see
 \k{syntax}), so a hex number prefixed with a \c{$} sign must have a
 digit after the \c{$} rather than a letter.  In addition, current
-versions of NASM accept the prefix \c{0h} for hexadecimal, \c{0o} or
-\c{0q} for octal, and \c{0b} for binary.  Please note that unlike C, a
-\c{0} prefix by itself does \e{not} imply an octal constant!
+versions of NASM accept the prefix \c{0h} for hexadecimal, \c{0d} or
+\c{0t} for decimal, \c{0o} or \c{0q} for octal, and \c{0b} or \c{0y}
+for binary.  Please note that unlike C, a \c{0} prefix by itself does
+\e{not} imply an octal constant!
 
 Numeric constants can have underscores (\c{_}) interspersed to break
 up long strings.
@@ -1494,7 +1497,9 @@ Some examples (all producing exactly the same code):
 \c         mov     ax,0q310        ; hex yet again
 \c         mov     ax,11001000b    ; binary
 \c         mov     ax,1100_1000b   ; same binary constant
+\c         mov     ax,1100_1000y   ; same binary constant once more
 \c         mov     ax,0b1100_1000  ; same binary constant yet again
+\c         mov     ax,0y1100_1000  ; same binary constant yet again
 
 \S{strings} \I{Strings}\i{Character Strings}
 
@@ -1615,11 +1620,15 @@ Floating-point constants are expressed in the traditional form:
 digits, then a period, then optionally more digits, then optionally an
 \c{E} followed by an exponent. The period is mandatory, so that NASM
 can distinguish between \c{dd 1}, which declares an integer constant,
-and \c{dd 1.0} which declares a floating-point constant.  NASM also
-support C99-style hexadecimal floating-point: \c{0x}, hexadecimal
-digits, period, optionally more hexadeximal digits, then optionally a
-\c{P} followed by a \e{binary} (not hexadecimal) exponent in decimal
-notation.
+and \c{dd 1.0} which declares a floating-point constant.
+
+NASM also support C99-style hexadecimal floating-point: \c{0x},
+hexadecimal digits, period, optionally more hexadeximal digits, then
+optionally a \c{P} followed by a \e{binary} (not hexadecimal) exponent
+in decimal notation.  As an extension, NASM additionally supports the
+\c{0h} and \c{$} prefixes for hexadecimal, as well binary and octal
+floating-point, using the \c{0b} or \c{0y} and \c{0o} or \c{0q}
+prefixes, respectively.
 
 Underscores to break up groups of digits are permitted in
 floating-point constants as well.
@@ -1952,7 +1961,11 @@ to the local label mechanism. So you could code
 
 NASM has the capacity to define other special symbols beginning with
 a double period: for example, \c{..start} is used to specify the
-entry point in the \c{obj} output format (see \k{dotdotstart}).
+entry point in the \c{obj} output format (see \k{dotdotstart}),
+\c{..imagebase} is used to find out the offset from a base address
+of the current image in the \c{win64} output format (see \k{win64pic}).
+So just keep in mind that symbols beginning with a double period are
+special.
 
 
 \C{preproc} The NASM \i{Preprocessor}
@@ -2546,6 +2559,48 @@ definition.
 
 See \k{sectmac} for a better way to write the above macro.
 
+\S{mlmacrange} \i{Macro Parameters Range}
+
+NASM also allows you to expand parameters via special construction \c{%\{x:y\}}
+where \c{x} is the first parameter index and \c{y} is the last. Any index can
+be either negative or positive. Though the indices must never be zero.
+
+For example
+
+\c %macro mpar 1-*
+\c      db %{3:5}
+\c %endmacro
+\c
+\c mpar 1,2,3,4,5,6
+
+expands to \c{3,4,5} range.
+
+Even more, the parameters can be reversed so that
+
+\c %macro mpar 1-*
+\c      db %{5:3}
+\c %endmacro
+\c
+\c mpar 1,2,3,4,5,6
+
+expands to \c{5,4,3} range.
+
+But even this is not the last. The parameters can be addressed via negative
+indices so NASM will count them reversed. The ones who know Python may see
+the analogue here.
+
+\c %macro mpar 1-*
+\c      db %{-1:-3}
+\c %endmacro
+\c
+\c mpar 1,2,3,4,5,6
+
+expands to \c{6,5,4} range.
+
+Note that NASM uses \i{comma} to separate parameters being expanded.
+
+By the way, here is a trick - you might use the index \c{%{-1:-1}} gives
+you the \i{last} argument passed to a macro.
 
 \S{mlmacdef} \i{Default Macro Parameters}
 
@@ -3095,6 +3150,15 @@ any tokens at all, whitespace excepted.
 The usual \i\c{%elifempty}, \i\c\{%ifnempty}, and \i\c{%elifnempty}
 variants are also provided.
 
+\S{ifenv} \i\c{%ifenv}: Test If Environment Variable Exists
+
+The conditional assembly construct \c{%ifenv} assembles the
+subsequent code if and only if the environment variable referenced by
+the \c{%!<env>} directive exists.
+
+The usual \i\c{%elifenv}, \i\c\{%ifnenv}, and \i\c{%elifnenv}
+variants are also provided.
+
 \H{rep} \i{Preprocessor Loops}\I{repeating code}: \i\c{%rep}
 
 NASM's \c{TIMES} prefix, though useful, cannot be used to invoke a
@@ -4069,8 +4133,9 @@ sequence.
 
 The specific instructions generated can be controlled with the
 new \i\c{ALIGNMODE} macro.  This macro takes two parameters: one mode,
-and an optional jump threshold override.  The modes are as
-follows:
+and an optional jump threshold override. If (for any reason) you need
+to turn off the jump completely just set jump threshold value to -1
+(or set it to \c{nojmp}). The following modes are possible:
 
 \b \c{generic}: Works on all x86 CPUs and should have reasonable
 performance.  The default jump threshold is 8.  This is the
@@ -7476,7 +7541,7 @@ a zero-extended absolute displacement can access from 0 to 4 GB.
 
 On Unix, the 64-bit ABI is defined by the document:
 
-\W{http://www.x86-64.org/documentation/abi.pdf}\c{http://www.x86-64.org/documentation/abi.pdf}
+\W{http://www.nasm.us/links/unix64abi}\c{http://www.nasm.us/links/unix64abi}
 
 Although written for AT&T-syntax assembly, the concepts apply equally
 well for NASM-style assembly.  What follows is a simplified summary.
@@ -7508,7 +7573,7 @@ Integer and SSE register arguments are counted separately, so for the case of
 
 The Win64 ABI is described at:
 
-\W{http://msdn2.microsoft.com/en-gb/library/ms794533.aspx}\c{http://msdn2.microsoft.com/en-gb/library/ms794533.aspx}
+\W{http://www.nasm.us/links/win64abi}\c{http://www.nasm.us/links/win64abi}
 
 What follows is a simplified summary.
 
@@ -7647,8 +7712,8 @@ We have never yet released a version of NASM with any \e{known}
 bugs. That doesn't usually stop there being plenty we didn't know
 about, though. Any that you find should be reported firstly via the
 \i\c{bugtracker} at
-\W{https://sourceforge.net/projects/nasm/}\c{https://sourceforge.net/projects/nasm/}
-(click on "Bugs"), or if that fails then through one of the
+\W{http://www.nasm.us/}\c{http://www.nasm.us/}
+(click on "Bug Tracker"), or if that fails then through one of the
 contacts in \k{contact}.
 
 Please read \k{qstart} first, and don't report the bug if it's
@@ -7908,7 +7973,7 @@ There are no known bugs. However, any you find, with patches if
 possible, should be sent to
 \W{mailto:nasm-bugs@lists.sourceforge.net}\c{nasm-bugs@lists.sourceforge.net}, or to the
 developer's site at
-\W{https://sourceforge.net/projects/nasm/}\c{https://sourceforge.net/projects/nasm/}
+\W{http://www.nasm.us/}\c{http://www.nasm.us/}
 and we'll try to fix them. Feel free to send contributions and
 new features as well.
 
index 7ceab01..311e15b 100644 (file)
--- a/headers/c
+++ b/headers/c
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *
- *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
index 38ab133..0a6c381 100644 (file)
@@ -1,6 +1,6 @@
 \# --------------------------------------------------------------------------
-\#   
-\#   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+\#
+\#   Copyright 1996-2010 The NASM Authors - All Rights Reserved
 \#   See the file AUTHORS included with the NASM distribution for
 \#   the specific copyright holders.
 \#
@@ -14,7 +14,7 @@
 \#     copyright notice, this list of conditions and the following
 \#     disclaimer in the documentation and/or other materials provided
 \#     with the distribution.
-\#     
+\#
 \#     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 \#     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 \#     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
index b68288f..514315b 100644 (file)
@@ -1,6 +1,6 @@
 ;; --------------------------------------------------------------------------
-;;   
-;;   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+;;
+;;   Copyright 1996-2010 The NASM Authors - All Rights Reserved
 ;;   See the file AUTHORS included with the NASM distribution for
 ;;   the specific copyright holders.
 ;;
@@ -14,7 +14,7 @@
 ;;     copyright notice, this list of conditions and the following
 ;;     disclaimer in the documentation and/or other materials provided
 ;;     with the distribution.
-;;     
+;;
 ;;     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 ;;     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 ;;     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
index 2317088..3ce5ad7 100644 (file)
@@ -1,6 +1,6 @@
 ## --------------------------------------------------------------------------
 ##   
-##   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+##   Copyright 1996-2010 The NASM Authors - All Rights Reserved
 ##   See the file AUTHORS included with the NASM distribution for
 ##   the specific copyright holders.
 ##
diff --git a/ilog2.c b/ilog2.c
new file mode 100644 (file)
index 0000000..9c054fd
--- /dev/null
+++ b/ilog2.c
@@ -0,0 +1,160 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
+ *   See the file AUTHORS included with the NASM distribution for
+ *   the specific copyright holders.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following
+ *   conditions are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above
+ *     copyright notice, this list of conditions and the following
+ *     disclaimer in the documentation and/or other materials provided
+ *     with the distribution.
+ *
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include "compiler.h"
+#include "nasmlib.h"
+
+#define ROUND(v, a, w)                      \
+    do {                                    \
+        if (v & (((1 << w) - 1) << w)) {    \
+            a  += w;                        \
+            v >>= w;                        \
+        }                                   \
+    } while (0)
+
+#if defined(__GNUC__) && defined(__x86_64__)
+
+int ilog2_32(uint32_t v)
+{
+    int n;
+
+    __asm__("bsrl %1,%0"
+            : "=r" (n)
+            : "rm" (v), "0" (0));
+    return n;
+}
+
+#elif defined(__GNUC__) && defined(__i386__)
+
+int ilog2_32(uint32_t v)
+{
+    int n;
+
+    __asm__("bsrl %1,%0 ; jnz 1f ; xorl %0,%0\n"
+            "1:"
+            : "=&r" (n)
+            : "rm" (v));
+    return n;
+}
+
+#elif defined(HAVE_GNUC_4)
+
+int ilog2_32(uint32_t v)
+{
+    if (!v)
+        return 0;
+
+    return __builtin_clz(v) ^ 31;
+}
+
+#else
+
+int ilog2_32(uint32_t v)
+{
+    int p = 0;
+
+    ROUND(v, p, 16);
+    ROUND(v, p,  8);
+    ROUND(v, p,  4);
+    ROUND(v, p,  2);
+    ROUND(v, p,  1);
+
+    return p;
+}
+
+#endif
+
+#if defined(__GNUC__) && defined(__x86_64__)
+
+int ilog2_64(uint64_t v)
+{
+    uint64_t n;
+
+    __asm__("bsrq %1,%0"
+            : "=r" (n)
+            : "rm" (v), "0" (UINT64_C(0)));
+    return n;
+}
+
+#elif defined(HAVE_GNUC_4)
+
+int ilog2_64(uint64_t v)
+{
+    if (!v)
+        return 0;
+
+    return __builtin_clzll(v) ^ 63;
+}
+
+#else
+
+int ilog2_64(uint64_t vv)
+{
+    int p = 0;
+    uint32_t v;
+
+    v = vv >> 32;
+    if (v)
+        p += 32;
+    else
+        v = vv;
+
+    ROUND(v, p, 16);
+    ROUND(v, p,  8);
+    ROUND(v, p,  4);
+    ROUND(v, p,  2);
+    ROUND(v, p,  1);
+
+    return p;
+}
+
+#endif
+
+/*
+ * v == 0 ? 0 : is_power2(x) ? ilog2_X(v) : -1
+ */
+int alignlog2_32(uint32_t v)
+{
+    if (unlikely(v & (v-1)))
+        return -1;              /* invalid alignment */
+
+    return ilog2_32(v);
+}
+
+int alignlog2_64(uint64_t v)
+{
+    if (unlikely(v & (v-1)))
+        return -1;              /* invalid alignment */
+
+    return ilog2_64(v);
+}
index 2873652..414ff81 100644 (file)
--- a/insns.dat
+++ b/insns.dat
@@ -1,6 +1,6 @@
 ;; --------------------------------------------------------------------------
 ;;
-;;   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+;;   Copyright 1996-2010 The NASM Authors - All Rights Reserved
 ;;   See the file AUTHORS included with the NASM distribution for
 ;;   the specific copyright holders.
 ;;
@@ -710,9 +710,11 @@ LES                reg32,mem                       \321\1\xC4\110                                  386,NOLONG
 LFENCE         void                            \3\x0F\xAE\xE8                                  X64,AMD
 LFS            reg16,mem                       \320\2\x0F\xB4\110                              386
 LFS            reg32,mem                       \321\2\x0F\xB4\110                              386
+LFS            reg64,mem                       \324\2\x0F\xB4\110                              X64
 LGDT           mem                             \2\x0F\x01\202                                  286,PRIV
 LGS            reg16,mem                       \320\2\x0F\xB5\110                              386
 LGS            reg32,mem                       \321\2\x0F\xB5\110                              386
+LGS            reg64,mem                       \324\2\x0F\xB5\110                              X64
 LIDT           mem                             \2\x0F\x01\203                                  286,PRIV
 LLDT           mem                             \2\x0F\x00\202                                  286,PROT,PRIV
 LLDT           mem16                           \2\x0F\x00\202                                  286,PROT,PRIV
@@ -760,6 +762,7 @@ LSL         reg64,reg32                     \324\2\x0F\x03\110                              X64,PROT
 LSL            reg64,reg64                     \324\2\x0F\x03\110                              X64,PROT
 LSS            reg16,mem                       \320\2\x0F\xB2\110                              386
 LSS            reg32,mem                       \321\2\x0F\xB2\110                              386
+LSS            reg64,mem                       \324\2\x0F\xB2\110                              X64
 LTR            mem                             \2\x0F\x00\203                                  286,PROT,PRIV
 LTR            mem16                           \2\x0F\x00\203                                  286,PROT,PRIV
 LTR            reg16                           \2\x0F\x00\203                                  286,PROT,PRIV
@@ -1023,6 +1026,7 @@ PUSH              imm8                            \1\x6A\274                                      186
 PUSH           imm16                           \320\144\x68\140                                186,AR0,SZ
 PUSH           imm32                           \321\154\x68\150                                386,NOLONG,AR0,SZ
 PUSH           imm32                           \321\154\x68\150                                386,NOLONG,SD
+PUSH           imm32                           \323\154\x68\250                                X64,AR0,SZ
 PUSH           imm64                           \323\154\x68\250                                X64,AR0,SZ
 PUSHA          void                            \322\1\x60                                      186,NOLONG
 PUSHAD         void                            \321\1\x60                                      386,NOLONG
@@ -1506,16 +1510,22 @@ UNPCKLPS        xmmreg,xmmrm                    \360\2\x0F\x14\110                              KATMAI,SSE
 XORPS          xmmreg,xmmrm                    \360\2\x0F\x57\110                              KATMAI,SSE
 
 ;# Introduced in Deschutes but necessary for SSE support
-FXRSTOR                mem                             \2\x0F\xAE\201                                  P6,SSE,FPU
-FXSAVE         mem                             \2\x0F\xAE\200                                  P6,SSE,FPU
+FXRSTOR                mem                             [m:     0f ae /1]                               P6,SSE,FPU
+FXRSTOR64      mem                             [m:     o64 0f ae /1]                           X64,SSE,FPU
+FXSAVE         mem                             [m:     0f ae /0]                               P6,SSE,FPU
+FXSAVE64       mem                             [m:     o64 0f ae /0]                           X64,SSE,FPU
 
 ;# XSAVE group (AVX and extended state)
 ; Introduced in late Penryn ... we really need to clean up the handling
 ; of CPU feature bits.
 XGETBV         void                            \360\3\x0F\x01\xD0                              NEHALEM
 XSETBV         void                            \360\3\x0F\x01\xD1                              NEHALEM,PRIV
-XSAVE          mem                             \360\2\x0F\xAE\204                              NEHALEM
-XRSTOR         mem                             \360\2\x0F\xAE\205                              NEHALEM
+XSAVE          mem                             [m:     0f ae /4]                               NEHALEM
+XSAVE64                mem                             [m:     o64 0f ae /4]                           LONG,NEHALEM
+XSAVEOPT       mem                             [m:     0f ae /6]                               FUTURE
+XSAVEOPT64     mem                             [m:     o64 0f ae /6]                           LONG,FUTURE
+XRSTOR         mem                             [m:     0f ae /5]                               NEHALEM
+XRSTOR64       mem                             [m:     o64 0f ae /5]                           LONG,NEHALEM
 
 ; These instructions are not SSE-specific; they are
 ;# Generic memory operations
@@ -2799,6 +2809,25 @@ VFNMSUB231SD     xmmreg,xmmreg,xmmrm64           [rvm:   vex.dds.128.66.0f38.w1 bf /r]           FMA,FUT
 VFNMSUB321SS   xmmreg,xmmreg,xmmrm32           [rvm:   vex.dds.128.66.0f38.w0 bf /r]           FMA,FUTURE
 VFNMSUB321SD   xmmreg,xmmreg,xmmrm64           [rvm:   vex.dds.128.66.0f38.w1 bf /r]           FMA,FUTURE
 
+;# Intel post-32 nm processor instructions
+;
+; Per AVX spec revision 7, document 319433-007
+RDFSBASE       reg32                           [m:     f3 0f ae /0]                            LONG,FUTURE
+RDFSBASE       reg64                           [m:     o64 f3 0f ae /0]                        LONG,FUTURE
+RDGSBASE       reg32                           [m:     f3 0f ae /1]                            LONG,FUTURE
+RDGSBASE       reg64                           [m:     o64 f3 0f ae /1]                        LONG,FUTURE
+RDRAND         reg16                           [m:     o16 0f c7 /6]                           FUTURE
+RDRAND         reg32                           [m:     o32 0f c7 /6]                           FUTURE
+RDRAND         reg64                           [m:     o64 0f c7 /6]                           LONG,FUTURE
+WRFSBASE       reg32                           [m:     f3 0f ae /2]                            LONG,FUTURE
+WRFSBASE       reg64                           [m:     o64 f3 0f ae /2]                        LONG,FUTURE
+WRGSBASE       reg32                           [m:     f3 0f ae /3]                            LONG,FUTURE
+WRGSBASE       reg64                           [m:     o64 f3 0f ae /3]                        LONG,FUTURE
+VCVTPH2PS      ymmreg,xmmrm128                 [rm:    vex.256.66.0f38.w0 13 /r]               AVX,FUTURE
+VCVTPH2PS      xmmreg,xmmrm64                  [rm:    vex.128.66.0f38.w0 13 /r]               AVX,FUTURE
+VCVTPS2PH      xmmrm128,ymmreg,imm8            [mri:   vex.256.66.0f3a.w0 1d /r ib]            AVX,FUTURE
+VCVTPS2PH      xmmrm64,xmmreg,imm8             [mri:   vex.128.66.0f3a.w0 1d /r ib]            AVX,FUTURE
+
 ;# VIA (Centaur) security instructions
 XSTORE         void                            \3\x0F\xA7\xC0                                  PENT,CYRIX
 XCRYPTECB      void                            \336\3\x0F\xA7\xC8                              PENT,CYRIX
@@ -2814,34 +2843,27 @@ XSHA256         void                            \336\3\x0F\xA6\xD0                              PENT,CYRIX
 ;
 ; based on pub number 43724 revision 3.04 date August 2009
 ;
-LLWPCB         reg16                           [m: xop.m9.w0.l0.p0 12 /0]                      AMD
-LLWPCB         reg32                           [m: xop.m9.w0.l1.p0 12 /0]                      AMD,386
+; updated to match draft from AMD developer (patch has been
+; sent to binutils
+; 2010-03-22 Quentin Neill <quentin.neill@amd.com>
+;           Sebastian Pop  <sebastian.pop@amd.com>
+;
+LLWPCB         reg32                           [m: xop.m9.w0.l0.p0 12 /0]                      AMD,386
 LLWPCB         reg64                           [m: xop.m9.w1.l0.p0 12 /0]                      AMD,X64
 
-SLWPCB         reg16                           [m: xop.m9.w0.l0.p0 12 /1]                      AMD
-SLWPCB         reg32                           [m: xop.m9.w0.l1.p0 12 /1]                      AMD,386
+SLWPCB         reg32                           [m: xop.m9.w0.l0.p0 12 /1]                      AMD,386
 SLWPCB         reg64                           [m: xop.m9.w1.l0.p0 12 /1]                      AMD,X64
 
-LWPVAL         reg16,rm32,imm16                [vmi: xop.m10.w0.ndd.l0.p0 12 /1 iw]            AMD,386
-LWPVAL         reg32,rm32,imm32                [vmi: xop.m10.w0.ndd.l1.p0 12 /1 id]            AMD,386
+LWPVAL         reg32,rm32,imm32                [vmi: xop.m10.w0.ndd.l0.p0 12 /1 id]            AMD,386
 LWPVAL         reg64,rm32,imm32                [vmi: xop.m10.w1.ndd.l0.p0 12 /1 id]            AMD,X64
 
-LWPINS         reg16,rm32,imm16                [vmi: xop.m10.w0.ndd.l0.p0 12 /0 iw]            AMD,386
-LWPINS         reg32,rm32,imm32                [vmi: xop.m10.w0.ndd.l1.p0 12 /0 id]            AMD,386
+LWPINS         reg32,rm32,imm32                [vmi: xop.m10.w0.ndd.l0.p0 12 /0 id]            AMD,386
 LWPINS         reg64,rm32,imm32                [vmi: xop.m10.w1.ndd.l0.p0 12 /0 id]            AMD,X64
 
-;# AMD XOP, FMA4 and CVT16 instructions (SSE5)
+;# AMD XOP and FMA4 instructions (SSE5)
 ;
-; based on pub number 43479 revision 3.03 date May 2009
+; based on pub number 43479 revision 3.04 dated November 2009
 ;
-VCVTPH2PS      xmmreg,xmmrm64*,imm8            [rmi:   xop.m8.w0.l0 a0 /r ib]                  AMD,SSE5
-VCVTPH2PS      ymmreg,xmmrm128,imm8            [rmi:   xop.m8.w0.l1 a0 /r ib]                  AMD,SSE5
-VCVTPH2PS      ymmreg,ymmrm128*,imm8           [rmi:   xop.m8.w0.l1 a0 /r ib]                  AMD,SSE5
-
-VCVTPS2PH      xmmrm64,xmmreg*,imm8            [mri:   xop.m8.w0.l0 a1 /r ib]                  AMD,SSE5
-VCVTPS2PH      xmmrm128,ymmreg,imm8            [mri:   xop.m8.w0.l1 a1 /r ib]                  AMD,SSE5
-VCVTPS2PH      ymmrm128,ymmreg*,imm8           [mri:   xop.m8.w0.l1 a1 /r ib]                  AMD,SSE5
-
 VFMADDPD       xmmreg,xmmreg*,xmmrm128,xmmreg  [rvms:  vex.m3.w0.nds.l0.p1 69 /r /is4]         AMD,SSE5
 VFMADDPD       ymmreg,ymmreg*,ymmrm256,ymmreg  [rvms:  vex.m3.w0.nds.l1.p1 69 /r /is4]         AMD,SSE5
 VFMADDPD       xmmreg,xmmreg*,xmmreg,xmmrm128  [rvsm:  vex.m3.w1.nds.l0.p1 69 /r /is4]         AMD,SSE5
index 32937b3..e727c15 100644 (file)
--- a/labels.c
+++ b/labels.c
@@ -193,8 +193,9 @@ bool lookup_label(char *label, int32_t *segment, int64_t *offset)
         *segment = lptr->defn.segment;
         *offset = lptr->defn.offset;
         return true;
-    } else
-        return false;
+    }
+
+    return false;
 }
 
 bool is_extern(char *label)
index f5ae2fe..bc54f94 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "nasmlib.h"
 
-#define BUFFER_SIZE    65536   /* Bigger than any string we might print... */
+#define BUFFER_SIZE     65536   /* Bigger than any string we might print... */
 
 static char snprintf_buffer[BUFFER_SIZE];
 
@@ -23,26 +23,23 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
     int rv, bytes;
 
     if (size > BUFFER_SIZE) {
-       nasm_malloc_error(ERR_PANIC|ERR_NOFILE,
-                         "snprintf: size (%d) > BUFFER_SIZE (%d)",
-                         size, BUFFER_SIZE);
-       size = BUFFER_SIZE;
+        nasm_error(ERR_PANIC|ERR_NOFILE,
+                   "vsnprintf: size (%d) > BUFFER_SIZE (%d)",
+                   size, BUFFER_SIZE);
+        size = BUFFER_SIZE;
     }
 
     rv = vsprintf(snprintf_buffer, format, ap);
-    if (rv >= BUFFER_SIZE) {
-       nasm_malloc_error(ERR_PANIC|ERR_NOFILE,
-                         "snprintf buffer overflow");
-    }
+    if (rv >= BUFFER_SIZE)
+        nasm_error(ERR_PANIC|ERR_NOFILE, "vsnprintf buffer overflow");
 
     if (size > 0) {
-       if ((size_t)rv < size-1)
-           bytes = rv;
-       else
-           bytes = size-1;
-
-       memcpy(str, snprintf_buffer, bytes);
-       str[bytes] = '\0';
+        if ((size_t)rv < size-1)
+            bytes = rv;
+        else
+            bytes = size-1;
+        memcpy(str, snprintf_buffer, bytes);
+        str[bytes] = '\0';
     }
 
     return rv;
index 5a09440..38d7908 100644 (file)
--- a/listing.c
+++ b/listing.c
@@ -173,9 +173,30 @@ static void list_out(int32_t offset, char *str)
     strcat(listdata, str);
 }
 
+static void list_address(int32_t offset, const char *brackets,
+                        int64_t addr, int size)
+{
+    char q[20];
+    char *r = q;
+
+    nasm_assert(size <= 8);
+
+    *r++ = brackets[0];
+    while (size--) {
+       HEX(r, addr);
+       addr >>= 8;
+       r += 2;
+    }
+    *r++ = brackets[1];
+    *r = '\0';
+    list_out(offset, q);
+}
+
 static void list_output(int32_t offset, const void *data,
                        enum out_type type, uint64_t size)
 {
+    char q[20];
+
     if (!listp || suppress || user_nolist)      /* fbk - 9/2/00 */
         return;
 
@@ -183,7 +204,7 @@ static void list_output(int32_t offset, const void *data,
     case OUT_RAWDATA:
     {
         uint8_t const *p = data;
-        char q[3];
+
        if (size == 0 && !listdata[0])
            listoffset = offset;
         while (size--) {
@@ -195,98 +216,22 @@ static void list_output(int32_t offset, const void *data,
        break;
     }
     case OUT_ADDRESS:
-    {
-        uint64_t d = *(int64_t *)data;
-        char q[20];
-        uint8_t p[8], *r = p;
-        if (size == 4) {
-            q[0] = '[';
-            q[9] = ']';
-            q[10] = '\0';
-            WRITELONG(r, d);
-            HEX(q + 1, p[0]);
-            HEX(q + 3, p[1]);
-            HEX(q + 5, p[2]);
-            HEX(q + 7, p[3]);
-            list_out(offset, q);
-        } else if (size == 8) {
-            q[0] = '[';
-            q[17] = ']';
-            q[18] = '\0';
-            WRITEDLONG(r, d);
-            HEX(q + 1,  p[0]);
-            HEX(q + 3,  p[1]);
-            HEX(q + 5,  p[2]);
-            HEX(q + 7,  p[3]);
-            HEX(q + 9,  p[4]);
-            HEX(q + 11, p[5]);
-            HEX(q + 13, p[6]);
-            HEX(q + 15, p[7]);
-            list_out(offset, q);
-        } else {
-            q[0] = '[';
-            q[5] = ']';
-            q[6] = '\0';
-            WRITESHORT(r, d);
-            HEX(q + 1, p[0]);
-            HEX(q + 3, p[1]);
-            list_out(offset, q);
-        }
+       list_address(offset, "[]", *(int64_t *)data, size);
+       break;
+    case OUT_REL1ADR:
+       list_address(offset, "()", *(int64_t *)data, 1);
        break;
-    }
     case OUT_REL2ADR:
-    {
-        uint32_t d = *(int32_t *)data;
-        char q[11];
-        uint8_t p[4], *r = p;
-        q[0] = '(';
-        q[5] = ')';
-        q[6] = '\0';
-        WRITESHORT(r, d);
-        HEX(q + 1, p[0]);
-        HEX(q + 3, p[1]);
-        list_out(offset, q);
+       list_address(offset, "()", *(int64_t *)data, 2);
        break;
-    }
     case OUT_REL4ADR:
-    {
-        uint32_t d = *(int32_t *)data;
-        char q[11];
-        uint8_t p[4], *r = p;
-        q[0] = '(';
-        q[9] = ')';
-        q[10] = '\0';
-        WRITELONG(r, d);
-        HEX(q + 1, p[0]);
-        HEX(q + 3, p[1]);
-        HEX(q + 5, p[2]);
-        HEX(q + 7, p[3]);
-        list_out(offset, q);
+       list_address(offset, "()", *(int64_t *)data, 4);
        break;
-    }
     case OUT_REL8ADR:
-    {
-        uint64_t d = *(int64_t *)data;
-        char q[19];
-        uint8_t p[8], *r = p;
-        q[0] = '(';
-        q[17] = ')';
-        q[18] = '\0';
-        WRITEDLONG(r, d);
-        HEX(q + 1, p[0]);
-        HEX(q + 3, p[1]);
-        HEX(q + 5, p[2]);
-        HEX(q + 7, p[3]);
-        HEX(q + 9, p[4]);
-        HEX(q + 11, p[5]);
-        HEX(q + 13, p[6]);
-        HEX(q + 15, p[7]);
-        list_out(offset, q);
+       list_address(offset, "()", *(int64_t *)data, 8);
        break;
-    }
     case OUT_RESERVE:
     {
-        char q[20];
         snprintf(q, sizeof(q), "<res %08"PRIX64">", size);
         list_out(offset, q);
        break;
diff --git a/macros/fp.mac b/macros/fp.mac
new file mode 100644 (file)
index 0000000..1334784
--- /dev/null
@@ -0,0 +1,54 @@
+;; --------------------------------------------------------------------------
+;;   
+;;   Copyright 2010 The NASM Authors - All Rights Reserved
+;;   See the file AUTHORS included with the NASM distribution for
+;;   the specific copyright holders.
+;;
+;;   Redistribution and use in source and binary forms, with or without
+;;   modification, are permitted provided that the following
+;;   conditions are met:
+;;
+;;   * Redistributions of source code must retain the above copyright
+;;     notice, this list of conditions and the following disclaimer.
+;;   * Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the following
+;;     disclaimer in the documentation and/or other materials provided
+;;     with the distribution.
+;;     
+;;     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+;;     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+;; --------------------------------------------------------------------------
+
+;;
+;; fp.mac
+;;
+;; Floating-point utility macros
+;;
+
+USE: fp
+
+%define        Inf             __Infinity__
+%define NaN            __QNaN__
+%define QNaN           __QNaN__
+%define SNaN           __SNaN__
+
+%define float8(x)      __float8__(x)
+%define float16(x)     __float16__(x)
+%define float32(x)     __float32__(x)
+%define float64(x)     __float64__(x)
+%define float80m(x)    __float80m__(x)
+%define float80e(x)    __float80e__(x)
+%define float128l(x)   __float128l__(x)
+%define float128h(x)   __float128h__(x)
index 51779c6..9b37f12 100644 (file)
@@ -150,26 +150,31 @@ USE: smartalign
     %error unknown alignment mode: %1
   %endif
   %ifnempty %2
-    %xdefine __ALIGN_JMP_THRESHOLD__ %2
+    %ifidni %2,nojmp
+      %xdefine __ALIGN_JMP_THRESHOLD__ -1
+    %else
+      %xdefine __ALIGN_JMP_THRESHOLD__ %2
+    %endif
   %endif
   %xdefine __ALIGNMODE__ %1,__ALIGN_JMP_THRESHOLD__
 %endmacro
 
 %unimacro align 1-2+.nolist
 %imacro align 1-2+.nolist
+  sectalign %1   ; align a segment as well
   %ifnempty %2
     times (((%1) - (($-$$) % (%1))) % (%1)) %2
   %else
     %push
     %assign %$pad (((%1) - (($-$$) % (%1))) % (%1))
-    %if %$pad > __ALIGN_JMP_THRESHOLD__
+    %if __ALIGN_JMP_THRESHOLD__ != -1 && %$pad > __ALIGN_JMP_THRESHOLD__
       jmp %$end
       ; We can't re-use %$pad here as $ will have changed!
       times (((%1) - (($-$$) % (%1))) % (%1)) nop
 %$end:
     %else
       times (%$pad / __ALIGN_%[__BITS__]BIT_GROUP__) \
-       db __ALIGN_%[__BITS__]BIT_%[__ALIGN_%[__BITS__]BIT_GROUP__]B__
+        db __ALIGN_%[__BITS__]BIT_%[__ALIGN_%[__BITS__]BIT_GROUP__]B__
       %assign %$pad %$pad % __ALIGN_%[__BITS__]BIT_GROUP__
       %if %$pad > 0
         db __ALIGN_%[__BITS__]BIT_%[%$pad]B__
diff --git a/nasm.c b/nasm.c
index d8f64c5..7a63afb 100644 (file)
--- a/nasm.c
+++ b/nasm.c
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *
- *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
 #include "output/outform.h"
 #include "listing.h"
 
+/*
+ * This is the maximum number of optimization passes to do.  If we ever
+ * find a case where the optimizer doesn't naturally converge, we might
+ * have to drop this value so the assembler doesn't appear to just hang.
+ */
+#define MAX_OPTIMIZE (INT_MAX >> 1)
+
 struct forwrefinfo {            /* info held on forward refs. */
     int lineno;
     int operand;
@@ -96,8 +103,8 @@ const struct dfmt *dfmt;
 static FILE *error_file;        /* Where to write error messages */
 
 FILE *ofile = NULL;
-int optimizing = -1;            /* number of optimization passes to take */
-static int sb, cmd_sb = 16;     /* by default */
+int optimizing = MAX_OPTIMIZE; /* number of optimization passes to take */
+static int sb, cmd_sb = 16;    /* by default */
 static uint32_t cmd_cpu = IF_PLEVEL;       /* highest level by default */
 static uint32_t cpu = IF_PLEVEL;   /* passed to insn_size & assemble.c */
 int64_t global_offset_changed;      /* referenced in labels.c */
@@ -261,7 +268,7 @@ static void define_macros_late(void)
 {
     char temp[128];
 
-    snprintf(temp, sizeof(temp), "__OUTPUT_FORMAT__=%s\n",
+    snprintf(temp, sizeof(temp), "__OUTPUT_FORMAT__=%s",
             ofmt->shortname);
     pp_pre_define(temp);
 }
@@ -659,7 +666,7 @@ static bool process_arg(char *p, char *q)
 
            if (!*param) {
                /* Naked -O == -Ox */
-               optimizing = INT_MAX >> 1; /* Almost unlimited */
+               optimizing = MAX_OPTIMIZE;
            } else {
                while (*param) {
                    switch (*param) {
@@ -683,7 +690,7 @@ static bool process_arg(char *p, char *q)
 
                    case 'x':
                        param++;
-                       optimizing = INT_MAX >> 1; /* Almost unlimited */
+                       optimizing = MAX_OPTIMIZE;
                        break;
 
                    default:
@@ -693,6 +700,8 @@ static bool process_arg(char *p, char *q)
                        break;
                    }
                }
+               if (optimizing > MAX_OPTIMIZE)
+                   optimizing = MAX_OPTIMIZE;
            }
            break;
        }
@@ -849,8 +858,8 @@ static bool process_arg(char *p, char *q)
             }
            do_warn = (param[0] == '+');
            param++;
-           goto set_warning;
-       set_warning:
+
+set_warning:
            for (i = 0; i <= ERR_WARN_MAX; i++)
                if (!nasm_stricmp(param, warnings[i].name))
                    break;
@@ -1232,7 +1241,21 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                         location.segment = seg;
                     }
                     break;
-                case D_EXTERN:         /* [EXTERN label:special] */
+                case D_SECTALIGN:        /* [SECTALIGN n] */
+                    {
+                        if (*value) {
+                            unsigned int align = atoi(value);
+                            if (!is_power2(align)) {
+                                nasm_error(ERR_NONFATAL,
+                                           "segment alignment `%s' is not power of two",
+                                            value);
+                            }
+                            /* callee should be able to handle all details */
+                            ofmt->sectalign(location.segment, align);
+                        }
+                    }
+                    break;
+                case D_EXTERN:              /* [EXTERN label:special] */
                     if (*value == '$')
                         value++;        /* skip initial $ if present */
                     if (pass0 == 2) {
@@ -1496,10 +1519,13 @@ static void assemble_file(char *fname, StrList **depend_ptr)
                    }
                    break;
                 default:
-                   if (!d || !ofmt->directive(d, value, pass2))
-                        nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
-                                     "unrecognised directive [%s]",
-                                     directive);
+                   if (ofmt->directive(d, value, pass2))
+                       break;
+                   /* else fall through */
+               case D_unknown:
+                   nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
+                              "unrecognised directive [%s]",
+                              directive);
                    break;
                 }
                if (err) {
@@ -1750,16 +1776,16 @@ static enum directives getkw(char **directive, char **value)
 
     /* it should be enclosed in [ ] */
     if (*buf != '[')
-        return D_NONE;
+        return D_none;
     q = strchr(buf, ']');
     if (!q)
-        return D_NONE;
+        return D_none;
 
     /* stip off the comments */
     p = strchr(buf, ';');
     if (p) {
         if (p < q) /* ouch! somwhere inside */
-            return D_NONE;
+            return D_none;
         *p = '\0';
     }
 
@@ -1771,7 +1797,7 @@ static enum directives getkw(char **directive, char **value)
     p = nasm_skip_spaces(++buf);
     q = nasm_skip_word(p);
     if (!q)
-        return D_NONE; /* sigh... no value there */
+        return D_none; /* sigh... no value there */
     *q = '\0';
     *directive = p;
 
diff --git a/nasm.h b/nasm.h
index 5d5aae7..76f561f 100644 (file)
--- a/nasm.h
+++ b/nasm.h
@@ -45,7 +45,7 @@
 #include "nasmlib.h"
 #include "preproc.h"
 #include "insnsi.h"            /* For enum opcode */
-#include "directives.h"                /* For enum directive */
+#include "directiv.h"          /* For enum directive */
 #include "opflags.h"
 
 #define NO_SEG -1L              /* null segment value */
@@ -101,6 +101,7 @@ enum out_type {
     OUT_RAWDATA,               /* Plain bytes */
     OUT_ADDRESS,               /* An address (symbol value) */
     OUT_RESERVE,               /* Reserved bytes (RESB et al) */
+    OUT_REL1ADR,               /* 1-byte relative address */
     OUT_REL2ADR,               /* 2-byte relative address */
     OUT_REL4ADR,               /* 4-byte relative address */
     OUT_REL8ADR,               /* 8-byte relative address */
@@ -682,6 +683,12 @@ struct ofmt {
     int32_t (*section) (char *name, int pass, int *bits);
 
     /*
+     * This procedure is called to modify section alignment,
+     * note there is a trick, the alignment can only increase
+     */
+    void (*sectalign)(int32_t seg, unsigned int value);
+
+    /*
      * This procedure is called to modify the segment base values
      * returned from the SEG operator. It is given a segment base
      * value (i.e. a segment value with the low bit set), and is
index 22d3b62..460186e 100644 (file)
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *   
- *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
@@ -90,7 +90,12 @@ void nasm_init_malloc_error(void)
 {
 #ifdef LOGALLOC
     logfp = fopen("malloc.log", "w");
-    setvbuf(logfp, NULL, _IOLBF, BUFSIZ);
+    if (logfp) {
+        setvbuf(logfp, NULL, _IOLBF, BUFSIZ);
+    } else {
+        nasm_error(ERR_NONFATAL | ERR_NOFILE, "Unable to open %s", file);
+        logfp = stderr;
+    }
     fprintf(logfp, "null pointer is %p\n", NULL);
 #endif
 }
@@ -565,7 +570,7 @@ static const char *prefix_names[] = {
 const char *prefix_name(int token)
 {
     unsigned int prefix = token-PREFIX_ENUM_START;
-    if (prefix > elements(prefix_names))
+    if (prefix >= ARRAY_SIZE(prefix_names))
        return NULL;
 
     return prefix_names[prefix];
@@ -690,6 +695,81 @@ char *nasm_zap_spaces_rev(char *p)
     return p;
 }
 
+/* zap leading and trailing spaces */
+char *nasm_trim_spaces(char *p)
+{
+    p = nasm_zap_spaces_fwd(p);
+    nasm_zap_spaces_fwd(nasm_skip_word(p));
+
+    return p;
+}
+
+/*
+ * return the word extracted from a stream
+ * or NULL if nothing left
+ */
+char *nasm_get_word(char *p, char **tail)
+{
+    char *word = nasm_skip_spaces(p);
+    char *next = nasm_skip_word(word);
+
+    if (word && *word) {
+        if (*next)
+            *next++ = '\0';
+    } else
+        word = next = NULL;
+
+    /* NOTE: the tail may start with spaces */
+    *tail = next;
+
+    return word;
+}
+
+/*
+ * Extract "opt=val" values from the stream and
+ * returns "opt"
+ *
+ * Exceptions:
+ * 1) If "=val" passed the NULL returned though
+ *    you may continue handling the tail via "next"
+ * 2) If "=" passed the NULL is returned and "val"
+ *    is set to NULL as well
+ */
+char *nasm_opt_val(char *p, char **val, char **next)
+{
+    char *q, *opt, *nxt;
+
+    opt = *val = *next = NULL;
+
+    p = nasm_get_word(p, &nxt);
+    if (!p)
+        return NULL;
+
+    q = strchr(p, '=');
+    if (q) {
+        if (q == p)
+            p = NULL;
+        *q++='\0';
+        if (*q) {
+            *val = q;
+        } else {
+            q = nasm_get_word(q + 1, &nxt);
+            if (q)
+                *val = q;
+        }
+    } else {
+        q = nasm_skip_spaces(nxt);
+        if (q && *q == '=') {
+            q = nasm_get_word(q + 1, &nxt);
+            if (q)
+                *val = q;
+        }
+    }
+
+    *next = nxt;
+    return p;
+}
+
 /*
  * initialized data bytes length from opcode
  */
index 793fccd..2c335e1 100644 (file)
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -239,8 +239,7 @@ void standard_extension(char *inname, char *outname, char *extension);
  * This is a useful #define which I keep meaning to use more often:
  * the number of elements of a statically defined array.
  */
-
-#define elements(x)     ( sizeof(x) / sizeof(*(x)) )
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
 /*
  * List handling
@@ -393,6 +392,9 @@ char *nasm_skip_spaces(const char *p);
 char *nasm_skip_word(const char *p);
 char *nasm_zap_spaces_fwd(char *p);
 char *nasm_zap_spaces_rev(char *p);
+char *nasm_trim_spaces(char *p);
+char *nasm_get_word(char *p, char **tail);
+char *nasm_opt_val(char *p, char **opt, char **val);
 
 const char *prefix_name(int);
 
@@ -445,9 +447,31 @@ static inline bool overflow_unsigned(int64_t value, int bytes)
     return value < vmin || value > vmax;
 }
 
+static inline int64_t signed_bits(int64_t value, int bits)
+{
+    if (bits < 64) {
+        value &= ((int64_t)1 << bits) - 1;
+        if (value & (int64_t)1 << (bits - 1))
+            value |= (int64_t)-1 << bits;
+    }
+    return value;
+}
+
 int idata_bytes(int opcode);
 
 /* check if value is power of 2 */
 #define is_power2(v)   ((v) && ((v) & ((v) - 1)) == 0)
 
+/*
+ * floor(log2(v))
+ */
+int ilog2_32(uint32_t v);
+int ilog2_64(uint64_t v);
+
+/*
+ * v == 0 ? 0 : is_power2(x) ? ilog2_X(v) : -1
+ */
+int alignlog2_32(uint32_t v);
+int alignlog2_64(uint64_t v);
+
 #endif
index ebdbfe6..ed3467e 100644 (file)
 #define SHN_COMMON      0xfff2
 #define SHN_HIRESERVE   0xffff
 
+/* Section align flag */
+#define SHA_ANY         1       /* No alignment constraint */
+
 /* Lenght of magic at the start of a file */
 #define EI_NIDENT       16
 
index 228fa16..196a09d 100644 (file)
@@ -49,3 +49,9 @@ int null_directive(enum directives directive, char *value, int pass)
     (void)pass;
     return 0;
 }
+
+void null_sectalign(int32_t seg, unsigned int value)
+{
+    (void)seg;
+    (void)value;
+}
index 31ce5b5..e096392 100644 (file)
@@ -924,6 +924,7 @@ struct ofmt of_aout = {
     aout_out,
     aout_deflabel,
     aout_section_names,
+    null_sectalign,
     aout_segbase,
     null_directive,
     aout_filename,
@@ -946,6 +947,7 @@ struct ofmt of_aoutb = {
     aout_out,
     aout_deflabel,
     aout_section_names,
+    null_sectalign,
     aout_segbase,
     null_directive,
     aout_filename,
index 877eebd..b288637 100644 (file)
@@ -638,6 +638,7 @@ struct ofmt of_as86 = {
     as86_out,
     as86_deflabel,
     as86_section_names,
+    null_sectalign,
     as86_segbase,
     null_directive,
     as86_filename,
index 332d84e..4012cc9 100644 (file)
@@ -152,8 +152,6 @@ static struct Reloc {
     struct Section *target;
 } *relocs, **reloctail;
 
-static uint8_t format_mode;       /* 0 = original bin, 1 = extended bin */
-static int32_t current_section;    /* only really needed if format_mode = 0 */
 static uint64_t origin;
 static int origin_defined;
 
@@ -540,26 +538,17 @@ static void bin_cleanup(int debuginfo)
         saa_rewind(s->contents);
     /* Apply relocations. */
     list_for_each(r, relocs) {
-        uint8_t *p, *q, mydata[8];
+        uint8_t *p, mydata[8];
         int64_t l;
+        int b;
+
+        nasm_assert(r->bytes <= 8);
 
         saa_fread(r->target->contents, r->posn, mydata, r->bytes);
-        p = q = mydata;
-        l = *p++;
-
-        if (r->bytes > 1) {
-            l += ((int64_t)*p++) << 8;
-            if (r->bytes >= 4) {
-                l += ((int64_t)*p++) << 16;
-                l += ((int64_t)*p++) << 24;
-            }
-            if (r->bytes == 8) {
-                l += ((int64_t)*p++) << 32;
-                l += ((int64_t)*p++) << 40;
-                l += ((int64_t)*p++) << 48;
-                l += ((int64_t)*p++) << 56;
-            }
-        }
+        p = mydata;
+        l = 0;
+        for (b = r->bytes - 1; b >= 0; b--)
+            l = (l << 8) + mydata[b];
 
         s = find_section_by_index(r->secref);
         if (s) {
@@ -576,12 +565,7 @@ static void bin_cleanup(int debuginfo)
                 l -= s->vstart;
         }
 
-        if (r->bytes >= 4)
-            WRITEDLONG(q, l);
-        else if (r->bytes == 2)
-            WRITESHORT(q, l);
-        else
-            *q++ = (uint8_t)(l & 0xFF);
+        WRITEADDR(p, l, r->bytes);
         saa_fwrite(r->target->contents, r->posn, mydata, r->bytes);
     }
 
@@ -778,7 +762,8 @@ static void bin_out(int32_t segto, const void *data,
         nasm_error(ERR_WARNING, "attempt to initialize memory in a"
               " nobits section: ignored");
 
-    if (type == OUT_ADDRESS) {
+    switch (type) {
+    case OUT_ADDRESS:
         if (segment != NO_SEG && !find_section_by_index(segment)) {
             if (segment % 2)
                 nasm_error(ERR_NONFATAL, "binary output format does not support"
@@ -795,20 +780,26 @@ static void bin_out(int32_t segto, const void *data,
            WRITEADDR(p, *(int64_t *)data, size);
             saa_wbytes(s->contents, mydata, size);
         }
-        s->length += size;
-    } else if (type == OUT_RAWDATA) {
+       break;
+
+    case OUT_RAWDATA:
         if (s->flags & TYPE_PROGBITS)
             saa_wbytes(s->contents, data, size);
-        s->length += size;
-    } else if (type == OUT_RESERVE) {
+       break;
+
+    case OUT_RESERVE:
         if (s->flags & TYPE_PROGBITS) {
             nasm_error(ERR_WARNING, "uninitialized space declared in"
                   " %s section: zeroing", s->name);
             saa_wbytes(s->contents, NULL, size);
         }
-        s->length += size;
-    } else if (type == OUT_REL2ADR || type == OUT_REL4ADR ||
-              type == OUT_REL8ADR) {
+       break;
+
+    case OUT_REL1ADR:
+    case OUT_REL2ADR:
+    case OUT_REL4ADR:
+    case OUT_REL8ADR:
+    {
        int64_t addr = *(int64_t *)data - size;
        size = realsize(type, size);
         if (segment != NO_SEG && !find_section_by_index(segment)) {
@@ -826,8 +817,15 @@ static void bin_out(int32_t segto, const void *data,
            WRITEADDR(p, addr - s->length, size);
             saa_wbytes(s->contents, mydata, size);
         }
-        s->length += size;
+       break;
     }
+
+    default:
+       nasm_error(ERR_NONFATAL, "unsupported relocation type %d\n", type);
+       break;
+    }
+
+    s->length += size;
 }
 
 static void bin_deflabel(char *name, int32_t segment, int64_t offset,
@@ -889,7 +887,7 @@ static int bin_read_attribute(char **line, int *attribute,
     if (!nasm_strnicmp(*line, "align=", 6)) {
         *attribute = ATTRIB_ALIGN;
         attrib_name_size = 6;
-    } else if (format_mode) {
+    } else {
         if (!nasm_strnicmp(*line, "start=", 6)) {
             *attribute = ATTRIB_START;
             attrib_name_size = 6;
@@ -919,8 +917,7 @@ static int bin_read_attribute(char **line, int *attribute,
             return 1;
         } else
             return 0;
-    } else
-        return 0;
+    }
 
     /* Find the end of the expression. */
     if ((*line)[attrib_name_size] != '(') {
@@ -999,6 +996,20 @@ static int bin_read_attribute(char **line, int *attribute,
     return 1;
 }
 
+static void bin_sectalign(int32_t seg, unsigned int value)
+{
+    struct Section *s = find_section_by_index(seg);
+
+    if (!s || !is_power2(value))
+        return;
+
+    if (value > s->align)
+        s->align = value;
+
+    if (!(s->flags & ALIGN_DEFINED))
+        s->flags |= ALIGN_DEFINED;
+}
+
 static void bin_assign_attributes(struct Section *sec, char *astring)
 {
     int attribute, check;
@@ -1050,29 +1061,24 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
 
             /* Handle align attribute. */
         case ATTRIB_ALIGN:
-            if (!format_mode && (!strcmp(sec->name, ".text")))
-                nasm_error(ERR_NONFATAL, "cannot specify an alignment"
-                      " to the .text section");
-            else {
-                if (!value || ((value - 1) & value))
-                    nasm_error(ERR_NONFATAL, "argument to `align' is not a"
-                          " power of two");
-                else {          /* Alignment is already satisfied if the previous
-                                 * align value is greater. */
-                    if ((sec->flags & ALIGN_DEFINED)
-                        && (value < sec->align))
-                        value = sec->align;
-
-                    /* Don't allow a conflicting align value. */
-                    if ((sec->flags & START_DEFINED)
-                        && (sec->start & (value - 1)))
-                        nasm_error(ERR_NONFATAL,
-                              "`align' value conflicts "
-                              "with section start address");
-                    else {
-                        sec->align = value;
-                        sec->flags |= ALIGN_DEFINED;
-                    }
+            if (!value || ((value - 1) & value)) {
+                nasm_error(ERR_NONFATAL,
+                           "argument to `align' is not a power of two");
+            } else {
+                /*
+                 * Alignment is already satisfied if
+                 * the previous align value is greater
+                 */
+                if ((sec->flags & ALIGN_DEFINED) && (value < sec->align))
+                    value = sec->align;
+
+                /* Don't allow a conflicting align value. */
+                if ((sec->flags & START_DEFINED) && (sec->start & (value - 1))) {
+                    nasm_error(ERR_NONFATAL,
+                              "`align' value conflicts with section start address");
+                } else {
+                    sec->align  = value;
+                    sec->flags |= ALIGN_DEFINED;
                 }
             }
             continue;
@@ -1228,15 +1234,14 @@ static int32_t bin_secname(char *name, int pass, int *bits)
                             ALIGN_DEFINED | VALIGN_DEFINED);
 
         /* Define section start and vstart labels. */
-        if (format_mode && (pass != 1))
+        if (pass != 1)
             bin_define_section_labels();
 
         /* Establish the default (.text) section. */
         *bits = 16;
         sec = find_section_by_name(".text");
         sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
-        current_section = sec->vstart_index;
-        return current_section;
+        return sec->vstart_index;
     }
 
     /* Attempt to find the requested section.  If it does not
@@ -1254,10 +1259,6 @@ static int32_t bin_secname(char *name, int pass, int *bits)
         else if (!strcmp(name, ".bss")) {
             sec->flags |= TYPE_DEFINED | TYPE_NOBITS;
             sec->ifollows = NULL;
-        } else if (!format_mode) {
-            nasm_error(ERR_NONFATAL, "section name must be "
-                  ".text, .data, or .bss");
-            return current_section;
         }
     }
 
@@ -1273,9 +1274,7 @@ static int32_t bin_secname(char *name, int pass, int *bits)
         sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
 #endif
 
-    /* Set the current section and return. */
-    current_section = sec->vstart_index;
-    return current_section;
+    return sec->vstart_index;
 }
 
 static int bin_directive(enum directives directive, char *args, int pass)
@@ -1428,8 +1427,6 @@ static void binfmt_init(void)
     origin_defined = 0;
     no_seg_labels = NULL;
     nsl_tail = &no_seg_labels;
-    format_mode = 1;            /* Extended bin format
-                                 * (set this to zero for old bin format). */
 
     /* Create default section (.text). */
     sections = last_section = nasm_malloc(sizeof(struct Section));
@@ -1443,7 +1440,7 @@ static void binfmt_init(void)
     last_section->labels = NULL;
     last_section->labels_end = &(last_section->labels);
     last_section->start_index = seg_alloc();
-    last_section->vstart_index = current_section = seg_alloc();
+    last_section->vstart_index = seg_alloc();
 }
 
 /* Generate binary file output */
@@ -1672,6 +1669,7 @@ struct ofmt of_bin = {
     bin_out,
     bin_deflabel,
     bin_secname,
+    bin_sectalign,
     bin_segbase,
     bin_directive,
     bin_filename,
@@ -1690,6 +1688,7 @@ struct ofmt of_ith = {
     bin_out,
     bin_deflabel,
     bin_secname,
+    bin_sectalign,
     bin_segbase,
     bin_directive,
     ith_filename,
@@ -1708,6 +1707,7 @@ struct ofmt of_srec = {
     bin_out,
     bin_deflabel,
     bin_secname,
+    bin_sectalign,
     bin_segbase,
     bin_directive,
     srec_filename,
index 5dc4023..5b232bb 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
- *   
- *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
@@ -14,7 +14,7 @@
  *     copyright notice, this list of conditions and the following
  *     disclaimer in the documentation and/or other materials provided
  *     with the distribution.
- *     
+ *
  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -31,9 +31,9 @@
  *
  * ----------------------------------------------------------------------- */
 
-/* 
- * outcoff.c   output routines for the Netwide Assembler to produce
- *             COFF object files (for DJGPP and Win32)
+/*
+ * outcoff.c    output routines for the Netwide Assembler to produce
+ *              COFF object files (for DJGPP and Win32)
  */
 
 #include "compiler.h"
@@ -52,6 +52,7 @@
 #include "eval.h"
 #include "output/outform.h"
 #include "output/outlib.h"
+#include "output/pecoff.h"
 
 #if defined(OF_COFF) || defined(OF_WIN32) || defined(OF_WIN64)
 
@@ -106,8 +107,8 @@ static int32_t imagebase_sect;
 
 struct Reloc {
     struct Reloc *next;
-    int32_t address;           /* relative to _start_ of section */
-    int32_t symbol;            /* symbol number */
+    int32_t address;            /* relative to _start_ of section */
+    int32_t symbol;             /* symbol number */
     enum {
         SECT_SYMBOLS,
         ABS_SYMBOL,
@@ -116,24 +117,15 @@ struct Reloc {
     int16_t type;
 };
 
-/* possible values for Reloc->type */
-#define IMAGE_REL_AMD64_ADDR64         0x0001
-#define IMAGE_REL_AMD64_ADDR32         0x0002
-#define IMAGE_REL_AMD64_ADDR32NB       0x0003
-#define IMAGE_REL_AMD64_REL32          0x0004
-#define IMAGE_REL_I386_DIR32           0x0006
-#define IMAGE_REL_I386_DIR32NB         0x0007
-#define IMAGE_REL_I386_REL32           0x0014
-
 struct Symbol {
     char name[9];
-    int32_t strpos;            /* string table position of name */
-    int32_t value;             /* address, or COMMON variable size */
+    int32_t strpos;             /* string table position of name */
+    int32_t value;              /* address, or COMMON variable size */
     int section;                /* section number where it's defined
                                  * - in COFF codes, not NASM codes */
-    bool is_global;              /* is it a global symbol or not? */
-    int16_t type;              /* 0 - notype, 0x20 - function */
-    int32_t namlen;            /* full name length */
+    bool is_global;             /* is it a global symbol or not? */
+    int16_t type;               /* 0 - notype, 0x20 - function */
+    int32_t namlen;             /* full name length */
 };
 
 static char coff_infile[FILENAME_MAX];
@@ -144,16 +136,65 @@ struct Section {
     int nrelocs;
     int32_t index;
     struct Reloc *head, **tail;
-    uint32_t flags;        /* section flags */
+    uint32_t flags;             /* section flags */
     char name[9];
     int32_t pos, relpos;
 };
 
-#define TEXT_FLAGS ((win32 | win64) ? 0x60500020L : 0x20L)
-#define DATA_FLAGS ((win32 | win64) ? 0xC0300040L : 0x40L)
-#define BSS_FLAGS ((win32 | win64) ? 0xC0300080L : 0x80L)
-#define INFO_FLAGS 0x00100A00L
-#define RDATA_FLAGS ((win32 | win64) ? 0x40400040L : 0x40L)
+/*
+ * Some common section flags by default
+ */
+#define TEXT_FLAGS_WIN                                  \
+        (IMAGE_SCN_CNT_CODE                     |       \
+         IMAGE_SCN_ALIGN_16BYTES                |       \
+         IMAGE_SCN_MEM_EXECUTE                  |       \
+         IMAGE_SCN_MEM_READ)
+#define TEXT_FLAGS_DOS                                  \
+        (IMAGE_SCN_CNT_CODE)
+
+#define DATA_FLAGS_WIN                                  \
+        (IMAGE_SCN_CNT_INITIALIZED_DATA         |       \
+         IMAGE_SCN_ALIGN_4BYTES                 |       \
+         IMAGE_SCN_MEM_READ                     |       \
+         IMAGE_SCN_MEM_WRITE)
+#define DATA_FLAGS_DOS                                  \
+        (IMAGE_SCN_CNT_INITIALIZED_DATA)
+
+#define BSS_FLAGS_WIN                                   \
+        (IMAGE_SCN_CNT_UNINITIALIZED_DATA       |       \
+         IMAGE_SCN_ALIGN_4BYTES                 |       \
+         IMAGE_SCN_MEM_READ                     |       \
+         IMAGE_SCN_MEM_WRITE)
+#define BSS_FLAGS_DOS                                   \
+        (IMAGE_SCN_CNT_UNINITIALIZED_DATA)
+
+#define RDATA_FLAGS_WIN                                 \
+        (IMAGE_SCN_CNT_INITIALIZED_DATA         |       \
+         IMAGE_SCN_ALIGN_8BYTES                 |       \
+         IMAGE_SCN_MEM_READ)
+
+#define RDATA_FLAGS_DOS                                 \
+        (IMAGE_SCN_CNT_INITIALIZED_DATA)
+
+#define PDATA_FLAGS                                     \
+        (IMAGE_SCN_CNT_INITIALIZED_DATA         |       \
+         IMAGE_SCN_ALIGN_4BYTES                 |       \
+         IMAGE_SCN_MEM_READ)
+
+#define XDATA_FLAGS                                     \
+        (IMAGE_SCN_CNT_INITIALIZED_DATA         |       \
+         IMAGE_SCN_ALIGN_8BYTES                 |       \
+         IMAGE_SCN_MEM_READ)
+
+#define INFO_FLAGS                                      \
+        (IMAGE_SCN_ALIGN_1BYTES                 |       \
+         IMAGE_SCN_LNK_INFO                     |       \
+         IMAGE_SCN_LNK_REMOVE)
+
+#define TEXT_FLAGS      ((win32 | win64) ? TEXT_FLAGS_WIN  : TEXT_FLAGS_DOS)
+#define DATA_FLAGS      ((win32 | win64) ? DATA_FLAGS_WIN  : DATA_FLAGS_DOS)
+#define BSS_FLAGS       ((win32 | win64) ? BSS_FLAGS_WIN   : BSS_FLAGS_DOS)
+#define RDATA_FLAGS     ((win32 | win64) ? RDATA_FLAGS_WIN : RDATA_FLAGS_DOS)
 
 #define SECT_DELTA 32
 static struct Section **sects;
@@ -172,8 +213,7 @@ static struct SAA *strs;
 static uint32_t strslen;
 
 static void coff_gen_init(void);
-static void coff_sect_write(struct Section *, const uint8_t *,
-                            uint32_t);
+static void coff_sect_write(struct Section *, const uint8_t *, uint32_t);
 static void coff_write(void);
 static void coff_section_header(char *, int32_t, int32_t, int32_t, int32_t, int, int32_t);
 static void coff_write_relocs(struct Section *);
@@ -264,7 +304,7 @@ static int coff_make_section(char *name, uint32_t flags)
     s->flags = flags;
 
     if (nsects >= sectlen) {
-       sectlen += SECT_DELTA;
+        sectlen += SECT_DELTA;
         sects = nasm_realloc(sects, sectlen * sizeof(*sects));
     }
     sects[nsects++] = s;
@@ -272,6 +312,11 @@ static int coff_make_section(char *name, uint32_t flags)
     return nsects - 1;
 }
 
+static inline int32_t coff_sectalign_flags(unsigned int align)
+{
+    return (ilog2_32(align) + 1) << 20;
+}
+
 static int32_t coff_section_names(char *name, int pass, int *bits)
 {
     char *p;
@@ -354,13 +399,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
                               " to better than 64-byte boundaries");
                     else {
                         align_and = ~0x00F00000L;
-                        align_or = (align == 1 ? 0x00100000L :
-                                    align == 2 ? 0x00200000L :
-                                    align == 4 ? 0x00300000L :
-                                    align == 8 ? 0x00400000L :
-                                    align == 16 ? 0x00500000L :
-                                    align ==
-                                    32 ? 0x00600000L : 0x00700000L);
+                        align_or  = coff_sectalign_flags(align);
                     }
                 }
             }
@@ -378,10 +417,10 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
                 flags = RDATA_FLAGS;
             else if (!strcmp(name, ".bss"))
                 flags = BSS_FLAGS;
-           else if (win64 && !strcmp(name, ".pdata"))
-               flags = 0x40300040; /* rdata align=4 */
-           else if (win64 && !strcmp(name, ".xdata"))
-               flags = 0x40400040; /* rdate align=8 */
+            else if (win64 && !strcmp(name, ".pdata"))
+                flags = PDATA_FLAGS;
+            else if (win64 && !strcmp(name, ".xdata"))
+                flags = XDATA_FLAGS;
             else
                 flags = TEXT_FLAGS;
         }
@@ -410,15 +449,15 @@ static void coff_deflabel(char *name, int32_t segment, int64_t offset,
               " special symbol types");
 
     if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
-       if (strcmp(name,WRT_IMAGEBASE))
+        if (strcmp(name,WRT_IMAGEBASE))
             nasm_error(ERR_NONFATAL, "unrecognized special symbol `%s'", name);
         return;
     }
 
     if (strlen(name) > 8) {
-       size_t nlen = strlen(name)+1;
+        size_t nlen = strlen(name)+1;
         saa_wbytes(strs, name, nlen);
-       strslen += nlen;
+        strslen += nlen;
     } else
         pos = -1;
 
@@ -429,7 +468,7 @@ static void coff_deflabel(char *name, int32_t segment, int64_t offset,
     if (pos == -1)
         strcpy(sym->name, name);
     sym->is_global = !!is_global;
-    sym->type = 0;             /* Default to T_NULL (no type) */
+    sym->type = 0;              /* Default to T_NULL (no type) */
     if (segment == NO_SEG)
         sym->section = -1;      /* absolute symbol */
     else {
@@ -452,9 +491,8 @@ static void coff_deflabel(char *name, int32_t segment, int64_t offset,
      * define the references from external-symbol segment numbers
      * to these symbol records.
      */
-    if (sym->section == 0) {
+    if (sym->section == 0)
         bsym = raa_write(bsym, segment, nsyms);
-    }
 
     if (segment != NO_SEG)
         symval = raa_write(symval, segment, sym->section ? 0 : sym->value);
@@ -463,7 +501,7 @@ static void coff_deflabel(char *name, int32_t segment, int64_t offset,
 }
 
 static int32_t coff_add_reloc(struct Section *sect, int32_t segment,
-                               int16_t type)
+                              int16_t type)
 {
     struct Reloc *r;
 
@@ -472,17 +510,18 @@ static int32_t coff_add_reloc(struct Section *sect, int32_t segment,
     r->next = NULL;
 
     r->address = sect->len;
-    if (segment == NO_SEG)
+    if (segment == NO_SEG) {
         r->symbol = 0, r->symbase = ABS_SYMBOL;
-    else {
+    else {
         int i;
         r->symbase = REAL_SYMBOLS;
-        for (i = 0; i < nsects; i++)
+        for (i = 0; i < nsects; i++) {
             if (segment == sects[i]->index) {
                 r->symbol = i * 2;
                 r->symbase = SECT_SYMBOLS;
                 break;
             }
+        }
         if (r->symbase == REAL_SYMBOLS)
             r->symbol = raa_read(bsym, segment);
     }
@@ -495,12 +534,12 @@ static int32_t coff_add_reloc(struct Section *sect, int32_t segment,
      */
     if (r->symbase == REAL_SYMBOLS && !(win32 | win64))
         return raa_read(symval, segment);
-    else
-        return 0;
+
+    return 0;
 }
 
 static void coff_out(int32_t segto, const void *data,
-                    enum out_type type, uint64_t size,
+                     enum out_type type, uint64_t size,
                      int32_t segment, int32_t wrt)
 {
     struct Section *s;
@@ -523,11 +562,12 @@ static void coff_out(int32_t segto, const void *data,
     }
 
     s = NULL;
-    for (i = 0; i < nsects; i++)
+    for (i = 0; i < nsects; i++) {
         if (segto == sects[i]->index) {
             s = sects[i];
             break;
         }
+    }
     if (!s) {
         int tempint;            /* ignored */
         if (segto != coff_section_names(".text", 2, &tempint))
@@ -537,9 +577,10 @@ static void coff_out(int32_t segto, const void *data,
     }
 
     /* magically default to 'wrt ..imagebase' in .pdata and .xdata */
-    if (win64 && wrt == NO_SEG &&
-       (!strcmp(s->name,".pdata") || !strcmp(s->name,".xdata")))
-       wrt = imagebase_sect;
+    if (win64 && wrt == NO_SEG) {
+        if (!strcmp(s->name,".pdata") || !strcmp(s->name,".xdata"))
+            wrt = imagebase_sect;
+    }
 
     if (!s->data && type != OUT_RESERVE) {
         nasm_error(ERR_WARNING, "attempt to initialize memory in"
@@ -561,10 +602,10 @@ static void coff_out(int32_t segto, const void *data,
         coff_sect_write(s, data, size);
     } else if (type == OUT_ADDRESS) {
         if (!(win64)) {
-            if (size != 4 && (segment != NO_SEG || wrt != NO_SEG))
+            if (size != 4 && (segment != NO_SEG || wrt != NO_SEG)) {
                 nasm_error(ERR_NONFATAL, "COFF format does not support non-32-bit"
                       " relocations");
-            else {
+            else {
                 int32_t fix = 0;
                 if (segment != NO_SEG || wrt != NO_SEG) {
                     if (wrt != NO_SEG) {
@@ -584,17 +625,17 @@ static void coff_out(int32_t segto, const void *data,
             int32_t fix = 0;
             p = mydata;
             if (size == 8) {
-               if (wrt == imagebase_sect) {
-                   nasm_error(ERR_NONFATAL, "operand size mismatch: 'wrt "
-                       WRT_IMAGEBASE "' is a 32-bit operand");
-               }
+                if (wrt == imagebase_sect) {
+                    nasm_error(ERR_NONFATAL, "operand size mismatch: 'wrt "
+                               WRT_IMAGEBASE "' is a 32-bit operand");
+                }
                 fix = coff_add_reloc(s, segment, IMAGE_REL_AMD64_ADDR64);
                 WRITEDLONG(p, *(int64_t *)data + fix);
                 coff_sect_write(s, mydata, size);
             } else {
                 fix = coff_add_reloc(s, segment,
-                       wrt == imagebase_sect ? IMAGE_REL_AMD64_ADDR32NB:
-                                               IMAGE_REL_AMD64_ADDR32);
+                        wrt == imagebase_sect ?        IMAGE_REL_AMD64_ADDR32NB:
+                                                IMAGE_REL_AMD64_ADDR32);
                 WRITELONG(p, *(int64_t *)data + fix);
                 coff_sect_write(s, mydata, size);
             }
@@ -615,7 +656,7 @@ static void coff_out(int32_t segto, const void *data,
                       " segment base references");
             } else
                 fix = coff_add_reloc(s, segment,
-                       win64 ? IMAGE_REL_AMD64_REL32 : IMAGE_REL_I386_REL32);
+                        win64 ? IMAGE_REL_AMD64_REL32 : IMAGE_REL_I386_REL32);
             p = mydata;
             if (win32 | win64) {
                 WRITELONG(p, *(int64_t *)data + 4 - size + fix);
@@ -644,9 +685,9 @@ typedef struct tagString {
 #define EXPORT_SECTION_NAME ".drectve"
 #define EXPORT_SECTION_FLAGS INFO_FLAGS
 /*
-#define EXPORT_SECTION_NAME ".text"
-#define EXPORT_SECTION_FLAGS TEXT_FLAGS
-*/
+ * #define EXPORT_SECTION_NAME ".text"
+ * #define EXPORT_SECTION_FLAGS TEXT_FLAGS
+ */
 
 static STRING *Exports = NULL;
 static struct Section *directive_sec;
@@ -665,12 +706,12 @@ void AddExport(char *name)
         for (i = 0; i < nsects; i++) {
             if (!strcmp(EXPORT_SECTION_NAME, sects[i]->name))
                 break;
-       }
+        }
 
         if (i == nsects)
-           i = coff_make_section(EXPORT_SECTION_NAME, EXPORT_SECTION_FLAGS);
+            i = coff_make_section(EXPORT_SECTION_NAME, EXPORT_SECTION_FLAGS);
 
-       directive_sec = sects[i];
+        directive_sec = sects[i];
         Exports = newS;
     } else {
         while (rvp->next) {
@@ -731,62 +772,68 @@ static int coff_directives(enum directives directive, char *value, int pass)
     }
     case D_SAFESEH:
     {
-       static int sxseg=-1;
-       int i;
-
-       if (!win32)             /* Only applicable for -f win32 */
-           return 0;
-
-       if (sxseg==-1)
-       {   for (i = 0; i < nsects; i++)
-               if (!strcmp(".sxdata",sects[i]->name))
-                   break;
-           if (i == nsects)
-               sxseg = coff_make_section(".sxdata",0x200);
-           else
-               sxseg = i;
-       }
-       /* pass0 == 2 is the only time when the full set of symbols are
-          guaranteed to be present; it is the final output pass. */
-       if (pass0 == 2) {
-           uint32_t n;
-           saa_rewind(syms);
-           for (n = 0; n < nsyms; n++) {
-               struct Symbol *sym = saa_rstruct(syms);
-               bool equals;
-
-               /* sym->strpos is biased by 4, because symbol
-                * table is prefixed with table length */
-               if (sym->strpos >=4) {
-                   char *name = nasm_malloc(sym->namlen+1);
-                   saa_fread(strs, sym->strpos-4, name, sym->namlen);
-                   name[sym->namlen] = '\0';
-                   equals = !strcmp(value,name);
-                   nasm_free(name);
-               }
-               else
-                   equals = !strcmp(value,sym->name);
-
-               if (equals) {
-                   /* this value arithmetics effectively reflects
-                    * initsym in coff_write(): 2 for file, 1 for
-                    * .absolute and two per each section */
-                   unsigned char value[4],*p=value;
-                   WRITELONG(p,n + 2 + 1 + nsects*2);
-                   coff_sect_write(sects[sxseg],value,4);
-                   sym->type = 0x20;
-                   break;
-               }
-           }
-           if (n == nsyms) {
-               nasm_error(ERR_NONFATAL,
-                     "`safeseh' directive requires valid symbol");
-           }
-       }
-       return 1;
+        static int sxseg=-1;
+        int i;
+
+        if (!win32) /* Only applicable for -f win32 */
+            return 0;
+
+        if (sxseg == -1) {
+            for (i = 0; i < nsects; i++)
+                if (!strcmp(".sxdata",sects[i]->name))
+                    break;
+            if (i == nsects)
+                sxseg = coff_make_section(".sxdata", IMAGE_SCN_LNK_INFO);
+            else
+                sxseg = i;
+        }
+        /*
+         * pass0 == 2 is the only time when the full set of symbols are
+         * guaranteed to be present; it is the final output pass.
+         */
+        if (pass0 == 2) {
+            uint32_t n;
+            saa_rewind(syms);
+            for (n = 0; n < nsyms; n++) {
+                struct Symbol *sym = saa_rstruct(syms);
+                bool equals;
+
+                /*
+                 * sym->strpos is biased by 4, because symbol
+                 * table is prefixed with table length
+                 */
+                if (sym->strpos >=4) {
+                    char *name = nasm_malloc(sym->namlen+1);
+                    saa_fread(strs, sym->strpos-4, name, sym->namlen);
+                    name[sym->namlen] = '\0';
+                    equals = !strcmp(value,name);
+                    nasm_free(name);
+                } else {
+                    equals = !strcmp(value,sym->name);
+                }
+
+                if (equals) {
+                    /*
+                     * this value arithmetics effectively reflects
+                     * initsym in coff_write(): 2 for file, 1 for
+                     * .absolute and two per each section
+                     */
+                    unsigned char value[4],*p=value;
+                    WRITELONG(p,n + 2 + 1 + nsects*2);
+                    coff_sect_write(sects[sxseg],value,4);
+                    sym->type = 0x20;
+                    break;
+                }
+            }
+            if (n == nsyms) {
+                nasm_error(ERR_NONFATAL,
+                           "`safeseh' directive requires valid symbol");
+            }
+        }
+        return 1;
     }
     default:
-       return 0;
+        return 0;
     }
 }
 
@@ -799,17 +846,17 @@ static void coff_write(void)
     BuildExportTable(&Exports);
 
     if (win32) {
-       /* add default value for @feat.00, this allows to 'link /safeseh' */
-       uint32_t n;
+        /* add default value for @feat.00, this allows to 'link /safeseh' */
+        uint32_t n;
 
-       saa_rewind(syms);
-       for (n = 0; n < nsyms; n++) {
+        saa_rewind(syms);
+        for (n = 0; n < nsyms; n++) {
             struct Symbol *sym = saa_rstruct(syms);
-           if (sym->strpos == -1 && !strcmp("@feat.00",sym->name))
-               break;
-       }
-       if (n == nsyms)
-           coff_deflabel("@feat.00",NO_SEG,1,0,NULL);
+            if (sym->strpos == -1 && !strcmp("@feat.00",sym->name))
+                break;
+        }
+        if (n == nsyms)
+            coff_deflabel("@feat.00", NO_SEG, 1, 0, NULL);
     }
 
     /*
@@ -834,14 +881,15 @@ static void coff_write(void)
      * Output the COFF header.
      */
     if (win64)
-        fwriteint16_t(0x8664, ofile);  /* MACHINE_x86-64 */
+        i = IMAGE_FILE_MACHINE_AMD64;
     else
-        fwriteint16_t(0x014C, ofile);  /* MACHINE_i386 */
-    fwriteint16_t(nsects, ofile); /* number of sections */
-    fwriteint32_t(time(NULL), ofile);      /* time stamp */
-    fwriteint32_t(sympos, ofile);
-    fwriteint32_t(nsyms + initsym, ofile);
-    fwriteint16_t(0, ofile);      /* no optional header */
+        i = IMAGE_FILE_MACHINE_I386;
+    fwriteint16_t(i,                    ofile); /* machine type */
+    fwriteint16_t(nsects,               ofile); /* number of sections */
+    fwriteint32_t(time(NULL),           ofile); /* time stamp */
+    fwriteint32_t(sympos,               ofile);
+    fwriteint32_t(nsyms + initsym,      ofile);
+    fwriteint16_t(0,                    ofile); /* no optional header */
     /* Flags: 32-bit, no line numbers. Win32 doesn't even bother with them. */
     fwriteint16_t((win32 | win64) ? 0 : 0x104, ofile);
 
@@ -884,15 +932,16 @@ static void coff_section_header(char *name, int32_t vsize,
     memset(padname, 0, 8);
     strncpy(padname, name, 8);
     fwrite(padname, 8, 1, ofile);
-    fwriteint32_t(0, ofile);   /* Virtual size field - set to 0 or vsize */
-    fwriteint32_t(0L, ofile);      /* RVA/offset - we ignore */
-    fwriteint32_t(datalen, ofile);
-    fwriteint32_t(datapos, ofile);
-    fwriteint32_t(relpos, ofile);
-    fwriteint32_t(0L, ofile);      /* no line numbers - we don't do 'em */
-    fwriteint16_t(nrelocs, ofile);
-    fwriteint16_t(0, ofile);      /* again, no line numbers */
-    fwriteint32_t(flags, ofile);
+
+    fwriteint32_t(0,            ofile); /* Virtual size field - set to 0 or vsize */
+    fwriteint32_t(0L,           ofile); /* RVA/offset - we ignore */
+    fwriteint32_t(datalen,      ofile);
+    fwriteint32_t(datapos,      ofile);
+    fwriteint32_t(relpos,       ofile);
+    fwriteint32_t(0L,           ofile); /* no line numbers - we don't do 'em */
+    fwriteint16_t(nrelocs,      ofile);
+    fwriteint16_t(0,            ofile); /* again, no line numbers */
+    fwriteint32_t(flags,        ofile);
 }
 
 static void coff_write_relocs(struct Section *s)
@@ -902,10 +951,10 @@ static void coff_write_relocs(struct Section *s)
     for (r = s->head; r; r = r->next) {
         fwriteint32_t(r->address, ofile);
         fwriteint32_t(r->symbol + (r->symbase == REAL_SYMBOLS ? initsym :
-                                r->symbase == ABS_SYMBOL ? initsym - 1 :
-                                r->symbase == SECT_SYMBOLS ? 2 : 0),
-                   ofile);
-       fwriteint16_t(r->type, ofile);
+                                   r->symbase == ABS_SYMBOL   ? initsym - 1 :
+                                   r->symbase == SECT_SYMBOLS ? 2 : 0),
+                      ofile);
+        fwriteint16_t(r->type, ofile);
     }
 }
 
@@ -922,9 +971,11 @@ static void coff_symbol(char *name, int32_t strpos, int32_t value,
         fwriteint32_t(0, ofile);
         fwriteint32_t(strpos, ofile);
     }
-    fwriteint32_t(value, ofile);
-    fwriteint16_t(section, ofile);
-    fwriteint16_t(type, ofile);
+
+    fwriteint32_t(value,        ofile);
+    fwriteint16_t(section,      ofile);
+    fwriteint16_t(type,         ofile);
+
     fputc(storageclass, ofile);
     fputc(aux, ofile);
 }
@@ -949,8 +1000,8 @@ static void coff_write_symbols(void)
 
     for (i = 0; i < (uint32_t) nsects; i++) {
         coff_symbol(sects[i]->name, 0L, 0L, i + 1, 0, 3, 1);
-        fwriteint32_t(sects[i]->len, ofile);
-        fwriteint16_t(sects[i]->nrelocs, ofile);
+        fwriteint32_t(sects[i]->len,    ofile);
+        fwriteint16_t(sects[i]->nrelocs,ofile);
         fwrite(filename, 12, 1, ofile);
     }
 
@@ -971,6 +1022,32 @@ static void coff_write_symbols(void)
     }
 }
 
+static void coff_sectalign(int32_t seg, unsigned int value)
+{
+    struct Section *s = NULL;
+    uint32_t align;
+    int i;
+
+    for (i = 0; i < nsects; i++) {
+        if (sects[i]->index == seg) {
+            s = sects[i];
+            break;
+        }
+    }
+
+    if (!s || !is_power2(value))
+        return;
+
+    /* DOS has limitation on 64 bytes */
+    if (!(win32 | win64) && value > 64)
+        return;
+
+    align = (s->flags & IMAGE_SCN_ALIGN_MASK);
+    value = coff_sectalign_flags(value);
+    if (value > align)
+        s->flags = (s->flags & ~IMAGE_SCN_ALIGN_MASK) | value;
+}
+
 static int32_t coff_segbase(int32_t segment)
 {
     return segment;
@@ -996,7 +1073,7 @@ static int coff_set_info(enum geninfo type, char **val)
     (void)val;
     return 0;
 }
-#endif                          /* defined(OF_COFF) || defined(OF_WIN32) */
+#endif /* defined(OF_COFF) || defined(OF_WIN32) */
 
 #ifdef OF_COFF
 
@@ -1012,6 +1089,7 @@ struct ofmt of_coff = {
     coff_out,
     coff_deflabel,
     coff_section_names,
+    coff_sectalign,
     coff_segbase,
     coff_directives,
     coff_std_filename,
@@ -1034,6 +1112,7 @@ struct ofmt of_win32 = {
     coff_out,
     coff_deflabel,
     coff_section_names,
+    coff_sectalign,
     coff_segbase,
     coff_directives,
     coff_win32_filename,
@@ -1056,6 +1135,7 @@ struct ofmt of_win64 = {
     coff_out,
     coff_deflabel,
     coff_section_names,
+    coff_sectalign,
     coff_segbase,
     coff_directives,
     coff_win32_filename,
index 891bc17..675af83 100644 (file)
@@ -147,6 +147,10 @@ static void dbg_out(int32_t segto, const void *data,
         fprintf(ofile, "addr %08"PRIx32" (seg %08"PRIx32", wrt %08"PRIx32")\n", ldata,
                 segment, wrt);
         break;
+    case OUT_REL1ADR:
+        fprintf(ofile, "rel1adr %02"PRIx8" (seg %08"PRIx32")\n",
+               (uint8_t)*(int64_t *)data, segment);
+        break;
     case OUT_REL2ADR:
         fprintf(ofile, "rel2adr %04"PRIx16" (seg %08"PRIx32")\n",
                (uint16_t)*(int64_t *)data, segment);
@@ -166,6 +170,12 @@ static void dbg_out(int32_t segto, const void *data,
     }
 }
 
+static void dbg_sectalign(int32_t seg, unsigned int value)
+{
+    fprintf(ofile, "set alignment (%d) for segment (%d)\n",
+            seg, value);       
+}
+
 static int32_t dbg_segbase(int32_t segment)
 {
     return segment;
@@ -259,6 +269,7 @@ struct ofmt of_dbg = {
     dbg_out,
     dbg_deflabel,
     dbg_section_names,
+    dbg_sectalign,
     dbg_segbase,
     dbg_directive,
     dbg_filename,
index e80d913..6d43b86 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *   
- *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
@@ -64,4 +64,60 @@ const struct elf_known_section elf_known_sections[] = {
     { NULL,       SHT_PROGBITS, SHF_ALLOC,                    1 } /* default */
 };
 
+/* parse section attributes */
+void section_attrib(char *name, char *attr, int pass,
+                    uint32_t *flags_and, uint32_t *flags_or,
+                    uint64_t *align, int *type)
+{
+    char *opt, *val, *next;
+
+    opt = nasm_skip_spaces(attr);
+    if (!opt || !*opt)
+        return;
+
+    while ((opt = nasm_opt_val(opt, &val, &next))) {
+        if (!nasm_stricmp(opt, "align")) {
+            *align = atoi(val);
+            if (*align == 0) {
+                *align = SHA_ANY;
+            } else if (!is_power2(*align)) {
+                nasm_error(ERR_NONFATAL,
+                           "section alignment %"PRId64" is not a power of two",
+                           *align);
+                *align = SHA_ANY;
+            }
+        } else if (!nasm_stricmp(opt, "alloc")) {
+            *flags_and  |= SHF_ALLOC;
+            *flags_or   |= SHF_ALLOC;
+        } else if (!nasm_stricmp(opt, "noalloc")) {
+            *flags_and  |= SHF_ALLOC;
+            *flags_or   &= ~SHF_ALLOC;
+        } else if (!nasm_stricmp(opt, "exec")) {
+            *flags_and  |= SHF_EXECINSTR;
+            *flags_or   |= SHF_EXECINSTR;
+        } else if (!nasm_stricmp(opt, "noexec")) {
+            *flags_and  |= SHF_EXECINSTR;
+            *flags_or   &= ~SHF_EXECINSTR;
+        } else if (!nasm_stricmp(opt, "write")) {
+            *flags_and  |= SHF_WRITE;
+            *flags_or   |= SHF_WRITE;
+        } else if (!nasm_stricmp(opt, "tls")) {
+            *flags_and  |= SHF_TLS;
+            *flags_or   |= SHF_TLS;
+        } else if (!nasm_stricmp(opt, "nowrite")) {
+            *flags_and  |= SHF_WRITE;
+            *flags_or   &= ~SHF_WRITE;
+        } else if (!nasm_stricmp(opt, "progbits")) {
+            *type = SHT_PROGBITS;
+        } else if (!nasm_stricmp(opt, "nobits")) {
+            *type = SHT_NOBITS;
+        } else if (pass == 1) {
+            nasm_error(ERR_WARNING,
+                       "Unknown section attribute '%s' ignored on"
+                       " declaration of section `%s'", opt, name);
+        }
+        opt = next;
+    }
+}
+
 #endif /* defined(OF_ELF32) || defined(OF_ELF64) */
index 1efa2d0..b47f317 100644 (file)
@@ -45,7 +45,8 @@
 
 #define GLOBAL_TEMP_BASE  0x40000000 /* bigger than any sane symbol index */
 
-#define SEG_ALIGN 16            /* alignment of sections in file */
+/* alignment of sections in file */
+#define SEC_FILEALIGN 16
 
 /* this stuff is needed for the stabs debugging format */
 #define TY_STABSSYMLIN 0x40     /* ouch */
@@ -91,4 +92,17 @@ extern const struct elf_known_section elf_known_sections[];
 #define sec_debug_frame         (nsections-2)
 #define sec_debug_loc           (nsections-1)
 
+void section_attrib(char *name, char *attr, int pass,
+                    uint32_t *flags_and, uint32_t *flags_or,
+                    uint64_t *align, int *type);
+
+#define WRITE_STAB(p,n_strx,n_type,n_other,n_desc,n_value)  \
+    do {                                                    \
+        WRITELONG(p, n_strx);                               \
+        WRITECHAR(p, n_type);                               \
+        WRITECHAR(p, n_other);                              \
+        WRITESHORT(p, n_desc);                              \
+        WRITELONG(p, n_value);                              \
+    } while (0)
+
 #endif /* OUTPUT_OUTELF_H */
index 0a2bbba..14df371 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *
- *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
@@ -43,6 +43,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <inttypes.h>
+#include <limits.h>
 
 #include "nasm.h"
 #include "nasmlib.h"
@@ -122,9 +123,6 @@ static uint8_t elf_osabi = 0;   /* Default OSABI = 0 (System V or Linux) */
 static uint8_t elf_abiver = 0;  /* Current ABI version */
 
 extern struct ofmt of_elf32;
-extern struct ofmt of_elf;
-
-#define SOC(ln,aa) ln - line_base + (line_range * aa) + opcode_base
 
 static struct ELF_SECTDATA {
     void *data;
@@ -268,12 +266,6 @@ static void elf_init(void)
     def_seg = seg_alloc();
 }
 
-static void elf_init_hack(void)
-{
-    of_elf32.current_dfmt = of_elf.current_dfmt; /* Sync debugging format */
-    elf_init();
-}
-
 static void elf_cleanup(int debuginfo)
 {
     struct Reloc *r;
@@ -343,12 +335,11 @@ static int elf_make_section(char *name, int type, int flags, int align)
     return nsects - 1;
 }
 
-
 static int32_t elf_section_names(char *name, int pass, int *bits)
 {
     char *p;
     uint32_t flags, flags_and, flags_or;
-    uint32_t align;
+    uint64_t align;
     int type, i;
 
     /*
@@ -364,53 +355,8 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
         *p++ = '\0';
     flags_and = flags_or = type = align = 0;
 
-    p = nasm_skip_spaces(p);
-    while (*p) {
-        char *q = p;
-        p = nasm_skip_word(p);
-        if (*p)
-            *p++ = '\0';
-        p = nasm_skip_spaces(p);
-
-        if (!nasm_strnicmp(q, "align=", 6)) {
-            align = atoi(q + 6);
-            if (align == 0)
-                align = 1;
-            if ((align - 1) & align) {  /* means it's not a power of two */
-                nasm_error(ERR_NONFATAL, "section alignment %d is not"
-                      " a power of two", align);
-                align = 1;
-            }
-        } else if (!nasm_stricmp(q, "alloc")) {
-            flags_and |= SHF_ALLOC;
-            flags_or |= SHF_ALLOC;
-        } else if (!nasm_stricmp(q, "noalloc")) {
-            flags_and |= SHF_ALLOC;
-            flags_or &= ~SHF_ALLOC;
-        } else if (!nasm_stricmp(q, "exec")) {
-            flags_and |= SHF_EXECINSTR;
-            flags_or |= SHF_EXECINSTR;
-        } else if (!nasm_stricmp(q, "noexec")) {
-            flags_and |= SHF_EXECINSTR;
-            flags_or &= ~SHF_EXECINSTR;
-        } else if (!nasm_stricmp(q, "write")) {
-            flags_and |= SHF_WRITE;
-            flags_or |= SHF_WRITE;
-        } else if (!nasm_stricmp(q, "tls")) {
-            flags_and |= SHF_TLS;
-            flags_or |= SHF_TLS;
-        } else if (!nasm_stricmp(q, "nowrite")) {
-            flags_and |= SHF_WRITE;
-            flags_or &= ~SHF_WRITE;
-        } else if (!nasm_stricmp(q, "progbits")) {
-            type = SHT_PROGBITS;
-        } else if (!nasm_stricmp(q, "nobits")) {
-            type = SHT_NOBITS;
-        } else if (pass == 1) {
-            nasm_error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
-                  " declaration of section `%s'", q, name);
-        }
-    }
+    section_attrib(name, p, pass, &flags_and,
+                   &flags_or, &align, &type);
 
     if (!strcmp(name, ".shstrtab") ||
         !strcmp(name, ".symtab") ||
@@ -441,7 +387,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
           if ((type && sects[i]->type != type)
               || (align && sects[i]->align != align)
               || (flags_and && ((sects[i]->flags & flags_and) != flags_or)))
-            nasm_error(ERR_WARNING, "section attributes ignored on"
+            nasm_error(ERR_WARNING, "incompatible section attributes ignored on"
                   " redeclaration of section `%s'", name);
     }
 
@@ -770,7 +716,8 @@ static void elf_out(int32_t segto, const void *data,
 {
     struct Section *s;
     int32_t addr;
-    uint8_t mydata[4], *p;
+    uint8_t mydata[8], *p;
+    int reltype, bytes;
     int i;
     static struct symlininfo sinfo;
 
@@ -816,18 +763,24 @@ static void elf_out(int32_t segto, const void *data,
         return;
     }
 
-    if (type == OUT_RESERVE) {
+    switch (type) {
+    case OUT_RESERVE:
         if (s->type == SHT_PROGBITS) {
             nasm_error(ERR_WARNING, "uninitialized space declared in"
                   " non-BSS section `%s': zeroing", s->name);
             elf_sect_write(s, NULL, size);
         } else
             s->len += size;
-    } else if (type == OUT_RAWDATA) {
+       break;
+
+    case OUT_RAWDATA:
         if (segment != NO_SEG)
             nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
         elf_sect_write(s, data, size);
-    } else if (type == OUT_ADDRESS) {
+       break;
+
+    case OUT_ADDRESS:
+    {
         bool gnu16 = false;
         addr = *(int64_t *)data;
         if (segment != NO_SEG) {
@@ -836,11 +789,27 @@ static void elf_out(int32_t segto, const void *data,
                       " segment base references");
             } else {
                 if (wrt == NO_SEG) {
-                    if (size == 2) {
-                        gnu16 = true;
-                        elf_add_reloc(s, segment, R_386_16);
-                    } else {
-                        elf_add_reloc(s, segment, R_386_32);
+                   /* 
+                    * The if() is a hack to deal with compilers which
+                    * don't handle switch() statements with 64-bit
+                    * expressions.
+                    */
+                   if (size < UINT_MAX) {
+                       switch ((unsigned int)size) {
+                       case 1:
+                           gnu16 = true;
+                           elf_add_reloc(s, segment, R_386_8);
+                           break;
+                       case 2:
+                           gnu16 = true;
+                           elf_add_reloc(s, segment, R_386_16);
+                           break;
+                       case 4:
+                           elf_add_reloc(s, segment, R_386_32);
+                           break;
+                       default:        /* Error issued further down */
+                           break;
+                       }
                     }
                 } else if (wrt == elf_gotpc_sect + 1) {
                     /*
@@ -880,36 +849,45 @@ static void elf_out(int32_t segto, const void *data,
         p = mydata;
         if (gnu16) {
             nasm_error(ERR_WARNING | ERR_WARN_GNUELF,
-                  "16-bit relocations in ELF is a GNU extension");
-            WRITESHORT(p, addr);
-        } else {
-            if (size != 4 && segment != NO_SEG) {
-                nasm_error(ERR_NONFATAL,
-                      "Unsupported non-32-bit ELF relocation");
-            }
-            WRITELONG(p, addr);
+                  "8- or 16-bit relocations in ELF32 is a GNU extension");
+        } else if (size != 4 && segment != NO_SEG) {
+           nasm_error(ERR_NONFATAL, "Unsupported non-32-bit ELF relocation");
         }
+       WRITEADDR(p, addr, size);
         elf_sect_write(s, mydata, size);
-    } else if (type == OUT_REL2ADR) {
-        if (segment == segto)
-            nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR");
+       break;
+    }
+
+    case OUT_REL1ADR:
+       bytes = 1;
+       reltype = R_386_PC8;
+       goto rel12adr;
+    case OUT_REL2ADR:
+       bytes = 2;
+       reltype = R_386_PC16;
+       goto rel12adr;
+
+    rel12adr:
+        nasm_assert(segment != segto);
         if (segment != NO_SEG && segment % 2) {
             nasm_error(ERR_NONFATAL, "ELF format does not support"
                   " segment base references");
         } else {
             if (wrt == NO_SEG) {
                 nasm_error(ERR_WARNING | ERR_WARN_GNUELF,
-                      "16-bit relocations in ELF is a GNU extension");
-                elf_add_reloc(s, segment, R_386_PC16);
+                      "8- or 16-bit relocations in ELF is a GNU extension");
+                elf_add_reloc(s, segment, reltype);
             } else {
                 nasm_error(ERR_NONFATAL,
                       "Unsupported non-32-bit ELF relocation");
             }
         }
-        p = mydata;
+       p = mydata;
         WRITESHORT(p, *(int64_t *)data - size);
-        elf_sect_write(s, mydata, 2L);
-    } else if (type == OUT_REL4ADR) {
+        elf_sect_write(s, mydata, bytes);
+       break;
+
+    case OUT_REL4ADR:
         if (segment == segto)
             nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
         if (segment != NO_SEG && segment % 2) {
@@ -931,9 +909,18 @@ static void elf_out(int32_t segto, const void *data,
                 wrt = NO_SEG;   /* we can at least _try_ to continue */
             }
         }
-        p = mydata;
+       p = mydata;
         WRITELONG(p, *(int64_t *)data - size);
         elf_sect_write(s, mydata, 4L);
+       break;
+
+    case OUT_REL8ADR:
+       nasm_error(ERR_NONFATAL,
+                  "32-bit ELF format does not support 64-bit relocations");
+       p = mydata;
+       WRITEDLONG(p, 0);
+       elf_sect_write(s, mydata, 8L);
+       break;
     }
 }
 
@@ -1030,7 +1017,7 @@ static void elf_write(void)
      */
 
     elf_foffs = 0x40 + 0x28 * nsections;
-    align = ALIGN(elf_foffs, SEG_ALIGN) - elf_foffs;
+    align = ALIGN(elf_foffs, SEC_FILEALIGN) - elf_foffs;
     elf_foffs += align;
     elf_nsect = 0;
     elf_sects = nasm_malloc(sizeof(*elf_sects) * nsections);
@@ -1055,12 +1042,12 @@ static void elf_write(void)
 
     /* .symtab */
     elf_section_header(p - shstrtab, SHT_SYMTAB, 0, symtab, true,
-                        symtablen, sec_strtab, symtablocal, 4, 16);
+                       symtablen, sec_strtab, symtablocal, 4, 16);
     p += strlen(p) + 1;
 
     /* .strtab */
     elf_section_header(p - shstrtab, SHT_STRTAB, 0, strs, true,
-                        strslen, 0, 0, 1, 0);
+                       strslen, 0, 0, 1, 0);
     p += strlen(p) + 1;
 
     /* The relocation sections */
@@ -1089,7 +1076,7 @@ static void elf_write(void)
 
             /* link -> symtable  info -> section to refer to */
             elf_section_header(p - shstrtab, SHT_REL, 0, stabrelbuf, false,
-                                stabrellen, sec_symtab, sec_stab, 4, 8);
+                               stabrellen, sec_symtab, sec_stab, 4, 8);
             p += strlen(p) + 1;
         }
     } else if (of_elf32.current_dfmt == &df_dwarf) {
@@ -1330,7 +1317,7 @@ static void elf_section_header(int name, int type, int flags,
     fwriteint32_t(type == 0 ? 0L : elf_foffs, ofile);
     fwriteint32_t(datalen, ofile);
     if (data)
-        elf_foffs += ALIGN(datalen, SEG_ALIGN);
+        elf_foffs += ALIGN(datalen, SEC_FILEALIGN);
     fwriteint32_t((int32_t)link, ofile);
     fwriteint32_t((int32_t)info, ofile);
     fwriteint32_t((int32_t)align, ofile);
@@ -1343,7 +1330,7 @@ static void elf_write_sections(void)
     for (i = 0; i < elf_nsect; i++)
         if (elf_sects[i].data) {
             int32_t len = elf_sects[i].len;
-            int32_t reallen = ALIGN(len, SEG_ALIGN);
+            int32_t reallen = ALIGN(len, SEC_FILEALIGN);
             int32_t align = reallen - len;
             if (elf_sects[i].is_saa)
                 saa_fpwrite(elf_sects[i].data, ofile);
@@ -1360,6 +1347,24 @@ static void elf_sect_write(struct Section *sect,
     sect->len += len;
 }
 
+static void elf_sectalign(int32_t seg, unsigned int value)
+{
+    struct Section *s = NULL;
+    int i;
+
+    for (i = 0; i < nsects; i++) {
+        if (sects[i]->index == seg) {
+            s = sects[i];
+            break;
+        }
+    }
+    if (!s || !is_power2(value))
+        return;
+
+    if (value > s->align)
+        s->align = value;
+}
+
 static int32_t elf_segbase(int32_t segment)
 {
     return segment;
@@ -1456,29 +1461,13 @@ struct ofmt of_elf32 = {
     elf_out,
     elf_deflabel,
     elf_section_names,
+    elf_sectalign,
     elf_segbase,
     elf_directive,
     elf_filename,
     elf_cleanup
 };
 
-struct ofmt of_elf = {
-    "ELF (short name for ELF32) ",
-    "elf",
-    0,
-    elf32_debugs_arr,
-    &df_stabs,
-    elf_stdmac,
-    elf_init_hack,
-    elf_set_info,
-    elf_out,
-    elf_deflabel,
-    elf_section_names,
-    elf_segbase,
-    elf_directive,
-    elf_filename,
-    elf_cleanup
-};
 /* again, the stabs debugging stuff (code) */
 
 static void stabs32_linenum(const char *filename, int32_t linenumber,
@@ -1598,7 +1587,7 @@ static void stabs32_output(int type, void *param)
         if (debug_immcall) {
             s = (struct symlininfo *)param;
             if (!(sects[s->section]->flags & SHF_EXECINSTR))
-                return; /* we are only interested in the text stuff */
+                return; /* line info is only collected for executable sections */
             numlinestabs++;
             el = (struct linelist *)nasm_malloc(sizeof(struct linelist));
             el->info.offset = s->offset;
@@ -1619,15 +1608,6 @@ static void stabs32_output(int type, void *param)
     debug_immcall = 0;
 }
 
-#define WRITE_STAB(p,n_strx,n_type,n_other,n_desc,n_value)  \
-    do {                                                    \
-        WRITELONG(p,n_strx);                                \
-        WRITECHAR(p,n_type);                                \
-        WRITECHAR(p,n_other);                               \
-        WRITESHORT(p,n_desc);                               \
-        WRITELONG(p,n_value);                               \
-    } while (0)
-
 /* for creating the .stab , .stabstr and .rel.stab sections in memory */
 
 static void stabs32_generate(void)
index bf5f80e..e6cd8d8 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *
- *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
@@ -60,8 +60,9 @@
 
 #ifdef OF_ELF64
 
-#define SOC(ln,aa) ln - line_base + (line_range * aa) + opcode_base
-
+/*
+ * Relocation types.
+ */
 struct Reloc {
     struct Reloc *next;
     int64_t address;            /* relative to _start_ of section */
@@ -106,7 +107,7 @@ static char *shstrtab;
 static int shstrtablen, shstrtabsize;
 
 static struct SAA *syms;
-static uint32_t nlocals, nglobs, ndebugs;
+static uint32_t nlocals, nglobs, ndebugs; /* Symbol counts */
 
 static int32_t def_seg;
 
@@ -247,7 +248,7 @@ static void elf_init(void)
     bsym = raa_init();
     strs = saa_init(1L);
     saa_wbytes(strs, "\0", 1L);
-    saa_wbytes(strs, elf_module, (int32_t)(strlen(elf_module) + 1));
+    saa_wbytes(strs, elf_module, strlen(elf_module)+1);
     strslen = 2 + strlen(elf_module);
     shstrtab = NULL;
     shstrtablen = shstrtabsize = 0;;
@@ -362,53 +363,8 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
         *p++ = '\0';
     flags_and = flags_or = type = align = 0;
 
-    p = nasm_skip_spaces(p);
-    while (*p) {
-        char *q = p;
-        p = nasm_skip_word(p);
-        if (*p)
-            *p++ = '\0';
-        p = nasm_skip_spaces(p);
-
-        if (!nasm_strnicmp(q, "align=", 6)) {
-            align = atoi(q + 6);
-            if (align == 0)
-                align = 1;
-            if ((align - 1) & align) {  /* means it's not a power of two */
-                nasm_error(ERR_NONFATAL, "section alignment %"PRId64" is not"
-                      " a power of two", align);
-                align = 1;
-            }
-        } else if (!nasm_stricmp(q, "alloc")) {
-            flags_and |= SHF_ALLOC;
-            flags_or |= SHF_ALLOC;
-        } else if (!nasm_stricmp(q, "noalloc")) {
-            flags_and |= SHF_ALLOC;
-            flags_or &= ~SHF_ALLOC;
-        } else if (!nasm_stricmp(q, "exec")) {
-            flags_and |= SHF_EXECINSTR;
-            flags_or |= SHF_EXECINSTR;
-        } else if (!nasm_stricmp(q, "noexec")) {
-            flags_and |= SHF_EXECINSTR;
-            flags_or &= ~SHF_EXECINSTR;
-        } else if (!nasm_stricmp(q, "write")) {
-            flags_and |= SHF_WRITE;
-            flags_or |= SHF_WRITE;
-        } else if (!nasm_stricmp(q, "tls")) {
-            flags_and |= SHF_TLS;
-            flags_or |= SHF_TLS;
-        } else if (!nasm_stricmp(q, "nowrite")) {
-            flags_and |= SHF_WRITE;
-            flags_or &= ~SHF_WRITE;
-        } else if (!nasm_stricmp(q, "progbits")) {
-            type = SHT_PROGBITS;
-        } else if (!nasm_stricmp(q, "nobits")) {
-            type = SHT_NOBITS;
-        } else if (pass == 1) {
-            nasm_error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
-                  " declaration of section `%s'", q, name);
-        }
-    }
+    section_attrib(name, p, pass, &flags_and,
+                   &flags_or, &align, &type);
 
     if (!strcmp(name, ".shstrtab") ||
         !strcmp(name, ".symtab") ||
@@ -768,6 +724,7 @@ static void elf_out(int32_t segto, const void *data,
 {
     struct Section *s;
     int64_t addr, zero;
+    int reltype, bytes;
     int i;
     static struct symlininfo sinfo;
 
@@ -809,7 +766,8 @@ static void elf_out(int32_t segto, const void *data,
             i = nsects - 1;
         }
     }
-    /* invoke current debug_output routine */
+
+    /* again some stabs debugging stuff */
     if (of_elf64.current_dfmt) {
         sinfo.offset = s->len;
         sinfo.section = i;
@@ -826,18 +784,23 @@ static void elf_out(int32_t segto, const void *data,
         return;
     }
 
-    if (type == OUT_RESERVE) {
+    switch (type) {
+    case OUT_RESERVE:
         if (s->type == SHT_PROGBITS) {
             nasm_error(ERR_WARNING, "uninitialized space declared in"
                   " non-BSS section `%s': zeroing", s->name);
             elf_sect_write(s, NULL, size);
         } else
             s->len += size;
-    } else if (type == OUT_RAWDATA) {
+       break;
+
+    case OUT_RAWDATA:
         if (segment != NO_SEG)
             nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
         elf_sect_write(s, data, size);
-    } else if (type == OUT_ADDRESS) {
+       break;
+
+    case OUT_ADDRESS:
         addr = *(int64_t *)data;
         if (segment == NO_SEG) {
             /* Do nothing */
@@ -932,10 +895,22 @@ static void elf_out(int32_t segto, const void *data,
             }
         }
         elf_sect_writeaddr(s, addr, size);
-    } else if (type == OUT_REL2ADR) {
+       break;
+
+    case OUT_REL1ADR:
+       reltype = R_X86_64_PC8;
+       bytes = 1;
+       goto rel12adr;
+
+    case OUT_REL2ADR:
+       reltype = R_X86_64_PC16;
+       bytes = 2;
+       goto rel12adr;
+
+    rel12adr:
         addr = *(int64_t *)data - size;
         if (segment == segto)
-            nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR");
+            nasm_error(ERR_PANIC, "intra-segment OUT_REL1ADR");
         if (segment == NO_SEG) {
             /* Do nothing */
         } else if (segment % 2) {
@@ -943,15 +918,17 @@ static void elf_out(int32_t segto, const void *data,
                   " segment base references");
         } else {
             if (wrt == NO_SEG) {
-                elf_add_reloc(s, segment, addr, R_X86_64_PC16);
+                elf_add_reloc(s, segment, addr, reltype);
                 addr = 0;
             } else {
                 nasm_error(ERR_NONFATAL,
-                      "Unsupported non-32-bit ELF relocation [2]");
+                      "Unsupported non-32-bit ELF relocation");
             }
         }
-        elf_sect_writeaddr(s, addr, 2);
-    } else if (type == OUT_REL4ADR) {
+        elf_sect_writeaddr(s, addr, bytes);
+       break;
+
+    case OUT_REL4ADR:
         addr = *(int64_t *)data - size;
         if (segment == segto)
             nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
@@ -987,7 +964,9 @@ static void elf_out(int32_t segto, const void *data,
             }
         }
         elf_sect_writeaddr(s, addr, 4);
-    } else if (type == OUT_REL8ADR) {
+       break;
+
+    case OUT_REL8ADR:
         addr = *(int64_t *)data - size;
         if (segment == segto)
             nasm_error(ERR_PANIC, "intra-segment OUT_REL8ADR");
@@ -1018,6 +997,7 @@ static void elf_out(int32_t segto, const void *data,
             }
         }
         elf_sect_writeaddr(s, addr, 8);
+       break;
     }
 }
 
@@ -1117,7 +1097,7 @@ static void elf_write(void)
      */
 
     elf_foffs = 0x40 + sizeof(Elf64_Shdr) * nsections;
-    align = ALIGN(elf_foffs, SEG_ALIGN) - elf_foffs;
+    align = ALIGN(elf_foffs, SEC_FILEALIGN) - elf_foffs;
     elf_foffs += align;
     elf_nsect = 0;
     elf_sects = nasm_malloc(sizeof(*elf_sects) * nsections);
@@ -1179,8 +1159,7 @@ static void elf_write(void)
                                stabrellen, symtabsection, sec_stab, 4, 16);
             p += strlen(p) + 1;
         }
-    }
-    else if (of_elf64.current_dfmt == &df_dwarf) {
+    } else if (of_elf64.current_dfmt == &df_dwarf) {
             /* for dwarf debugging information, create the ten dwarf sections */
 
             /* this function call creates the dwarf sections in memory */
@@ -1415,7 +1394,7 @@ static void elf_section_header(int name, int type, uint64_t flags,
     fwriteint64_t(type == 0 ? 0L : elf_foffs, ofile);
     fwriteint64_t(datalen, ofile);
     if (data)
-        elf_foffs += ALIGN(datalen, SEG_ALIGN);
+        elf_foffs += ALIGN(datalen, SEC_FILEALIGN);
     fwriteint32_t((int32_t)link, ofile);
     fwriteint32_t((int32_t)info, ofile);
     fwriteint64_t((int64_t)align, ofile);
@@ -1428,7 +1407,7 @@ static void elf_write_sections(void)
     for (i = 0; i < elf_nsect; i++)
         if (elf_sects[i].data) {
             int32_t len = elf_sects[i].len;
-            int32_t reallen = ALIGN(len, SEG_ALIGN);
+            int32_t reallen = ALIGN(len, SEC_FILEALIGN);
             int32_t align = reallen - len;
             if (elf_sects[i].is_saa)
                 saa_fpwrite(elf_sects[i].data, ofile);
@@ -1449,6 +1428,24 @@ static void elf_sect_writeaddr(struct Section *sect, int64_t data, size_t len)
     sect->len += len;
 }
 
+static void elf_sectalign(int32_t seg, unsigned int value)
+{
+    struct Section *s = NULL;
+    int i;
+
+    for (i = 0; i < nsects; i++) {
+        if (sects[i]->index == seg) {
+            s = sects[i];
+            break;
+        }
+    }
+    if (!s || !is_power2(value))
+        return;
+
+    if (value > s->align)
+        s->align = value;
+}
+
 static int32_t elf_segbase(int32_t segment)
 {
     return segment;
@@ -1545,6 +1542,7 @@ struct ofmt of_elf64 = {
     elf_out,
     elf_deflabel,
     elf_section_names,
+    elf_sectalign,
     elf_segbase,
     elf_directive,
     elf_filename,
@@ -1689,15 +1687,6 @@ static void stabs64_output(int type, void *param)
     debug_immcall = 0;
 }
 
-#define WRITE_STAB(p,n_strx,n_type,n_other,n_desc,n_value)  \
-    do {                                                    \
-        WRITELONG(p,n_strx);                                \
-        WRITECHAR(p,n_type);                                \
-        WRITECHAR(p,n_other);                               \
-        WRITESHORT(p,n_desc);                               \
-        WRITELONG(p,n_value);                               \
-    } while (0)
-
 /* for creating the .stab , .stabstr and .rel.stab sections in memory */
 
 static void stabs64_generate(void)
index fa30986..e386343 100644 (file)
 #include "output/outform.h"
 
 struct ofmt *ofmt_find(char *name)
-{                               /* find driver */
+{
     struct ofmt **ofp, *of;
+    unsigned int i;
 
+    /* primary targets first */
     for (ofp = drivers; (of = *ofp); ofp++) {
         if (!nasm_stricmp(name, of->shortname))
             return of;
     }
+
+    /* lets walk thru aliases then */
+    for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
+        if (ofmt_aliases[i].shortname &&
+            !nasm_stricmp(name, ofmt_aliases[i].shortname))
+            return ofmt_aliases[i].ofmt;
+    }
+
     return NULL;
 }
 
 struct dfmt *dfmt_find(struct ofmt *ofmt, char *name)
-{                               /* find driver */
+{
     struct dfmt **dfp, *df;
 
     for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
@@ -72,12 +82,23 @@ struct dfmt *dfmt_find(struct ofmt *ofmt, char *name)
 void ofmt_list(struct ofmt *deffmt, FILE * fp)
 {
     struct ofmt **ofp, *of;
+    unsigned int i;
 
+    /* primary targets first */
     for (ofp = drivers; (of = *ofp); ofp++) {
         fprintf(fp, "  %c %-10s%s\n",
                 of == deffmt ? '*' : ' ',
                 of->shortname, of->fullname);
     }
+
+    /* lets walk through aliases then */
+    for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
+        if (!ofmt_aliases[i].shortname)
+            continue;
+        fprintf(fp, "    %-10s%s\n",
+                ofmt_aliases[i].shortname,
+                ofmt_aliases[i].fullname);
+    }
 }
 
 void dfmt_list(struct ofmt *ofmt, FILE *fp)
index 318e716..e703d99 100644 (file)
@@ -1,5 +1,5 @@
 /* ----------------------------------------------------------------------- *
- *   
+ *
  *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
@@ -14,7 +14,7 @@
  *     copyright notice, this list of conditions and the following
  *     disclaimer in the documentation and/or other materials provided
  *     with the distribution.
- *     
+ *
  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 #define OF_BIN
 #endif
 #ifndef OF_COFF
-#define OF_COFF                        /* COFF is used by DJGPP */
+#define OF_COFF                 /* COFF is used by DJGPP */
 #endif
 #ifndef OF_WIN32
 #define OF_WIN32
@@ -260,7 +260,6 @@ extern struct ofmt of_aout;
 extern struct ofmt of_aoutb;
 extern struct ofmt of_coff;
 extern struct ofmt of_elf32;
-extern struct ofmt of_elf;
 extern struct ofmt of_elf64;
 extern struct ofmt of_as86;
 extern struct ofmt of_obj;
@@ -269,14 +268,15 @@ extern struct ofmt of_win64;
 extern struct ofmt of_rdf2;
 extern struct ofmt of_ieee;
 extern struct ofmt of_macho32;
-extern struct ofmt of_macho;
 extern struct ofmt of_macho64;
 extern struct ofmt of_dbg;
 
 #ifdef BUILD_DRIVERS_ARRAY      /* only if included from outform.c */
 
-/* pull in the externs for the different formats, then make the *drivers
- * array based on the above defines */
+/*
+ * pull in the externs for the different formats, then make the
+ * drivers array based on the above defines
+ */
 
 static struct ofmt *drivers[] = {
 #ifdef OF_BIN
@@ -295,7 +295,6 @@ static struct ofmt *drivers[] = {
 #endif
 #ifdef OF_ELF32
     &of_elf32,
-    &of_elf,
 #endif
 #ifdef OF_ELF64
     &of_elf64,
@@ -320,7 +319,6 @@ static struct ofmt *drivers[] = {
 #endif
 #ifdef OF_MACHO32
     &of_macho32,
-       &of_macho,
 #endif
 #ifdef OF_MACHO64
     &of_macho64,
@@ -332,7 +330,36 @@ static struct ofmt *drivers[] = {
     NULL
 };
 
-#endif                          /* BUILD_DRIVERS_ARRAY */
+static struct ofmt_alias {
+    const char *shortname;
+    const char *fullname;
+    struct ofmt *ofmt;
+} ofmt_aliases[] = {
+#ifdef OF_ELF32
+    {
+        "elf",
+        "ELF (short name for ELF32)",
+        &of_elf32,
+    },
+#endif
+#ifdef OF_MACHO32
+    {
+        "macho",
+        "MACHO (short name for MACHO32)",
+        &of_macho32,
+    },
+#endif
+#ifdef OF_WIN32
+    {
+        "win",
+        "WIN (short name for WIN32)",
+        &of_win32,
+    },
+#endif
+    { NULL, NULL, NULL }
+};
+
+#endif /* BUILD_DRIVERS_ARRAY */
 
 struct ofmt *ofmt_find(char *);
 struct dfmt *dfmt_find(struct ofmt *, char *);
@@ -341,4 +368,4 @@ void dfmt_list(struct ofmt *ofmt, FILE * fp);
 struct ofmt *ofmt_register(efunc error);
 extern struct dfmt null_debug_form;
 
-#endif                          /* NASM_OUTFORM_H */
+#endif /* NASM_OUTFORM_H */
index e3245f5..c6923fd 100644 (file)
@@ -843,6 +843,28 @@ static int ieee_directive(enum directives directive, char *value, int pass)
     }
 }
 
+static void ieee_sectalign(int32_t seg, unsigned int value)
+{
+    struct ieeeSection *s;
+
+    list_for_each(s, seghead) {
+        if (s->index == seg)
+            break;
+    }
+
+    /*
+     * 256 is maximum there, note it may happen
+     * that align is issued on "absolute" segment
+     * it's fine since SEG_ABS > 256 and we never
+     * get escape this test
+     */
+    if (!s || !is_power2(value) || value > 256)
+        return;
+
+    if ((unsigned int)s->align < value)
+        s->align = value;
+}
+
 /*
  * Return segment data
  */
@@ -1501,6 +1523,7 @@ struct ofmt of_ieee = {
     ieee_out,
     ieee_deflabel,
     ieee_segment,
+    ieee_sectalign,
     ieee_segbase,
     ieee_directive,
     ieee_filename,
index 56ac6cd..10f1bfa 100644 (file)
@@ -44,6 +44,8 @@
 uint64_t realsize(enum out_type type, uint64_t size)
 {
     switch (type) {
+    case OUT_REL1ADR:
+       return 1;
     case OUT_REL2ADR:
        return 2;
     case OUT_REL4ADR:
index f3cd1bc..29c27a0 100644 (file)
@@ -41,6 +41,7 @@ uint64_t realsize(enum out_type type, uint64_t size);
 /* Do-nothing versions of some output routines */
 int null_setinfo(enum geninfo type, char **string);
 int null_directive(enum directives directive, char *value, int pass);
+void null_sectalign(int32_t seg, unsigned int value);
 
 /* Do-nothing versions of all the debug routines */
 struct ofmt;
similarity index 97%
rename from output/outmacho32.c
rename to output/outmac32.c
index 51c2231..a13e0d9 100644 (file)
@@ -208,8 +208,6 @@ static struct RAA *extsyms;
 static struct SAA *strs;
 static uint32_t strslen;
 
-extern struct ofmt of_macho;
-
 /* Global file information. This should be cleaned up into either
    a structure or as function arguments.  */
 uint32_t head_ncmds = 0;
@@ -231,35 +229,6 @@ uint32_t rel_padcnt = 0;
 static void debug_reloc (struct reloc *);
 static void debug_section_relocs (struct section *) _unused;
 
-static int exact_log2 (uint32_t align)
-{
-    if (align == 0) {
-       return 0;
-    } else if (align & (align-1)) {
-       return -1;              /* Not a power of 2 */
-    } else {
-#ifdef HAVE_GNUC_4
-       return __builtin_ctzl (align);
-#else
-       uint32_t result = 0;
-
-       /* We know exactly one bit is set at this point. */
-       if (align & 0xffff0000)
-           result |= 16;
-       if (align & 0xff00ff00)
-           result |= 8;
-       if (align & 0xf0f0f0f0)
-           result |= 4;
-       if (align & 0xcccccccc)
-           result |= 2;
-       if (align & 0xaaaaaaaa)
-           result |= 1;
-
-       return result;
-#endif
-    }
-}
-
 static struct section *get_section_by_name(const char *segname,
                                            const char *sectname)
 {
@@ -571,7 +540,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
                         int newAlignment, value;
 
                         value = strtoul(currentAttribute + 6, (char**)&end, 0);
-                        newAlignment = exact_log2(value);
+                        newAlignment = alignlog2_32(value);
 
                         if (0 != *end) {
                             nasm_error(ERR_PANIC,
@@ -695,6 +664,23 @@ static void macho_symdef(char *name, int32_t section, int64_t offset,
     ++nsyms;
 }
 
+static void macho_sectalign(int32_t seg, unsigned int value)
+{
+    struct section *s;
+
+    list_for_each(s, sects) {
+        if (s->index == seg)
+            break;
+    }
+
+    if (!s || !is_power2(value))
+        return;
+
+    value = alignlog2_32(value);
+    if (s->align < (int)value)
+        s->align = value;
+}
+
 static int32_t macho_segbase(int32_t section)
 {
     return section;
@@ -1319,24 +1305,7 @@ struct ofmt of_macho32 = {
     macho_output,
     macho_symdef,
     macho_section,
-    macho_segbase,
-    null_directive,
-    macho_filename,
-    macho_cleanup
-};
-
-struct ofmt of_macho = {
-    "MACHO (short name for MACHO32)",
-    "macho",
-    0,
-    null_debug_arr,
-    &null_debug_form,
-    macho_stdmac,
-    macho_init,
-    null_setinfo,
-    macho_output,
-    macho_symdef,
-    macho_section,
+    macho_sectalign,
     macho_segbase,
     null_directive,
     macho_filename,
similarity index 98%
rename from output/outmacho64.c
rename to output/outmac64.c
index ba785fa..f633db0 100644 (file)
@@ -32,7 +32,7 @@
  * ----------------------------------------------------------------------- */
 
 /*
- * outmacho64.c        output routines for the Netwide Assembler to produce
+ * outmac64.c  output routines for the Netwide Assembler to produce
  *             NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files
  */
 
@@ -235,35 +235,6 @@ uint64_t rel_padcnt64 = 0;
 static void debug_reloc (struct reloc *);
 static void debug_section_relocs (struct section *) _unused;
 
-static int exact_log2 (uint32_t align)
-{
-    if (align == 0) {
-       return 0;
-    } else if (align & (align-1)) {
-       return -1;              /* Not a power of 2 */
-    } else {
-#ifdef HAVE_GNUC_4
-       return __builtin_ctzl (align);
-#else
-       uint32_t result = 0;
-
-       /* We know exactly one bit is set at this point. */
-       if (align & 0xffff0000)
-           result |= 16;
-       if (align & 0xff00ff00)
-           result |= 8;
-       if (align & 0xf0f0f0f0)
-           result |= 4;
-       if (align & 0xcccccccc)
-           result |= 2;
-       if (align & 0xaaaaaaaa)
-           result |= 1;
-
-       return result;
-#endif
-    }
-}
-
 static struct section *get_section_by_name(const char *segname,
                                            const char *sectname)
 {
@@ -704,7 +675,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
                         int newAlignment, value;
 
                         value = strtoul(currentAttribute + 6, (char**)&end, 0);
-                        newAlignment = exact_log2(value);
+                        newAlignment = alignlog2_32(value);
 
                         if (0 != *end) {
                             nasm_error(ERR_PANIC,
@@ -842,6 +813,23 @@ static void macho_symdef(char *name, int32_t section, int64_t offset,
     ++nsyms;
 }
 
+static void macho_sectalign(int32_t seg, unsigned int value)
+{
+    struct section *s;
+
+    list_for_each(s, sects) {
+        if (s->index == seg)
+            break;
+    }
+
+    if (!s || !is_power2(value))
+        return;
+
+    value = alignlog2_32(value);
+    if (s->align < (int)value)
+        s->align = value;
+}
+
 static int32_t macho_segbase(int32_t section)
 {
     return section;
@@ -1488,6 +1476,7 @@ struct ofmt of_macho64 = {
     macho_output,
     macho_symdef,
     macho_section,
+    macho_sectalign,
     macho_segbase,
     null_directive,
     macho_filename,
index 804ff52..e62bc3f 100644 (file)
@@ -43,6 +43,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <inttypes.h>
+#include <limits.h>
 
 #include "nasm.h"
 #include "nasmlib.h"
@@ -1060,7 +1061,8 @@ static void obj_out(int32_t segto, const void *data,
     orp = seg->orp;
     orp->parm[0] = seg->currentpos;
 
-    if (type == OUT_RAWDATA) {
+    switch (type) {
+    case OUT_RAWDATA:
         ucdata = data;
         while (size > 0) {
             unsigned int len;
@@ -1074,8 +1076,14 @@ static void obj_out(int32_t segto, const void *data,
             ucdata += len;
             size -= len;
         }
-    } else if (type == OUT_ADDRESS || type == OUT_REL2ADR ||
-               type == OUT_REL4ADR) {
+       break;
+
+    case OUT_ADDRESS:
+    case OUT_REL1ADR:
+    case OUT_REL2ADR:
+    case OUT_REL4ADR:
+    case OUT_REL8ADR:
+    {
         int rsize;
 
         if (segment == NO_SEG && type != OUT_ADDRESS)
@@ -1084,18 +1092,31 @@ static void obj_out(int32_t segto, const void *data,
         if (segment >= SEG_ABS)
             nasm_error(ERR_NONFATAL, "far-absolute relocations not supported"
                   " by OBJ format");
+
         ldata = *(int64_t *)data;
-        if (type == OUT_REL2ADR) {
-            ldata += (size - 2);
-            size = 2;
-        } else if (type == OUT_REL4ADR) {
-            ldata += (size - 4);
-            size = 4;
+        if (type != OUT_ADDRESS) {
+            ldata += size;
+           size = realsize(type, size);
+           ldata -= size;
         }
-        if (size == 2)
+
+       if (size > UINT_MAX)
+           size = 0;
+
+       switch ((unsigned int)size) {
+       default:
+           nasm_error(ERR_NONFATAL, "OBJ format can only handle 16- or "
+                      "32-byte relocations");
+           segment = NO_SEG;   /* Don't actually generate a relocation */
+           break;
+       case 2:
             orp = obj_word(orp, ldata);
-        else
+           break;
+       case 4:
             orp = obj_dword(orp, ldata);
+           break;
+       }
+
         rsize = size;
         if (segment < SEG_ABS && (segment != NO_SEG && segment % 2) &&
             size == 4) {
@@ -1116,10 +1137,19 @@ static void obj_out(int32_t segto, const void *data,
                             (type == OUT_ADDRESS ? 0x4000 : 0),
                             segment, wrt, seg);
         seg->currentpos += size;
-    } else if (type == OUT_RESERVE) {
+       break;
+    }
+
+    default:
+       nasm_error(ERR_NONFATAL,
+                  "Relocation type not supported by output format");
+       /* fall through */
+
+    case OUT_RESERVE:
         if (orp->committed)
             orp = obj_bump(orp);
         seg->currentpos += size;
+       break;
     }
     obj_commit(orp);
 }
@@ -1137,9 +1167,9 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
     struct External *e = NULL;
     ObjRecord *forp;
 
-    if (bytes == 1) {
+    if (bytes != 2 && bytes != 4) {
         nasm_error(ERR_NONFATAL, "`obj' output driver does not support"
-              " one-byte relocations");
+                  " %d-bit relocations", bytes << 3);
         return;
     }
 
@@ -1777,6 +1807,49 @@ static int obj_directive(enum directives directive, char *value, int pass)
     }
 }
 
+static void obj_sectalign(int32_t seg, unsigned int value)
+{
+    struct Segment *s;
+
+    list_for_each(s, seghead) {
+        if (s->index == seg)
+            break;
+    }
+
+    /*
+     * it should not be too big value
+     * and applied on non-absolute sections
+     */
+    if (!s || !is_power2(value) ||
+        value > 4096 || s->align >= SEG_ABS)
+        return;
+
+    /*
+     * FIXME: No code duplication please
+     * consider making helper for this
+     * mapping since section handler has
+     * to do the same
+     */
+    switch (value) {
+    case 8:
+        value = 16;
+        break;
+    case 32:
+    case 64:
+    case 128:
+        value = 256;
+        break;
+    case 512:
+    case 1024:
+    case 2048:
+        value = 4096;
+        break;
+    }
+
+    if (s->align < (int)value)
+        s->align = value;
+}
+
 static int32_t obj_segbase(int32_t segment)
 {
     struct Segment *seg;
@@ -2559,6 +2632,7 @@ struct ofmt of_obj = {
     obj_out,
     obj_deflabel,
     obj_segment,
+    obj_sectalign,
     obj_segbase,
     obj_directive,
     obj_filename,
index 6d95803..02518a1 100644 (file)
@@ -788,6 +788,7 @@ struct ofmt of_rdf2 = {
     rdf2_out,
     rdf2_deflabel,
     rdf2_section_names,
+    null_sectalign,
     rdf2_segbase,
     rdf2_directive,
     rdf2_filename,
diff --git a/output/pecoff.h b/output/pecoff.h
new file mode 100644 (file)
index 0000000..7c90c49
--- /dev/null
@@ -0,0 +1,475 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
+ *   See the file AUTHORS included with the NASM distribution for
+ *   the specific copyright holders.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following
+ *   conditions are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above
+ *     copyright notice, this list of conditions and the following
+ *     disclaimer in the documentation and/or other materials provided
+ *     with the distribution.
+ *
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#ifndef PECOFF_H
+#define PECOFF_H
+
+/*
+ * Microsoft Portable Executable and Common Object
+ * File Format Specification
+ *
+ * Revision 8.1 â€“ February 15, 2008
+ */
+
+/*
+ * Machine types
+ */
+#define IMAGE_FILE_MACHINE_UNKNOWN      0x0000
+#define IMAGE_FILE_MACHINE_AM33         0x01d3
+#define IMAGE_FILE_MACHINE_AMD64        0x8664
+#define IMAGE_FILE_MACHINE_EBC          0x0ebc
+#define IMAGE_FILE_MACHINE_M32R         0x9041
+#define IMAGE_FILE_MACHINE_ALPHA        0x0184
+#define IMAGE_FILE_MACHINE_ARM          0x01c0
+#define IMAGE_FILE_MACHINE_ALPHA64      0x0284
+#define IMAGE_FILE_MACHINE_I386         0x014c
+#define IMAGE_FILE_MACHINE_IA64         0x0200
+#define IMAGE_FILE_MACHINE_M68K         0x0268
+#define IMAGE_FILE_MACHINE_MIPS16       0x0266
+#define IMAGE_FILE_MACHINE_MIPSFPU      0x0366
+#define IMAGE_FILE_MACHINE_MIPSFPU16    0x0466
+#define IMAGE_FILE_MACHINE_POWERPC      0x01f0
+#define IMAGE_FILE_MACHINE_POWERPCFP    0x01f1
+#define IMAGE_FILE_MACHINE_R3000        0x0162
+#define IMAGE_FILE_MACHINE_R4000        0x0166
+#define IMAGE_FILE_MACHINE_R10000       0x0168
+#define IMAGE_FILE_MACHINE_SH3          0x01a2
+#define IMAGE_FILE_MACHINE_SH3DSP       0x01a3
+#define IMAGE_FILE_MACHINE_SH4          0x01a6
+#define IMAGE_FILE_MACHINE_SH5          0x01a8
+#define IMAGE_FILE_MACHINE_THUMB        0x01c2
+#define IMAGE_FILE_MACHINE_WCEMIPSV2    0x0169
+#define IMAGE_FILE_MACHINE_MASK         0xffff
+
+/*
+ * Characteristics
+ */
+#define IMAGE_FILE_RELOCS_STRIPPED              0x0001
+#define IMAGE_FILE_EXECUTABLE_IMAGE             0x0002
+#define IMAGE_FILE_LINE_NUMS_STRIPPED           0x0004
+#define IMAGE_FILE_LOCAL_SYMS_STRIPPED          0x0008
+#define IMAGE_FILE_AGGRESSIVE_WS_TRIM           0x0010
+#define IMAGE_FILE_LARGE_ADDRESS_AWARE          0x0020
+#define IMAGE_FILE_BYTES_REVERSED_LO            0x0080
+#define IMAGE_FILE_32BIT_MACHINE                0x0100
+#define IMAGE_FILE_DEBUG_STRIPPED               0x0200
+#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP      0x0400
+#define IMAGE_FILE_NET_RUN_FROM_SWAP            0x0800
+#define IMAGE_FILE_SYSTEM                       0x1000
+#define IMAGE_FILE_DLL                          0x2000
+#define IMAGE_FILE_UP_SYSTEM_ONLY               0x4000
+#define IMAGE_FILE_BYTES_REVERSED_HI            0x8000
+
+/*
+ * Windows subsystem
+ */
+#define IMAGE_SUBSYSTEM_UNKNOWN                 0
+#define IMAGE_SUBSYSTEM_NATIVE                  1
+#define IMAGE_SUBSYSTEM_WINDOWS_GUI             2
+#define IMAGE_SUBSYSTEM_WINDOWS_CUI             3
+#define IMAGE_SUBSYSTEM_POSIX_CUI               7
+#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI          9
+#define IMAGE_SUBSYSTEM_EFI_APPLICATION         10
+#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
+#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER      12
+#define IMAGE_SUBSYSTEM_EFI_ROM                 13
+#define IMAGE_SUBSYSTEM_XBOX                    14
+
+/*
+ * DLL characteristics
+ */
+#define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE          0x0040
+#define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY       0x0080
+#define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT             0x0100
+#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION           0x0200
+#define IMAGE_DLLCHARACTERISTICS_NO_SEH                 0x0400
+#define IMAGE_DLLCHARACTERISTICS_NO_BIND                0x0800
+#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER             0x2000
+#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE  0x8000
+
+/*
+ * Section flags
+ */
+#define IMAGE_SCN_TYPE_REG                      0x00000000
+#define IMAGE_SCN_TYPE_DSECT                    0x00000001
+#define IMAGE_SCN_TYPE_NOLOAD                   0x00000002
+#define IMAGE_SCN_TYPE_GROUP                    0x00000004
+#define IMAGE_SCN_TYPE_NO_PAD                   0x00000008
+#define IMAGE_SCN_TYPE_COPY                     0x00000010
+
+#define IMAGE_SCN_CNT_CODE                      0x00000020
+#define IMAGE_SCN_CNT_INITIALIZED_DATA          0x00000040
+#define IMAGE_SCN_CNT_UNINITIALIZED_DATA        0x00000080
+
+#define IMAGE_SCN_LNK_OTHER                     0x00000100
+#define IMAGE_SCN_LNK_INFO                      0x00000200
+#define IMAGE_SCN_TYPE_OVER                     0x00000400
+#define IMAGE_SCN_LNK_REMOVE                    0x00000800
+#define IMAGE_SCN_LNK_COMDAT                    0x00001000
+
+#define IMAGE_SCN_MEM_FARDATA                   0x00008000
+#define IMAGE_SCN_MEM_PURGEABLE                 0x00020000
+#define IMAGE_SCN_MEM_16BIT                     0x00020000
+#define IMAGE_SCN_MEM_LOCKED                    0x00040000
+#define IMAGE_SCN_MEM_PRELOAD                   0x00080000
+
+#define IMAGE_SCN_ALIGN_1BYTES                  0x00100000
+#define IMAGE_SCN_ALIGN_2BYTES                  0x00200000
+#define IMAGE_SCN_ALIGN_4BYTES                  0x00300000
+#define IMAGE_SCN_ALIGN_8BYTES                  0x00400000
+#define IMAGE_SCN_ALIGN_16BYTES                 0x00500000
+#define IMAGE_SCN_ALIGN_32BYTES                 0x00600000
+#define IMAGE_SCN_ALIGN_64BYTES                 0x00700000
+#define IMAGE_SCN_ALIGN_128BYTES                0x00800000
+#define IMAGE_SCN_ALIGN_256BYTES                0x00900000
+#define IMAGE_SCN_ALIGN_512BYTES                0x00a00000
+#define IMAGE_SCN_ALIGN_1024BYTES               0x00b00000
+#define IMAGE_SCN_ALIGN_2048BYTES               0x00c00000
+#define IMAGE_SCN_ALIGN_4096BYTES               0x00d00000
+#define IMAGE_SCN_ALIGN_8192BYTES               0x00e00000
+#define IMAGE_SCN_ALIGN_MASK                    0x00f00000
+
+#define IMAGE_SCN_LNK_NRELOC_OVFL               0x01000000
+#define IMAGE_SCN_MEM_DISCARDABLE               0x02000000
+#define IMAGE_SCN_MEM_NOT_CACHED                0x04000000
+#define IMAGE_SCN_MEM_NOT_PAGED                 0x08000000
+#define IMAGE_SCN_MEM_SHARED                    0x10000000
+#define IMAGE_SCN_MEM_EXECUTE                   0x20000000
+#define IMAGE_SCN_MEM_READ                      0x40000000
+#define IMAGE_SCN_MEM_WRITE                     0x80000000
+
+/*
+ * Relocation type x86-64
+ */
+#define IMAGE_REL_AMD64_ABSOLUTE        0x0000
+#define IMAGE_REL_AMD64_ADDR64          0x0001
+#define IMAGE_REL_AMD64_ADDR32          0x0002
+#define IMAGE_REL_AMD64_ADDR32NB        0x0003
+#define IMAGE_REL_AMD64_REL32           0x0004
+#define IMAGE_REL_AMD64_REL32_1         0x0005
+#define IMAGE_REL_AMD64_REL32_2         0x0006
+#define IMAGE_REL_AMD64_REL32_3         0x0007
+#define IMAGE_REL_AMD64_REL32_4         0x0008
+#define IMAGE_REL_AMD64_REL32_5         0x0009
+#define IMAGE_REL_AMD64_SECTION         0x000a
+#define IMAGE_REL_AMD64_SECREL          0x000b
+#define IMAGE_REL_AMD64_SECREL7         0x000c
+#define IMAGE_REL_AMD64_TOKEN           0x000d
+#define IMAGE_REL_AMD64_SREL32          0x000e
+#define IMAGE_REL_AMD64_PAIR            0x000f
+#define IMAGE_REL_AMD64_SSPAN32         0x0010
+
+/*
+ * Relocation types i386
+ */
+#define IMAGE_REL_I386_ABSOLUTE         0x0000
+#define IMAGE_REL_I386_DIR16            0x0001
+#define IMAGE_REL_I386_REL16            0x0002
+#define IMAGE_REL_I386_DIR32            0x0006
+#define IMAGE_REL_I386_DIR32NB          0x0007
+#define IMAGE_REL_I386_SEG12            0x0009
+#define IMAGE_REL_I386_SECTION          0x000a
+#define IMAGE_REL_I386_SECREL           0x000b
+#define IMAGE_REL_I386_TOKEN            0x000c
+#define IMAGE_REL_I386_SECREL7          0x000d
+#define IMAGE_REL_I386_REL32            0x0014
+
+/*
+ * Relocation types ARM
+ */
+#define IMAGE_REL_ARM_ABSOLUTE          0x0000
+#define IMAGE_REL_ARM_ADDR32            0x0001
+#define IMAGE_REL_ARM_ADDR32NB          0x0002
+#define IMAGE_REL_ARM_BRANCH24          0x0003
+#define IMAGE_REL_ARM_BRANCH11          0x0004
+#define IMAGE_REL_ARM_SECTION           0x000e
+#define IMAGE_REL_ARM_SECREL            0x000f
+
+/*
+ * Relocation types Hitachi SuperH
+ */
+#define IMAGE_REL_SH3_ABSOLUTE          0x0000
+#define IMAGE_REL_SH3_DIRECT16          0x0001
+#define IMAGE_REL_SH3_DIRECT32          0x0002
+#define IMAGE_REL_SH3_DIRECT8           0x0003
+#define IMAGE_REL_SH3_DIRECT8_WORD      0x0004
+#define IMAGE_REL_SH3_DIRECT8_LONG      0x0005
+#define IMAGE_REL_SH3_DIRECT4           0x0006
+#define IMAGE_REL_SH3_DIRECT4_WORD      0x0007
+#define IMAGE_REL_SH3_DIRECT4_LONG      0x0008
+#define IMAGE_REL_SH3_PCREL8_WORD       0x0009
+#define IMAGE_REL_SH3_PCREL8_LONG       0x000a
+#define IMAGE_REL_SH3_PCREL12_WORD      0x000b
+#define IMAGE_REL_SH3_STARTOF_SECTION   0x000c
+#define IMAGE_REL_SH3_SIZEOF_SECTION    0x000d
+#define IMAGE_REL_SH3_SECTION           0x000e
+#define IMAGE_REL_SH3_SECREL            0x000f
+#define IMAGE_REL_SH3_DIRECT32_NB       0x0010
+#define IMAGE_REL_SH3_GPREL4_LONG       0x0011
+#define IMAGE_REL_SH3_TOKEN             0x0012
+#define IMAGE_REL_SHM_PCRELPT           0x0013
+#define IMAGE_REL_SHM_REFLO             0x0014
+#define IMAGE_REL_SHM_REFHALF           0x0015
+#define IMAGE_REL_SHM_RELLO             0x0016
+#define IMAGE_REL_SHM_RELHALF           0x0017
+#define IMAGE_REL_SHM_PAIR              0x0018
+#define IMAGE_REL_SHM_NOMODE            0x8000
+
+/*
+ * Relocation types IBM PowerPC processors
+ */
+#define IMAGE_REL_PPC_ABSOLUTE          0x0000
+#define IMAGE_REL_PPC_ADDR64            0x0001
+#define IMAGE_REL_PPC_ADDR32            0x0002
+#define IMAGE_REL_PPC_ADDR24            0x0003
+#define IMAGE_REL_PPC_ADDR16            0x0004
+#define IMAGE_REL_PPC_ADDR14            0x0005
+#define IMAGE_REL_PPC_REL24             0x0006
+#define IMAGE_REL_PPC_REL14             0x0007
+#define IMAGE_REL_PPC_ADDR32NB          0x000a
+#define IMAGE_REL_PPC_SECREL            0x000b
+#define IMAGE_REL_PPC_SECTION           0x000c
+#define IMAGE_REL_PPC_SECREL16          0x000f
+#define IMAGE_REL_PPC_REFHI             0x0010
+#define IMAGE_REL_PPC_REFLO             0x0011
+#define IMAGE_REL_PPC_PAIR              0x0012
+#define IMAGE_REL_PPC_SECRELLO          0x0013
+#define IMAGE_REL_PPC_GPREL             0x0015
+#define IMAGE_REL_PPC_TOKEN             0x0016
+
+/*
+ * Relocation types Intel Itanium processor family (IPF)
+ */
+#define IMAGE_REL_IA64_ABSOLUTE         0x0000
+#define IMAGE_REL_IA64_IMM14            0x0001
+#define IMAGE_REL_IA64_IMM22            0x0002
+#define IMAGE_REL_IA64_IMM64            0x0003
+#define IMAGE_REL_IA64_DIR32            0x0004
+#define IMAGE_REL_IA64_DIR64            0x0005
+#define IMAGE_REL_IA64_PCREL21B         0x0006
+#define IMAGE_REL_IA64_PCREL21M         0x0007
+#define IMAGE_REL_IA64_PCREL21F         0x0008
+#define IMAGE_REL_IA64_GPREL22          0x0009
+#define IMAGE_REL_IA64_LTOFF22          0x000a
+#define IMAGE_REL_IA64_SECTION          0x000b
+#define IMAGE_REL_IA64_SECREL22         0x000c
+#define IMAGE_REL_IA64_SECREL64I        0x000d
+#define IMAGE_REL_IA64_SECREL32         0x000e
+#define IMAGE_REL_IA64_DIR32NB          0x0010
+#define IMAGE_REL_IA64_SREL14           0x0011
+#define IMAGE_REL_IA64_SREL22           0x0012
+#define IMAGE_REL_IA64_SREL32           0x0013
+#define IMAGE_REL_IA64_UREL32           0x0014
+#define IMAGE_REL_IA64_PCREL60X         0x0015
+#define IMAGE_REL_IA64_PCREL 60B        0x0016
+#define IMAGE_REL_IA64_PCREL60F         0x0017
+#define IMAGE_REL_IA64_PCREL60I         0x0018
+#define IMAGE_REL_IA64_PCREL60M         0x0019
+#define IMAGE_REL_IA64_IMMGPREL64       0x001a
+#define IMAGE_REL_IA64_TOKEN            0x001b
+#define IMAGE_REL_IA64_GPREL32          0x001c
+#define IMAGE_REL_IA64_ADDEND           0x001f
+
+/*
+ * Relocation types MIPS Processors
+ */
+#define IMAGE_REL_MIPS_ABSOLUTE         0x0000
+#define IMAGE_REL_MIPS_REFHALF          0x0001
+#define IMAGE_REL_MIPS_REFWORD          0x0002
+#define IMAGE_REL_MIPS_JMPADDR          0x0003
+#define IMAGE_REL_MIPS_REFHI            0x0004
+#define IMAGE_REL_MIPS_REFLO            0x0005
+#define IMAGE_REL_MIPS_GPREL            0x0006
+#define IMAGE_REL_MIPS_LITERAL          0x0007
+#define IMAGE_REL_MIPS_SECTION          0x000a
+#define IMAGE_REL_MIPS_SECREL           0x000b
+#define IMAGE_REL_MIPS_SECRELLO         0x000c
+#define IMAGE_REL_MIPS_SECRELHI         0x000d
+#define IMAGE_REL_MIPS_JMPADDR16        0x0010
+#define IMAGE_REL_MIPS_REFWORDNB        0x0022
+#define IMAGE_REL_MIPS_PAIR             0x0025
+
+/*
+ * Relocation types Mitsubishi M32R
+ */
+#define IMAGE_REL_M32R_ABSOLUTE         0x0000
+#define IMAGE_REL_M32R_ADDR32           0x0001
+#define IMAGE_REL_M32R_ADDR32NB         0x0002
+#define IMAGE_REL_M32R_ADDR24           0x0003
+#define IMAGE_REL_M32R_GPREL16          0x0004
+#define IMAGE_REL_M32R_PCREL24          0x0005
+#define IMAGE_REL_M32R_PCREL16          0x0006
+#define IMAGE_REL_M32R_PCREL8           0x0007
+#define IMAGE_REL_M32R_REFHALF          0x0008
+#define IMAGE_REL_M32R_REFHI            0x0009
+#define IMAGE_REL_M32R_REFLO            0x000a
+#define IMAGE_REL_M32R_PAIR             0x000b
+#define IMAGE_REL_M32R_SECTION          0x000c
+#define IMAGE_REL_M32R_SECREL           0x000d
+#define IMAGE_REL_M32R_TOKEN            0x000e
+
+/*
+ * Section number values
+ */
+#define IMAGE_SYM_UNDEFINED      0
+#define IMAGE_SYM_ABSOLUTE      -1
+#define IMAGE_SYM_DEBUG         -2
+
+/*
+ * Type representation
+ */
+#define IMAGE_SYM_TYPE_NULL             0
+#define IMAGE_SYM_TYPE_VOID             1
+#define IMAGE_SYM_TYPE_CHAR             2
+#define IMAGE_SYM_TYPE_SHORT            3
+#define IMAGE_SYM_TYPE_INT              4
+#define IMAGE_SYM_TYPE_LONG             5
+#define IMAGE_SYM_TYPE_FLOAT            6
+#define IMAGE_SYM_TYPE_DOUBLE           7
+#define IMAGE_SYM_TYPE_STRUCT           8
+#define IMAGE_SYM_TYPE_UNION            9
+#define IMAGE_SYM_TYPE_ENUM             10
+#define IMAGE_SYM_TYPE_MOE              11
+#define IMAGE_SYM_TYPE_BYTE             12
+#define IMAGE_SYM_TYPE_WORD             13
+#define IMAGE_SYM_TYPE_UINT             14
+#define IMAGE_SYM_TYPE_DWORD            15
+
+#define IMAGE_SYM_DTYPE_NULL            0
+#define IMAGE_SYM_DTYPE_POINTER         1
+#define IMAGE_SYM_DTYPE_FUNCTION        2
+#define IMAGE_SYM_DTYPE_ARRAY           3
+
+/*
+ * Storage class
+ */
+#define IMAGE_SYM_CLASS_END_OF_FUNCTION         -1
+#define IMAGE_SYM_CLASS_NULL                    0
+#define IMAGE_SYM_CLASS_AUTOMATIC               1
+#define IMAGE_SYM_CLASS_EXTERNAL                2
+#define IMAGE_SYM_CLASS_STATIC                  3
+#define IMAGE_SYM_CLAS S_REGISTER               4
+#define IMAGE_SYM_CLASS_EXTERNAL_DEF            5
+#define IMAGE_SYM_CLASS_LABEL                   6
+#define IMAGE_SYM_CLASS_UNDEFINED_LABEL         7
+#define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT        8
+#define IMAGE_SYM_CLASS_ARGUMENT                9
+#define IMAGE_SYM_CLASS_STRUCT_TAG              10
+#define IMAGE_SYM_CLASS_MEMBER_OF_UNION         11
+#define IMAGE_SYM_CLASS_UNION_TAG               12
+#define IMAGE_SYM_CLASS_TYPE_DEFINITION         13
+#define IMAGE_SYM_CLASS_UNDEFINED_STATIC        14
+#define IMAGE_SYM_CLASS_ENUM_TAG                15
+#define IMAGE_SYM_CLASS_MEMBER_OF_ENUM          16
+#define IMAGE_SYM_CLASS_REGISTER_PARAM          17
+#define IMAGE_SYM_CLASS_BIT_FIELD               18
+#define IMAGE_SYM_CLASS_BLOCK                   100
+#define IMAGE_SYM_CLASS_FUNCTION                101
+#define IMAGE_SYM_CLASS_END_OF_STRUCT           102
+#define IMAGE_SYM_CLASS_FILE                    103
+#define IMAGE_SYM_CLASS_SECTION                 104
+#define IMAGE_SYM_CLASS_WEAK_EXTERNAL           105
+#define IMAGE_SYM_CLASS_CLR_TOKEN               107
+
+/*
+ * COMDAT sections
+ */
+#define IMAGE_COMDAT_SELECT_NODUPLICATES        1
+#define IMAGE_COMDAT_SELECT_ANY                 2
+#define IMAGE_COMDAT_SELECT_SAME_SIZE           3
+#define IMAGE_COMDAT_SELECT_EXACT_MATCH         4
+#define IMAGE_COMDAT_SELECT_ASSOCIATIVE         5
+#define IMAGE_COMDAT_SELECT_LARGEST             6
+
+/*
+ * Attribute certificate table
+ */
+#define WIN_CERT_REVISION_1_0           0x0100
+#define WIN_CERT_REVISION_2_0           0x0200
+#define WIN_CERT_TYPE_X509              0x0001
+#define WIN_CERT_TYPE_PKCS_SIGNED_DATA  0x0002
+#define WIN_CERT_TYPE_RESERVED_1        0x0003
+#define WIN_CERT_TYPE_TS_STACK_SIGNED   0x0004
+
+/*
+ * Debug type
+ */
+#define IMAGE_DEBUG_TYPE_UNKNOWN        0
+#define IMAGE_DEBUG_TYPE_COFF           1
+#define IMAGE_DEBUG_TYPE_CODEVIEW       2
+#define IMAGE_DEBUG_TYPE_FPO            3
+#define IMAGE_DEBUG_TYPE_MISC           4
+#define IMAGE_DEBUG_TYPE_EXCEPTION      5
+#define IMAGE_DEBUG_TYPE_FIXUP          6
+#define IMAGE_DEBUG_TYPE_OMAP_TO_SRC    7
+#define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC  8
+#define IMAGE_DEBUG_TYP E_BORLAND       9
+#define IMAGE_DEBUG_TYPE_RESERVED10     10
+#define IMAGE_DEBUG_TYPE_CLSID          11
+
+/*
+ * Base relocation types
+ */
+#define IMAGE_REL_BASED_ABSOLUTE        0
+#define IMAGE_REL_BASED_HIGH            1
+#define IMAGE_REL_BASED_LOW             2
+#define IMAGE_REL_BASED_HIGHLOW         3
+#define IMAGE_REL_BASED_HIGHADJ         4
+#define IMAGE_REL_BASED_MIPS_JMPADDR    5
+#define IMAGE_REL_BASED_MIPS_JMPADDR16  9
+#define IMAGE_REL_BASED_DIR64           10
+
+/*
+ * TLS callback functions
+ */
+#define DLL_PROCESS_ATTACH      1
+#define DLL_THREAD_ATTACH       2
+#define DLL_THREAD_DETACH       3
+#define DLL_PROCESS_DETACH      0
+
+/*
+ * Import Type
+ */
+#define IMPORT_CODE     0
+#define IMPORT_DATA     1
+#define IMPORT_CONST    2
+
+/*
+ * Import name type
+ */
+#define IMPORT_ORDINAL          0
+#define IMPORT_NAME             1
+#define IMPORT_NAME_NOPREFIX    2
+#define IMPORT_NAME_UNDECORATE  3
+
+#endif /* PECOFF_H */
index 76ca360..b78d138 100644 (file)
--- a/pptok.dat
+++ b/pptok.dat
@@ -1,6 +1,6 @@
 ## --------------------------------------------------------------------------
 ##   
-##   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+##   Copyright 1996-2010 The NASM Authors - All Rights Reserved
 ##   See the file AUTHORS included with the NASM distribution for
 ##   the specific copyright holders.
 ##
@@ -39,6 +39,7 @@
 *ctx
 *def
 *empty
+*env
 *id
 *idn
 *idni
index 3c35828..ba1acd5 100644 (file)
--- a/preproc.c
+++ b/preproc.c
@@ -482,7 +482,7 @@ static char *check_tasm_directive(char *line)
 
     /* Binary search for the directive name */
     i = -1;
-    j = elements(tasm_directives);
+    j = ARRAY_SIZE(tasm_directives);
     q = nasm_skip_word(p);
     len = q - p;
     if (len) {
@@ -556,9 +556,8 @@ static char *prepreproc(char *line)
  */
 static void free_tlist(Token * list)
 {
-    while (list) {
+    while (list)
         list = delete_Token(list);
-    }
 }
 
 /*
@@ -566,10 +565,8 @@ static void free_tlist(Token * list)
  */
 static void free_llist(Line * list)
 {
-    Line *l;
-    while (list) {
-        l = list;
-        list = list->next;
+    Line *l, *tmp;
+    list_for_each_safe(l, tmp, list) {
         free_tlist(l->first);
         nasm_free(l);
     }
@@ -592,18 +589,16 @@ static void free_mmacro(MMacro * m)
  */
 static void free_smacro_table(struct hash_table *smt)
 {
-    SMacro *s;
+    SMacro *s, *tmp;
     const char *key;
     struct hash_tbl_node *it = NULL;
 
     while ((s = hash_iterate(smt, &it, &key)) != NULL) {
         nasm_free((void *)key);
-        while (s) {
-            SMacro *ns = s->next;
+        list_for_each_safe(s, tmp, s) {
             nasm_free(s->name);
             free_tlist(s->expansion);
             nasm_free(s);
-            s = ns;
         }
     }
     hash_free(smt);
@@ -611,18 +606,15 @@ static void free_smacro_table(struct hash_table *smt)
 
 static void free_mmacro_table(struct hash_table *mmt)
 {
-    MMacro *m;
+    MMacro *m, *tmp;
     const char *key;
     struct hash_tbl_node *it = NULL;
 
     it = NULL;
     while ((m = hash_iterate(mmt, &it, &key)) != NULL) {
         nasm_free((void *)key);
-        while (m) {
-            MMacro *nm = m->next;
+        list_for_each_safe(m ,tmp, m)
             free_mmacro(m);
-            m = nm;
-        }
     }
     hash_free(mmt);
 }
@@ -688,6 +680,80 @@ hash_findix(struct hash_table *hash, const char *str)
     return p ? *p : NULL;
 }
 
+/*
+ * read line from standart macros set,
+ * if there no more left -- return NULL
+ */
+static char *line_from_stdmac(void)
+{
+    unsigned char c;
+    const unsigned char *p = stdmacpos;
+    char *line, *q;
+    size_t len = 0;
+
+    if (!stdmacpos)
+        return NULL;
+
+    while ((c = *p++)) {
+        if (c >= 0x80)
+            len += pp_directives_len[c - 0x80] + 1;
+        else
+            len++;
+    }
+
+    line = nasm_malloc(len + 1);
+    q = line;
+    while ((c = *stdmacpos++)) {
+        if (c >= 0x80) {
+            memcpy(q, pp_directives[c - 0x80], pp_directives_len[c - 0x80]);
+            q += pp_directives_len[c - 0x80];
+            *q++ = ' ';
+        } else {
+            *q++ = c;
+        }
+    }
+    stdmacpos = p;
+    *q = '\0';
+
+    if (!*stdmacpos) {
+        /* This was the last of the standard macro chain... */
+        stdmacpos = NULL;
+        if (any_extrastdmac) {
+            stdmacpos = extrastdmac;
+            any_extrastdmac = false;
+        } else if (do_predef) {
+            Line *pd, *l;
+            Token *head, **tail, *t;
+
+            /*
+             * Nasty hack: here we push the contents of
+             * `predef' on to the top-level expansion stack,
+             * since this is the most convenient way to
+             * implement the pre-include and pre-define
+             * features.
+             */
+            list_for_each(pd, predef) {
+                head = NULL;
+                tail = &head;
+                list_for_each(t, pd->first) {
+                    *tail = new_Token(NULL, t->type, t->text, 0);
+                    tail = &(*tail)->next;
+                }
+
+                l           = nasm_malloc(sizeof(Line));
+                l->next     = istk->expansion;
+                l->first    = head;
+                l->finishes = NULL;
+
+                istk->expansion = l;
+            }
+            do_predef = false;
+        }
+    }
+
+    return line;
+}
+
 #define BUF_DELTA 512
 /*
  * Read a line from the top file in istk, handling multiple CR/LFs
@@ -700,67 +766,16 @@ static char *read_line(void)
     char *buffer, *p, *q;
     int bufsize, continued_count;
 
-    if (stdmacpos) {
-        unsigned char c;
-        const unsigned char *p = stdmacpos;
-        char *ret, *q;
-        size_t len = 0;
-        while ((c = *p++)) {
-            if (c >= 0x80)
-                len += pp_directives_len[c-0x80]+1;
-            else
-                len++;
-        }
-        ret = nasm_malloc(len+1);
-        q = ret;
-        while ((c = *stdmacpos++)) {
-            if (c >= 0x80) {
-                memcpy(q, pp_directives[c-0x80], pp_directives_len[c-0x80]);
-                q += pp_directives_len[c-0x80];
-                *q++ = ' ';
-            } else {
-                *q++ = c;
-            }
-        }
-        stdmacpos = p;
-        *q = '\0';
-
-        if (!*stdmacpos) {
-            /* This was the last of the standard macro chain... */
-            stdmacpos = NULL;
-            if (any_extrastdmac) {
-                stdmacpos = extrastdmac;
-                any_extrastdmac = false;
-            } else if (do_predef) {
-                Line *pd, *l;
-                Token *head, **tail, *t;
-
-                /*
-                 * Nasty hack: here we push the contents of
-                 * `predef' on to the top-level expansion stack,
-                 * since this is the most convenient way to
-                 * implement the pre-include and pre-define
-                 * features.
-                 */
-                for (pd = predef; pd; pd = pd->next) {
-                    head = NULL;
-                    tail = &head;
-                    for (t = pd->first; t; t = t->next) {
-                        *tail = new_Token(NULL, t->type, t->text, 0);
-                        tail = &(*tail)->next;
-                    }
-                    l = nasm_malloc(sizeof(Line));
-                    l->next = istk->expansion;
-                    l->first = head;
-                    l->finishes = NULL;
-                    istk->expansion = l;
-                }
-                do_predef = false;
-            }
-        }
-        return ret;
-    }
+    /*
+     * standart macros set (predefined) goes first
+     */
+    p = line_from_stdmac();
+    if (p)
+        return p;
 
+    /*
+     * regular read from a file
+     */
     bufsize = BUF_DELTA;
     buffer = nasm_malloc(BUF_DELTA);
     p = buffer;
@@ -878,7 +893,7 @@ static Token *tokenize(char *line)
                     case '\'':
                     case '\"':
                     case '`':
-                        p = nasm_skip_string(p)+1;
+                        p = nasm_skip_string(p - 1) + 1;
                         break;
                     default:
                         break;
@@ -1159,19 +1174,21 @@ static Token *delete_Token(Token * t)
 static char *detoken(Token * tlist, bool expand_locals)
 {
     Token *t;
-    int len;
     char *line, *p;
     const char *q;
+    int len = 0;
 
-    len = 0;
-    for (t = tlist; t; t = t->next) {
+    list_for_each(t, tlist) {
         if (t->type == TOK_PREPROC_ID && t->text[1] == '!') {
             char *p = getenv(t->text + 2);
-            nasm_free(t->text);
-            if (p)
-                t->text = nasm_strdup(p);
-            else
-                t->text = NULL;
+            char *q = t->text;
+           if (!p) {
+                error(ERR_NONFATAL | ERR_PASS1,
+                     "nonexistent environment variable `%s'", q + 2);
+               p = "";
+           }
+           t->text = nasm_strdup(p);
+            nasm_free(q);
         }
         /* Expand local macros here and not during preprocessing */
         if (expand_locals &&
@@ -1188,14 +1205,15 @@ static char *detoken(Token * tlist, bool expand_locals)
                 t->text = p;
             }
         }
-        if (t->type == TOK_WHITESPACE) {
+        if (t->type == TOK_WHITESPACE)
             len++;
-        } else if (t->text) {
+        else if (t->text)
             len += strlen(t->text);
-        }
     }
+
     p = line = nasm_malloc(len + 1);
-    for (t = tlist; t; t = t->next) {
+
+    list_for_each(t, tlist) {
         if (t->type == TOK_WHITESPACE) {
             *p++ = ' ';
         } else if (t->text) {
@@ -1205,6 +1223,7 @@ static char *detoken(Token * tlist, bool expand_locals)
         }
     }
     *p = '\0';
+
     return line;
 }
 
@@ -1225,9 +1244,8 @@ static int ppscan(void *private_data, struct tokenval *tokval)
     do {
         tline = *tlineptr;
         *tlineptr = tline ? tline->next : NULL;
-    }
-    while (tline && (tline->type == TOK_WHITESPACE ||
-                     tline->type == TOK_COMMENT));
+    } while (tline && (tline->type == TOK_WHITESPACE ||
+                       tline->type == TOK_COMMENT));
 
     if (!tline)
         return tokval->t_type = TOKEN_EOS;
@@ -1592,6 +1610,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
     struct tokenval tokval;
     expr *evalresult;
     enum pp_token_type needtype;
+    const char *p;
 
     origline = tline;
 
@@ -1631,6 +1650,26 @@ static bool if_condition(Token * tline, enum preproc_token ct)
         }
         break;
 
+    case PPC_IFENV:
+       tline = expand_smacro(tline);
+        j = false;              /* have we matched yet? */
+        while (tline) {
+            skip_white_(tline);
+            if (!tline || (tline->type != TOK_ID &&
+                           (tline->type != TOK_PREPROC_ID ||
+                              tline->text[1] != '!'))) {
+                error(ERR_NONFATAL,
+                      "`%s' expects environment variable names",
+                     pp_directives[ct]);
+                goto fail;
+            }
+           p = tline->type == TOK_ID ? tline->text : tline->text + 2;
+           if (getenv(p))
+               j = true;
+            tline = tline->next;
+        }
+        break;
+
     case PPC_IFIDN:
     case PPC_IFIDNI:
         tline = expand_smacro(tline);
@@ -2013,7 +2052,7 @@ static int parse_size(const char *str) {
     static const int sizes[] =
         { 0, 1, 4, 16, 8, 10, 2, 32 };
 
-    return sizes[bsii(str, size_names, elements(size_names))+1];
+    return sizes[bsii(str, size_names, ARRAY_SIZE(size_names))+1];
 }
 
 /*
@@ -2684,7 +2723,7 @@ issue_error:
          * macro-end marker for a macro with a name. Then we
          * bypass all lines between exitmacro and endmacro.
          */
-        for (l = istk->expansion; l; l = l->next)
+        list_for_each(l, istk->expansion)
             if (l->finishes && l->finishes->name)
                 break;
 
@@ -2871,7 +2910,7 @@ issue_error:
          * macro-end marker for a macro with no name. Then we set
          * its `in_progress' flag to 0.
          */
-        for (l = istk->expansion; l; l = l->next)
+        list_for_each(l, istk->expansion)
             if (l->finishes && !l->finishes->name)
                 break;
 
@@ -2954,7 +2993,7 @@ issue_error:
         t = tline;
         while (t) {
             if (t->type == TOK_ID) {
-                for (tt = param_start; tt; tt = tt->next)
+                list_for_each(tt, param_start)
                     if (tt->type >= TOK_SMAC_PARAM &&
                         !strcmp(tt->text, t->text))
                         t->type = tt->type;
@@ -3218,7 +3257,7 @@ issue_error:
         last->next = NULL;
 
         len = 0;
-        for (t = tline; t; t = t->next) {
+        list_for_each(t, tline) {
             switch (t->type) {
             case TOK_WHITESPACE:
                 break;
@@ -3239,7 +3278,7 @@ issue_error:
         }
 
         p = pp = nasm_malloc(len);
-        for (t = tline; t; t = t->next) {
+        list_for_each(t, tline) {
             if (t->type == TOK_STRING) {
                 memcpy(p, t->text, t->a.len);
                 p += t->a.len;
@@ -3477,7 +3516,7 @@ static int find_cc(Token * t)
         return -1;
 
     i = -1;
-    j = elements(conditions);
+    j = ARRAY_SIZE(conditions);
     while (j - i > 1) {
         k = (j + i) / 2;
         m = nasm_stricmp(t->text, conditions[k]);
@@ -3517,7 +3556,6 @@ static bool paste_tokens(Token **head, bool handle_paste_tokens)
             }
             break;
         case TOK_ID:
-        case TOK_PREPROC_ID:
         case TOK_NUMBER:
         case TOK_FLOAT:
         {
@@ -3602,24 +3640,95 @@ static bool paste_tokens(Token **head, bool handle_paste_tokens)
     }
     return did_paste;
 }
+
+/*
+ * expands to a list of tokens from %{x:y}
+ */
+static Token *expand_mmac_params_range(MMacro *mac, Token *tline, Token ***last)
+{
+    Token *t = tline, **tt, *tm, *head;
+    char *pos;
+    int fst, lst, j, i;
+
+    pos = strchr(tline->text, ':');
+    nasm_assert(pos);
+
+    lst = atoi(pos + 1);
+    fst = atoi(tline->text + 1);
+
+    /*
+     * only macros params are accounted so
+     * if someone passes %0 -- we reject such
+     * value(s)
+     */
+    if (lst == 0 || fst == 0)
+        goto err;
+
+    /* the values should be sane */
+    if ((fst > (int)mac->nparam || fst < (-(int)mac->nparam)) ||
+        (lst > (int)mac->nparam || lst < (-(int)mac->nparam)))
+        goto err;
+
+    fst = fst < 0 ? fst + (int)mac->nparam + 1: fst;
+    lst = lst < 0 ? lst + (int)mac->nparam + 1: lst;
+
+    /* counted from zero */
+    fst--, lst--;
+
+    /*
+     * it will be at least one token
+     */
+    tm = mac->params[(fst + mac->rotate) % mac->nparam];
+    t = new_Token(NULL, tm->type, tm->text, 0);
+    head = t, tt = &t->next;
+    if (fst < lst) {
+        for (i = fst + 1; i <= lst; i++) {
+            t = new_Token(NULL, TOK_OTHER, ",", 0);
+            *tt = t, tt = &t->next;
+            j = (i + mac->rotate) % mac->nparam;
+            tm = mac->params[j];
+            t = new_Token(NULL, tm->type, tm->text, 0);
+            *tt = t, tt = &t->next;
+        }
+    } else {
+        for (i = fst - 1; i >= lst; i--) {
+            t = new_Token(NULL, TOK_OTHER, ",", 0);
+            *tt = t, tt = &t->next;
+            j = (i + mac->rotate) % mac->nparam;
+            tm = mac->params[j];
+            t = new_Token(NULL, tm->type, tm->text, 0);
+            *tt = t, tt = &t->next;
+        }
+    }
+
+    *last = tt;
+    return head;
+
+err:
+    error(ERR_NONFATAL, "`%%{%s}': macro parameters out of range",
+          &tline->text[1]);
+    return tline;
+}
+
 /*
  * Expand MMacro-local things: parameter references (%0, %n, %+n,
  * %-n) and MMacro-local identifiers (%%foo) as well as
- * macro indirection (%[...]).
+ * macro indirection (%[...]) and range (%{..:..}).
  */
 static Token *expand_mmac_params(Token * tline)
 {
     Token *t, *tt, **tail, *thead;
     bool changed = false;
+    char *pos;
 
     tail = &thead;
     thead = NULL;
 
     while (tline) {
         if (tline->type == TOK_PREPROC_ID &&
-            (((tline->text[1] == '+' || tline->text[1] == '-')
-              && tline->text[2]) || tline->text[1] == '%'
-             || (tline->text[1] >= '0' && tline->text[1] <= '9'))) {
+            (((tline->text[1] == '+' || tline->text[1] == '-') && tline->text[2])   ||
+              (tline->text[1] >= '0' && tline->text[1] <= '9')                      ||
+               tline->text[1] == '%')) {
             char *text = NULL;
             int type = 0, cc;   /* type = 0 to placate optimisers */
             char tmpbuf[30];
@@ -3633,90 +3742,106 @@ static Token *expand_mmac_params(Token * tline)
             mac = istk->mstk;
             while (mac && !mac->name)   /* avoid mistaking %reps for macros */
                 mac = mac->next_active;
-            if (!mac)
+            if (!mac) {
                 error(ERR_NONFATAL, "`%s': not in a macro call", t->text);
-            else
-                switch (t->text[1]) {
-                    /*
-                     * We have to make a substitution of one of the
-                     * forms %1, %-1, %+1, %%foo, %0.
-                     */
-                case '0':
-                    type = TOK_NUMBER;
-                    snprintf(tmpbuf, sizeof(tmpbuf), "%d", mac->nparam);
-                    text = nasm_strdup(tmpbuf);
-                    break;
-                case '%':
-                    type = TOK_ID;
-                    snprintf(tmpbuf, sizeof(tmpbuf), "..@%"PRIu64".",
-                             mac->unique);
-                    text = nasm_strcat(tmpbuf, t->text + 2);
-                    break;
-                case '-':
-                    n = atoi(t->text + 2) - 1;
-                    if (n >= mac->nparam)
-                        tt = NULL;
-                    else {
-                        if (mac->nparam > 1)
-                            n = (n + mac->rotate) % mac->nparam;
-                        tt = mac->params[n];
-                    }
-                    cc = find_cc(tt);
-                    if (cc == -1) {
-                        error(ERR_NONFATAL,
-                              "macro parameter %d is not a condition code",
-                              n + 1);
-                        text = NULL;
-                    } else {
+            } else {
+                pos = strchr(t->text, ':');
+                if (!pos) {
+                    switch (t->text[1]) {
+                        /*
+                         * We have to make a substitution of one of the
+                         * forms %1, %-1, %+1, %%foo, %0.
+                         */
+                    case '0':
+                        type = TOK_NUMBER;
+                        snprintf(tmpbuf, sizeof(tmpbuf), "%d", mac->nparam);
+                        text = nasm_strdup(tmpbuf);
+                        break;
+                    case '%':
                         type = TOK_ID;
-                        if (inverse_ccs[cc] == -1) {
+                        snprintf(tmpbuf, sizeof(tmpbuf), "..@%"PRIu64".",
+                                 mac->unique);
+                        text = nasm_strcat(tmpbuf, t->text + 2);
+                        break;
+                    case '-':
+                        n = atoi(t->text + 2) - 1;
+                        if (n >= mac->nparam)
+                            tt = NULL;
+                        else {
+                            if (mac->nparam > 1)
+                                n = (n + mac->rotate) % mac->nparam;
+                            tt = mac->params[n];
+                        }
+                        cc = find_cc(tt);
+                        if (cc == -1) {
                             error(ERR_NONFATAL,
-                                  "condition code `%s' is not invertible",
-                                  conditions[cc]);
+                                  "macro parameter %d is not a condition code",
+                                  n + 1);
                             text = NULL;
-                        } else
-                            text = nasm_strdup(conditions[inverse_ccs[cc]]);
-                    }
-                    break;
-                case '+':
-                    n = atoi(t->text + 2) - 1;
-                    if (n >= mac->nparam)
-                        tt = NULL;
-                    else {
-                        if (mac->nparam > 1)
-                            n = (n + mac->rotate) % mac->nparam;
-                        tt = mac->params[n];
+                        } else {
+                            type = TOK_ID;
+                            if (inverse_ccs[cc] == -1) {
+                                error(ERR_NONFATAL,
+                                      "condition code `%s' is not invertible",
+                                      conditions[cc]);
+                                text = NULL;
+                            } else
+                                text = nasm_strdup(conditions[inverse_ccs[cc]]);
+                        }
+                        break;
+                    case '+':
+                        n = atoi(t->text + 2) - 1;
+                        if (n >= mac->nparam)
+                            tt = NULL;
+                        else {
+                            if (mac->nparam > 1)
+                                n = (n + mac->rotate) % mac->nparam;
+                            tt = mac->params[n];
+                        }
+                        cc = find_cc(tt);
+                        if (cc == -1) {
+                            error(ERR_NONFATAL,
+                                  "macro parameter %d is not a condition code",
+                                  n + 1);
+                            text = NULL;
+                        } else {
+                            type = TOK_ID;
+                            text = nasm_strdup(conditions[cc]);
+                        }
+                        break;
+                    default:
+                        n = atoi(t->text + 1) - 1;
+                        if (n >= mac->nparam)
+                            tt = NULL;
+                        else {
+                            if (mac->nparam > 1)
+                                n = (n + mac->rotate) % mac->nparam;
+                            tt = mac->params[n];
+                        }
+                        if (tt) {
+                            for (i = 0; i < mac->paramlen[n]; i++) {
+                                *tail = new_Token(NULL, tt->type, tt->text, 0);
+                                tail = &(*tail)->next;
+                                tt = tt->next;
+                            }
+                        }
+                        text = NULL;        /* we've done it here */
+                        break;
                     }
-                    cc = find_cc(tt);
-                    if (cc == -1) {
-                        error(ERR_NONFATAL,
-                              "macro parameter %d is not a condition code",
-                              n + 1);
+                } else {
+                    /*
+                     * seems we have a parameters range here
+                     */
+                    Token *head, **last;
+                    head = expand_mmac_params_range(mac, t, &last);
+                    if (head != t) {
+                        *tail = head;
+                        *last = tline;
+                        tline = head;
                         text = NULL;
-                    } else {
-                        type = TOK_ID;
-                        text = nasm_strdup(conditions[cc]);
                     }
-                    break;
-                default:
-                    n = atoi(t->text + 1) - 1;
-                    if (n >= mac->nparam)
-                        tt = NULL;
-                    else {
-                        if (mac->nparam > 1)
-                            n = (n + mac->rotate) % mac->nparam;
-                        tt = mac->params[n];
-                    }
-                    if (tt) {
-                        for (i = 0; i < mac->paramlen[n]; i++) {
-                            *tail = new_Token(NULL, tt->type, tt->text, 0);
-                            tail = &(*tail)->next;
-                            tt = tt->next;
-                        }
-                    }
-                    text = NULL;        /* we've done it here */
-                    break;
                 }
+            }
             if (!text) {
                 delete_Token(t);
             } else {
@@ -3787,9 +3912,8 @@ static Token *expand_smacro(Token * tline)
      * routine we copy it back
      */
     if (org_tline) {
-        tline =
-            new_Token(org_tline->next, org_tline->type, org_tline->text,
-                      0);
+        tline = new_Token(org_tline->next, org_tline->type,
+                          org_tline->text, 0);
         tline->a.mac = org_tline->a.mac;
         nasm_free(org_tline->text);
         org_tline->text = NULL;
@@ -3798,8 +3922,8 @@ static Token *expand_smacro(Token * tline)
     expanded = true;            /* Always expand %+ at least once */
 
 again:
-    tail = &thead;
     thead = NULL;
+    tail = &thead;
 
     while (tline) {             /* main token loop */
         if (!--deadman) {
@@ -3823,7 +3947,7 @@ again:
              * all, then think about checking for parameters if
              * necessary.
              */
-            for (m = head; m; m = m->next)
+            list_for_each(m, head)
                 if (!mstrcmp(m->name, mname, m->casesense))
                     break;
             if (m) {
@@ -3929,13 +4053,9 @@ again:
                                     if (++nparam >= sparam) {
                                         sparam += PARAM_DELTA;
                                         params = nasm_realloc(params,
-                                                              sparam *
-                                                              sizeof(Token
-                                                                     *));
-                                        paramsize =
-                                            nasm_realloc(paramsize,
-                                                         sparam *
-                                                         sizeof(int));
+                                                        sparam * sizeof(Token *));
+                                        paramsize = nasm_realloc(paramsize,
+                                                        sparam * sizeof(int));
                                     }
                                     params[nparam] = tline->next;
                                     paramsize[nparam] = 0;
@@ -4010,18 +4130,17 @@ again:
                     tt->a.mac = m;
                     m->in_progress = true;
                     tline = tt;
-                    for (t = m->expansion; t; t = t->next) {
+                    list_for_each(t, m->expansion) {
                         if (t->type >= TOK_SMAC_PARAM) {
                             Token *pcopy = tline, **ptail = &pcopy;
                             Token *ttt, *pt;
                             int i;
 
                             ttt = params[t->type - TOK_SMAC_PARAM];
-                            for (i = paramsize[t->type - TOK_SMAC_PARAM];
-                                 --i >= 0;) {
-                                pt = *ptail =
-                                    new_Token(tline, ttt->type, ttt->text,
-                                              0);
+                            i = paramsize[t->type - TOK_SMAC_PARAM];
+                            while (--i >= 0) {
+                                pt = *ptail = new_Token(tline, ttt->type,
+                                                        ttt->text, 0);
                                 ptail = &pt->next;
                                 ttt = ttt->next;
                             }
@@ -4179,7 +4298,7 @@ static MMacro *is_mmacro(Token * tline, Token *** params_array)
      * count the parameters, and then we look further along the
      * list if necessary to find the proper MMacro.
      */
-    for (m = head; m; m = m->next)
+    list_for_each(m, head)
         if (!mstrcmp(m->name, tline->text, m->casesense))
             break;
     if (!m)
@@ -4247,7 +4366,7 @@ static MMacro *is_mmacro(Token * tline, Token *** params_array)
          * This one wasn't right: look for the next one with the
          * same name.
          */
-        for (m = m->next; m; m = m->next)
+        list_for_each(m, m->next)
             if (!mstrcmp(m->name, tline->text, m->casesense))
                 break;
     }
@@ -4428,7 +4547,7 @@ static int expand_mmacro(Token * tline)
     m->next_active = istk->mstk;
     istk->mstk = m;
 
-    for (l = m->expansion; l; l = l->next) {
+    list_for_each(l, m->expansion) {
         Token **tail;
 
         ll = nasm_malloc(sizeof(Line));
@@ -4437,7 +4556,7 @@ static int expand_mmacro(Token * tline)
         istk->expansion = ll;
         tail = &ll->first;
 
-        for (t = l->first; t; t = t->next) {
+        list_for_each(t, l->first) {
             Token *x = t;
             switch (t->type) {
             case TOK_PREPROC_Q:
@@ -4630,7 +4749,7 @@ static char *pp_getline(void)
                  * if we did.
                  */
                 l->finishes->in_progress--;
-                for (l = l->finishes->expansion; l; l = l->next) {
+                list_for_each(l, l->finishes->expansion) {
                     Token *t, *tt, **tail;
 
                     ll = nasm_malloc(sizeof(Line));
@@ -4639,10 +4758,9 @@ static char *pp_getline(void)
                     ll->first = NULL;
                     tail = &ll->first;
 
-                    for (t = l->first; t; t = t->next) {
+                    list_for_each(t, l->first) {
                         if (t->text || t->type == TOK_WHITESPACE) {
-                            tt = *tail =
-                                new_Token(NULL, t->type, t->text, 0);
+                            tt = *tail = new_Token(NULL, t->type, t->text, 0);
                             tail = &tt->next;
                         }
                     }
index a3e8eea..727de87 100644 (file)
@@ -66,6 +66,9 @@
 %define __SECT__ [segment %1]
          __SECT__
 %endmacro
+%imacro sectalign 1.nolist
+       [sectalign %1]
+%endmacro
 
 %imacro absolute 1+.nolist
 %define __SECT__ [absolute %1]
@@ -99,9 +102,11 @@ __SECT__
 %endmacro
 
 %imacro align 1-2+.nolist nop
+         sectalign %1
          times (((%1) - (($-$$) % (%1))) % (%1)) %2
 %endmacro
 %imacro alignb 1-2+.nolist
+         sectalign %1
          %ifempty %2
                resb (((%1) - (($-$$) % (%1))) % (%1))
          %else
diff --git a/test/br2496848.asm b/test/br2496848.asm
new file mode 100644 (file)
index 0000000..a60b7c9
--- /dev/null
@@ -0,0 +1,42 @@
+;Testname=unoptimized; Arguments=-O0 -fbin -o br2496848.bin; Files=stdout stderr br2496848.bin
+;Testname=optimized;   Arguments=-Ox -fbin -o br2496848.bin; Files=stdout stderr br2496848.bin
+
+bits 64
+
+foo:
+
+default abs
+
+mov al, [qword 0xffffffffffffffff]
+mov al, [qword 0x1ffffffffffffffff]
+
+mov cl, [byte 0x12345678]
+
+default rel
+
+mov cl, [foo]
+mov cl, [foo + 0x10000000]
+mov cl, [foo + 0x100000000]
+
+mov cl, [0x100]
+mov cl, [$$ + 0x100]
+
+mov cl, [rax - 1]
+mov cl, [rax + 0xffffffff]
+mov cl, [rax + 0x1ffffffff]
+
+bits 32
+mov cl, [eax - 1]
+mov cl, [eax + 0xffffffff]
+mov cl, [eax + 0x1ffffffff]
+mov cl, [byte eax + 0xffffffff]
+mov cl, [byte eax + 0x1ffffffff]
+mov cl, [byte eax + 0x1000ffff]
+
+bits 16
+mov cl, [di - 1]
+mov cl, [di + 0xffff]
+mov cl, [di + 0x1ffff]
+mov cl, [byte di + 0xffff]
+mov cl, [byte di + 0x1ffff]
+mov cl, [byte di + 0x10ff]
diff --git a/test/br3005117.asm b/test/br3005117.asm
new file mode 100644 (file)
index 0000000..4e7a5b5
--- /dev/null
@@ -0,0 +1,24 @@
+%macro B_STRUC 1-*
+%push foo
+%define %$strucname %1
+%%top_%$strucname:
+%rep %0 - 1
+%rotate 1
+resb %{$strucname}%1 - ($ - %%top_%$strucname)
+%1:
+%endrep
+resb %{$strucname}_size - ($ - %%top_%$strucname)
+%pop
+%endmacro
+
+struc timeval
+.tv_sec                resd    1
+.tv_usec       resd    1
+endstruc
+
+mov    [timeval_struct.tv_sec], eax
+
+section .bss
+
+timeval_struct B_STRUC timeval, .tv_sec, .tv_usec
+       timeval_struct_len      equ     $ - timeval_struct
diff --git a/test/br3026808.asm b/test/br3026808.asm
new file mode 100644 (file)
index 0000000..5c61c95
--- /dev/null
@@ -0,0 +1,18 @@
+%imacro proc 1
+       %push proc
+       %assign %$arg 1
+%endmacro
+
+%imacro arg 0-1 1
+       %assign %$arg %1+%$arg
+%endmacro
+
+%imacro endproc 0
+       %pop
+%endmacro
+
+;----------------------------
+
+proc Test
+       %$ARG   arg
+endproc
diff --git a/test/br3028880.asm b/test/br3028880.asm
new file mode 100644 (file)
index 0000000..20c8bd0
--- /dev/null
@@ -0,0 +1,6 @@
+%macro import 1
+       %define %%incfile %!PROJECTBASEDIR/%{1}.inc
+%endmacro
+
+import foo
+
diff --git a/test/lwp.asm b/test/lwp.asm
new file mode 100644 (file)
index 0000000..f097b63
--- /dev/null
@@ -0,0 +1,213 @@
+; LWP testcases from 2010/03/22 binutils change: no more 16-bit variants
+;------------------------------------------------------------------------
+
+%define testcase3(x) x
+%define testcase3(x,y) y,x
+%define testcase3(x,y,z) z,y,x
+
+%macro testcase 3.nolist       ; uncomment one of the two, and compare the -f bin and -l output between them
+;    db %1
+;    %2 testcase3(%3)
+%endmacro
+
+bits 32
+
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc0                                                                          }, { llwpcb }, { eax }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc1                                                                          }, { llwpcb }, { ecx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc2                                                                          }, { llwpcb }, { edx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc3                                                                          }, { llwpcb }, { ebx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc4                                                                          }, { llwpcb }, { esp }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc5                                                                          }, { llwpcb }, { ebp }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc6                                                                          }, { llwpcb }, { esi }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc7                                                                          }, { llwpcb }, { edi }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xcf                                                                          }, { slwpcb }, { edi }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xce                                                                          }, { slwpcb }, { esi }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xcd                                                                          }, { slwpcb }, { ebp }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xcc                                                                          }, { slwpcb }, { esp }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xcb                                                                          }, { slwpcb }, { ebx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xca                                                                          }, { slwpcb }, { edx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc9                                                                          }, { slwpcb }, { ecx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc8                                                                          }, { slwpcb }, { eax }
+testcase { 0x8f, 0xea, 0x78, 0x12, 0xc7, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,edi,eax }
+testcase { 0x8f, 0xea, 0x70, 0x12, 0xc6, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,esi,ecx }
+testcase { 0x8f, 0xea, 0x68, 0x12, 0xc5, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,ebp,edx }
+testcase { 0x8f, 0xea, 0x60, 0x12, 0xc4, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,esp,ebx }
+testcase { 0x8f, 0xea, 0x58, 0x12, 0xc3, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,ebx,esp }
+testcase { 0x8f, 0xea, 0x50, 0x12, 0xc2, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,edx,ebp }
+testcase { 0x8f, 0xea, 0x48, 0x12, 0xc1, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,ecx,esi }
+testcase { 0x8f, 0xea, 0x40, 0x12, 0xc0, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,eax,edi }
+testcase { 0x8f, 0xea, 0x78, 0x12, 0xcf, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,edi,eax }
+testcase { 0x8f, 0xea, 0x70, 0x12, 0xce, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,esi,ecx }
+testcase { 0x8f, 0xea, 0x68, 0x12, 0xcd, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,ebp,edx }
+testcase { 0x8f, 0xea, 0x60, 0x12, 0xcc, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,esp,ebx }
+testcase { 0x8f, 0xea, 0x58, 0x12, 0xcb, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,ebx,esp }
+testcase { 0x8f, 0xea, 0x50, 0x12, 0xca, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,edx,ebp }
+testcase { 0x8f, 0xea, 0x48, 0x12, 0xc9, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,ecx,esi }
+testcase { 0x8f, 0xea, 0x40, 0x12, 0xc8, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,eax,edi }
+testcase { 0x8f, 0xea, 0x78, 0x12, 0x07, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,[edi],eax }
+testcase { 0x8f, 0xea, 0x70, 0x12, 0x06, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,[esi],ecx }
+testcase { 0x8f, 0xea, 0x68, 0x12, 0x45, 0x00, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[ebp],edx }
+testcase { 0x8f, 0xea, 0x60, 0x12, 0x04, 0x24, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[esp],ebx }
+testcase { 0x8f, 0xea, 0x58, 0x12, 0x03, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,[ebx],esp }
+testcase { 0x8f, 0xea, 0x50, 0x12, 0x02, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,[edx],ebp }
+testcase { 0x8f, 0xea, 0x48, 0x12, 0x01, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,[ecx],esi }
+testcase { 0x8f, 0xea, 0x40, 0x12, 0x00, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,[eax],edi }
+testcase { 0x8f, 0xea, 0x78, 0x12, 0x0f, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,[edi],eax }
+testcase { 0x8f, 0xea, 0x70, 0x12, 0x0e, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,[esi],ecx }
+testcase { 0x8f, 0xea, 0x68, 0x12, 0x4d, 0x00, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[ebp],edx }
+testcase { 0x8f, 0xea, 0x60, 0x12, 0x0c, 0x24, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[esp],ebx }
+testcase { 0x8f, 0xea, 0x58, 0x12, 0x0b, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,[ebx],esp }
+testcase { 0x8f, 0xea, 0x50, 0x12, 0x0a, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,[edx],ebp }
+testcase { 0x8f, 0xea, 0x48, 0x12, 0x09, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,[ecx],esi }
+testcase { 0x8f, 0xea, 0x40, 0x12, 0x08, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,[eax],edi }
+testcase { 0x8f, 0xea, 0x78, 0x12, 0x87, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpins }, { 0x12345678,[0xcafe+edi],eax }
+testcase { 0x8f, 0xea, 0x70, 0x12, 0x86, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpins }, { 0x12345678,[0xcafe+esi],ecx }
+testcase { 0x8f, 0xea, 0x68, 0x12, 0x85, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpins }, { 0x12345678,[0xcafe+ebp],edx }
+testcase { 0x8f, 0xea, 0x60, 0x12, 0x84, 0x24, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+esp],ebx }
+testcase { 0x8f, 0xea, 0x58, 0x12, 0x83, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpins }, { 0x12345678,[0xcafe+ebx],esp }
+testcase { 0x8f, 0xea, 0x50, 0x12, 0x82, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpins }, { 0x12345678,[0xcafe+edx],ebp }
+testcase { 0x8f, 0xea, 0x48, 0x12, 0x81, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpins }, { 0x12345678,[0xcafe+ecx],esi }
+testcase { 0x8f, 0xea, 0x40, 0x12, 0x80, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpins }, { 0x12345678,[0xcafe+eax],edi }
+testcase { 0x8f, 0xea, 0x78, 0x12, 0x8f, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpval }, { 0x12345678,[0xcafe+edi],eax }
+testcase { 0x8f, 0xea, 0x70, 0x12, 0x8e, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpval }, { 0x12345678,[0xcafe+esi],ecx }
+testcase { 0x8f, 0xea, 0x68, 0x12, 0x8d, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpval }, { 0x12345678,[0xcafe+ebp],edx }
+testcase { 0x8f, 0xea, 0x60, 0x12, 0x8c, 0x24, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+esp],ebx }
+testcase { 0x8f, 0xea, 0x58, 0x12, 0x8b, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpval }, { 0x12345678,[0xcafe+ebx],esp }
+testcase { 0x8f, 0xea, 0x50, 0x12, 0x8a, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpval }, { 0x12345678,[0xcafe+edx],ebp }
+testcase { 0x8f, 0xea, 0x48, 0x12, 0x89, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpval }, { 0x12345678,[0xcafe+ecx],esi }
+testcase { 0x8f, 0xea, 0x40, 0x12, 0x88, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12                          }, { lwpval }, { 0x12345678,[0xcafe+eax],edi }
+
+bits 64
+
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc0                                                                          }, { llwpcb }, { eax }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc1                                                                          }, { llwpcb }, { ecx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc2                                                                          }, { llwpcb }, { edx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc3                                                                          }, { llwpcb }, { ebx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc4                                                                          }, { llwpcb }, { esp }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc5                                                                          }, { llwpcb }, { ebp }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc6                                                                          }, { llwpcb }, { esi }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc7                                                                          }, { llwpcb }, { edi }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xc0                                                                          }, { llwpcb }, { r8d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xc1                                                                          }, { llwpcb }, { r9d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xc2                                                                          }, { llwpcb }, { r10d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xc3                                                                          }, { llwpcb }, { r11d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xc4                                                                          }, { llwpcb }, { r12d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xc5                                                                          }, { llwpcb }, { r13d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xc6                                                                          }, { llwpcb }, { r14d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xc7                                                                          }, { llwpcb }, { r15d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xcf                                                                          }, { slwpcb }, { r15d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xce                                                                          }, { slwpcb }, { r14d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xcd                                                                          }, { slwpcb }, { r13d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xcc                                                                          }, { slwpcb }, { r12d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xcb                                                                          }, { slwpcb }, { r11d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xca                                                                          }, { slwpcb }, { r10d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xc9                                                                          }, { slwpcb }, { r9d }
+testcase { 0x8f, 0xc9, 0x78, 0x12, 0xc8                                                                          }, { slwpcb }, { r8d }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xcf                                                                          }, { slwpcb }, { edi }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xce                                                                          }, { slwpcb }, { esi }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xcd                                                                          }, { slwpcb }, { ebp }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xcc                                                                          }, { slwpcb }, { esp }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xcb                                                                          }, { slwpcb }, { ebx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xca                                                                          }, { slwpcb }, { edx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc9                                                                          }, { slwpcb }, { ecx }
+testcase { 0x8f, 0xe9, 0x78, 0x12, 0xc8                                                                          }, { slwpcb }, { eax }
+testcase { 0x8f, 0xca, 0x78, 0x12, 0xc7, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,r15d,eax }
+testcase { 0x8f, 0xca, 0x70, 0x12, 0xc6, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,r14d,ecx }
+testcase { 0x8f, 0xca, 0x68, 0x12, 0xc5, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,r13d,edx }
+testcase { 0x8f, 0xca, 0x60, 0x12, 0xc4, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,r12d,ebx }
+testcase { 0x8f, 0xca, 0x58, 0x12, 0xc3, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,r11d,esp }
+testcase { 0x8f, 0xca, 0x50, 0x12, 0xc2, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,r10d,ebp }
+testcase { 0x8f, 0xca, 0x48, 0x12, 0xc1, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,r9d,esi }
+testcase { 0x8f, 0xca, 0x40, 0x12, 0xc0, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,r8d,edi }
+testcase { 0x8f, 0xea, 0x38, 0x12, 0xc7, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,edi,r8d }
+testcase { 0x8f, 0xea, 0x30, 0x12, 0xc6, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,esi,r9d }
+testcase { 0x8f, 0xea, 0x28, 0x12, 0xc5, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,ebp,r10d }
+testcase { 0x8f, 0xea, 0x20, 0x12, 0xc4, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,esp,r11d }
+testcase { 0x8f, 0xea, 0x18, 0x12, 0xc3, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,ebx,r12d }
+testcase { 0x8f, 0xea, 0x10, 0x12, 0xc2, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,edx,r13d }
+testcase { 0x8f, 0xea, 0x08, 0x12, 0xc1, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,ecx,r14d }
+testcase { 0x8f, 0xea, 0x00, 0x12, 0xc0, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpins }, { 0x12345678,eax,r15d }
+testcase { 0x8f, 0xca, 0x78, 0x12, 0xcf, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,r15d,eax }
+testcase { 0x8f, 0xca, 0x70, 0x12, 0xce, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,r14d,ecx }
+testcase { 0x8f, 0xca, 0x68, 0x12, 0xcd, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,r13d,edx }
+testcase { 0x8f, 0xca, 0x60, 0x12, 0xcc, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,r12d,ebx }
+testcase { 0x8f, 0xca, 0x58, 0x12, 0xcb, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,r11d,esp }
+testcase { 0x8f, 0xca, 0x50, 0x12, 0xca, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,r10d,ebp }
+testcase { 0x8f, 0xca, 0x48, 0x12, 0xc9, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,r9d,esi }
+testcase { 0x8f, 0xca, 0x40, 0x12, 0xc8, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,r8d,edi }
+testcase { 0x8f, 0xea, 0x38, 0x12, 0xcf, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,edi,r8d }
+testcase { 0x8f, 0xea, 0x30, 0x12, 0xce, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,esi,r9d }
+testcase { 0x8f, 0xea, 0x28, 0x12, 0xcd, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,ebp,r10d }
+testcase { 0x8f, 0xea, 0x20, 0x12, 0xcc, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,esp,r11d }
+testcase { 0x8f, 0xea, 0x18, 0x12, 0xcb, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,ebx,r12d }
+testcase { 0x8f, 0xea, 0x10, 0x12, 0xca, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,edx,r13d }
+testcase { 0x8f, 0xea, 0x08, 0x12, 0xc9, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,ecx,r14d }
+testcase { 0x8f, 0xea, 0x00, 0x12, 0xc8, 0x78, 0x56, 0x34, 0x12                                                  }, { lwpval }, { 0x12345678,eax,r15d }
+testcase { 0x67, 0x8f, 0xca, 0x78, 0x12, 0x07, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[r15d],eax }
+testcase { 0x67, 0x8f, 0xca, 0x70, 0x12, 0x06, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[r14d],ecx }
+testcase { 0x67, 0x8f, 0xca, 0x68, 0x12, 0x45, 0x00, 0x78, 0x56, 0x34, 0x12                              }, { lwpins }, { 0x12345678,[r13d],edx }
+testcase { 0x67, 0x8f, 0xca, 0x60, 0x12, 0x04, 0x24, 0x78, 0x56, 0x34, 0x12                              }, { lwpins }, { 0x12345678,[r12d],ebx }
+testcase { 0x67, 0x8f, 0xca, 0x58, 0x12, 0x03, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[r11d],esp }
+testcase { 0x67, 0x8f, 0xca, 0x50, 0x12, 0x02, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[r10d],ebp }
+testcase { 0x67, 0x8f, 0xca, 0x48, 0x12, 0x01, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[r9d],esi }
+testcase { 0x67, 0x8f, 0xca, 0x40, 0x12, 0x00, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[r8d],edi }
+testcase { 0x67, 0x8f, 0xea, 0x38, 0x12, 0x07, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[edi],r8d }
+testcase { 0x67, 0x8f, 0xea, 0x30, 0x12, 0x06, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[esi],r9d }
+testcase { 0x67, 0x8f, 0xea, 0x28, 0x12, 0x45, 0x00, 0x78, 0x56, 0x34, 0x12                              }, { lwpins }, { 0x12345678,[ebp],r10d }
+testcase { 0x67, 0x8f, 0xea, 0x20, 0x12, 0x04, 0x24, 0x78, 0x56, 0x34, 0x12                              }, { lwpins }, { 0x12345678,[esp],r11d }
+testcase { 0x67, 0x8f, 0xea, 0x18, 0x12, 0x03, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[ebx],r12d }
+testcase { 0x67, 0x8f, 0xea, 0x10, 0x12, 0x02, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[edx],r13d }
+testcase { 0x67, 0x8f, 0xea, 0x08, 0x12, 0x01, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[ecx],r14d }
+testcase { 0x67, 0x8f, 0xea, 0x00, 0x12, 0x00, 0x78, 0x56, 0x34, 0x12                                    }, { lwpins }, { 0x12345678,[eax],r15d }
+testcase { 0x67, 0x8f, 0xca, 0x78, 0x12, 0x0f, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[r15d],eax }
+testcase { 0x67, 0x8f, 0xca, 0x70, 0x12, 0x0e, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[r14d],ecx }
+testcase { 0x67, 0x8f, 0xca, 0x68, 0x12, 0x4d, 0x00, 0x78, 0x56, 0x34, 0x12                              }, { lwpval }, { 0x12345678,[r13d],edx }
+testcase { 0x67, 0x8f, 0xca, 0x60, 0x12, 0x0c, 0x24, 0x78, 0x56, 0x34, 0x12                              }, { lwpval }, { 0x12345678,[r12d],ebx }
+testcase { 0x67, 0x8f, 0xca, 0x58, 0x12, 0x0b, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[r11d],esp }
+testcase { 0x67, 0x8f, 0xca, 0x50, 0x12, 0x0a, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[r10d],ebp }
+testcase { 0x67, 0x8f, 0xca, 0x48, 0x12, 0x09, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[r9d],esi }
+testcase { 0x67, 0x8f, 0xca, 0x40, 0x12, 0x08, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[r8d],edi }
+testcase { 0x67, 0x8f, 0xea, 0x38, 0x12, 0x0f, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[edi],r8d }
+testcase { 0x67, 0x8f, 0xea, 0x30, 0x12, 0x0e, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[esi],r9d }
+testcase { 0x67, 0x8f, 0xea, 0x28, 0x12, 0x4d, 0x00, 0x78, 0x56, 0x34, 0x12                              }, { lwpval }, { 0x12345678,[ebp],r10d }
+testcase { 0x67, 0x8f, 0xea, 0x20, 0x12, 0x0c, 0x24, 0x78, 0x56, 0x34, 0x12                              }, { lwpval }, { 0x12345678,[esp],r11d }
+testcase { 0x67, 0x8f, 0xea, 0x18, 0x12, 0x0b, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[ebx],r12d }
+testcase { 0x67, 0x8f, 0xea, 0x10, 0x12, 0x0a, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[edx],r13d }
+testcase { 0x67, 0x8f, 0xea, 0x08, 0x12, 0x09, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[ecx],r14d }
+testcase { 0x67, 0x8f, 0xea, 0x00, 0x12, 0x08, 0x78, 0x56, 0x34, 0x12                                    }, { lwpval }, { 0x12345678,[eax],r15d }
+testcase { 0x67, 0x8f, 0xca, 0x78, 0x12, 0x87, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+r15d],eax }
+testcase { 0x67, 0x8f, 0xca, 0x70, 0x12, 0x86, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+r14d],ecx }
+testcase { 0x67, 0x8f, 0xca, 0x68, 0x12, 0x85, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+r13d],edx }
+testcase { 0x67, 0x8f, 0xca, 0x60, 0x12, 0x84, 0x24, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12      }, { lwpins }, { 0x12345678,[0xcafe+r12d],ebx }
+testcase { 0x67, 0x8f, 0xca, 0x58, 0x12, 0x83, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+r11d],esp }
+testcase { 0x67, 0x8f, 0xca, 0x50, 0x12, 0x82, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+r10d],ebp }
+testcase { 0x67, 0x8f, 0xca, 0x48, 0x12, 0x81, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+r9d],esi }
+testcase { 0x67, 0x8f, 0xca, 0x40, 0x12, 0x80, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+r8d],edi }
+testcase { 0x67, 0x8f, 0xea, 0x38, 0x12, 0x87, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+edi],r8d }
+testcase { 0x67, 0x8f, 0xea, 0x30, 0x12, 0x86, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+esi],r9d }
+testcase { 0x67, 0x8f, 0xea, 0x28, 0x12, 0x85, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+ebp],r10d }
+testcase { 0x67, 0x8f, 0xea, 0x20, 0x12, 0x84, 0x24, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12      }, { lwpins }, { 0x12345678,[0xcafe+esp],r11d }
+testcase { 0x67, 0x8f, 0xea, 0x18, 0x12, 0x83, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+ebx],r12d }
+testcase { 0x67, 0x8f, 0xea, 0x10, 0x12, 0x82, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+edx],r13d }
+testcase { 0x67, 0x8f, 0xea, 0x08, 0x12, 0x81, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+ecx],r14d }
+testcase { 0x67, 0x8f, 0xea, 0x00, 0x12, 0x80, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpins }, { 0x12345678,[0xcafe+eax],r15d }
+testcase { 0x67, 0x8f, 0xca, 0x78, 0x12, 0x8f, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+r15d],eax }
+testcase { 0x67, 0x8f, 0xca, 0x70, 0x12, 0x8e, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+r14d],ecx }
+testcase { 0x67, 0x8f, 0xca, 0x68, 0x12, 0x8d, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+r13d],edx }
+testcase { 0x67, 0x8f, 0xca, 0x60, 0x12, 0x8c, 0x24, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12      }, { lwpval }, { 0x12345678,[0xcafe+r12d],ebx }
+testcase { 0x67, 0x8f, 0xca, 0x58, 0x12, 0x8b, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+r11d],esp }
+testcase { 0x67, 0x8f, 0xca, 0x50, 0x12, 0x8a, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+r10d],ebp }
+testcase { 0x67, 0x8f, 0xca, 0x48, 0x12, 0x89, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+r9d],esi }
+testcase { 0x67, 0x8f, 0xca, 0x40, 0x12, 0x88, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+r8d],edi }
+testcase { 0x67, 0x8f, 0xea, 0x38, 0x12, 0x8f, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+edi],r8d }
+testcase { 0x67, 0x8f, 0xea, 0x30, 0x12, 0x8e, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+esi],r9d }
+testcase { 0x67, 0x8f, 0xea, 0x28, 0x12, 0x8d, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+ebp],r10d }
+testcase { 0x67, 0x8f, 0xea, 0x20, 0x12, 0x8c, 0x24, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12      }, { lwpval }, { 0x12345678,[0xcafe+esp],r11d }
+testcase { 0x67, 0x8f, 0xea, 0x18, 0x12, 0x8b, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+ebx],r12d }
+testcase { 0x67, 0x8f, 0xea, 0x10, 0x12, 0x8a, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+edx],r13d }
+testcase { 0x67, 0x8f, 0xea, 0x08, 0x12, 0x89, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+ecx],r14d }
+testcase { 0x67, 0x8f, 0xea, 0x00, 0x12, 0x88, 0xfe, 0xca, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12            }, { lwpval }, { 0x12345678,[0xcafe+eax],r15d }
+
+; EOF
+
+                
diff --git a/test/newrdwr.asm b/test/newrdwr.asm
new file mode 100644 (file)
index 0000000..dcfc194
--- /dev/null
@@ -0,0 +1,24 @@
+;Testname=test; Arguments=-fbin -onewrdwr.bin; Files=stdout stderr newrdwr.bin
+
+       bits 64
+
+       rdfsbase eax
+       rdfsbase rax
+       rdgsbase eax
+       rdgsbase rax
+       rdrand ax
+       rdrand eax
+       rdrand rax
+       wrfsbase eax
+       wrfsbase rax
+       wrgsbase eax
+       wrgsbase rax
+
+       osp rdfsbase eax
+       osp rdfsbase rax
+       osp rdgsbase eax
+       osp rdgsbase rax
+       osp wrfsbase eax
+       osp wrfsbase rax
+       osp wrgsbase eax
+       osp wrgsbase rax
diff --git a/test/paste.asm b/test/paste.asm
new file mode 100644 (file)
index 0000000..0bc4838
--- /dev/null
@@ -0,0 +1,12 @@
+%macro bug 1-*
+       %push foo
+               %define %$v %1
+               %define vv %$v_ %+ %1
+               %%top_{%$v}%1:
+               mov eax, eax
+               mov eax, %%top_{%$v}%1
+               mov eax, vv
+       %pop
+%endmacro
+
+bug a
diff --git a/version b/version
index 95aa84f..17f63d0 100644 (file)
--- a/version
+++ b/version
@@ -1 +1 @@
-2.08.02
+2.09rc4