-- File: CommUtilDefs.Mesa, Last Edit: Sandman February 7, 1980 8:48 AM

-- Copyright Xerox Corporation 1979, 1980

DIRECTORY
ControlDefs: FROM "ControlDefs" USING [FrameHandle, returnOffset],
ImageDefs: FROM "ImageDefs" USING [CleanupItem, AllReasons],
Mopcodes: FROM "Mopcodes" USING [zLIW, zGADRB, zKFCB, zLLB, zR0],
BcplOps: FROM "BcplOps" USING [CleanupReason],
ProcessDefs: FROM "ProcessDefs" USING [Ticks, Priority, InterruptLevel],
SDDefs: FROM "SDDefs" USING [sCopy, sUnNew];

CommUtilDefs: DEFINITIONS =
BEGIN

-- Heap Allocation
AllocateLockedNode: PROCEDURE [CARDINAL] RETURNS [POINTER];
AllocateHeapNode: PROCEDURE [CARDINAL] RETURNS [POINTER];
FreeHeapNode: PROCEDURE [POINTER];
AllocateHeapString: PROCEDURE [CARDINAL] RETURNS [STRING];
FreeHeapString: PROCEDURE [STRING];

-- IOCB Allocation
AllocateIocbs: PROCEDURE [CARDINAL] RETURNS [LONG POINTER];
FreeIocbs: PROCEDURE [LONG POINTER];

-- Page Allocation
AllocateSegment: PROCEDURE [nwords: CARDINAL] RETURNS [base: POINTER];
FreeSegment: PROCEDURE [base: POINTER];
AllocateHyperspace: PROCEDURE [nwords: CARDINAL] RETURNS [base: POINTER];
FreeHyperspace: PROCEDURE [base: POINTER];

-- Locking Code + Data
LockCode: PROCEDURE [UNSPECIFIED];
UnlockCode: PROCEDURE [UNSPECIFIED];
LockData: PROCEDURE [LONG POINTER];
UnlockData: PROCEDURE [LONG POINTER];

-- New + UnNew things
-- These POINTERs should really be GlobalFrames,
-- but that gets mixed up with POINTER TO FRAME
GlobalFrame: PROCEDURE [UNSPECIFIED] RETURNS [POINTER];
MyGlobalFrame: PROCEDURE RETURNS [POINTER] = MACHINE CODE
BEGIN
Mopcodes.zGADRB, 0;
END;
Copy: PROCEDURE [POINTER] RETURNS [POINTER] = MACHINE CODE
BEGIN
Mopcodes.zKFCB, SDDefs.sCopy;
END;
UnNew: PROCEDURE [POINTER] = MACHINE CODE
BEGIN
Mopcodes.zKFCB, SDDefs.sUnNew;
END;
SelfDestruct: PROCEDURE;
IsBound: PROCEDURE [UNSPECIFIED] RETURNS [BOOLEAN];

-- Clocks
GetClock: PROCEDURE RETURNS [ms: LONG CARDINAL];
-- BEWARE: This can jump wildly if we reset the time
GetSeconds: PROCEDURE RETURNS [CARDINAL] =
MACHINE CODE BEGIN
Mopcodes.zLIW, 573B/400B, 573B MOD 400B;
Mopcodes.zR0;
END;
GetTicks: PROCEDURE RETURNS [CARDINAL] =
MACHINE CODE BEGIN
Mopcodes.zLIW, 430B/400B, 430B MOD 400B;
Mopcodes.zR0;
END;
msPerTick: CARDINAL = 39; -- not ProcessDefs.TimerGrain

-- Interface to StringDefs
AppendChar: PROCEDURE [STRING,CHARACTER];
AppendString: PROCEDURE [to, from: STRING];
AppendLongNumber: PROCEDURE [STRING,LONG INTEGER,CARDINAL];

-- Interface to Process/ProcessDefs
Ticks: TYPE = ProcessDefs.Ticks;
Detach: PROCEDURE [UNSPECIFIED];
Yield: PROCEDURE;
MsecToTicks: PROCEDURE [CARDINAL] RETURNS [Ticks];
SetTimeout: PROCEDURE [LONG POINTER TO CONDITION, Ticks];
DisableTimeout: PROCEDURE [LONG POINTER TO CONDITION];
InitializeCondition: PROCEDURE [LONG POINTER TO CONDITION, Ticks];
InitializeMonitor: PROCEDURE [LONG POINTER TO MONITORLOCK];

-- More Process/ProcessDefs stuff for Device Drivers
SetPriority: PROCEDURE [Priority];
AssignInterruptLevel: PROCEDURE [hint: InterruptLevel] RETURNS [InterruptLevel];
AddInterruptHandler: PROCEDURE [InterruptLevel, POINTER TO CONDITION, WORD];
RemoveInterruptHandler: PROCEDURE [InterruptLevel];
GetEthernetHostNumber: PROCEDURE RETURNS [CARDINAL];
Priority: TYPE = ProcessDefs.Priority;
InterruptLevel: TYPE = ProcessDefs.InterruptLevel;
-- Parity Process runs at Pritority 7, and uses InterruptLevel 0
-- Swat watcher and TOD clock uses InterruptLevel 3
-- Timeout process uses InterruptLevel 4
-- Keyboard Process run at Pritority 6, and uses InterruptLevel 7
-- AltoEthernet drivers run at Pritority 5, and use InterruptLevels 5, 6, and 8
-- PacketRadio driver runs at Priority 4 and uses InterruptLevels 9 and 10
-- Bob Bell (ASD) is using Pritority 3 and InterruptLevels 9 and 10 for other lines
-- AltoSLA driver runs at Pritority 3, and uses InterruptLevel 12
-- ReadDisk runs at normal Pritority, and uses InterruptLevel 13
-- Gateway Dispatcher runs at Pritority 2

-- Debugging things
FrameHandle: TYPE = ControlDefs.FrameHandle;
GetReturnFrame: PROCEDURE RETURNS [FrameHandle] = MACHINE CODE
BEGIN
Mopcodes.zLLB, ControlDefs.returnOffset;
END;
AddCleanupProcedure: PROCEDURE [POINTER TO CleanupItem];
RemoveCleanupProcedure: PROCEDURE [POINTER TO CleanupItem];
CleanupItem: TYPE = ImageDefs.CleanupItem;
CleanupReason: TYPE = BcplOps.CleanupReason;
AllReasons: CARDINAL = ImageDefs.AllReasons;

-- Other goodies
Zero: PROCEDURE [POINTER,CARDINAL];

-- This is a hack for debugging
SetDebuggingPointer: PROCEDURE [LONG POINTER];
magicMemoryLocation: POINTER = LOOPHOLE [612B];

END.