Skip to main content

Full text of "xerox :: mesa :: 4.0 1978 :: listing :: Mesa 4 Microcode :: Mesa.bcpl Sep78"

See other formats


Mesa.bcpl 



2-Sep-78 17:21:54 



Page 1 



//Mesa.bcpl - BCPL setup for Mesa Emulator - R. Johnsson 
//last modified August 10, 1978 9:47 AM 

//bldr mesa format mboot mesa-noval m8sa-nova2 mesaram readpram gp timeconva timeconvb timeio 
//files mesaram and later may not be used after FindSpace() 

//incompatible microcode with version 15a; February 3, 1977 
//ROM compatible microcode with version 16a; February 18, 1977 
//incompatible microcode with version 18a; May 18, 1977 
//incompatible microcode with version 19a; May 27. 1977 
//new version numbering at 23.3 
//check file format at version 29; March 1978 



manifest [ MajorVersion = 29; MinorVersion • 16 ] 
manifest [ ImageVersionID = 03168 ] 
manifest [ printversion » true ] 

get "SysDefs.d" 
get "Streams. d" 
get "AUoFileSys.d" 

// OS routines 
external [ 

Gets; Puts; Resets; Ws; ReadBlock 

OpenFile; Closes; Endofs 

TruncateDiskStream 

MoveBlock; Zero 

RealDA; RealDiskDA 

MyFrame 

Junta; OsFinish 

Disabl einterrupts ; Enabl einterrupts 
OutLd; InLd 

GetCompleteFa; PositionPage 
] 

// OS statics 
external [ 

dsp 

keys 

sysDisk 

1 vUserFinishProc 
fpComCm; fpSysDir 
] 

manifest [ 

InterruptVector - ^501 
Displ aylnterruptWord * #421 
WakeupsWaiting = #452 
Active = #453 
PointerToBootMap = #24 
PuntData = #456 
Defaul tPriori ty = 13 
Swatlnter ruptLevel = 3 
SwatlnterruptBi t = #10 
TimeoutlnterruptLevel = 4 
TimeoutlnterruptBi t = #20 
Par i tylnterruptBi t = 1 
// These must match SDDefs.mesa 
SystemDispatch = #1060 
sGoingAway = #43 
sFirstProcess = #56 
sLastProcess = #56 
sProcessTrap - #57 
sFirstStateVector = #60 
] 



external 



Ramlmage 



//mesaram 



external 
external 
external 
external 
external 



[ SetupReadParam; ReadParam ] 



ReadPackedRAM; LoadPackedRAM 
FORMATN; CONCATENATE ] 
UNPACKDT; WRITEUDT ] 



EMLOOP 
MesaNoval 
MesaNovaSizel 
AClPtr 
AbsoluteTXV 



//gp 

] //readpram 
//format 

//ctime 
//mesa-nova 



Mesa. bcpl 



2-Sep"78 17:21:54 



Page 2 



CleanUpQueueUser 

RequeueSubUser 

WakeHeadlmplementer 

STOPUser 

AdvanceTimerPtr 

processTrapPtr 

f irstProcessPtr 

1 astProcessPtr 

f irstStateVectorPtr 

PScode 

MesaNova2 

MesaNovaSize2 

STOPImplementer 

CleanUpQueuelmpl ementer 

RequeueSublmplementer 

WakeHeadUser 

OSFPtr 

OutLdPtr 

InLdPtr 

FinishPtr 

FinProcPtr 

] 

external [ 
MBOOT 
SwatFl ag 
] 



//mboot 



manifest 
manifest 
manifest 
manifest 

static 
static 
static 
static 
static 
static 
static 



[ MesaStart=j^420] //Starting address in ram 
[ TXV=i^25 ] //Transfer Vector for Nova Code 
[ xNovaCode=/ifl74400 ] //Extended Nova Code 
[ MicrocodeOption=#l ] 

EmulateLoop; BootOata ] 
ImageCount=0 ] 
MFil eName; IFileName; IFile ] 
ram=true; bootf i 1 e-f a1 se ] 
PM1oc;Bnoc;PagesToSkip ] 
FirstBlock; ImageOptions ] 
giveimageversion = false ] 



