;Alto->8086 small-c compiler rev 2.0
C←CODE SEGMENT

$INCLUDE(8086LIB.D)

$INCLUDE(rpcbonsai.DEC)

ASSUME CS:C←CODE, DS:C←DATA

; #include <Signal.h>

; extern int Call();

; extern int *mySoc;

; extern StartCall();

; extern int RejectUnbound;

; extern struct PBI *GetPBI();

; extern ReleasePBI();

; extern DISABLE();

; extern ENABLEWithFrame();

; extern SIGNAL();

; extern Call1();

; extern CallersFrame();

; extern MoveBlock();

; extern MyFrame();

; static UnwindPkt(sig, code, seal)
←UnwindPkt:

;   int sig, code;

;   struct Seal1 *seal;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   ReleasePBI(seal->data[0]);

;	BX ← ←seal
POP BX
PUSH BX
ADD BX,4
MOV CX,[BX]
MOV BX,CX
CALL ←ReleasePBI

;   DISABLE(seal);

;	BX ← ←seal
POP BX
PUSH BX
CALL ←DISABLE

;   };
MOV SP,BP
POP BP
RET;

; static struct PBI

; *GetUnwindPkt(seal)
←GetUnwindPkt:

;   struct Seal1 *seal;
PUSH BP
MOV BP,SP
PUSH BX

;   {

;   struct PBI *pkt;
PUSH DX

;   pkt = GetPBI(mySoc);
MOV BX,←mySoc
CALL ←GetPBI

;	←pkt ← BX
POP DX
PUSH BX

;   ENABLEWithFrame(UNWIND, &UnwindPkt, seal, CallersFrame(MyFrame()));
MOV BX,1
PUSH BX
MOV BX,OFFSET ←UnwindPkt
PUSH BX
CALL ←MyFrame
CALL ←CallersFrame

;	CX ← ←seal
MOV CX,[BP-2]
CALL ←ENABLEWithFrame
ADD SP,4

;   seal->data[0] = (int) pkt;

;	BX ← ←seal
MOV BX,[BP-2]
ADD BX,4

;	CX ← ←pkt
POP CX
PUSH CX
MOV [BX],CX

;   return (pkt);

;	BX ← ←pkt
POP BX
PUSH BX
MOV SP,BP
POP BP
RET;

;   };

; int *StartBonsai(interface, seal)
←StartBonsai:

;   struct ImportInstance *interface;

;   struct Seal1 *seal;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   struct PBI *pkt;

;   struct Header *hdr;
ADD SP,0FFFCX

;   pkt = GetUnwindPkt(seal);

;	BX ← ←seal
MOV BX,[BP-4]
CALL ←GetUnwindPkt

;	←pkt ← BX
MOV [BP-6],BX

;   StartCall(pkt, interface, interface->currentConversation);

;	BX ← ←pkt
MOV BX,[BP-6]
PUSH BX

;	BX ← ←interface
MOV BX,[BP-2]
MOV CX,[BX+2]
MOV BX,CX

;	CX ← ←interface
MOV CX,[BP-2]
CALL ←StartCall
POP DX

;   hdr = pkt->pup;

;	BX ← ←pkt
MOV BX,[BP-6]
MOV CX,[BX+6]

;	←hdr ← CX
POP DX
PUSH CX

;   return(&hdr->callData.words[0]);

;	BX ← ←hdr
POP BX
PUSH BX
ADD BX,028X
MOV SP,BP
POP BP
RET;

;   };

; CallBonsai(seal, arglen)
←CallBonsai:

;   struct Seal1 *seal;

;   int arglen;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   Call(seal->data[0], arglen, maxDataLength);

;	BX ← ←seal
MOV BX,[BP-2]
ADD BX,4
MOV CX,[BX]
PUSH CX
MOV BX,076X

;	CX ← ←arglen
MOV CX,[BP-4]
CALL ←Call
POP DX

;   };
MOV SP,BP
POP BP
RET;

; CleanupCall(seal)
←CleanupCall:

;   struct Seal1 *seal;
PUSH BP
MOV BP,SP
PUSH BX

;   {

;   ReleasePBI(seal->data[0]);

;	BX ← ←seal
POP BX
PUSH BX
ADD BX,4
MOV CX,[BX]
MOV BX,CX
CALL ←ReleasePBI

;   DISABLE(seal);

;	BX ← ←seal
POP BX
PUSH BX
CALL ←DISABLE

;   };
MOV SP,BP
POP BP
RET;

; int BonsaiDispatcher(pkt, newLength, conversation, sSpecsT)
←BonsaiDispatcher:

;   struct PBI *pkt;

;   int newLength;

;   int *conversation;

;   struct SSpecsTable *sSpecsT;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   int rout, argLen, *wp;

;   int thisProc;

;   struct Header *hdr;
ADD SP,0FFF6X

;   hdr = pkt->pup;

;	BX ← ←pkt
MOV BX,[BP+6]
MOV CX,[BX+6]

;	←hdr ← CX
POP DX
PUSH CX

;   wp = &hdr->callData.words[0];

