Inter-Office MemorandumToDistributionDateApril 16, 1979FromRoy LevinLocationPalo AltoSubjectOn the Harmonious Cooperation ofOrganizationPARC/CSLXMesa and User Microcode (version 3)XEROX Filed on: [Ivy]Doc>Microcode.bravo (and .press)This 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 under XMesa. Higher-level facilities of XMesa are described in a separate documentfiled on [Ivy]Doc>XMesa.press (and .bravo).Loading User MicrocodeThe XMesa emulator occupies all of ROM1 and about 105 words of RAM. The remainder of theRAM is available for use by client programs. To simplify loading of user microcode, a filecontaining the overflow portion of the XMesa emulator is included in the user's assembly,producing a single output file that can be loaded in its entirety. Addressing requirements arespecified in the file; no locations are reserved "by convention" alone. Assembly ProcedureUsers should carefully follow the steps below in constructing RAM images to be loaded underXMesa.1)Obtain MesaXRAM.mu, MesaBLTLreal.mu, and MesabROM.mu from the dump file[Ivy]System>XMesaMu.dm. The first tow files are the actual microcode, thethird contains the definitions for all registers and other symbols used by the Mesaemulator.2)Prepare a source file, Driver.mu, of the following form:#AltoConsts23.mu;standard Alto definitions; Sufficient pre-definitions must be inserted here to; reserve locations 0-17 inclusive.#MesaXRAM.mu;includes MesabROM internally#MesaBLTLreal.mu;full implementation of BLTL#UserMicrocode.mu;user microcode source3)Assemble Driver.mu with MU, obtaining Driver.mb .]gpi c8q]r -q7BrX ]q]r-q7Br Yq]r-q 7Br]W$Ssr N"qF6 Gr?! FQ DX=% B2 >t ;>r1( 9@ 78! 6F*4 4H 1Ou .r> ,X) v rvrv r'avr%&-$ vrsv,@#5{#+ ,@,@,@rvrvrE=ZOn the Harmonious Cooperation of XMesa and User Microcode24)Use the PackMU subsystem to convert Driver.mb to Driver.br .The code in MesaXRAM.mu must be assembled to begin at RAM location 20. The user must assurethis condition by including a predefinition (with no omitted labels) at the indicated place inDriver.mu; e.g.,%17,1777,0,L0,L1,L2,L3,L4,L5,L6,L7,L10,L11,L12,L13,L14,L15,L16,L17;If the user microcode includes the code to control a non-standard I/O device (e.g., a Trident disk),at least one of the labels in this predefinition will refer to an instruction used as part of the silentboot sequence (see Alto Hardware Manual, sections 2.4, 8.4, and 9.2.2). Prudence suggests that thelocations corresponding to tasks that are not intended to execute in the RAM be filled in withdummy instructions of the formLi:TASK, :Li;Thus, if Driver.mu contains no device control microcode, L0-L17 should all have this form. Ifthere is a space crunch, however, locations 0-17 may be used for ordinary microcode, though this is usually unnecessary. Loading ProcedureDriver.br can now be loaded using the (Mesa) RamLoad package. The facilities of this packageare defined in RamDefs.bcd, and are exported by the module RamLoad.bcd. These files may allbe found on [Ivy]Utilities. RamDefs.mesa contains adequate documentation for the useof this package; 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 thismachine.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.Obtaining More RAM SpaceThe implementation of BLTL in microcode can be removed to recover approximately 26 words ofRAM space, as described below. Clients should weigh this option carefully, since BLTL is normallyused by the XMesa swapper to move blocks of words (particularly code segments) between memorybanks. The swapper can survive without BLTL, but its performance is degraded.To eliminate BLTL from the RAM, retrieve the file MesaBLTLfake.mu from[Ivy]System>XMesaMu.dm and include it in Driver.mu in the place ofMesaBLTLreal.mu. Nothing else in Driver.mu should be changed. ft9Gbr$vrvr ^ v r' ]'+3 [vr X0vC Tr22 S9R QQ OY NA J GvrHw E`r Bu ?]vr#1 =v rv r < $v r, :eC 7xF yXx 5nyxyxyxy x 3yxyxF yXxFyXx 2y xyx 0v -'ry r + xr. )4y r (/D &@ $ !wj R] 0 u wrR  X '(5 N 0,vr vrxvr y vrvr P >[qROn the Harmonious Cooperation of XMesa and User Microcode3There 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 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 youmust specify 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.The Mesa JRAM InstructionMesa has a bytecode, JRAM, that is a straightforward mapping of the Nova 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.Getting 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,440,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 = 440B; ft9G b ^r%9 ]'$5 [O Y ur1 X/ TG S8@! Q5' OT N@$ur/ L? IIu Er= DRD BD ?[v ) =  < 8rE 7 3W 0vv)# . ) +rv r ) & U $" !v A ) ryr0 J vr u rM ]y xF yXx >X On the Harmonious Cooperation of XMesa and User Microcode4MyCode: 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 440 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 400-477 and 600-677 isunlikely 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.An argument or return record exceeding 5 words in length requires special handling that is beyondthe scope of this document. See Roy Levin for details.Other Emulator StateThe Mesa emulator has a number of temporary registers that may be freely used by code enteredvia JRAM. The following list identifies all registers used by the Mesa emulator, their intendedfunction, 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 temporary ft9G byxF yxyXxyxy xFyXxyxy xF``v`^y xyXxyxyx`]&y `[~x X/ryr> VA yr TY S7.yr P w[ NT" M&< Iu Fr5vrvrvrvr D#vr& C8f Avr.yr$ur ?U >@yryr!vrvrv  >w= =Er ;sU 8$:$ 6|V 40. 3, , *X )> '  'O=@ TIMESROMAN  HELVETICA TIMESROMAN LOGO TIMESROMAN  TIMESROMAN GACHA  TIMESROMAN HELVETICA  HELVETICA   TIMESROMAN Y!j/$"BMicrocode.bravoLevinApril 16, 1979 9:04 PM