summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2002-04-30 21:06:37 +0000
committerH. Peter Anvin <hpa@zytor.com>2002-04-30 21:06:37 +0000
commitdce1e2f795dea9eedb05a1eea1f4c0f3a443b452 (patch)
treeb8fc285bb2ce1f0732bb4e68d9a3c5a67e1ce5a2
parent225c5926f04fb8052be3c12fcd1445934a9fd44f (diff)
downloadnasm-dce1e2f795dea9eedb05a1eea1f4c0f3a443b452.tar.gz
NASM 0.98.23nasm-0.98.23
-rw-r--r--AUTHORS2
-rw-r--r--Mkfiles/Makefile.b321
-rw-r--r--Mkfiles/Makefile.bc23
-rw-r--r--Mkfiles/Makefile.bor1
-rw-r--r--Mkfiles/Makefile.dj1
-rw-r--r--Mkfiles/Makefile.djo3
-rw-r--r--Mkfiles/Makefile.dos1
-rw-r--r--Mkfiles/Makefile.emx1
-rw-r--r--Mkfiles/Makefile.lcc1
-rw-r--r--Mkfiles/Makefile.os23
-rw-r--r--Mkfiles/Makefile.sc1
-rw-r--r--Mkfiles/Makefile.scw1
-rw-r--r--Mkfiles/Makefile.unx1
-rw-r--r--Mkfiles/Makefile.vc1
-rw-r--r--Mkfiles/Makefile.wc1
-rw-r--r--Mkfiles/Makefile.wcw1
-rw-r--r--insns.dat126
-rw-r--r--nasm.h2
-rw-r--r--preproc.c5
-rw-r--r--rdoff/ldrdf1.c728
20 files changed, 796 insertions, 88 deletions
diff --git a/AUTHORS b/AUTHORS
index b6764d7d..fb109579 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -40,7 +40,7 @@ D: New Athlon instructions
D: Makefile.vc fix
N: John Coffman
-E: johninsd@san.rr.com
+E: johninsd@users.sourceforge.net
D: added Jcc optimizations; CPU level checks
D: bug fixes, compilation fixes
diff --git a/Mkfiles/Makefile.b32 b/Mkfiles/Makefile.b32
index d83e6e02..3b92d0b4 100644
--- a/Mkfiles/Makefile.b32
+++ b/Mkfiles/Makefile.b32
@@ -133,7 +133,6 @@ outcoff.$(OBJ): outcoff.c nasm.h insnsi.h nasmlib.h
outdbg.$(OBJ): outdbg.c nasm.h insnsi.h nasmlib.h
outelf.$(OBJ): outelf.c nasm.h insnsi.h nasmlib.h
outobj.$(OBJ): outobj.c nasm.h insnsi.h nasmlib.h
-outrdf.$(OBJ): outrdf.c nasm.h insnsi.h nasmlib.h
outrdf2.$(OBJ): outrdf2.c nasm.h insnsi.h nasmlib.h
zoutieee.$(OBJ): zoutieee.c nasm.h insnsi.h nasmlib.h
outform.$(OBJ): outform.c outform.h nasm.h insnsi.h
diff --git a/Mkfiles/Makefile.bc2 b/Mkfiles/Makefile.bc2
index 69a376df..a6a31ee3 100644
--- a/Mkfiles/Makefile.bc2
+++ b/Mkfiles/Makefile.bc2
@@ -222,9 +222,6 @@ $(OBJD)outelf.$(OBJ): outelf.c nasm.h insnsi.h nasmlib.h
$(OBJD)outobj.$(OBJ): outobj.c nasm.h insnsi.h nasmlib.h
$(NASM_ASM)
-$(OBJD)outrdf.$(OBJ): outrdf.c nasm.h insnsi.h nasmlib.h
- $(NASM_ASM)
-
$(OBJD)outrdf2.$(OBJ): outrdf2.c nasm.h insnsi.h nasmlib.h
$(NASM_ASM)
diff --git a/Mkfiles/Makefile.bor b/Mkfiles/Makefile.bor
index d0303951..eeb59cd2 100644
--- a/Mkfiles/Makefile.bor
+++ b/Mkfiles/Makefile.bor
@@ -72,7 +72,6 @@ outcoff.$(OBJ): outcoff.c nasm.h insnsi.h nasmlib.h
outdbg.$(OBJ): outdbg.c nasm.h insnsi.h nasmlib.h
outelf.$(OBJ): outelf.c nasm.h insnsi.h nasmlib.h
outobj.$(OBJ): outobj.c nasm.h insnsi.h nasmlib.h
-outrdf.$(OBJ): outrdf.c nasm.h insnsi.h nasmlib.h
outrdf2.$(OBJ): outrdf2.c nasm.h insnsi.h nasmlib.h
zoutieee.$(OBJ): zoutieee.c nasm.h insnsi.h nasmlib.h
outform.$(OBJ): outform.c outform.h nasm.h insnsi.h
diff --git a/Mkfiles/Makefile.dj b/Mkfiles/Makefile.dj
index 7cb2399d..abfe2b2b 100644
--- a/Mkfiles/Makefile.dj
+++ b/Mkfiles/Makefile.dj
@@ -56,7 +56,6 @@ outdbg.o: outdbg.c nasm.h insnsi.h nasmlib.h outform.h
outelf.o: outelf.c nasm.h insnsi.h nasmlib.h outform.h
outform.o: outform.c outform.h nasm.h insnsi.h
outobj.o: outobj.c nasm.h insnsi.h nasmlib.h outform.h
-outrdf.o: outrdf.c nasm.h insnsi.h nasmlib.h outform.h
outrdf2.o: outrdf2.c nasm.h insnsi.h nasmlib.h outform.h
zoutieee.o: zoutieee.c nasm.h insnsi.h nasmlib.h outform.h
parser.o: parser.c nasm.h insnsi.h nasmlib.h parser.h float.h names.c insnsn.c
diff --git a/Mkfiles/Makefile.djo b/Mkfiles/Makefile.djo
index d69a4dfe..1b529c37 100644
--- a/Mkfiles/Makefile.djo
+++ b/Mkfiles/Makefile.djo
@@ -107,7 +107,6 @@ outdbg.o: outdbg.c nasm.h insnsi.h nasmlib.h outform.h
outelf.o: outelf.c nasm.h insnsi.h nasmlib.h outform.h
outform.o: outform.c outform.h nasm.h insnsi.h
outobj.o: outobj.c nasm.h insnsi.h nasmlib.h outform.h
-outrdf.o: outrdf.c nasm.h insnsi.h nasmlib.h outform.h
outrdf2.o: outrdf2.c nasm.h insnsi.h nasmlib.h outform.h
parser.o: parser.c nasm.h insnsi.h nasmlib.h parser.h float.h names.c insnsn.c
preproc.o: preproc.c nasm.h insnsi.h nasmlib.h macros.c
@@ -134,7 +133,6 @@ outdbg.ol: outdbg.c nasm.h insnsi.h nasmlib.h outform.h
outelf.ol: outelf.c nasm.h insnsi.h nasmlib.h outform.h
outform.ol: outform.c outform.h nasm.h insnsi.h
outobj.ol: outobj.c nasm.h insnsi.h nasmlib.h outform.h
-outrdf.ol: outrdf.c nasm.h insnsi.h nasmlib.h outform.h
outrdf2.ol: outrdf2.c nasm.h insnsi.h nasmlib.h outform.h
parser.ol: parser.c nasm.h insnsi.h nasmlib.h parser.h float.h names.c insnsn.c
preproc.ol: preproc.c nasm.h insnsi.h nasmlib.h macros.c
@@ -161,7 +159,6 @@ outdbg.obj: outdbg.c nasm.h insnsi.h nasmlib.h outform.h
outelf.obj: outelf.c nasm.h insnsi.h nasmlib.h outform.h
outform.obj: outform.c outform.h nasm.h insnsi.h
outobj.obj: outobj.c nasm.h insnsi.h nasmlib.h outform.h
-outrdf.obj: outrdf.c nasm.h insnsi.h nasmlib.h outform.h
outrdf2.obj: outrdf2.c nasm.h insnsi.h nasmlib.h outform.h
parser.obj: parser.c nasm.h insnsi.h nasmlib.h parser.h float.h names.c insnsn.c
preproc.obj: preproc.c nasm.h insnsi.h nasmlib.h macros.c
diff --git a/Mkfiles/Makefile.dos b/Mkfiles/Makefile.dos
index 6835e7df..6b87d1f6 100644
--- a/Mkfiles/Makefile.dos
+++ b/Mkfiles/Makefile.dos
@@ -59,7 +59,6 @@ outcoff.$(OBJ): outcoff.c nasm.h insnsi.h nasmlib.h
outdbg.$(OBJ): outdbg.c nasm.h insnsi.h nasmlib.h
outelf.$(OBJ): outelf.c nasm.h insnsi.h nasmlib.h
outobj.$(OBJ): outobj.c nasm.h insnsi.h nasmlib.h
-outrdf.$(OBJ): outrdf.c nasm.h insnsi.h nasmlib.h
outrdf2.$(OBJ): outrdf2.c nasm.h insnsi.h nasmlib.h
zoutieee.$(OBJ): zoutieee.c nasm.h insnsi.h nasmlib.h
outform.$(OBJ): outform.c outform.h nasm.h insnsi.h
diff --git a/Mkfiles/Makefile.emx b/Mkfiles/Makefile.emx
index bb7ef0f9..9d532654 100644
--- a/Mkfiles/Makefile.emx
+++ b/Mkfiles/Makefile.emx
@@ -79,7 +79,6 @@ outdbg.o: outdbg.c nasm.h insnsi.h nasmlib.h outform.h
outelf.o: outelf.c nasm.h insnsi.h nasmlib.h outform.h
outform.o: outform.c outform.h nasm.h insnsi.h
outobj.o: outobj.c nasm.h insnsi.h nasmlib.h outform.h
-outrdf.o: outrdf.c nasm.h insnsi.h nasmlib.h outform.h
outrdf2.o: outrdf2.c nasm.h insnsi.h nasmlib.h outform.h
parser.o: parser.c nasm.h insnsi.h nasmlib.h parser.h float.h names.c insnsn.c
preproc.o: preproc.c nasm.h insnsi.h nasmlib.h macros.c
diff --git a/Mkfiles/Makefile.lcc b/Mkfiles/Makefile.lcc
index 3c2c205d..c5bbec73 100644
--- a/Mkfiles/Makefile.lcc
+++ b/Mkfiles/Makefile.lcc
@@ -88,7 +88,6 @@ outdbg.${OBJ}: outdbg.c nasm.h insnsi.h nasmlib.h outform.h
outelf.${OBJ}: outelf.c nasm.h insnsi.h nasmlib.h outform.h
outform.${OBJ}: outform.c outform.h nasm.h insnsi.h
outobj.${OBJ}: outobj.c nasm.h insnsi.h nasmlib.h outform.h
-outrdf.${OBJ}: outrdf.c nasm.h insnsi.h nasmlib.h outform.h
outrdf2.${OBJ}: outrdf2.c nasm.h insnsi.h nasmlib.h outform.h
zoutieee.${OBJ}: zoutieee.c nasm.h insnsi.h nasmlib.h outform.h
parser.${OBJ}: parser.c nasm.h insnsi.h nasmlib.h parser.h float.h names.c insnsn.c
diff --git a/Mkfiles/Makefile.os2 b/Mkfiles/Makefile.os2
index 0d99283d..f9236fe6 100644
--- a/Mkfiles/Makefile.os2
+++ b/Mkfiles/Makefile.os2
@@ -189,9 +189,6 @@ $(OBJD)outelf.$(OBJ): outelf.c nasm.h nasmlib.h
$(OBJD)outobj.$(OBJ): outobj.c nasm.h nasmlib.h
$(NASM_ASM)
-$(OBJD)outrdf.$(OBJ): outrdf.c nasm.h nasmlib.h
- $(NASM_ASM)
-
$(OBJD)outform.$(OBJ): outform.c outform.h nasm.h
$(NASM_ASM)
diff --git a/Mkfiles/Makefile.sc b/Mkfiles/Makefile.sc
index 325a7525..6563b69d 100644
--- a/Mkfiles/Makefile.sc
+++ b/Mkfiles/Makefile.sc
@@ -99,7 +99,6 @@ outcoff.$(OBJ): outcoff.c nasm.h insnsi.h nasmlib.h
outdbg.$(OBJ): outdbg.c nasm.h insnsi.h nasmlib.h
outelf.$(OBJ): outelf.c nasm.h insnsi.h nasmlib.h
outobj.$(OBJ): outobj.c nasm.h insnsi.h nasmlib.h
-outrdf.$(OBJ): outrdf.c nasm.h insnsi.h nasmlib.h
outrdf2.$(OBJ): outrdf2.c nasm.h insnsi.h nasmlib.h
zoutieee.$(OBJ): zoutieee.c nasm.h insnsi.h nasmlib.h
outform.$(OBJ): outform.c outform.h nasm.h insnsi.h
diff --git a/Mkfiles/Makefile.scw b/Mkfiles/Makefile.scw
index 510b72a6..d7ce92e4 100644
--- a/Mkfiles/Makefile.scw
+++ b/Mkfiles/Makefile.scw
@@ -99,7 +99,6 @@ outcoff.$(OBJ): outcoff.c nasm.h insnsi.h nasmlib.h
outdbg.$(OBJ): outdbg.c nasm.h insnsi.h nasmlib.h
outelf.$(OBJ): outelf.c nasm.h insnsi.h nasmlib.h
outobj.$(OBJ): outobj.c nasm.h insnsi.h nasmlib.h
-outrdf.$(OBJ): outrdf.c nasm.h insnsi.h nasmlib.h
outrdf2.$(OBJ): outrdf2.c nasm.h insnsi.h nasmlib.h
zoutieee.$(OBJ): zoutieee.c nasm.h insnsi.h nasmlib.h
outform.$(OBJ): outform.c outform.h nasm.h insnsi.h
diff --git a/Mkfiles/Makefile.unx b/Mkfiles/Makefile.unx
index ef47696a..9bcb0c87 100644
--- a/Mkfiles/Makefile.unx
+++ b/Mkfiles/Makefile.unx
@@ -62,7 +62,6 @@ outdbg.o: outdbg.c nasm.h insnsi.h nasmlib.h outform.h
outelf.o: outelf.c nasm.h insnsi.h nasmlib.h outform.h
outform.o: outform.c outform.h nasm.h insnsi.h
outobj.o: outobj.c nasm.h insnsi.h nasmlib.h outform.h
-outrdf.o: outrdf.c nasm.h insnsi.h nasmlib.h outform.h
outrdf2.o: outrdf2.c nasm.h insnsi.h nasmlib.h outform.h
zoutieee.o: zoutieee.c nasm.h insnsi.h nasmlib.h outform.h
parser.o: parser.c nasm.h insnsi.h nasmlib.h parser.h float.h names.c insnsn.c
diff --git a/Mkfiles/Makefile.vc b/Mkfiles/Makefile.vc
index 0bc4f68d..4b8c280a 100644
--- a/Mkfiles/Makefile.vc
+++ b/Mkfiles/Makefile.vc
@@ -58,7 +58,6 @@ outcoff.$(OBJ): outcoff.c nasm.h insnsi.h nasmlib.h
outdbg.$(OBJ): outdbg.c nasm.h insnsi.h nasmlib.h
outelf.$(OBJ): outelf.c nasm.h insnsi.h nasmlib.h
outobj.$(OBJ): outobj.c nasm.h insnsi.h nasmlib.h
-outrdf.$(OBJ): outrdf.c nasm.h insnsi.h nasmlib.h
outrdf2.$(OBJ): outrdf2.c nasm.h insnsi.h nasmlib.h
zoutieee.$(OBJ): zoutieee.c nasm.h insnsi.h nasmlib.h
outform.$(OBJ): outform.c outform.h nasm.h insnsi.h
diff --git a/Mkfiles/Makefile.wc b/Mkfiles/Makefile.wc
index 85b20ec7..3feb8605 100644
--- a/Mkfiles/Makefile.wc
+++ b/Mkfiles/Makefile.wc
@@ -109,7 +109,6 @@ outbin.$(OBJ): outbin.c nasm.h insnsi.h nasmlib.h
outcoff.$(OBJ): outcoff.c nasm.h insnsi.h nasmlib.h
outelf.$(OBJ): outelf.c nasm.h insnsi.h nasmlib.h
outobj.$(OBJ): outobj.c nasm.h insnsi.h nasmlib.h
-outrdf.$(OBJ): outrdf.c nasm.h insnsi.h nasmlib.h
outrdf2.$(OBJ): outrdf2.c nasm.h insnsi.h nasmlib.h
zoutieee.$(OBJ): zoutieee.c nasm.h insnsi.h nasmlib.h
outform.$(OBJ): outform.c outform.h nasm.h insnsi.h
diff --git a/Mkfiles/Makefile.wcw b/Mkfiles/Makefile.wcw
index 289c45de..81a96fee 100644
--- a/Mkfiles/Makefile.wcw
+++ b/Mkfiles/Makefile.wcw
@@ -109,7 +109,6 @@ outbin.$(OBJ): outbin.c nasm.h insnsi.h nasmlib.h
outcoff.$(OBJ): outcoff.c nasm.h insnsi.h nasmlib.h
outelf.$(OBJ): outelf.c nasm.h insnsi.h nasmlib.h
outobj.$(OBJ): outobj.c nasm.h insnsi.h nasmlib.h
-outrdf.$(OBJ): outrdf.c nasm.h insnsi.h nasmlib.h
outrdf2.$(OBJ): outrdf2.c nasm.h insnsi.h nasmlib.h
zoutieee.$(OBJ): zoutieee.c nasm.h insnsi.h nasmlib.h
outform.$(OBJ): outform.c outform.h nasm.h insnsi.h
diff --git a/insns.dat b/insns.dat
index ca6c3b98..fff23ee3 100644
--- a/insns.dat
+++ b/insns.dat
@@ -37,14 +37,14 @@ ADC rm16,imm8 \320\300\1\x83\202\15 8086
ADC rm32,imm8 \321\300\1\x83\202\15 386
ADC reg_al,imm \1\x14\21 8086,SM
ADC reg_ax,imm \320\1\x15\31 8086,SM
-ADC reg_eax,sbyte \321\1\x83\202\15 386,SM,ND
-ADC reg_eax,imm \321\1\x15\41 386,SM
+ADC reg_eax,sbyte \321\1\x83\202\15 386,SM,ND
+ADC reg_eax,imm \321\1\x15\41 386,SM
ADC rm8,imm \300\1\x80\202\21 8086,SM
-ADC rm16,imm \320\300\134\1\x81\202\131 8086,SM
-ADC rm32,imm \321\300\144\1\x81\202\141 386,SM
+ADC rm16,imm \320\300\134\1\x81\202\131 8086,SM
+ADC rm32,imm \321\300\144\1\x81\202\141 386,SM
ADC mem,imm8 \300\1\x80\202\21 8086,SM
-ADC mem,imm16 \320\300\134\1\x81\202\131 8086,SM
-ADC mem,imm32 \321\300\144\1\x81\202\141 386,SM
+ADC mem,imm16 \320\300\134\1\x81\202\131 8086,SM
+ADC mem,imm32 \321\300\144\1\x81\202\141 386,SM
ADD mem,reg8 \300\17\101 8086,SM
ADD reg8,reg8 \300\17\101 8086
ADD mem,reg16 \320\300\1\x01\101 8086,SM
@@ -61,14 +61,14 @@ ADD rm16,imm8 \320\300\1\x83\200\15 8086
ADD rm32,imm8 \321\300\1\x83\200\15 386
ADD reg_al,imm \1\x04\21 8086,SM
ADD reg_ax,imm \320\1\x05\31 8086,SM
-ADD reg_eax,sbyte \321\1\x83\200\15 386,SM,ND
+ADD reg_eax,sbyte \321\1\x83\200\15 386,SM,ND
ADD reg_eax,imm \321\1\x05\41 386,SM
ADD rm8,imm \300\1\x80\200\21 8086,SM
-ADD rm16,imm \320\300\134\1\x81\200\131 8086,SM
-ADD rm32,imm \321\300\144\1\x81\200\141 386,SM
+ADD rm16,imm \320\300\134\1\x81\200\131 8086,SM
+ADD rm32,imm \321\300\144\1\x81\200\141 386,SM
ADD mem,imm8 \300\1\x80\200\21 8086,SM
-ADD mem,imm16 \320\300\134\1\x81\200\131 8086,SM
-ADD mem,imm32 \321\300\144\1\x81\200\141 386,SM
+ADD mem,imm16 \320\300\134\1\x81\200\131 8086,SM
+ADD mem,imm32 \321\300\144\1\x81\200\141 386,SM
AND mem,reg8 \300\1\x20\101 8086,SM
AND reg8,reg8 \300\1\x20\101 8086
AND mem,reg16 \320\300\1\x21\101 8086,SM
@@ -85,14 +85,14 @@ AND rm16,imm8 \320\300\1\x83\204\15 8086
AND rm32,imm8 \321\300\1\x83\204\15 386
AND reg_al,imm \1\x24\21 8086,SM
AND reg_ax,imm \320\1\x25\31 8086,SM
-AND reg_eax,sbyte \321\1\x83\204\15 386,SM,ND
+AND reg_eax,sbyte \321\1\x83\204\15 386,SM,ND
AND reg_eax,imm \321\1\x25\41 386,SM
AND rm8,imm \300\1\x80\204\21 8086,SM
-AND rm16,imm \320\300\134\1\x81\204\131 8086,SM
-AND rm32,imm \321\300\144\1\x81\204\141 386,SM
+AND rm16,imm \320\300\134\1\x81\204\131 8086,SM
+AND rm32,imm \321\300\144\1\x81\204\141 386,SM
AND mem,imm8 \300\1\x80\204\21 8086,SM
-AND mem,imm16 \320\300\134\1\x81\204\131 8086,SM
-AND mem,imm32 \321\300\144\1\x81\204\141 386,SM
+AND mem,imm16 \320\300\134\1\x81\204\131 8086,SM
+AND mem,imm32 \321\300\144\1\x81\204\141 386,SM
ARPL mem,reg16 \300\1\x63\101 286,PROT,SM
ARPL reg16,reg16 \300\1\x63\101 286,PROT
BOUND reg16,mem \320\301\1\x62\110 186
@@ -178,14 +178,14 @@ CMP rm16,imm8 \320\300\1\x83\207\15 8086
CMP rm32,imm8 \321\300\1\x83\207\15 386
CMP reg_al,imm \1\x3C\21 8086,SM
CMP reg_ax,imm \320\1\x3D\31 8086,SM
-CMP reg_eax,sbyte \321\1\x83\207\15 386,SM,ND
+CMP reg_eax,sbyte \321\1\x83\207\15 386,SM,ND
CMP reg_eax,imm \321\1\x3D\41 386,SM
CMP rm8,imm \300\1\x80\207\21 8086,SM
-CMP rm16,imm \320\300\134\1\x81\207\131 8086,SM
-CMP rm32,imm \321\300\144\1\x81\207\141 386,SM
+CMP rm16,imm \320\300\134\1\x81\207\131 8086,SM
+CMP rm32,imm \321\300\144\1\x81\207\141 386,SM
CMP mem,imm8 \300\1\x80\207\21 8086,SM
-CMP mem,imm16 \320\300\134\1\x81\207\131 8086,SM
-CMP mem,imm32 \321\300\144\1\x81\207\141 386,SM
+CMP mem,imm16 \320\300\134\1\x81\207\131 8086,SM
+CMP mem,imm32 \321\300\144\1\x81\207\141 386,SM
CMPSB void \332\1\xA6 8086
CMPSD void \332\321\1\xA7 386
CMPSW void \332\320\1\xA7 8086
@@ -423,29 +423,29 @@ IMUL reg16,reg16 \320\2\x0F\xAF\110 386
IMUL reg32,mem \321\301\2\x0F\xAF\110 386,SM
IMUL reg32,reg32 \321\2\x0F\xAF\110 386
IMUL reg16,mem,imm8 \320\301\1\x6B\110\16 186,SM
-IMUL reg16,mem,sbyte \320\301\1\x6B\110\16 186,SM,ND
-IMUL reg16,mem,imm16 \320\301\1\x69\110\32 186,SM
-IMUL reg16,mem,imm \320\301\135\1\x69\110\132 186,SM,ND
+IMUL reg16,mem,sbyte \320\301\1\x6B\110\16 186,SM,ND
+IMUL reg16,mem,imm16 \320\301\1\x69\110\32 186,SM
+IMUL reg16,mem,imm \320\301\135\1\x69\110\132 186,SM,ND
IMUL reg16,reg16,imm8 \320\1\x6B\110\16 186
-IMUL reg16,reg16,sbyte \320\1\x6B\110\16 186,SM,ND
-IMUL reg16,reg16,imm16 \320\1\x69\110\32 186
-IMUL reg16,reg16,imm \320\135\1\x69\110\132 186,SM,ND
+IMUL reg16,reg16,sbyte \320\1\x6B\110\16 186,SM,ND
+IMUL reg16,reg16,imm16 \320\1\x69\110\32 186
+IMUL reg16,reg16,imm \320\135\1\x69\110\132 186,SM,ND
IMUL reg32,mem,imm8 \321\301\1\x6B\110\16 386,SM
-IMUL reg32,mem,sbyte \321\301\1\x6B\110\16 386,SM,ND
-IMUL reg32,mem,imm32 \321\301\1\x69\110\42 386,SM
-IMUL reg32,mem,imm \321\301\145\1\x69\110\142 386,SM,ND
+IMUL reg32,mem,sbyte \321\301\1\x6B\110\16 386,SM,ND
+IMUL reg32,mem,imm32 \321\301\1\x69\110\42 386,SM
+IMUL reg32,mem,imm \321\301\145\1\x69\110\142 386,SM,ND
IMUL reg32,reg32,imm8 \321\1\x6B\110\16 386
-IMUL reg32,reg32,sbyte \321\1\x6B\110\16 386,SM,ND
-IMUL reg32,reg32,imm32 \321\1\x69\110\42 386
-IMUL reg32,reg32,imm \321\145\1\x69\110\142 386,SM,ND
+IMUL reg32,reg32,sbyte \321\1\x6B\110\16 386,SM,ND
+IMUL reg32,reg32,imm32 \321\1\x69\110\42 386
+IMUL reg32,reg32,imm \321\145\1\x69\110\142 386,SM,ND
IMUL reg16,imm8 \320\1\x6B\100\15 186
-IMUL reg16,sbyte \320\1\x6B\100\15 186,SM,ND
-IMUL reg16,imm16 \320\1\x69\100\31 186
-IMUL reg16,imm \320\134\1\x69\100\131 186,SM,ND
+IMUL reg16,sbyte \320\1\x6B\100\15 186,SM,ND
+IMUL reg16,imm16 \320\1\x69\100\31 186
+IMUL reg16,imm \320\134\1\x69\100\131 186,SM,ND
IMUL reg32,imm8 \321\1\x6B\100\15 386
-IMUL reg32,sbyte \321\1\x6B\100\15 386,SM,ND
-IMUL reg32,imm32 \321\1\x69\100\41 386
-IMUL reg32,imm \321\144\1\x69\100\141 386,SM,ND
+IMUL reg32,sbyte \321\1\x6B\100\15 386,SM,ND
+IMUL reg32,imm32 \321\1\x69\100\41 386
+IMUL reg32,imm \321\144\1\x69\100\141 386,SM,ND
IN reg_al,imm \1\xE4\25 8086,SB
IN reg_ax,imm \320\1\xE5\25 8086,SB
IN reg_eax,imm \321\1\xE5\25 386,SB
@@ -475,7 +475,7 @@ IRETW void \320\1\xCF 8086
JCXZ imm \310\1\xE3\50 8086
JECXZ imm \311\1\xE3\50 386
JMP imm|short \1\xEB\50 8086
-JMP imm \371\1\xEB\50 8086,ND
+JMP imm \371\1\xEB\50 8086,ND
JMP imm \322\1\xE9\64 8086
JMP imm|near \322\1\xE9\64 8086,ND
JMP imm|far \322\1\xEA\34\37 8086,ND
@@ -554,9 +554,9 @@ LSS reg32,mem \321\301\2\x0F\xB2\110 386
LTR mem \300\1\x0F\17\203 286,PROT,PRIV
LTR mem16 \300\1\x0F\17\203 286,PROT,PRIV
LTR reg16 \300\1\x0F\17\203 286,PROT,PRIV
-MOV mem,reg_cs \300\1\x8C\201 8086,SM
-MOV mem,reg_dess \300\1\x8C\101 8086,SM
-MOV mem,reg_fsgs \300\1\x8C\101 386,SM
+MOV mem,reg_cs \300\1\x8C\201 8086,SM
+MOV mem,reg_dess \300\1\x8C\101 8086,SM
+MOV mem,reg_fsgs \300\1\x8C\101 386,SM
MOV reg16,reg_cs \320\300\1\x8C\201 8086
MOV reg16,reg_dess \320\300\1\x8C\101 8086
MOV reg16,reg_fsgs \320\300\1\x8C\101 386
@@ -649,14 +649,14 @@ OR rm16,imm8 \320\300\1\x83\201\15 8086
OR rm32,imm8 \321\300\1\x83\201\15 386
OR reg_al,imm \1\x0C\21 8086,SM
OR reg_ax,imm \320\1\x0D\31 8086,SM
-OR reg_eax,sbyte \321\1\x83\201\15 386,SM,ND
+OR reg_eax,sbyte \321\1\x83\201\15 386,SM,ND
OR reg_eax,imm \321\1\x0D\41 386,SM
OR rm8,imm \300\1\x80\201\21 8086,SM
-OR rm16,imm \320\300\134\1\x81\201\131 8086,SM
-OR rm32,imm \321\300\144\1\x81\201\141 386,SM
+OR rm16,imm \320\300\134\1\x81\201\131 8086,SM
+OR rm32,imm \321\300\144\1\x81\201\141 386,SM
OR mem,imm8 \300\1\x80\201\21 8086,SM
-OR mem,imm16 \320\300\134\1\x81\201\131 8086,SM
-OR mem,imm32 \321\300\144\1\x81\201\141 386,SM
+OR mem,imm16 \320\300\134\1\x81\201\131 8086,SM
+OR mem,imm32 \321\300\144\1\x81\201\141 386,SM
OUT imm,reg_al \1\xE6\24 8086,SB
OUT imm,reg_ax \320\1\xE7\24 8086,SB
OUT imm,reg_eax \321\1\xE7\24 386,SB
@@ -941,14 +941,14 @@ SBB rm16,imm8 \320\300\1\x83\203\15 8086
SBB rm32,imm8 \321\300\1\x83\203\15 8086
SBB reg_al,imm \1\x1C\21 8086,SM
SBB reg_ax,imm \320\1\x1D\31 8086,SM
-SBB reg_eax,sbyte \321\1\x83\203\15 386,SM,ND
+SBB reg_eax,sbyte \321\1\x83\203\15 386,SM,ND
SBB reg_eax,imm \321\1\x1D\41 386,SM
SBB rm8,imm \300\1\x80\203\21 8086,SM
-SBB rm16,imm \320\300\134\1\x81\203\131 8086,SM
-SBB rm32,imm \321\300\144\1\x81\203\141 386,SM
+SBB rm16,imm \320\300\134\1\x81\203\131 8086,SM
+SBB rm32,imm \321\300\144\1\x81\203\141 386,SM
SBB mem,imm8 \300\1\x80\203\21 8086,SM
-SBB mem,imm16 \320\300\134\1\x81\203\131 8086,SM
-SBB mem,imm32 \321\300\144\1\x81\203\141 386,SM
+SBB mem,imm16 \320\300\134\1\x81\203\131 8086,SM
+SBB mem,imm32 \321\300\144\1\x81\203\141 386,SM
SCASB void \332\1\xAE 8086
SCASD void \332\321\1\xAF 386
SCASW void \332\320\1\xAF 8086
@@ -1023,14 +1023,14 @@ SUB rm16,imm8 \320\300\1\x83\205\15 8086
SUB rm32,imm8 \321\300\1\x83\205\15 386
SUB reg_al,imm \1\x2C\21 8086,SM
SUB reg_ax,imm \320\1\x2D\31 8086,SM
-SUB reg_eax,sbyte \321\1\x83\205\15 386,SM,ND
+SUB reg_eax,sbyte \321\1\x83\205\15 386,SM,ND
SUB reg_eax,imm \321\1\x2D\41 386,SM
SUB rm8,imm \300\1\x80\205\21 8086,SM
-SUB rm16,imm \320\300\134\1\x81\205\131 8086,SM
-SUB rm32,imm \321\300\144\1\x81\205\141 386,SM
+SUB rm16,imm \320\300\134\1\x81\205\131 8086,SM
+SUB rm32,imm \321\300\144\1\x81\205\141 386,SM
SUB mem,imm8 \300\1\x80\205\21 8086,SM
-SUB mem,imm16 \320\300\134\1\x81\205\131 8086,SM
-SUB mem,imm32 \321\300\144\1\x81\205\141 386,SM
+SUB mem,imm16 \320\300\134\1\x81\205\131 8086,SM
+SUB mem,imm32 \321\300\144\1\x81\205\141 386,SM
SVDC mem80,reg_sreg \300\2\x0F\x78\101 486,CYRIX,SMM
SVLDT mem80 \300\2\x0F\x7A\200 486,CYRIX,SMM
SVTS mem80 \300\2\x0F\x7C\200 486,CYRIX,SMM
@@ -1125,14 +1125,14 @@ XOR rm16,imm8 \320\300\1\x83\206\15 8086
XOR rm32,imm8 \321\300\1\x83\206\15 386
XOR reg_al,imm \1\x34\21 8086,SM
XOR reg_ax,imm \320\1\x35\31 8086,SM
-XOR reg_eax,sbyte \321\1\x83\206\15 386,SM,ND
+XOR reg_eax,sbyte \321\1\x83\206\15 386,SM,ND
XOR reg_eax,imm \321\1\x35\41 386,SM
XOR rm8,imm \300\1\x80\206\21 8086,SM
-XOR rm16,imm \320\300\134\1\x81\206\131 8086,SM
-XOR rm32,imm \321\300\144\1\x81\206\141 386,SM
+XOR rm16,imm \320\300\134\1\x81\206\131 8086,SM
+XOR rm32,imm \321\300\144\1\x81\206\141 386,SM
XOR mem,imm8 \300\1\x80\206\21 8086,SM
-XOR mem,imm16 \320\300\134\1\x81\206\131 8086,SM
-XOR mem,imm32 \321\300\144\1\x81\206\141 386,SM
+XOR mem,imm16 \320\300\134\1\x81\206\131 8086,SM
+XOR mem,imm32 \321\300\144\1\x81\206\141 386,SM
CMOVcc reg16,mem \320\301\1\x0F\330\x40\110 P6,SM
CMOVcc reg16,reg16 \320\301\1\x0F\330\x40\110 P6
CMOVcc reg32,mem \321\301\1\x0F\330\x40\110 P6,SM
diff --git a/nasm.h b/nasm.h
index 684b4e83..3571a7f3 100644
--- a/nasm.h
+++ b/nasm.h
@@ -13,7 +13,7 @@
#define NASM_MAJOR_VER 0
#define NASM_MINOR_VER 98
-#define NASM_VER "0.98.22"
+#define NASM_VER "0.98.23"
#ifndef NULL
#define NULL 0
diff --git a/preproc.c b/preproc.c
index 4ec38269..a6a6d6b2 100644
--- a/preproc.c
+++ b/preproc.c
@@ -1199,7 +1199,7 @@ get_ctx(char *name, int all_contexts)
for (i = strspn(name + 2, "$"), ctx = cstk; (i > 0) && ctx; i--)
{
ctx = ctx->next;
- i--;
+/* i--; Lino - 02/25/02 */
}
if (!ctx)
{
@@ -3741,7 +3741,8 @@ expand_mmacro(Token * tline)
t = tline;
skip_white_(t);
- if (!tok_type_(t, TOK_ID))
+/* if (!tok_type_(t, TOK_ID)) Lino 02/25/02 */
+ if (!tok_type_(t, TOK_ID) && !tok_type_(t, TOK_PREPROC_ID))
return 0;
m = is_mmacro(t, &params);
if (!m)
diff --git a/rdoff/ldrdf1.c b/rdoff/ldrdf1.c
new file mode 100644
index 00000000..9e4a215d
--- /dev/null
+++ b/rdoff/ldrdf1.c
@@ -0,0 +1,728 @@
+/* ldrdf.c RDOFF Object File linker/loader main program
+ *
+ * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
+ * Julian Hall. All rights reserved. The software is
+ * redistributable under the licence given in the file "Licence"
+ * distributed in the NASM archive.
+ */
+
+/* TODO: Make the system skip a module (other than the first) if none
+ * of the other specified modules contain a reference to it.
+ * May require the system to make an extra pass of the modules to be
+ * loaded eliminating those that aren't required.
+ *
+ * Support all the existing documented options...
+ *
+ * Support libaries (.a files - requires a 'ranlib' type utility)
+ * (I think I've got this working, so I've upped the version)
+ *
+ * -s option to strip resolved symbols from exports. (Could make this an
+ * external utility)
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "rdoff.h"
+#include "nasmlib.h"
+#include "symtab.h"
+#include "collectn.h"
+#include "rdlib.h"
+
+#define LDRDF_VERSION "0.30"
+
+/* global variables - those to set options: */
+
+int verbose = 0; /* reflects setting of command line switch */
+int align = 16;
+int errors = 0; /* set by functions to cause halt after current
+ stage of processing */
+
+/* the linked list of modules that must be loaded & linked */
+
+struct modulenode {
+ rdffile f; /* the file */
+ long coderel; /* module's code relocation factor */
+ long datarel; /* module's data relocation factor */
+ long bssrel; /* module's bss data reloc. factor */
+ void * header; /* header location, if loaded */
+ char * name; /* filename */
+ struct modulenode *next;
+};
+
+#define newstr(str) strcpy(malloc(strlen(str) + 1),str)
+#define newstrcat(s1,s2) strcat(strcpy(malloc(strlen(s1)+strlen(s2)+1),s1),s2)
+
+
+struct modulenode *modules = NULL,*lastmodule = NULL;
+
+/* the linked list of libraries to be searched for missing imported
+ symbols */
+
+struct librarynode * libraries = NULL, * lastlib = NULL;
+
+void *symtab; /* The symbol table */
+
+rdf_headerbuf * newheader ; /* New header to be written to output */
+
+/* loadmodule - find the characteristics of a module and add it to the
+ * list of those being linked together */
+
+void loadmodule(char *filename)
+{
+ struct modulenode *prev;
+ if (! modules) {
+ modules = malloc(sizeof(struct modulenode));
+ lastmodule = modules;
+ prev = NULL;
+ }
+ else {
+ lastmodule->next = malloc(sizeof(struct modulenode));
+ prev = lastmodule;
+ lastmodule = lastmodule->next;
+ }
+
+ if (! lastmodule) {
+ fputs("ldrdf: not enough memory\n",stderr);
+ exit(1);
+ }
+
+ if (rdfopen(&lastmodule->f,filename)) {
+ rdfperror("ldrdf",filename);
+ exit(1);
+ }
+
+ lastmodule->header = NULL; /* header hasn't been loaded */
+ lastmodule->name = filename;
+ lastmodule->next = NULL;
+
+ if (prev) {
+ lastmodule->coderel = prev->coderel + prev->f.code_len;
+ if (lastmodule->coderel % align != 0)
+ lastmodule->coderel += align - (lastmodule->coderel % align);
+ lastmodule->datarel = prev->datarel + prev->f.data_len;
+ if (lastmodule->datarel % align != 0)
+ lastmodule->datarel += align - (lastmodule->datarel % align);
+ }
+ else {
+ lastmodule->coderel = 0;
+ lastmodule->datarel = 0;
+ }
+
+ if (verbose)
+ printf("%s code = %08lx (+%04lx), data = %08lx (+%04lx)\n",filename,
+ lastmodule->coderel,lastmodule->f.code_len,
+ lastmodule->datarel,lastmodule->f.data_len);
+
+ lastmodule->header = malloc(lastmodule->f.header_len);
+ if (!lastmodule->header) {
+ fprintf(stderr,"ldrdf: out of memory\n");
+ exit(1);
+ }
+
+ if (rdfloadseg(&lastmodule->f,RDOFF_HEADER,lastmodule->header))
+ {
+ rdfperror("ldrdf",filename);
+ exit(1);
+ }
+}
+
+/* load_library add a library to list of libraries to search
+ * for undefined symbols
+ */
+
+void load_library(char * name)
+{
+ if (verbose)
+ printf("adding library %s to search path\n",name);
+
+ if (! lastlib) {
+ lastlib = libraries = malloc(sizeof(struct librarynode));
+ }
+ else
+ {
+ lastlib->next = malloc(sizeof(struct librarynode));
+ lastlib = lastlib->next;
+ }
+
+ if (! lastlib) {
+ fprintf(stderr, "ldrdf: out of memory\n");
+ exit(1);
+ }
+ strcpy (lastlib->name = malloc (1+strlen(name)), name);
+ lastlib->fp = NULL;
+ lastlib->referenced = 0;
+ lastlib->next = NULL;
+}
+
+
+/* build_symbols() step through each module's header, and locate
+ * exported symbols, placing them in a global table
+ */
+
+long bsslength;
+
+void mod_addsymbols(struct modulenode * mod)
+{
+ rdfheaderrec *r;
+ symtabEnt e;
+ long cbBss;
+
+ mod->bssrel = bsslength;
+ cbBss = 0;
+ rdfheaderrewind(&mod->f);
+ while ((r = rdfgetheaderrec(&mod->f)))
+ {
+
+ if (r->type == 5) /* Allocate BSS */
+ cbBss += r->b.amount;
+
+ if (r->type != 3) continue; /* ignore all but export recs */
+
+ e.segment = r->e.segment;
+ e.offset = r->e.offset +
+ (e.segment == 0 ? mod->coderel : /* 0 -> code */
+ e.segment == 1 ? mod->datarel : /* 1 -> data */
+ mod->bssrel) ; /* 2 -> bss */
+
+ e.flags = 0;
+ e.name = malloc(strlen(r->e.label) + 1);
+ if (! e.name)
+ {
+ fprintf(stderr,"ldrdf: out of memory\n");
+ exit(1);
+ }
+ strcpy(e.name,r->e.label);
+ symtabInsert(symtab,&e);
+ }
+ bsslength += cbBss;
+}
+
+void build_symbols()
+{
+ struct modulenode *mod;
+
+ if (verbose) printf("building global symbol table:\n");
+ newheader = rdfnewheader();
+
+ symtab = symtabNew();
+ bsslength = 0; /* keep track of location of BSS symbols */
+
+ for (mod = modules; mod; mod = mod->next)
+ {
+ mod_addsymbols( mod );
+ }
+ if (verbose)
+ {
+ symtabDump(symtab,stdout);
+ printf("BSS length = %ld bytes\n\n",bsslength);
+ }
+}
+
+
+/* scan_libraries() search through headers of modules for undefined
+ * symbols, and scan libraries for those symbols,
+ * adding library modules found to list of modules
+ * to load. */
+
+void scan_libraries(void)
+{
+ struct modulenode * mod, * nm;
+ struct librarynode * lib;
+ rdfheaderrec * r;
+ int found;
+ char * tmp;
+
+ if (verbose) printf("Scanning libraries for unresolved symbols...\n");
+
+ mod = modules;
+
+ while (mod)
+ {
+ rdfheaderrewind(&mod->f);
+
+ while ((r = rdfgetheaderrec(&mod->f)))
+ {
+ if (r->type != 2) continue; /* not an import record */
+ if ( symtabFind (symtab,r->i.label) )
+ continue; /* symbol already defined */
+
+ /* okay, we have an undefined symbol... step through
+ the libraries now */
+ if (verbose >= 2) {
+ printf("undefined symbol '%s'...",r->i.label);
+ fflush(stdout);
+ }
+
+ lib = libraries;
+ found = 0;
+
+ tmp = newstr(r->i.label);
+ while (! found && lib)
+ {
+ /* move this to an outer loop...! */
+ nm = malloc(sizeof(struct modulenode));
+
+ if (rdl_searchlib(lib,tmp,&nm->f))
+ { /* found a module in the library */
+
+ /* create a modulenode for it */
+
+ if (! nm) {
+ fprintf(stderr,"ldrdf: out of memory\n");
+ exit(1);
+ }
+
+ nm->name = newstrcat(lib->name,nm->f.name);
+ if (verbose >= 2) printf("found in '%s'\n",nm->name);
+
+ nm->coderel = lastmodule->coderel + lastmodule->f.code_len;
+ if (nm->coderel % align != 0)
+ nm->coderel += align - (nm->coderel % align);
+
+ nm->datarel = lastmodule->datarel + lastmodule->f.data_len;
+ if (nm->datarel % align != 0)
+ nm->datarel += align - (nm->datarel % align);
+
+ nm->header = malloc(nm->f.header_len);
+ if (! nm->header)
+ {
+ fprintf(stderr,"ldrdf: out of memory\n");
+ exit(1);
+ }
+
+ if (rdfloadseg(&nm->f,RDOFF_HEADER,nm->header))
+ {
+ rdfperror("ldrdf",nm->name);
+ exit(1);
+ }
+
+ nm->next = NULL;
+ found = 1;
+ lastmodule->next = nm;
+ lastmodule = nm;
+
+ if (verbose)
+ printf("%s code = %08lx (+%04lx), data = %08lx "
+ "(+%04lx)\n",lastmodule->name,
+ lastmodule->coderel,lastmodule->f.code_len,
+ lastmodule->datarel,lastmodule->f.data_len);
+
+ /* add the module's info to the symbol table */
+ mod_addsymbols(nm);
+ }
+ else
+ {
+ if (rdl_error) {
+ rdl_perror("ldrdf",lib->name);
+ exit(1);
+ }
+ free(nm);
+ }
+ lib = lib->next;
+ }
+ free(tmp);
+ if (!found && verbose >= 2) printf("not found\n");
+ }
+ mod = mod->next;
+ }
+}
+
+/* load_segments() allocates memory for & loads the code & data segs
+ * from the RDF modules
+ */
+
+char *text,*data;
+long textlength,datalength;
+
+void load_segments(void)
+{
+ struct modulenode *mod;
+
+ if (!modules) {
+ fprintf(stderr,"ldrdf: nothing to do\n");
+ exit(0);
+ }
+ if (!lastmodule) {
+ fprintf(stderr,"ldrdf: panic: module list exists, but lastmodule=NULL\n");
+ exit(3);
+ }
+
+ if (verbose)
+ printf("loading modules into memory\n");
+
+ /* The following stops 16 bit DOS from crashing whilst attempting to
+ work using segments > 64K */
+ if (sizeof(int) == 2) { /* expect a 'code has no effect' warning on 32 bit
+ platforms... */
+ if (lastmodule->coderel + lastmodule->f.code_len > 65535 ||
+ lastmodule->datarel + lastmodule->f.data_len > 65535) {
+ fprintf(stderr,"ldrdf: segment length has exceeded 64K; use a 32 bit "
+ "version.\nldrdf: code size = %05lx, data size = %05lx\n",
+ lastmodule->coderel + lastmodule->f.code_len,
+ lastmodule->datarel + lastmodule->f.data_len);
+ exit(1);
+ }
+ }
+
+ text = malloc(textlength = lastmodule->coderel + lastmodule->f.code_len);
+ data = malloc(datalength = lastmodule->datarel + lastmodule->f.data_len);
+
+ if (!text || !data) {
+ fprintf(stderr,"ldrdf: out of memory\n");
+ exit(1);
+ }
+
+ mod = modules;
+ while (mod) { /* load the segments for each module */
+ if (verbose >= 2) printf(" loading %s\n",mod->name);
+ if (rdfloadseg(&mod->f,RDOFF_CODE,&text[mod->coderel]) ||
+ rdfloadseg(&mod->f,RDOFF_DATA,&data[mod->datarel])) {
+ rdfperror("ldrdf",mod->name);
+ exit(1);
+ }
+ rdfclose(&mod->f); /* close file; segments remain */
+ mod = mod->next;
+ }
+}
+
+/* link_segments() step through relocation records in each module's
+ * header, fixing up references.
+ */
+
+void link_segments(void)
+{
+ struct modulenode *mod;
+ Collection imports;
+ symtabEnt *s;
+ long rel,relto;
+ char *seg;
+ rdfheaderrec *r;
+ int bRelative;
+
+ if (verbose) printf("linking segments\n");
+
+ collection_init(&imports);
+
+ for (mod = modules; mod; mod = mod->next) {
+ if (verbose >= 2) printf("* processing %s\n",mod->name);
+ rdfheaderrewind(&mod->f);
+ while((r = rdfgetheaderrec(&mod->f))) {
+ if (verbose >= 3) printf("record type: %d\n",r->type);
+ switch(r->type) {
+ case 1: /* relocation record */
+ if (r->r.segment >= 64) { /* Relative relocation; */
+ bRelative = 1; /* need to find location relative */
+ r->r.segment -= 64; /* to start of this segment */
+ relto = r->r.segment == 0 ? mod->coderel : mod->datarel;
+ }
+ else
+ {
+ bRelative = 0; /* non-relative - need to relocate
+ * at load time */
+ relto = 0; /* placate optimiser warnings */
+ }
+
+ /* calculate absolute offset of reference, not rel to beginning of
+ segment */
+ r->r.offset += r->r.segment == 0 ? mod->coderel : mod->datarel;
+
+ /* calculate the relocation factor to apply to the operand -
+ the base address of one of this modules segments if referred
+ segment is 0 - 2, or the address of an imported symbol
+ otherwise. */
+
+ if (r->r.refseg == 0) rel = mod->coderel;
+ else if (r->r.refseg == 1) rel = mod->datarel;
+ else if (r->r.refseg == 2) rel = mod->bssrel;
+ else { /* cross module link - find reference */
+ s = *colln(&imports,r->r.refseg - 2);
+ if (!s) {
+ fprintf(stderr,"ldrdf: link to undefined segment %04x in"
+ " %s:%d\n", r->r.refseg,mod->name,r->r.segment);
+ errors = 1;
+ break;
+ }
+ rel = s->offset;
+
+ r->r.refseg = s->segment; /* change referred segment,
+ so that new header is
+ correct */
+ }
+
+ if (bRelative) /* Relative - subtract current segment start */
+ rel -= relto;
+ else
+ { /* Add new relocation header */
+ rdfaddheader(newheader,r);
+ }
+
+ /* Work out which segment we're making changes to ... */
+ if (r->r.segment == 0) seg = text;
+ else if (r->r.segment == 1) seg = data;
+ else {
+ fprintf(stderr,"ldrdf: relocation in unknown segment %d in "
+ "%s\n", r->r.segment,mod->name);
+ errors = 1;
+ break;
+ }
+
+ /* Add the relocation factor to the datum specified: */
+
+ if (verbose >= 3)
+ printf(" - relocating %d:%08lx by %08lx\n",r->r.segment,
+ r->r.offset,rel);
+
+ /**** The following code is non-portable. Rewrite it... ****/
+ switch(r->r.length) {
+ case 1:
+ seg[r->r.offset] += (char) rel;
+ break;
+ case 2:
+ *(int16 *)(seg + r->r.offset) += (int16) rel;
+ break;
+ case 4:
+ *(long *)(seg + r->r.offset) += rel;
+ break;
+ }
+ break;
+
+ case 2: /* import record */
+ s = symtabFind(symtab, r->i.label);
+ if (s == NULL) {
+ /* Need to add support for dynamic linkage */
+ fprintf(stderr,"ldrdf: undefined symbol %s in module %s\n",
+ r->i.label,mod->name);
+ errors = 1;
+ }
+ else
+ {
+ *colln(&imports,r->i.segment - 2) = s;
+ if (verbose >= 2)
+ printf("imported %s as %04x\n", r->i.label, r->i.segment);
+ }
+ break;
+
+ case 3: /* export; dump to output new version */
+ s = symtabFind(symtab, r->e.label);
+ if (! s) {
+ fprintf(stderr,"ldrdf: internal error - undefined symbol %s "
+ "exported in header of '%s'\n",r->e.label,mod->name);
+ continue;
+ }
+ r->e.offset = s->offset;
+ rdfaddheader(newheader,r);
+ break;
+
+ case 4: /* DLL record */
+ rdfaddheader(newheader,r); /* copy straight to output */
+ break;
+ }
+ }
+ if (rdf_errno != 0) {
+ rdfperror("ldrdf",mod->name);
+ exit(1);
+ }
+ collection_reset(&imports);
+ }
+}
+
+/* write_output() write linked program out to a file */
+
+void write_output(char *filename)
+{
+ FILE * fp;
+ rdfheaderrec r;
+
+ if (verbose) printf("writing output to '%s'\n",filename);
+
+ fp = fopen(filename,"wb");
+ if (! fp)
+ {
+ fprintf(stderr,"ldrdf: could not open '%s' for writing\n",filename);
+ exit(1);
+ }
+
+
+ /* add BSS length count to header... */
+ if (bsslength)
+ {
+ r.type = 5;
+ r.b.amount = bsslength;
+ rdfaddheader(newheader,&r);
+ }
+
+ /* Write header */
+ rdfwriteheader(fp,newheader);
+ rdfdoneheader(newheader);
+ newheader = NULL;
+
+ /* Write text */
+ if (fwrite(&textlength,1,4,fp) != 4
+ || fwrite(text,1,textlength,fp) !=textlength)
+ {
+ fprintf(stderr,"ldrdf: error writing %s\n",filename);
+ exit(1);
+ }
+
+ /* Write data */
+ if (fwrite(&datalength,1,4,fp) != 4 ||
+ fwrite(data,1,datalength,fp) != datalength)
+ {
+ fprintf (stderr,"ldrdf: error writing %s\n", filename);
+ exit(1);
+ }
+ fclose(fp);
+}
+
+
+/* main program: interpret command line, and pass parameters on to
+ * individual module loaders & the linker
+ *
+ * Command line format:
+ * ldrdf [-o outfile | -x] [-r xxxx] [-v] [--] infile [infile ...]
+ *
+ * Default action is to output a file named 'aout.rdx'. -x specifies
+ * that the linked object program should be executed, rather than
+ * written to a file. -r specifies that the object program should
+ * be prelocated at address 'xxxx'. This option cannot be used
+ * in conjunction with -x.
+ */
+
+const char *usagemsg = "usage:\n"
+" ldrdf [-o outfile | -x] [-a x] [-v] [-p x] [--] infile [infile ...]\n"
+" [-l<libname> ...]\n\n"
+" ldrdf -h displays this message\n"
+" ldrdf -r displays version information\n\n"
+" -o selects output filename (default is aout.rdx)\n"
+" -x causes ldrdx to link & execute rather than write to file\n"
+" -a x causes object program to be statically relocated to address 'x'\n"
+" -v turns on verbose mode\n"
+" -p x causes segments to be aligned (padded) to x byte boundaries\n"
+" (default is 16 bytes)\n"
+" -l<name> causes 'name' to be linked in as a library. Note no search is\n"
+" performed - the entire pathname MUST be specified.\n";
+
+void usage(void)
+{
+ fputs(usagemsg,stderr);
+}
+
+int main(int argc,char **argv)
+{
+ char *ofilename = "aout.rdx";
+ long relocateaddr = -1; /* -1 if no relocation is to occur */
+ int execute = 0; /* 1 to execute after linking, 0 otherwise */
+ int procsw = 1; /* set to 0 by '--' */
+ int tmp;
+
+ if (argc == 1) {
+ usage();
+ exit(1);
+ }
+
+ /* process command line switches, and add modules specified to linked list
+ of modules, keeping track of total memory required to load them */
+
+ while(argv++,--argc) {
+ if (procsw && !strcmp(*argv,"-h")) { /* Help command */
+ usage(); exit(1);
+ }
+ else if (procsw && !strcmp(*argv,"-r")) {
+ printf("ldrdf version %s (%s) (%s)\n",LDRDF_VERSION,_RDOFF_H,
+ sizeof(int) == 2 ? "16 bit" : "32 bit");
+ exit(1);
+ }
+ else if (procsw && !strcmp(*argv,"-o")) {
+ ofilename = *++argv;
+ --argc;
+ if (execute) {
+ fprintf(stderr,"ldrdf: -o and -x switches incompatible\n");
+ exit(1);
+ }
+ if (verbose > 1) printf("output filename set to '%s'\n",ofilename);
+ }
+ else if (procsw && !strcmp(*argv,"-x")) {
+ execute++;
+ if (verbose > 1) printf("will execute linked object\n");
+ }
+ else if (procsw && !strcmp(*argv,"-a")) {
+ relocateaddr = readnum(*++argv,&tmp);
+ --argc;
+ if (tmp) {
+ fprintf(stderr,"ldrdf: error in parameter to '-a' switch: '%s'\n",
+ *argv);
+ exit(1);
+ }
+ if (execute) {
+ fprintf(stderr,"ldrdf: -a and -x switches incompatible\n");
+ exit(1);
+ }
+ if (verbose) printf("will relocate to %08lx\n",relocateaddr);
+ }
+ else if (procsw && !strcmp(*argv,"-v")) {
+ verbose++;
+ if (verbose == 1) printf("verbose mode selected\n");
+ }
+ else if (procsw && !strcmp(*argv,"-p")) {
+ align = readnum(*++argv,&tmp);
+ --argc;
+ if (tmp) {
+ fprintf(stderr,"ldrdf: error in parameter to '-p' switch: '%s'\n",
+ *argv);
+ exit(1);
+ }
+ if (align != 1 && align != 2 && align != 4 && align != 8 && align != 16
+ && align != 32 && align != 256) {
+ fprintf(stderr,"ldrdf: %d is an invalid alignment factor - must be"
+ "1,2,4,8,16 or 256\n",align);
+ exit(1);
+ }
+ if (verbose > 1) printf("alignment %d selected\n",align);
+ }
+ else if (procsw && !strncmp(*argv,"-l",2)) {
+ load_library(*argv + 2);
+ }
+ else if (procsw && !strcmp(*argv,"--")) {
+ procsw = 0;
+ }
+ else { /* is a filename */
+ if (verbose > 1) printf("processing module %s\n",*argv);
+ loadmodule(*argv);
+ }
+ }
+
+ /* we should be scanning for unresolved references, and removing
+ unreferenced modules from the list of modules here, so that
+ we know about the final size once libraries have been linked in */
+
+ build_symbols(); /* build a global symbol table... */
+
+ scan_libraries(); /* check for imported symbols not in table,
+ and ensure the relevant library modules
+ are loaded */
+
+ load_segments(); /* having calculated size of reqd segments, load
+ each rdoff module's segments into memory */
+
+ link_segments(); /* step through each module's header, and resolve
+ references to the global symbol table.
+ This also does local address fixups. */
+
+ if (errors) {
+ fprintf(stderr,"ldrdf: there were errors - aborted\n");
+ exit(errors);
+ }
+ if (execute) {
+ fprintf(stderr,"ldrdf: module execution not yet supported\n");
+ exit(1);
+ }
+ if (relocateaddr != -1) {
+ fprintf(stderr,"ldrdf: static relocation not yet supported\n");
+ exit(1);
+ }
+
+ write_output(ofilename);
+ return 0;
+}