PDInterpSysCallsDevelImpl.mesa
Michael Plass, November 30, 1983 10:21 am
Tim Diebert: September 24, 1985 3:37:54 pm PDT
DIRECTORY
VM,
PDInterpSysCalls,
PrincOps USING [PageCount, wordsPerPage],
ProcessorFace USING [SetMP];
PDInterpSysCallsDevelImpl: MONITOR
IMPORTS VM, ProcessorFace
EXPORTS PDInterpSysCalls
= BEGIN
SetDisplayLights: PUBLIC PROC [value: [0..9999]] = {ProcessorFace.SetMP[value]};
AllocateSpace: PUBLIC ENTRY PROC [words: INT] RETURNS [LONG POINTER] = {
ENABLE UNWIND => NULL;
pages: CARDINAL ← (words+PrincOps.wordsPerPage)/PrincOps.wordsPerPage;
RETURN [ScratchMap[pages]]
};
FreeSpace: PUBLIC ENTRY PROC [pointer: LONG POINTER] = {
ENABLE UNWIND => NULL;
[] ← Unmap[pointer];
};
BadFreeSpaceRequest: PUBLIC ERROR = CODE;
Exported to Space
ScratchMap: PUBLIC PROCEDURE [count: VM.PageCount]
RETURNS [pointer: LONG POINTER] ~ {
interval: Interval ← Allocate[count];
AddToScratchList[interval];
pointer ← interval.pointer;
};
Unmap: PUBLIC PROCEDURE [pointer: LONG POINTER]
RETURNS [nil: LONG POINTERNIL] ~ {
interval: Interval ← RemoveFromScratchList[pointer];
IF interval.pointer = NIL THEN BadFreeSpaceRequest;
Deallocate[interval];
};
scratchList: LIST OF Interval ← NIL;
AddToScratchList: PROC [interval: Interval] ~ {
scratchList ← CONS[interval, scratchList];
};
RemoveFromScratchList: PROC [pointer: LONG POINTER] RETURNS [Interval] ~ {
prev: LIST OF Interval ← NIL;
FOR p: LIST OF Interval ← scratchList, p.rest UNTIL p=NIL DO
IF p.first.pointer = pointer THEN {
IF prev = NIL THEN scratchList ← p.rest ELSE prev.rest ← p.rest;
p.rest ← NIL;
RETURN [p.first];
};
prev ← p;
ENDLOOP;
RETURN [[NIL, 0]]
};
Activate, ActivateProc, Deactivate, DeactivateProc, ForceOut, Kill, SetAccess unimplemented for now
Interval: TYPE ~ RECORD [pointer: LONG POINTER, count: PrincOps.PageCount];
Allocate: PUBLIC PROCEDURE [count: VM.PageCount] RETURNS [interval: Interval] ~ {
interval ← SpaceIntervalFromVMInterval[VM.Allocate[count]];
};
Deallocate: PUBLIC PROCEDURE [interval: Interval] ~ {
VM.Free[VMIntervalFromSpaceInterval[interval]];
};
SpaceIntervalFromVMInterval: PROCEDURE [vmInterval: VM.Interval] RETURNS [interval: Interval] ~ {
interval.pointer ← VM.AddressForPageNumber[vmInterval.page];
interval.count ← vmInterval.count;
};
VMIntervalFromSpaceInterval: PROCEDURE [interval: Interval] RETURNS [vmInterval: VM.Interval] ~ {
vmInterval.page ← VM.PageNumberForAddress[interval.pointer];
vmInterval.count ← interval.count;
};
END.