;	BX ← ←hdr
POP BX
PUSH BX
ADD BX,028X

;	←wp ← BX
MOV [BP-10],BX

;   rout = Swab(*wp);

;	DI ← ←wp
MOV DI,[BP-10]
MOV BX,[DI]
CALL ←Swab

;	←rout ← BX
MOV [BP-6],BX

;   if ((rout < lupineOffset) || (rout > sSpecsT->maxProcs)) SIGNAL(RejectUnbound);

;	BX ← ←rout
MOV BX,[BP-6]
CMP BX,4
JL X3

;	DI ← ←sSpecsT
MOV DI,[BP-4]
MOV BX,[DI]

;	CX ← ←rout
MOV CX,[BP-6]
CMP CX,BX
JLE X2
X3:
MOV AL,1
JR X4
X2:
XOR AL,AL
X4:
OR AL,AL
JZ X1
MOV BX,←RejectUnbound
CALL ←SIGNAL
X1:

;   thisProc = sSpecsT->procs[rout];

;	BX ← ←sSpecsT
MOV BX,[BP-4]
INC BX
INC BX

;	CX ← ←rout
MOV CX,[BP-6]
SAL CX
ADD BX,CX
MOV CX,[BX]

;	←thisProc ← CX
MOV [BP-12],CX

;   if (thisProc == 0) SIGNAL(RejectUnbound);

;	BX ← ←thisProc
MOV BX,[BP-12]
OR BX,BX
JNZ X5
MOV BX,←RejectUnbound
CALL ←SIGNAL
X5:

;   return (Call1(thisProc, wp));

;	BX ← ←wp
MOV BX,[BP-10]

;	CX ← ←thisProc
MOV CX,[BP-12]
CALL ←Call1
MOV SP,BP
POP BP
RET;

;   };

; int *StringToPkt(pp, s)
←StringToPkt:

;   int *pp;

;   struct ShortSTRING *s;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   int len;

;   if (s == 0) *pp++ = swapped1; /* isNil */
PUSH DX

;	BX ← ←s
MOV BX,[BP-4]
OR BX,BX
JNZ X6
ADD WORD PTR [BP-2],2

;	BX ← ←pp
MOV BX,[BP-2]
MOV WORD PTR [BX-2],0100X

;   else {
JR X7
X6:

;     *pp++ = 0; /* isNil */
ADD WORD PTR [BP-2],2

;	BX ← ←pp
MOV BX,[BP-2]
MOV WORD PTR [BX-2],0

;     *pp++ = Swab(s->length);
ADD WORD PTR [BP-2],2

;	BX ← ←pp
MOV BX,[BP-2]
PUSH BX

;	DI ← ←s
MOV DI,[BP-4]
MOV BX,[DI]
CALL ←Swab
MOV CX,BX
POP BX
MOV [BX-2],CX

;     len = (s->length+1) >> 1;  /* text only */

;	DI ← ←s
MOV DI,[BP-4]
MOV BX,[DI]
INC BX
SHR BX

;	←len ← BX
POP DX
PUSH BX

;     MoveBlock(pp, &s->text[0], len);

;	BX ← ←pp
MOV BX,[BP-2]
PUSH BX

;	BX ← ←s
MOV BX,[BP-4]
ADD BX,4
PUSH BX

;	BX ← ←len
MOV BX,[BP-6]
POP CX
CALL ←MoveBlock
POP DX

;     pp += len;

;	BX ← ←len
POP BX
PUSH BX
SAL BX
ADD [BP-2],BX

;     };
X7:

;   return (pp);

;	BX ← ←pp
MOV BX,[BP-2]
MOV SP,BP
POP BP
RET;

;   };

; struct ShortSTRING

; *AllocStringFromPkt(pp)
←AllocStringFromPkt:

;   int **pp;
PUSH BP
MOV BP,SP
PUSH BX

