-- TeleLoad6.mesa
-- last edited by Stewart, September 7, 1982  10:27 PM

DIRECTORY
  PupDefs USING [PupSocket],
  PupTypes USING [Pair, PupType, PupSocketID];

TeleLoad6: DEFINITIONS =
  BEGIN

  -- note: a LONG CARDINAL has the more significant
  --word at the higher memory address.
  MaxByte: CARDINAL = 200;
  BlockIndex: TYPE = [0..MaxByte);
  CoreAddress: TYPE = LONG CARDINAL;
  BootTypeNumber: TYPE = LONG CARDINAL;
  MachineTypeNumber: TYPE = LONG CARDINAL;
  Byte: TYPE = [0..400B);
  DataBlock: TYPE = PACKED ARRAY [0..0) OF Byte;

  TLObject: TYPE = RECORD [
    socket: PupDefs.PupSocket ← NIL,
    myID: PupTypes.Pair ← [1711, 1],
    attempts: INTEGER ← 5
    ];

  Handle: TYPE = POINTER TO TLObject;

  teleSwatSocket: PupTypes.PupSocketID = [0, 60B];

  -- Core fetch and store requests are identical except that the
  --store request includes data.  Both reply with the new contents of
  --memory.  The pupType of the reply is that of the request plus one.

  coreStoreRequest: PupTypes.PupType = LOOPHOLE[300B];
  coreFetchRequest: PupTypes.PupType = LOOPHOLE[302B];

  -- The state fetch and store requests fetch and return the
  --remote processor "state" whatever that may be.  The count
  --field is ignored and the address field is a small integer indicating
  --which block of state is involved, if there is more than one.
  -- Load state of block zero also cause execution to begin after
  --the acknowledgement is sent.

  stateStoreRequest: PupTypes.PupType = LOOPHOLE[304B];
  stateFetchRequest: PupTypes.PupType = LOOPHOLE[306B];

  -- These commands read and write locations in IO space.  The concept
  --is that one often wants to read or write a number of consecutive
  --bytes to the same address.  The messages consist of a sequence of
  --read and write commands.

  ioStoreRequest: PupTypes.PupType = LOOPHOLE[310B];
  ioFetchRequest: PupTypes.PupType = LOOPHOLE[312B];

  -- The following records are contained in the data part of a Pup

  -- The fetch  and store requests use this record.
  CorePktObject: TYPE = MACHINE DEPENDENT RECORD [
    address: CoreAddress,
    count: CARDINAL,
    data: DataBlock
    ];

  CorePkt: TYPE = POINTER TO CorePktObject;

  -- 8086 state
  Registers8086: TYPE = MACHINE DEPENDENT {
    AX(0), BX(1), CX(2), DX(3), SP(4), BP(5), SI(6),
    DI(7), CS(8), DS(9), SS(10), ES(11), IP(12), FL(13)
    };

  State8086Object: TYPE = MACHINE DEPENDENT RECORD [
    Regs: ARRAY Registers8086 OF CARDINAL
    ];

  State8086: TYPE = POINTER TO State8086Object;

  -- The store requests and acknowledges use this record.
  CoreBlockObject: TYPE = RECORD [
    next: CoreBlock,
    address: CoreAddress,
    data: PACKED SEQUENCE count: CARDINAL OF Byte
    ];

  CoreBlock: TYPE = POINTER TO CoreBlockObject;

  -- count may be odd, but the data array is padded to an even number of bytes.

  IOItemObject: TYPE = RECORD [
    next: IOItem,
    port: LONG CARDINAL,
    data: PACKED SEQUENCE count: BlockIndex OF Byte
    ];

  IOItem: TYPE = POINTER TO IOItemObject;

  -- Processors send the following kinds of packets when they arrive
  --in the kernel for divers reasons.

  helpRequest: PupTypes.PupType = LOOPHOLE[314B];
  bootRequest: PupTypes.PupType = LOOPHOLE[315B];

  -- The following records are contained in the data part of a Pup

  HelpRequest: TYPE = MACHINE DEPENDENT RECORD [type: MachineTypeNumber];
  
  BootRequest: TYPE = MACHINE DEPENDENT RECORD [type: BootTypeNumber];
  
    -- Procedures

  GetZone: PROC RETURNS [MDSZone];
  Start: PROC [host: STRING] RETURNS [h: Handle];
  Stop: PROC [h: Handle];

  Result: TYPE = RECORD [
    success: BOOLEAN,
    attempts: INTEGER
    ];

  -- The value returned is the number of attempts made.
  Store: PROC [h: Handle, cb: CoreBlock] RETURNS [Result];
  Fetch: PROC [h: Handle, cb: CoreBlock] RETURNS [Result];
  StoreState: PROC [h: Handle, cb: CoreBlock] RETURNS [Result];
  FetchState: PROC [h: Handle, cb: CoreBlock] RETURNS [Result];
  IOFetch: PROC[h: Handle, l: IOItem] RETURNS [Result];
  IOStore: PROC[h: Handle, l: IOItem] RETURNS [Result];

  END.

December 30, 1981  1:42 PM, Stewart, created
 3-Jan-82 20:52:45, Stewart, Added 8086 state
July 20, 1982  10:22 AM, Stewart, Mesa 6
July 27, 1982  3:52 PM, Stewart, added MDSZone
September 7, 1982  10:34 PM, Stewart, added attempt counters