static void as86_out(int32_t segto, const void *data, enum out_type type, uint64_t size, int32_t segment, int32_t wrt) { struct Section *s; int32_t offset; uint8_t mydata[4], *p; if (wrt != NO_SEG) { wrt = NO_SEG; /* continue to do _something_ */ nasm_error(ERR_NONFATAL, "WRT not supported by as86 output format"); } /* * handle absolute-assembly (structure definitions) */ if (segto == NO_SEG) { if (type != OUT_RESERVE) nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" " space"); return; } if (segto == stext.index) s = &stext; else if (segto == sdata.index) s = &sdata; else if (segto == bssindex) s = NULL; else { nasm_error(ERR_WARNING, "attempt to assemble code in" " segment %d: defaulting to `.text'", segto); s = &stext; } if (!s && type != OUT_RESERVE) { nasm_error(ERR_WARNING, "attempt to initialize memory in the" " BSS section: ignored"); bsslen += realsize(type, size); return; } memset(mydata, 0, sizeof(mydata)); if (type == OUT_RESERVE) { if (s) { nasm_error(ERR_WARNING, "uninitialized space declared in" " %s section: zeroing", (segto == stext.index ? "code" : "data")); as86_sect_write(s, NULL, size); as86_add_piece(s, 0, 0L, 0L, size, 0); } else bsslen += size; } else if (type == OUT_RAWDATA) { if (segment != NO_SEG) nasm_panic(0, "OUT_RAWDATA with other than NO_SEG"); as86_sect_write(s, data, size); as86_add_piece(s, 0, 0L, 0L, size, 0); } else if (type == OUT_ADDRESS) { int asize = abs((int)size); if (segment != NO_SEG) { if (segment % 2) { nasm_error(ERR_NONFATAL, "as86 format does not support" " segment base references"); } else { offset = *(int64_t *)data; as86_add_piece(s, 1, offset, segment, asize, 0); } } else { p = mydata; WRITELONG(p, *(int64_t *)data); as86_sect_write(s, data, asize); as86_add_piece(s, 0, 0L, 0L, asize, 0); } } else if (type == OUT_REL2ADR) { if (segment == segto) nasm_panic(0, "intra-segment OUT_REL2ADR"); if (segment != NO_SEG) { if (segment % 2) { nasm_error(ERR_NONFATAL, "as86 format does not support" " segment base references"); } else { offset = *(int64_t *)data; as86_add_piece(s, 1, offset - size + 2, segment, 2L, 1); } } } else if (type == OUT_REL4ADR) { if (segment == segto) nasm_panic(0, "intra-segment OUT_REL4ADR"); if (segment != NO_SEG) { if (segment % 2) { nasm_error(ERR_NONFATAL, "as86 format does not support" " segment base references"); } else { offset = *(int64_t *)data; as86_add_piece(s, 1, offset - size + 4, segment, 4L, 1); } } } }
static void as86_out (long segto, void *data, unsigned long type, long segment, long wrt) { struct Section *s; long realbytes = type & OUT_SIZMASK; long offset; unsigned char mydata[4], *p; if (wrt != NO_SEG) { wrt = NO_SEG; /* continue to do _something_ */ error (ERR_NONFATAL, "WRT not supported by as86 output format"); } type &= OUT_TYPMASK; /* * handle absolute-assembly (structure definitions) */ if (segto == NO_SEG) { if (type != OUT_RESERVE) error (ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" " space"); return; } if (segto == stext.index) s = &stext; else if (segto == sdata.index) s = &sdata; else if (segto == bssindex) s = NULL; else { error(ERR_WARNING, "attempt to assemble code in" " segment %d: defaulting to `.text'", segto); s = &stext; } if (!s && type != OUT_RESERVE) { error(ERR_WARNING, "attempt to initialise memory in the" " BSS section: ignored"); if (type == OUT_REL2ADR) realbytes = 2; else if (type == OUT_REL4ADR) realbytes = 4; bsslen += realbytes; return; } if (type == OUT_RESERVE) { if (s) { error(ERR_WARNING, "uninitialised space declared in" " %s section: zeroing", (segto == stext.index ? "code" : "data")); as86_sect_write (s, NULL, realbytes); as86_add_piece (s, 0, 0L, 0L, realbytes, 0); } else bsslen += realbytes; } else if (type == OUT_RAWDATA) { if (segment != NO_SEG) error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); as86_sect_write (s, data, realbytes); as86_add_piece (s, 0, 0L, 0L, realbytes, 0); } else if (type == OUT_ADDRESS) { if (segment != NO_SEG) { if (segment % 2) { error(ERR_NONFATAL, "as86 format does not support" " segment base references"); } else{ offset = * (long *) data; as86_add_piece (s, 1, offset, segment, realbytes, 0); } } else { p = mydata; WRITELONG (p, * (long *) data); as86_sect_write (s, data, realbytes); as86_add_piece (s, 0, 0L, 0L, realbytes, 0); } } else if (type == OUT_REL2ADR) { if (segment == segto) error(ERR_PANIC, "intra-segment OUT_REL2ADR"); if (segment != NO_SEG) { if (segment % 2) { error(ERR_NONFATAL, "as86 format does not support" " segment base references"); } else { offset = * (long *) data; as86_add_piece (s, 1, offset-realbytes+2, segment, 2L, 1); } } } else if (type == OUT_REL4ADR) { if (segment == segto) error(ERR_PANIC, "intra-segment OUT_REL4ADR"); if (segment != NO_SEG) { if (segment % 2) { error(ERR_NONFATAL, "as86 format does not support" " segment base references"); } else { offset = * (long *) data; as86_add_piece (s, 1, offset-realbytes+4, segment, 4L, 1); } } } }