rdoff: kill it off

RDOFF has been deprecated as it has unfixable problems, and has been
announced that it will be killed off in NASM 2.16.

This deletes it once and for all.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2022-11-07 16:49:13 -08:00
parent 6224dd0b45
commit 93548c2de2
57 changed files with 26 additions and 7321 deletions

View file

@ -77,7 +77,7 @@ endif
.SUFFIXES:
.SUFFIXES: $(X) .$(O) .$(A) .xml .1 .c .i .s .txt .time
.PHONY: all doc rdf install clean distclean cleaner spotless install_rdf test
.PHONY: all doc install clean distclean cleaner spotless test
.PHONY: install_doc everything install_everything strip perlreq dist tags TAGS
.PHONY: nothing manpages nsis
@ -143,7 +143,7 @@ LIBOBJ_NW = stdlib/snprintf.$(O) stdlib/vsnprintf.$(O) stdlib/strlcpy.$(O) \
output/nulldbg.$(O) output/nullout.$(O) \
output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) \
output/outelf.$(O) \
output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
output/outobj.$(O) output/outas86.$(O) \
output/outdbg.$(O) output/outieee.$(O) output/outmacho.$(O) \
output/codeview.$(O) \
\
@ -157,12 +157,12 @@ ALLOBJ_NW = $(PROGOBJ) $(LIBOBJ_NW)
ALLOBJ = $(PROGOBJ) $(LIBOBJ)
SUBDIRS = stdlib nasmlib output asm disasm x86 common macros
XSUBDIRS = test doc nsis rdoff
DEPDIRS = . include config x86 rdoff $(SUBDIRS)
XSUBDIRS = test doc nsis
DEPDIRS = . include config x86 $(SUBDIRS)
#-- End File Lists --#
all: dirs
$(MAKE) $(PROGS) rdf
$(MAKE) $(PROGS)
NASMLIB = libnasm.$(A)
@ -340,54 +340,6 @@ asm/directbl.c: asm/directiv.dat nasmlib/perfhash.pl perllib/phash.ph
perlreq: $(PERLREQ)
# This rule is only used for RDOFF
.$(O)$(X):
$(CC) $(ALL_LDFLAGS) -o $@ $< $(RDFLIB) $(NASMLIB) $(LIBS)
RDFLN = cd rdoff && ln -s
RDFLNPFX =
#-- Begin RDOFF Shared Rules --#
RDFLIBOBJ = rdoff/rdoff.$(O) rdoff/rdfload.$(O) rdoff/symtab.$(O) \
rdoff/collectn.$(O) rdoff/rdlib.$(O) rdoff/segtab.$(O) \
rdoff/hash.$(O)
RDFPROGS = rdoff/rdfdump$(X) rdoff/ldrdf$(X) rdoff/rdx$(X) rdoff/rdflib$(X) \
rdoff/rdf2bin$(X)
RDF2BINLINKS = rdoff/rdf2com$(X) rdoff/rdf2ith$(X) \
rdoff/rdf2ihx$(X) rdoff/rdf2srec$(X)
RDFLIB = rdoff/librdoff.$(A)
RDFLIBS = $(RDFLIB) $(NASMLIB)
rdoff/rdfdump$(X): rdoff/rdfdump.$(O) $(RDFLIBS)
rdoff/ldrdf$(X): rdoff/ldrdf.$(O) $(RDFLIBS)
rdoff/rdx$(X): rdoff/rdx.$(O) $(RDFLIBS)
rdoff/rdflib$(X): rdoff/rdflib.$(O) $(RDFLIBS)
rdoff/rdf2bin$(X): rdoff/rdf2bin.$(O) $(RDFLIBS)
rdoff/rdf2com$(X): rdoff/rdf2bin$(X)
$(RM_F) rdoff/rdf2com$(X)
$(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2com$(X)
rdoff/rdf2ith$(X): rdoff/rdf2bin$(X)
$(RM_F) rdoff/rdf2ith$(X)
$(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2ith$(X)
rdoff/rdf2ihx$(X): rdoff/rdf2bin$(X)
$(RM_F) rdoff/rdf2ihx$(X)
$(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2ihx$(X)
rdoff/rdf2srec$(X): rdoff/rdf2bin$(X)
$(RM_F) rdoff/rdf2srec$(X)
$(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2srec$(X)
#-- End RDOFF Shared Rules --#
rdf: $(RDFPROGS) $(RDF2BINLINKS)
$(RDFLIB): $(RDFLIBOBJ)
$(RM_F) $(RDFLIB)
$(AR) cq $(RDFLIB) $(RDFLIBOBJ)
$(RANLIB) $(RDFLIB)
#-- Begin NSIS Rules --#
nsis/arch.nsh: nsis/getpearch.pl nasm$(X)
@ -420,7 +372,6 @@ clean:
$(RM_F) tags TAGS
$(RM_F) nsis/arch.nsh
$(RM_F) perlbreq.si
$(RM_F) $(RDFPROGS) $(RDF2BINLINKS)
distclean: clean
$(RM_F) config.log config.status config/config.h
@ -456,19 +407,6 @@ cscope:
$(FIND) . -name '*.[hcS]' -print > cscope.files
cscope -b -f cscope.out
rdf_install install_rdf install_rdoff:
$(MKDIR_P) $(DESTDIR)$(bindir)
for f in $(RDFPROGS); do \
$(INSTALL_PROGRAM) "$$f" '$(DESTDIR)$(bindir)'/ ; \
done
cd '$(DESTDIR)$(bindir)' && \
for f in $(RDF2BINLINKS); do \
bn=`basename "$$f"` && $(RM_F) "$$bn" && \
$(LN_S) rdf2bin$(X) "$$bn" ; \
done
$(MKDIR_P) $(DESTDIR)$(mandir)/man1
$(INSTALL_DATA) $(srcdir)/rdoff/*.1 $(DESTDIR)$(mandir)/man1/
doc: doc/warnings.src
$(MAKE) -C doc all
@ -484,7 +422,7 @@ always_everything: dirs
everything: always_everything
$(MAKE) $(MANPAGES) $(NSIS) nothing
install_everything: everything install install_doc install_rdf
install_everything: everything install install_doc
dist:
$(MAKE) alldeps

View file

@ -107,7 +107,7 @@ LIBOBJ_NW = stdlib\snprintf.$(O) stdlib\vsnprintf.$(O) stdlib\strlcpy.$(O) \
output\nulldbg.$(O) output\nullout.$(O) \
output\outbin.$(O) output\outaout.$(O) output\outcoff.$(O) \
output\outelf.$(O) \
output\outobj.$(O) output\outas86.$(O) output\outrdf2.$(O) \
output\outobj.$(O) output\outas86.$(O) \
output\outdbg.$(O) output\outieee.$(O) output\outmacho.$(O) \
output\codeview.$(O) \
\
@ -121,13 +121,13 @@ ALLOBJ_NW = $(PROGOBJ) $(LIBOBJ_NW)
ALLOBJ = $(PROGOBJ) $(LIBOBJ)
SUBDIRS = stdlib nasmlib output asm disasm x86 common macros
XSUBDIRS = test doc nsis rdoff
DEPDIRS = . include config x86 rdoff $(SUBDIRS)
XSUBDIRS = test doc nsis
DEPDIRS = . include config x86 $(SUBDIRS)
#-- End File Lists --#
NASMLIB = libnasm.$(A)
all: nasm$(X) ndisasm$(X) rdf
all: nasm$(X) ndisasm$(X)
nasm$(X): $(NASM) $(NASMLIB)
$(CC) /Fe$@ $(NASM) $(LDFLAGS) $(NASMLIB) $(LIBS)
@ -299,53 +299,6 @@ asm\directbl.c: asm\directiv.dat nasmlib\perfhash.pl perllib\phash.ph
perlreq: $(PERLREQ)
# This rule is only used for RDOFF
.obj.exe:
$(CC) /Fe$@ $< $(LDFLAGS) $(RDFLIB) $(NASMLIB) $(LIBS)
RDFLN = copy
RDFLNPFX = rdoff^\
#-- Begin RDOFF Shared Rules --#
# Edit in Makefile.in, not here!
RDFLIBOBJ = rdoff\rdoff.$(O) rdoff\rdfload.$(O) rdoff\symtab.$(O) \
rdoff\collectn.$(O) rdoff\rdlib.$(O) rdoff\segtab.$(O) \
rdoff\hash.$(O)
RDFPROGS = rdoff\rdfdump$(X) rdoff\ldrdf$(X) rdoff\rdx$(X) rdoff\rdflib$(X) \
rdoff\rdf2bin$(X)
RDF2BINLINKS = rdoff\rdf2com$(X) rdoff\rdf2ith$(X) \
rdoff\rdf2ihx$(X) rdoff\rdf2srec$(X)
RDFLIB = rdoff\librdoff.$(A)
RDFLIBS = $(RDFLIB) $(NASMLIB)
rdoff\rdfdump$(X): rdoff\rdfdump.$(O) $(RDFLIBS)
rdoff\ldrdf$(X): rdoff\ldrdf.$(O) $(RDFLIBS)
rdoff\rdx$(X): rdoff\rdx.$(O) $(RDFLIBS)
rdoff\rdflib$(X): rdoff\rdflib.$(O) $(RDFLIBS)
rdoff\rdf2bin$(X): rdoff\rdf2bin.$(O) $(RDFLIBS)
rdoff\rdf2com$(X): rdoff\rdf2bin$(X)
$(RM_F) rdoff\rdf2com$(X)
$(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2com$(X)
rdoff\rdf2ith$(X): rdoff\rdf2bin$(X)
$(RM_F) rdoff\rdf2ith$(X)
$(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2ith$(X)
rdoff\rdf2ihx$(X): rdoff\rdf2bin$(X)
$(RM_F) rdoff\rdf2ihx$(X)
$(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2ihx$(X)
rdoff\rdf2srec$(X): rdoff\rdf2bin$(X)
$(RM_F) rdoff\rdf2srec$(X)
$(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2srec$(X)
#-- End RDOFF Shared Rules --#
rdf: $(RDFPROGS) $(RDF2BINLINKS)
$(RDFLIB): $(RDFLIBOBJ)
$(AR) $(ARFLAGS) /OUT:$@ $**
#-- Begin NSIS Rules --#
# Edit in Makefile.in, not here!
@ -368,7 +321,6 @@ clean:
-del /f $(NASMLIB) $(RDFLIB)
-del /f nasm$(X)
-del /f ndisasm$(X)
-del /f rdoff\*$(X)
distclean: clean
-del /f config.h
@ -387,7 +339,6 @@ distclean: clean
-del /f test\*.$(O)
-del /f test\*.bin
-del /f/s autom4te*.cache
rem cd rdoff && $(MAKE) distclean
cleaner: clean
-del /f $(PERLREQ)

View file

@ -96,7 +96,7 @@ LIBOBJ_NW = stdlib\snprintf.$(O) stdlib\vsnprintf.$(O) stdlib\strlcpy.$(O) &
output\nulldbg.$(O) output\nullout.$(O) &
output\outbin.$(O) output\outaout.$(O) output\outcoff.$(O) &
output\outelf.$(O) &
output\outobj.$(O) output\outas86.$(O) output\outrdf2.$(O) &
output\outobj.$(O) output\outas86.$(O) &
output\outdbg.$(O) output\outieee.$(O) output\outmacho.$(O) &
output\codeview.$(O) &
&
@ -110,8 +110,8 @@ ALLOBJ_NW = $(PROGOBJ) $(LIBOBJ_NW)
ALLOBJ = $(PROGOBJ) $(LIBOBJ)
SUBDIRS = stdlib nasmlib output asm disasm x86 common macros
XSUBDIRS = test doc nsis rdoff
DEPDIRS = . include config x86 rdoff $(SUBDIRS)
XSUBDIRS = test doc nsis
DEPDIRS = . include config x86 $(SUBDIRS)
#-- End File Lists --#
what: .SYMBOLIC
@ -339,15 +339,12 @@ clean: .SYMBOLIC
rm -f disasm\*.$(O) disasm\*.s disasm\*.i
rm -f config.h config.log config.status
rm -f nasm$(X) ndisasm$(X) $(NASMLIB)
# cd rdoff && $(MAKE) clean
distclean: clean .SYMBOLIC
rm -f config.h config.log config.status
rm -f Makefile *~ *.bak *.lst *.bin
rm -f output\*~ output\*.bak
rm -f test\*.lst test\*.bin test\*.$(O) test\*.bin
# -del \s autom4te*.cache
# cd rdoff && $(MAKE) distclean
cleaner: clean .SYMBOLIC
rm -f $(PERLREQ)
@ -361,13 +358,10 @@ spotless: distclean cleaner .SYMBOLIC
strip: .SYMBOLIC
$(STRIP) *.exe
rdf:
# cd rdoff && $(MAKE)
doc:
# cd doc && $(MAKE) all
everything: all doc rdf
everything: all doc
#
# This build dependencies in *ALL* makefiles. Partially for that reason,

View file

@ -55,7 +55,7 @@ since at least NASM 2.14, has been disabled. The RDOFF tools are
scheduled to be removed from the NASM distribution in NASM 2.16. If
you have a concrete use case for RDOFF, please file a NASM bug report
at \W{https://bugs.nasm.us/}\c{https://bugs.nasm.us/} as soon as
possible. See \k{rdffmt}.
possible.
\S{cl-2.15.03} Version 2.15.03

View file

@ -1,6 +1,6 @@
\# --------------------------------------------------------------------------
\#
\# Copyright 1996-2020 The NASM Authors - All Rights Reserved
\# Copyright 1996-2022 The NASM Authors - All Rights Reserved
\M{year}{1996-2020}
\# See the file AUTHORS included with the NASM distribution for
\# the specific copyright holders.
@ -182,7 +182,6 @@ variables
\IR{executable and linkable format} Executable and Linkable Format
\IR{extern, elf extensions to} \c{EXTERN}, \c{elf} extensions to
\IR{extern, obj extensions to} \c{EXTERN}, \c{obj} extensions to
\IR{extern, rdf extensions to} \c{EXTERN}, \c{rdf} extensions to
\IR{floating-point, constants} floating-point, constants
\IR{floating-point, packed bcd constants} floating-point, packed BCD constants
\IR{freebsd} FreeBSD
@ -245,10 +244,6 @@ variables
\IA{preprocessor expressions}{preprocessor, expressions}
\IA{preprocessor loops}{preprocessor, loops}
\IA{preprocessor variables}{preprocessor, variables}
\IA{rdoff subdirectory}{rdoff}
\IR{rdoff} \c{rdoff} subdirectory
\IR{relocatable dynamic object file format} Relocatable Dynamic
Object File Format
\IR{relocations, pic-specific} relocations, PIC-specific
\IA{repeating}{repeating code}
\IR{section alignment, in elf} section alignment, in ELF
@ -413,8 +408,8 @@ it will remove the \c{.asm} \i{extension} (or whatever extension you
like to use - NASM doesn't care) from your source file name and
substitute \c{.obj}. For Unix object file formats (\c{aout}, \c{as86},
\c{coff}, \c{elf32}, \c{elf64}, \c{elfx32}, \c{ieee}, \c{macho32} and
\c{macho64}) it will substitute \c{.o}. For \c{dbg}, \c{rdf}, \c{ith}
and \c{srec}, it will use \c{.dbg}, \c{.rdf}, \c{.ith} and \c{.srec},
\c{macho64}) it will substitute \c{.o}. For \c{dbg}, \c{ith}
and \c{srec}, it will use \c{.dbg}, \c{.ith} and \c{.srec},
respectively, and for the \c{bin} format it will simply remove the
extension, so that \c{myfile.asm} produces the output file \c{myfile}.
@ -6765,103 +6760,6 @@ and no extensions to any standard directives. It supports only the three
only special symbol supported is \c{..start}.
\H{rdffmt} \I{RDOFF}\i\c{rdf}: \i{Relocatable Dynamic Object File
Format} (deprecated)
\e{The RDOFF format is strongly deprecated and has been disabled
starting in NASM 2.15.04. The RDOFF backend has been broken since at
least NASM 2.14. The RDOFF utilities are scheduled to be removed from
the NASM distribution in NASM 2.16.} If you have a strong use case for
the RDOFF format, file a bug report at
\W{https://bugs.nasm.us/}\c{https://bugs.nasm.us/} as soon as possible.
The \c{rdf} output format produces \c{RDOFF} object files. \c{RDOFF}
(Relocatable Dynamic Object File Format) is a home-grown object-file
format, designed alongside NASM itself and reflecting in its file
format the internal structure of the assembler.
\c{RDOFF} is not used by any well-known operating systems. Those
writing their own systems, however, may well wish to use \c{RDOFF}
as their object format, on the grounds that it is designed primarily
for simplicity and contains very little file-header bureaucracy.
The Unix NASM archive, and the DOS archive which includes sources,
both contain an \I{rdoff subdirectory}\c{rdoff} subdirectory holding
a set of RDOFF utilities: an RDF linker, an \c{RDF} static-library
manager, an RDF file dump utility, and a program which will load and
execute an RDF executable under Linux.
\S{rdflib} Requiring a Library: The \i\c{LIBRARY} Directive
\c{RDOFF} contains a mechanism for an object file to demand a given
library to be linked to the module, either at load time or run time.
This is done by the \c{LIBRARY} directive, which takes one argument
which is the name of the module:
\c library mylib.rdl
\S{rdfmod} Specifying a Module Name: The \i\c{MODULE} Directive
Special \c{RDOFF} header record is used to store the name of the module.
It can be used, for example, by run-time loader to perform dynamic
linking. \c{MODULE} directive takes one argument which is the name
of current module:
\c module mymodname
Note that when you statically link modules and tell linker to strip
the symbols from output file, all module names will be stripped too.
To avoid it, you should start module names with \I{$, prefix}\c{$}, like:
\c module $kernel.core
\S{rdfglob} \c{rdf} Extensions to the \c{GLOBAL} Directive\I{GLOBAL,
rdf extensions to}
\c{RDOFF} global symbols can contain additional information needed by
the static linker. You can mark a global symbol as exported, thus
telling the linker do not strip it from target executable or library
file. Like in \c{ELF}, you can also specify whether an exported symbol
is a procedure (function) or data object.
Suffixing the name with a colon and the word \i\c{export} you make the
symbol exported:
\c global sys_open:export
To specify that exported symbol is a procedure (function), you add the
word \i\c{proc} or \i\c{function} after declaration:
\c global sys_open:export proc
Similarly, to specify exported data object, add the word \i\c{data}
or \i\c{object} to the directive:
\c global kernel_ticks:export data
\S{rdfimpt} \c{rdf} Extensions to the \c{EXTERN} Directive\I{EXTERN,
rdf extensions to}
By default the \c{EXTERN} directive in \c{RDOFF} declares a "pure external"
symbol (i.e. the static linker will complain if such a symbol is not resolved).
To declare an "imported" symbol, which must be resolved later during a dynamic
linking phase, \c{RDOFF} offers an additional \c{import} modifier. As in
\c{GLOBAL}, you can also specify whether an imported symbol is a procedure
(function) or data object. For example:
\c library $libc
\c extern _open:import
\c extern _printf:import proc
\c extern _errno:import data
Here the directive \c{LIBRARY} is also included, which gives the dynamic linker
a hint as to where to find requested symbols.
\H{dbgfmt} \i\c{dbg}: Debugging Format
The \c{dbg} format does not output an object file as such; instead,
@ -6884,14 +6782,14 @@ will not be defined in the \c{dbg} format. Therefore it can be
useful to run NASM twice, in order to do the preprocessing with the
native object format selected:
\c nasm -e -f rdf -o rdfprog.i rdfprog.asm
\c nasm -a -f dbg rdfprog.i
\c nasm -e -f elf32 -o elfprog.i elfprog.asm
\c nasm -a -f dbg elfprog.i
This preprocesses \c{rdfprog.asm} into \c{rdfprog.i}, keeping the
\c{rdf} object format selected in order to make sure RDF special
This preprocesses \c{elfprog.asm} into \c{elfprog.i}, keeping the
\c{elf32} object format selected in order to make sure ELF special
directives are converted into primitive form correctly. Then the
preprocessed source is fed through the \c{dbg} format to generate
the final diagnostic output.
preprocessed source is fed through the \c{dbg} format to generate the
final diagnostic output.
This workaround will still typically not work for programs intended
for \c{obj} format, because the \c{obj} \c{SEGMENT} and \c{GROUP}

View file

@ -26,9 +26,6 @@ BuildRequires: fontconfig
BuildRequires: adobe-source-sans-pro-fonts
BuildRequires: adobe-source-code-pro-fonts
%package rdoff
Summary: Tools for the RDOFF binary format, sometimes used with NASM.
%description
NASM is the Netwide Assembler, a free portable assembler for the Intel
80x86 microprocessor series, using primarily the traditional Intel
@ -38,11 +35,6 @@ instruction mnemonics and syntax.
Extensive documentation for the Netwide Assembler (NASM) in HTML and
PDF formats.
%description rdoff
Tools for the operating-system independent RDOFF binary format, which
is sometimes used with the Netwide Assembler (NASM). These tools
include linker, library manager, loader, and information dump.
%prep
%setup -q -n nasm-%{nasm_version}
@ -55,7 +47,7 @@ make %{?_smp_mflags} everything
rm -rf "%{buildroot}"
mkdir -p "%{buildroot}"/%{_bindir}
mkdir -p "%{buildroot}"/%{_mandir}/man1
make DESTDIR="%{buildroot}" install install_rdf
make DESTDIR="%{buildroot}" install
%files
%doc AUTHORS
@ -67,18 +59,5 @@ make DESTDIR="%{buildroot}" install install_rdf
%files doc
%doc doc/html doc/nasmdoc.pdf.xz
%files rdoff
%{_bindir}/ldrdf
%{_bindir}/rdf2bin
%{_bindir}/rdf2com
%{_bindir}/rdf2ihx
%{_bindir}/rdf2ith
%{_bindir}/rdf2srec
%{_bindir}/rdfdump
%{_bindir}/rdflib
%{_bindir}/rdx
%{_mandir}/man1/ldrdf.1*
%{_mandir}/man1/rd*.1*
# This is the upstream spec file; the change log is in git
%changelog

View file

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2011 The NASM Authors - All Rights Reserved
* Copyright 1996-2022 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@ -236,9 +236,6 @@
#ifdef OF_NO_AS86
#undef OF_AS86
#endif
#ifdef OF_NO_RDF2
#undef OF_RDF2
#endif
#ifdef OF_NO_IEEE
#undef OF_IEEE
#endif
@ -269,7 +266,6 @@ extern const struct ofmt of_as86;
extern const struct ofmt of_obj;
extern const struct ofmt of_win32;
extern const struct ofmt of_win64;
extern const struct ofmt of_rdf2;
extern const struct ofmt of_ieee;
extern const struct ofmt of_macho32;
extern const struct ofmt of_macho64;
@ -318,9 +314,6 @@ static const struct ofmt * const drivers[] = {
#ifdef OF_WIN64
&of_win64,
#endif
#ifdef OF_RDF2
&of_rdf2,
#endif
#ifdef OF_IEEE
&of_ieee,
#endif

View file

@ -1,40 +0,0 @@
;; --------------------------------------------------------------------------
;;
;; Copyright 1996-2009 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.
;;
;; --------------------------------------------------------------------------
OUT: rdf
%define __?SECT?__ [section .text]
%imacro library 1+.nolist
[library %1]
%endmacro
%macro __?NASM_CDecl?__ 1
%endmacro

View file

@ -1,766 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2016 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.
*
* ----------------------------------------------------------------------- */
/*
* outrdf2.c output routines for the Netwide Assembler to produce
* RDOFF version 2 format object files, which Julian originally
* planned to use it in his MOSCOW operating system.
*/
#include "compiler.h"
#include "nctype.h"
#include "nasm.h"
#include "nasmlib.h"
#include "error.h"
#include "saa.h"
#include "outform.h"
#include "outlib.h"
/* VERBOSE_WARNINGS: define this to add some extra warnings... */
#define VERBOSE_WARNINGS
#ifdef OF_RDF2
#include "rdoff.h"
/* This signature is written to start of RDOFF files */
static const char *RDOFF2Id = RDOFF2_SIGNATURE;
/* Note that whenever a segment is referred to in the RDOFF file, its number
* is always half of the segment number that NASM uses to refer to it; this
* is because NASM only allocates even numbered segments, so as to not
* waste any of the 16 bits of segment number written to the file - this
* allows up to 65533 external labels to be defined; otherwise it would be
* 32764. */
#define COUNT_SEGTYPES 9
static char *segmenttypes[COUNT_SEGTYPES] = {
"null", "text", "code", "data",
"comment", "lcomment", "pcomment",
"symdebug", "linedebug"
};
static int segmenttypenumbers[COUNT_SEGTYPES] = {
0, 1, 1, 2, 3, 4, 5, 6, 7
};
/* code for managing buffers needed to separate code and data into individual
* sections until they are ready to be written to the file.
* We'd better hope that it all fits in memory else we're buggered... */
#define BUF_BLOCK_LEN 4088 /* selected to match page size (4096)
* on 80x86 machines for efficiency */
/***********************************************************************
* Actual code to deal with RDOFF2 output format begins here...
*/
/* global variables set during the initialisation phase */
static struct SAA *seg[RDF_MAXSEGS]; /* seg 0 = code, seg 1 = data */
static struct SAA *header; /* relocation/import/export records */
static struct seginfo {
char *segname;
int segnumber;
uint16_t segtype;
uint16_t segreserved;
int32_t seglength;
} segments[RDF_MAXSEGS];
static int nsegments;
static int32_t bsslength;
static int32_t headerlength;
static void rdf2_init(void)
{
int segtext, segdata, segbss;
/* set up the initial segments */
segments[0].segname = ".text";
segments[0].segnumber = 0;
segments[0].segtype = 1;
segments[0].segreserved = 0;
segments[0].seglength = 0;
segments[1].segname = ".data";
segments[1].segnumber = 1;
segments[1].segtype = 2;
segments[1].segreserved = 0;
segments[1].seglength = 0;
segments[2].segname = ".bss";
segments[2].segnumber = 2;
segments[2].segtype = 0xFFFF; /* reserved - should never be produced */
segments[2].segreserved = 0;
segments[2].seglength = 0;
nsegments = 3;
seg[0] = saa_init(1L);
seg[1] = saa_init(1L);
seg[2] = NULL; /* special case! */
header = saa_init(1L);
segtext = seg_alloc();
segdata = seg_alloc();
segbss = seg_alloc();
if (segtext != 0 || segdata != 2 || segbss != 4)
nasm_panic("rdf segment numbers not allocated as expected (%d,%d,%d)",
segtext, segdata, segbss);
bsslength = 0;
headerlength = 0;
}
static int32_t rdf2_section_names(char *name, int *bits)
{
int i;
bool err;
char *p, *q;
int code = -1;
int reserved = 0;
/*
* Default is 32 bits, in the text segment.
*/
if (!name) {
*bits = 32;
return 0;
}
/* look for segment type code following segment name */
p = name;
while (*p && !nasm_isspace(*p))
p++;
if (*p) { /* we're now in whitespace */
*p++ = '\0';
while (*p && nasm_isspace(80))
*p++ = '\0';
}
if (*p) { /* we're now in an attribute value */
/*
* see if we have an optional ',number' following the type code
*/
if ((q = strchr(p, ','))) {
*q++ = '\0';
reserved = readnum(q, &err);
if (err) {
nasm_error(ERR_NONFATAL,
"value following comma must be numeric");
reserved = 0;
}
}
/*
* check it against the text strings in segmenttypes
*/
for (i = 0; i < COUNT_SEGTYPES; i++)
if (!nasm_stricmp(p, segmenttypes[i])) {
code = segmenttypenumbers[i];
break;
}
if (code == -1) { /* didn't find anything */
code = readnum(p, &err);
if (err) {
nasm_error(ERR_NONFATAL, "unrecognised RDF segment type (%s)",
p);
code = 3;
}
}
}
for (i = 0; i < nsegments; i++) {
if (!strcmp(name, segments[i].segname)) {
if (code != -1 || reserved != 0)
nasm_error(ERR_NONFATAL, "segment attributes specified on"
" redeclaration of segment");
return segments[i].segnumber * 2;
}
}
/* declaring a new segment! */
if (code == -1) {
nasm_error(ERR_NONFATAL, "new segment declared without type code");
code = 3;
}
if (nsegments == RDF_MAXSEGS) {
nasm_fatal("reached compiled-in maximum segment limit (%d)",
RDF_MAXSEGS);
return NO_SEG;
}
segments[nsegments].segname = nasm_strdup(name);
i = seg_alloc();
if (i % 2 != 0)
nasm_panic("seg_alloc() returned odd number");
segments[nsegments].segnumber = i >> 1;
segments[nsegments].segtype = code;
segments[nsegments].segreserved = reserved;
segments[nsegments].seglength = 0;
seg[nsegments] = saa_init(1L);
return i;
}
/*
* Write relocation record
*/
static void write_reloc_rec(struct RelocRec *r)
{
char buf[4], *b;
if (r->refseg != (uint16_t) NO_SEG && (r->refseg & 1)) /* segment base ref */
r->type = RDFREC_SEGRELOC;
r->refseg >>= 1; /* adjust segment nos to RDF rather than NASM */
saa_wbytes(header, &r->type, 1);
saa_wbytes(header, &r->reclen, 1);
saa_wbytes(header, &r->segment, 1);
b = buf;
WRITELONG(b, r->offset);
saa_wbytes(header, buf, 4);
saa_wbytes(header, &r->length, 1);
b = buf;
WRITESHORT(b, r->refseg);
saa_wbytes(header, buf, 2);
headerlength += r->reclen + 2;
}
/*
* Write export record
*/
static void write_export_rec(struct ExportRec *r)
{
char buf[4], *b;
r->segment >>= 1;
saa_wbytes(header, &r->type, 1);
saa_wbytes(header, &r->reclen, 1);
saa_wbytes(header, &r->flags, 1);
saa_wbytes(header, &r->segment, 1);
b = buf;
WRITELONG(b, r->offset);
saa_wbytes(header, buf, 4);
saa_wbytes(header, r->label, strlen(r->label) + 1);
headerlength += r->reclen + 2;
}
static void write_import_rec(struct ImportRec *r)
{
char buf[4], *b;
r->segment >>= 1;
saa_wbytes(header, &r->type, 1);
saa_wbytes(header, &r->reclen, 1);
saa_wbytes(header, &r->flags, 1);
b = buf;
WRITESHORT(b, r->segment);
saa_wbytes(header, buf, 2);
saa_wbytes(header, r->label, strlen(r->label) + 1);
headerlength += r->reclen + 2;
}
/*
* Write BSS record
*/
static void write_bss_rec(struct BSSRec *r)
{
char buf[4], *b;
saa_wbytes(header, &r->type, 1);
saa_wbytes(header, &r->reclen, 1);
b = buf;
WRITELONG(b, r->amount);
saa_wbytes(header, buf, 4);
headerlength += r->reclen + 2;
}
/*
* Write common variable record
*/
static void write_common_rec(struct CommonRec *r)
{
char buf[4], *b;
r->segment >>= 1;
saa_wbytes(header, &r->type, 1);
saa_wbytes(header, &r->reclen, 1);
b = buf;
WRITESHORT(b, r->segment);
saa_wbytes(header, buf, 2);
b = buf;
WRITELONG(b, r->size);
saa_wbytes(header, buf, 4);
b = buf;
WRITESHORT(b, r->align);
saa_wbytes(header, buf, 2);
saa_wbytes(header, r->label, strlen(r->label) + 1);
headerlength += r->reclen + 2;
}
/*
* Write library record
*/
static void write_dll_rec(struct DLLRec *r)
{
saa_wbytes(header, &r->type, 1);
saa_wbytes(header, &r->reclen, 1);
saa_wbytes(header, r->libname, strlen(r->libname) + 1);
headerlength += r->reclen + 2;
}
/*
* Write module name record
*/
static void write_modname_rec(struct ModRec *r)
{
saa_wbytes(header, &r->type, 1);
saa_wbytes(header, &r->reclen, 1);
saa_wbytes(header, r->modname, strlen(r->modname) + 1);
headerlength += r->reclen + 2;
}
/*
* Handle export, import and common records.
*/
static void rdf2_deflabel(char *name, int32_t segment, int64_t offset,
int is_global, char *special)
{
struct ExportRec r;
struct ImportRec ri;
struct CommonRec ci;
static int farsym = 0;
static int i;
char symflags = 0;
int len;
/* Check if the label length is OK */
if ((len = strlen(name)) >= EXIM_LABEL_MAX) {
nasm_error(ERR_NONFATAL, "label size exceeds %d bytes", EXIM_LABEL_MAX);
return;
}
if (!len) {
nasm_error(ERR_NONFATAL, "zero-length label");
return;
}
if (is_global == 2) {
/* Common variable */
ci.type = RDFREC_COMMON;
ci.size = offset;
ci.segment = segment;
strcpy(ci.label, name);
ci.reclen = 9 + len;
ci.align = 0;
/*
* Check the special text to see if it's a valid number and power
* of two; if so, store it as the alignment for the common variable.
*/
if (special) {
bool err;
ci.align = readnum(special, &err);
if (err)
nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
" valid number", special);
else if ((ci.align | (ci.align - 1)) != 2 * ci.align - 1)
nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
" power of two", special);
}
write_common_rec(&ci);
}
/* We don't care about local labels or fix-up hints */
if (is_global != 1)
return;
if (special) {
while (*special == ' ' || *special == '\t')
special++;
if (!nasm_strnicmp(special, "export", 6)) {
special += 6;
symflags |= SYM_GLOBAL;
} else if (!nasm_strnicmp(special, "import", 6)) {
special += 6;
symflags |= SYM_IMPORT;
}
if (*special) {
while (nasm_isspace(*special))
special++;
if (!nasm_stricmp(special, "far")) {
farsym = 1;
} else if (!nasm_stricmp(special, "near")) {
farsym = 0;
} else if (!nasm_stricmp(special, "proc") ||
!nasm_stricmp(special, "function")) {
symflags |= SYM_FUNCTION;
} else if (!nasm_stricmp(special, "data") ||
!nasm_stricmp(special, "object")) {
symflags |= SYM_DATA;
} else
nasm_error(ERR_NONFATAL, "unrecognised symbol type `%s'",
special);
}
}
if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
return;
}
for (i = 0; i < nsegments; i++) {
if (segments[i].segnumber == segment >> 1)
break;
}
if (i >= nsegments) { /* EXTERN declaration */
ri.type = farsym ? RDFREC_FARIMPORT : RDFREC_IMPORT;
if (symflags & SYM_GLOBAL)
nasm_error(ERR_NONFATAL,
"symbol type conflict - EXTERN cannot be EXPORT");
ri.flags = symflags;
ri.segment = segment;
strcpy(ri.label, name);
ri.reclen = 4 + len;
write_import_rec(&ri);
} else if (is_global) {
r.type = RDFREC_GLOBAL; /* GLOBAL declaration */
if (symflags & SYM_IMPORT)
nasm_error(ERR_NONFATAL,
"symbol type conflict - GLOBAL cannot be IMPORT");
r.flags = symflags;
r.segment = segment;
r.offset = offset;
strcpy(r.label, name);
r.reclen = 7 + len;
write_export_rec(&r);
}
}
static void membufwrite(int segment, const void *data, int bytes)
{
int i;
char buf[4], *b;
for (i = 0; i < nsegments; i++) {
if (segments[i].segnumber == segment)
break;
}
if (i == nsegments)
nasm_panic("can't find segment %d", segment);
if (bytes < 0) {
b = buf;
if (bytes == -2)
WRITESHORT(b, *(int16_t *)data);
else
WRITELONG(b, *(int32_t *)data);
data = buf;
bytes = -bytes;
}
segments[i].seglength += bytes;
saa_wbytes(seg[i], data, bytes);
}
static int getsegmentlength(int segment)
{
int i;
for (i = 0; i < nsegments; i++) {
if (segments[i].segnumber == segment)
break;
}
if (i == nsegments)
nasm_panic("can't find segment %d", segment);
return segments[i].seglength;
}
static void rdf2_out(int32_t segto, const void *data,
enum out_type type, uint64_t size,
int32_t segment, int32_t wrt)
{
struct RelocRec rr;
uint8_t databuf[8], *pd;
int seg;
segto >>= 1; /* convert NASM segment no to RDF number */
for (seg = 0; seg < nsegments; seg++) {
if (segments[seg].segnumber == segto)
break;
}
if (seg >= nsegments) {
nasm_error(ERR_NONFATAL,
"specified segment not supported by rdf output format");
return;
}
if (wrt != NO_SEG) {
wrt = NO_SEG; /* continue to do _something_ */
nasm_error(ERR_NONFATAL, "WRT not supported by rdf output format");
}
if (segto == 2 && type != OUT_RESERVE) {
nasm_error(ERR_NONFATAL, "BSS segments may not be initialized");
/* just reserve the space for now... */
if (type == OUT_REL2ADR)
size = 2;
else
size = 4;
type = OUT_RESERVE;
}
if (type == OUT_RESERVE) {
if (segto == 2) /* BSS segment space reserved */
bsslength += size;
else
while (size--)
membufwrite(segto, databuf, 1);
} else if (type == OUT_RAWDATA) {
membufwrite(segto, data, size);
} else if (type == OUT_ADDRESS) {
int asize = abs((int)size);
/* if segment == NO_SEG then we are writing an address of an
object within the same segment - do not produce reloc rec. */
/* FIXME - is this behaviour sane? at first glance it doesn't
appear to be. Must test this thoroughly...! */
if (segment != NO_SEG) {
/* it's an address, so we must write a relocation record */
rr.type = RDFREC_RELOC; /* type signature */
rr.reclen = 8;
rr.segment = segto; /* segment we're currently in */
rr.offset = getsegmentlength(segto); /* current offset */
rr.length = asize; /* length of reference */
rr.refseg = segment; /* segment referred to */
write_reloc_rec(&rr);
}
pd = databuf; /* convert address to little-endian */
WRITEADDR(pd, *(int64_t *)data, asize);
membufwrite(segto, databuf, asize);
} else if (type == OUT_REL2ADR) {
if (segment == segto)
nasm_panic("intra-segment OUT_REL2ADR");
rr.reclen = 8;
rr.offset = getsegmentlength(segto); /* current offset */
rr.length = 2; /* length of reference */
rr.refseg = segment; /* segment referred to (will be >>1'd) */
if (segment != NO_SEG && segment % 2) {
rr.type = RDFREC_SEGRELOC;
rr.segment = segto; /* memory base refs *aren't ever* relative! */
write_reloc_rec(&rr);
/* what do we put in the code? Simply the data. This should almost
* always be zero, unless someone's doing segment arithmetic...
*/
rr.offset = *(int64_t *)data;
} else {
rr.type = RDFREC_RELOC; /* type signature */
rr.segment = segto + 64; /* segment we're currently in + rel flag */
write_reloc_rec(&rr);
/* work out what to put in the code: offset of the end of this operand,
* subtracted from any data specified, so that loader can just add
* address of imported symbol onto it to get address relative to end of
* instruction: import_address + data(offset) - end_of_instrn */
rr.offset = *(int32_t *)data - (rr.offset + size);
}
membufwrite(segto, &rr.offset, -2);
} else if (type == OUT_REL4ADR) {
if ((segment == segto) && (globalbits != 64))
nasm_panic("intra-segment OUT_REL4ADR");
if (segment != NO_SEG && segment % 2) {
nasm_panic("erm... 4 byte segment base ref?");
}
rr.type = RDFREC_RELOC; /* type signature */
rr.segment = segto + 64; /* segment we're currently in + rel tag */
rr.offset = getsegmentlength(segto); /* current offset */
rr.length = 4; /* length of reference */
rr.refseg = segment; /* segment referred to */
rr.reclen = 8;
write_reloc_rec(&rr);
rr.offset = *(int64_t *)data - (rr.offset + size);
membufwrite(segto, &rr.offset, -4);
}
}
static void rdf2_cleanup(void)
{
int32_t l;
struct BSSRec bs;
int i;
/* should write imported & exported symbol declarations to header here */
/* generate the output file... */
nasm_write(RDOFF2Id, 6, ofile); /* file type magic number */
if (bsslength != 0) { /* reserve BSS */
bs.type = RDFREC_BSS;
bs.amount = bsslength;
bs.reclen = 4;
write_bss_rec(&bs);
}
/*
* calculate overall length of the output object
*/
l = headerlength + 4;
for (i = 0; i < nsegments; i++) {
if (i == 2)
continue; /* skip BSS segment */
l += 10 + segments[i].seglength;
}
l += 10; /* null segment */
fwriteint32_t(l, ofile);
fwriteint32_t(headerlength, ofile);
saa_fpwrite(header, ofile); /* dump header */
saa_free(header);
for (i = 0; i < nsegments; i++) {
if (i == 2)
continue;
fwriteint16_t(segments[i].segtype, ofile);
fwriteint16_t(segments[i].segnumber, ofile);
fwriteint16_t(segments[i].segreserved, ofile);
fwriteint32_t(segments[i].seglength, ofile);
saa_fpwrite(seg[i], ofile);
saa_free(seg[i]);
}
/* null segment - write 10 bytes of zero */
fwriteint32_t(0, ofile);
fwriteint32_t(0, ofile);
fwriteint16_t(0, ofile);
}
/*
* Handle RDOFF2 specific directives
*/
static enum directive_result
rdf2_directive(enum directive directive, char *value)
{
size_t n;
switch (directive) {
case D_LIBRARY:
n = strlen(value);
if (n >= MODLIB_NAME_MAX) {
nasm_error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
return DIRR_ERROR;
}
if (pass_first()) { /* XXX */
struct DLLRec r;
r.type = RDFREC_DLL;
r.reclen = n + 1;
strcpy(r.libname, value);
write_dll_rec(&r);
}
return DIRR_OK;
case D_MODULE:
if ((n = strlen(value)) >= MODLIB_NAME_MAX) {
nasm_error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
return DIRR_ERROR;
}
if (pass_first()) { /* XXX */
struct ModRec r;
r.type = RDFREC_MODNAME;
r.reclen = n + 1;
strcpy(r.modname, value);
write_modname_rec(&r);
}
return DIRR_OK;
default:
return DIRR_UNKNOWN;
}
}
extern macros_t rdf2_stdmac[];
const struct ofmt of_rdf2 = {
"Relocatable Dynamic Object File Format v2.0",
"rdf",
".rdf",
0,
64,
null_debug_arr,
&null_debug_form,
rdf2_stdmac,
rdf2_init,
null_reset,
nasm_do_legacy_output,
rdf2_out,
rdf2_deflabel,
rdf2_section_names,
NULL,
null_sectalign,
null_segbase,
rdf2_directive,
rdf2_cleanup,
NULL /* pragma list */
};
#endif /* OF_RDF2 */

View file

@ -1,43 +0,0 @@
;; --------------------------------------------------------------------------
;;
;; Copyright 1996-2009 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.
;;
;; --------------------------------------------------------------------------
OUT: rdf2
%define __?SECT?__ [section .text]
%imacro library 1+.nolist
[library %1]
%endmacro
%imacro module 1+.nolist
[module %1]
%endmacro
%macro __?NASM_CDecl?__ 1
%endmacro

View file

@ -1,185 +0,0 @@
*******
This file is getting obsolete. RDOFF documentation is written in Texinfo now.
Directory doc/ contains Texinfo source (rdoff.texi) and makefile for creating
different output formats (info, HTML, PostScript and PDF).
*******
RDOFF Utilities, version 0.3.2
==============================
The files contained in this directory are the C source code of a set
of tools (and general purpose library files) for the manipulation of
RDOFF version 2 object files. Note that these programs (with the
exception of 'rdfdump') will NOT work with version 1 object files.
Version 1 of RDOFF is no longer supported.
There is also a 'doc' directory with 'v1-v2' file, which documents the
differences between RDOFF 1 and 2, and an 'rdoff2.texi' (texinfo source),
with complete documentation for the new format.
Here is a brief summary of the programs' usage:
rdfdump
=======
This tool prints a list of the header records in an RDOFF object in
human-readable form, and optionally prints a hex dump of the contents
of the segments.
Usage:
rdfdump [-v] filename
The -v flag specifies that the hex dump (see above) should be printed.
Changes from previous versions:
* rdfdump supports both version 1 and 2 of RDOFF.
* rdfdump now gives warnings if the RDOFF2 format is violated (it
looks for incorrect lengths for header records, and checks the
overall length count at the start of the file)
ldrdf
=====
This tool is a version of unix 'ld' (or DOS 'link') for use with RDOFF
files. It is capable of linking RDOFF objects, and libraries produced
with the 'rdlib' utility discussed below.
In normal usage, its command line takes the form:
ldrdf [-o output-file] object files [-llibrary ...]
Modules in libraries are not linked to the program unless they are
referred to.
Most of its options are not implemented, but those that are are listed here:
-2 redirect all output from stderr to stdout. It is useful for some
systems which don't have such a redirection in shell (e.g. DOS).
-v increase verbosity level. Currently 4 verbosity levels are
available: default (which only prints error information), normal
(which prints information about the produced object, -v), medium
(which prints information about what the program is doing, -v -v)
and high (which prints all available information, -v -v -v).
-a change alignment value to which multiple segments combigned into
a single segment should be aligned (must be either 1, 2, 4, 8,
16, 32 or 256. Default is 16).
-s strip exported symbols from output file. Symbols marked as
SYM_GLOBAL are never stripped.
-x warn about unresolved symbols.
-xe issue an error when at least one symbol is unresolved.
-o name write output to file <name>. The default output filename
is 'aout.rdx'.
-j path specify search path for object files. Default path is a
current directory.
-L path specify search path for libraries. Default path is a
current directory.
-g file embed 'file' as a first header record with type 'generic'.
rdx
===
This program simply loads and executes an RDOFF object, by calling
'_main', which it expects to be a C-style function, which will accept
two parameters, argc and argv in normal C style.
rdflib
======
This program creates a library file for use with ldrdf.
It is supplied with a shell script 'makelib' which should probably be used
to create libraries.
Usage:
rdflib command library [optional arguments]
Valid commands are:
c Create (or truncate) the library
a Add a module (requires a filename and a name to give the
module, ie 'rdflib a libc.rdl strcpy.rdf strcpy' puts the
file 'strcpy.rdf' into 'libc.rdl', and calls it 'strcpy'.
x Extract (arguments are the opposite to the 'a' command,
ie you'd do 'rdflib x libc.rdl strcpy strcpy.rdf to get
a copy of strcpy.rdf back out again...)
t List modules in the library
d Delete modules from library
r Replace a module in library with a new file
Library functions
=================
The files 'rdoff.c', 'rdoff.h', 'rdfload.c' and 'rdfload.h' contain
code which you may find useful. They retain the same interface as
the previous version, so any code that used them previously should
still work OK (maybe). 'rdoff.c' contains at the top a line:
#define STRICT_ERRORS
Comment this line out if you wish to use record types other than the
7 predefined types; it will then not report such records as an error,
but accept them gracefully, and read them byte for byte into
a 'generic record' (see the definition of GenericRec in 'rdoff.h').
If you are using these functions to write RDF modules (rather than
just reading them), then please note the existence of a new function
'rdfaddsegment(rdf_headerbuf,long)'. This must be called once for
each segment in your object, to tell the header writing functions
how long the segment is.
BUGS
====
This product has recently undergone a major revision, and as such there
are probably several bugs left over from the testing phase (although the
previous version had quite a few that have now been fixed!). Could you
please report any bugs to maintainers at the addresses below, including the
following information:
- A description of the bug
- What you think the program should be doing
- Which programs you are using
- Which operating system you are using, and which C compiler was used to
compile the programs (or state that the pre-compiled versions were used).
- If appropriate, any of the following:
* source code (preferably cut down to a minimum that will still assemble
and show the bug)
* the output of rdfdump on produced modules (or send the module if the
problem is in code generated)
* exact descriptions of error messages/symptoms/etc
TODO
====
There are still various things unimplemented that we would like to add.
If you want to find out what these are, search near the top of each *.c
file for a comment containing the word 'TODO'. A brief list is given here:
- Improve the performance of ldrdf (there are several enhancements I can think
of that wouldn't be too hard to add)
- Stop assuming that we're on a little endian machine
- Check for more bugs
MAINTAINERS
===========
Yuri Zaporozhets <r_tty@yahoo.co.uk> - primary maintainer
Julian Hall <jules@dsf.org.uk> - original designer and author

View file

@ -1,44 +0,0 @@
/*
* collectn.c - implements variable length pointer arrays [collections].
*
* This file is public domain.
*/
#include "rdfutils.h"
#include "collectn.h"
void collection_init(Collection * c)
{
int i;
for (i = 0; i < 32; i++)
c->p[i] = NULL;
c->next = NULL;
}
void **colln(Collection * c, int index)
{
while (index >= 32) {
index -= 32;
if (c->next == NULL) {
c->next = nasm_malloc(sizeof(Collection));
collection_init(c->next);
}
c = c->next;
}
return &(c->p[index]);
}
void collection_reset(Collection * c)
{
int i;
if (c->next) {
collection_reset(c->next);
nasm_free(c->next);
}
c->next = NULL;
for (i = 0; i < 32; i++)
c->p[i] = NULL;
}

View file

@ -1,22 +0,0 @@
/*
* collectn.h - header file for 'collection' abstract data type.
*
* This file is public domain, and does not come under the NASM license.
* It, aint32_t with 'collectn.c' implements what is basically a variable
* length array (of pointers).
*/
#ifndef RDOFF_COLLECTN_H
#define RDOFF_COLLECTN_H 1
typedef struct tagCollection {
void *p[32]; /* array of pointers to objects */
struct tagCollection *next;
} Collection;
void collection_init(Collection * c);
void **colln(Collection * c, int index);
void collection_reset(Collection * c);
#endif

View file

@ -1,37 +0,0 @@
#
# Make info documentation
#
AUXFILES = *.aux *.cp *.fn *.ky *.log *.pg *.toc *.tp *.vr *.dvi
SRCS = rdoff.texi
OUTS = rdoff.info rdoff.html rdoff.ps rdoff.pdf
## Implicit rules
%.html : %.texi
makeinfo --html $<
%.dvi : %.texi
texi2dvi $<
%.ps: %.dvi
dvips $<
%.pdf: %.dvi
dvipdf $<
## Explicit rules
all: info
info: rdoff.info
html: rdoff.html
ps: rdoff.ps
pdf: rdoff.pdf
clean:
rm -f $(OUTS) $(AUXFILES)

View file

@ -1,137 +0,0 @@
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename rdoff.info
@settitle Relocatable Dynamic Object File Format (RDOFF)
@afourpaper
@c %**end of header
@titlepage
@title Relocatable Dynamic Object File Format (RDOFF)
@author Yuri Zaporozhets @email{r_tty@@yahoo.co.uk}
@author Julian Hall @email{jules@@dsf.org.uk}
@end titlepage
@ifinfo
Copyright @copyright{} 2002-2015 Netwide Assembler Project.
Written by Yuri Zaporozhets @email{r_tty@@yahoo.co.uk}
Based on various sources and notes written by Julian Hall @email{jules@@dsf.org.uk}
Distributed under GNU documentation license.
@end ifinfo
@ifnottex
@node Top, Overview, (dir), (dir)
@top RDOFF
RDOFF is a Relocatable Dynamic Object File Format.
@end ifnottex
@menu
* Overview:: Introduction.
* Structure:: Structure of RDOFF file.
* Utilities:: Description of RDOFF utilities.
@end menu
@node Overview
@chapter Introduction
RDOFF was designed initially to test the object-file production
interface to NASM. It soon became apparent that it could be enhanced
for use in serious applications due to its simplicity; code to load
and execute an RDOFF object module is very simple. It also contains
enhancements to allow it to be linked with a dynamic link library at
either run- or load- time, depending on how complex you wish to make
your loader.
@node Structure
@chapter Structure of RDOFF file
RDOFF module consists of three parts:
@itemize
@item Master header
@item Header (may be omitted)
@item Sections
@end itemize
@dfn{Master header} contains signature, version and size information.
@dfn{Header} consists of zero or more @ref{Records, records}.
@dfn{Sections} represent actual contents of the file. Each section is prepended
by a section header.
@node Records, , ,Structure
@section Records that may appear in RDOFF header
@menu
* Relocation:: Relocation records.
* Import:: Declaring external symbols.
* Export:: Declaring public and exported symbols.
* DLL:: Specifying a run-time library name.
* BSS:: Reserving space in BSS section.
* Segment relocation:: Complexity of relocation in segmented systems.
* Far import:: External 'far' symbols.
* Module name:: Specifying module name.
* Common variable:: Declaring common variables.
* Generic record:: Embedding general-purpose data into the header.
@end menu
@node Relocation
@subsection Relocation records
@node Import
@subsection Declaring external and imported symbols
@node Export
@subsection Declaring public and exported symbols
@node DLL
@subsection Specifying a run-time library name
@node BSS
@subsection Reserving space in BSS section
@node Segment relocation
@subsection Complexity of relocation in segmented systems
@node Far import
@subsection External 'far' symbols.
@node Module name
@subsection Specifying module name.
@node Common variable
@subsection Declaring common variables.
@node Generic record
@subsection Embedding general-purpose data into the header.
@node Utilities
@chapter RDOFF utilities
@menu
* rdfdump:: Dump the contents of RDOFF file.
* ldrdf:: RDOFF linker.
* rdflib:: RDOFF librarian.
* rdlar:: New RDOFF librarian/archiver.
* rdx:: Load and execute RDOFF module.
@end menu
@node rdfdump
@section @command{rdfdump} - dump the contents of RDOFF file
@node ldrdf
@section @command{ldrdf} - RDOFF linker
@node rdflib
@section @command{rdflib} - RDOFF librarian
@node rdlar
@section @command{rdlar} - new RDOFF librarian/archiver
@node rdx
@section @command{rdx} - load and execute RDOFF module
@bye

View file

@ -1,62 +0,0 @@
Differences between RDOFF versions 1 & 2
========================================
This document is designed primarily for people maintaining code which
uses RDOFF version 1, and would like to upgrade that code to work
with version 2.
The main changes are summarised here:
Overall format
==============
The overall format has changed somewhat since version 1, in order
to make RDOFF more flexible. After the file type identifier (which
has been changed to 'RDOFF2', obviously), there is now a 4 byte
integer describing the length of the object module. This allows
multiple objects to be concatenated, while the loader can easily
build an index of the locations of each object. This isn't as
pointless as it sounds; I'm using RDOFF in a microkernel operating
system, and this is the ideal way of loading multiple driver modules
at boot time.
There are also no longer a fixed number of segments; instead there
is a list of segments, immediately following the header.
Each segment is preceded by a 10 byte header giving information about
that segment. This header has the following format:
Length Description
2 Type
2 Number
2 Reserved
4 Length
'Type' is a number describing what sort of segment it is (eg text, data,
comment, debug info). See 'rdoff2.txt' for a list of the segment types.
'Number' is the number used to refer to the segment in the header records.
Not all segments will be loaded; it is only intended that one code
and one data segment will be loaded into memory. It is possible, however,
for a loaded segment to contain a reference to an unloaded segment.
This is an error, and should be flagged at load time. Or maybe you should
load the segment... its up to you, really.
The segment's data immediately follows the end of the segment header.
HEADER RECORDS
==============
All of the header records have changed in this version, but not
substantially. Each record type has had a content-length code added,
a single byte immediately following the type byte. This contains the
length of the rest of the record (excluding the type and length bytes,
but including the terminating nulls on any strings in the record).
There are two new record types, Segment Relocation (6), and FAR import (7).
The record formats are identical to Relocation (1) and import (2). They are
only of real use on systems using segmented architectures. Systems using
a flat model should treat FAR import (7) exactly the same as an import (2),
and should either flag segment relocation as an error, or attempt to figure
out whether it is a reference to a code or data symbol, and set the value
referenced to the according selector value. I am opting for the former
approach, and would recommend that others working on 32 bit flat systems
do the same.

View file

@ -1,122 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 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.
*
* ----------------------------------------------------------------------- */
/*
* hash.h Routines to calculate a CRC32 hash value
*
* These routines donated to the NASM effort by Graeme Defty.
*/
#include "compiler.h"
#include "hash.h"
const uint32_t consttab[] = {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
};
uint32_t hash(const char *name)
{
register const char *n;
register uint32_t hashval = 0xffffffff;
for (n = name; *n; n++)
hashval = (hashval >> 8) ^ consttab[(hashval ^ *n) & 0xff];
hashval ^= 0xffffffff;
return hashval;
}

View file

@ -1,17 +0,0 @@
/* hash.h Routines to calculate a CRC32 hash value
*
* These routines donated to the NASM effort by Graeme Defty.
*
* The Netwide Assembler is copyright (C) 1996 Simon Tatham and
* Julian Hall. All rights reserved. The software is
* redistributable under the license given in the file "LICENSE"
* distributed in the NASM archive.
*/
#ifndef RDOFF_HASH_H
#define RDOFF_HASH_H 1
uint32_t hash(const char *name);
#endif

View file

@ -1,41 +0,0 @@
.TH LDRDF 1 "September 6, 1999" "Debian Project" "Debian Manual"
.SH NAME
ldrdf \- link RDOFF objects and libraries produced by rdflib(1)
.SH SYNOPSIS
.B ldrdf
.RI "[-o " output-file ]
.I object-file\c
.RI "... [-l" library "...]"
.SH DESCRIPTION
.B ldrdf
is a version of unix
.BR ld (1)
(or DOS LINK) for use with RDOFF files. It is capable of linking RDOFF
objects, and libraries produced with the
.BR rdflib (1)
utility.
.PP
Libraries must be specified with their path as no search is performed.
Modules in libraries are not linked to the program unless they are
referred to.
.SH OPTIONS
.TP
.RI "-o " output-file
Specify an output file. The default output filename is
.RI ' aout.rdx '.
.TP
-v
Increase verbosity level. Currently 4 verbosity levels are available:
default (which only prints error information), normal (which prints
information about the produced object, -v), medium (which prints information
about what the program is doing, -v -v) and high (which prints all available
information, -v -v -v).
.TP
-p
Change alignment value to which multiple segments combigned into a single
segment should be aligned (must be either 1, 2, 4, 8, 16, 32 or 256; default
is 16).
.SH AUTHORS
Julian Hall <jules@earthcorp.com>.
.PP
This manual page was written by Matej Vela <vela@debian.org>.

File diff suppressed because it is too large Load diff

View file

@ -1,59 +0,0 @@
/*
* ldsegs.h Data for 'ldrdf' to determine what to do with different
* types of segment. This may be useful in other contexts also.
*/
#ifndef RDOFF_LDSEGS_H
#define RDOFF_LDSEGS_H 1
struct segconfig {
uint16_t typelow, typehi; /* range of seg nos for which this is valid */
char *typedesc; /* a description of the segment type */
uint16_t dowhat; /* one of the SEG_xxxx values below */
uint16_t mergetype; /* if SEG_MERGE what type segment do we merge
with?
0 -> same type of segment. This type is also
used with SEG_NEWSEG. */
};
#define SEG_IGNORE 0
#define SEG_NEWSEG 1
#define SEG_MERGE 2
#define SEGCONFIGMAX 11
struct segconfig sconft[SEGCONFIGMAX] = {
{0x0000, 0x0000, "NULL segment", 0, 0},
{0x0001, 0x0001, "text", 2, 0},
{0x0002, 0x0002, "data", 2, 0},
{0x0003, 0x0003, "comment(ignored)", 0, 0},
{0x0004, 0x0005, "comment(kept)", 2, 0},
{0x0006, 0x0007, "debug information", 2, 0},
{0x0008, 0x001F, "reserved(general extensions)", 1, 0},
{0x0020, 0x0FFF, "reserved(MOSCOW)", 1, 0},
{0x1000, 0x7FFF, "reserved(system dependent)", 1, 0},
{0x8000, 0xFFFE, "reserved(other)", 1, 0},
{0xFFFF, 0xFFFF, "invalid segment", 0, 0}
};
#define getsegconfig(target,number) \
{ \
int _i; \
int _t = number; \
for (_i = 0; _i < SEGCONFIGMAX; _i++) \
if (_t >= sconft[_i].typelow && _t <= sconft[_i].typehi) \
{ \
target = sconft[_i]; \
if (target.mergetype == 0) target.mergetype = _t; \
break; \
} \
if (_i == SEGCONFIGMAX) \
{ \
fprintf(stderr, "PANIC: can't find segment %04X in segconfig\n",\
_t); \
exit(1); \
} \
}
#endif

View file

@ -1,65 +0,0 @@
.TH RDF2BIN 1 "September 6, 1999" "Debian Project" "Debian Manual"
.SH NAME
rdf2bin, rdf2com \- convert an RDOFF object file to flat binary
.SH SYNOPSIS
.B rdf2bin
.RI "[\-o " relocation-origin ]
.RI "[\-p " segment-alignment ]
.RI "[\-f " format ]
.I input-file
.I output-file
.br
.B rdf2com
.RI "[\-p " segment-alignment ]
.I input-file
.I output-file
.br
.B rdf2ith
.RI "[\-o " relocation-origin ]
.RI "[\-p " segment-alignment ]
.I input-file
.I output-file
.br
.B rdf2srec
.RI "[\-o " relocation-origin ]
.RI "[\-p " segment-alignment ]
.I input-file
.I output-file
.SH OPTIONS
.TP
.RI "\-o " relocation-origin
Relocate at origin
.IR relocation-origin .
If invoked as
.BR rdf2com ,
the default relocation origin will be 0x100. Else, the default origin is 0.
.TP
.RI "\-p " segment-alignment
Pad segments until their size is a multiple of
.IR segment-alignment .
By default, 16 is used.
.TP
.RI "\-f " format
Specify the output format. The currently supported formats are binary
.RI ( bin ),
DOS COM (binary with origin 0x100)
.RI ( com )
Intel hex
.RI ( ith
or
.IR ihx ),
and
Motorola S-Records
.RI ( srec ).
If not specified, the format is set by the command name.
.SH AUTHORS
Julian Hall <jules@earthcorp.com>, H. Peter Anvin <hpa@zytor.com>.
.PP
This manual page was written by Matej Vela <vela@debian.org>.
.SH BUGS
This utility currently only supports the classic segments
.IR .text ,
.I .data
and
.IR .bss .