;   {

;   int len, *wp;

;   struct ShortSTRING *s;
ADD SP,0FFFAX

;   wp = *pp;

;	DI ← ←pp
MOV DI,[BP-2]
MOV BX,[DI]

;	←wp ← BX
MOV [BP-6],BX

;   if (*wp) {

;	DI ← ←wp
MOV DI,[BP-6]
MOV BX,[DI]
OR BX,BX
JZ X8

;     *pp = wp+1;

;	BX ← ←wp
MOV BX,[BP-6]
INC BX
INC BX
MOV CX,BX

;	BX ← ←pp
MOV BX,[BP-2]
MOV [BX],CX

;     return(0);
XOR BX,BX
MOV SP,BP
POP BP
RET;

;     };
X8:

;   len = (Swab(wp[1])+5)/2;

;	BX ← ←wp
MOV BX,[BP-6]
MOV CX,[BX+2]
MOV BX,CX
CALL ←Swab
ADD BX,5
SAR BX

;	←len ← BX
MOV [BP-4],BX

;   if (len > 100) CallSwat(ecLarkImpl + 22);

;	BX ← ←len
MOV BX,[BP-4]
CMP BX,064X
JLE X9
MOV BX,07016X
CALL ←CallSwat
X9:

;   s = (struct ShortSTRING *) GetFixed(len);

;	BX ← ←len
MOV BX,[BP-4]
CALL ←GetFixed

;	←s ← BX
POP DX
PUSH BX

;   MoveBlock(s, wp, len);

;	BX ← ←s
POP BX
PUSH BX
PUSH BX

;	BX ← ←len
MOV BX,[BP-4]

;	CX ← ←wp
MOV CX,[BP-6]
CALL ←MoveBlock
POP DX

;   s->maxLength = Swab(s->maxLength);

;	BX ← ←s
POP BX
PUSH BX
PUSH BX

;	BX ← ←s
MOV BX,[BP-8]
MOV CX,[BX+2]
MOV BX,CX
CALL ←Swab
MOV CX,BX
POP BX
MOV [BX+2],CX

;   s->length = s->maxLength;

;	BX ← ←s
POP BX
PUSH BX
MOV CX,[BX+2]

;	BX ← ←s
POP BX
PUSH BX
MOV [BX],CX

;   *pp = wp + len;

;	BX ← ←len
MOV BX,[BP-4]

;	CX ← ←wp
MOV CX,[BP-6]
SAL BX
ADD BX,CX
MOV CX,BX

;	BX ← ←pp
MOV BX,[BP-2]
MOV [BX],CX

;   return(s);

;	BX ← ←s
POP BX
PUSH BX
MOV SP,BP
POP BP
RET;

;   };

; int *AllocWordsFromPkt(pp, swap)
←AllocWordsFromPkt:

;   int **pp;

;   int swap;  /* boolean */
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   int len, *wp;

;   int *wseq;
ADD SP,0FFFAX

;   wp = *pp;

;	DI ← ←pp
MOV DI,[BP-2]
MOV BX,[DI]

;	←wp ← BX
MOV [BP-8],BX

;   if (*wp) {

;	DI ← ←wp
MOV DI,[BP-8]
MOV BX,[DI]
OR BX,BX
JZ X10

;     *pp = wp+1;

;	BX ← ←wp
MOV BX,[BP-8]
INC BX
INC BX
MOV CX,BX

;	BX ← ←pp
MOV BX,[BP-2]
MOV [BX],CX

;     return(0);
XOR BX,BX
MOV SP,BP
POP BP
RET;

;     };
X10:

;   len = Swab(wp[1]);

;	BX ← ←wp
MOV BX,[BP-8]
MOV CX,[BX+2]
MOV BX,CX
CALL ←Swab

;	←len ← BX
MOV [BP-6],BX

;   if (len > 100) CallSwat(ecLarkImpl + 22);

;	BX ← ←len
MOV BX,[BP-6]
CMP BX,064X
JLE X11
MOV BX,07016X
CALL ←CallSwat
X11:

;   wseq = GetFixed(len+1);

;	BX ← ←len
MOV BX,[BP-6]
INC BX
CALL ←GetFixed

;	←wseq ← BX
POP DX
PUSH BX

;   *wseq = Swab(wp[3]);

;	BX ← ←wp
MOV BX,[BP-8]
MOV CX,[BX+6]
MOV BX,CX
CALL ←Swab
MOV CX,BX

;	BX ← ←wseq
POP BX
PUSH BX
MOV [BX],CX

;   Marshall(swap, wseq+1, &wp[4], len);

;	BX ← ←swap
MOV BX,[BP-4]
PUSH BX

;	BX ← ←wseq
MOV BX,[BP-10]
INC BX
INC BX
PUSH BX

;	BX ← ←wp
MOV BX,[BP-8]
ADD BX,8
PUSH BX

;	BX ← ←len
MOV BX,[BP-6]
POP CX
CALL ←Marshall
ADD SP,4

;   *pp = wp + len + 4;

;	BX ← ←len
MOV BX,[BP-6]
ADD BX,4

;	CX ← ←wp
MOV CX,[BP-8]
SAL BX
ADD BX,CX
MOV CX,BX

;	BX ← ←pp
MOV BX,[BP-2]
MOV [BX],CX

;   return(wseq);

;	BX ← ←wseq
POP BX
PUSH BX
MOV SP,BP
POP BP
RET;

;   };

; SwabInPlace(addr, words)
←SwabInPlace:

;   int *addr, words;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   Marshall(true, addr, addr, words);
MOV BX,0FFFFX
PUSH BX

;	BX ← ←addr
MOV BX,[BP-2]
PUSH BX

;	BX ← ←words
MOV BX,[BP-4]

;	CX ← ←addr
MOV CX,[BP-2]
CALL ←Marshall
ADD SP,4

;   };
MOV SP,BP
POP BP
RET;

; Externals Declared Here
PUBLIC ←StartBonsai
PUBLIC ←CallBonsai
PUBLIC ←CleanupCall
PUBLIC ←BonsaiDispatcher
PUBLIC ←StringToPkt
PUBLIC ←AllocStringFromPkt
PUBLIC ←AllocWordsFromPkt
PUBLIC ←SwabInPlace

C←CODE ENDS

; Number of Bytes of Code = 02DDX, (733)