[comp.sys.ibm.pc] IBM ROM Format???

myxm@beta.UUCP (Mike Mitchell) (04/21/87)

Hello,

Can anyone explain the format of a ROM which lives in the address
space C8000 to F4000? I am aware that the first two bytes of one
of any 2K increments would need to be 0x55 and 0xAA. The third byte
is the length of the ROM software / 512 bytes. The fourth byte is
the beginning of the actual code.

What is stumping me is the method in which the PC calculates a
checksum on the ROM. How is this checksum derived and what locations
are totaled to get it? My understanding is that the checksum is
only one byte long and should total zero for the ROM software to
be valid.

Thanx for any help.

Mike Mitchell
myxm@lanl.gov OR
...!{ucbvax,decvax,cmcl2,sun,...}!lanl!myxm

timothym@tekigm2.TEK.COM (Timothy D Margeson) (04/22/87)

In article <4342@beta.UUCP> myxm@beta.UUCP (Mike Mitchell) writes:
>What is stumping me is the method in which the PC calculates a
>checksum on the ROM. How is this checksum derived and what locations
>Mike Mitchell

It is easier than it looks. Just add ALL of the 8 bit locations together,
modulo 256, and if the result is 0 then the ROM is valid (as far as the
BIOS will be concerned).

The byte that is used to adjust the checksum can be anywhere in the ROM, but
is typically the last byte location.

So, to create the checksum byte, add together all but one byte of the data in
the ROM (we'll assume it to be the location holding the checksum), this can
be done easiest in HEX. 

From the sum, strip any of the bits above XX (making the number between 0 and
255, essentially doing a mod 256 on it), add to this result a one byte value
so that the final sum is 100, this one byte value is what you want to put into
the ROM checksum location.

Most ROM burners can do all but the last step for you (at least the Data I/O
machines I've used).

Good luck...


-- 
Tim Margeson (206)253-5240
PO Box 3500  d/s C1-937                          @@   'Who said that?'  
Vancouver, WA. 98668
{amd..hplabs}cae780!tektronix!tekigm2!timothym (this changes daily)

bill@hpcvlo.HP.COM (Bill Frolik) (04/23/87)

The checksum is the one-byte sum of the bytes in however many 512-byte
blocks the ROM claims to contain.  A valid ROM has a zero checksum,
which can be tested as follows:

	mov	ax,<ROM segment>;
	mov	ds,ax		;DS:SI ->
	xor	si,si		; start of ROM
	xor	ah,ah		;Clear checksum accumulator
	mov	dl,ds:[si+2]	;DL = Number of 512-byte blocks

Sum1:	mov	cx,512		;In AH, sum up
Sum2:	lodsb			; all the bytes in
	add	ah,al		; this 512-byte
	loop	Sum2		; block.

	dec	dl		;Sum up as many 512-byte blocks
	jnz	Sum1		; as the ROM claims it contains
	test	ah,ah		;Is the sum zero?
	jz	GoodROM		;If yes, checksum passes

You can get the checksum to work out to zero on a new ROM 
by just setting any unused byte (within the region of however
many 512-byte blocks you're using) to whatever value it takes
to get the total to become zero.

Bill Frolik
hp-pcd!bill
Hewlett-Packard Portable Computer Division
Corvallis, Oregon

jallen@netxcom.UUCP (04/23/87)

In article <4342@beta.UUCP> myxm@beta.UUCP (Mike Mitchell) writes:
>Hello,
>
>Can anyone explain the format of a ROM which lives in the address
>space C8000 to F4000? I am aware that the first two bytes of one
>of any 2K increments would need to be 0x55 and 0xAA. The third byte
>is the length of the ROM software / 512 bytes. The fourth byte is
>the beginning of the actual code.
>
>Mike Mitchell
>myxm@lanl.gov OR
>...!{ucbvax,decvax,cmcl2,sun,...}!lanl!myxm

The ROM checksum is the simple sum of ALL bytes in the device
modulo 256, and forced to zero.  This includes the checksum byte
itself.  So, what you have to do is:

1)  Choose a location for your checksum.  Anyplace other
    than the first three + the initial JMP is OK.

2)  Take the sum of all other bytes on the device, subtract
    that from 256, and write the result into the checksum location.

3)  Test your end product by making sure that the checksum for the
    entire device is zero.


John Allen
=========================================================================
NetExpress Communications, Inc.      seismo!{sundc|hadron}!netxcom!jallen
1953 Gallows Road, Suite 300         (703) 749-2238
Vienna, Va., 22180
=========================================================================

john@hpcvlo.HP.COM (John Eaton) (04/24/87)

<<<<<
< It is easier than it looks. Just add ALL of the 8 bit locations together,
< modulo 256, and if the result is 0 then the ROM is valid (as far as the
< BIOS will be concerned).
<
Testing for the presence of a device or memory is always trickey because of 
the different ways that the system responds when nothing is present. Reading
a non existent memory location will usually return whatever data the bus
capacitance is holding at the time of the read. If the read is in a loop then
the same value can easily be read during each iteration of the loop. If the
loop count is a multiple of 256 then the sum of any constant value will be 
zero. Thats why IBM also uses the 55AA check to verify roms.



John Eaton
!hplabs!hp-pcd!john

mikey@bbimg.UUCP (04/27/87)

Just ADD all the bytes together and it should be modulo 100 to 00.  I.e.,
what you said was correct.  Remember that the POST enters the ROM via a 
FAR CALL and you must exit with a FAR RETURN.  And don't forget about
stack limitations and such.

				Mike Yetsko 
				Boston's Beth Israel Hospital
				trsvax!techsup!bbimg!mikey