View file

@ -1,430 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 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.
*
* ----------------------------------------------------------------------- */
/*
* rdf2bin.c - convert an RDOFF object file to flat binary
*/
#include "compiler.h"
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include "rdfload.h"
#include "nasmlib.h"
const char *progname;
static uint32_t origin = 0;
static bool origin_def = false;
static uint32_t align = 16;
static bool align_def = false;
struct output_format {
const char *name;
const char *mode;
int (*init)(FILE *f);
int (*output)(FILE *f, void *data, uint32_t bytes, uint32_t where);
int (*fini)(FILE *f);
};
static int null_init_fini(FILE *f)
{
(void)f;
return 0;
}
static int com_init(FILE *f)
{
(void)f;
if (!origin_def)
origin = 0x100;
return 0;
}
static int output_bin(FILE *f, void *data, uint32_t bytes, uint32_t where)
{
static uint32_t offset = 0; /* Current file offset, if applicable */
size_t pad;
if (where-origin < offset) {
fprintf(stderr, "%s: internal error: backwards movement\n", progname);
exit(1);
}
pad = (where-origin) - offset;
fwritezero(pad, f);
offset += pad;
if (fwrite(data, 1, bytes, f) != bytes)
return -1;
offset += bytes;
return 0;
}
static int write_ith_record(FILE *f, unsigned int len, uint16_t addr,
uint8_t type, void *data)
{
char buf[1+2+4+2+255*2+2+2];
char *p = buf;
uint8_t csum, *dptr = data;
unsigned int i;
if (len > 255) {
fprintf(stderr, "%s: internal error: invalid ith record size\n",
progname);
exit(1);
}
csum = len + addr + (addr >> 8) + type;
for (i = 0; i < len; i++)
csum += dptr[i];
csum = -csum;
p += sprintf(p, ":%02X%04X%02X", len, addr, type);
for (i = 0; i < len; i++)
p += sprintf(p, "%02X", dptr[i]);
p += sprintf(p, "%02X\n", csum);
if (fwrite(buf, 1, p-buf, f) != (size_t)(p-buf))
return -1;
return 0;
}
static int output_ith(FILE *f, void *data, uint32_t bytes, uint32_t where)
{
static uint32_t last = 0; /* Last address written */
uint8_t abuf[2];
uint8_t *dbuf = data;
uint32_t chunk;
while (bytes) {
if ((where ^ last) & ~0xffff) {
abuf[0] = where >> 24;
abuf[1] = where >> 16;
if (write_ith_record(f, 2, 0, 4, abuf))
return -1;
}
/* Output up to 32 bytes, but always end on an aligned boundary */
chunk = 32 - (where & 31);
if (bytes < chunk)
chunk = bytes;
if (write_ith_record(f, chunk, (uint16_t)where, 0, dbuf))
return -1;
dbuf += chunk;
last = where + chunk - 1;
where += chunk;
bytes -= chunk;
}
return 0;
}
static int fini_ith(FILE *f)
{
/* XXX: entry point? */
return write_ith_record(f, 0, 0, 1, NULL);
}
static int write_srecord(FILE *f, unsigned int len, unsigned int alen,
uint32_t addr, uint8_t type, void *data)
{
char buf[2+2+8+255*2+2+2];
char *p = buf;
uint8_t csum, *dptr = data;
unsigned int i;
if (len > 255) {
fprintf(stderr, "%s: internal error: invalid srec record size\n",
progname);
exit(1);
}
switch (alen) {
case 2:
addr &= 0xffff;
break;
case 3:
addr &= 0xffffff;
break;
case 4:
break;
default:
fprintf(stderr, "%s: internal error: invalid srec address length\n",
progname);
exit(1);
}
csum = (len+alen+1) + addr + (addr >> 8) + (addr >> 16) + (addr >> 24);
for (i = 0; i < len; i++)
csum += dptr[i];
csum = 0xff-csum;
p += sprintf(p, "S%c%02X%0*X", type, len+alen+1, alen*2, addr);
for (i = 0; i < len; i++)
p += sprintf(p, "%02X", dptr[i]);
p += sprintf(p, "%02X\n", csum);
if (fwrite(buf, 1, p-buf, f) != (size_t)(p-buf))
return -1;
return 0;
}
static int init_srec(FILE *f)
{
return write_srecord(f, 0, 2, 0, '0', NULL);
}
static int fini_srec(FILE *f)
{
/* XXX: entry point? */
return write_srecord(f, 0, 4, 0, '7', NULL);
}
static int output_srec(FILE *f, void *data, uint32_t bytes, uint32_t where)
{
uint8_t *dbuf = data;
unsigned int chunk;
while (bytes) {
/* Output up to 32 bytes, but always end on an aligned boundary */
chunk = 32 - (where & 31);
if (bytes < chunk)
chunk = bytes;
if (write_srecord(f, chunk, 4, where, '3', dbuf))
return -1;
dbuf += chunk;
where += chunk;
bytes -= chunk;
}
return 0;
}
static struct output_format output_formats[] = {
{ "bin", "wb", null_init_fini, output_bin, null_init_fini },
{ "com", "wb", com_init, output_bin, null_init_fini },
{ "ith", "wt", null_init_fini, output_ith, fini_ith },
{ "ihx", "wt", null_init_fini, output_ith, fini_ith },
{ "srec", "wt", init_srec, output_srec, fini_srec },
{ NULL, NULL, NULL, NULL, NULL }
};
static const char *getformat(const char *pathname)
{
const char *p;
static char fmt_buf[16];
/*
* Search backwards for the string "rdf2" followed by a string
* of alphanumeric characters. This should handle path prefixes,
* as well as extensions (e.g. C:\FOO\RDF2SREC.EXE).
*/
for (p = strchr(pathname, '\0')-1 ; p >= pathname ; p--) {
if (!nasm_stricmp(p, "rdf2")) {
const char *q = p+4;
char *r = fmt_buf;
while (isalnum(*q) && r < fmt_buf+sizeof fmt_buf-1)
*r++ = *q++;
*r = '\0';
if (fmt_buf[0])
return fmt_buf;
}
}
return NULL;
}
static void usage(void)
{
fprintf(stderr,
"Usage: %s [options] input-file output-file\n"
"Options:\n"
" -o origin Specify the relocation origin\n"
" -p alignment Specify minimum segment alignment\n"
" -f format Select format (bin, com, ith, srec)\n"
" -q Run quiet\n"
" -v Run verbose\n",
progname);
}
int main(int argc, char **argv)
{
rdfmodule *m;
bool err;
FILE *of;
int codepad, datapad;
const char *format = NULL;
const struct output_format *fmt;
bool quiet = false;
progname = argv[0];
if (argc < 2) {
usage();
return 1;
}
rdoff_init();
argv++, argc--;
while (argc > 2) {
if (argv[0][0] == '-' && argv[0][1] && !argv[0][2]) {
switch (argv[0][1]) {
case 'o':
argv++, argc--;
origin = readnum(*argv, &err);
if (err) {
fprintf(stderr, "%s: invalid parameter: %s\n",
progname, *argv);
return 1;
}
origin_def = true;
break;
case 'p':
argv++, argc--;
align = readnum(*argv, &err);
if (err) {
fprintf(stderr, "%s: invalid parameter: %s\n",
progname, *argv);
return 1;
}
align_def = true;
break;
case 'f':
argv++, argc--;
format = *argv;
break;
case 'q':
quiet = true;
break;
case 'v':
quiet = false;
break;
case 'h':
usage();
return 0;
default:
fprintf(stderr, "%s: unknown option: %s\n",
progname, *argv);
return 1;
}
}
argv++, argc--;
}
if (argc < 2) {
usage();
return 1;
}
if (!format)
format = getformat(progname);
if (!format) {
fprintf(stderr, "%s: unable to determine desired output format\n",
progname);
return 1;
}
for (fmt = output_formats; fmt->name; fmt++) {
if (!nasm_stricmp(format, fmt->name))
break;
}
if (!fmt->name) {
fprintf(stderr, "%s: unknown output format: %s\n", progname, format);
return 1;
}
m = rdfload(*argv);
if (!m) {
rdfperror(progname, *argv);
return 1;
}
if (!quiet)
printf("relocating %s: origin=%"PRIx32", align=%d\n",
*argv, origin, align);
m->textrel = origin;
m->datarel = origin + m->f.seg[0].length;
if (m->datarel % align != 0) {
codepad = align - (m->datarel % align);
m->datarel += codepad;
} else
codepad = 0;
m->bssrel = m->datarel + m->f.seg[1].length;
if (m->bssrel % align != 0) {
datapad = align - (m->bssrel % align);
m->bssrel += datapad;
} else
datapad = 0;
if (!quiet)
printf("code: %08"PRIx32"\ndata: %08"PRIx32"\nbss: %08"PRIx32"\n",
m->textrel, m->datarel, m->bssrel);
rdf_relocate(m);
argv++;
of = fopen(*argv, fmt->mode);
if (!of) {
fprintf(stderr, "%s: could not open output file %s: %s\n",
progname, *argv, strerror(errno));
return 1;
}
if (fmt->init(of) ||
fmt->output(of, m->t, m->f.seg[0].length, m->textrel) ||
fmt->output(of, m->d, m->f.seg[1].length, m->datarel) ||
fmt->fini(of)) {
fprintf(stderr, "%s: error writing to %s: %s\n",
progname, *argv, strerror(errno));
return 1;
}
fclose(of);
return 0;
}

