1 /* ----------------------------------------------------------------------- *
3 * Copyright 2016-2017 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
37 * Mangle a struct out_data to match the rather bizarre legacy
40 * The "data" parameter for the output function points to a "int64_t",
41 * containing the address of the target in question, unless the type is
42 * OUT_RAWDATA, in which case it points to an "uint8_t"
45 * Exceptions are OUT_RELxADR, which denote an x-byte relocation
46 * which will be a relative jump. For this we need to know the
47 * distance in bytes from the start of the relocated record until
48 * the end of the containing instruction. _This_ is what is stored
49 * in the size part of the parameter, in this case.
51 * Also OUT_RESERVE denotes reservation of N bytes of BSS space,
52 * and the contents of the "data" parameter is irrelevant.
58 void nasm_do_legacy_output(const struct out_data
*data
)
60 const void *dptr
= data
->data
;
61 enum out_type type
= data
->type
;
62 int32_t tsegment
= data
->tsegment
;
63 int32_t twrt
= data
->twrt
;
64 uint64_t size
= data
->size
;
86 dptr
= &data
->toffset
;
87 size
= data
->relbase
- data
->offset
;
93 size
= (data
->sign
== OUT_SIGNED
) ? -data
->size
: data
->size
;
98 dptr
= &data
->toffset
;
99 size
= (data
->sign
== OUT_SIGNED
) ? -data
->size
: data
->size
;
104 tsegment
= twrt
= NO_SEG
;
108 tsegment
= twrt
= NO_SEG
;
111 while (size
> ZERO_BUF_SIZE
) {
112 ofmt
->legacy_output(data
->segment
, dptr
, type
,
113 ZERO_BUF_SIZE
, tsegment
, twrt
);
114 size
-= ZERO_BUF_SIZE
;
123 ofmt
->legacy_output(data
->segment
, dptr
, type
, size
, tsegment
, twrt
);