Skip to main content
Home Forums 68kMLA Mac ROM Checksum Computation? — #3
Post #3 by Dennis Nedry
Source Forum68kMLA
Category68k
Post DateWed, 24 Feb 2010 - 22:34
Original URLhttps://68kmla.org/bb/threads/mac-rom-checksum-computation.19981/
Post
Here's my take:

Code:
                     P_ChecksumRom:
26C8   7000                      MoveQ.L   $0, D0         ; D0 = 0.
26CA   7200                      MoveQ.L   $0, D1         ; D1 = 0.
26CC   41F9 0040 0000            Lea.L     ($400000), A0  ; Load A0 with the address $40 0000. (middle of ROM)
26D2   2818                      Move.L    (A0)+, D4      ; Load D4 with memory contents at A0 (location $40 0000).
                                                         ; D4 = $6656 2270.  This is the actual checksum?
                                                         ; A0 = A0 + 4 = $40 0004.
26D4   263C 0001 FFFE            Move.L    $1FFFE, D3     ; D3 = $1 FFFE.

                                                         ; LOOP
                                                         ; D0 fetches each 32-bit word.
                                                         ; D1 keeps track of the 32-bit sum.
                                                         ; D3 is a decrementing counter for the loop, which tells it when to exit.
                                                         ; When the loop exits, D1 is holding the sum.

26DA   3018           L335:      Move      (A0)+, D0      ; D0 = memory contents at A0. (location $40 0004 = $8161 0002).  A0=A0+4=$40 0008.
26DC   D280                      Add.L     D0, D1         ; D1 = D1 + D0 = 0 + 8161 0002.
26DE   5383                      SubQ.L    $1, D3         ; D3 = D3 - 1 = $1 FFFD
26E0   66F8                      BNE       L335           ; If (D3 != 0), goto LOOP.  (values above are for first time through loop only.)

26E2   4E71                      Nop                      ; Wait 1 cycle.
26E4   4E71                      Nop                      ; Wait 1 cycle.
26E6   B981                      Eor.L     D4, D1         ; D1 = D1 XOR D4. (i.e. verify checksum)
26E8   6704                      BEQ       L336           ; If (D1 = 0), goto L336 (i.e. checksum PASSED.)
26EA   3C3C FFFF                 Move      $-1, D6        ; Else set flag for checksum FAIL
26EE   4ED6           L336:      Jmp       (A6)           ; Exit Subroutine.
It would appear that the checksum is actually stored at $40 0000, not the very beginning (location $0000 0000)? Maybe I'm seeing it wrong; is there some sort of paging I'm not knowledgeable about? It also appears that it loops around the ROM, starting somewhere in the middle, getting to the end, jumping to the beginning, then back to the middle. What facilitates this looping? This doesn't really appear to be a simple overflow-type loop.

mp.ls