View file

@ -1 +0,0 @@
.so man1/rdf2bin.1

View file

@ -1 +0,0 @@
.so man1/rdf2bin.1

View file

@ -1 +0,0 @@
.so man1/rdf2bin.1

View file

@ -1 +0,0 @@
.so man1/rdf2bin.1

View file

@ -1,24 +0,0 @@
.TH RDFDUMP 1 "September 6, 1999" "Debian Project" "Debian Manual"
.SH NAME
rdfdump \- dumps an RDOFF object in human-readable form
.SH SYNOPSIS
.B rdfdump
[-v]
.RI < filename >
.SH DESCRIPTION
.B rdfdump
prints a list of the header records in an RDOFF object in human-readable
form, and optionally prints a hex dump of the contents of the segments.
.PP
.B rdfdump
supports both version 1 and 2 of RDOFF. It will give warnings if the RDOFF2
format is violated (it looks for incorrect lengths for header records, and
checks the overall length count at the start of the file).
.SH OPTIONS
.TP
-v
Print a hex dump of the contents of the segments.
.SH AUTHORS
Julian Hall <jules@earthcorp.com>.
.PP
This manual page was written by Matej Vela <vela@debian.org>.

View file

@ -1,346 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2014 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.
*
* ----------------------------------------------------------------------- */
/*
* rdfdump.c - dump RDOFF file header.
*/
#include "compiler.h"
#include <stdio.h>
#include <stdlib.h>
#include "rdfutils.h"
#define PROGRAM_VERSION "2.3"
FILE *infile;
static void print_header(int32_t length, int rdf_version)
{
char buf[129], t, l, s, flags;
uint8_t reclen;
int32_t o, ll;
uint16_t rs;
while (length > 0) {
nasm_read(&t, 1, infile);
if (rdf_version >= 2) {
nasm_read(&reclen, 1, infile);
}
switch (t) {
case RDFREC_GENERIC: /* generic record */
printf(" generic record (length=%d)\n", (int)reclen);
fseek(infile, reclen, SEEK_CUR);
break;
case RDFREC_RELOC: /* relocation record */
case RDFREC_SEGRELOC: /* segment relocation */
nasm_read(&s, 1, infile);
nasm_read(&o, 4, infile);
nasm_read(&l, 1, infile);
nasm_read(&rs, 2, infile);
printf(" %s: location (%04x:%08"PRIx32"), length %d, "
"referred seg %04x\n",
t == 1 ? "relocation" : "seg relocation", (int)s,
translateint32_t(o), (int)l, translateint16_t(rs));
if (rdf_version >= 2 && reclen != 8)
printf(" warning: reclen != 8\n");
if (rdf_version == 1)
length -= 9;
if (rdf_version == 1 && t == 6)
printf
(" warning: seg relocation not supported in RDOFF1\n");
break;
case RDFREC_IMPORT: /* import record */
case RDFREC_FARIMPORT: /* import far symbol */
nasm_read(&flags, 1, infile);
nasm_read(&rs, 2, infile);
ll = 0;
if (rdf_version == 1) {
do {
nasm_read(&buf[ll], 1, infile);
} while (buf[ll++]);
} else {
for (; ll < reclen - 3; ll++)
nasm_read(&buf[ll], 1, infile);
}
if (t == 7)
printf("far ");
printf((flags & SYM_IMPORT) ? " import" : " extern");
if (flags & SYM_FUNCTION)
printf(" proc");
if (flags & SYM_DATA)
printf(" data");
printf(": segment %04x = %s\n", translateint16_t(rs), buf);
if (rdf_version == 1)
length -= ll + 3;
if (rdf_version == 1 && t == 7)
printf
(" warning: far import not supported in RDOFF1\n");
break;
case RDFREC_GLOBAL: /* export record */
nasm_read(&flags, 1, infile);
nasm_read(&s, 1, infile);
nasm_read(&o, 4, infile);
ll = 0;
if (rdf_version == 1) {
do {
nasm_read(&buf[ll], 1, infile);
} while (buf[ll++]);
} else {
for (; ll < reclen - 6; ll++)
nasm_read(&buf[ll], 1, infile);
}
printf((flags & SYM_GLOBAL) ? " export" : " public");
if (flags & SYM_FUNCTION)
printf(" proc");
if (flags & SYM_DATA)
printf(" data");
printf(": (%04x:%08"PRIx32") = %s\n", (int)s, translateint32_t(o), buf);
if (rdf_version == 1)
length -= ll + 6;
break;
case RDFREC_DLL: /* DLL and Module records */
case RDFREC_MODNAME:
ll = 0;
if (rdf_version == 1) {
do {
nasm_read(&buf[ll], 1, infile);
} while (buf[ll++]);
} else {
for (; ll < reclen; ll++)
nasm_read(&buf[ll], 1, infile);
}
if (t == 4)
printf(" dll: %s\n", buf);
else
printf(" module: %s\n", buf);
if (rdf_version == 1)
length -= ll + 1;
break;
case RDFREC_BSS: /* BSS reservation */
nasm_read(&ll, 4, infile);
printf(" bss reservation: %08"PRIx32" bytes\n", translateint32_t(ll));
if (rdf_version == 1)
length -= 5;
if (rdf_version > 1 && reclen != 4)
printf(" warning: reclen != 4\n");
break;
case RDFREC_COMMON:{
uint16_t seg, align;
uint32_t size;
nasm_read(&seg, 2, infile);
nasm_read(&size, 4, infile);
nasm_read(&align, 2, infile);
for (ll = 0; ll < reclen - 8; ll++)
nasm_read(buf + ll, 1, infile);
printf(" common: segment %04x = %s, %"PRId32":%d\n",
translateint16_t(seg), buf, translateint32_t(size),
translateint16_t(align));
break;
}
default:
printf(" unrecognized record (type %d", (int)t);
if (rdf_version > 1) {
printf(", length %d", (int)reclen);
fseek(infile, reclen, SEEK_CUR);
} else
length--;
printf(")\n");
}
if (rdf_version != 1)
length -= 2 + reclen;
}
}
int main(int argc, char **argv)
{
char id[7];
int32_t l;
uint16_t s;
int verbose = 0;
int32_t offset;
int foundnullsegment = 0;
int version;
int32_t segmentcontentlength = 0;
int nsegments = 0;
int32_t headerlength = 0;
int32_t objectlength = 0;
printf("RDOFF dump utility, version %s\n", PROGRAM_VERSION);
printf("RDOFF2 revision %s\n", RDOFF2_REVISION);
puts("Copyright (c) 1996,99 Julian R Hall\n"
"Improvements and fixes (c) 2002-2004 RET & COM Research.");
if (argc < 2) {
fputs("Usage: rdfdump [-v] <filename>\n", stderr);
exit(1);
}
rdoff_init();
if (!strcmp(argv[1], "-v")) {
verbose = 1;
if (argc < 3) {
fputs("required parameter missing\n", stderr);
exit(1);
}
argv++;
}
infile = fopen(argv[1], "rb");
if (!infile) {
fprintf(stderr, "rdfdump: Could not open %s\n", argv[1]);
exit(1);
}
nasm_read(id, 6, infile);
if (strncmp(id, "RDOFF", 5)) {
fputs("rdfdump: File does not contain valid RDOFF header\n",
stderr);
exit(1);
}
printf("File %s: RDOFF version %c\n\n", argv[1], id[5]);
if (id[5] < '1' || id[5] > '2') {
fprintf(stderr, "rdfdump: unknown RDOFF version '%c'\n", id[5]);
exit(1);
}
version = id[5] - '0';
if (version > 1) {
nasm_read(&l, 4, infile);
objectlength = translateint32_t(l);
printf("Object content size: %"PRId32" bytes\n", objectlength);
}
nasm_read(&l, 4, infile);
headerlength = translateint32_t(l);
printf("Header (%"PRId32" bytes):\n", headerlength);
print_header(headerlength, version);
if (version == 1) {
nasm_read(&l, 4, infile);
l = translateint32_t(l);
printf("\nText segment length = %"PRId32" bytes\n", l);
offset = 0;
while (l--) {
nasm_read(id, 1, infile);
if (verbose) {
if (offset % 16 == 0)
printf("\n%08"PRIx32" ", offset);
printf(" %02x", (int)(uint8_t)id[0]);
offset++;
}
}
if (verbose)
printf("\n\n");
nasm_read(&l, 4, infile);
l = translateint32_t(l);
printf("Data segment length = %"PRId32" bytes\n", l);
if (verbose) {
offset = 0;
while (l--) {
nasm_read(id, 1, infile);
if (offset % 16 == 0)
printf("\n%08"PRIx32" ", offset);
printf(" %02x", (int)(uint8_t)id[0]);
offset++;
}
printf("\n");
}
} else {
do {
nasm_read(&s, 2, infile);
s = translateint16_t(s);
if (!s) {
printf("\nNULL segment\n");
foundnullsegment = 1;
break;
}
printf("\nSegment:\n Type = %04X (%s)\n", (int)s,
translatesegmenttype(s));
nsegments++;
nasm_read(&s, 2, infile);
printf(" Number = %04X\n", (int)translateint16_t(s));
nasm_read(&s, 2, infile);
printf(" Resrvd = %04X\n", (int)translateint16_t(s));
nasm_read(&l, 4, infile);
l = translateint32_t(l);
printf(" Length = %"PRId32" bytes\n", l);
segmentcontentlength += l;
offset = 0;
while (l--) {
nasm_read(id, 1, infile);
if (verbose) {
if (offset % 16 == 0)
printf("\n%08"PRIx32" ", offset);
printf(" %02x", (int)(uint8_t)id[0]);
offset++;
}
}
if (verbose)
printf("\n");
} while (!feof(infile));
if (!foundnullsegment)
printf("\nWarning: unexpected end of file - "
"NULL segment not found\n");
printf("\nTotal number of segments: %d\n", nsegments);
printf("Total segment content length: %"PRId32" bytes\n",
segmentcontentlength);
/* calculate what the total object content length should have been */
l = segmentcontentlength + 10 * (nsegments + 1) + headerlength + 4;
if (l != objectlength)
printf("Warning: actual object length (%"PRId32") != "
"stored object length (%"PRId32")\n", l, objectlength);
}
fclose(infile);
return 0;
}

