The size of the CFR is derived from values found in the EXE header (refer to Table 13. ). Offsets 04 and 05 of the EXE file image give the size of the file in 512 byte increments, offsets 02 and 03 are the file size modulo 512, offsets 08 and 09 give the size of the EXE header, and offsets 0A and 0B give the minimum number of paragraphs required above the loaded image. For a more detailed explanation of the EXE file format created by LINK, see the DOS Technical Reference manual chapter titled "EXE File Structure and Loading".
Once the resident size of the CFR header and code has been determined, use CMD MB to allocate space. The 7526 responds to this command with an address representing the segment at which the program loads. This address points to the CFR header, and the actual start of the CFR code (its base address) will be 32 bytes higher in memory. Use this base address to relocate the CFR image.
The final step in the relocation process is building a JMP (jump) instruction in the 32-byte CFR load header which directs the execution to the entry point of the relocated image. The JMP instruction uses the first 5 bytes of the CFR header, and the remaining 27 bytes of the header are unused and should be set to zero.
Once the relocation of the CFR takes place, downloading may be performed using CMD MC. After the relocated CFR image has been downloaded, the CFR is activated by CMD MD.
Disk EXE image:
+-----+ + + | EXE | | hea | | der | | , | | var | | iab | | le | | len | | gth | +-----+ + + | EXE | | pro | | gra | | m | | ima | | ge | +-----+
Terminal image:
+-----+ + + | 32- | | byt | | e | | hea | | der | | Fir | | st | | 5 | | byt | | es | | are | | a | | jum | | p | | ins | | tru | | cti | | on | | to | | the | | ent | | ry | | poi | | nt | | of | | the | | rel | | oca | | ted | | ima | | ge | | bel | | ow. | | Rem | | ain | | ing | | 27 | | byt | | es | | res | | erv | | ed. | +-----+ + + | Rel | | oca | | ted | | EXE | | pro | | gra | | m | | ima | | ge | | (si | | ze | | is | | tot | | al | | EXE | | fil | | e | | siz | | e | | min | | us | | the | | EXE | | hea | | der | | siz | | e) | +-----+
Table 13. DOS EXE File Header Format
+================+========+=========================+========================+ | Hex Offset | Contents | +================+========+=========================+========================+ | 00-01 | 4DH, 5AH &mdash. This is the link program's signature to | | | mark the file as a valid .EXE file. | +----------------+--------+-------------------------+------------------------+ | 02-03 | Length of image modulo 512 (remainder after dividing the | | | load module image size by 512.) | +----------------+--------+-------------------------+------------------------+ | 04-05 | Size of the file, in 512-byte increments (pages), | | | including the header. | +----------------+--------+-------------------------+------------------------+ | 06-07 | Number of relocation table items that follow the | | | formatted portion of the header. | +----------------+--------+-------------------------+------------------------+ | 08-09 | Size of the header in 16-byte increments (paragraphs). | | | This is used to locate the beginning of the load module | | | in the file. | +----------------+--------+-------------------------+------------------------+ | 0A-0B | Minimum number of 16-byte paragraphs required above the | | | end of the loaded program. | +----------------+--------+-------------------------+------------------------+ | 0C-0D | Maximum number of 16-byte paragraphs required above the | | | end of the loaded program. | +----------------+--------+-------------------------+------------------------+ | 0E-0F | Offset of stack segment in load module (in segment form). | +----------------+--------+-------------------------+------------------------+ | 10-11 | Value to be in the SP register when the module is given | | | control. | +----------------+--------+-------------------------+------------------------+ | 12-13 | Word checksum&mdash.negative sum of all the words in the | | | file, ignoring overflow. | +----------------+--------+-------------------------+------------------------+ | 14-15 | Value to be in the IP register when the module is given | | | control. | +----------------+--------+-------------------------+------------------------+ | 16-17 | Offset of code segment within load module (in segment | | | form). | +----------------+--------+-------------------------+------------------------+ | 18-19 | Offset of first relocation item within the file. | +----------------+--------+-------------------------+------------------------+ | 1A-1B | Overlay number (0 for resident part of the program). | +----------------+-----------------------------------------------------------+
Determine .EXE file size, "x", from:
x = ( ( (offset 04-05h) X 512) +
(offset 02-03h) +
( (offset 0A-0Bh) X 16) -
(offset 08-09h) +
32
)
if ((offset 02-03h)>0)
x = x - 512;
Note:
The two bytes used in the size requested and the address returned have the high-order byte first, followed by the low-order byte. This will most likely be in the opposite order from the method of storage in personal computer systems (that is Intel reverse order storage).- Using this fix-up segment value, complete the CFR header jump instruction and the fix-up of relocatable items in the code:
- Place a jump instruction at the beginning of the CFR header in the CFR load image. This causes a jump to the relocated entry point of the code image. The jump instruction consists of 5 bytes, defined as follows:
- Byte
- 1
- 8088 jump instruction&mdash.always EAh
- 2-3
- Memory offset for jump destination. Set to equal offsets 14-15h from the EXE header.
- 4-5
- Memory segment for jump destination. Set this to equal offsets 16-17h from the EXE header plus the fix-up segment value found in step 8 (return from MB command plus 2 paragraphs).
- Perform the relocation of all absolute references in the EXE image. The base address for relocation is the address returned by the CMD MB plus 2 paragraphs.
Based on .EXE header offsets 18-19 (first relocation item) and 6-7 (number of relocation items), for each relocation item (2 byte segment and 2 byte offset):
- Convert to the location in the .EXE code (segment*16+offset). Take into consideration the 32-byte CFR header at the beginning of the image. The relocation item is actually 32 bytes further into the CFR load image than is indicated by the segment and offset of the relocation item.
- Seek to that position in the relocation file/RAM image.
- Read the relocatable segment value from the relocation image.
- Add the base address for relocation to that segment value.
- Re-seek back to the relocation segment and write the re-located segment value there.
- Download the image created in step 5 using CMD MC. Start at the beginning of the CFR load image and work all the way to the end of the image.
- Execute CMD MD to complete the download sequence.
TERMINAL
CONTROLLER DCT
__________ ___
CMD MB ----&rarrow. Allocate space
&larrow.---- RSP Allocation address
Create download image, do relocations
CMD MC ----&rarrow. Send image blocks
&larrow.---- ACK
.
.
CMD 1 ----&rarrow. Status Request
&larrow.---- RSP
ACK ----&rarrow.
CMD MD ----&rarrow. CFR load complete
&larrow.---- ACK