summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-07-06 10:58:37 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-07-06 10:58:37 -0700
commit0bc3bf61dbf1c774a71965b7cc8f145d359d25b2 (patch)
tree5216183122a4f128822015f3b066f5f2404e72fd
parent565be91fb729611e8056face229d37d25bba360b (diff)
downloadnasm-0bc3bf61dbf1c774a71965b7cc8f145d359d25b2.tar.gz
outbin: minor cleanups
- add assert so we don't try to write 2^64 bytes of zero - explicitly track the Intel hex "LBA" (64K page) instead of playing games with the last byte written. This way it is more explicit what we're doing and why. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--output/outbin.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/output/outbin.c b/output/outbin.c
index 2aae2fb7..e0448025 100644
--- a/output/outbin.c
+++ b/output/outbin.c
@@ -1477,6 +1477,7 @@ static void do_output_bin(void)
continue;
/* Pad the space between sections. */
+ nasm_assert(addr <= s->start);
fwritezero(s->start - addr, fp);
/* Write the section to the output file. */
@@ -1518,12 +1519,12 @@ static void do_output_ith(void)
{
uint8_t buf[32];
struct Section *s;
- uint64_t addr, last;
+ uint64_t addr, hiaddr, hilba;
uint64_t length;
unsigned int chunk;
/* Write the progbits sections to the output file. */
- last = 0;
+ hilba = 0;
for (s = sections; s; s = s->next) {
/* Skip non-progbits sections */
if (!(s->flags & TYPE_PROGBITS))
@@ -1537,10 +1538,12 @@ static void do_output_ith(void)
saa_rewind(s->contents);
while (length) {
- if ((addr^last) & 0xffff0000) {
- buf[0] = addr >> 24;
- buf[1] = addr >> 16;
+ hiaddr = addr >> 16;
+ if (hiaddr != hilba) {
+ buf[0] = hiaddr >> 8;
+ buf[1] = hiaddr;
write_ith_record(2, 0, 4, buf);
+ hilba = hiaddr;
}
chunk = 32 - (addr & 31);
@@ -1550,7 +1553,6 @@ static void do_output_ith(void)
saa_rnbytes(s->contents, buf, chunk);
write_ith_record(chunk, (uint16_t)addr, 0, buf);
- last = addr + chunk - 1;
addr += chunk;
length -= chunk;
}