View file

@ -1,39 +0,0 @@
.TH RDFLIB 1 "September 6, 1999" "Debian Project" "Debian Manual"
.SH NAME
rdflib \- manage a library file for use with ldrdf(1)
.SH SYNOPSIS
.B rdflib
.I command
.I arguments
.SH DESCRIPTION
.B rdflib
manages a library file which can be used by
.BR ldrdf (1).
It is supplied with a shell script
.B makelib
which should probably be used to create libraries.
.SH COMMANDS
.TP
.BI c " library-file"
Create (or truncate) a library.
.TP
.BI a " library-file object-file module"
Add the
.I object-file
to the library under the name
.IR module .
.TP
.BI x " library-file module object-file"
Extract a
.I module
from the library to the file
.IR object-file .
.TP
.B t " library-file"
Display a list of modules in the library.
.SH NOTES
A remove command will be added soon.
.SH AUTHORS
Julian Hall <jules@earthcorp.com>.
.PP
This manual page was written by Matej Vela <vela@debian.org>.

View file

@ -1,438 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 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.
*
* ----------------------------------------------------------------------- */
/* rdflib - manipulate RDOFF library files (.rdl) */
/*
* an rdoff library is simply a sequence of RDOFF object files, each
* preceded by the name of the module, an ASCII string of up to 255
* characters, terminated by a zero.
*
* When a library is being created, special signature block is placed
* in the beginning of the file. It is a string 'RDLIB' followed by a
* version number, then int32_t content size and a int32_t time stamp.
* The module name of the signature block is '.sig'.
*
*
* There may be an optional directory placed on the end of the file.
* The format of the directory will be 'RDLDD' followed by a version
* number, followed by the length of the directory, and then the
* directory, the format of which has not yet been designed.
* The module name of the directory must be '.dir'.
*
* All module names beginning with '.' are reserved for possible future
* extensions. The linker ignores all such modules, assuming they have
* the format of a six uint8_t type & version identifier followed by int32_t
* content size, followed by data.
*/
#include "compiler.h"
#include "rdfutils.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
/* functions supported:
* create a library (no extra operands required)
* add a module from a library (requires filename and name to give mod.)
* replace a module in a library (requires given name and filename)
* delete a module from a library (requires given name)
* extract a module from the library (requires given name and filename)
* list modules
*/
const char *usage =
"usage:\n"
" rdflib x libname [extra operands]\n\n"
" where x is one of:\n"
" c - create library\n"
" a - add module (operands = filename module-name)\n"
" x - extract (module-name filename)\n"
" r - replace (module-name filename)\n"
" d - delete (module-name)\n" " t - list\n";
/* Library signature */
const char *rdl_signature = "RDLIB2", *sig_modname = ".sig";
char **_argv;
#define _ENDIANNESS 0 /* 0 for little, 1 for big */
static void int32_ttolocal(int32_t *l)
{
#if _ENDIANNESS
uint8_t t;
uint8_t *p = (uint8_t *)l;
t = p[0];
p[0] = p[3];
p[3] = t;
t = p[1];
p[1] = p[2];
p[2] = p[1];
#else
(void)l; /* placate optimizers */
#endif
}
static char copybytes(FILE * fp, FILE * fp2, int n)
{
int i, t = 0;
for (i = 0; i < n; i++) {
t = fgetc(fp);
if (t == EOF) {
fprintf(stderr, "rdflib: premature end of file in '%s'\n",
_argv[2]);
exit(1);
}
if (fp2)
if (fputc(t, fp2) == EOF) {
fprintf(stderr, "rdflib: write error\n");
exit(1);
}
}
return (char)t; /* return last char read */
}
static int32_t copyint32_t(FILE * fp, FILE * fp2)
{
int32_t l;
int i, t;
uint8_t *p = (uint8_t *)&l;
for (i = 0; i < 4; i++) { /* skip magic no */
t = fgetc(fp);
if (t == EOF) {
fprintf(stderr, "rdflib: premature end of file in '%s'\n",
_argv[2]);
exit(1);
}
if (fp2)
if (fputc(t, fp2) == EOF) {
fprintf(stderr, "rdflib: write error\n");
exit(1);
}
*p++ = t;
}
int32_ttolocal(&l);
return l;
}
int main(int argc, char **argv)
{
FILE *fp, *fp2 = NULL, *fptmp;
char *p, buf[256], c;
int i;
int32_t l;
time_t t;
char rdbuf[10];
_argv = argv;
if (argc < 3 || !strncmp(argv[1], "-h", 2)
|| !strncmp(argv[1], "--h", 3)) {
fputs(usage, stdout);
exit(1);
}
rdoff_init();
switch (argv[1][0]) {
case 'c': /* create library */
fp = fopen(argv[2], "wb");
if (!fp) {
fprintf(stderr, "rdflib: could not open '%s'\n", argv[2]);
perror("rdflib");
exit(1);
}
nasm_write(sig_modname, strlen(sig_modname) + 1, fp);
nasm_write(rdl_signature, strlen(rdl_signature), fp);
t = time(NULL);
l = sizeof(t);
fwriteint32_t(l, fp);
fwriteint32_t(t, fp);
fclose(fp);
break;
case 'a': /* add module */
if (argc < 5) {
fprintf(stderr, "rdflib: required parameter missing\n");
exit(1);
}
fp = fopen(argv[2], "ab");
if (!fp) {
fprintf(stderr, "rdflib: could not open '%s'\n", argv[2]);
perror("rdflib");
exit(1);
}
fp2 = fopen(argv[3], "rb");
if (!fp2) {
fprintf(stderr, "rdflib: could not open '%s'\n", argv[3]);
perror("rdflib");
exit(1);
}
p = argv[4];
do {
if (fputc(*p, fp) == EOF) {
fprintf(stderr, "rdflib: write error\n");
exit(1);
}
} while (*p++);
while (!feof(fp2)) {
i = fgetc(fp2);
if (i == EOF) {
break;
}
if (fputc(i, fp) == EOF) {
fprintf(stderr, "rdflib: write error\n");
exit(1);
}
}
fclose(fp2);
fclose(fp);
break;
case 'x':
if (argc < 5) {
fprintf(stderr, "rdflib: required parameter missing\n");
exit(1);
}
/* fall through */
case 't':
fp = fopen(argv[2], "rb");
if (!fp) {
fprintf(stderr, "rdflib: could not open '%s'\n", argv[2]);
perror("rdflib");
exit(1);
}
fp2 = NULL;
while (!feof(fp)) {
/* read name */
p = buf;
while ((*(p++) = (char)fgetc(fp)))
if (feof(fp))
break;
if (feof(fp))
break;
fp2 = NULL;
if (argv[1][0] == 'x') {
/* check against desired name */
if (!strcmp(buf, argv[3])) {
fp2 = fopen(argv[4], "wb");
if (!fp2) {
fprintf(stderr, "rdflib: could not open '%s'\n",
argv[4]);
perror("rdflib");
exit(1);
}
}
} else
printf("%-40s ", buf);
/* step over the RDOFF file, extracting type information for
* the listing, and copying it if fp2 != NULL */
if (buf[0] == '.') {
if (argv[1][0] == 't')
for (i = 0; i < 6; i++)
printf("%c", copybytes(fp, fp2, 1));
else
copybytes(fp, fp2, 6);
l = copyint32_t(fp, fp2);
if (argv[1][0] == 't')
printf(" %"PRId32" bytes content\n", l);
copybytes(fp, fp2, l);
} else if ((c = copybytes(fp, fp2, 6)) >= '2') { /* version 2 or above */
l = copyint32_t(fp, fp2);
if (argv[1][0] == 't')
printf("RDOFF%c %"PRId32" bytes content\n", c, l);
copybytes(fp, fp2, l); /* entire object */
} else {
if (argv[1][0] == 't')
printf("RDOFF1\n");
/*
* version 1 object, so we don't have an object content
* length field.
*/
copybytes(fp, fp2, copyint32_t(fp, fp2)); /* header */
copybytes(fp, fp2, copyint32_t(fp, fp2)); /* text */
copybytes(fp, fp2, copyint32_t(fp, fp2)); /* data */
}
if (fp2)
break;
}
fclose(fp);
if (fp2)
fclose(fp2);
else if (argv[1][0] == 'x') {
fprintf(stderr, "rdflib: module '%s' not found in '%s'\n",
argv[3], argv[2]);
exit(1);
}
break;
case 'r': /* replace module */
argc--;
/* fall through */
case 'd': /* delete module */
if (argc < 4) {
fprintf(stderr, "rdflib: required parameter missing\n");
exit(1);
}
fp = fopen(argv[2], "rb");
if (!fp) {
fprintf(stderr, "rdflib: could not open '%s'\n", argv[2]);
perror("rdflib");
exit(1);
}
if (argv[1][0] == 'r') {
fp2 = fopen(argv[4], "rb");
if (!fp2) {
fprintf(stderr, "rdflib: could not open '%s'\n", argv[4]);
perror("rdflib");
exit(1);
}
}
fptmp = tmpfile();
if (!fptmp) {
fprintf(stderr, "rdflib: could not open temporary file\n");
perror("rdflib");
exit(1);
}
/* copy library into temporary file */
fseek(fp, 0, SEEK_END); /* get file length */
l = ftell(fp);
fseek(fp, 0, SEEK_SET);
copybytes(fp, fptmp, l);
rewind(fptmp);
if (freopen(argv[2], "wb", fp) == NULL) {
fprintf(stderr, "rdflib: could not reopen '%s'\n", argv[2]);
perror("rdflib");
exit(1);
}
while (!feof(fptmp)) {
/* read name */
p = buf;
while ((*(p++) = (char)fgetc(fptmp)))
if (feof(fptmp))
break;
if (feof(fptmp))
break;
/* check against desired name */
if (!strcmp(buf, argv[3])) {
if (fread(p = rdbuf, 1, sizeof(rdbuf), fptmp) < 10) {
nasm_fatal("short read on input");
}
l = *(int32_t *)(p + 6);
fseek(fptmp, l, SEEK_CUR);
break;
} else {
nasm_write(buf, strlen(buf) + 1, fp); /* module name */
if ((c = copybytes(fptmp, fp, 6)) >= '2') {
l = copyint32_t(fptmp, fp); /* version 2 or above */
copybytes(fptmp, fp, l); /* entire object */
}
}
}
if (argv[1][0] == 'r') {
/* copy new module into library */
p = argv[3];
do {
if (fputc(*p, fp) == EOF) {
fprintf(stderr, "rdflib: write error\n");
exit(1);
}
} while (*p++);
while (!feof(fp2)) {
i = fgetc(fp2);
if (i == EOF) {
break;
}
if (fputc(i, fp) == EOF) {
fprintf(stderr, "rdflib: write error\n");
exit(1);
}
}
fclose(fp2);
}
/* copy rest of library if any */
while (!feof(fptmp)) {
i = fgetc(fptmp);
if (i == EOF) {
break;
}
if (fputc(i, fp) == EOF) {
fprintf(stderr, "rdflib: write error\n");
exit(1);
}
}
fclose(fp);
fclose(fptmp);
break;
default:
fprintf(stderr, "rdflib: command '%c' not recognized\n",
argv[1][0]);
exit(1);
}
return 0;
}

