2009-06-29 08:25:15 +08:00
|
|
|
/* ----------------------------------------------------------------------- *
|
2017-08-03 09:37:54 +08:00
|
|
|
*
|
2016-03-08 14:04:54 +08:00
|
|
|
* Copyright 1996-2016 The NASM Authors - All Rights Reserved
|
2009-06-29 08:25:15 +08:00
|
|
|
* 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.
|
2017-08-03 09:37:54 +08:00
|
|
|
*
|
2009-06-29 08:25:15 +08:00
|
|
|
* 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.
|
2002-05-01 04:53:55 +08:00
|
|
|
*
|
2009-06-29 08:25:15 +08:00
|
|
|
* ----------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* outieee.c output routines for the Netwide Assembler to produce
|
|
|
|
* IEEE-std object files
|
2002-05-01 04:53:55 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* notes: I have tried to make this correspond to the IEEE version
|
|
|
|
* of the standard, specifically the primary ASCII version. It should
|
|
|
|
* be trivial to create the binary version given this source (which is
|
|
|
|
* one of MANY things that have to be done to make this correspond to
|
|
|
|
* the hp-microtek version of the standard).
|
|
|
|
*
|
|
|
|
* 16-bit support is assumed to use 24-bit addresses
|
|
|
|
* The linker can sort out segmentation-specific stuff
|
|
|
|
* if it keeps track of externals
|
|
|
|
* in terms of being relative to section bases
|
|
|
|
*
|
|
|
|
* A non-standard variable type, the 'Yn' variable, has been introduced.
|
|
|
|
* Basically it is a reference to extern 'n'- denoting the low limit
|
|
|
|
* (L-variable) of the section that extern 'n' is defined in. Like the
|
|
|
|
* x variable, there may be no explicit assignment to it, it is derived
|
|
|
|
* from the public definition corresponding to the extern name. This
|
|
|
|
* is required because the one thing the mufom guys forgot to do well was
|
|
|
|
* take into account segmented architectures.
|
|
|
|
*
|
|
|
|
* I use comment classes for various things and these are undefined by
|
|
|
|
* the standard.
|
|
|
|
*
|
|
|
|
* Debug info should be considered totally non-standard (local labels are
|
|
|
|
* standard but linenum records are not covered by the standard.
|
|
|
|
* Type defs have the standard format but absolute meanings for ordinal
|
|
|
|
* types are not covered by the standard.)
|
|
|
|
*
|
|
|
|
* David Lindauer, LADsoft
|
|
|
|
*/
|
2007-10-03 12:53:51 +08:00
|
|
|
#include "compiler.h"
|
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2005-01-16 06:15:51 +08:00
|
|
|
#include <stdarg.h> /* Note: we need the ANSI version of stdarg.h */
|
2002-05-01 04:53:55 +08:00
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "nasm.h"
|
|
|
|
#include "nasmlib.h"
|
2017-03-08 11:23:03 +08:00
|
|
|
#include "error.h"
|
2016-03-08 18:17:36 +08:00
|
|
|
#include "ver.h"
|
|
|
|
|
2016-05-26 03:06:29 +08:00
|
|
|
#include "outform.h"
|
|
|
|
#include "outlib.h"
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
#ifdef OF_IEEE
|
|
|
|
|
|
|
|
#define ARRAY_BOT 0x1
|
|
|
|
|
2007-04-14 00:47:53 +08:00
|
|
|
static char ieee_infile[FILENAME_MAX];
|
2002-05-01 04:53:55 +08:00
|
|
|
static int ieee_uppercase;
|
|
|
|
|
2007-10-11 05:58:45 +08:00
|
|
|
static bool any_segs;
|
2002-05-01 04:53:55 +08:00
|
|
|
static int arrindex;
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
#define HUNKSIZE 1024 /* Size of the data hunk */
|
2002-05-01 04:53:55 +08:00
|
|
|
#define EXT_BLKSIZ 512
|
2005-01-16 06:15:51 +08:00
|
|
|
#define LDPERLINE 32 /* bytes per line in output */
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
struct ieeeSection;
|
|
|
|
|
|
|
|
struct LineNumber {
|
|
|
|
struct LineNumber *next;
|
|
|
|
struct ieeeSection *segment;
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t offset;
|
|
|
|
int32_t lineno;
|
2002-05-01 04:53:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct FileName {
|
|
|
|
struct FileName *next;
|
2007-04-14 00:47:53 +08:00
|
|
|
char *name;
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t index;
|
2002-05-01 04:53:55 +08:00
|
|
|
} *fnhead, **fntail;
|
|
|
|
|
|
|
|
static struct Array {
|
|
|
|
struct Array *next;
|
|
|
|
unsigned size;
|
|
|
|
int basetype;
|
|
|
|
} *arrhead, **arrtail;
|
|
|
|
|
|
|
|
static struct ieeePublic {
|
|
|
|
struct ieeePublic *next;
|
2007-04-14 00:47:53 +08:00
|
|
|
char *name;
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t offset;
|
|
|
|
int32_t segment; /* only if it's far-absolute */
|
|
|
|
int32_t index;
|
2005-01-16 06:15:51 +08:00
|
|
|
int type; /* for debug purposes */
|
2002-05-01 04:53:55 +08:00
|
|
|
} *fpubhead, **fpubtail, *last_defined;
|
|
|
|
|
|
|
|
static struct ieeeExternal {
|
|
|
|
struct ieeeExternal *next;
|
2007-04-14 00:47:53 +08:00
|
|
|
char *name;
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t commonsize;
|
2002-05-01 04:53:55 +08:00
|
|
|
} *exthead, **exttail;
|
|
|
|
|
|
|
|
static int externals;
|
|
|
|
|
|
|
|
static struct ExtBack {
|
|
|
|
struct ExtBack *next;
|
|
|
|
int index[EXT_BLKSIZ];
|
|
|
|
} *ebhead, **ebtail;
|
|
|
|
|
|
|
|
/* NOTE: the first segment MUST be the lineno segment */
|
|
|
|
static struct ieeeSection {
|
|
|
|
struct ieeeSection *next;
|
2011-08-28 21:00:04 +08:00
|
|
|
char *name;
|
|
|
|
struct ieeeObjData *data, *datacurr;
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ieeeFixupp *fptr, *flptr;
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t index; /* the NASM segment id */
|
|
|
|
int32_t ieee_index; /* the OBJ-file segment index */
|
|
|
|
int32_t currentpos;
|
|
|
|
int32_t align; /* can be SEG_ABS + absolute addr */
|
|
|
|
int32_t startpos;
|
2011-08-28 21:00:04 +08:00
|
|
|
int32_t use32; /* is this segment 32-bit? */
|
|
|
|
struct ieeePublic *pubhead, **pubtail, *lochead, **loctail;
|
2002-05-01 04:53:55 +08:00
|
|
|
enum {
|
2005-01-16 06:15:51 +08:00
|
|
|
CMB_PRIVATE = 0,
|
|
|
|
CMB_PUBLIC = 2,
|
|
|
|
CMB_COMMON = 6
|
2002-05-01 04:53:55 +08:00
|
|
|
} combine;
|
|
|
|
} *seghead, **segtail, *ieee_seg_needs_update;
|
|
|
|
|
2002-05-01 04:54:58 +08:00
|
|
|
struct ieeeObjData {
|
2002-05-01 04:53:55 +08:00
|
|
|
struct ieeeObjData *next;
|
2007-04-12 10:40:54 +08:00
|
|
|
uint8_t data[HUNKSIZE];
|
2002-05-01 04:53:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ieeeFixupp {
|
|
|
|
struct ieeeFixupp *next;
|
2005-01-16 06:15:51 +08:00
|
|
|
enum {
|
|
|
|
FT_SEG = 0,
|
|
|
|
FT_REL = 1,
|
|
|
|
FT_OFS = 2,
|
|
|
|
FT_EXT = 3,
|
|
|
|
FT_WRT = 4,
|
|
|
|
FT_EXTREL = 5,
|
|
|
|
FT_EXTWRT = 6,
|
|
|
|
FT_EXTSEG = 7
|
2002-05-01 04:53:55 +08:00
|
|
|
} ftype;
|
2007-04-12 10:40:54 +08:00
|
|
|
int16_t size;
|
|
|
|
int32_t id1;
|
|
|
|
int32_t id2;
|
|
|
|
int32_t offset;
|
|
|
|
int32_t addend;
|
2002-05-01 04:53:55 +08:00
|
|
|
};
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2007-04-12 10:40:54 +08:00
|
|
|
static int32_t ieee_entry_seg, ieee_entry_ofs;
|
2002-05-01 04:53:55 +08:00
|
|
|
static int checksum;
|
|
|
|
|
2016-02-18 12:59:22 +08:00
|
|
|
extern const struct ofmt of_ieee;
|
2016-03-08 17:08:53 +08:00
|
|
|
static const struct dfmt ladsoft_debug_form;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
static void ieee_data_new(struct ieeeSection *);
|
2007-04-12 10:40:54 +08:00
|
|
|
static void ieee_write_fixup(int32_t, int32_t, struct ieeeSection *,
|
2007-11-07 13:48:12 +08:00
|
|
|
int, uint64_t, int32_t);
|
2002-05-01 04:53:55 +08:00
|
|
|
static void ieee_install_fixup(struct ieeeSection *, struct ieeeFixupp *);
|
2007-04-14 00:47:53 +08:00
|
|
|
static int32_t ieee_segment(char *, int, int *);
|
2016-03-08 14:53:06 +08:00
|
|
|
static void ieee_write_file(void);
|
2002-05-01 04:53:55 +08:00
|
|
|
static void ieee_write_byte(struct ieeeSection *, int);
|
|
|
|
static void ieee_write_word(struct ieeeSection *, int);
|
2007-04-12 10:40:54 +08:00
|
|
|
static void ieee_write_dword(struct ieeeSection *, int32_t);
|
2007-04-14 00:47:53 +08:00
|
|
|
static void ieee_putascii(char *, ...);
|
2002-05-01 04:53:55 +08:00
|
|
|
static void ieee_putcs(int);
|
2007-04-12 10:40:54 +08:00
|
|
|
static int32_t ieee_putld(int32_t, int32_t, uint8_t *);
|
|
|
|
static int32_t ieee_putlr(struct ieeeFixupp *);
|
2007-04-14 00:47:53 +08:00
|
|
|
static void ieee_unqualified_name(char *, char *);
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2007-10-20 05:42:29 +08:00
|
|
|
/*
|
|
|
|
* pup init
|
2002-05-01 04:53:55 +08:00
|
|
|
*/
|
2009-07-19 09:07:17 +08:00
|
|
|
static void ieee_init(void)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2018-02-25 20:50:35 +08:00
|
|
|
strlcpy(ieee_infile, inname, sizeof(ieee_infile));
|
2007-10-11 05:58:45 +08:00
|
|
|
any_segs = false;
|
2002-05-01 04:53:55 +08:00
|
|
|
fpubhead = NULL;
|
|
|
|
fpubtail = &fpubhead;
|
|
|
|
exthead = NULL;
|
|
|
|
exttail = &exthead;
|
|
|
|
externals = 1;
|
|
|
|
ebhead = NULL;
|
|
|
|
ebtail = &ebhead;
|
|
|
|
seghead = ieee_seg_needs_update = NULL;
|
|
|
|
segtail = &seghead;
|
|
|
|
ieee_entry_seg = NO_SEG;
|
2007-10-11 05:58:45 +08:00
|
|
|
ieee_uppercase = false;
|
2002-05-01 04:53:55 +08:00
|
|
|
checksum = 0;
|
|
|
|
}
|
2009-06-28 12:54:10 +08:00
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
/*
|
|
|
|
* Rundown
|
|
|
|
*/
|
2016-03-08 14:53:06 +08:00
|
|
|
static void ieee_cleanup(void)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2016-03-08 14:53:06 +08:00
|
|
|
ieee_write_file();
|
2016-02-18 12:55:08 +08:00
|
|
|
dfmt->cleanup();
|
2002-05-01 04:53:55 +08:00
|
|
|
while (seghead) {
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ieeeSection *segtmp = seghead;
|
|
|
|
seghead = seghead->next;
|
|
|
|
while (segtmp->pubhead) {
|
|
|
|
struct ieeePublic *pubtmp = segtmp->pubhead;
|
|
|
|
segtmp->pubhead = pubtmp->next;
|
|
|
|
nasm_free(pubtmp);
|
|
|
|
}
|
|
|
|
while (segtmp->fptr) {
|
|
|
|
struct ieeeFixupp *fixtmp = segtmp->fptr;
|
|
|
|
segtmp->fptr = fixtmp->next;
|
|
|
|
nasm_free(fixtmp);
|
|
|
|
}
|
|
|
|
while (segtmp->data) {
|
|
|
|
struct ieeeObjData *dattmp = segtmp->data;
|
|
|
|
segtmp->data = dattmp->next;
|
|
|
|
nasm_free(dattmp);
|
|
|
|
}
|
|
|
|
nasm_free(segtmp);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
while (fpubhead) {
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ieeePublic *pubtmp = fpubhead;
|
|
|
|
fpubhead = fpubhead->next;
|
|
|
|
nasm_free(pubtmp);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
while (exthead) {
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ieeeExternal *exttmp = exthead;
|
|
|
|
exthead = exthead->next;
|
|
|
|
nasm_free(exttmp);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
while (ebhead) {
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ExtBack *ebtmp = ebhead;
|
|
|
|
ebhead = ebhead->next;
|
|
|
|
nasm_free(ebtmp);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
/*
|
|
|
|
* callback for labels
|
|
|
|
*/
|
2007-04-14 00:47:53 +08:00
|
|
|
static void ieee_deflabel(char *name, int32_t segment,
|
2007-11-06 09:19:32 +08:00
|
|
|
int64_t offset, int is_global, char *special)
|
2005-01-16 06:15:51 +08:00
|
|
|
{
|
2002-05-01 04:53:55 +08:00
|
|
|
/*
|
|
|
|
* We have three cases:
|
|
|
|
*
|
|
|
|
* (i) `segment' is a segment-base. If so, set the name field
|
|
|
|
* for the segment structure it refers to, and then
|
|
|
|
* return.
|
|
|
|
*
|
|
|
|
* (ii) `segment' is one of our segments, or a SEG_ABS segment.
|
|
|
|
* Save the label position for later output of a PUBDEF record.
|
2007-10-20 05:42:29 +08:00
|
|
|
*
|
2002-05-01 04:53:55 +08:00
|
|
|
*
|
|
|
|
* (iii) `segment' is not one of our segments. Save the label
|
|
|
|
* position for later output of an EXTDEF.
|
|
|
|
*/
|
|
|
|
struct ieeeExternal *ext;
|
|
|
|
struct ExtBack *eb;
|
|
|
|
struct ieeeSection *seg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (special) {
|
2009-07-19 09:07:17 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "unrecognised symbol type `%s'", special);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* First check for the double-period, signifying something
|
|
|
|
* unusual.
|
|
|
|
*/
|
2016-03-08 14:04:54 +08:00
|
|
|
if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
|
2005-01-16 06:15:51 +08:00
|
|
|
if (!strcmp(name, "..start")) {
|
|
|
|
ieee_entry_seg = segment;
|
|
|
|
ieee_entry_ofs = offset;
|
|
|
|
}
|
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Case (i):
|
|
|
|
*/
|
|
|
|
if (ieee_seg_needs_update) {
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_seg_needs_update->name = name;
|
|
|
|
return;
|
|
|
|
}
|
2002-05-01 04:53:55 +08:00
|
|
|
if (segment < SEG_ABS && segment != NO_SEG && segment % 2)
|
2005-01-16 06:15:51 +08:00
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* case (ii)
|
|
|
|
*/
|
|
|
|
if (segment >= SEG_ABS) {
|
2005-01-16 06:15:51 +08:00
|
|
|
/*
|
|
|
|
* SEG_ABS subcase of (ii).
|
|
|
|
*/
|
|
|
|
if (is_global) {
|
|
|
|
struct ieeePublic *pub;
|
|
|
|
|
|
|
|
pub = *fpubtail = nasm_malloc(sizeof(*pub));
|
|
|
|
fpubtail = &pub->next;
|
|
|
|
pub->next = NULL;
|
|
|
|
pub->name = name;
|
|
|
|
pub->offset = offset;
|
|
|
|
pub->segment = segment & ~SEG_ABS;
|
|
|
|
}
|
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (seg = seghead; seg && is_global; seg = seg->next)
|
2005-01-16 06:15:51 +08:00
|
|
|
if (seg->index == segment) {
|
|
|
|
struct ieeePublic *pub;
|
|
|
|
|
|
|
|
last_defined = pub = *seg->pubtail = nasm_malloc(sizeof(*pub));
|
|
|
|
seg->pubtail = &pub->next;
|
|
|
|
pub->next = NULL;
|
|
|
|
pub->name = name;
|
|
|
|
pub->offset = offset;
|
|
|
|
pub->index = seg->ieee_index;
|
|
|
|
pub->segment = -1;
|
|
|
|
return;
|
|
|
|
}
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Case (iii).
|
|
|
|
*/
|
|
|
|
if (is_global) {
|
|
|
|
ext = *exttail = nasm_malloc(sizeof(*ext));
|
|
|
|
ext->next = NULL;
|
|
|
|
exttail = &ext->next;
|
|
|
|
ext->name = name;
|
|
|
|
if (is_global == 2)
|
2005-01-16 06:15:51 +08:00
|
|
|
ext->commonsize = offset;
|
|
|
|
else
|
|
|
|
ext->commonsize = 0;
|
|
|
|
i = segment / 2;
|
|
|
|
eb = ebhead;
|
|
|
|
if (!eb) {
|
2010-10-02 05:21:00 +08:00
|
|
|
eb = *ebtail = nasm_zalloc(sizeof(*eb));
|
2005-01-16 06:15:51 +08:00
|
|
|
eb->next = NULL;
|
|
|
|
ebtail = &eb->next;
|
|
|
|
}
|
|
|
|
while (i > EXT_BLKSIZ) {
|
|
|
|
if (eb && eb->next)
|
|
|
|
eb = eb->next;
|
|
|
|
else {
|
2010-10-02 05:21:00 +08:00
|
|
|
eb = *ebtail = nasm_zalloc(sizeof(*eb));
|
2005-01-16 06:15:51 +08:00
|
|
|
eb->next = NULL;
|
|
|
|
ebtail = &eb->next;
|
|
|
|
}
|
|
|
|
i -= EXT_BLKSIZ;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
eb->index[i] = externals++;
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put data out
|
|
|
|
*/
|
2007-11-10 06:44:02 +08:00
|
|
|
static void ieee_out(int32_t segto, const void *data,
|
|
|
|
enum out_type type, uint64_t size,
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t segment, int32_t wrt)
|
2005-01-16 06:15:51 +08:00
|
|
|
{
|
2007-04-12 10:40:54 +08:00
|
|
|
const uint8_t *ucdata;
|
|
|
|
int32_t ldata;
|
2002-05-01 04:53:55 +08:00
|
|
|
struct ieeeSection *seg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle absolute-assembly (structure definitions)
|
|
|
|
*/
|
|
|
|
if (segto == NO_SEG) {
|
2007-11-10 06:44:02 +08:00
|
|
|
if (type != OUT_RESERVE)
|
2009-07-19 09:07:17 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
|
2005-01-16 06:15:51 +08:00
|
|
|
" space");
|
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-11 05:58:45 +08:00
|
|
|
* If `any_segs' is still false, we must define a default
|
2002-05-01 04:53:55 +08:00
|
|
|
* segment.
|
|
|
|
*/
|
|
|
|
if (!any_segs) {
|
2005-01-16 06:15:51 +08:00
|
|
|
int tempint; /* ignored */
|
|
|
|
if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint))
|
2016-03-04 06:27:34 +08:00
|
|
|
nasm_panic(0, "strange segment conditions in IEEE driver");
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the segment we are targetting.
|
|
|
|
*/
|
|
|
|
for (seg = seghead; seg; seg = seg->next)
|
2005-01-16 06:15:51 +08:00
|
|
|
if (seg->index == segto)
|
|
|
|
break;
|
2002-05-01 04:53:55 +08:00
|
|
|
if (!seg)
|
2016-03-04 06:27:34 +08:00
|
|
|
nasm_panic(0, "code directed to nonexistent segment?");
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2007-11-10 06:44:02 +08:00
|
|
|
if (type == OUT_RAWDATA) {
|
2005-01-16 06:15:51 +08:00
|
|
|
ucdata = data;
|
|
|
|
while (size--)
|
|
|
|
ieee_write_byte(seg, *ucdata++);
|
2007-11-10 06:44:02 +08:00
|
|
|
} else if (type == OUT_ADDRESS || type == OUT_REL2ADR ||
|
|
|
|
type == OUT_REL4ADR) {
|
2013-11-27 10:09:56 +08:00
|
|
|
if (type == OUT_ADDRESS)
|
2016-02-06 03:34:07 +08:00
|
|
|
size = abs((int)size);
|
2013-11-27 10:09:56 +08:00
|
|
|
else if (segment == NO_SEG)
|
2009-07-19 09:07:17 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "relative call to absolute address not"
|
2005-01-16 06:15:51 +08:00
|
|
|
" supported by IEEE format");
|
2007-11-14 01:37:59 +08:00
|
|
|
ldata = *(int64_t *)data;
|
2007-11-10 06:44:02 +08:00
|
|
|
if (type == OUT_REL2ADR)
|
2005-01-16 06:15:51 +08:00
|
|
|
ldata += (size - 2);
|
2007-11-10 06:44:02 +08:00
|
|
|
if (type == OUT_REL4ADR)
|
2005-01-16 06:15:51 +08:00
|
|
|
ldata += (size - 4);
|
2007-11-10 06:44:02 +08:00
|
|
|
ieee_write_fixup(segment, wrt, seg, size, type, ldata);
|
2005-01-16 06:15:51 +08:00
|
|
|
if (size == 2)
|
|
|
|
ieee_write_word(seg, ldata);
|
|
|
|
else
|
|
|
|
ieee_write_dword(seg, ldata);
|
2007-11-10 06:44:02 +08:00
|
|
|
} else if (type == OUT_RESERVE) {
|
2005-01-16 06:15:51 +08:00
|
|
|
while (size--)
|
|
|
|
ieee_write_byte(seg, 0);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
static void ieee_data_new(struct ieeeSection *segto)
|
|
|
|
{
|
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
if (!segto->data)
|
2005-01-16 06:15:51 +08:00
|
|
|
segto->data = segto->datacurr =
|
|
|
|
nasm_malloc(sizeof(*(segto->datacurr)));
|
2002-05-01 04:53:55 +08:00
|
|
|
else
|
2005-01-16 06:15:51 +08:00
|
|
|
segto->datacurr = segto->datacurr->next =
|
|
|
|
nasm_malloc(sizeof(*(segto->datacurr)));
|
2002-05-01 04:53:55 +08:00
|
|
|
segto->datacurr->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this routine is unalduterated bloatware. I usually don't do this
|
|
|
|
* but I might as well see what it is like on a harmless program.
|
|
|
|
* If anyone wants to optimize this is a good canditate!
|
|
|
|
*/
|
2007-04-12 10:40:54 +08:00
|
|
|
static void ieee_write_fixup(int32_t segment, int32_t wrt,
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ieeeSection *segto, int size,
|
2007-11-07 13:48:12 +08:00
|
|
|
uint64_t realtype, int32_t offset)
|
2005-01-16 06:15:51 +08:00
|
|
|
{
|
2002-05-01 04:53:55 +08:00
|
|
|
struct ieeeSection *target;
|
|
|
|
struct ieeeFixupp s;
|
|
|
|
|
|
|
|
/* Don't put a fixup for things NASM can calculate */
|
|
|
|
if (wrt == NO_SEG && segment == NO_SEG)
|
2005-01-16 06:15:51 +08:00
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
s.ftype = -1;
|
|
|
|
/* if it is a WRT offset */
|
|
|
|
if (wrt != NO_SEG) {
|
2005-01-16 06:15:51 +08:00
|
|
|
s.ftype = FT_WRT;
|
|
|
|
s.addend = offset;
|
|
|
|
if (wrt >= SEG_ABS)
|
|
|
|
s.id1 = -(wrt - SEG_ABS);
|
|
|
|
else {
|
|
|
|
if (wrt % 2 && realtype != OUT_REL2ADR
|
|
|
|
&& realtype != OUT_REL4ADR) {
|
|
|
|
wrt--;
|
|
|
|
|
|
|
|
for (target = seghead; target; target = target->next)
|
|
|
|
if (target->index == wrt)
|
|
|
|
break;
|
|
|
|
if (target) {
|
|
|
|
s.id1 = target->ieee_index;
|
|
|
|
for (target = seghead; target; target = target->next)
|
|
|
|
if (target->index == segment)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (target)
|
|
|
|
s.id2 = target->ieee_index;
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Now we assume the segment field is being used
|
|
|
|
* to hold an extern index
|
|
|
|
*/
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t i = segment / 2;
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ExtBack *eb = ebhead;
|
|
|
|
while (i > EXT_BLKSIZ) {
|
|
|
|
if (eb)
|
|
|
|
eb = eb->next;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
i -= EXT_BLKSIZ;
|
|
|
|
}
|
|
|
|
/* if we have an extern decide the type and make a record
|
|
|
|
*/
|
|
|
|
if (eb) {
|
|
|
|
s.ftype = FT_EXTWRT;
|
|
|
|
s.addend = 0;
|
|
|
|
s.id2 = eb->index[i];
|
|
|
|
} else
|
2009-07-19 09:07:17 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2005-01-16 06:15:51 +08:00
|
|
|
"Source of WRT must be an offset");
|
|
|
|
}
|
|
|
|
|
|
|
|
} else
|
2016-03-04 06:27:34 +08:00
|
|
|
nasm_panic(0,
|
2005-01-16 06:15:51 +08:00
|
|
|
"unrecognised WRT value in ieee_write_fixup");
|
|
|
|
} else
|
2009-07-19 09:07:17 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "target of WRT must be a section ");
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
s.size = size;
|
|
|
|
ieee_install_fixup(segto, &s);
|
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
/* Pure segment fixup ? */
|
|
|
|
if (segment != NO_SEG) {
|
2005-01-16 06:15:51 +08:00
|
|
|
s.ftype = FT_SEG;
|
|
|
|
s.id1 = 0;
|
|
|
|
if (segment >= SEG_ABS) {
|
|
|
|
/* absolute far segment fixup */
|
|
|
|
s.id1 = -(segment - ~SEG_ABS);
|
|
|
|
} else if (segment % 2) {
|
|
|
|
/* fixup to named segment */
|
|
|
|
/* look it up */
|
|
|
|
for (target = seghead; target; target = target->next)
|
|
|
|
if (target->index == segment - 1)
|
|
|
|
break;
|
|
|
|
if (target)
|
|
|
|
s.id1 = target->ieee_index;
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Now we assume the segment field is being used
|
|
|
|
* to hold an extern index
|
|
|
|
*/
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t i = segment / 2;
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ExtBack *eb = ebhead;
|
|
|
|
while (i > EXT_BLKSIZ) {
|
|
|
|
if (eb)
|
|
|
|
eb = eb->next;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
i -= EXT_BLKSIZ;
|
|
|
|
}
|
|
|
|
/* if we have an extern decide the type and make a record
|
|
|
|
*/
|
|
|
|
if (eb) {
|
|
|
|
if (realtype == OUT_REL2ADR || realtype == OUT_REL4ADR) {
|
2016-03-04 06:27:34 +08:00
|
|
|
nasm_panic(0,
|
2005-01-16 06:15:51 +08:00
|
|
|
"Segment of a rel not supported in ieee_write_fixup");
|
|
|
|
} else {
|
|
|
|
/* If we want the segment */
|
|
|
|
s.ftype = FT_EXTSEG;
|
|
|
|
s.addend = 0;
|
|
|
|
s.id1 = eb->index[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
} else
|
|
|
|
/* If we get here the seg value doesn't make sense */
|
2016-03-04 06:27:34 +08:00
|
|
|
nasm_panic(0,
|
2005-01-16 06:15:51 +08:00
|
|
|
"unrecognised segment value in ieee_write_fixup");
|
|
|
|
}
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
} else {
|
2005-01-16 06:15:51 +08:00
|
|
|
/* Assume we are offsetting directly from a section
|
|
|
|
* So look up the target segment
|
|
|
|
*/
|
|
|
|
for (target = seghead; target; target = target->next)
|
|
|
|
if (target->index == segment)
|
|
|
|
break;
|
|
|
|
if (target) {
|
|
|
|
if (realtype == OUT_REL2ADR || realtype == OUT_REL4ADR) {
|
|
|
|
/* PC rel to a known offset */
|
|
|
|
s.id1 = target->ieee_index;
|
|
|
|
s.ftype = FT_REL;
|
|
|
|
s.size = size;
|
|
|
|
s.addend = offset;
|
|
|
|
} else {
|
|
|
|
/* We were offsetting from a seg */
|
|
|
|
s.id1 = target->ieee_index;
|
|
|
|
s.ftype = FT_OFS;
|
|
|
|
s.size = size;
|
|
|
|
s.addend = offset;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Now we assume the segment field is being used
|
|
|
|
* to hold an extern index
|
|
|
|
*/
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t i = segment / 2;
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ExtBack *eb = ebhead;
|
|
|
|
while (i > EXT_BLKSIZ) {
|
|
|
|
if (eb)
|
|
|
|
eb = eb->next;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
i -= EXT_BLKSIZ;
|
|
|
|
}
|
|
|
|
/* if we have an extern decide the type and make a record
|
|
|
|
*/
|
|
|
|
if (eb) {
|
|
|
|
if (realtype == OUT_REL2ADR || realtype == OUT_REL4ADR) {
|
|
|
|
s.ftype = FT_EXTREL;
|
|
|
|
s.addend = 0;
|
|
|
|
s.id1 = eb->index[i];
|
|
|
|
} else {
|
|
|
|
/* else we want the external offset */
|
|
|
|
s.ftype = FT_EXT;
|
|
|
|
s.addend = 0;
|
|
|
|
s.id1 = eb->index[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
} else
|
|
|
|
/* If we get here the seg value doesn't make sense */
|
2016-03-04 06:27:34 +08:00
|
|
|
nasm_panic(0,
|
2005-01-16 06:15:51 +08:00
|
|
|
"unrecognised segment value in ieee_write_fixup");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (size != 2 && s.ftype == FT_SEG)
|
2009-07-19 09:07:17 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "IEEE format can only handle 2-byte"
|
2005-01-16 06:15:51 +08:00
|
|
|
" segment base references");
|
|
|
|
s.size = size;
|
|
|
|
ieee_install_fixup(segto, &s);
|
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
/* should never get here */
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
static void ieee_install_fixup(struct ieeeSection *seg,
|
|
|
|
struct ieeeFixupp *fix)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
|
|
|
struct ieeeFixupp *f;
|
|
|
|
f = nasm_malloc(sizeof(struct ieeeFixupp));
|
2005-01-16 06:15:51 +08:00
|
|
|
memcpy(f, fix, sizeof(struct ieeeFixupp));
|
2002-05-01 04:53:55 +08:00
|
|
|
f->offset = seg->currentpos;
|
|
|
|
seg->currentpos += fix->size;
|
|
|
|
f->next = NULL;
|
|
|
|
if (seg->fptr)
|
2005-01-16 06:15:51 +08:00
|
|
|
seg->flptr = seg->flptr->next = f;
|
2002-05-01 04:53:55 +08:00
|
|
|
else
|
2005-01-16 06:15:51 +08:00
|
|
|
seg->fptr = seg->flptr = f;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* segment registry
|
|
|
|
*/
|
2007-04-14 00:47:53 +08:00
|
|
|
static int32_t ieee_segment(char *name, int pass, int *bits)
|
2005-01-16 06:15:51 +08:00
|
|
|
{
|
2002-05-01 04:53:55 +08:00
|
|
|
/*
|
|
|
|
* We call the label manager here to define a name for the new
|
|
|
|
* segment, and when our _own_ label-definition stub gets
|
|
|
|
* called in return, it should register the new segment name
|
|
|
|
* using the pointer it gets passed. That way we save memory,
|
|
|
|
* by sponging off the label manager.
|
|
|
|
*/
|
|
|
|
if (!name) {
|
2005-01-16 06:15:51 +08:00
|
|
|
*bits = 16;
|
|
|
|
if (!any_segs)
|
|
|
|
return 0;
|
|
|
|
return seghead->index;
|
2002-05-01 04:53:55 +08:00
|
|
|
} else {
|
2005-01-16 06:15:51 +08:00
|
|
|
struct ieeeSection *seg;
|
2007-10-12 01:12:58 +08:00
|
|
|
int ieee_idx, attrs;
|
|
|
|
bool rn_error;
|
2007-04-14 00:47:53 +08:00
|
|
|
char *p;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for segment attributes.
|
|
|
|
*/
|
|
|
|
attrs = 0;
|
|
|
|
while (*name == '.')
|
|
|
|
name++; /* hack, but a documented one */
|
|
|
|
p = name;
|
2008-06-22 01:23:17 +08:00
|
|
|
while (*p && !nasm_isspace(*p))
|
2005-01-16 06:15:51 +08:00
|
|
|
p++;
|
|
|
|
if (*p) {
|
|
|
|
*p++ = '\0';
|
2008-06-22 01:23:17 +08:00
|
|
|
while (*p && nasm_isspace(*p))
|
2005-01-16 06:15:51 +08:00
|
|
|
*p++ = '\0';
|
|
|
|
}
|
|
|
|
while (*p) {
|
2008-06-22 01:23:17 +08:00
|
|
|
while (*p && !nasm_isspace(*p))
|
2005-01-16 06:15:51 +08:00
|
|
|
p++;
|
|
|
|
if (*p) {
|
|
|
|
*p++ = '\0';
|
2008-06-22 01:23:17 +08:00
|
|
|
while (*p && nasm_isspace(*p))
|
2005-01-16 06:15:51 +08:00
|
|
|
*p++ = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ieee_idx = 1;
|
|
|
|
for (seg = seghead; seg; seg = seg->next) {
|
|
|
|
ieee_idx++;
|
|
|
|
if (!strcmp(seg->name, name)) {
|
|
|
|
if (attrs > 0 && pass == 1)
|
2009-07-19 09:07:17 +08:00
|
|
|
nasm_error(ERR_WARNING, "segment attributes specified on"
|
2005-01-16 06:15:51 +08:00
|
|
|
" redeclaration of segment: ignoring");
|
|
|
|
if (seg->use32)
|
|
|
|
*bits = 32;
|
|
|
|
else
|
|
|
|
*bits = 16;
|
|
|
|
return seg->index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*segtail = seg = nasm_malloc(sizeof(*seg));
|
|
|
|
seg->next = NULL;
|
|
|
|
segtail = &seg->next;
|
|
|
|
seg->index = seg_alloc();
|
|
|
|
seg->ieee_index = ieee_idx;
|
2007-10-11 05:58:45 +08:00
|
|
|
any_segs = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
seg->name = NULL;
|
|
|
|
seg->currentpos = 0;
|
|
|
|
seg->align = 1; /* default */
|
|
|
|
seg->use32 = *bits == 32; /* default to user spec */
|
|
|
|
seg->combine = CMB_PUBLIC; /* default */
|
|
|
|
seg->pubhead = NULL;
|
|
|
|
seg->pubtail = &seg->pubhead;
|
|
|
|
seg->data = NULL;
|
|
|
|
seg->fptr = NULL;
|
|
|
|
seg->lochead = NULL;
|
|
|
|
seg->loctail = &seg->lochead;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the segment attributes.
|
|
|
|
*/
|
|
|
|
p = name;
|
|
|
|
while (attrs--) {
|
|
|
|
p += strlen(p);
|
|
|
|
while (!*p)
|
|
|
|
p++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* `p' contains a segment attribute.
|
|
|
|
*/
|
|
|
|
if (!nasm_stricmp(p, "private"))
|
|
|
|
seg->combine = CMB_PRIVATE;
|
|
|
|
else if (!nasm_stricmp(p, "public"))
|
|
|
|
seg->combine = CMB_PUBLIC;
|
|
|
|
else if (!nasm_stricmp(p, "common"))
|
|
|
|
seg->combine = CMB_COMMON;
|
|
|
|
else if (!nasm_stricmp(p, "use16"))
|
2007-10-11 05:58:45 +08:00
|
|
|
seg->use32 = false;
|
2005-01-16 06:15:51 +08:00
|
|
|
else if (!nasm_stricmp(p, "use32"))
|
2007-10-11 05:58:45 +08:00
|
|
|
seg->use32 = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
else if (!nasm_strnicmp(p, "align=", 6)) {
|
|
|
|
seg->align = readnum(p + 6, &rn_error);
|
|
|
|
if (seg->align == 0)
|
|
|
|
seg->align = 1;
|
|
|
|
if (rn_error) {
|
|
|
|
seg->align = 1;
|
2009-07-19 09:07:17 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "segment alignment should be"
|
2005-01-16 06:15:51 +08:00
|
|
|
" numeric");
|
|
|
|
}
|
2017-03-01 17:01:37 +08:00
|
|
|
switch (seg->align) {
|
2005-01-16 06:15:51 +08:00
|
|
|
case 1: /* BYTE */
|
|
|
|
case 2: /* WORD */
|
|
|
|
case 4: /* DWORD */
|
|
|
|
case 16: /* PARA */
|
|
|
|
case 256: /* PAGE */
|
|
|
|
case 8:
|
|
|
|
case 32:
|
|
|
|
case 64:
|
|
|
|
case 128:
|
|
|
|
break;
|
|
|
|
default:
|
2009-07-19 09:07:17 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "invalid alignment value %d",
|
2005-01-16 06:15:51 +08:00
|
|
|
seg->align);
|
|
|
|
seg->align = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (!nasm_strnicmp(p, "absolute=", 9)) {
|
|
|
|
seg->align = SEG_ABS + readnum(p + 9, &rn_error);
|
|
|
|
if (rn_error)
|
2009-07-19 09:07:17 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "argument to `absolute' segment"
|
2005-01-16 06:15:51 +08:00
|
|
|
" attribute should be numeric");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ieee_seg_needs_update = seg;
|
|
|
|
if (seg->align >= SEG_ABS)
|
2018-06-02 09:02:54 +08:00
|
|
|
define_label(name, NO_SEG, seg->align - SEG_ABS, false);
|
2005-01-16 06:15:51 +08:00
|
|
|
else
|
2018-06-02 09:02:54 +08:00
|
|
|
define_label(name, seg->index + 1, 0L, false);
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_seg_needs_update = NULL;
|
|
|
|
|
|
|
|
if (seg->use32)
|
|
|
|
*bits = 32;
|
|
|
|
else
|
|
|
|
*bits = 16;
|
|
|
|
return seg->index;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
/*
|
|
|
|
* directives supported
|
|
|
|
*/
|
2017-03-08 14:40:00 +08:00
|
|
|
static enum directive_result
|
2017-04-03 15:09:58 +08:00
|
|
|
ieee_directive(enum directive directive, char *value, int pass)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
(void)value;
|
|
|
|
(void)pass;
|
2009-07-13 03:53:49 +08:00
|
|
|
|
|
|
|
switch (directive) {
|
|
|
|
case D_UPPERCASE:
|
2007-10-11 05:58:45 +08:00
|
|
|
ieee_uppercase = true;
|
2017-03-08 14:40:00 +08:00
|
|
|
return DIRR_OK;
|
2017-08-03 09:37:54 +08:00
|
|
|
|
2009-07-13 03:53:49 +08:00
|
|
|
default:
|
2017-03-08 14:40:00 +08:00
|
|
|
return DIRR_UNKNOWN;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2010-04-25 05:17:11 +08:00
|
|
|
static void ieee_sectalign(int32_t seg, unsigned int value)
|
|
|
|
{
|
|
|
|
struct ieeeSection *s;
|
|
|
|
|
|
|
|
list_for_each(s, seghead) {
|
2010-04-25 21:55:52 +08:00
|
|
|
if (s->index == seg)
|
2010-04-25 05:17:11 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 256 is maximum there, note it may happen
|
|
|
|
* that align is issued on "absolute" segment
|
|
|
|
* it's fine since SEG_ABS > 256 and we never
|
|
|
|
* get escape this test
|
|
|
|
*/
|
|
|
|
if (!s || !is_power2(value) || value > 256)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((unsigned int)s->align < value)
|
|
|
|
s->align = value;
|
|
|
|
}
|
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
/*
|
|
|
|
* Return segment data
|
|
|
|
*/
|
2007-04-12 10:40:54 +08:00
|
|
|
static int32_t ieee_segbase(int32_t segment)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
|
|
|
struct ieeeSection *seg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the segment in our list.
|
|
|
|
*/
|
|
|
|
for (seg = seghead; seg; seg = seg->next)
|
2005-01-16 06:15:51 +08:00
|
|
|
if (seg->index == segment - 1)
|
|
|
|
break;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
if (!seg)
|
2005-01-16 06:15:51 +08:00
|
|
|
return segment; /* not one of ours - leave it alone */
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
if (seg->align >= SEG_ABS)
|
2005-01-16 06:15:51 +08:00
|
|
|
return seg->align; /* absolute segment */
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
return segment; /* no special treatment */
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2016-03-08 14:53:06 +08:00
|
|
|
static void ieee_write_file(void)
|
2005-01-16 06:15:51 +08:00
|
|
|
{
|
2017-08-03 09:37:54 +08:00
|
|
|
const struct tm * const thetime = &official_compile_time.local;
|
2002-05-01 04:53:55 +08:00
|
|
|
struct FileName *fn;
|
|
|
|
struct ieeeSection *seg;
|
|
|
|
struct ieeePublic *pub, *loc;
|
|
|
|
struct ieeeExternal *ext;
|
|
|
|
struct ieeeObjData *data;
|
|
|
|
struct ieeeFixupp *fix;
|
|
|
|
struct Array *arr;
|
|
|
|
int i;
|
2016-03-08 14:53:06 +08:00
|
|
|
const bool debuginfo = (dfmt == &ladsoft_debug_form);
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the module header
|
|
|
|
*/
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("MBFNASM,%02X%s.\n", strlen(ieee_infile), ieee_infile);
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the NASM boast comment.
|
|
|
|
*/
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("CO0,%02X%s.\n", strlen(nasm_comment), nasm_comment);
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2007-10-20 05:42:29 +08:00
|
|
|
/*
|
2002-05-01 04:53:55 +08:00
|
|
|
* write processor-specific information
|
|
|
|
*/
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("AD8,4,L.\n");
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* date and time
|
|
|
|
*/
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("DT%04d%02d%02d%02d%02d%02d.\n",
|
2005-01-16 06:15:51 +08:00
|
|
|
1900 + thetime->tm_year, thetime->tm_mon + 1,
|
|
|
|
thetime->tm_mday, thetime->tm_hour, thetime->tm_min,
|
|
|
|
thetime->tm_sec);
|
2007-10-20 05:42:29 +08:00
|
|
|
/*
|
2002-05-01 04:53:55 +08:00
|
|
|
* if debugging, dump file names
|
|
|
|
*/
|
|
|
|
for (fn = fnhead; fn && debuginfo; fn = fn->next) {
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("C0105,%02X%s.\n", strlen(fn->name), fn->name);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("CO101,07ENDHEAD.\n");
|
2002-05-01 04:53:55 +08:00
|
|
|
/*
|
|
|
|
* the standard doesn't specify when to put checksums,
|
|
|
|
* we'll just do it periodically.
|
|
|
|
*/
|
2007-10-11 05:58:45 +08:00
|
|
|
ieee_putcs(false);
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2007-10-20 05:42:29 +08:00
|
|
|
/*
|
2002-05-01 04:53:55 +08:00
|
|
|
* Write the section headers
|
|
|
|
*/
|
|
|
|
seg = seghead;
|
2005-01-16 06:15:51 +08:00
|
|
|
if (!debuginfo && !strcmp(seg->name, "??LINE"))
|
|
|
|
seg = seg->next;
|
2002-05-01 04:53:55 +08:00
|
|
|
while (seg) {
|
2007-04-14 00:47:53 +08:00
|
|
|
char buf[256];
|
|
|
|
char attrib;
|
2005-01-16 06:15:51 +08:00
|
|
|
switch (seg->combine) {
|
|
|
|
case CMB_PUBLIC:
|
|
|
|
default:
|
|
|
|
attrib = 'C';
|
|
|
|
break;
|
|
|
|
case CMB_PRIVATE:
|
|
|
|
attrib = 'S';
|
|
|
|
break;
|
|
|
|
case CMB_COMMON:
|
|
|
|
attrib = 'M';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ieee_unqualified_name(buf, seg->name);
|
|
|
|
if (seg->align >= SEG_ABS) {
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ST%X,A,%02X%s.\n", seg->ieee_index,
|
2005-01-16 06:15:51 +08:00
|
|
|
strlen(buf), buf);
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ASL%X,%lX.\n", seg->ieee_index,
|
2005-01-16 06:15:51 +08:00
|
|
|
(seg->align - SEG_ABS) * 16);
|
|
|
|
} else {
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ST%X,%c,%02X%s.\n", seg->ieee_index, attrib,
|
2005-01-16 06:15:51 +08:00
|
|
|
strlen(buf), buf);
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("SA%X,%lX.\n", seg->ieee_index, seg->align);
|
|
|
|
ieee_putascii("ASS%X,%X.\n", seg->ieee_index,
|
2005-01-16 06:15:51 +08:00
|
|
|
seg->currentpos);
|
|
|
|
}
|
|
|
|
seg = seg->next;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* write the start address if there is one
|
|
|
|
*/
|
|
|
|
if (ieee_entry_seg) {
|
|
|
|
for (seg = seghead; seg; seg = seg->next)
|
2005-01-16 06:15:51 +08:00
|
|
|
if (seg->index == ieee_entry_seg)
|
|
|
|
break;
|
|
|
|
if (!seg)
|
2016-03-04 06:27:34 +08:00
|
|
|
nasm_panic(0, "Start address records are incorrect");
|
2005-01-16 06:15:51 +08:00
|
|
|
else
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ASG,R%X,%lX,+.\n", seg->ieee_index,
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_entry_ofs);
|
|
|
|
}
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2007-10-11 05:58:45 +08:00
|
|
|
ieee_putcs(false);
|
2002-05-01 04:53:55 +08:00
|
|
|
/*
|
|
|
|
* Write the publics
|
|
|
|
*/
|
|
|
|
i = 1;
|
|
|
|
for (seg = seghead; seg; seg = seg->next) {
|
|
|
|
for (pub = seg->pubhead; pub; pub = pub->next) {
|
2007-04-14 00:47:53 +08:00
|
|
|
char buf[256];
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_unqualified_name(buf, pub->name);
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("NI%X,%02X%s.\n", i, strlen(buf), buf);
|
2005-01-16 06:15:51 +08:00
|
|
|
if (pub->segment == -1)
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ASI%X,R%X,%lX,+.\n", i, pub->index,
|
2005-01-16 06:15:51 +08:00
|
|
|
pub->offset);
|
|
|
|
else
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ASI%X,%lX,%lX,+.\n", i, pub->segment * 16,
|
2005-01-16 06:15:51 +08:00
|
|
|
pub->offset);
|
|
|
|
if (debuginfo) {
|
|
|
|
if (pub->type >= 0x100)
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ATI%X,T%X.\n", i, pub->type - 0x100);
|
2005-01-16 06:15:51 +08:00
|
|
|
else
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ATI%X,%X.\n", i, pub->type);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
i++;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pub = fpubhead;
|
|
|
|
i = 1;
|
|
|
|
while (pub) {
|
2007-04-14 00:47:53 +08:00
|
|
|
char buf[256];
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_unqualified_name(buf, pub->name);
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("NI%X,%02X%s.\n", i, strlen(buf), buf);
|
2005-01-16 06:15:51 +08:00
|
|
|
if (pub->segment == -1)
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ASI%X,R%X,%lX,+.\n", i, pub->index,
|
2005-01-16 06:15:51 +08:00
|
|
|
pub->offset);
|
|
|
|
else
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ASI%X,%lX,%lX,+.\n", i, pub->segment * 16,
|
2005-01-16 06:15:51 +08:00
|
|
|
pub->offset);
|
|
|
|
if (debuginfo) {
|
|
|
|
if (pub->type >= 0x100)
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ATI%X,T%X.\n", i, pub->type - 0x100);
|
2005-01-16 06:15:51 +08:00
|
|
|
else
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ATI%X,%X.\n", i, pub->type);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
i++;
|
2002-05-01 04:53:55 +08:00
|
|
|
pub = pub->next;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Write the externals
|
|
|
|
*/
|
|
|
|
ext = exthead;
|
|
|
|
i = 1;
|
|
|
|
while (ext) {
|
2007-04-14 00:47:53 +08:00
|
|
|
char buf[256];
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_unqualified_name(buf, ext->name);
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("NX%X,%02X%s.\n", i++, strlen(buf), buf);
|
2002-05-01 04:53:55 +08:00
|
|
|
ext = ext->next;
|
|
|
|
}
|
2007-10-11 05:58:45 +08:00
|
|
|
ieee_putcs(false);
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IEEE doesn't have a standard pass break record
|
|
|
|
* so use the ladsoft variant
|
|
|
|
*/
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("CO100,06ENDSYM.\n");
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* now put types
|
|
|
|
*/
|
|
|
|
i = ARRAY_BOT;
|
|
|
|
for (arr = arrhead; arr && debuginfo; arr = arr->next) {
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("TY%X,20,%X,%lX.\n", i++, arr->basetype,
|
2005-01-16 06:15:51 +08:00
|
|
|
arr->size);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* now put locals
|
|
|
|
*/
|
|
|
|
i = 1;
|
|
|
|
for (seg = seghead; seg && debuginfo; seg = seg->next) {
|
|
|
|
for (loc = seg->lochead; loc; loc = loc->next) {
|
2007-04-14 00:47:53 +08:00
|
|
|
char buf[256];
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_unqualified_name(buf, loc->name);
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("NN%X,%02X%s.\n", i, strlen(buf), buf);
|
2005-01-16 06:15:51 +08:00
|
|
|
if (loc->segment == -1)
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ASN%X,R%X,%lX,+.\n", i, loc->index,
|
2005-01-16 06:15:51 +08:00
|
|
|
loc->offset);
|
|
|
|
else
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ASN%X,%lX,%lX,+.\n", i, loc->segment * 16,
|
2005-01-16 06:15:51 +08:00
|
|
|
loc->offset);
|
|
|
|
if (debuginfo) {
|
|
|
|
if (loc->type >= 0x100)
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ATN%X,T%X.\n", i, loc->type - 0x100);
|
2005-01-16 06:15:51 +08:00
|
|
|
else
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ATN%X,%X.\n", i, loc->type);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
i++;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* put out section data;
|
2005-01-16 06:15:51 +08:00
|
|
|
*/
|
2002-05-01 04:53:55 +08:00
|
|
|
seg = seghead;
|
2005-01-16 06:15:51 +08:00
|
|
|
if (!debuginfo && !strcmp(seg->name, "??LINE"))
|
|
|
|
seg = seg->next;
|
2002-05-01 04:53:55 +08:00
|
|
|
while (seg) {
|
2005-01-16 06:15:51 +08:00
|
|
|
if (seg->currentpos) {
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t size, org = 0;
|
2005-01-16 06:15:51 +08:00
|
|
|
data = seg->data;
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("SB%X.\n", seg->ieee_index);
|
2005-01-16 06:15:51 +08:00
|
|
|
fix = seg->fptr;
|
|
|
|
while (fix) {
|
|
|
|
size = HUNKSIZE - (org % HUNKSIZE);
|
|
|
|
size =
|
|
|
|
size + org >
|
|
|
|
seg->currentpos ? seg->currentpos - org : size;
|
|
|
|
size = fix->offset - org > size ? size : fix->offset - org;
|
|
|
|
org = ieee_putld(org, org + size, data->data);
|
|
|
|
if (org % HUNKSIZE == 0)
|
|
|
|
data = data->next;
|
|
|
|
if (org == fix->offset) {
|
|
|
|
org += ieee_putlr(fix);
|
|
|
|
fix = fix->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (org < seg->currentpos && data) {
|
|
|
|
size =
|
|
|
|
seg->currentpos - org >
|
|
|
|
HUNKSIZE ? HUNKSIZE : seg->currentpos - org;
|
|
|
|
org = ieee_putld(org, org + size, data->data);
|
|
|
|
data = data->next;
|
|
|
|
}
|
2007-10-11 05:58:45 +08:00
|
|
|
ieee_putcs(false);
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
seg = seg->next;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* module end record
|
|
|
|
*/
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("ME.\n");
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
static void ieee_write_byte(struct ieeeSection *seg, int data)
|
|
|
|
{
|
2002-05-01 04:53:55 +08:00
|
|
|
int temp;
|
|
|
|
if (!(temp = seg->currentpos++ % HUNKSIZE))
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_data_new(seg);
|
2002-05-01 04:53:55 +08:00
|
|
|
seg->datacurr->data[temp] = data;
|
|
|
|
}
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
static void ieee_write_word(struct ieeeSection *seg, int data)
|
|
|
|
{
|
2002-05-01 04:53:55 +08:00
|
|
|
ieee_write_byte(seg, data & 0xFF);
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_write_byte(seg, (data >> 8) & 0xFF);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
2007-04-12 10:40:54 +08:00
|
|
|
static void ieee_write_dword(struct ieeeSection *seg, int32_t data)
|
2005-01-16 06:15:51 +08:00
|
|
|
{
|
2002-05-01 04:53:55 +08:00
|
|
|
ieee_write_byte(seg, data & 0xFF);
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_write_byte(seg, (data >> 8) & 0xFF);
|
|
|
|
ieee_write_byte(seg, (data >> 16) & 0xFF);
|
|
|
|
ieee_write_byte(seg, (data >> 24) & 0xFF);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2007-04-14 00:47:53 +08:00
|
|
|
static void ieee_putascii(char *format, ...)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2007-04-14 00:47:53 +08:00
|
|
|
char buffer[256];
|
2005-01-16 06:15:51 +08:00
|
|
|
int i, l;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
2005-05-10 00:34:43 +08:00
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
2005-01-16 06:15:51 +08:00
|
|
|
l = strlen(buffer);
|
|
|
|
for (i = 0; i < l; i++)
|
2009-07-06 05:45:12 +08:00
|
|
|
if ((uint8_t)buffer[i] > 31)
|
2005-01-16 06:15:51 +08:00
|
|
|
checksum += buffer[i];
|
|
|
|
va_end(ap);
|
2009-08-13 21:07:59 +08:00
|
|
|
fputs(buffer, ofile);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* put out a checksum record */
|
|
|
|
static void ieee_putcs(int toclear)
|
|
|
|
{
|
2005-01-16 06:15:51 +08:00
|
|
|
if (toclear) {
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("CS.\n");
|
2005-01-16 06:15:51 +08:00
|
|
|
} else {
|
|
|
|
checksum += 'C';
|
|
|
|
checksum += 'S';
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("CS%02X.\n", checksum & 127);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
checksum = 0;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
2007-04-12 10:40:54 +08:00
|
|
|
static int32_t ieee_putld(int32_t start, int32_t end, uint8_t *buf)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t val;
|
2005-01-16 06:15:51 +08:00
|
|
|
if (start == end)
|
|
|
|
return (start);
|
|
|
|
val = start % HUNKSIZE;
|
|
|
|
/* fill up multiple lines */
|
|
|
|
while (end - start >= LDPERLINE) {
|
|
|
|
int i;
|
|
|
|
ieee_putascii("LD");
|
|
|
|
for (i = 0; i < LDPERLINE; i++) {
|
|
|
|
ieee_putascii("%02X", buf[val++]);
|
|
|
|
start++;
|
|
|
|
}
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii(".\n");
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
/* if no partial lines */
|
|
|
|
if (start == end)
|
|
|
|
return (start);
|
|
|
|
/* make a partial line */
|
|
|
|
ieee_putascii("LD");
|
|
|
|
while (start < end) {
|
|
|
|
ieee_putascii("%02X", buf[val++]);
|
|
|
|
start++;
|
|
|
|
}
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii(".\n");
|
2005-01-16 06:15:51 +08:00
|
|
|
return (start);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2007-04-12 10:40:54 +08:00
|
|
|
static int32_t ieee_putlr(struct ieeeFixupp *p)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* To deal with the vagaries of segmentation the LADsoft linker
|
|
|
|
* defines two types of segments: absolute and virtual. Note that
|
|
|
|
* 'absolute' in this context is a different thing from the IEEE
|
|
|
|
* definition of an absolute segment type, which is also supported. If a
|
|
|
|
* sement is linked in virtual mode the low limit (L-var) is
|
|
|
|
* subtracted from each R,X, and P variable which appears in an
|
|
|
|
* expression, so that we can have relative offsets. Meanwhile
|
|
|
|
* in the ABSOLUTE mode this subtraction is not done and
|
|
|
|
* so we can use absolute offsets from 0. In the LADsoft linker
|
|
|
|
* this configuration is not done in the assemblker source but in
|
|
|
|
* a source the linker reads. Generally this type of thing only
|
|
|
|
* becomes an issue if real mode code is used. A pure 32-bit linker could
|
|
|
|
* get away without defining the virtual mode...
|
|
|
|
*/
|
2007-04-14 00:47:53 +08:00
|
|
|
char buf[40];
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t size = p->size;
|
2005-01-16 06:15:51 +08:00
|
|
|
switch (p->ftype) {
|
|
|
|
case FT_SEG:
|
|
|
|
if (p->id1 < 0)
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "%"PRIX32"", -p->id1);
|
2005-01-16 06:15:51 +08:00
|
|
|
else
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "L%"PRIX32",10,/", p->id1);
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case FT_OFS:
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "R%"PRIX32",%"PRIX32",+", p->id1, p->addend);
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case FT_REL:
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "R%"PRIX32",%"PRIX32",+,P,-,%X,-", p->id1, p->addend, p->size);
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FT_WRT:
|
|
|
|
if (p->id2 < 0)
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "R%"PRIX32",%"PRIX32",+,L%"PRIX32",+,%"PRIX32",-", p->id2, p->addend,
|
2005-01-16 06:15:51 +08:00
|
|
|
p->id2, -p->id1 * 16);
|
|
|
|
else
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "R%"PRIX32",%"PRIX32",+,L%"PRIX32",+,L%"PRIX32",-", p->id2, p->addend,
|
2005-01-16 06:15:51 +08:00
|
|
|
p->id2, p->id1);
|
|
|
|
break;
|
|
|
|
case FT_EXT:
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "X%"PRIX32"", p->id1);
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case FT_EXTREL:
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "X%"PRIX32",P,-,%"PRIX32",-", p->id1, size);
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case FT_EXTSEG:
|
|
|
|
/* We needed a non-ieee hack here.
|
|
|
|
* We introduce the Y variable, which is the low
|
|
|
|
* limit of the native segment the extern resides in
|
|
|
|
*/
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "Y%"PRIX32",10,/", p->id1);
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case FT_EXTWRT:
|
|
|
|
if (p->id2 < 0)
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "X%"PRIX32",Y%"PRIX32",+,%"PRIX32",-", p->id2, p->id2,
|
2005-01-16 06:15:51 +08:00
|
|
|
-p->id1 * 16);
|
|
|
|
else
|
2007-04-14 08:10:59 +08:00
|
|
|
sprintf(buf, "X%"PRIX32",Y%"PRIX32",+,L%"PRIX32",-", p->id2, p->id2, p->id1);
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-07-06 05:45:12 +08:00
|
|
|
ieee_putascii("LR(%s,%"PRIX32").\n", buf, size);
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
return (size);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
/* Dump all segment data (text and fixups )*/
|
|
|
|
|
2007-04-14 00:47:53 +08:00
|
|
|
static void ieee_unqualified_name(char *dest, char *source)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
|
|
|
if (ieee_uppercase) {
|
2005-01-16 06:15:51 +08:00
|
|
|
while (*source)
|
|
|
|
*dest++ = toupper(*source++);
|
2002-05-01 04:53:55 +08:00
|
|
|
*dest = 0;
|
2005-01-16 06:15:51 +08:00
|
|
|
} else
|
|
|
|
strcpy(dest, source);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2014-11-26 04:08:41 +08:00
|
|
|
static void dbgls_init(void)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
|
|
|
int tempint;
|
|
|
|
|
|
|
|
fnhead = NULL;
|
|
|
|
fntail = &fnhead;
|
2005-01-16 06:15:51 +08:00
|
|
|
arrindex = ARRAY_BOT;
|
2002-05-01 04:53:55 +08:00
|
|
|
arrhead = NULL;
|
|
|
|
arrtail = &arrhead;
|
|
|
|
ieee_segment("??LINE", 2, &tempint);
|
2007-10-11 05:58:45 +08:00
|
|
|
any_segs = false;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
static void dbgls_cleanup(void)
|
|
|
|
{
|
|
|
|
struct ieeeSection *segtmp;
|
|
|
|
while (fnhead) {
|
2005-01-16 06:15:51 +08:00
|
|
|
struct FileName *fntemp = fnhead;
|
|
|
|
fnhead = fnhead->next;
|
|
|
|
nasm_free(fntemp->name);
|
|
|
|
nasm_free(fntemp);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
for (segtmp = seghead; segtmp; segtmp = segtmp->next) {
|
2005-01-16 06:15:51 +08:00
|
|
|
while (segtmp->lochead) {
|
|
|
|
struct ieeePublic *loctmp = segtmp->lochead;
|
|
|
|
segtmp->lochead = loctmp->next;
|
|
|
|
nasm_free(loctmp->name);
|
|
|
|
nasm_free(loctmp);
|
|
|
|
}
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
while (arrhead) {
|
2005-01-16 06:15:51 +08:00
|
|
|
struct Array *arrtmp = arrhead;
|
2002-05-01 04:53:55 +08:00
|
|
|
arrhead = arrhead->next;
|
2005-01-16 06:15:51 +08:00
|
|
|
nasm_free(arrtmp);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* because this routine is not bracketed in
|
|
|
|
* the main program, this routine will be called even if there
|
|
|
|
* is no request for debug info
|
|
|
|
* so, we have to make sure the ??LINE segment is avaialbe
|
|
|
|
* as the first segment when this debug format is selected
|
|
|
|
*/
|
2007-04-14 00:47:53 +08:00
|
|
|
static void dbgls_linnum(const char *lnfname, int32_t lineno, int32_t segto)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
|
|
|
struct FileName *fn;
|
|
|
|
struct ieeeSection *seg;
|
|
|
|
int i = 0;
|
|
|
|
if (segto == NO_SEG)
|
2005-01-16 06:15:51 +08:00
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
/*
|
2007-10-11 05:58:45 +08:00
|
|
|
* If `any_segs' is still false, we must define a default
|
2002-05-01 04:53:55 +08:00
|
|
|
* segment.
|
|
|
|
*/
|
|
|
|
if (!any_segs) {
|
2005-01-16 06:15:51 +08:00
|
|
|
int tempint; /* ignored */
|
|
|
|
if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint))
|
2016-03-04 06:27:34 +08:00
|
|
|
nasm_panic(0, "strange segment conditions in OBJ driver");
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the segment we are targetting.
|
|
|
|
*/
|
|
|
|
for (seg = seghead; seg; seg = seg->next)
|
2005-01-16 06:15:51 +08:00
|
|
|
if (seg->index == segto)
|
|
|
|
break;
|
2002-05-01 04:53:55 +08:00
|
|
|
if (!seg)
|
2016-03-04 06:27:34 +08:00
|
|
|
nasm_panic(0, "lineno directed to nonexistent segment?");
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2003-09-13 04:49:25 +08:00
|
|
|
for (fn = fnhead; fn; fn = fn->next) {
|
2005-01-16 06:15:51 +08:00
|
|
|
if (!nasm_stricmp(lnfname, fn->name))
|
|
|
|
break;
|
2002-05-01 04:53:55 +08:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (!fn) {
|
2005-01-16 06:15:51 +08:00
|
|
|
fn = nasm_malloc(sizeof(*fn));
|
|
|
|
fn->name = nasm_malloc(strlen(lnfname) + 1);
|
|
|
|
fn->index = i;
|
|
|
|
strcpy(fn->name, lnfname);
|
|
|
|
fn->next = NULL;
|
|
|
|
*fntail = fn;
|
|
|
|
fntail = &fn->next;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
ieee_write_byte(seghead, fn->index);
|
|
|
|
ieee_write_word(seghead, lineno);
|
2005-01-16 06:15:51 +08:00
|
|
|
ieee_write_fixup(segto, NO_SEG, seghead, 4, OUT_ADDRESS,
|
|
|
|
seg->currentpos);
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
}
|
2007-04-14 00:47:53 +08:00
|
|
|
static void dbgls_deflabel(char *name, int32_t segment,
|
2007-11-06 09:19:32 +08:00
|
|
|
int64_t offset, int is_global, char *special)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
|
|
|
struct ieeeSection *seg;
|
|
|
|
|
2007-10-11 05:58:45 +08:00
|
|
|
/* Keep compiler from warning about special */
|
|
|
|
(void)special;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
/*
|
2016-03-08 14:04:54 +08:00
|
|
|
* Note: ..[^@] special symbols are filtered in labels.c
|
2002-05-01 04:53:55 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-03-08 14:04:54 +08:00
|
|
|
* If it's a special-retry from pass two, discard it.
|
2002-05-01 04:53:55 +08:00
|
|
|
*/
|
2016-03-08 14:04:54 +08:00
|
|
|
if (is_global == 3)
|
2005-01-16 06:15:51 +08:00
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Case (i):
|
|
|
|
*/
|
|
|
|
if (ieee_seg_needs_update)
|
2005-01-16 06:15:51 +08:00
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
if (segment < SEG_ABS && segment != NO_SEG && segment % 2)
|
2005-01-16 06:15:51 +08:00
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
if (segment >= SEG_ABS || segment == NO_SEG) {
|
2005-01-16 06:15:51 +08:00
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-11 05:58:45 +08:00
|
|
|
* If `any_segs' is still false, we might need to define a
|
2002-05-01 04:53:55 +08:00
|
|
|
* default segment, if they're trying to declare a label in
|
|
|
|
* `first_seg'. But the label should exist due to a prior
|
|
|
|
* call to ieee_deflabel so we can skip that.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (seg = seghead; seg; seg = seg->next)
|
2005-01-16 06:15:51 +08:00
|
|
|
if (seg->index == segment) {
|
|
|
|
struct ieeePublic *loc;
|
|
|
|
/*
|
|
|
|
* Case (ii). Maybe MODPUB someday?
|
|
|
|
*/
|
|
|
|
if (!is_global) {
|
|
|
|
last_defined = loc = nasm_malloc(sizeof(*loc));
|
|
|
|
*seg->loctail = loc;
|
|
|
|
seg->loctail = &loc->next;
|
|
|
|
loc->next = NULL;
|
|
|
|
loc->name = nasm_strdup(name);
|
|
|
|
loc->offset = offset;
|
|
|
|
loc->segment = -1;
|
|
|
|
loc->index = seg->ieee_index;
|
|
|
|
}
|
|
|
|
}
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2007-04-12 10:40:54 +08:00
|
|
|
static void dbgls_typevalue(int32_t type)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
|
|
|
int elem = TYM_ELEMENTS(type);
|
|
|
|
type = TYM_TYPE(type);
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
if (!last_defined)
|
|
|
|
return;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
|
|
|
switch (type) {
|
2005-01-16 06:15:51 +08:00
|
|
|
case TY_BYTE:
|
2007-04-12 10:40:54 +08:00
|
|
|
last_defined->type = 1; /* uint8_t */
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case TY_WORD:
|
|
|
|
last_defined->type = 3; /* unsigned word */
|
|
|
|
break;
|
|
|
|
case TY_DWORD:
|
|
|
|
last_defined->type = 5; /* unsigned dword */
|
|
|
|
break;
|
|
|
|
case TY_FLOAT:
|
|
|
|
last_defined->type = 9; /* float */
|
|
|
|
break;
|
|
|
|
case TY_QWORD:
|
|
|
|
last_defined->type = 10; /* qword */
|
|
|
|
break;
|
|
|
|
case TY_TBYTE:
|
|
|
|
last_defined->type = 11; /* TBYTE */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
last_defined->type = 0x10; /* near label */
|
|
|
|
break;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
if (elem > 1) {
|
2005-01-16 06:15:51 +08:00
|
|
|
struct Array *arrtmp = nasm_malloc(sizeof(*arrtmp));
|
2002-05-01 04:53:55 +08:00
|
|
|
int vtype = last_defined->type;
|
|
|
|
arrtmp->size = elem;
|
|
|
|
arrtmp->basetype = vtype;
|
|
|
|
arrtmp->next = NULL;
|
|
|
|
last_defined->type = arrindex++ + 0x100;
|
|
|
|
*arrtail = arrtmp;
|
2005-01-16 06:15:51 +08:00
|
|
|
arrtail = &(arrtmp->next);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
last_defined = NULL;
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
static void dbgls_output(int output_type, void *param)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2005-01-16 06:15:51 +08:00
|
|
|
(void)output_type;
|
|
|
|
(void)param;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2016-02-18 18:16:36 +08:00
|
|
|
static const struct dfmt ladsoft_debug_form = {
|
2002-05-01 04:53:55 +08:00
|
|
|
"LADsoft Debug Records",
|
|
|
|
"ladsoft",
|
|
|
|
dbgls_init,
|
|
|
|
dbgls_linnum,
|
|
|
|
dbgls_deflabel,
|
2009-08-10 04:02:35 +08:00
|
|
|
null_debug_directive,
|
2002-05-01 04:53:55 +08:00
|
|
|
dbgls_typevalue,
|
|
|
|
dbgls_output,
|
|
|
|
dbgls_cleanup,
|
2017-03-08 13:32:37 +08:00
|
|
|
NULL /* pragma list */
|
2002-05-01 04:53:55 +08:00
|
|
|
};
|
2016-02-18 18:25:26 +08:00
|
|
|
static const struct dfmt * const ladsoft_debug_arr[3] = {
|
2005-01-16 06:15:51 +08:00
|
|
|
&ladsoft_debug_form,
|
|
|
|
&null_debug_form,
|
|
|
|
NULL
|
2002-05-01 04:53:55 +08:00
|
|
|
};
|
2016-02-18 12:59:22 +08:00
|
|
|
const struct ofmt of_ieee = {
|
2002-05-01 04:53:55 +08:00
|
|
|
"IEEE-695 (LADsoft variant) object file format",
|
|
|
|
"ieee",
|
2017-12-21 05:33:49 +08:00
|
|
|
".o",
|
2009-07-06 05:45:12 +08:00
|
|
|
OFMT_TEXT,
|
2016-02-12 12:40:07 +08:00
|
|
|
32,
|
2002-05-01 04:53:55 +08:00
|
|
|
ladsoft_debug_arr,
|
2008-11-05 21:11:46 +08:00
|
|
|
&ladsoft_debug_form,
|
2002-05-01 04:53:55 +08:00
|
|
|
NULL,
|
|
|
|
ieee_init,
|
2018-05-31 05:43:46 +08:00
|
|
|
null_reset,
|
2016-09-25 00:46:47 +08:00
|
|
|
nasm_do_legacy_output,
|
2002-05-01 04:53:55 +08:00
|
|
|
ieee_out,
|
|
|
|
ieee_deflabel,
|
|
|
|
ieee_segment,
|
2018-05-31 05:43:46 +08:00
|
|
|
NULL,
|
2010-04-25 05:17:11 +08:00
|
|
|
ieee_sectalign,
|
2002-05-01 04:53:55 +08:00
|
|
|
ieee_segbase,
|
|
|
|
ieee_directive,
|
2017-03-08 13:32:37 +08:00
|
|
|
ieee_cleanup,
|
|
|
|
NULL /* pragma list */
|
2002-05-01 04:53:55 +08:00
|
|
|
};
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
#endif /* OF_IEEE */
|