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>
This commit is contained in:
H. Peter Anvin 2009-07-06 10:58:37 -07:00
parent 565be91fb7
commit 0bc3bf61db

View File

@ -1477,6 +1477,7 @@ static void do_output_bin(void)
continue; continue;
/* Pad the space between sections. */ /* Pad the space between sections. */
nasm_assert(addr <= s->start);
fwritezero(s->start - addr, fp); fwritezero(s->start - addr, fp);
/* Write the section to the output file. */ /* Write the section to the output file. */
@ -1518,12 +1519,12 @@ static void do_output_ith(void)
{ {
uint8_t buf[32]; uint8_t buf[32];
struct Section *s; struct Section *s;
uint64_t addr, last; uint64_t addr, hiaddr, hilba;
uint64_t length; uint64_t length;
unsigned int chunk; unsigned int chunk;
/* Write the progbits sections to the output file. */ /* Write the progbits sections to the output file. */
last = 0; hilba = 0;
for (s = sections; s; s = s->next) { for (s = sections; s; s = s->next) {
/* Skip non-progbits sections */ /* Skip non-progbits sections */
if (!(s->flags & TYPE_PROGBITS)) if (!(s->flags & TYPE_PROGBITS))
@ -1537,10 +1538,12 @@ static void do_output_ith(void)
saa_rewind(s->contents); saa_rewind(s->contents);
while (length) { while (length) {
if ((addr^last) & 0xffff0000) { hiaddr = addr >> 16;
buf[0] = addr >> 24; if (hiaddr != hilba) {
buf[1] = addr >> 16; buf[0] = hiaddr >> 8;
buf[1] = hiaddr;
write_ith_record(2, 0, 4, buf); write_ith_record(2, 0, 4, buf);
hilba = hiaddr;
} }
chunk = 32 - (addr & 31); chunk = 32 - (addr & 31);
@ -1550,7 +1553,6 @@ static void do_output_ith(void)
saa_rnbytes(s->contents, buf, chunk); saa_rnbytes(s->contents, buf, chunk);
write_ith_record(chunk, (uint16_t)addr, 0, buf); write_ith_record(chunk, (uint16_t)addr, 0, buf);
last = addr + chunk - 1;
addr += chunk; addr += chunk;
length -= chunk; length -= chunk;
} }