structure string: [ length byte 

chartl,255 byte 

] 

structure BootMap: [ fp 0FP 

firstpage word 
addresstO.(255-lFP-l) word 

] 

manifest [ IBootMap » 256 ] 

structure Bltltem: [ 

f irstSourceMl word 
lastDest word 
minusCount word 

] 

structure BootList: [ 

pageMap word 
firstDa word 
initialState word 

bltt0,3 @BltItem // could be any number of these 
terminator word // « 0 

] 

manifest [ IBootList = size BootList/16 ] 

structure StateVector: [ 

stkt0,7 word 
instbyte byte 
fill bit 4 
stkptr bit 4 
X word 
Y word 

] 

manifest [ IStateVector «» size State\/ector/16 ] 



structure VersionStamp: [ 



Mesa. bcpl 



2-Sep-78 17:21:54 



zapped bit 1 
net bit 7 
host bit 8 
time: [ 

low word 
high word 
] 

] 



structure ImagePrefix: [ 

versionident word 
version ©VersionStamp 
creator QVersionStamp 
options word 
leaderDA word 
state QStateVector 
1 oadStateBase word 
initialLoadStateBase word 
type bit 2 
fin bit 5 

loadStatePages bit 9 

] 

manifest [ llmagePrefix = size ImagePref ix/16 ] 
manifest [ FirstlmageDataPage « 2 ] 
manifest [ // image types 

bootmesa « 0 

makeimage « 1 

checkfile = 2 

other « 3 

] 



structure Mapltem: [ 



page byte 
count bit 
tag bit 1 
da word 
base word 

] 

manifest [ 

1 normalMapItem » 1 
1 changeMapItem = 3 
] 



let Mesa( 1 ayout , up , cf a) be 
[Mesa 

let fl=vec 20; IFi leName=f 1 ; IFileNamelO=0 
let f2=vec 20; MFi leName=f 2 ; MFileNamel 0«0 



if printversion then Wri teVersion( ) 
IFile = 0 

until uplO eq 0 do 
[ 

if up>>UPE.type eq openStreams then 

[ IFile = upll; break ] 
up = up + up>>UPE . 1 ength 
] 

if IFile eq 0 then SetupParams{) 



//Load emulation state from image file 
let header = vec 1 ImagePref ix-1 
ReadImageBlock( header , 1 ImagePrefix) 

if gi veimageversion then 
[ 

WriteStamp(l V heade r>> ImagePref ix . version) 
Ws(", creator ") 

Wr iteStamp{ 1 V header >> ImagePr ef ix . creator) 

KeyboardWait{ ) 

] 

let imageCfa « vec lCFA-1 
GetCompleteFa( IFile , imageCfa) 



Mesa.bcp! 



2-S8P-78 17:21:54 



Page 4 



if header>>ImagePref IX. versionident ne ImageVersionID then 

AbortMsg( "*NIncorrect image file format.") 
if header>>ImagePref ix . type eq checkfile & 

header>>ImagePref ix. leaderDA ne imageCf a>>CFA.fp.leaderVirtua1Da then 
AbortMsg("*NThis Checkpoint file has been tampered with,") 

ImageOptions"header>>ImagePrefix. opt ions 

//read in the page address-count words until a 0 is found 
let PageMap»vec 250 
let Maplast«0 
for i«0 to 260 do 
[ 

PageMap I i= Read Image ( ) 
if PageMap li eq 0 then 
C 

Map! ast-i 

break 

3 

] 

PagesToSkipsQ //number of pages to skip in file 
LoadMesaMicrocode( ) 
FindSpace( PageMap .Maplast) 
//get stuff ready for page zero 

let bd = vec IBootList; BootData = bd; Zero(BootData, IBootList) 
FixMESANOVAO 

//find disk address of page Fi rs tImageDataPage of image file 
PositionPage(IFile, Fi rs tImageDataPage) 
GetCompleteFa(IFile, imageCfa) 

RealDiskDA(sysDisk , imageCf a>>CFA. f a . da, Iv FirstBlock) 

// set up bootmap 
[ 

QPointerToBootMap = PMloc 
MoveBlock( PMloc.lv ( imageCf a»CFA . f p ) . 1 FP) 
PMl oc>>BootMap . f irstpage = Fi rstlmageDataPage 
for i = 0 to PagesToSkip-1 do 

PMloc>>BootMap.addressti = PageMap I 0&^177400 
let a = PagesToSkip; 
let nexti = nil 
let i = 0 

until i eq Maplast do 
C 

let item = Iv (PageMapli) 
test item>>MapItem. tag 
ifso 
[ 

PMl oc>>BootMap . addressta = ( i tem>>MapItem. base Ishift 1) + 1 
PMloc>>BootMap . addresst(a+l) « item>>MapItem. da 
a = a + 2 

nexti = i+lchangeMapItem 
] 

ifnot nexti = i+lnormalMapItem 

let memaddress = i tem>>MapI tern. page Ishift 8 
for j = 1 to item>>MapItem. count do 

[ 

PMl oc>>BootMap . addressta = memaddress 
memaddress = memaddress + #400 
a « a + 1 
] 

i = nexti 
] 

PMloc>>BootMap . addressta « 0 

3 

Emul ateLoop=TXV 
FixAndMoveMBOOTO 

let inlvec » vec 15 
Fixlnterrupts{ intvec) 

let initialstate = xNovaCode+M8saNovaSize2 



Mesa.bcpl 



2-Sep-78 17:21:54 



Page 5 



MakeBUItem(l V BootData>>BootList . bUt3 , 

Iv header>>ImagePrefix. state, initial state , IStateVector) 
BootData>>BootList . initialState « initial state; 

@1 vUserFinishProc ■ FinishPtr 
Junta( levBasic , Go) 

]Mesa 

