// PupAlImp.decl -- declarations specific to Alto Imp (96-bit leader version)
// Copyright Xerox Corporation 1983

// Last modified August 20, 1983  12:25 PM by Taft

manifest
[
maxImpMessBits = 96+	// Leader
		8064+	// Maximum data bits per message
		16	// Imp end-of-message padding
maxImpMessWords = (maxImpMessBits+15)/16  // Maximum Alto words per message
maxLinkNCP = 71		// Highest NCP link
linkPup = 152		// Pup link number in Arpanet
linkInternet = 155	// Arpa Internet link
firstFakeHost = 252	// Fake host numbers start here
]


// Imp message structures

//----------------------------------------------------------------------------
structure ImpLeader:	// Imp-Host protocol leader (new format)
//----------------------------------------------------------------------------
[
blank bit 4		// word 0
format bit 4
net bit 8
blank bit 4		// word 1
trace bit 1
leaderFlags bit 3
messageType bit 8
handlingType bit 8 =	// word 2
   [ highPriority bit ]
host bit 8
imp bit 16		// word 3
messageID bit 12 =	// word 4
   [ link bit 8; linkX bit 4 ]
subType bit 4
messageLength bit 16	// word 5
data word 0		// start of encapsulated Pup, IP, or whatever
]
manifest lenImpLeader = size ImpLeader/16

//----------------------------------------------------------------------------
structure IPHeader:	// ARPA Internet protocol header
//----------------------------------------------------------------------------
[
version bit 4
headerLength bit 4	// in units of 32 bits
typeOfService byte
length word		// in bytes
identification word
flags bit 3 =
   [
   reserved bit
   dontFragment bit
   moreFragments bit
   ]
fragmentOffset bit 13	// in units of 64 bits
timeToLive byte		// seconds
protocol byte
headerChecksum word
sourceAddress word 2
destinationAddress word 2
options word 0
]

manifest
[
versionIP = 4		// current IP version number

ipICMP = 1		// Internet Protocol numbers
ipGGP = 3
ipTCP = 6
ipPup = 12
ipUDP = 17
]

// Data structures

//----------------------------------------------------------------------------
structure ImpPBI:	// Arpanet "encapsulation"
//----------------------------------------------------------------------------
// This is not how data is actually encapsulated on the Arpanet; but the 6-word
// Imp leader is too large to fit in the PBI space reserved for encapsulation.
// The interrupt-level code converts between this representation and the
// actual 96-bit leader on the fly.
// Note: contrary to normal practice, the PBI.packetLength refers only to the
// encapsulated data.  It MAY include one word of Imp padding at the end.
[
blank word offset PBI.encapsulation/16
link byte
host byte
imp word
data word 0 = pup @Pup = ip @IPHeader
]

//----------------------------------------------------------------------------
structure Q: [ head word; tail word ]  // Queue header (for Queue Package)
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
structure ImpStatus:	// Imp status word
//----------------------------------------------------------------------------
[
microcode byte		// microcode status
hardware byte =		// hardware status
   [
   blank bit 5
   impWasDown bit
   impNotReady bit
   hostNotReady bit
   ]
]

//----------------------------------------------------------------------------
structure ImpNDB:	// Arpanet NDB
//----------------------------------------------------------------------------
[
@NDB			// standard portion
iPBI word		// -> current input PBI
oPBI word		// -> current output PBI
oQ @Q			// Queue of pending output PBIs
flags word =
   [
   oActive bit		// Output is in progress
   iError bit		// Ready line dropped during input packet
   oError bit		// Ready line dropped during output packet
   sendingNop bit	// Nop being transmitted
   ]
status @ImpStatus	// status from last call to UpdateStatus
icb word		// -> Imp Control Block
zone word		// -> zone from which NDB allocated
ctx word		// -> housekeeping context
ctxQ word		// -> ctxQ on which context put
iLeader @ImpLeader	// Imp leader for input packet
oLeader @ImpLeader	// Imp leader for output packet
]
manifest lenImpNDB = size ImpNDB/16

// Imp interface hardware and microcode definitions

//----------------------------------------------------------------------------
structure ICB:		// Imp Control Block -- must be even-word aligned
//----------------------------------------------------------------------------
[
control word		// Control command
blank word
inputPointer word	// -> beginning of input buffer
inputEnd word		// -> word beyond end of input buffer
outputPointer word	// -> beginning of output buffer
outputEnd word		// -> word beyond end of output buffer
controlPost @ImpStatus	// Control post location
controlChanMask word	// Control interrupt channel mask
inputPost @ImpStatus	// Input post location
inputChanMask word	// Input interrupt channel mask
outputPost @ImpStatus	// Output post location
outputChanMask word	// Output interrupt channel mask
]
manifest lenICB = size ICB/16

manifest
[
// SIO commands for Imp control
impStartOutput = 1000B	// Start output
impStartInput = 2000B	// Start input
impControlStatus = 3000B  // Control/Status

// Imp Control commands
icNoop = 0
icMasterReset = 1	// Clear wakeups, turn off transfers, but don't
			// touch the Host Ready relay
icSetLastWord = 2	// Set Last Word flipflop -- for microcode use only
icClearImpWasDown = 3	// Try to clear Imp Was Down flipflop
icLoopBackOn = 4	// Turn on Loop Back mode
icLoopBackOff = 5	// Turn off Loop Back mode
icHostReadyOn = 6	// Turn on Host Ready relay
icHostReadyOff = 7	// Turn off Host Ready relay
icEndPacketOn = 2000B	// Turn on End of Packet flipflop
icEndPacketOff = 1000B	// Turn off End of Packet flipflop

// Microcode status byte values
isDone = 1		// Input or output completed normally
isInputOverflow = 2	// Input buffer full
isInputLengthZero = 3	// Input buffer length was zero at start of packet
isInputFullAndEnd = 4	// Input buffer full and end of packet simultaneously
]