-- CPSwapDefs.mesa  (last edited by Knutsen on December 16, 1980  3:28 PM)

-- Data structures for CoPilot <=> Pilot communication.

DIRECTORY
  PrincOps USING [GlobalFrameHandle, StateVector, SVPointer, BytePC],
  PSB USING [PsbIndex, PsbNull];

CPSwapDefs: DEFINITIONS =

  BEGIN

  SVPointer: TYPE = PrincOps.SVPointer;

  ProcessState: TYPE = RECORD [
    -- This is the actual usage for the PSB.PsbFlags.available field.
    state:
      { frameReady,  -- child process ready to be Joined (or Detached).
	frameTaken,  -- parent process has recorded child's frameHandle.
	dead,  -- child process has finished all cleanup, and is dead.
	alive},  -- normal state of running process.
    detached: BOOLEAN ];

  SwapInfo: TYPE = RECORD [
    -- (this is the actual usage of PSB.PDA.available.)
    availableA: UNSPECIFIED,
    externalStateVector: LONG POINTER TO ExternalStateVector,
    availableB: ARRAY [0..2) OF UNSPECIFIED ];

  ExternalStateVector: TYPE = MACHINE DEPENDENT RECORD [
    state: SVPointer,   -- client's higher level state.  (a short pointer
			-- in the (only) MDS.
    reason: SwapReason,
    level: [0..3777B],
    parameter: POINTER TO DebugParameter,
    versionident: CARDINAL,
    loadstatepage: CARDINAL,
    lspages: CARDINAL,
    mapLog: LONG POINTER --TO VMMapLog.Descriptor--,
    mds: CARDINAL,  -- MDS of *all* processes.
    filler: [0..100B) ← 0,
    psb: PSB.PsbIndex ← PSB.PsbNull,  -- PSB of current process.
    fill: ARRAY [10..19) OF WORD];

  VersionID: CARDINAL = 08130;

  SwapReason: TYPE = {
    -- handled by user's nub
    proceed,	-- THIS MUST BE FIRST !!
    start,
    call,
    resume,
    quit,
    showscreen,
    kill,

    -- handled by debugger
    install,
    breakpoint,
    worrybreak,
    worrycall,
    uncaughtsignal,
    explicitcall,
    return,
    punt,
    interrupt,
    cleanmaplog,
    addressfault,
    writeprotect,
    cascade,
    bug,
    spare1,
    spare2,
    spare3
    };

  DebugParameter: TYPE = MACHINE DEPENDENT RECORD [
    string: STRING,
    body: SELECT OVERLAID SwapReason FROM
      uncaughtsignal => [
  	msg: UNSPECIFIED,
  	signal: UNSPECIFIED],
      return => [
  	value: UNSPECIFIED],
      start => [
  	frame: PrincOps.GlobalFrameHandle],
      bug, call => [
	sv: PrincOps.StateVector],
      addressfault, writeprotect => [
	page, psbIndex: CARDINAL],
      ENDCASE];

  AddressfaultDP: TYPE = POINTER TO addressfault DebugParameter;
  BugDP: TYPE = POINTER TO bug DebugParameter;
  CallDP: TYPE = POINTER TO call DebugParameter;
  ReturnDP: TYPE = POINTER TO return DebugParameter;
  StartDP: TYPE = POINTER TO start DebugParameter;
  UncaughtSignalDP: TYPE = POINTER TO uncaughtsignal DebugParameter;
  WriteprotectDP: TYPE = POINTER TO writeprotect DebugParameter;
  
  -- Conditional Breakpoint Stuff

  BBArray: TYPE = RECORD [
    length: CARDINAL,
    blocks: ARRAY [0..0) OF UserBreakBlock];

  BBHandle: TYPE = POINTER TO BBArray;

  UserBreakBlock: TYPE = RECORD [
    frame: PrincOps.GlobalFrameHandle,
    pc: PrincOps.BytePC,
    ptrL: POINTER,
    ptrR: POINTER,
    posnL: [0..16),
    posnR: [0..16),
    sizeL: [1..16],
    sizeR: [1..16],
    inst: [0..377B],
    relation: Relations,
    immediateR: BOOLEAN,
    counterL: BOOLEAN,
    localL: BOOLEAN,
    localR: BOOLEAN,
    stackRelative: BOOLEAN];
  
  UBBPointer: TYPE = POINTER TO UserBreakBlock;
  
  Relations: TYPE = {eq, ne, lt, ge, gt, le};

  END.