Annotation of cci/d/entry/div.c, revision 1.1

1.1     ! root        1: #define error_hdl0 error
        !             2: #define error_hdl2 error
        !             3: #define ediv_errhdl error
        !             4: 
        !             5: extern long scoplp;
        !             6: extern long force_lp;
        !             7: 
        !             8: #define C      0x1
        !             9: #define V      0x2
        !            10: #define Z      0x4
        !            11: #define N      0x8
        !            12: 
        !            13: /*     DIV instructions                */
        !            14: 
        !            15: 
        !            16: /* Some global variables */
        !            17: 
        !            18: static long flag_msk, divr, quo, rem, psl, quotient, divd[2];
        !            19: 
        !            20: 
        !            21: 
        !            22: div()
        !            23: {
        !            24:        asm("movl       $2,_no_opr");
        !            25:        divl2();                /* DIVIDE LONG WITH 2 OPERANDS */
        !            26:        divl3();                /* DIVIDE LONG WITH 3 OPERANDS */
        !            27: /*     divl2u();       */      /* DIVIDE LONG WITH 2 UNSIGNED OPERANDS */
        !            28: /*     divl3u();       */      /* DIVIDE LONG WITH 3 UNSIGNED OPERANDS */
        !            29:        exdiv();                /* EXTENDED DIVISION */
        !            30:        asm("jmp *return");
        !            31: }
        !            32: 
        !            33: static divl2()
        !            34: {
        !            35:        long exp_psw;
        !            36:        int unsign, no_op;
        !            37: 
        !            38:        unsign = 0;     /* signed division */
        !            39:        no_op = 2;      /* 2 operands      */
        !            40: 
        !            41:        asm("d1:        movab   d1,_stpc");
        !            42:        flag_msk = exp_psw = C;
        !            43:        flag_msk = N|Z|V|C;
        !            44:        divr = 0x47;
        !            45:        quo = 0x5678ffff;
        !            46:        divl(unsign,no_op,0x137c9ea,exp_psw);
        !            47:        
        !            48:        asm("d2:        movab   d2,_stpc");
        !            49:        flag_msk = exp_psw = 0;
        !            50:        flag_msk = N|V|C;               /* set all flags except Z */
        !            51:        exp_psw = exp_psw | Z | C;
        !            52:        divr = 1234;
        !            53:        quo = 0;
        !            54:        divl(unsign,no_op,0,exp_psw);
        !            55: 
        !            56:        asm("d3:        movab   d3,_stpc");
        !            57:        flag_msk = exp_psw = 0;
        !            58:        flag_msk = Z|V|C;               /* set all flags except N */
        !            59:        exp_psw = exp_psw | N | C;
        !            60:        divr = 4;
        !            61:        quo = -80;
        !            62:        divl(unsign,no_op,-20,exp_psw);
        !            63: 
        !            64:        /* test V bit                   */
        !            65:        asm("d4:        movab   d4,_stpc");
        !            66:        flag_msk = exp_psw = 0;
        !            67:        flag_msk = Z|C;                 /* set Z,C flags  */
        !            68:        exp_psw = exp_psw | (V|C);
        !            69:        /* divide largest negative no. by -1 */
        !            70:        divr = -1;
        !            71:        quo = 0x80000000;
        !            72:        divl(unsign,no_op,0x80000000,exp_psw);
        !            73: 
        !            74: }
        !            75: 
        !            76: static divl3()
        !            77: {
        !            78:        long exp_psw;
        !            79:        int unsign, no_op;
        !            80: 
        !            81:        unsign = 0;     /* signed division */
        !            82:        no_op = 3;      /* 3 operands      */
        !            83: 
        !            84:        asm("d5:        movab   d5,_stpc");
        !            85:        flag_msk = exp_psw = C;
        !            86:        flag_msk = N|Z|V|C;
        !            87:        divr = 0x47;
        !            88:        quo = 0x5678ffff;
        !            89:        divl(unsign,no_op,0x137c9ea,exp_psw);
        !            90:        
        !            91:        asm("d6:        movab   d6,_stpc");
        !            92:        flag_msk = exp_psw = 0;
        !            93:        flag_msk = N|V|C;               /* set all flags except Z */
        !            94:        exp_psw = exp_psw | Z | C;
        !            95:        divr = 1234;
        !            96:        quo = 0;
        !            97:        divl(unsign,no_op,0,exp_psw);
        !            98: 
        !            99:        asm("d7:        movab   d7,_stpc");
        !           100:        flag_msk = exp_psw = 0;
        !           101:        flag_msk = Z|V|C;               /* set all flags except N */
        !           102:        exp_psw = exp_psw | N | C;
        !           103:        divr = 4;
        !           104:        quo = -80;
        !           105:        divl(unsign,no_op,-20,exp_psw);
        !           106: 
        !           107:        /* test V bit                   */
        !           108:        asm("d8:        movab   d8,_stpc");
        !           109:        flag_msk = exp_psw = 0;
        !           110:        flag_msk = Z|C;                 /* set Z,C flags  */
        !           111:        exp_psw = exp_psw | (V|C);
        !           112:        /* divide largest negative no. by -1 */
        !           113:        divr = -1;
        !           114:        quo = 0x80000000;
        !           115:        divl(unsign,no_op,0x80000000,exp_psw);
        !           116: 
        !           117: }
        !           118: 
        !           119: 
        !           120: static exdiv()
        !           121: {
        !           122:        long exp_rem,  exp_psw;
        !           123: 
        !           124:        /* EXTENDED DIVISION            */
        !           125:        asm("d9:        movab   d9,_stpc");
        !           126:        flag_msk = exp_psw = C;
        !           127:        flag_msk = N|Z|V|C;             /* set all flags        */
        !           128:        divd[0] = 0;
        !           129:        divd[1] = 0xfffffff;
        !           130:        divr = 0xffffff0;
        !           131:        ediv(1,0xf,exp_psw);
        !           132: 
        !           133:        asm("d10:       movab   d10,_stpc");
        !           134:        flag_msk = exp_psw = 0;
        !           135:        flag_msk = N|V|C;               /* set N,V,C flags      */
        !           136:        exp_psw = exp_psw | Z | C;
        !           137:        divd[0] = 0;
        !           138:        divd[1] = 0;
        !           139:        divr = 4;
        !           140:        ediv(0,0,exp_psw);
        !           141: 
        !           142:        asm("d11:       movab   d11,_stpc");
        !           143:        flag_msk = exp_psw = 0;
        !           144:        flag_msk = Z|V|C;               /* set Z,V,C flags      */
        !           145:        exp_psw = exp_psw | N | C;
        !           146:        divd[0] = 0xffffffff;
        !           147:        divd[1] = -4005;
        !           148:        divr = 50;
        !           149:        ediv(-80,-5,exp_psw);
        !           150: 
        !           151:        asm("d12:       movab   d12,_stpc");
        !           152:        flag_msk = exp_psw = C;
        !           153:        flag_msk = Z|N|C;               /* set Z,N,C flags  */
        !           154:        exp_psw = exp_psw | N | C;
        !           155:        divd[0] = 0x6000;
        !           156:        divd[1] = 0xb000;       /* divd = 0x60000000b000 */
        !           157:        divr =  0xaeaeaeae;
        !           158:        ediv(0xfffed1c8,0x48482a10,exp_psw);
        !           159: 
        !           160: 
        !           161:        /* check overflow bit on extended division */
        !           162:        asm("d13:       movab   d13,_stpc");
        !           163:        flag_msk = exp_psw = 0;
        !           164:        flag_msk = Z|C;                 /* set Z,C flags  */
        !           165:        exp_psw = exp_psw | (Z|V|C);
        !           166:        /* divide largest negative no. by -1 */
        !           167:        divd[0] = 0x80000000;
        !           168:        divd[1] = 0;            /* divd = 0x8000000000000000 */
        !           169:        divr = -1;
        !           170:        ediv(0,0,exp_psw);
        !           171: 
        !           172:        asm("d14:       movab   d14,_stpc");
        !           173:        flag_msk = exp_psw = 0;
        !           174:        flag_msk = Z|N|C;               /* set Z,N,C flags  */
        !           175:        exp_psw = exp_psw | (Z|V|C);
        !           176:        divd[0] = 0xff;
        !           177:        divd[1] = 0;            /* divd = 0x000000ff00000000 */
        !           178:        divr = 2;
        !           179:        ediv(0,0,exp_psw);
        !           180: 
        !           181: 
        !           182: }
        !           183: 
        !           184: /*     THIS ROUTINE EXECUTE DIVL2,DIVL3,DIVL2U,DIVL3U INSTRUCTIONS     */
        !           185: 
        !           186: static divl(unsign,no_op,exp_result,exp_psw)
        !           187: long exp_result,exp_psw;
        !           188: int unsign, no_op;
        !           189: {      
        !           190:        long op1, op2, op3, psw, type;
        !           191: 
        !           192:    flag_msk = flag_msk << 16;
        !           193:    op1 = divr;
        !           194:    op2 = quo;
        !           195:    for(;;)
        !           196:         {
        !           197:        for (type=0;type<8;type++)
        !           198:        {
        !           199:        divr = op1;
        !           200:        quo = op2;
        !           201: 
        !           202:            if (no_op==2)  {
        !           203:                    if (type==0)  {     /* Memory to memory */
        !           204:                        setjmp();
        !           205:                        asm("movl       $1,_subtst");
        !           206:                        asm("bicpsw $0xf");             /* clear all flags */
        !           207:                        asm("bispsw _flag_msk");        /* set flags       */
        !           208:                        asm("divl2  _divr,_quo");
        !           209:                        asm("movpsl _psl");     /* save PSL */
        !           210:                        quotient = quo;
        !           211:                                 }
        !           212:                    if (type==1) {      /* Register to register */
        !           213:                        setjmp();
        !           214:                        asm("movl       $2,_subtst");
        !           215:                        asm("movl _divr,r3");
        !           216:                        asm("movl _quo,r4");
        !           217:                        asm("bicpsw $0xf");             /* clear all flags */
        !           218:                        asm("bispsw _flag_msk");        /* set flags       */
        !           219:                        asm("divl2  r3,r4");
        !           220:                        asm("movpsl _psl");     /* save PSL */
        !           221:                        asm("movl r4,_quo");
        !           222:                        quotient = quo;
        !           223:                                 }
        !           224:                    if (type==2) {      /* Register to Memory */
        !           225:                        setjmp();
        !           226:                        asm("movl       $3,_subtst");
        !           227:                        asm("movl _divr,r3");
        !           228:                        asm("bicpsw $0xf");             /* clear all flags */
        !           229:                        asm("bispsw _flag_msk");        /* set flags       */
        !           230:                        asm("divl2  r3,_quo");
        !           231:                        asm("movpsl _psl");     /* save PSL */
        !           232:                        quotient = quo;
        !           233:                                 }
        !           234:                    if (type==3) {      /* Memory to Register */
        !           235:                        setjmp();
        !           236:                        asm("movl       $4,_subtst");
        !           237:                        asm("movl _quo,r4");
        !           238:                        asm("bicpsw $0xf");             /* clear all flags */
        !           239:                        asm("bispsw _flag_msk");        /* set flags       */
        !           240:                        asm("divl2  _divr,r4");
        !           241:                        asm("movpsl _psl");     /* save PSL */
        !           242:                        asm("movl r4,_quo");
        !           243:                        quotient = quo;
        !           244:                                 }
        !           245:                      
        !           246:                    }
        !           247:                    if (type==0) {      /* Memory to memory  to memory */
        !           248:                        setjmp();
        !           249:                        asm("movl       $5,_subtst");
        !           250:                        asm("bicpsw $0xf");             /* clear all flags */
        !           251:                        asm("bispsw _flag_msk");        /* set flags       */
        !           252:                        asm("divl3  _divr,_quo,_quotient");
        !           253:                        asm("movpsl _psl");     /* save PSL */
        !           254:                                 }
        !           255:                    if (type==1) {      /* Register to register  to memory */
        !           256:                        setjmp();
        !           257:                        asm("movl       $6,_subtst");
        !           258:                        asm("movl _divr,r3");
        !           259:                        asm("movl _quo,r4");
        !           260:                        asm("bicpsw $0xf");             /* clear all flags */
        !           261:                        asm("bispsw _flag_msk");        /* set flags       */
        !           262:                        asm("divl3  r3,r4,_quotient");
        !           263:                        asm("movpsl _psl");     /* save PSL */
        !           264:                                 }
        !           265:                    if (type==2) {      /* Register to Memory  to memory */
        !           266:                        setjmp();
        !           267:                        asm("movl       $7,_subtst");
        !           268:                        asm("movl _divr,r3");
        !           269:                        asm("bicpsw $0xf");             /* clear all flags */
        !           270:                        asm("bispsw _flag_msk");        /* set flags       */
        !           271:                        asm("divl3  r3,_quo,_quotient");
        !           272:                        asm("movpsl _psl");     /* save PSL */
        !           273:                                 }
        !           274:                    if (type==3) {      /* Memory to Register  to register */
        !           275:                        setjmp();
        !           276:                        asm("movl       $8,_subtst");
        !           277:                        asm("movl _quo,r4");
        !           278:                        asm("bicpsw $0xf");             /* clear all flags */
        !           279:                        asm("bispsw _flag_msk");        /* set flags       */
        !           280:                        asm("divl3  _divr,r4,r5");
        !           281:                        asm("movpsl _psl");     /* save PSL */
        !           282:                        asm("movl r5,_quotient");
        !           283:                                 }
        !           284:                    if (type==4) {      /* Register to register to register */
        !           285:                        setjmp();
        !           286:                        asm("movl       $9,_subtst");
        !           287:                        asm("movl _divr,r3");
        !           288:                        asm("movl _quo,r4");
        !           289:                        asm("bicpsw $0xf");             /* clear all flags */
        !           290:                        asm("bispsw _flag_msk");        /* set flags       */
        !           291:                        asm("divl3  r3,r4,r5");
        !           292:                        asm("movpsl _psl");     /* save PSL */
        !           293:                        asm("movl r5,_quotient");
        !           294:                                 }
        !           295:                    if (type==5) {      /* Register to memory to register */
        !           296:                        setjmp();
        !           297:                        asm("movl       $0xa,_subtst");
        !           298:                        asm("movl _divr,r3");
        !           299:                        asm("bicpsw $0xf");             /* clear all flags */
        !           300:                        asm("bispsw _flag_msk");        /* set flags       */
        !           301:                        asm("divl3  r3,_quo,r5");
        !           302:                        asm("movpsl _psl");     /* save PSL */
        !           303:                        asm("movl r5,_quotient");
        !           304:                                 }
        !           305:                    if (type==6) {      /* Memory to  memory to Register */
        !           306:                        setjmp();
        !           307:                        asm("movl       $0xb,_subtst");
        !           308:                        asm("bicpsw $0xf");             /* clear all flags */
        !           309:                        asm("bispsw _flag_msk");        /* set flags       */
        !           310:                        asm("divl3  _divr,_quo,r5");
        !           311:                        asm("movpsl _psl");     /* save PSL */
        !           312:                        asm("movl r5,_quotient");
        !           313:                                 }
        !           314:                    if (type==7) {      /* Memory to Register to memory */
        !           315:                        setjmp();
        !           316:                        asm("movl       $0xc,_subtst");
        !           317:                        asm("movl _quo,r4");
        !           318:                        asm("bicpsw $0xf");             /* clear all flags */
        !           319:                        asm("bispsw _flag_msk");        /* set flags       */
        !           320:                        asm("divl3  _divr,r4,_quotient");
        !           321:                        asm("movpsl _psl");     /* save PSL */
        !           322:                                 }
        !           323:                }
        !           324:        psw =  psl & 0xf;
        !           325: 
        !           326:        /*  check flags */
        !           327:        if (psw != exp_psw) 
        !           328:                {
        !           329:                asm("movl       $2,_ercode");
        !           330:                if (scoplp) longjmp();
        !           331:                error_hdl2(psw,exp_psw,op1,op2);
        !           332:                }
        !           333: 
        !           334:        if (divr != op1)
        !           335:                {
        !           336:                asm("movl       $3,_ercode");
        !           337:                if (scoplp) longjmp();
        !           338:                error_hdl2(divr,op1,op1,op2);
        !           339:                }
        !           340:        if (no_op == 3)
        !           341:                {
        !           342:                if (quo != op2)
        !           343:                   {
        !           344:                        asm("movl       $3,_ercode");
        !           345:                        if (scoplp) longjmp();
        !           346:                        error_hdl2(quo,op2,op1,op2);
        !           347:                   }
        !           348:                }
        !           349:        if (quotient != exp_result)
        !           350:                {
        !           351:                asm("movl       $1,_ercode");
        !           352:                if (scoplp) longjmp();
        !           353:                error_hdl2(quotient,exp_result,op1,op2);
        !           354:                }
        !           355:                if (force_lp) longjmp();
        !           356:        break;
        !           357:        }
        !           358: }
        !           359: 
        !           360: 
        !           361: static ediv(exp_quo,exp_rem,exp_psw)
        !           362: long exp_quo, exp_rem, exp_psw;
        !           363: {      
        !           364:        long op1, op2[2], psw, type;
        !           365: 
        !           366:    flag_msk = flag_msk << 16;
        !           367:    op1 = divr;
        !           368:    op2[0] = divd[0];
        !           369:    op2[1] = divd[1];
        !           370:    for(;;)
        !           371:         {
        !           372:        for (type=0;type<4;type++) {
        !           373:        divr = op1;
        !           374:        divd[0] = op2[0];
        !           375:        divd[1] = op2[1];
        !           376: 
        !           377:        if (type==0) {          /* Memory to memory to memory to register */
        !           378:                setjmp();
        !           379:                asm("movl       $0xd,_subtst");
        !           380:                asm("bicpsw $0xf");             /* clear all flags */
        !           381:                asm("bispsw _flag_msk");        /* set flags       */
        !           382:                asm("ediv  _divr,_divd,_quo,r7");
        !           383:                asm("movpsl _psl");             /* save PSL */
        !           384:                asm("movl r7,_rem");
        !           385:                }
        !           386:        if (type==1) {  /* Register to register to register to register */
        !           387:                setjmp();
        !           388:                asm("movl       $0xe,_subtst");
        !           389:                asm("movl _divr,r3");
        !           390:                asm("movl _divd,r4");
        !           391:                asm("movl _divd+4,r5");
        !           392:                asm("bicpsw $0xf");             /* clear all flags */
        !           393:                asm("bispsw _flag_msk");        /* set flags       */
        !           394:                asm("ediv  r3,r4,r6,r7");
        !           395:                asm("movpsl _psl");             /* save PSL */
        !           396:                asm("movl r6,_quo");
        !           397:                asm("movl r7,_rem");
        !           398:                }
        !           399:        if (type==2) {  /* Register to memory to register to register */
        !           400:                setjmp();
        !           401:                asm("movl       $0xf,_subtst");
        !           402:                asm("movl _divr,r3");
        !           403:                asm("bicpsw $0xf");             /* clear all flags */
        !           404:                asm("bispsw _flag_msk");        /* set flags       */
        !           405:                asm("ediv  r3,_divd,r6,r7");
        !           406:                asm("movpsl _psl");             /* save PSL */
        !           407:                asm("movl r6,_quo");
        !           408:                asm("movl r7,_rem");
        !           409:                }
        !           410:        if (type==3) {  /* Memory to register to memory to register */
        !           411:                setjmp();
        !           412:                asm("movl       $0x10,_subtst");
        !           413:                asm("movl _divd,r4");
        !           414:                asm("movl _divd+4,r5");
        !           415:                asm("bicpsw $0xf");             /* clear all flags */
        !           416:                asm("bispsw _flag_msk");        /* set flags       */
        !           417:                asm("ediv  _divr,r4,_quo,r6");
        !           418:                asm("movpsl _psl");             /* save PSL */
        !           419:                asm("movl r6,_rem");
        !           420:                }
        !           421: 
        !           422:        psw =  psl & 0xf;
        !           423:        if (quo != exp_quo)
        !           424:                {               /* error in multiply operation */
        !           425:                asm("movl       $1,_ercode");
        !           426:                if (scoplp) longjmp();
        !           427:                ediv_errhdl(quo,exp_quo,op1,op2);
        !           428:                }
        !           429: 
        !           430:        /*  check flags */
        !           431:        if  (psw != exp_psw) 
        !           432:                {
        !           433:                asm("movl       $2,_ercode");
        !           434:                if (scoplp) longjmp();
        !           435:                ediv_errhdl(psw,exp_psw,op1,op2);
        !           436:                }
        !           437: 
        !           438:        if (divr != op1)
        !           439:                {
        !           440:                asm("movl       $3,_ercode");
        !           441:                if (scoplp) longjmp();
        !           442:                ediv_errhdl(divr,op1,op1,op2);
        !           443:                }
        !           444:        if ( (divd[0]!=op2[0]) || (divd[1]!=op2[1]) )
        !           445:                {
        !           446:                asm("movl       $3,_ercode");
        !           447:                if (scoplp) longjmp();
        !           448:                error_hdl0(divd,op2,op1,op2);
        !           449:                }
        !           450:        if (rem != exp_rem)
        !           451:                {
        !           452:                asm("movl       $1,_ercode");
        !           453:                if (scoplp) longjmp();
        !           454:                ediv_errhdl(rem,exp_rem,op1,op2);
        !           455:                }
        !           456:                if (force_lp) longjmp();
        !           457:        }
        !           458:        break;
        !           459:        }
        !           460: }
        !           461: 
        !           462: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.