View file

@ -1,212 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2017 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.
*
* ----------------------------------------------------------------------- */
/*
* rdfload.c RDOFF Object File loader library
*/
/*
* TODO: this has been modified from previous version only in very
* simplistic ways. Needs to be improved drastically, especially:
* - support for more than the 2 standard segments
* - support for segment relocations (hard to do in ANSI C)
*/
#include "compiler.h"
#include <stdio.h>
#include <stdlib.h>
#include "rdfload.h"
#include "symtab.h"
#include "collectn.h"
extern int rdf_errno;
rdfmodule *rdfload(const char *filename)
{
rdfmodule *f;
int32_t bsslength = 0;
char *hdr;
rdfheaderrec *r;
f = nasm_malloc(sizeof(rdfmodule));
if (f == NULL) {
rdf_errno = RDF_ERR_NOMEM;
return NULL;
}
f->symtab = symtabNew();
if (!f->symtab) {
nasm_free(f);
rdf_errno = RDF_ERR_NOMEM;
return NULL;
}
/* open the file */
if (rdfopen(&(f->f), filename)) {
nasm_free(f);
return NULL;
}
/* read in text and data segments, and header */
f->t = nasm_malloc(f->f.seg[0].length);
f->d = nasm_malloc(f->f.seg[1].length); /* BSS seg allocated later */
hdr = nasm_malloc(f->f.header_len);
if (!f->t || !f->d || !hdr) {
rdf_errno = RDF_ERR_NOMEM;
rdfclose(&f->f);
if (f->t)
nasm_free(f->t);
if (f->d)
nasm_free(f->d);
nasm_free(f);
nasm_free(hdr);
return NULL;
}
if (rdfloadseg(&f->f, RDOFF_HEADER, hdr) ||
rdfloadseg(&f->f, RDOFF_CODE, f->t) ||
rdfloadseg(&f->f, RDOFF_DATA, f->d)) {
rdfclose(&f->f);
nasm_free(f->t);
nasm_free(f->d);
nasm_free(f);
nasm_free(hdr);
return NULL;
}
rdfclose(&f->f);
/* Allocate BSS segment; step through header and count BSS records */
while ((r = rdfgetheaderrec(&f->f))) {
if (r->type == 5)
bsslength += r->b.amount;
}
f->b = nasm_malloc(bsslength);
if (bsslength && (!f->b)) {
nasm_free(f->t);
nasm_free(f->d);
nasm_free(f);
nasm_free(hdr);
rdf_errno = RDF_ERR_NOMEM;
return NULL;
}
rdfheaderrewind(&f->f);
f->textrel = (int32_t)(size_t)f->t;
f->datarel = (int32_t)(size_t)f->d;
f->bssrel = (int32_t)(size_t)f->b;
return f;
}
int rdf_relocate(rdfmodule * m)
{
rdfheaderrec *r;
Collection imports;
symtabEnt e;
int32_t rel;
uint8_t *seg;
rdfheaderrewind(&m->f);
collection_init(&imports);
while ((r = rdfgetheaderrec(&m->f))) {
switch (r->type) {
case 1: /* Relocation record */
/* calculate relocation factor */
if (r->r.refseg == 0)
rel = m->textrel;
else if (r->r.refseg == 1)
rel = m->datarel;
else if (r->r.refseg == 2)
rel = m->bssrel;
else
/* We currently do not support load-time linkage.
This should be added some time soon... */
return 1; /* return error code */
if ((r->r.segment & 63) == 0)
seg = m->t;
else if ((r->r.segment & 63) == 1)
seg = m->d;
else
continue; /* relocation not in a loaded segment */
/* it doesn't matter in this case that the code is non-portable,
as the entire concept of executing a module like this is
non-portable */
switch (r->r.length) {
case 1:
seg[r->r.offset] += (char)rel;
break;
case 2:
*(uint16_t *) (seg + r->r.offset) += (uint16_t) rel;
break;
case 4:
*(int32_t *)(seg + r->r.offset) += rel;
break;
}
break;
case 3: /* export record - add to symtab */
e.segment = r->e.segment;
e.offset = r->e.offset + (e.segment == 0 ? m->textrel : /* 0 -> code */
e.segment == 1 ? m->datarel : /* 1 -> data */
m->bssrel); /* 2 -> bss */
e.flags = 0;
e.name = nasm_malloc(strlen(r->e.label) + 1);
if (!e.name)
return 1;
strcpy(e.name, r->e.label);
symtabInsert(m->symtab, &e);
break;
case 6: /* segment relocation */
fprintf(stderr, "%s: segment relocation not supported by this "
"loader\n", m->f.name);
return 1;
}
}
return 0;
}

