// GatewayInit.bcpl -- initialization for Gateway.bcpl
// Last modified July 9, 1982  10:57 AM by Taft

get "AltoDefs.d"

external
[
// outgoing procedures
InitGateway

// incoming procedures
CreateMiscServ; CreateEchoServ; InitPupLevel1; InitEFTPPackage
CreateGateConServ; CreateStatServ; ReadGateParam
PupChecksum; UPupChecksum; LoadRam; InitBcplRuntime
InitializeZone; Allocate; CallSwat; Block
InitializeContext; MyFrame; MoveBlock; Zero

// outgoing statics
ctxQ

// incoming statics
lvSysZone; sysZone; lvIdle
GateRamImage; etherMcLoaded
]

static ctxQ

manifest stackLimit = 335b

//----------------------------------------------------------------------------
let InitGateway() be
//----------------------------------------------------------------------------
[
MoveBlock(431b, table [ 0; 0; 61167b; 102444b; 132446b; 113444b; 62447b; 0;
 0; 52224b; 52524b; 52510b; 52710b; 24510b; 0; 0 ], 16)

let freeBegin = @stackLimit
let freeEnd = MyFrame() -1500
@stackLimit = freeEnd
test freeEnd-freeBegin gr 0
   ifso sysZone = InitializeZone(freeBegin, freeEnd-freeBegin)
   ifnot sysZone = InitializeZone(freeEnd-77777b, 77777b)
@lvSysZone = sysZone

let dcb = Allocate(sysZone, 4, false, true); Zero(dcb, lDCB)
dcb>>DCB.background = 1
@displayListHead = dcb

if LoadRam(GateRamImage, true) ne 0 then CallSwat("LoadRam failed")
PupChecksum = UPupChecksum
etherMcLoaded = 1  // one extra ethernet
InitBcplRuntime()

ctxQ = Allocate(sysZone, 2); ctxQ!0 = 0
@lvIdle = Block
InitPupLevel1(sysZone, ctxQ, 0, 0, 128)
InitEFTPPackage(sysZone)
CreateEchoServ(sysZone, ctxQ)
CreateMiscServ(sysZone, ctxQ)
CreateStatServ(sysZone, ctxQ)
CreateGateConServ()
ReadGateParam()	// must FOLLOW server initialization
]