-- SwapperOps.Mesa  Edited by Sandman on August 27, 1980  10:02 AM
-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  AllocDefs USING [SwappingProcedure, SwapStrategy],
  AltoDefs USING [MaxMDSPage, PageCount, PageNumber],
  AltoFileDefs USING [vDC],
  Region USING [Count, Handle, Index, NodeObject, Object, Page, PageStatus],
  SegmentDefs USING [
    AccessOptions, AllocInfo, BankIndex, Banks, DataSegmentHandle, FileHandle,
    FileSegmentHandle, Frob, MemoryConfig, ObjectHandle, ObjectType,
    SegmentHandle];

SwapperOps: DEFINITIONS SHARES SegmentDefs =
  BEGIN OPEN AltoDefs, SegmentDefs;

  -- Boot Primative Objects


  BootDataSegment: PROCEDURE [base: PageNumber, pages: PageCount]
    RETURNS [seg: DataSegmentHandle];
  BootFileSegment: PROCEDURE [
    file: FileHandle, base: PageNumber, pages: PageCount, access: AccessOptions,
    addr: POINTER] RETURNS [seg: FileSegmentHandle];
  BootFile: PROCEDURE [access: AccessOptions] RETURNS [file: FileHandle];

  -- Primative Object Tables

  Table: TYPE = RECORD [free: Frob, link: TableHandle, seg: DataSegmentHandle];

  TableHandle: TYPE = POINTER TO Table;

  PageTable: TYPE = ARRAY [0..MaxMDSPage] OF SegmentHandle;
  PageMap: TYPE = POINTER TO PageTable;
  RegionTable: TYPE = ARRAY Region.Index OF Region.Handle;

  SystemTable: TYPE = RECORD [
    mdsMap: PageMap,
    table: TableHandle,
    memConfig: POINTER TO MemoryConfig,
    regions: POINTER TO RegionTable];

  systemTable: SystemTable;
  regions: RegionTable;

  -- MDS Region variables

  Page: TYPE = Region.Page;
  Count: TYPE = Region.Count;
  PageStatus: TYPE = Region.PageStatus;

  memConfig: MemoryConfig;
  ff, lf, rover: Region.Page;
  mdsIndex: Region.Index;
  mdsRegion: Region.Object;
  map: PageMap;
  mdsNodes: Region.NodeObject;
  strategyList: POINTER TO AllocDefs.SwapStrategy;
  Alloc: PROCEDURE [
    base: PageNumber, pages: Count, info: AllocInfo, anyWhere: BOOLEAN]
    RETURNS [success: BOOLEAN, page: Page];
  Update: PROCEDURE [
    base: Page, pages: Count, seg: SegmentHandle, simple: BOOLEAN];
  Available: PROCEDURE [page: Page, info: AllocInfo] RETURNS [BOOLEAN];
  Status: PROCEDURE [page: Page] RETURNS [seg: SegmentHandle, status: PageStatus];
  TrySwapping: AllocDefs.SwappingProcedure;
  Disable: PROCEDURE [BOOLEAN];
  InvalidNode: ERROR [node: UNSPECIFIED];

  -- Configuration Information

  InitMemoryConfig: PROCEDURE;
  ComputeRealMemory: PROC RETURNS [pages: CARDINAL, banks: Banks];
  initMemoryConfig: POINTER TO SegmentDefs.MemoryConfig = LOOPHOLE[3B];

  Direction: TYPE = {intoMDS, outofMDS};
  MoveCode: PROCEDURE [direction: Direction];
  EnableHyperspace, DisableHyperspace: PROCEDURE;
  EnableBank, DisableBank: PROCEDURE [bank: BankIndex];

  -- Object Management

  FreePage: SegmentHandle = LOOPHOLE[0];
  BusyPage: SegmentHandle = LOOPHOLE[1];

  InvalidObject: SIGNAL [object: POINTER];

  AllocateObject: PROCEDURE [CARDINAL] RETURNS [ObjectHandle];
  LiberateObject: PROCEDURE [ObjectHandle];
  ValidateObject: PROCEDURE [ObjectHandle];
  EnumerateObjects: PROCEDURE [
    type: ObjectType, proc: PROCEDURE [ObjectHandle] RETURNS [BOOLEAN]]
    RETURNS [ObjectHandle];

  -- Allocation Primatives


  AllocVM: PROCEDURE [
    base: PageNumber, pages: PageCount, info: AllocInfo, seg: SegmentHandle]
    RETURNS [PageNumber];
  UpdateVM: PROCEDURE [base: PageNumber, pages: PageCount, seg: SegmentHandle];
  SwapOutUnlocked: PROCEDURE [seg: FileSegmentHandle];
  SwapOutCodeSeg: PROCEDURE [seg: FileSegmentHandle];
  UpdateCodebases: PROCEDURE [seg: FileSegmentHandle];

  -- File Length Operations


  NormalizeFileIndex: PROCEDURE [page: PageNumber, byte: CARDINAL]
    RETURNS [PageNumber, CARDINAL];
  RoundFileIndex: PROCEDURE [page: PageNumber, byte: CARDINAL]
    RETURNS [PageNumber, CARDINAL];
  TruncateFileIndex: PROCEDURE [page: PageNumber, byte: CARDINAL]
    RETURNS [PageNumber, CARDINAL];

  -- File Segment Positioning


  FindSegHint: PROCEDURE [seg: FileSegmentHandle];
  PositionSeg: PROCEDURE [seg: FileSegmentHandle, useseg: BOOLEAN]
    RETURNS [BOOLEAN];

  MapVM: PROCEDURE [seg: FileSegmentHandle, dc: AltoFileDefs.vDC];

  -- Initialization

  MemInit, MDSRegion, Swapper: PROGRAM;
  InitMemory: PROCEDURE [ffvmp, lfvmp: CARDINAL];

  END.