Newsgroups: comp.sys.transputer
From: teig@autro1.UUCP (Oyvind Teig)
Subject: Peek and poke in occam - a cheksum calculation program example
Organization: Autronica A/S, Trondheim, Norway
Date: 24 Mar 94 07:27:29 GMT
Message-ID: <169@autro1.UUCP>

Peek and poke in occam.

  Here's a rotuine that calculates a checksum of the entire
  code area. You should run the Checksum.Addresses.Ok to
  check that they are legal.

  This routine was used to check a network we had some problems with.
  The correct checksum was found by running the same routine in a
  bootable file we knew was correctly loaded. The addresses were found
  in the .map file. We have D7305A.

  I cut the heading and one include file.

  --  Avoid internal registers:
  VAL BYTE.MemStart  IS #70:                 -- 32 bits transputer
  VAL PLACE.MemStart IS (BYTE.MemStart / 4): -- 32 bits transputer

  VAL MaxSizeOfRam IS (1024 * 1000): -- 1M bytes

  --{{{  FUNCTION Checksum.Addresses.Ok
  INT FUNCTION Checksum.Addresses.Ok (VAL INT MachineAddressOfStartOfCode,
    VAL INT SizeOfCode,
    VAL INT ClassReasonIn)
    INT classReasonOut:
    VALOF
      SEQ
        classReasonOut := ClassReasonIn
        IF
          ClassReasonIn = Ok
            --{{{  Test
            IF
              (SizeOfCode < 0) OR (SizeOfCode > MaxSizeOfRam)
                classReasonOut := Checksum.SizeOfCode.OutOfRange
              MachineAddressOfStartOfCode < ((MOSTNEG INT) + BYTE.MemStart)
                classReasonOut := Checksum.MachineAddressOfStartOfCode.OutOfRange
              (MachineAddressOfStartOfCode + SizeOfCode) > ((MOSTNEG INT) + MaxSizeOfRam)
                classReasonOut := Checksum.MachineAddressOfStartOfCode.OutOfRange
              TRUE
                SKIP
            --}}}
          ClassReasonIn <> Ok
            SKIP
      RESULT classReasonOut
  :
  --}}}
  --{{{  PROC     Checksum.Calculate
  PROC Checksum.Calculate (VAL INT MachineAddressOfStartOfCode,
    VAL INT SizeOfCode,
    INT checksum)
  
    [(MOSTPOS INT) - BYTE.MemStart] BYTE byteMemory: -- 2 GBytes = Max
    PLACE byteMemory AT PLACE.MemStart:
  
    -- I guess that occam allows this incredible aliasing error between
    -- byteMemory and the other modules ram, either because it is in a
    -- separate module, or because PLACE is being used?
  
    VAL StartOfCode IS (MachineAddressOfStartOfCode >< (MOSTNEG INT)) -
                        BYTE.MemStart: -- Obs. Checksum.Addresses.Ok
    VAL ByteMem     IS [byteMemory FROM StartOfCode FOR SizeOfCode]:
    SEQ
      checksum := 0
      SEQ i = 0 FOR SizeOfCode
        checksum := checksum PLUS (INT ByteMem [i])
  :
  --}}}

0yvind Teig
Autronica
Trondheim
Norway

