-- SegOps.mesa  Edited by: Sandman, July 10, 1980  7:37 AM
-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  AltoDefs USING [PageCount, PageNumber],
  SegmentDefs USING [DefaultBase, DefaultPages, FileHandle, FileSegmentHandle],
  WartDefs USING [SegIndex];

SegOps: DEFINITIONS =
  BEGIN OPEN SegmentDefs, AltoDefs;
  
  DefaultBase: PageNumber = SegmentDefs.DefaultBase;
  DefaultPages: PageCount = SegmentDefs.DefaultPages;
  DefaultFile: FileHandle = NIL;
  
  Seg: TYPE = POINTER TO SegObject;
  
  SegObject: TYPE = RECORD [
    realFile: FileHandle,
    resident, write, data, in: BOOLEAN,
    class: CodeClass ← other,
    inUse: BOOLEAN,
    base: CARDINAL,
    pages: PageCount,
    vmPage: CARDINAL,
    lockCount: CARDINAL,
    trueFile: FileHandle,
    imageBase: PageNumber,
    link: Seg,
    link2: FileSegmentHandle,
    index: WartDefs.SegIndex];
  
  CodeClass: TYPE = {resident, in, other};
  
  InvalidSeg: ERROR [s: POINTER];
  
  NewSeg: PROCEDURE [
    file: FileHandle, base: PageNumber, pages: PageCount, write: BOOLEAN ← FALSE]
    RETURNS [Seg];
  DeleteSeg: PROCEDURE [segment: Seg];
  
  TooManySegs: SIGNAL;
  InvalidSegSize: ERROR;
  NoVM: SIGNAL [needed: PageCount];
  VMBusy: SIGNAL [base: PageNumber, pages: PageCount];
  
  SwappingError: ERROR [segment: Seg];
  SwapInSeg, UnlockSeg, SwapOutSeg: PROCEDURE [segment: Seg];
  
  EnumerateSegs: PROCEDURE [proc: PROCEDURE [Seg] RETURNS [BOOLEAN]]
    RETURNS [Seg];
  
  InitSegMachinery: PROCEDURE [PageNumber, PageNumber];
  ffvmp, lfvmp: CARDINAL;
  vmFile: FileHandle;
  
  END.