Inter-Office MemorandumToDistributionDateOctober 26, 1980FromRoy Levin, Richard JohnssonLocationPalo AltoSubjectOn the Harmonious Cooperation ofOrganizationPARC/CSL, OPD/SDDMesa and User MicrocodeXEROX Filed on: Doc>Microcode.bravo, .pressThis document describes an interface that permits users to load their own microcode into the RAMof an Alto II XM and execute it without interfering with the Mesa emulator. These facilities areavailable only on Alto II XM's with XMesa PROMs or with 3K RAM boards. When running on anAlto with the 3K RAM option, the following substitutions should be made in the remainder of thismemo: RAM1 replaces ROM1. RAM0 replaces RAM.Loading User MicrocodeThe Mesa emulator occupies all of ROM1 and about 143 words of RAM. The remainder of the RAMis available for use by client programs. To simplify loading of user microcode, a file containing theoverflow (RAM) portion of the Mesa emulator is included in the user's assembly, producing a singleoutput file that can be loaded in its entirety. Addressing requirements are specified in the file.The microcode normally loaded in the RAM by RunMesa includes some optional extensions so thatmany clients who loaded private microcode in the past may no longer need to do so. The includedfunctions are: Pup Checksum, IEEE floating point, and HBLT (used by Griffin). These microcodepackages use up all of the remaining RAM so that clients desiring additional microcode will have toeliminate one or more of these extensions.Assembly ProcedureUsers should carefully follow the steps below in constructing RAM images to be loaded under Mesa.1)Obtain XMesaOverflow.mu, XMesaRAM.mu, and Mesab.mu from the dump fileSystem>MesaMu.dm. (The dump file contains other files which should beignored.) The first two files are the actual microcode, the third contains the definitions forall registers and other symbols used by the Mesa emulator. If you want to retain any ofthe standard extensions you must get them from the dump file as well. The file names areFloat.mu, HBlt.mu and Checksum.mu.2)Rename XMesaOverflow.mu to be Driver.mu and add to the end a line of the form:#UserMicrocode.mu;user microcode source3)Delete one or more of the optional included files. If you delete Float.mu you must eitheruncomment the line ahead of it or provide your own implementation of the MISCinstruction.]gpi c8q]r -q7BrX ]q]r-q7Br Yq]r-q 7Br]WSsr N#qF+ Gr]t Fr trQ DZtr tr tr Btr @ A tr trtr tr Utilities>. RamDefs.mesa contains adequate documentation for the use of thispackage; the following Mesa code illustrates a typical use.BEGIN OPEN RamDefs;driver: MuImage _ ReadPackedMuFile["Driver.br"];IF LoadRamAndBoot[driver,FALSE] # 0 THEN SIGNAL BogusMicrocode;ReleaseMuImage[driver];END;The second parameter to LoadRamAndBoot controls whether a silent boot is performed andshould be FALSE unless it is necessary to alter the set of running tasks (as is required whenadditional device control microcode is initialized). LoadRamAndBoot returns the number ofmismatches between the constants specified in the microcode file and those present in the Alto'sconstants ROM. If this number is non-zero, the microcode cannot execute properly on this machine.Note to the nervous: Since RamLoad is a Mesa program, it must exercise caution to avoid smashing the emulator onwhich it is running. As long as the procedure above is meticulously followed in constructing Driver.br, RamLoad will beable to load the RAM without committing suicide.There and Back AgainThis section describes mechanisms for transferring control between the Mesa emulator and user-supplied microcode. It assumes that this microcode is, in effect, implementing "extendedinstructions", and the linkage mechanisms described are suitable for this purpose. Device drivermicrocode (e.g., for a Trident disk) executes in a different hardware task and therefore does notrequire these linkages.The hardware-defined linkage mechanism between control memory banks is somewhat precarious.Opportunities for errors arise because of the way the "next address" field of the microinstruction isinterpreted when SWMODE has been invoked (see section 8.4 of the Alto Hardware Manual). Thething to remember is that whether you are in ROM1 or RAM, to get to the other memory you mustspecify an address with the 400 bit on (i.e., BITAND[address,400B] = 400B). If you preservethis invariant, your Alto will probably avoid most black holes. Additional address restrictions are ineffect on 3K RAM Altos; see Alto Hardware Manual section 8.4. fu8Gbrwrwr wr^wrwrwr [wr6trtr YF X2I VV T>tr S< Ow Lrwr'w r Jt fr Gv DZwr$wr- B w rw r A wrw r/ ?d; <y zy :nzyzyzyz y 8zyzy zy zy 7z yzy 5x 2)rz r 0 yr. .4z r -3D + trT (`tqt3 '^qtqt %0 !u Qr%9 $5 O [ vr1  eG D! wrE o-trtr vrzr ` y tr vr  2>]{On the Harmonious Cooperation of Mesa and User Microcode3The Mesa MISC InstructionMesa has a bytecode, MISC, that is used to extend the Mesa bytecode set with special purposeinstructions. MISC takes an a-byte which specifies the operation to be performed. Some a valuesalready have defined meaning. These are recorded in System>MiscAlpha.mesa. To avoidconflict with "standard" extensions, e.g. floating point, users implementing strictly private functionsshould use a values larger than 200B. The a value 11B is filtered out by ROM1 and returns the AltoReal Time Clock. All other values are passed to microcode in the RAM. The MISC instruction operatesthis way only on version 41 microcode. In version 39 (released with Mesa 5.0) the MISC instruction always reads theclock regardless of the a value.The normal RAM microcode for MISC simply zeros the stack pointer and returns. The instructionlabeled MISC: in Driver.mu may be replaced by code to decode the a value. When control reachesMISC, the a value is in T. Control is returned to ROM1 by the sequenceSWMODE;sigh...SWMODE and TASK are both F1s:romnext;(... and we can't TASK here)romnext is defined in Mesab.mu, as are all the registers and other symbols used by the Mesaemulator.Setting Up a MISC in MesaThe easiest way to access microcode in the RAM is by declaring a procedure to invoke it as follows:alphaValue: CARDINAL = 100B;MyCode: PROCEDURE[arg1: AType, arg2: AnotherType]RETURNS [result: AThirdType] =MACHINE CODE BEGINMopcodes.zMISC, alphaValueEND;When MyCode is invoked, the arguments are pushed on the evaluation stack. Control will thenwind up at the location MISC in the RAM with alphaValue in T. The microcode is responsible forcomputing result and placing it on the stack (details appear below). The return sequencedescribed above will then cause execution to resume immediately after the invocation of MyCode.The Mesa JRAM InstructionNote: The MISC bytecode provides the function for which JRAM was originally intended. While JRAM isretained for compatibility, its use is discouraged.Mesa also has a bytecode, JRAM, that is a straightforward mapping of the Alto JMPRAM instruction.JRAM takes the top element off the stack and dispatches on it, doing a SWMODE in the sameinstruction. The microcode therefore looks approximately like this:JRAM: IR_sr17, :Pop;pops stack into L, T; returns to JRAMrJRAMr:SINK_M, BUS, SWMODE;L_0, :zero;Thus, at entry to whatever microcode JRAM jumps to, L=0 and T has the target address of thejump. fu8G bv{v ^rqr: ](qr |r&|r [!wr Y%vr. X2 |rtr|rtrtr V"trtqt U',qt S|t P4r tr qr= Nqrwr|r Lqr|r(tr Iw)# G) Dr wr= B ?v {v <\rtr5 9 z yF zXy 5zyF zyzXyzyz y04zyzyz yF02p00z yzX 0/!y +rzrA *+qrtrw rwr# ( zr9 &Xzr #v{v ? {v*{v{v 3 Irqr0qr qr@wr D w )"   ] r%qr g >[{On the Harmonious Cooperation of Mesa and User Microcode4Getting back to ROM1 is equally straightforward. User microcode should terminate with:SWMODE;sigh...SWMODE and TASK are both F1s:romnextA;(... and we can't TASK here)romnextA is defined in MesabROM.mu, as are all the registers and other symbols used by theMesa emulator.The safest way to force a microinstruction to a specific address in the RAM is to use MU's '%' pre-definition facility. For example,%1,1777,540,MyCode;MyCode:. . . ;start of user-written microcodewould enable the Mesa procedure MyCode (defined just below) to transfer control to themicrocode at MyCode.Setting Up a JRAM in MesaThe easiest way to access microcode in the RAM is by declaring a procedure to invoke it as follows:locationInRAM: CARDINAL = 540B;MyCode: PROCEDURE[arg1: AType, arg2: AnotherType]RETURNS [result: AThirdType] =MACHINE CODE BEGINMopcodes.zLIW, locationInRAM/256, locationInRAM MOD 256;Mopcodes.zJRAMEND;When MyCode is invoked, the arguments are pushed on the evaluation stack, then a transfer tolocation 540B in the RAM occurs. The microcode is responsible for computing result and placing iton the stack (details appear below). The return sequence described above will then cause executionto resume immediately after the invocation of MyCode.Note: A few locations in the RAM are already used as entry points from the emulator microcode in ROM1. Althoughno firm convention has been established, user microcode that avoids RAM addresses in the ranges 400B-477B and 600B-677B is unlikely to experience compatibility problems in the future.The Mesa StackThe Mesa stack is implemented by 8 S-registers named stk0, stk1, ..., stk7, with stk0 being thebase of the stack. An R-register, stkp, indicates the number of words on the stack and is thus inthe range [0..8]. To obtain values from the stack in the general case, therefore, requires a dispatchon stkp, but there is an important special case. If MyCode is invoked in a statement context (i.e.,one in which it stands alone and is not a term of an expression), the stack will be empty except forarg1 and arg2, which will therefore appear in stk0 and stk1, respectively. In this case stkpwill be 2 at entry, and the microcode should set it to 1 before returning to ROM1. result shouldalso be stored in stk0. It is frequently useful to restrict the use of MyCode to statement contextsso that the microcode can take advantage of the known stack depth. Note: this assumes that values oftype AType, AnotherType, and AThirdType are each represented in a single word. Multi-word quantities are stored inadjacent stack words, with consecutive memory cells being pushed in increasing address order. fu8G brtrC ^w)# ]( ) Yr w r8 X2 THtr wr S<" Ow L ) IPrzr0 G wr DZv {v A rtr5 =z yF zXy :nzyF zyzXyzyz y08zyzyz yF0705xz yzXyzyzy03z 02)y .rzr> -3 trtr,zr +Y ).zr &t[ %X=+ %%X0 #D v 7r5wrwr #wr: #C Awr.zr vr U zrzr!xrxrx Kr3!zr wr2zr Bt! x}t} t} tL ] =[^kOn the Harmonious Cooperation of Mesa and User Microcode5An argument or return record may not exceed 5 words in length. If you need more arguments youshould pass a pointer. We believe that it is relatively easy to allow arguments up to 6 words. It may be possible toallow up to 8 words in the future.Other Emulator StateThe Mesa emulator has a number of temporary registers that may be freely used by code enteredvia MISC or JRAM. The following list identifies all registers used by the Mesa emulator, theirintended function, and whether they may be used as destroyable temporaries by user-supplied RAMmicrocode:RegisterTypeDestroyableFunctionby RAM codempcRNoprogram counterstkpRNostack pointerXTSregRNoXfer trap statusibRNoinstruction bytebrkbyteRNoXfer state variable; overlaps AC3clockregRNohigh resolution clock bitsmxRYestemporary during Xfer; overlaps AC2saveretRYesholds return dispatch values; overlaps AC1newfieldRYesused by field instructions; overlaps AC0countRYestemporary for countingtaskholeRYestemporary for holding things across TASKstempRYesgeneral temporarytemp2RYesgeneral temporarylpSNolocal frame pointer (+6)gpSNoglobal frame pointer (+4)cpSNocode segment pointerstk0-7SNo8 evaluation stack registerswdcSNowakeup disable counter (interrupt control)ATPregSYesalloc trap parameterXTPregSYesxfer trap parameterOTPregSYesother trap parametermaskSYesused by field instructions; smashed by BITBLTindexSYesused by field instructions; smashed by BITBLTalphaSYestemporary for alpha byte; smashed by BITBLTentrySYesXfer and field temporary; smashed by BITBLTframeSYesALLOC/FREE temporary; smashed by BITBLTmySYesXfer temporary; smashed by BITBLTunused1SYessmashed by BITBLTunused2SYessmashed by BITBLTunused3SYessmashed by BITBLTUser microcode should endeavor to TASK within 5 microcycles of entry. It should also TASK asclose to the end as possible. Ideally, the penultimate instruction before returning to the emulator would TASK, butunfortunately SWMODE must appear in the same instruction and both are F1s. The Mesa emulator tries toTASK at least every 12 microcycles; user microcode should observe the same guideline.The Mesa emulator does not check for pending interrupts on every instruction. It does so onlywhen it must fetch a new instruction word from memory. Therefore, user microcode that sets apending interrupt condition must not expect that the interrupt will be noticed by the emulator fu8G br^ `vtL ^" [v X2r:# VqrqrN T[t Swr!@)*@=vwr!@)(@;wr!@)@:nwr!@))@8wr!@)@7fwr!@)@4^wr!@)@2wr!@)@1Uwr!@)@/wr!@)@.Mwr!@)*@+Ewr!@)@)wr!@)@(=wr!@)@&wr!@)-@%5wr!@)-@#wr!@)+@"-wr!@)+@ wr!@)'@%wr!@)!@wr!@)@wr!@)@wr!@) "wr*wr t4qt w qt$r wrQ :$ V 30. x =^On the Harmonious Cooperation of Mesa and User Microcode6immediately upon return to ROM1.Distribution:Mesa UsersCedar GroupMesa Group fu8G brtr [ YX X2 V  VC)* TIMESROMAN  HELVETICA TIMESROMAN LOGO TIMESROMAN TIMESROMAN  TIMESROMAN  HELVETICA GACHA   HELVETICA  HELVETICA   HELVETICA HIPPO   TIMESROMAN "&(j/+)#yMicrocode.bravoJohnssonOctober 26, 1980 4:29 PM