and Go() be 

[ BLloc(BootData) ] 

and SetupParamsO be 
C 

//Get switches From command line 

let StringVec»vec 100 

let SwitchVec=vec 100 

let GlobalSwitchVec^SwitchVec 

let comcm = OpenFile("Com.Cm" , ksTypeReadOnly , charltem, verLatest, f pComCm) ; 
Se tupRead Par am{ St r i ngVec, Sw i tchVec, comcm, Global SwitchVec) 

ImageCount=0 
let done » false 

let usename » false 

test ImageFile(Str ingVec) 
ifso usename=true 
ifnot 

if (GlobalSwitchVecIO ne 0) then for 1=1 to GlobalSwitchVeclO do 
[Swi tchLoop 

switchon GlobalSwi tchVec 1 1 into 
[Swi tchCases 
case $V: case $v: 
[V 

if not printversion then Wr iteVersion( ) 

giveimageversion = true 

endcase 

]V 

case $M: case $m: 
[M 

test LoadMesaMicrocode( ) 

ifso [ Ws( "♦NMicrocode loaded"); finish ] 

ifnot AbortMsg( "*NThis machine has extra ROM; can't use RAM") 
endcase 
]M 

case $S: case $s: 
[S 

@SwatFlag=/^77400 

endcase 

]S 

case $Q: case $q: 
CC 

done=true 

endcase 

3C 

case $B: case $b: 
[B 

bootf ile«true 

endcase 

]B 

default: 

[Huh 

Ws("*NBad switch encountered. ") 

endcase 

]Huh 

]Swi tchCases 
]Swi tchLoop 

let rewritecomcm = not usename 

// read the parameters 
test usename 

ifso CONCATENATE(IFileName.StringVec) 

ifnot 

until done do 



Mesa.bcpl 



2-Sep-78 17:21:54 



Page 6 