View file

@ -1,29 +0,0 @@
/* rdfload.h RDOFF Object File loader library header file
*
* The Netwide Assembler is copyright (C) 1996 Simon Tatham and
* Julian Hall. All rights reserved. The software is
* redistributable under the license given in the file "LICENSE"
* distributed in the NASM archive.
*
* See the file 'rdfload.c' for special license information for this
* file.
*/
#ifndef RDOFF_RDFLOAD_H
#define RDOFF_RDFLOAD_H 1
#include "rdfutils.h"
typedef struct RDFModuleStruct {
rdffile f; /* file structure */
uint8_t *t, *d, *b; /* text, data, and bss segments */
uint32_t textrel;
uint32_t datarel;
uint32_t bssrel;
void *symtab;
} rdfmodule;
rdfmodule *rdfload(const char *filename);
int rdf_relocate(rdfmodule * m);
#endif

View file

@ -1,165 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2017 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.
*
* ----------------------------------------------------------------------- */
/*
* rdfutils.h
*
* Internal header file for RDOFF utilities
*/
#ifndef RDOFF_RDFUTILS_H
#define RDOFF_RDFUTILS_H 1
#include "compiler.h"
#include "nasmlib.h"
#include "error.h"
#include "rdoff.h"
#include <stdlib.h>
#include <stdio.h>
typedef union RDFHeaderRec {
char type; /* invariant throughout all below */
struct GenericRec g; /* type 0 */
struct RelocRec r; /* type == 1 / 6 */
struct ImportRec i; /* type == 2 / 7 */
struct ExportRec e; /* type == 3 */
struct DLLRec d; /* type == 4 */
struct BSSRec b; /* type == 5 */
struct ModRec m; /* type == 8 */
struct CommonRec c; /* type == 10 */
} rdfheaderrec;
struct SegmentHeaderRec {
/* information from file */
uint16_t type;
uint16_t number;
uint16_t reserved;
int32_t length;
/* information built up here */
int32_t offset;
uint8_t *data; /* pointer to segment data if it exists in memory */
};
typedef struct RDFFileInfo {
FILE *fp; /* file descriptor; must be open to use this struct */
int rdoff_ver; /* should be 1; any higher => not guaranteed to work */
int32_t header_len;
int32_t header_ofs;
uint8_t *header_loc; /* keep location of header */
int32_t header_fp; /* current location within header for reading */
struct SegmentHeaderRec seg[RDF_MAXSEGS];
int nsegs;
int32_t eof_offset; /* offset of the first uint8_t beyond the end of this
module */
char *name; /* name of module in libraries */
int *refcount; /* pointer to reference count on file, or NULL */
} rdffile;
#define BUF_BLOCK_LEN 4088 /* selected to match page size (4096)
* on 80x86 machines for efficiency */
typedef struct memorybuffer {
int length;
uint8_t buffer[BUF_BLOCK_LEN];
struct memorybuffer *next;
} memorybuffer;
typedef struct {
memorybuffer *buf; /* buffer containing header records */
int nsegments; /* number of segments to be written */
int32_t seglength; /* total length of all the segments */
} rdf_headerbuf;
/* segments used by RDOFF, understood by rdoffloadseg */
#define RDOFF_CODE 0
#define RDOFF_DATA 1
#define RDOFF_HEADER -1
/* mask for 'segment' in relocation records to find if relative relocation */
#define RDOFF_RELATIVEMASK 64
/* mask to find actual segment value in relocation records */
#define RDOFF_SEGMENTMASK 63
extern int rdf_errno;
/* rdf_errno can hold these error codes */
enum {
/* 0 */ RDF_OK,
/* 1 */ RDF_ERR_OPEN,
/* 2 */ RDF_ERR_FORMAT,
/* 3 */ RDF_ERR_READ,
/* 4 */ RDF_ERR_UNKNOWN,
/* 5 */ RDF_ERR_HEADER,
/* 6 */ RDF_ERR_NOMEM,
/* 7 */ RDF_ERR_VER,
/* 8 */ RDF_ERR_RECTYPE,
/* 9 */ RDF_ERR_RECLEN,
/* 10 */ RDF_ERR_SEGMENT
};
/* library init */
void rdoff_init(void);
/* utility functions */
int32_t translateint32_t(int32_t in);
uint16_t translateint16_t(uint16_t in);
char *translatesegmenttype(uint16_t type);
/* RDOFF file manipulation functions */
int rdfopen(rdffile * f, const char *name);
int rdfopenhere(rdffile * f, FILE * fp, int *refcount, const char *name);
int rdfclose(rdffile * f);
int rdffindsegment(rdffile * f, int segno);
int rdfloadseg(rdffile * f, int segment, void *buffer);
rdfheaderrec *rdfgetheaderrec(rdffile * f); /* returns static storage */
void rdfheaderrewind(rdffile * f); /* back to start of header */
void rdfperror(const char *app, const char *name);
/* functions to write a new RDOFF header to a file -
use rdfnewheader to allocate a header, rdfaddheader to add records to it,
rdfaddsegment to notify the header routines that a segment exists, and
to tell it how int32_t the segment will be.
rdfwriteheader to write the file id, object length, and header
to a file, and then rdfdoneheader to dispose of the header */
rdf_headerbuf *rdfnewheader(void);
int rdfaddheader(rdf_headerbuf * h, rdfheaderrec * r);
int rdfaddsegment(rdf_headerbuf * h, int32_t seglength);
int rdfwriteheader(FILE * fp, rdf_headerbuf * h);
void rdfdoneheader(rdf_headerbuf * h);
#endif /* RDOFF_RDFUTILS_H */

View file

@ -1,491 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 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.
*
* ----------------------------------------------------------------------- */
/*
* rdlar.c - new librarian/archiver for RDOFF2.
*/
#include "compiler.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rdlar.h"
#define PROGRAM_VERSION "0.1"
/** Constants **/
const char commands[] = "adnrtx";
const char modifiers[] = "cflouvV";
/** Global variables **/
char *progname = "rdlar";
char **_argv = NULL;
struct {
bool createok;
bool usefname;
bool align;
bool odate;
bool fresh;
int verbose;
} options = {
0, 0, 0, 0, 0, 0};
#define _ENDIANNESS 0 /* 0 for little, 1 for big */
/*
* Convert int32_t to little endian (if we were compiled on big-endian machine)
*/
static void int32_ttolocal(int32_t *l)
{
#if _ENDIANNESS
uint8_t t;
uint8_t *p = (uint8_t *)l;
t = p[0];
p[0] = p[3];
p[3] = t;
t = p[1];
p[1] = p[2];
p[2] = p[1];
#endif
}
/*
* Print version information
*/
void show_version(void)
{
puts("New RDOFF2 librarian/archiver, version " PROGRAM_VERSION);
}
/*
* Print usage instructions
*/
void usage(void)
{
printf("Usage: %s [-]{%s}[%s] libfile [module-name] [files]\n",
progname, commands, modifiers);
puts(" commands:\n"
" a - add module(s) to the library\n"
" d - delete module(s) from the library\n"
" n - create the library\n"
" r - replace module(s)\n"
" t - display contents of library\n"
" x - extract module(s)\n"
" command specific modifiers:\n"
" o - preserve original dates\n"
" u - only replace modules that are newer than library contents\n"
" generic modifiers:\n"
" c - do not warn if the library had to be created\n"
" f - use file name as a module name\n"
" v - be verbose\n"
" V - display version information");
}
/*
* Print an error message and exit
*/
void error_exit(int errcode, bool useperror, const char *fmt, ...)
{
va_list ap;
fprintf(stderr, "%s: ", progname);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
putc('\n', stderr);
if (useperror)
perror(progname);
exit(errcode);
}
/*
* Fill in and write a header
*/
void put_header(struct rdlm_hdr *hdr, FILE * libfp, char *modname)
{
int n = 0;
hdr->hdrsize = sizeof(*hdr);
if (modname)
hdr->hdrsize += (n = strlen(modname) + 1);
if (libfp == NULL)
return;
if (fwrite(hdr, 1, sizeof(*hdr), libfp) != sizeof(*hdr) ||
(modname && (fwrite(modname, 1, n, libfp) != n)))
error_exit(3, true, "could not write header");
}
/*
* Copy n bytes from one file to another and return last character read.
*/
char copybytes(FILE * fp, FILE * fp2, int n)
{
int i, t = 0;
for (i = 0; i < n; i++) {
t = fgetc(fp);
if (t == EOF)
error_exit(1, false, "premature end of file in '%s'",
_argv[2]);
if (fp2)
if (fputc(t, fp2) == EOF)
error_exit(1, false, "write error");
}
return (char)t;
}
/*
* Copy uint32_t from one file to another.
* Return local presentation of int32_t.
*/
int32_t copyint32_t(FILE * fp, FILE * fp2)
{
int32_t l;
int i, t;
uint8_t *p = (uint8_t *)&l;
for (i = 0; i < 4; i++) {
t = fgetc(fp);
if (t == EOF)
error_exit(1, false, "premature end of file in '%s'",
_argv[2]);
if (fp2)
if (fputc(t, fp2) == EOF)
error_exit(1, false, "write error");
*p++ = t;
}
int32_ttolocal(&l);
return l;
}
/*
* Create a new library
*/
int create_library(char *libname)
{
FILE *libfp;
struct rdlm_hdr hdr;
hdr.magic = RDLAMAG;
hdr.hdrsize = 0;
hdr.date = time(NULL);
hdr.owner = getuid();
hdr.group = getgid();
hdr.mode = umask(022);
hdr.size = 0;
libfp = fopen(libname, "wb");
if (!libfp)
error_exit(1, true, "could not open '%s'\n", libname);
/* Write library header */
put_header(&hdr, libfp, NULL);
fclose(libfp);
return true;
}
/*
* Add a module to the library
*/
int add_module(FILE * libfp, const char *fname, char *modname)
{
FILE *modfp;
struct rdlm_hdr hdr = { RDLMMAG, 0, 0, 0, 0, 0, 0 };
struct stat finfo;
int i;
if (options.verbose)
fprintf(stderr, "adding module %s\n", modname);
/* Initialize some fields in the module header */
if (stat(fname, &finfo) < 0)
error_exit(1, true, "could not stat '%s'", fname);
hdr.date = finfo.st_mtime;
hdr.owner = finfo.st_uid;
hdr.group = finfo.st_gid;
hdr.size = finfo.st_size;
modfp = fopen(fname, "rb");
if (!modfp)
error_exit(1, true, "could not open '%s'", fname);
/* Write module header */
put_header(&hdr, libfp, modname);
/* Put the module itself */
while (!feof(modfp)) {
i = fgetc(modfp);
if (i == EOF)
break;
if (fputc(i, libfp) == EOF)
error_exit(1, false, "write error");
}
fclose(modfp);
return true;
}
/*
* Main
*/
int main(int argc, char **argv)
{
FILE *libfp, *tmpfp, *modfp = NULL;
struct stat finfo;
struct rdlm_hdr hdr;
char buf[MAXMODNAMELEN], *p = NULL;
char c;
int i;
progname = argv[0];
_argv = argv;
if (argc < 2) {
usage();
exit(1);
}
rdoff_init();
/* Check whether some modifiers were specified */
for (i = 1; i < strlen(argv[1]); i++) {
switch (c = argv[1][i]) {
case 'c':
options.createok = true;
break;
case 'f':
options.usefname = true;
break;
case 'l':
options.align = true;
break;
case 'o':
options.odate = true;
break;
case 'u':
options.fresh = true;
break;
case 'v':
options.verbose++;
break;
case 'V':
show_version();
exit(0);
default:
if (strchr(commands, c) == NULL)
error_exit(2, false, "invalid command or modifier '%c'",
c);
}
}
if (argc < 3)
error_exit(2, false, "missing library name");
/* Process the command */
if (argv[1][0] == '-')
argv[1]++;
switch (c = argv[1][0]) {
case 'a': /* add a module */
if (argc < 4 || (!options.usefname && argc != 5))
error_exit(2, false, "invalid number of arguments");
/* Check if a library already exists. If not - create it */
if (access(argv[2], F_OK) < 0) {
if (!options.createok)
fprintf(stderr, "creating library %s\n", argv[2]);
create_library(argv[2]);
}
libfp = fopen(argv[2], "ab");
if (!libfp)
error_exit(1, true, "could not open '%s'", argv[2]);
if (!options.usefname)
add_module(libfp, argv[4], argv[3]);
else
for (i = 3; i < argc; i++)
add_module(libfp, argv[i], argv[i]);
fclose(libfp);
break;
case 'n': /* create library */
create_library(argv[2]);
break;
case 'x': /* extract module(s) */
if (!options.usefname)
argc--;
if (argc < 4)
error_exit(2, false, "required parameter missing");
p = options.usefname ? argv[3] : argv[4];
case 't': /* list library contents */
libfp = fopen(argv[2], "rb");
if (!libfp)
error_exit(1, true, "could not open '%s'\n", argv[2]);
/* Read library header */
if (fread(&hdr, 1, sizeof(hdr), libfp) != sizeof(hdr) ||
hdr.magic != RDLAMAG)
error_exit(1, false, "invalid library format");
/* Walk through the library looking for requested module */
while (!feof(libfp)) {
/* Read module header */
i = fread(&hdr, 1, sizeof(hdr), libfp);
if (feof(libfp))
break;
if (i != sizeof(hdr) || hdr.magic != RDLMMAG)
error_exit(1, false, "invalid module header");
/* Read module name */
i = hdr.hdrsize - sizeof(hdr);
if (i > sizeof(buf) || fread(buf, 1, i, libfp) != i)
error_exit(1, false, "invalid module name");
if (c == 'x') {
/* Check against desired name */
if (!strcmp(buf, argv[3])) {
if (options.verbose)
fprintf(stderr,
"extracting module %s to file %s\n", buf,
p);
modfp = fopen(p, "wb");
if (!modfp)
error_exit(1, true, "could not open '%s'", p);
}
} else {
printf("%-40s ", buf);
if (options.verbose) {
printf("%ld bytes", hdr.size);
}
putchar('\n');
}
copybytes(libfp, modfp, hdr.size);
if (modfp)
break;
}
fclose(libfp);
if (modfp)
fclose(modfp);
else if (c == 'x')
error_exit(1, false, "module '%s' not found in '%s'",
argv[3], argv[2]);
break;
case 'r': /* replace module(s) */
argc--;
if (stat(argv[4], &finfo) < 0)
error_exit(1, true, "could not stat '%s'", argv[4]);
case 'd': /* delete module(s) */
if (argc < 4)
error_exit(2, false, "required parameter missing");
libfp = fopen(argv[2], "rb");
if (!libfp)
error_exit(1, true, "could not open '%s'", argv[2]);
/* Copy the library into a temporary file */
tmpfp = tmpfile();
if (!tmpfp)
error_exit(1, true, "could not open temporary file");
stat(argv[2], &finfo);
copybytes(libfp, tmpfp, finfo.st_size);
rewind(tmpfp);
freopen(argv[2], "wb", libfp);
/* Read library header and write it to a new file */
if (fread(&hdr, 1, sizeof(hdr), tmpfp) != sizeof(hdr) ||
hdr.magic != RDLAMAG)
error_exit(1, false, "invalid library format");
put_header(&hdr, libfp, NULL);
/* Walk through the library looking for requested module */
while (!feof(tmpfp)) {
/* Read module header */
if (fread(&hdr, 1, sizeof(hdr), tmpfp) != sizeof(hdr) ||
hdr.magic != RDLMMAG)
error_exit(1, false, "invalid module header");
/* Read module name */
i = hdr.hdrsize - sizeof(hdr);
if (i > sizeof(buf) || fread(buf, 1, i, tmpfp) != i)
error_exit(1, false, "invalid module name");
/* Check against desired name */
if (!strcmp(buf, argv[3]) &&
(c == 'd' || !options.odate
|| finfo.st_mtime <= hdr.date)) {
if (options.verbose)
fprintf(stderr, "deleting module %s\n", buf);
fseek(tmpfp, hdr.size, SEEK_CUR);
break;
} else {
put_header(&hdr, libfp, buf);
copybytes(tmpfp, libfp, hdr.size);
}
}
if (c == 'r') {
/* Copy new module into library */
p = options.usefname ? argv[4] : argv[3];
add_module(libfp, argv[4], p);
}
/* Copy rest of library if any */
while (!feof(tmpfp)) {
if ((i = fgetc(tmpfp)) == EOF)
break;
if (fputc(i, libfp) == EOF)
error_exit(1, false, "write error");
}
fclose(libfp);
fclose(tmpfp);
break;
default:
error_exit(2, false, "invalid command '%c'\n", c);
}
return 0;
}

View file

@ -1,34 +0,0 @@
/*
* rdlar.h - definitions of new RDOFF library/archive format.
*/
#ifndef RDOFF_RDLAR_H
#define RDOFF_RDLAR_H 1
#include "compiler.h"
/* For non-POSIX operating systems */
#ifndef HAVE_GETUID
# define getuid() 0
#endif
#ifndef HAVE_GETGID
# define getgid() 0
#endif
#define RDLAMAG 0x414C4452 /* Archive magic */
#define RDLMMAG 0x4D4C4452 /* Member magic */
#define MAXMODNAMELEN 256 /* Maximum length of module name */
struct rdlm_hdr {
uint32_t magic; /* Must be RDLAMAG */
uint32_t hdrsize; /* Header size + sizeof(module_name) */
uint32_t date; /* Creation date */
uint32_t owner; /* UID */
uint32_t group; /* GID */
uint32_t mode; /* File mode */
uint32_t size; /* File size */
/* NULL-terminated module name immediately follows */
};
#endif

View file

