/* ----------------------------------------------------------------------- * * * 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 = …; /* 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 … static char *segmenttypes[COUNT_SEGTYPES] = …; static int segmenttypenumbers[COUNT_SEGTYPES] = …; /* 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 … /*********************************************************************** * Actual code to deal with RDOFF2 ouput 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 { … } segments[RDF_MAXSEGS]; static int nsegments; static int32_t bsslength; static int32_t headerlength; static void rdf2_init(void) { … } static int32_t rdf2_section_names(char *name, int *bits) { … } /* * Write relocation record */ static void write_reloc_rec(struct RelocRec *r) { … } /* * Write export record */ static void write_export_rec(struct ExportRec *r) { … } static void write_import_rec(struct ImportRec *r) { … } /* * Write BSS record */ static void write_bss_rec(struct BSSRec *r) { … } /* * Write common variable record */ static void write_common_rec(struct CommonRec *r) { … } /* * Write library record */ static void write_dll_rec(struct DLLRec *r) { … } /* * Write module name record */ static void write_modname_rec(struct ModRec *r) { … } /* * Handle export, import and common records. */ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { … } static void membufwrite(int segment, const void *data, int bytes) { … } static int getsegmentlength(int segment) { … } static void rdf2_out(int32_t segto, const void *data, enum out_type type, uint64_t size, int32_t segment, int32_t wrt) { … } static void rdf2_cleanup(void) { … } /* * Handle RDOFF2 specific directives */ static enum directive_result rdf2_directive(enum directive directive, char *value) { … } extern macros_t rdf2_stdmac[]; const struct ofmt of_rdf2 = …; #endif /* OF_RDF2 */