;Alto->8086 small-c compiler rev 2.0 C←CODE SEGMENT $INCLUDE(8086LIB.D) $INCLUDE(RPCUtilsImpl.DEC) ASSUME CS:C←CODE, DS:C←DATA ; #include <Env.h> ; extern int NewPSB(); ; extern int Min(); ; extern int lc(); ; extern struct RPCCtx *CurrentContext(); ; extern int *Enqueue(); ; extern struct RPCCtx *InitNContext(); ; extern int *GetFixed(); ; extern int CallSwat(); ; extern int MoveBlock(); ; extern int Zero(); ; extern int DoubleDiff(); ; struct HostNet { ; char net; ; char host; ; }; ; union Machine { ; int w; ; struct HostNet b; ; }; ; struct Calendar { ; int time[2]; ; int zoneInfo; ; int dstStartDay; ; int dstEndDay; ; int base[2]; /* last ms timer, for updating time */ ; }; ; static struct Calendar calendar; ; int /*bool allFit*/ ; AppendString(tO, fRom) ←AppendString: ; struct ShortSTRING *tO, *fRom; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { /* RETURNS[allFit: BOOLEAN]*/ ; int i, toLen, totLen, fromLen; ADD SP,0FFF8X ; toLen = tO->length; ; DI ← ←tO MOV DI,[BP-2] MOV BX,[DI] ; ←toLen ← BX MOV [BP-8],BX ; totLen = Min(tO->maxLength, toLen+fRom->length); ; BX ← ←tO MOV BX,[BP-2] MOV CX,[BX+2] ; DI ← ←fRom MOV DI,[BP-4] MOV BX,[DI] ; AX ← ←toLen MOV AX,[BP-8] ADD AX,BX MOV BX,AX CALL ←Min ; ←totLen ← BX MOV [BP-10],BX ; fromLen = totLen-toLen; ; BX ← ←toLen MOV BX,[BP-8] ; CX ← ←totLen MOV CX,[BP-10] SUB CX,BX ; ←fromLen ← CX POP DX PUSH CX ; for (i=0; i<fromLen; ++i) tO->text[i+toLen] = fRom->text[i]; MOV WORD PTR [BP-6],0 X3: ; BX ← ←fromLen POP BX PUSH BX ; CX ← ←i MOV CX,[BP-6] CMP CX,BX JGE X2 JR X1 X4: INC WORD PTR [BP-6] JR X3 X1: ; BX ← ←tO MOV BX,[BP-2] ADD BX,4 ; CX ← ←toLen MOV CX,[BP-8] ; AX ← ←i MOV AX,[BP-6] ADD AX,CX ADD BX,AX ; CX ← ←fRom MOV CX,[BP-4] ADD CX,4 ; AX ← ←i MOV AX,[BP-6] ADD AX,CX MOV DI,AX MOV AL,[DI] MOV [BX],AL JR X4 X2: ; tO->length = totLen; ; BX ← ←tO MOV BX,[BP-2] ; CX ← ←totLen MOV CX,[BP-10] MOV [BX],CX ; return(fromLen == fRom->length); ; DI ← ←fRom MOV DI,[BP-4] MOV BX,[DI] ; CX ← ←fromLen POP CX PUSH CX CMP CX,BX JNZ X5 MOV BX,1 JR X6 X5: XOR BX,BX X6: MOV SP,BP POP BP RET; ; }; ; int /*bool*/ ; EquivalentStrings(a,b) ←EquivalentStrings: ; struct ShortSTRING *a, *b; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; int i; ; if (a->length != b->length) return(false); PUSH DX ; DI ← ←a MOV DI,[BP-2] MOV BX,[DI] ; DI ← ←b MOV DI,[BP-4] MOV CX,[DI] CMP BX,CX JZ X7 XOR BX,BX MOV SP,BP POP BP RET; X7: ; for (i=0; i<a->length; ++i) MOV WORD PTR [BP-6],0 X10: ; DI ← ←a MOV DI,[BP-2] MOV BX,[DI] ; CX ← ←i POP CX PUSH CX CMP CX,BX JGE X9 JR X8 X11: INC WORD PTR [BP-6] JR X10 X8: ; if (lc(a->text[i]) != lc(b->text[i])) return(false); ; BX ← ←a MOV BX,[BP-2] ADD BX,4 ; CX ← ←i POP CX PUSH CX ADD BX,CX MOV AL,[BX] CBW MOV BX,AX CALL ←lc PUSH BX ; BX ← ←b MOV BX,[BP-4] ADD BX,4 ; CX ← ←i MOV CX,[BP-6] ADD BX,CX MOV AL,[BX] CBW MOV BX,AX CALL ←lc POP CX CMP CX,BX JZ X12 XOR BX,BX MOV SP,BP POP BP RET; X12: JR X11 X9: ; return(true); MOV BX,0FFFFX MOV SP,BP POP BP RET; ; }; ; struct ShortSTRING ; *CStringToString(b) ←CStringToString: ; char b[]; PUSH BP MOV BP,SP PUSH BX ; { ; int len, i; ; struct ShortSTRING *s; ADD SP,0FFFAX ; len = strlen(b); ; BX ← ←b MOV BX,[BP-2] CALL ←strlen ; ←len ← BX MOV [BP-4],BX ; s = (struct ShortSTRING *) GetFixed(StringSizeN(len)); ; BX ← ←len MOV BX,[BP-4] CALL ←StringSizeN CALL ←GetFixed ; ←s ← BX POP DX PUSH BX ; s->length = s->maxLength = len; ; BX ← ←s POP BX PUSH BX ; CX ← ←len MOV CX,[BP-4] MOV [BX+2],CX ; BX ← ←s POP BX PUSH BX MOV [BX],CX ; for (i = 0; i<len; ++i) s->text[i] = b[i]; MOV WORD PTR [BP-6],0 X15: ; BX ← ←len MOV BX,[BP-4] ; CX ← ←i MOV CX,[BP-6] CMP CX,BX JGE X14 JR X13 X16: INC WORD PTR [BP-6] JR X15 X13: ; BX ← ←s POP BX PUSH BX ADD BX,4 ; CX ← ←i MOV CX,[BP-6] ADD BX,CX ; CX ← ←i MOV CX,[BP-6] ; AX ← ←b MOV AX,[BP-2] ADD CX,AX MOV DI,CX MOV AL,[DI] MOV [BX],AL JR X16 X14: ; return(s); ; BX ← ←s POP BX PUSH BX MOV SP,BP POP BP RET; ; }; ; static int strlen(b) ←strlen: ; char b[]; PUSH BP MOV BP,SP PUSH BX ; { ; int i; ; for (i = 0; i<100; ++i) if (b[i] == 0) return (i); PUSH DX MOV WORD PTR [BP-4],0 X19: ; BX ← ←i POP BX PUSH BX CMP BX,064X JGE X18 JR X17 X20: INC WORD PTR [BP-4] JR X19 X17: ; BX ← ←i POP BX PUSH BX ; CX ← ←b MOV CX,[BP-2] ADD BX,CX MOV AL,[BX] OR AL,AL JNZ X21 ; BX ← ←i POP BX PUSH BX MOV SP,BP POP BP RET; X21: JR X20 X18: ; return (100); MOV BX,064X MOV SP,BP POP BP RET; ; }; ; int ; InstanceToMachine(instance) ←InstanceToMachine: ; struct ShortSTRING *instance; PUSH BP MOV BP,SP PUSH BX ; { /* parses fixed-form net address*/ ; int i, net; ADD SP,0FFFCX ; i=0; MOV WORD PTR [BP-4],0 ; net=Num(instance, &i); ;&←i LEA BX,[BP-4] ; CX ← ←instance MOV CX,[BP-2] CALL ←Num ; ←net ← BX POP DX PUSH BX ; return((Num(instance, &i)<<8) + net); ;&←i LEA BX,[BP-4] ; CX ← ←instance MOV CX,[BP-2] CALL ←Num MOV CX,8 SAL BX,CX ; CX ← ←net POP CX PUSH CX ADD BX,CX MOV SP,BP POP BP RET; ; }; ; static int ; Num(s, lvChar) ←Num: ; struct ShortSTRING *s; ; int *lvChar; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; int res, i; ; char c; ADD SP,0FFFAX ; res=0; MOV WORD PTR [BP-6],0 ; for (i=*lvChar; i<s->length; ++i) { ; DI ← ←lvChar MOV DI,[BP-4] MOV BX,[DI] ; ←i ← BX MOV [BP-8],BX X24: ; DI ← ←s MOV DI,[BP-2] MOV BX,[DI] ; CX ← ←i MOV CX,[BP-8] CMP CX,BX JGE X23 JR X22 X25: INC WORD PTR [BP-8] JR X24 X22: ; c = s->text[i]; ; BX ← ←s MOV BX,[BP-2] ADD BX,4 ; CX ← ←i MOV CX,[BP-8] ADD BX,CX MOV AL,[BX] ; ←c ← AL POP DX PUSH AX ; if (c == '#') { ; AL ← ←c POP AX PUSH AX CMP AL,023X JNZ X26 ; *lvChar=i+1; ; BX ← ←i MOV BX,[BP-8] INC BX MOV CX,BX ; BX ← ←lvChar MOV BX,[BP-4] MOV [BX],CX ; return(res); ; BX ← ←res MOV BX,[BP-6] MOV SP,BP POP BP RET; ; }; X26: ; if ('0' > c || c > '7') break; ; AL ← ←c POP AX PUSH AX MOV CL,030X CMP CL,AL JG X29 ; AL ← ←c POP AX PUSH AX CMP AL,037X X29: X28: JLE X27 JR X23 X27: ; res = (res<<3) + c - '0'; MOV CX,3 ; BX ← ←res MOV BX,[BP-6] SAL BX,CX ; AL ← ←c POP AX PUSH AX ADD AL,0D0X XOR AH,AH ADD BX,AX ; ←res ← BX MOV [BP-6],BX ; if (res > 0377) break; ; BX ← ←res MOV BX,[BP-6] CMP BX,0FFX JLE X30 JR X23 X30: ; }; JR X25 X23: ; SIGNAL(ERROR, 0); XOR BX,BX MOV CX,2 CALL ←SIGNAL ; }; MOV SP,BP POP BP RET; ; int StringSize(s) ←StringSize: ; struct ShortSTRING *s; PUSH BP MOV BP,SP PUSH BX ; { ; return(lenShortSTRING+(s->length+1)/2); ; DI ← ←s POP DI PUSH DI MOV BX,[DI] INC BX SAR BX INC BX INC BX MOV SP,BP POP BP RET; ; }; ; int StringSizeN(n) ←StringSizeN: ; int n; PUSH BP MOV BP,SP PUSH BX ; { ; return(lenShortSTRING+(n+1)/2); ; BX ← ←n POP BX PUSH BX INC BX SAR BX INC BX INC BX MOV SP,BP POP BP RET; ; }; ; int *GetSigVec() ←GetSigVec: PUSH BP MOV BP,SP ; { ; struct RPCCtx *CtxRunning; PUSH DX ; CtxRunning = CurrentContext(); CALL ←CurrentContext ; ←CtxRunning ← BX POP DX PUSH BX ; return(CtxRunning->user.sigVec); ; BX ← ←CtxRunning POP BX PUSH BX ADD BX,01CX MOV SP,BP POP BP RET; ; }; ; StartNProcess(name, ctxQ, proc, len, sigVecLen) ←StartNProcess: ; char *name; ; struct Queue *ctxQ; ; int *proc, len, sigVecLen; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; int cBase; ; struct RPCCtx *context; ADD SP,0FFFCX ; cBase = (int) GetFixed(len); ; BX ← ←len MOV BX,[BP-2] CALL ←GetFixed ; ←cBase ← BX MOV [BP-6],BX ; len = len - (sigVecLen + lenRPCCtx + 3); /* 3 for slop */ ; BX ← ←sigVecLen MOV BX,[BP-4] ADD BX,011X ; CX ← ←len MOV CX,[BP-2] SUB CX,BX ; ←len ← CX MOV [BP-2],CX ; context = InitNContext(name, cBase, len, proc); ; BX ← ←name MOV BX,[BP+8] PUSH BX ; BX ← ←cBase MOV BX,[BP-6] PUSH BX ; BX ← ←proc MOV BX,[BP+4] ; CX ← ←len MOV CX,[BP-2] CALL ←InitNContext ADD SP,4 ; ←context ← BX POP DX PUSH BX ; context->user.myPSB = NewPSB(context); ; BX ← ←context POP BX PUSH BX PUSH BX ; BX ← ←context MOV BX,[BP-8] CALL ←NewPSB MOV CX,BX POP BX MOV [BX+26],CX ; SigInit(context->user.sigVec, sigVecLen, &GetSigVec); ; BX ← ←context POP BX PUSH BX ADD BX,01CX PUSH BX MOV BX,OFFSET ←GetSigVec ; CX ← ←sigVecLen MOV CX,[BP-4] CALL ←SigInit POP DX ; Enqueue(ctxQ, context); ; BX ← ←context POP BX PUSH BX ; CX ← ←ctxQ MOV CX,[BP+6] CALL ←Enqueue ; }; MOV SP,BP POP BP RET; ; struct ShortSTRING ; /*[Un]Mar*/ *ShallString(dest, src, how) ←ShallString: ; struct ShortSTRING *dest, *src; ; int how; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; int ln; ; if (src==0) return 0; PUSH DX ; BX ← ←src MOV BX,[BP-2] OR BX,BX JNZ X31 XOR BX,BX MOV SP,BP POP BP RET; X31: ; ln = src->length; ; DI ← ←src MOV DI,[BP-2] MOV BX,[DI] ; ←ln ← BX POP DX PUSH BX ; if ((how&2)!=0) ln = swab(ln); /* source is big-endian */ ; BX ← ←how MOV BX,[BP-4] AND BX,2 OR BX,BX JZ X32 ; BX ← ←ln POP BX PUSH BX CALL ←swab ; ←ln ← BX POP DX PUSH BX X32: ; ln = (ln+5)/2; /* now word count */ ; BX ← ←ln POP BX ADD BX,5 SAR BX ; ←ln ← BX PUSH BX ; if (dest == 0) dest = (struct ShortSTRING *) GetFixed(ln); ; BX ← ←dest MOV BX,[BP+4] OR BX,BX JNZ X33 ; BX ← ←ln POP BX PUSH BX CALL ←GetFixed ; ←dest ← BX MOV [BP+4],BX X33: ; MoveBlock(dest, src, ln); ; BX ← ←dest MOV BX,[BP+4] PUSH BX ; BX ← ←ln MOV BX,[BP-6] ; CX ← ←src MOV CX,[BP-2] CALL ←MoveBlock POP DX ; switch (how) { ; BX ← ←how MOV BX,[BP-4] JR X34 ; case 1: case 2: X36: X37: ; dest->length = swab(dest->length); ; DI ← ←dest MOV DI,[BP+4] MOV BX,[DI] CALL ←swab MOV CX,BX ; BX ← ←dest MOV BX,[BP+4] MOV [BX],CX ; default: {}; X38: ; }; JR X35 X34: MOV AL,BH OR AL,AL JNZ X38 MOV AL,BL CMP AL,1 JZ X36 CMP AL,2 JZ X37 JR X38 X35: ; dest->maxLength = dest->length; ; BX ← ←dest MOV BX,[BP+4] ; DI ← ←dest MOV DI,[BP+4] MOV CX,[DI] MOV [BX+2],CX ; Block(); CALL ←Block ; return (dest); ; BX ← ←dest MOV BX,[BP+4] MOV SP,BP POP BP RET; ; }; ; int DoubleComp(px, py) ←DoubleComp: ; int px[], py[]; PUSH BP MOV BP,SP PUSH CX PUSH BX ; { ; int pt0, pt[2]; ADD SP,0FFFAX ; Move2(pt, px); ; BX ← ←px MOV BX,[BP-2] ;&←pt LEA CX,[BP-10] CALL ←Move2 ; pt0 = DoubleDiff(pt, py); ; BX ← ←py MOV BX,[BP-4] ;&←pt LEA CX,[BP-10] CALL ←DoubleDiff ; ←pt0 ← BX MOV [BP-6],BX ; if (pt[1]==0) { ; BX ← ←pt+2 MOV BX,[BP-8] OR BX,BX JNZ X39 ; if (pt0>=0) return (pt0); ; BX ← ←pt0 MOV BX,[BP-6] CMP BX,0 JL X40 ; BX ← ←pt0 MOV BX,[BP-6] MOV SP,BP POP BP RET; X40: ; return (maxV); MOV BX,07FFFX MOV SP,BP POP BP RET; ; }; X39: ; if (pt[1]==-1) { ; BX ← ←pt+2 MOV BX,[BP-8] CMP BX,0FFFFX JNZ X41 ; if (pt0<0) return (pt0); ; BX ← ←pt0 MOV BX,[BP-6] CMP BX,0 JGE X42 ; BX ← ←pt0 MOV BX,[BP-6] MOV SP,BP POP BP RET; X42: ; return (minV); MOV BX,08001X MOV SP,BP POP BP RET; ; }; X41: ; if (pt[1]>0) return (maxV); ; BX ← ←pt+2 MOV BX,[BP-8] CMP BX,0 JLE X43 MOV BX,07FFFX MOV SP,BP POP BP RET; X43: ; /* if (pt[1]<-1) */ return (minV); MOV BX,08001X MOV SP,BP POP BP RET; ; }; ; Externals Declared Here PUBLIC ←AppendString PUBLIC ←EquivalentStrings PUBLIC ←CStringToString PUBLIC ←StringSizeN PUBLIC ←InstanceToMachine PUBLIC ←StringSize PUBLIC ←GetSigVec PUBLIC ←StartNProcess PUBLIC ←ShallString PUBLIC ←DoubleComp C←CODE ENDS ; Number of Bytes of Code = 03CCX, (972)