@ -1,289 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2014 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.
*
* ----------------------------------------------------------------------- */
/*
* rdlib.c - routines for manipulating RDOFF libraries (.rdl)
*/
#include "compiler.h"
#include <stdio.h>
#include <stdlib.h>
#include "rdfutils.h"
#include "rdlib.h"
#include "rdlar.h"
/* See Texinfo documentation about new RDOFF libraries format */
int rdl_error = 0;
char *rdl_errors[5] = {
"no error", "could not open file", "invalid file structure",
"file contains modules of an unsupported RDOFF version",
"module not found"
};
int rdl_verify(const char *filename)
{
FILE *fp;
char buf[257];
int i;
int32_t length;
static char lastverified[256];
static int lastresult = -1;
if (lastresult != -1 && !strcmp(filename, lastverified))
return lastresult;
fp = fopen(filename, "rb");
strcpy(lastverified, filename);
if (!fp)
return (rdl_error = lastresult = 1);
while (!feof(fp)) {
i = 0;
while (fread(buf + i, 1, 1, fp) == 1 && i < 257 && buf[i])
i++;
if (feof(fp))
break;
if (buf[0] == '.') {
/*
* A special module, eg a signature block or a directory.
* Format of such a module is defined to be:
* six char type identifier
* int32_t count bytes content
* content
* so we can handle it uniformaly with RDOFF2 modules.
*/
nasm_read(buf, 6, fp);
buf[6] = 0;
/* Currently, nothing useful to do with signature block.. */
} else {
nasm_read(buf, 6, fp);
buf[6] = 0;
if (strncmp(buf, "RDOFF", 5)) {
fclose(fp);
return rdl_error = lastresult = 2;
} else if (buf[5] != '2') {
fclose(fp);
return rdl_error = lastresult = 3;
}
}
nasm_read(&length, 4, fp);
fseek(fp, length, SEEK_CUR); /* skip over the module */
}
fclose(fp);
return lastresult = 0; /* library in correct format */
}
int rdl_open(struct librarynode *lib, const char *name)
{
int i = rdl_verify(name);
if (i)
return i;
lib->fp = NULL;
lib->name = nasm_strdup(name);
lib->referenced = 0;
lib->next = NULL;
return 0;
}
int rdl_searchlib(struct librarynode *lib, const char *label, rdffile * f)
{
char buf[512];
int i, t;
void *hdr;
rdfheaderrec *r;
int32_t l;
rdl_error = 0;
lib->referenced++;
if (!lib->fp) {
lib->fp = fopen(lib->name, "rb");
if (!lib->fp) {
rdl_error = 1;
return 0;
}
} else
rewind(lib->fp);
while (!feof(lib->fp)) {
/*
* read the module name from the file, and prepend
* the library name and '.' to it.
*/
strcpy(buf, lib->name);
i = strlen(lib->name);
buf[i++] = '.';
t = i;
while (fread(buf + i, 1, 1, lib->fp) == 1 && i < 512 && buf[i])
i++;
buf[i] = 0;
if (feof(lib->fp))
break;
if (!strcmp(buf + t, ".dir")) { /* skip over directory */
nasm_read(&l, 4, lib->fp);
fseek(lib->fp, l, SEEK_CUR);
continue;
}
/*
* open the RDOFF module
*/
if (rdfopenhere(f, lib->fp, &lib->referenced, buf)) {
rdl_error = 16 * rdf_errno;
return 0;
}
/*
* read in the header, and scan for exported symbols
*/
hdr = nasm_malloc(f->header_len);
rdfloadseg(f, RDOFF_HEADER, hdr);
while ((r = rdfgetheaderrec(f))) {
if (r->type != 3) /* not an export */
continue;
if (!strcmp(r->e.label, label)) { /* match! */
nasm_free(hdr); /* reset to 'just open' */
f->header_loc = NULL; /* state... */
f->header_fp = 0;
return 1;
}
}
/* find start of next module... */
i = f->eof_offset;
rdfclose(f);
fseek(lib->fp, i, SEEK_SET);
}
/*
* close the file if nobody else is using it
*/
lib->referenced--;
if (!lib->referenced) {
fclose(lib->fp);
lib->fp = NULL;
}
return 0;
}
int rdl_openmodule(struct librarynode *lib, int moduleno, rdffile * f)
{
char buf[512];
int i, cmod, t;
int32_t length;
lib->referenced++;
if (!lib->fp) {
lib->fp = fopen(lib->name, "rb");
if (!lib->fp) {
lib->referenced--;
return (rdl_error = 1);
}
} else
rewind(lib->fp);
cmod = -1;
while (!feof(lib->fp)) {
strcpy(buf, lib->name);
i = strlen(buf);
buf[i++] = '.';
t = i;
while (fread(buf + i, 1, 1, lib->fp) == 1 && i < 512 && buf[i])
i++;
buf[i] = 0;
if (feof(lib->fp))
break;
if (buf[t] != '.') /* special module - not counted in the numbering */
cmod++; /* of RDOFF modules - must be referred to by name */
if (cmod == moduleno) {
rdl_error = 16 *
rdfopenhere(f, lib->fp, &lib->referenced, buf);
lib->referenced--;
if (!lib->referenced) {
fclose(lib->fp);
lib->fp = NULL;
}
return rdl_error;
}
nasm_read(buf, 6, lib->fp);
buf[6] = 0;
if (buf[t] == '.') {
/* do nothing */
} else if (strncmp(buf, "RDOFF", 5)) {
if (!--lib->referenced) {
fclose(lib->fp);
lib->fp = NULL;
}
return rdl_error = 2;
} else if (buf[5] != '2') {
if (!--lib->referenced) {
fclose(lib->fp);
lib->fp = NULL;
}
return rdl_error = 3;
}
nasm_read(&length, 4, lib->fp);
fseek(lib->fp, length, SEEK_CUR); /* skip over the module */
}
if (!--lib->referenced) {
fclose(lib->fp);
lib->fp = NULL;
}
return rdl_error = 4; /* module not found */
}
void rdl_perror(const char *apname, const char *filename)
{
if (rdl_error >= 16)
rdfperror(apname, filename);
else
fprintf(stderr, "%s:%s:%s\n", apname, filename,
rdl_errors[rdl_error]);
}

View file

@ -1,62 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 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.
*
* ----------------------------------------------------------------------- */
/*
* rdlib.h Functions for manipulating libraries of RDOFF object files.
*/
#ifndef RDOFF_RDLIB_H
#define RDOFF_RDLIB_H 1
struct librarynode {
char *name;
FILE *fp; /* initialised to NULL - always check */
int referenced; /* & open if required. Close afterwards */
struct librarynode *next; /* if ! referenced. */
};
extern int rdl_error;
#define RDL_EOPEN 1
#define RDL_EINVALID 2
#define RDL_EVERSION 3
#define RDL_ENOTFOUND 4
int rdl_verify(const char *filename);
int rdl_open(struct librarynode *lib, const char *filename);
int rdl_searchlib(struct librarynode *lib, const char *label, rdffile * f);
int rdl_openmodule(struct librarynode *lib, int module, rdffile * f);
void rdl_perror(const char *apname, const char *filename);
#endif

View file

@ -1,627 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2014 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.
*
* ----------------------------------------------------------------------- */
/*
* rdoff.c library of routines for manipulating rdoff files
*/
/* TODO: The functions in this module assume they are running
* on a little-endian machine. This should be fixed to
* make it portable.
*/
#include "compiler.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "rdfutils.h"
/*
* Comment this out to allow the module to read & write header record types
* that it isn't aware of. With this defined, unrecognised header records
* will generate error number 8, reported as 'unknown extended header record'.
*/
#define STRICT_ERRORS
/* ========================================================================
* Code for memory buffers (for delayed writing of header until we know
* how int32_t it is).
* ======================================================================== */
static memorybuffer *newmembuf(void)
{
memorybuffer *t;
t = nasm_malloc(sizeof(memorybuffer));
if (!t)
return NULL;
t->length = 0;
t->next = NULL;
return t;
}
static void membufwrite(memorybuffer * const b, void *data, int bytes)
{
uint16_t w;
int32_t l;
char *c;
if (b->next) { /* memory buffer full - use next buffer */
membufwrite(b->next, data, bytes);
return;
}
if ((bytes < 0 && b->length - bytes > BUF_BLOCK_LEN)
|| (bytes > 0 && b->length + bytes > BUF_BLOCK_LEN)) {
/* buffer full and no next allocated... allocate and initialise next
* buffer */
b->next = newmembuf();
membufwrite(b->next, data, bytes);
return;
}
switch (bytes) {
case -4: /* convert to little-endian */
l = *(int32_t *)data;
b->buffer[b->length++] = l & 0xFF;
l >>= 8;
b->buffer[b->length++] = l & 0xFF;
l >>= 8;
b->buffer[b->length++] = l & 0xFF;
l >>= 8;
b->buffer[b->length++] = l & 0xFF;
break;
case -2:
w = *(uint16_t *) data;
b->buffer[b->length++] = w & 0xFF;
w >>= 8;
b->buffer[b->length++] = w & 0xFF;
break;
default:
c = data;
while (bytes--)
b->buffer[b->length++] = *c++;
break;
}
}
static void membufdump(memorybuffer * b, FILE * fp)
{
if (!b)
return;
nasm_write(b->buffer, b->length, fp);
membufdump(b->next, fp);
}
static int membuflength(memorybuffer * b)
{
if (!b)
return 0;
return b->length + membuflength(b->next);
}
static void freemembuf(memorybuffer * b)
{
if (!b)
return;
freemembuf(b->next);
nasm_free(b);
}
/* =========================================================================
General purpose routines and variables used by the library functions
========================================================================= */
/*
* translateint32_t() and translateint16_t()
*
* translate from little endian to local representation
*/
int32_t translateint32_t(int32_t in)
{
int32_t r;
uint8_t *i;
i = (uint8_t *)&in;
r = i[3];
r = (r << 8) + i[2];
r = (r << 8) + i[1];
r = (r << 8) + *i;
return r;
}
uint16_t translateint16_t(uint16_t in)
{
uint16_t r;
uint8_t *i;
i = (uint8_t *)&in;
r = (i[1] << 8) + i[0];
return r;
}
/* Segment types */
static char *knownsegtypes[8] = {
"NULL", "text", "data", "object comment",
"linked comment", "loader comment",
"symbolic debug", "line number debug"
};
/* Get a textual string describing the segment type */
char *translatesegmenttype(uint16_t type)
{
if (type < 8)
return knownsegtypes[type];
if (type < 0x0020)
return "reserved";
if (type < 0x1000)
return "reserved - Moscow";
if (type < 0x8000)
return "reserved - system dependent";
if (type < 0xFFFF)
return "reserved - other";
if (type == 0xFFFF)
return "invalid type code";
return "type code out of range";
}
/* This signature is written to the start of RDOFF files */
const char *RDOFFId = RDOFF2_SIGNATURE;
/* Error messages. Must correspond to the codes defined in rdoff.h */
const char *rdf_errors[11] = {
/* 0 */ "no error occurred",
/* 1 */ "could not open file",
/* 2 */ "invalid file format",
/* 3 */ "error reading file",
/* 4 */ "unknown error",
/* 5 */ "header not read",
/* 6 */ "out of memory",
/* 7 */ "RDOFF v1 not supported",
/* 8 */ "unknown extended header record",
/* 9 */ "header record of known type but unknown length",
/* 10 */ "no such segment"
};
int rdf_errno = 0;
/* ========================================================================
* Hook for nasm_error() to work
* ======================================================================== */
void nasm_verror(errflags severity, const char *fmt, va_list val)
{
severity &= ERR_MASK;
vfprintf(stderr, fmt, val);
if (severity >= ERR_FATAL)
exit(severity - ERR_FATAL + 1);
}
fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list val)
{
nasm_verror(severity, fmt, val);
abort();
}
void rdoff_init(void)
{
}
/* ========================================================================
The library functions
======================================================================== */
int rdfopen(rdffile * f, const char *name)
{
FILE *fp;
fp = fopen(name, "rb");
if (!fp)
return rdf_errno = RDF_ERR_OPEN;
return rdfopenhere(f, fp, NULL, name);
}
int rdfopenhere(rdffile * f, FILE * fp, int *refcount, const char *name)
{
char buf[8];
int32_t initpos;
int32_t l;
uint16_t s;
if (translateint32_t(0x01020304) != 0x01020304) {
/* fix this to be portable! */
fputs("*** this program requires a little endian machine\n",
stderr);
fprintf(stderr, "01020304h = %08"PRIx32"h\n", translateint32_t(0x01020304));
exit(3);
}
f->fp = fp;
initpos = ftell(fp);
/* read header */
if (fread(buf, 1, 6, f->fp) != 6) {
fclose(f->fp);
return rdf_errno = RDF_ERR_READ;
}
buf[6] = 0;
if (strcmp(buf, RDOFFId)) {
fclose(f->fp);
if (!strcmp(buf, "RDOFF1"))
return rdf_errno = RDF_ERR_VER;
return rdf_errno = RDF_ERR_FORMAT;
}
if (fread(&l, 1, 4, f->fp) != 4
|| fread(&f->header_len, 1, 4, f->fp) != 4) {
fclose(f->fp);
return rdf_errno = RDF_ERR_READ;
}
f->header_ofs = ftell(f->fp);
f->eof_offset = f->header_ofs + translateint32_t(l) - 4;
if (fseek(f->fp, f->header_len, SEEK_CUR)) {
fclose(f->fp);
return rdf_errno = RDF_ERR_FORMAT; /* seek past end of file...? */
}
if (fread(&s, 1, 2, f->fp) != 2) {
fclose(f->fp);
return rdf_errno = RDF_ERR_READ;
}
f->nsegs = 0;
while (s != 0) {
f->seg[f->nsegs].type = s;
if (fread(&f->seg[f->nsegs].number, 1, 2, f->fp) != 2 ||
fread(&f->seg[f->nsegs].reserved, 1, 2, f->fp) != 2 ||
fread(&f->seg[f->nsegs].length, 1, 4, f->fp) != 4) {
fclose(f->fp);
return rdf_errno = RDF_ERR_READ;
}
f->seg[f->nsegs].offset = ftell(f->fp);
if (fseek(f->fp, f->seg[f->nsegs].length, SEEK_CUR)) {
fclose(f->fp);
return rdf_errno = RDF_ERR_FORMAT;
}
f->nsegs++;
if (fread(&s, 1, 2, f->fp) != 2) {
fclose(f->fp);
return rdf_errno = RDF_ERR_READ;
}
}
if (f->eof_offset != ftell(f->fp) + 8) { /* +8 = skip null segment header */
fprintf(stderr, "warning: eof_offset [%"PRId32"] and actual eof offset "
"[%ld] don't match\n", f->eof_offset, ftell(f->fp) + 8);
}
fseek(f->fp, initpos, SEEK_SET);
f->header_loc = NULL;
f->name = nasm_strdup(name);
f->refcount = refcount;
if (refcount)
(*refcount)++;
return RDF_OK;
}
int rdfclose(rdffile * f)
{
if (!f->refcount || !--(*f->refcount)) {
fclose(f->fp);
f->fp = NULL;
}
nasm_free(f->name);
return 0;
}
/*
* Print the message for last error (from rdf_errno)
*/
void rdfperror(const char *app, const char *name)
{
fprintf(stderr, "%s:%s: %s\n", app, name, rdf_errors[rdf_errno]);
if (rdf_errno == RDF_ERR_OPEN || rdf_errno == RDF_ERR_READ) {
perror(app);
}
}
/*
* Find the segment by its number.
* Returns segment array index, or -1 if segment with such number was not found.
*/
int rdffindsegment(rdffile * f, int segno)
{
int i;
for (i = 0; i < f->nsegs; i++)
if (f->seg[i].number == segno)
return i;
return -1;
}
/*
* Load the segment. Returns status.
*/
int rdfloadseg(rdffile * f, int segment, void *buffer)
{
int32_t fpos;
size_t slen;
switch (segment) {
case RDOFF_HEADER:
fpos = f->header_ofs;
slen = f->header_len;
f->header_loc = (uint8_t *) buffer;
f->header_fp = 0;
break;
default:
if (segment < f->nsegs) {
fpos = f->seg[segment].offset;
slen = f->seg[segment].length;
f->seg[segment].data = (uint8_t *) buffer;
} else {
return rdf_errno = RDF_ERR_SEGMENT;
}
}
if (fseek(f->fp, fpos, SEEK_SET))
return rdf_errno = RDF_ERR_UNKNOWN;
if (fread(buffer, 1, slen, f->fp) != slen)
return rdf_errno = RDF_ERR_READ;
return RDF_OK;
}
/* Macros for reading integers from header in memory */
#define RI8(v) v = f->header_loc[f->header_fp++]
#define RI16(v) { v = (f->header_loc[f->header_fp] + \
(f->header_loc[f->header_fp+1] << 8)); \
f->header_fp += 2; }
#define RI32(v) { v = (f->header_loc[f->header_fp] + \
(f->header_loc[f->header_fp+1] << 8) + \
(f->header_loc[f->header_fp+2] << 16) + \
(f->header_loc[f->header_fp+3] << 24)); \
f->header_fp += 4; }
#define RS(str,max) { for(i=0;i<max;i++){\
RI8(str[i]); if (!str[i]) break;} str[i]=0; }
/*
* Read a header record.
* Returns the address of record, or NULL in case of error.
*/
rdfheaderrec *rdfgetheaderrec(rdffile * f)
{
static rdfheaderrec r;
int i;
if (!f->header_loc) {
rdf_errno = RDF_ERR_HEADER;
return NULL;
}
if (f->header_fp >= f->header_len)
return 0;
RI8(r.type);
RI8(r.g.reclen);
switch (r.type) {
case RDFREC_RELOC: /* Relocation record */
case RDFREC_SEGRELOC:
if (r.r.reclen != 8) {
rdf_errno = RDF_ERR_RECLEN;
return NULL;
}
RI8(r.r.segment);
RI32(r.r.offset);
RI8(r.r.length);
RI16(r.r.refseg);
break;
case RDFREC_IMPORT: /* Imported symbol record */
case RDFREC_FARIMPORT:
RI8(r.i.flags);
RI16(r.i.segment);
RS(r.i.label, EXIM_LABEL_MAX);
break;
case RDFREC_GLOBAL: /* Exported symbol record */
RI8(r.e.flags);
RI8(r.e.segment);
RI32(r.e.offset);
RS(r.e.label, EXIM_LABEL_MAX);
break;
case RDFREC_DLL: /* DLL record */
RS(r.d.libname, MODLIB_NAME_MAX);
break;
case RDFREC_BSS: /* BSS reservation record */
if (r.r.reclen != 4) {
rdf_errno = RDF_ERR_RECLEN;
return NULL;
}
RI32(r.b.amount);
break;
case RDFREC_MODNAME: /* Module name record */
RS(r.m.modname, MODLIB_NAME_MAX);
break;
case RDFREC_COMMON: /* Common variable */
RI16(r.c.segment);
RI32(r.c.size);
RI16(r.c.align);
RS(r.c.label, EXIM_LABEL_MAX);
break;
default:
#ifdef STRICT_ERRORS
rdf_errno = RDF_ERR_RECTYPE; /* unknown header record */
return NULL;
#else
for (i = 0; i < r.g.reclen; i++)
RI8(r.g.data[i]);
#endif
}
return &r;
}
/*
* Rewind to the beginning of the file
*/
void rdfheaderrewind(rdffile * f)
{
f->header_fp = 0;
}
rdf_headerbuf *rdfnewheader(void)
{
rdf_headerbuf *hb = nasm_malloc(sizeof(rdf_headerbuf));
if (hb == NULL)
return NULL;
hb->buf = newmembuf();
hb->nsegments = 0;
hb->seglength = 0;
return hb;
}
int rdfaddheader(rdf_headerbuf * h, rdfheaderrec * r)
{
#ifndef STRICT_ERRORS
int i;
#endif
membufwrite(h->buf, &r->type, 1);
membufwrite(h->buf, &r->g.reclen, 1);
switch (r->type) {
case RDFREC_GENERIC: /* generic */
membufwrite(h->buf, &r->g.data, r->g.reclen);
break;
case RDFREC_RELOC:
case RDFREC_SEGRELOC:
membufwrite(h->buf, &r->r.segment, 1);
membufwrite(h->buf, &r->r.offset, -4);
membufwrite(h->buf, &r->r.length, 1);
membufwrite(h->buf, &r->r.refseg, -2); /* 9 bytes written */
break;
case RDFREC_IMPORT: /* import */
case RDFREC_FARIMPORT:
membufwrite(h->buf, &r->i.flags, 1);
membufwrite(h->buf, &r->i.segment, -2);
membufwrite(h->buf, &r->i.label, strlen(r->i.label) + 1);
break;
case RDFREC_GLOBAL: /* export */
membufwrite(h->buf, &r->e.flags, 1);
membufwrite(h->buf, &r->e.segment, 1);
membufwrite(h->buf, &r->e.offset, -4);
membufwrite(h->buf, &r->e.label, strlen(r->e.label) + 1);
break;
case RDFREC_DLL: /* DLL */
membufwrite(h->buf, &r->d.libname, strlen(r->d.libname) + 1);
break;
case RDFREC_BSS: /* BSS */
membufwrite(h->buf, &r->b.amount, -4);
break;
case RDFREC_MODNAME: /* Module name */
membufwrite(h->buf, &r->m.modname, strlen(r->m.modname) + 1);
break;
default:
#ifdef STRICT_ERRORS
return rdf_errno = RDF_ERR_RECTYPE;
#else
for (i = 0; i < r->g.reclen; i++)
membufwrite(h->buf, r->g.data[i], 1);
#endif
}
return 0;
}
int rdfaddsegment(rdf_headerbuf * h, int32_t seglength)
{
h->nsegments++;
h->seglength += seglength;
return 0;
}
int rdfwriteheader(FILE * fp, rdf_headerbuf * h)
{
int32_t l, l2;
nasm_write(RDOFFId, strlen(RDOFFId), fp);
l = membuflength(h->buf);
l2 = l + 14 + 10 * h->nsegments + h->seglength;
fwriteint32_t(l2, fp); /* object length */
fwriteint32_t(l, fp); /* header length */
membufdump(h->buf, fp);
return 0; /* no error handling in here... CHANGE THIS! */
}
void rdfdoneheader(rdf_headerbuf * h)
{
freemembuf(h->buf);
nasm_free(h);
}

