Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you understand Hex file ? (Extended Address Record)

I am trying to make a bootloader for PIC18 so I need to understand how to process a hex file correctly. For example I understand what to do with the following hex line.

:040C0000E2EFFFF030

04: number of bytes

0C00 : Address of hex digits

00: Data records

E2EFFFF0: Sequence of data

30: Checksum

so I would know what to do with the above line, but how about the following hex line.

:020000040001F9

02 : # of bytes

0000: Address

04: Extended Linear Address Record

0001: data

F9: Checksum

But what exactly do I do with it? Am I writing those data to that address? Can you translate it to machine language?

By the way my application program starts at address 0c00 and bootloader starts at address 0020, and above it, is the interrupt vector. Thanks!

Update

If the third line of hex file was the following, would the address FFC0 change ?

:10FFC000FF00FF00FF00FF00FF00FF000001E9EF5E

I am thinking since the second line of hex file has 04 (Extended Linear Address Record), then I should add 0001 to the address of the third line FFC0, so the new address would be like this.

$0001 + $FFC0will equal 1FFC0 , so the next set of data bytes from line 3 should be written to this address 1FFC0, is this correct ?

like image 324
Ammar Avatar asked Dec 27 '13 21:12

Ammar


1 Answers

From wikipedia Intel Hex (the obvious source for such informations)

04, Extended Linear Address Record, allowing for fully 32 bit addressing (up to 4GiB). The address field is 0000, the byte count is 02. The two data bytes (two hex digit pairs in big endian order) represent the upper 16 bits of the 32 bit address for all subsequent 00 type records until the next 04 type record comes. If there is not a 04 type record, the upper 16 bits default to 0000. To get the absolute address for subsequent 00 type records, the address specified by the data field of the most recent 04 record is added to the 00 record addresses.

So the formula is (linAddr <<16) + addr or in your case ($0001 << 16) + $FFC0

And for the case of 02/Extended Segment Address Record, the formula changed to
(segAddr << 4) + addr

like image 58
jeb Avatar answered Oct 02 '22 22:10

jeb