[paramloop 

let p « ReadParam($P, 0,0,0, true) 
if (p eq 0)7o(p eq -1) then break 
test SwitchVeclO eq 0 

ifso if IFileNamelO eq 0 then [ C0NCATENATE(IFi1eName,p) ; break ] 

if not 

[localswitches 

for I«l to SwitchVeclO do 

switchon SwitchVeclI into 

[ 

case $C: case $c: 

[ if IFileNamelO eq 0 then CONCATENATE(IFileName,p) ; 
done = true; 
endcase 

] 

case $1 : case $i : 

[ CONCATENATE(IFileName,p); endcase ] 
case $M: case $m: 

[ CONCArENATE(MFileName,p); endcase ] 
default: 

[ 

Ws(FORMATN("*NBad switch •<C>'. item will be ignored.". SwitchVeclI)) 

KeyboardWaitO 

] 

] 

31ocal switches 
]paraniloop 

if MFileNamelO ne 0 then Defaul tName(MF i 1 eName , "MESA" . "PRAM") 
if bootfile then 
C 

Def au 1 tName ( I F i 1 eName , "MESA" , "SV" ) 

LoadMesaMicrocode( ) 

let message = vec llnLdMessage 

let fp = vec IFP 

let cfa = vec ICFA 

let file = OpenFile(IFileName,ksTypeReadOnly,wordItem) 
if ((file eq 0)yu{file eq -1)) then 

AbortMsg(FORMATN("*NFile '<S>' not found. ". IFileName) ) 
GetCompleteFa( file, cfa) ; 
MoveBlock{fp, Iv cfa»CFA.fp. IFP) 
let realda = 0 

RealOiskDA(sysDisk , cf a>>CFA. f a. da, Iv realda) 

f p>>FP. leaderVirtualDa « realda 

messagell = #377 // level « -1, reason « proceed 

InLd(fp .message) 

3 

Def aul tName( IFi 1 eName . "Mesa" , "image" ) 

// maybe rewrite comcm here 
test rewritecomcm 
ifso 

[ let newcomcm = OpenFile( "Com.Cm" , ksTypeWriteOnly . charltem, verLatest, fpComCm) 
for i=l to IFi 1 eName>>str ing . 1 ength do 

Puts (newcomcm, IFi 1 eName>>str ing . charti) 
test Endofs( comcm) 

ifso Puts(newcomcm,$*N) 
ifnot Puts( newcomcm, $*S) 
until Endof s(comcm) do 

Puts (newcomcm, Gets (comcm) ) ; 
Closes(comcm) ; Closes(newcomcm) ; 

3 

ifnot Closes(comcm) 

IFi 1 e=OpenF 11 e( IFi 1 eName , ksTypeReadOnly , wordltem) 
if ((IFile eq 0)7o(IFile eq -1)) then 

AbortMsg(FORMATN("*NImage file '<S>' not f ound .", IFi 1 eName) ) 

] // end SetupParams 



Mesa.bcpl 



2-Sep-78 17:21:54 



Page 7 



and ImageFil e(nam8) » valof 
C 

let cap(c) ° ((c ge $a) & (c le $z)) ? c+$A-$a. c 

let s " vac 40 

s>>string . length « namelO 

for i " 1 to s>>string . 1 ength do 

s>>string . charti a nameli 
MoveBlock(name,s .namelO) 
s«". IMAGE" 

let ofs = name>>string . length-s>>string . length 
if ofs Is 0 then resultis false 
for i « 1 to s>>string . 1 ength do 

if cap(name»string.chart(of s+i)) ne s>>string . charti then resultis false 
resultis true 

] 

and FixAndMoveMBOOTO be 
C 

BootData>>BootList .pageMap « PMloc 
BootData>>BootList .f irstOa = FirstBlock 

MoveBlock(BLloc, MBOOT. 266); 

] 

and FixMESANOVAO be 
C 

if AbsoluteTXV ne TXV then 

AbortMsg{ "Code in Mesa-Nova incorrectly assembled") 
QOSFPtr = OsFinish 
@AClPtr « MesaStart 
@OutLdPtr = OutLd 
einLdPtr = InLd 

@FinProcPtr = SystemDi spatch+sGoingAway 

eprocessTrapPtr = SystemDispatch+sProcessTrap 

@f irstProcessPtr = SystemDi spatch+sF i rstProcess 

61 astProcessPtr = SystemDispatch+sLastProcess 

@f irstStateVectorPtr = SystemDispatch+sFirstStateVector 

eSTOPUser = STOPImpl ementer 

0C1 eanUpQueueUser = CI eanUpQueuelmpl ementer 

@RequeueSubUser = RequeueSublmpl ementer 

QWakeHeadUser = WakeHeadlmpl ementer 

