diff --git a/Makefile.in b/Makefile.in index ffe21cb4..eea5cb47 100644 --- a/Makefile.in +++ b/Makefile.in @@ -99,8 +99,8 @@ NASM = asm/nasm.$(O) \ \ macros/macros.$(O) \ \ - output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \ - output/nullout.$(O) \ + output/outform.$(O) output/outlib.$(O) output/legacy.$(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) \ @@ -511,6 +511,10 @@ output/codeview.$(O): output/codeview.c asm/directiv.h asm/pptok.h \ include/nasm.h include/nasmint.h include/nasmlib.h include/opflags.h \ include/saa.h include/tables.h output/outlib.h output/pecoff.h version.h \ x86/insnsi.h x86/regs.h +output/legacy.$(O): output/legacy.c asm/directiv.h asm/pptok.h asm/preproc.h \ + config.h include/compiler.h include/nasm.h include/nasmint.h \ + include/nasmlib.h include/opflags.h include/tables.h x86/insnsi.h \ + x86/regs.h output/nulldbg.$(O): output/nulldbg.c asm/directiv.h asm/pptok.h \ asm/preproc.h config.h include/compiler.h include/nasm.h include/nasmint.h \ include/nasmlib.h include/opflags.h include/tables.h output/outlib.h \ @@ -541,7 +545,7 @@ output/outcoff.$(O): output/outcoff.c asm/directiv.h asm/eval.h asm/pptok.h \ output/outdbg.$(O): output/outdbg.c asm/directiv.h asm/pptok.h asm/preproc.h \ config.h include/compiler.h include/nasm.h include/nasmint.h \ include/nasmlib.h include/opflags.h include/tables.h output/outform.h \ - x86/insnsi.h x86/regs.h + output/outlib.h x86/insnsi.h x86/regs.h output/outelf.$(O): output/outelf.c asm/directiv.h asm/eval.h asm/pptok.h \ asm/preproc.h asm/stdscan.h config.h include/compiler.h include/nasm.h \ include/nasmint.h include/nasmlib.h include/opflags.h include/raa.h \ diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index 6a7f46b6..6b031c2e 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -63,8 +63,8 @@ NASM = asm/nasm.$(O) \ \ macros/macros.$(O) \ \ - output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \ - output/nullout.$(O) \ + output/outform.$(O) output/outlib.$(O) output/legacy.$(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) \ @@ -395,6 +395,9 @@ output/codeview.$(O): output/codeview.c asm/directiv.h asm/pptok.h \ include/nasm.h include/nasmint.h include/nasmlib.h include/opflags.h \ include/saa.h include/tables.h output/outlib.h output/pecoff.h version.h \ x86/insnsi.h x86/regs.h +output/legacy.$(O): output/legacy.c asm/directiv.h asm/pptok.h asm/preproc.h \ + include/compiler.h include/nasm.h include/nasmint.h include/nasmlib.h \ + include/opflags.h include/tables.h x86/insnsi.h x86/regs.h output/nulldbg.$(O): output/nulldbg.c asm/directiv.h asm/pptok.h \ asm/preproc.h include/compiler.h include/nasm.h include/nasmint.h \ include/nasmlib.h include/opflags.h include/tables.h output/outlib.h \ @@ -424,7 +427,8 @@ output/outcoff.$(O): output/outcoff.c asm/directiv.h asm/eval.h asm/pptok.h \ x86/insnsi.h x86/regs.h output/outdbg.$(O): output/outdbg.c asm/directiv.h asm/pptok.h asm/preproc.h \ include/compiler.h include/nasm.h include/nasmint.h include/nasmlib.h \ - include/opflags.h include/tables.h output/outform.h x86/insnsi.h x86/regs.h + include/opflags.h include/tables.h output/outform.h output/outlib.h \ + x86/insnsi.h x86/regs.h output/outelf.$(O): output/outelf.c asm/directiv.h asm/eval.h asm/pptok.h \ asm/preproc.h asm/stdscan.h include/compiler.h include/nasm.h \ include/nasmint.h include/nasmlib.h include/opflags.h include/raa.h \ diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index 891b60c3..958ee02e 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -44,8 +44,8 @@ NASM = nasm.o \ \ macros.o \ \ - outform.o outlib.o nulldbg.o \ - nullout.o \ + outform.o outlib.o legacy.o \ + nulldbg.o nullout.o \ outbin.o outaout.o outcoff.o \ outelf.o \ outobj.o outas86.o outrdf2.o \ @@ -226,6 +226,8 @@ zerobuf.o: zerobuf.c config.h compiler.h nasmint.h nasmlib.h codeview.o: codeview.c directiv.h pptok.h preproc.h config.h compiler.h \ hashtbl.h md5.h nasm.h nasmint.h nasmlib.h opflags.h saa.h tables.h \ outlib.h pecoff.h version.h insnsi.h regs.h +legacy.o: legacy.c directiv.h pptok.h preproc.h config.h compiler.h nasm.h \ + nasmint.h nasmlib.h opflags.h tables.h insnsi.h regs.h nulldbg.o: nulldbg.c directiv.h pptok.h preproc.h config.h compiler.h nasm.h \ nasmint.h nasmlib.h opflags.h tables.h outlib.h insnsi.h regs.h nullout.o: nullout.c directiv.h pptok.h preproc.h config.h compiler.h nasm.h \ @@ -243,7 +245,7 @@ outcoff.o: outcoff.c directiv.h eval.h pptok.h preproc.h config.h compiler.h \ nasm.h nasmint.h nasmlib.h opflags.h raa.h saa.h tables.h outform.h \ outlib.h pecoff.h insnsi.h regs.h outdbg.o: outdbg.c directiv.h pptok.h preproc.h config.h compiler.h nasm.h \ - nasmint.h nasmlib.h opflags.h tables.h outform.h insnsi.h regs.h + nasmint.h nasmlib.h opflags.h tables.h outform.h outlib.h insnsi.h regs.h outelf.o: outelf.c directiv.h eval.h pptok.h preproc.h stdscan.h config.h \ compiler.h nasm.h nasmint.h nasmlib.h opflags.h raa.h rbtree.h saa.h \ tables.h ver.h dwarf.h elf.h outelf.h outform.h outlib.h stabs.h insnsi.h \ diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index f62a9a13..c8fbf856 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -60,8 +60,8 @@ NASM = asm/nasm.$(O) & & macros/macros.$(O) & & - output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) & - output/nullout.$(O) & + output/outform.$(O) output/outlib.$(O) output/legacy.$(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) & @@ -422,6 +422,10 @@ output/codeview.$(O): output/codeview.c asm/directiv.h asm/pptok.h & include/nasm.h include/nasmint.h include/nasmlib.h include/opflags.h & include/saa.h include/tables.h output/outlib.h output/pecoff.h version.h & x86/insnsi.h x86/regs.h +output/legacy.$(O): output/legacy.c asm/directiv.h asm/pptok.h asm/preproc.h & + config.h include/compiler.h include/nasm.h include/nasmint.h & + include/nasmlib.h include/opflags.h include/tables.h x86/insnsi.h & + x86/regs.h output/nulldbg.$(O): output/nulldbg.c asm/directiv.h asm/pptok.h & asm/preproc.h config.h include/compiler.h include/nasm.h include/nasmint.h & include/nasmlib.h include/opflags.h include/tables.h output/outlib.h & @@ -452,7 +456,7 @@ output/outcoff.$(O): output/outcoff.c asm/directiv.h asm/eval.h asm/pptok.h & output/outdbg.$(O): output/outdbg.c asm/directiv.h asm/pptok.h asm/preproc.h & config.h include/compiler.h include/nasm.h include/nasmint.h & include/nasmlib.h include/opflags.h include/tables.h output/outform.h & - x86/insnsi.h x86/regs.h + output/outlib.h x86/insnsi.h x86/regs.h output/outelf.$(O): output/outelf.c asm/directiv.h asm/eval.h asm/pptok.h & asm/preproc.h asm/stdscan.h config.h include/compiler.h include/nasm.h & include/nasmint.h include/nasmlib.h include/opflags.h include/raa.h & diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index 069a0058..8ffe2ab5 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -71,8 +71,8 @@ NASM = asm/nasm.$(O) \ \ macros/macros.$(O) \ \ - output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \ - output/nullout.$(O) \ + output/outform.$(O) output/outlib.$(O) output/legacy.$(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) \ @@ -387,6 +387,9 @@ output/codeview.$(O): output/codeview.c asm/directiv.h asm/pptok.h \ include/nasm.h include/nasmint.h include/nasmlib.h include/opflags.h \ include/saa.h include/tables.h output/outlib.h output/pecoff.h version.h \ x86/insnsi.h x86/regs.h +output/legacy.$(O): output/legacy.c asm/directiv.h asm/pptok.h asm/preproc.h \ + include/compiler.h include/nasm.h include/nasmint.h include/nasmlib.h \ + include/opflags.h include/tables.h x86/insnsi.h x86/regs.h output/nulldbg.$(O): output/nulldbg.c asm/directiv.h asm/pptok.h \ asm/preproc.h include/compiler.h include/nasm.h include/nasmint.h \ include/nasmlib.h include/opflags.h include/tables.h output/outlib.h \ @@ -416,7 +419,8 @@ output/outcoff.$(O): output/outcoff.c asm/directiv.h asm/eval.h asm/pptok.h \ x86/insnsi.h x86/regs.h output/outdbg.$(O): output/outdbg.c asm/directiv.h asm/pptok.h asm/preproc.h \ include/compiler.h include/nasm.h include/nasmint.h include/nasmlib.h \ - include/opflags.h include/tables.h output/outform.h x86/insnsi.h x86/regs.h + include/opflags.h include/tables.h output/outform.h output/outlib.h \ + x86/insnsi.h x86/regs.h output/outelf.$(O): output/outelf.c asm/directiv.h asm/eval.h asm/pptok.h \ asm/preproc.h asm/stdscan.h include/compiler.h include/nasm.h \ include/nasmint.h include/nasmlib.h include/opflags.h include/raa.h \ diff --git a/asm/assemble.c b/asm/assemble.c index b09f7cbb..04d4d435 100644 --- a/asm/assemble.c +++ b/asm/assemble.c @@ -386,8 +386,7 @@ static void out(struct out_data *data) "%d-bit unsigned relocation zero-extended from %d bits\n", asize << 3, ofmt->maxbits); data->size = amax; - ofmt->output(data->segment, data->data, data->type, - data->size, data->tsegment, data->twrt); + ofmt->output(data); data->insoffs += amax; data->offset += amax; data->size = size = asize - amax; @@ -396,54 +395,7 @@ static void out(struct out_data *data) data->type = OUT_RAWDATA; } - /* Hack until backend change */ - switch (data->type) { - case OUT_RELADDR: - switch (data->size) { - case 1: - data->type = OUT_REL1ADR; - break; - case 2: - data->type = OUT_REL2ADR; - break; - case 4: - data->type = OUT_REL4ADR; - break; - case 8: - data->type = OUT_REL8ADR; - break; - default: - panic(); - break; - } - - xdata.q = data->toffset; - data->data = xdata.b; - data->size = data->inslen - data->insoffs; - break; - - case OUT_SEGMENT: - data->type = OUT_ADDRESS; - /* fall through */ - - case OUT_ADDRESS: - xdata.q = data->toffset; - data->data = xdata.b; - data->size = (data->sign == OUT_SIGNED) ? -data->size : data->size; - break; - - case OUT_RAWDATA: - case OUT_RESERVE: - data->tsegment = data->twrt = NO_SEG; - break; - - default: - panic(); - break; - } - - ofmt->output(data->segment, data->data, data->type, - data->size, data->tsegment, data->twrt); + ofmt->output(data); data->offset += size; data->insoffs += size; } diff --git a/include/nasm.h b/include/nasm.h index af8036f9..02857cb1 100644 --- a/include/nasm.h +++ b/include/nasm.h @@ -748,6 +748,13 @@ struct ofmt { */ int (*setinfo)(enum geninfo type, char **string); + /* + * This is the modern output function, which gets passed + * a struct out_data with much more information. See the + * definition of struct out_data. + */ + void (*output)(const struct out_data *data); + /* * This procedure is called by assemble() to write actual * generated code or data to the object file. Typically it @@ -756,10 +763,15 @@ struct ofmt { * * The `type' argument specifies the type of output data, and * usually the size as well: its contents are described below. + * + * This is used for backends which have not yet been ported to + * the new interface, and should be NULL on ported backends. + * To use this entry point, set the output pointer to + * nasm_do_legacy_output. */ - void (*output)(int32_t segto, const void *data, - enum out_type type, uint64_t size, - int32_t segment, int32_t wrt); + void (*legacy_output)(int32_t segto, const void *data, + enum out_type type, uint64_t size, + int32_t segment, int32_t wrt); /* * This procedure is called once for every symbol defined in diff --git a/output/legacy.c b/output/legacy.c new file mode 100644 index 00000000..7c1dcec1 --- /dev/null +++ b/output/legacy.c @@ -0,0 +1,95 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 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. + * + * ----------------------------------------------------------------------- */ + +/* + * output/legacy.c + * + * Mangle a struct out_data to match the rather bizarre legacy + * backend interface. + */ + +#include "nasm.h" + +void nasm_do_legacy_output(const struct out_data *data) +{ + const void *dptr = data->data; + enum out_type type = data->type; + int32_t tsegment = data->tsegment; + int32_t twrt = data->twrt; + uint64_t size = data->size; + + switch (data->type) { + case OUT_RELADDR: + switch (data->size) { + case 1: + type = OUT_REL1ADR; + break; + case 2: + type = OUT_REL2ADR; + break; + case 4: + type = OUT_REL4ADR; + break; + case 8: + type = OUT_REL8ADR; + break; + default: + panic(); + break; + } + + dptr = &data->toffset; + size = data->inslen - data->insoffs; + break; + + case OUT_SEGMENT: + type = OUT_ADDRESS; + /* fall through */ + + case OUT_ADDRESS: + dptr = &data->toffset; + size = (data->sign == OUT_SIGNED) ? -data->size : data->size; + break; + + case OUT_RAWDATA: + case OUT_RESERVE: + tsegment = twrt = NO_SEG; + break; + + default: + panic(); + break; + } + + ofmt->legacy_output(data->segment, dptr, type, size, tsegment, twrt); +} diff --git a/output/outaout.c b/output/outaout.c index ab5adcbc..8ab55ffe 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -915,6 +915,7 @@ const struct ofmt of_aout = { aout_stdmac, aout_init, null_setinfo, + nasm_do_legacy_output, aout_out, aout_deflabel, aout_section_names, @@ -939,6 +940,7 @@ const struct ofmt of_aoutb = { aout_stdmac, aoutb_init, null_setinfo, + nasm_do_legacy_output, aout_out, aout_deflabel, aout_section_names, diff --git a/output/outas86.c b/output/outas86.c index 3d3ad84f..bdd6c598 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -636,6 +636,7 @@ const struct ofmt of_as86 = { as86_stdmac, as86_init, null_setinfo, + nasm_do_legacy_output, as86_out, as86_deflabel, as86_section_names, diff --git a/output/outbin.c b/output/outbin.c index 544ff2a2..c2bccee6 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -1662,6 +1662,7 @@ const struct ofmt of_bin = { bin_stdmac, bin_init, bin_set_info, + nasm_do_legacy_output, bin_out, bin_deflabel, bin_secname, @@ -1682,6 +1683,7 @@ const struct ofmt of_ith = { bin_stdmac, ith_init, bin_set_info, + nasm_do_legacy_output, bin_out, bin_deflabel, bin_secname, @@ -1702,6 +1704,7 @@ const struct ofmt of_srec = { bin_stdmac, srec_init, bin_set_info, + nasm_do_legacy_output, bin_out, bin_deflabel, bin_secname, diff --git a/output/outcoff.c b/output/outcoff.c index 2fca0779..57dca0d5 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -1176,6 +1176,7 @@ const struct ofmt of_coff = { coff_stdmac, coff_std_init, coff_set_info, + nasm_do_legacy_output, coff_out, coff_deflabel, coff_section_names, @@ -1204,6 +1205,7 @@ const struct ofmt of_win32 = { coff_stdmac, coff_win32_init, coff_set_info, + nasm_do_legacy_output, coff_out, coff_deflabel, coff_section_names, @@ -1230,6 +1232,7 @@ const struct ofmt of_win64 = { coff_stdmac, coff_win64_init, coff_set_info, + nasm_do_legacy_output, coff_out, coff_deflabel, coff_section_names, diff --git a/output/outdbg.c b/output/outdbg.c index bc36f74c..783bd36f 100644 --- a/output/outdbg.c +++ b/output/outdbg.c @@ -46,6 +46,7 @@ #include "nasm.h" #include "nasmlib.h" #include "outform.h" +#include "outlib.h" #ifdef OF_DBG @@ -268,6 +269,7 @@ const struct ofmt of_dbg = { NULL, dbg_init, dbg_set_info, + nasm_do_legacy_output, dbg_out, dbg_deflabel, dbg_section_names, diff --git a/output/outelf.c b/output/outelf.c index b15c6c6c..92dda899 100644 --- a/output/outelf.c +++ b/output/outelf.c @@ -2262,6 +2262,7 @@ const struct ofmt of_elf32 = { elf_stdmac, elf_init, elf_set_info, + nasm_do_legacy_output, elf32_out, elf_deflabel, elf_section_names, @@ -2309,6 +2310,7 @@ const struct ofmt of_elf64 = { elf_stdmac, elf_init, elf_set_info, + nasm_do_legacy_output, elf64_out, elf_deflabel, elf_section_names, @@ -2356,6 +2358,7 @@ const struct ofmt of_elfx32 = { elf_stdmac, elf_init, elf_set_info, + nasm_do_legacy_output, elfx32_out, elf_deflabel, elf_section_names, diff --git a/output/outieee.c b/output/outieee.c index 9a0a732b..ff242ac6 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -1522,6 +1522,7 @@ const struct ofmt of_ieee = { NULL, ieee_init, ieee_set_info, + nasm_do_legacy_output, ieee_out, ieee_deflabel, ieee_segment, diff --git a/output/outlib.h b/output/outlib.h index c66dbf6b..b1dce646 100644 --- a/output/outlib.h +++ b/output/outlib.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -55,5 +55,8 @@ void null_debug_output(int type, void *param); void null_debug_cleanup(void); extern const struct dfmt * const null_debug_arr[2]; +/* Wrapper for unported backends */ +void nasm_do_legacy_output(const struct out_data *data); + #endif /* NASM_OUTLIB_H */ diff --git a/output/outmacho.c b/output/outmacho.c index 6a0dc921..32080551 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -1627,6 +1627,7 @@ const struct ofmt of_macho32 = { macho_stdmac, macho32_init, null_setinfo, + nasm_do_legacy_output, macho_output, macho_symdef, macho_section, @@ -1674,6 +1675,7 @@ const struct ofmt of_macho64 = { macho_stdmac, macho64_init, null_setinfo, + nasm_do_legacy_output, macho_output, macho_symdef, macho_section, diff --git a/output/outobj.c b/output/outobj.c index 149d6a33..6ae00f3b 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -2667,6 +2667,7 @@ const struct ofmt of_obj = { obj_stdmac, obj_init, obj_set_info, + nasm_do_legacy_output, obj_out, obj_deflabel, obj_segment, diff --git a/output/outrdf2.c b/output/outrdf2.c index f91d32a8..63e931d4 100644 --- a/output/outrdf2.c +++ b/output/outrdf2.c @@ -782,6 +782,7 @@ const struct ofmt of_rdf2 = { rdf2_stdmac, rdf2_init, rdf2_set_info, + nasm_do_legacy_output, rdf2_out, rdf2_deflabel, rdf2_section_names,