-- RTOS.Mesa: An internal Cedar system interface
-- last edited March 6, 1981 2:22 PM by Willie-Sue Haugeland
-- last edited September 9, 1982 10:32 am by Paul Rovner


DIRECTORY
Inline USING[HighHalf],
Mopcodes USING[zLADRB],
PrincOps USING[GlobalFrameHandle, FrameHandle, EPRange],
ProcessOperations USING[HandleToIndex, ReadPSB],
PSB USING[PsbIndex],
RTBasic USING[Address],
RTQuanta USING[QuantumCount, QuantumIndex],
Space USING[Handle];

RTOS: DEFINITIONS IMPORTS Inline, ProcessOperations
= BEGIN OPEN PrincOps, RTQuanta;

-- TYPEs
EVRange: TYPE = [0..4*EPRange);

-- SIGNALs
InsufficientVM: SIGNAL;
FrameCopySpaceTooSmall: SIGNAL;
TooManyCedarProcesses: SIGNAL;

-- variables
PermanentPageZone: UNCOUNTED ZONE;
-- use instead of GetPermanentDataPages if ZONE syntax is desired

FreeableSpaceZone: UNCOUNTED ZONE;
-- use instead of GetDataPagesFromNewSpace if ZONE syntax is desired

PrivateHeapZone: UNCOUNTED ZONE;

-- PROCs for the conservative scan
SnapshotTheFrameHeap: PROC;
AllocateFrameBodyBuffer: PROC[nPages: CARDINAL];
MapRCFrameBodies: PROC[conservativeScanner:
PROC[pa: LONG POINTER TO RTBasic.Address,
nWords: CARDINAL]];
RegisterFrameChains: PROC[d: DESCRIPTOR FOR ARRAY OF POINTER TO FrameHandle];
UnregisterFrameChains: PROC[d: DESCRIPTOR FOR ARRAY OF POINTER TO FrameHandle];


-- PROCs for module replacement
CheckForModuleReplacement: PROC[gfh: GlobalFrameHandle] RETURNS[ok: BOOLEAN];

-- PROCs for wholesale space management
GetPermanentDataPages: PROC[nPages: CARDINAL, createUniformSwapUnits: BOOLEANTRUE]
RETURNS[LONG POINTER];

GetCollectibleQuanta: PROC[desired, needed: QuantumCount]
RETURNS[qi: QuantumIndex, qc: QuantumCount];

GetDataPagesFromNewSpace: PROC[nPages: CARDINAL,
createUniformSwapUnits: BOOLEANTRUE]
RETURNS[LONG POINTER];

GetQuantaFromNewSpace: PROC[nQ: QuantumCount,
createUniformSwapUnits: BOOLEANTRUE]
RETURNS[QuantumIndex];

GetDataPagesForGCTables: PROC RETURNS[LONG POINTER];

SpaceInCedarVM: PROC[sh: Space.Handle] RETURNS[BOOLEAN];

DeleteSpace: PROC[space: Space.Handle];

UnRavelUSUs: PROC[space: Space.Handle] RETURNS[Space.Handle];

-- PROCs for startup
NotifyAllocatorReady: PROC;

IsAllocatorReady: PROC RETURNS[BOOLEAN];

RTProcessStarted: PROC;

-- PROCs for dealing with frames
EnumerateGlobalFrames: PROC[proc: PROC[GlobalFrameHandle] RETURNS[BOOLEAN]]
RETURNS[GlobalFrameHandle];

-- PROCs for dealing with processes
End: PROC; -- modified version from Processes, for Cedar process registration.

UnregisterCedarProcess: PROC[psbi: PSB.PsbIndex];

RegisterCedarProcess: PROC[psbi: PSB.PsbIndex];

-- Engine room goodies
MyLocalFrame: PROC RETURNS[FrameHandle] = MACHINE CODE{Mopcodes.zLADRB, 0};

InMDS: PROC[p: RTBasic.Address] RETURNS[BOOLEAN] =
INLINE {i: UNSPECIFIED;
RETURN[(p=0) OR (Inline.HighHalf[p] = Inline.HighHalf[LONG[@i]])]};

SameCode: PROC [f1, f2: GlobalFrameHandle] RETURNS [cm: CodeMatch];
CodeMatch: TYPE = {identical, same, different};

GetCurrent: PROC RETURNS[PSB.PsbIndex] =
INLINE {RETURN[ProcessOperations.HandleToIndex[ProcessOperations.ReadPSB[]]]};

END.