MakeBltItem(lv BootData>>BootList , bl ttO , MesaNoval, TXV, MesaNovaSizel) 
// MoveBl ock (TXV, MesaNoval, MesaNovaSizel) 

MakeBl tltem(lv BootData>>BootList . bl ttl . MesaNova2. xNovaCode, MesaNovaSize2) 
// MoveBlock(TXV, MesaNova2, MesaNovaSize2) 

QPuntData = 0 

] 

and MakeBl tltem( item, source, dest, count) be 
[ 

item>>Bl titem. f irstSourceMl = source-1 
i tem>>Bl titem. 1 astDest = dest+count-1 

i tem>>Bl tItem.minusCount « -count \ 
3 

and F ixlnterrupts( v) be 
[ 

let t=6PScode - 2 
for i«0 to 14 do 

[ t=t+l; vli=t ] 

MakeB1tItem(l V BootData>>BootList . bl tt2 . v. InterruptVector . 16) 

Disabl ein terrupts( ) 

QDispl aylnterruptWord = SwatlnterruptBi t 
©Active = SwatlnterruptBit 

InterruptVector ISwatlnterruptLevel « In terruptVector 1 8 //SWAT and TIMER 

eWakeupsWai ting = 0 
Enabl elnterrupts( ) 

V ISwatlnterruptLevel « Inter ruptVector I SwatlnterruptLevel //SWAT and TIMER 
V ITimeoutlnterruptLevel = AdvanceTimerPtr 

] 

and let LoadMesaMi crocode( ) » valof 

[LoadMesaMicrocode 

let MBFile-0 



Mesa. bcpl 



2-Sep-78 17:21;64 



#377 do sink«ReaclIinage( ) 

//lO more pages in microcode 
MBFile«IFile; MFileName-IFileName ] 



let ramver ■ 0 

if userom() then resultis false 
test ImageOptions&MicrocodeOption 
if so 

C 

let sink=0 

until ( ImageCount&i^377) eq 
PagesToSkip"PagesToSkip+lO 
if MFileNamelO eq 0 then [ 
3 

ifnot if MFileNamelO eq 0 then 
C 

LoadPackedRAM{RamImage , Iv ramver) 

resultis true 

3 

if MBFile eq 0 then 

MBFile=OpenFi le(MFileName , ksTypeReadOnly , wordltem) 
if (MBFile eq 0) then 

AbortMsg(FORMATN("*N<S> not f ound . " , MFi 1 eName) ) 

let MBProblems=ReadPackedRAM( MBFile) 
if (MBProblems ne 0) then 
C 

Ws( FORMATN{ "*N<S> had some constant disagreements ,MF il eName) ) 

KeyboardWait( ) 
3 

if MBFile ne IFile then Closes(MBFile) 
]LoadMesaMicrocode 



and 
[ 



let useromO = valof 



let 



[ // (high , address , low) 
//STA 3 1 2 
//LDA 3 3 2 
//WRTRAM 
//LDA 3 12 
//JMP 1 3 

// (pointer . address) 
//sSTA 3 12 
//MOV 0 3 
//RDRAM 
//STA 0 0 3 
//LDA 3 12 
//JMP 1 3 



[ 



xl: 



manifest highword 
let writeone=table 
#55001 
#35003 
#61012 
#35001 
#1401 
3 

readone=table 
#55001 
#115000 
#61011 
#41400 
#35001 
#1401 
3 

testcode = table [ 
#14030; #102020; // 
#20; #170776; // 

3 

vers=table [ 
#61014 //VERS 
#1401 //JMP 1 3 

3 

let altotype = vers() rshift 12 

if altotype eq 4 % altotype eq 5 then resultis true 
let saveram = vec 3 
readone( saveram, highword+#776) ; 
readone( saveram+2 , hi ghword+#777 ) 
wri teone( testcodeI0,#776,testcodell); 
writeone( testcode I 2, #777, testcode 13 ) ; 
let isram = ((table [ #61010; #1401 ])(0,#777)); 
wr i teone( saver ami 0 ,#776 , saveram! 1 ) ; 
writeone( saveraml 2 ,#777 , saveraml3) ; 
if isram then resultis false 
resultis true 



let 



let 



AC0<-L. : START; 
L^ONE.SWMODE. 



xl; 



readone( saver am+1 ,#776) ; 
readone(saveram+3,#777) ; 



Mesa.bcpl 



2-Sep-78 17:21:54 



Page 9 



and let FindSpace(PageMap,Maplast) be 
[FindSpace 

//find space for boot loader and pagemap which does not interfere 

//with this program or the image to be loaded 

let InUse=vec 15 

Zero(InUse, 16) 

let bootListSize ■ 0 

let nexti « nil 

let i » 0 

until i eq Maplast do 
[ 

let item ■ Iv (PageMapli) 
test item>>MapItem. tag 
ifso 

C 

nexti « i+lchangeMapItem 
bootListSize = bootListSize + 2 
] 

ifnot nexti = i+1 normalMapItem 
let page, count - item>>MapItem. page , item>>MapItem. count 
bootListSize = bootListSize + count 
for j=page to page+count-1 do 

C 

let wd « j rshift 4 

InUsel(wd) = InUsel(wd) % (ji'lOOOOO rshift (j&i^l7)) 
] 

i = nexti 
] 

let lastpage=(MyFrame()-256) rshift 8 

let f irstpage=(RamImage+255) rshift 8 

let p = Al locPages(InUse, firstpage, lastpage, 1) 

BLloc = p Ishift 8 

if p ne 0 then 

p = Al locPages(InUse. p+1, lastpage, (bootListSize+256) rshift 8) 
PMloc = p Ishift 8 
if PMloc eq 0 then 

AbortMsg("*NCan' t find enough space for loader.*') 
JFindSpace 

and AnocPages(map » first, last, npages) ■ valof 
C 

let n = 0 

for i = first to last do 
C 

test (mapl(i rshift 4) & (j^'lOOOOO rshift (i & /^17))) eq 0 
ifso 

[ n = n + 1; if n eq npages then resultis i-n+1 ] 
ifnot n « 0 

] 

resultis 0 
] 

and Def aul tName{name , def name, def ext) be 
[Def aul tName 
if namelO eq 0 then 
[ 

CONCATENATE (name , def name, " . " . def ext) * 

return 

] 

for 1=1 to name>>string. length do 
[ 

if name>>string . charti eq $. then return 

] 

CONCATENATE ( name .name , " . def ext) 
]Def aul tName 

and let KeyboardWait( ) be 
[KeyboardWai t 

Ws(" [] ") 
let Char«Gets(keys) 
Puts(dsp,Char) 
switchon Char into 
C 

case $F: case $f : finish 



Mesa.bcpl 



2-Sep"78 17:21:54 



Page 10 



] 

]KeyboarclWait 



and AbortMsg(s) be 
[AbortMsg 

Ws(s) 

Resets(keys) 
KeyboardWaitO 
finish 
3AbortMsg 

and ReadImage()"va1of 
[Readlmage 

ImageCount«ImageCount+l 

if Endof s(IFile) then AbortMsg( "Premature end of image file.") 

resultis Gets(IFile) 

]ReadImage 

and ReadlmageBl ock(p , n) be 
[ReadlmageBlock 
ImageCount=ImageCount+n 
if ReadBlock(IFile,p,n) ne n then 
C 

AbortMsg( "Premature end of image file.") 

] 

]ReadImageBlock 

and Wr i teVersion( ) be 

[Wri teVersion 

Ws( 

FORMATN( "RunMesa <D>.<D>, microcode <D>*N", MajorVersion , MinorVersion . ©Ramlmage)) 
]Wri teVersion 

and Wri teStamp( v) be 
[Wri teStamp 

let uv = vec 6 

let dv = vec 1 

dvIO, dvll = v>>VersionStamp . time. high . v>>VersionStamp . time. low // reverse 

UNPACKDT(dv, uv) 

WRITEUDT{dsp,uv) 

Ws(FORMATN( " <B>j?^<B>i5^" . v»Vers ionStamp . net , v>>VersionStamp . host ) ) 
if v>>VersionStamp .zapped ne 0 then 
Ws(" zappedl") 
]WriteStamp