View file

@ -1,21 +0,0 @@
.TH RDX 1 "September 6, 1999" "Debian Project" "Debian Manual"
.SH NAME
rdx \- load and execute an RDOFF object
.SH SYNOPSIS
.B rdx
.I object
.SH DESCRIPTION
.B rdx
loads an RDOFF
.IR object ,
and then calls
.RB ` _main ',
which it expects to be a C-style function, accepting two parameters,
.I argc
and
.I argv
in normal C style.
.SH AUTHORS
Julian Hall <jules@earthcorp.com>.
.PP
This manual page was written by Matej Vela <vela@debian.org>.

View file

@ -1,90 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 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.
*
* ----------------------------------------------------------------------- */
/*
* rdx.c RDOFF Object File loader program
*/
/* note: most of the actual work of this program is done by the modules
"rdfload.c", which loads and relocates the object file, and by "rdoff.c",
which contains general purpose routines to manipulate RDOFF object
files. You can use these files in your own program to load RDOFF objects
and execute the code in them in a similar way to what is shown here. */
#include "compiler.h"
#include <stdio.h>
#include <stdlib.h>
#include "rdfload.h"
#include "symtab.h"
typedef int (*main_fn) (int, char **); /* Main function prototype */
int main(int argc, char **argv)
{
rdfmodule *m;
main_fn code;
symtabEnt *s;
if (argc < 2) {
puts("usage: rdx <rdoff-executable> [params]\n");
exit(255);
}
rdoff_init();
m = rdfload(argv[1]);
if (!m) {
rdfperror("rdx", argv[1]);
exit(255);
}
rdf_relocate(m); /* in this instance, the default relocation
values will work fine, but they may need changing
in other cases... */
s = symtabFind(m->symtab, "_main");
if (!s) {
fprintf(stderr, "rdx: could not find symbol '_main' in '%s'\n",
argv[1]);
exit(255);
}
code = (main_fn)(size_t) s->offset;
argv++, argc--; /* remove 'rdx' from command line */
return code(argc, argv); /* execute */
}

View file

@ -1,172 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2014 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 "rdfutils.h"
#include "segtab.h"
struct segtabnode {
int localseg;
int destseg;
int32_t offset;
struct segtabnode *left;
struct segtabnode *right;
/*
* counts of how many are left or right, for use in reorganising
* the tree
*/
int leftcount;
int rightcount;
};
/*
* init_seglocations()
* add_seglocation()
* get_seglocation()
* done_seglocation()
*
* functions used by write_output() to manipulate associations
* between segment numbers and locations (which are built up on a per
* module basis, but we only need one module at a time...)
*
* implementation: we build a binary tree.
*/
void init_seglocations(segtab * root)
{
*root = NULL;
}
static void descend_tree_add(struct segtabnode **node,
int localseg, int destseg, int32_t offset)
{
struct segtabnode *n;
if (*node == NULL) {
*node = nasm_malloc(sizeof(**node));
if (!*node) {
fprintf(stderr, "segment table: out of memory\n");
exit(1);
}
(*node)->localseg = localseg;
(*node)->offset = offset;
(*node)->left = NULL;
(*node)->leftcount = 0;
(*node)->right = NULL;
(*node)->rightcount = 0;
(*node)->destseg = destseg;
return;
}
if (localseg < (*node)->localseg) {
(*node)->leftcount++;
descend_tree_add(&(*node)->left, localseg, destseg, offset);
if ((*node)->leftcount > (*node)->rightcount + 2) {
n = *node;
*node = n->left;
n->left = (*node)->right;
n->leftcount = (*node)->rightcount;
(*node)->right = n;
(*node)->rightcount = n->leftcount + n->rightcount + 1;
}
} else {
(*node)->rightcount++;
descend_tree_add(&(*node)->right, localseg, destseg, offset);
if ((*node)->rightcount > (*node)->leftcount + 2) {
n = *node;
*node = n->right;
n->right = (*node)->left;
n->rightcount = (*node)->leftcount;
(*node)->left = n;
(*node)->leftcount = n->leftcount + n->rightcount + 1;
}
}
}
void add_seglocation(segtab * root, int localseg, int destseg, int32_t offset)
{
descend_tree_add((struct segtabnode **)root, localseg, destseg,
offset);
}
int get_seglocation(segtab * root, int localseg, int *destseg,
int32_t *offset)
{
struct segtabnode *n = (struct segtabnode *)*root;
while (n && n->localseg != localseg) {
if (localseg < n->localseg)
n = n->left;
else
n = n->right;
}
if (n) {
*destseg = n->destseg;
*offset = n->offset;
return 1;
} else
return 0;
}
static void freenode(struct segtabnode *n)
{
if (!n)
return;
freenode(n->left);
freenode(n->right);
nasm_free(n);
}
void done_seglocations(segtab * root)
{
freenode(*root);
*root = NULL;
}
#if 0
void printnode(int i, struct segtabnode *n)
{
if (!n)
return;
printnode(i + 1, n->left);
printf("%*s%d %d %ld\n", i, "", n->localseg, n->destseg, n->offset);
printnode(i + 1, n->right);
}
void printtable()
{
printnode(0, root);
}
#endif

View file

@ -1,45 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 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 RDOFF_SEGTAB_H
#define RDOFF_SEGTAB_H 1
typedef void *segtab;
void init_seglocations(segtab * r);
void add_seglocation(segtab * r, int localseg, int destseg, int32_t offset);
int get_seglocation(segtab * r, int localseg, int *destseg, int32_t *offset);
void done_seglocations(segtab * r);
#endif

View file

@ -1,158 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 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.
*
* ----------------------------------------------------------------------- */
/*
* symtab.c Routines to maintain and manipulate a symbol table
*
* These routines donated to the NASM effort by Graeme Defty.
*/
#include "rdfutils.h"
#include <stdio.h>
#include <stdlib.h>
#include "symtab.h"
#include "hash.h"
#define SYMTABSIZE 64
#define slotnum(x) (hash((x)) % SYMTABSIZE)
/* ------------------------------------- */
/* Private data types */
typedef struct tagSymtabNode {
struct tagSymtabNode *next;
symtabEnt ent;
} symtabNode;
typedef symtabNode *(symtabTab[SYMTABSIZE]);
typedef symtabTab *symtab;
/* ------------------------------------- */
void *symtabNew(void)
{
symtab mytab;
mytab = (symtabTab *) nasm_calloc(SYMTABSIZE, sizeof(symtabNode *));
if (mytab == NULL) {
fprintf(stderr, "symtab: out of memory\n");
exit(3);
}
return mytab;
}
/* ------------------------------------- */
void symtabDone(void *stab)
{
symtab mytab = (symtab) stab;
int i;
symtabNode *this, *next;
for (i = 0; i < SYMTABSIZE; ++i) {
for (this = (*mytab)[i]; this; this = next) {
next = this->next;
nasm_free(this);
}
}
nasm_free(*mytab);
}
/* ------------------------------------- */
void symtabInsert(void *stab, symtabEnt * ent)
{
symtab mytab = (symtab) stab;
symtabNode *node;
int slot;
node = nasm_malloc(sizeof(symtabNode));
if (node == NULL) {
fprintf(stderr, "symtab: out of memory\n");
exit(3);
}
slot = slotnum(ent->name);
node->ent = *ent;
node->next = (*mytab)[slot];
(*mytab)[slot] = node;
}
/* ------------------------------------- */
symtabEnt *symtabFind(void *stab, const char *name)
{
symtab mytab = (symtab) stab;
int slot = slotnum(name);
symtabNode *node = (*mytab)[slot];
while (node) {
if (!strcmp(node->ent.name, name)) {
return &(node->ent);
}
node = node->next;
}
return NULL;
}
/* ------------------------------------- */
void symtabDump(void *stab, FILE * of)
{
symtab mytab = (symtab) stab;
int i;
char *SegNames[3] = { "code", "data", "bss" };
fprintf(of, "Symbol table is ...\n");
for (i = 0; i < SYMTABSIZE; ++i) {
symtabNode *l = (symtabNode *) (*mytab)[i];
if (l) {
fprintf(of, " ... slot %d ...\n", i);
}
while (l) {
if ((l->ent.segment) == -1) {
fprintf(of, "%-32s Unresolved reference\n", l->ent.name);
} else {
fprintf(of, "%-32s %s:%08"PRIx32" (%"PRId32")\n", l->ent.name,
SegNames[l->ent.segment],
l->ent.offset, l->ent.flags);
}
l = l->next;
}
}
fprintf(of, "........... end of Symbol table.\n");
}

View file

@ -1,55 +0,0 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 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.
*
* ----------------------------------------------------------------------- */
/*
* symtab.h Header file for symbol table manipulation routines
*/
#ifndef RDOFF_SYMTAB_H
#define RDOFF_SYMTAB_H 1
typedef struct {
char *name;
int segment;
int32_t offset;
int32_t flags;
} symtabEnt;
void *symtabNew(void);
void symtabDone(void *symtab);
void symtabInsert(void *symtab, symtabEnt * ent);
symtabEnt *symtabFind(void *symtab, const char *name);
void symtabDump(void *symtab, FILE * of);
#endif

View file

@ -1,10 +0,0 @@
RDT = $(patsubst %.asm,%.rdf,$(wildcard *.asm))
NASM = ../../nasm
all: $(RDT)
%.rdf: %.asm
$(NASM) -f rdf -o $@ -l $*.lst $<
clean:
rm -f *.rdf *.rdx *.lst

View file

@ -1,14 +0,0 @@
#! /bin/sh
[ $1 ] || {
echo "Usage: $0 <library name> <module> [...]"
exit 1
}
libname=$1; shift
rdflib c $libname
for f in $*; do
rdflib a $libname $f $f
done

View file

@ -1,20 +0,0 @@
;; program to test inter-segment production and linkage of RDF objects
;; [1] should produce segment base ref
;; [2] should produce standard relocation
[GLOBAL _main]
[EXTERN _puts: far]
[BITS 16]
_main:
mov ax, seg _message ; 0000 [1]
mov ds, ax ; 0003
mov dx, _message ; 0005 [2]
call far _puts ; 0008 [2][1]
xor ax,ax ; 000D
int 21h ; 000F
[SECTION .data]
_message: db 'Hello, World', 10, 13, 0

View file

@ -1,12 +0,0 @@
;; library function for rdfseg - this file is linked as a far segment
[BITS 16]
[GLOBAL _puts]
_puts:
;; can't remember how to print a string in DOS, but if anyone wants
;; to actually test this program, it should be fairly easy to put
;; in here!
retf

View file

@ -1,54 +0,0 @@
;; program to test RDOFF production and linkage
;; items to test include:
;; [1] relocation within the same segment in each module
;; [2] relocation to different segments in same module
;; [3] relocation to same segment in different module
;; [4] relocation to different segment in different module
;; [5] relative relocation to same module
;; [6] relative relocation to different module
;; [7] correct generation of BSS addresses
[SECTION .text]
[BITS 32]
_main:
mov ax,localdata ; [2] (16 bit) => 66 b8 0000
mov eax,localdata2 ; [2] (32 bit) => b8 0000000a
[EXTERN _fardata]
mov eax,[_fardata] ; [4] => a1 00000000 (+20)
mov cx,next ; [1] => 66 b9 0012
next:
call localproc ; [5] => e8 00000019
[EXTERN _farproc]
mov eax,_farproc ; [3] => b8 00000000 (+40+0)
call _farproc ; [6] => e8 -$ (-0+40+0) (=1f)
mov eax,localbss ; [7] => b8 00000000
[GLOBAL _term]
_term: xor ax,ax ; => 66 31 c0
int 21h ; => cd 21
jmp _term ; => e9 -0a (=fffffff6)
localproc:
ret ; => c3
[GLOBAL _test1proc]
_test1proc:
call localproc ; [5] => e8 -$ (-0+0+?) (=-6=fffffffa)
ret ; => c3
[SECTION .data]
[GLOBAL localdata2]
localdata: db 'localdata',0
localdata2: db 'localdata2',0
farref: dd _fardata ; [3] => 0 (+20)
localref: dd _main ; [2] => 0 (+0)
[SECTION .bss]
localbss: resw 4 ; reserve 8 bytes BSS

View file

@ -1,33 +0,0 @@
;; rdftest2.asm - test linkage and generation of RDOFF files
[SECTION .text]
[BITS 32]
[GLOBAL _farproc]
[EXTERN _test1proc]
[EXTERN localdata2]
[EXTERN _term]
_farproc:
mov bx,localdata2 ; [4] 0 => 66 bb 000a(+0)
mov eax,_term ; [3] 5 => b8 00000000(+26+0)
call _test1proc ; [6] A => e8 fffffff2(-40+0+31)(=ffffffe3)
mov eax,_farproc ; [1] => b8 00000000(+40)
add eax,[_fardata] ; [2] => 03 05 00000000(+20)
mov ebx,mybssdata ; [7] => bb 00000000(+08)
call myproc ; [5] => e8 00000001
ret
myproc:
add eax,ebx
ret
[SECTION .data]
[GLOBAL _fardata]
_fardata: dw _term ; [4]
_localref: dd _farproc ; [2]
[SECTION .bss]
mybssdata: resw 1

View file

@ -1,48 +0,0 @@
;; library functions for rdtmain - test of rdx linking and execution
;; library function = _strcmp, defined as in C
[SECTION .text]
[BITS 32]
[GLOBAL _strcmp]
_strcmp:
push ebp
mov ebp,esp
;; ebp+8 = first parameter, ebp+12 = second
mov esi,[ebp+8]
mov edi,[ebp+12]
.loop:
mov cl,byte [esi]
mov dl,byte [edi]
cmp cl,dl
jb .below
ja .above
or cl,cl
jz .match
inc esi
inc edi
jmp .loop
.below:
mov eax,-1
pop ebp
ret
.above:
mov eax,1
pop ebp
ret
.match:
xor eax,eax
pop ebp
ret
[SECTION .data]
[GLOBAL _message]
_message: db 'hello',0

View file

@ -1,47 +0,0 @@
;; rdtmain - main part of test program for RDX execution.
;; returns true (0) if its parameter equals the phrase "hello"
;; "hello" is stored in the library part, to complicate the
;; linkage.
;; assemble and link with the following commands:
;; nasm -f rdf rdtmain.asm
;; nasm -f rdf rdtlib.asm
;; ldrdf rdtmain.rdf rdtlib.rdf -o rdxtest.rdx
;; run with 'rdx rdxtest.rdx [parameters]' on a Linux (or possibly
;; other 32 bit OS) systems (x86 architectures only!)
;; try using '&& echo Yes' afterwards to find out when it returns 0.
[EXTERN _strcmp] ; strcmp is an imported function
[EXTERN _message] ; imported data
[SECTION .text]
[BITS 32]
;; main(int argc,char **argv)
[GLOBAL _main]
_main:
push ebp
mov ebp,esp
;; ebp+8 = argc, ebp+12 = argv
cmp dword [ebp+8],2
jb error ; cause error if < 1 parameters
mov eax, [ebp+12] ; eax = argv
mov ebx, [eax+4] ; ebx = argv[1]
mov ecx, _message ; ecx = "hello"
push ecx
push ebx
call _strcmp ; compare strings
add esp,8 ; caller clears stack
pop ebp
ret ; return return value of _strcmp
error:
mov eax,2 ; return 2 on error
pop ebp
ret

View file

@ -1,18 +0,0 @@
; program to test retrieval of and linkage to modules in libraries by
; ldrdf
[SECTION .text]
[GLOBAL _main]
[EXTERN _strcmp]
_main:
push dword string1
push dword string2
call _strcmp
add esp,8 ; doh! clear up stack ;-)
ret
[SECTION .data]
string1: db 'abc',0 ; try changing these strings and see
string2: db 'abd',0 ; what happens!

View file

@ -6,7 +6,6 @@
;Testname=as86; Arguments=-fas86 -obr560575.o; Files=stderr stdout br560575.o
;Testname=win32; Arguments=-fwin32 -obr560575.o; Files=stderr stdout br560575.o
;Testname=win64; Arguments=-fwin64 -obr560575.o; Files=stderr stdout br560575.o
;Testname=rdf; Arguments=-frdf -obr560575.o; Files=stderr stdout br560575.o
;Testname=ieee; Arguments=-fieee -obr560575.o; Files=stderr stdout br560575.o
;Testname=macho; Arguments=-fmacho -obr560575.o; Files=stderr stdout br560575.o

View file

@ -1,27 +0,0 @@
;Testname=unoptimized; Arguments=-O0 -frdf -obr560873.rdf; Files=stdout stderr br560873.rdf
;Testname=optimized; Arguments=-Ox -frdf -obr560873.rdf; Files=stdout stderr br560873.rdf
label:
bits 16
call far dword label
mov [label],ax
mov [label],eax
mov [word label],ax
mov [word label],eax
mov [dword label],ax
mov [dword label],eax
push 3700
push word 3700
push dword 3700
bits 32
call far word label
mov [label],ax
mov [label],eax
mov [word label],ax
mov [word label],eax
mov [dword label],ax
mov [dword label],eax
push 3700
push word 3700
push dword 3700

View file

@ -1,6 +1,5 @@
;Testname=obj; Arguments=-fobj -onasmfomat.o; Files=stdout stderr nasmfomat.o
;Testname=bin; Arguments=-fbin -onasmfomat.o; Files=stdout stderr nasmfomat.o
;Testname=rdf; Arguments=-frdf -onasmfomat.o; Files=stdout stderr nasmfomat.o
%if __OUTPUT_FORMAT__ == 'bin'