Annotation of nono/exp/fmovemc.php, revision 1.1.1.3

1.1       root        1: ;
                      2: ; nono
1.1.1.2   root        3: ; Copyright (C) 2020 nono project
1.1       root        4: ;
1.1.1.2   root        5: ; Redistribution and use in source and binary forms, with or without
                      6: ; modification, are permitted provided that the following conditions
                      7: ; are met:
                      8: ; 1. Redistributions of source code must retain the above copyright
                      9: ;    notice, this list of conditions and the following disclaimer.
                     10: ; 2. Redistributions in binary form must reproduce the above copyright
                     11: ;    notice, this list of conditions and the following disclaimer in the
                     12: ;    documentation and/or other materials provided with the distribution.
                     13: ;
                     14: ; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     15: ; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     16: ; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     17: ; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     18: ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
                     19: ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
                     20: ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
                     21: ; AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
                     22: ; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     23: ; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     24: ; SUCH DAMAGE.
1.1       root       25: 
                     26: ; How to compile:
1.1.1.3 ! root       27: ;  > has fmovemc.has
        !            28: ;  > hlk fmovemc.o si_util.o
1.1       root       29: 
                     30:        .xref   hexstr_long
                     31:        .include doscall.mac
                     32:        .list
                     33:        .cpu    68030
                     34: 
                     35: PRINT  .macro  msg
                     36:        pea.l   msg(pc)
                     37:        DOS     _PRINT
                     38:        addq.l  #4,sp
                     39:        .endm
                     40: 
                     41: SET_FLINE_TRAP .macro
                     42:        move.l  (a5),a4
                     43:        lea.l   fline_handler(pc),a1
                     44:        move.l  a1,(a5)
                     45:        .endm
                     46: 
                     47: RESTORE_FLINE_TRAP     .macro
                     48:        move.l  a4,(a5)
                     49:        .endm
                     50: 
                     51:        .text
                     52:        .even
1.1.1.3 ! root       53: start:
        !            54:        bra     start2
        !            55: 
1.1       root       56: <?php
                     57:        // レジスタ割り当て
                     58:        // d0/d1        work
                     59:        // d7   1=検査対象命令でFライン例外がおきた
                     60:        //      その後は ok を表示するかどうかのカウント
                     61:        // a0/a1        work
                     62:        // a3   検査対象命令の次の位置 (Fライン例外から戻るのに使用)
                     63:        // a4   元のFライン例外ハンドラ置き場
                     64:        // a5   Fライン例外ベクタの位置 $002c
                     65: ?>
                     66: <?php
                     67:        // regs がターゲットのFPcr。
                     68:        // C..FPCR
                     69:        // S..FPSR
                     70:        // I..FPIAR の3ビット。
                     71:        // 右辺がそのターゲットの時に使える EA。レジスタ相対は省略でいい?
                     72:        //  d..Dn
                     73:        //  a..An
                     74:        //  m..(An)
                     75:        //  +..(An)+
                     76:        //  -..-(An)
                     77:        //  i..#imm
                     78: 
                     79:        // FMOVEM EA,regs
                     80:        $table = array(
                     81:                //regs     EA
                     82:                "___"   => "dam+-i",
                     83:                "__I"   => "dam+-i",
                     84:                "_S_"   => "d.m+-i",
                     85:                "_SI"   => "..m+-i",
                     86:                "C__"   => "d.m+-i",
                     87:                "C_I"   => "..m+-i",
                     88:                "CS_"   => "..m+-i",
                     89:                "CSI"   => "..m+-i",
                     90:        );
                     91:        foreach ($table as $regs => $eastr) {
                     92:                $ealist = preg_split("//", $eastr, -1, PREG_SPLIT_NO_EMPTY);
                     93:                for ($id = 0; $id < 6; $id++) {
                     94:                        $ea = $eastr[$id];
                     95:                        if (0) printf("regs='{$regs}' id=${id} ea={$ea}\n");
                     96: 
                     97:                        if ($ea == ".") {
                     98:                                // 許されない組み合わせ。例外が出ることを確認
                     99:                                subr_fail("to", $regs, $id);
                    100:                        } else {
                    101:                                // アクセス可能な場合のテスト
                    102:                                subr_success_to($regs, $id);
                    103:                        }
                    104:                }
                    105:        }
                    106: 
                    107:        // FMOVEM regs,EA
                    108:        foreach ($table as $regs => $eastr_src) {
                    109:                // EA が dst になる時は #imm は無効
                    110:                $eastr = preg_replace("/i/", ".", $eastr_src);
                    111: 
                    112:                $ealist = preg_split("//", $eastr, -1, PREG_SPLIT_NO_EMPTY);
                    113:                for ($id = 0; $id < 6; $id++) {
                    114:                        $ea = $eastr[$id];
                    115:                        if (0) printf("regs='{$regs}' id=${id} ea={$ea}\n");
                    116: 
                    117:                        if ($ea == ".") {
                    118:                                // 許されない組み合わせ。例外が出ることを確認
                    119:                                subr_fail("from", $regs, $id);
                    120:                        } else {
                    121:                                // アクセス可能な場合のテスト
                    122:                                subr_success_from($regs, $id);
                    123:                        }
                    124:                }
                    125:        }
                    126: ?>
                    127: <?php
                    128: // 1行を出力する。引数は printf のように fmt... で指定可能。
                    129: // 改行はこちらで付加する。
                    130: function out()
                    131: {
                    132:        $args = func_get_args();
                    133:        $fmt = array_shift($args);
                    134:        print vsprintf($fmt, $args);
                    135:        print "\n";
                    136: }
                    137: 
                    138: // regs の省略記号を数値形式に
                    139: function reg2num($str)
                    140: {
                    141:        $n = 0;
                    142:        if (preg_match("/I/", $str))
                    143:                $n += 1;
                    144:        if (preg_match("/S/", $str))
                    145:                $n += 2;
                    146:        if (preg_match("/C/", $str))
                    147:                $n += 4;
                    148:        return $n;
                    149: }
                    150: 
                    151: // regs 数値形式をニーモニックに
                    152: function regnum2mnemonic($regnum)
                    153: {
                    154:        if ($regnum == 0)
                    155:                return "nofpc";
                    156: 
                    157:        $list = array();
                    158:        if ($regnum & 4)
                    159:                $list[] = "fpcr";
                    160:        if ($regnum & 2)
                    161:                $list[] = "fpsr";
                    162:        if ($regnum & 1)
                    163:                $list[] = "fpiar";
1.1.1.3 ! root      164:        return implode("/", $list);
1.1       root      165: }
                    166: 
                    167: // regs 数値形式から転送レジスタ数に
                    168: function regnum2count($regnum)
                    169: {
                    170:        $counts = array(0, 1, 1, 2, 1, 2, 2, 3);
                    171:        return $counts[$regnum];
                    172: }
                    173: 
                    174: // regs 数値形式からマスクを返す。
                    175: // regs は1ビットだけ立っていること。
                    176: // %100=FPCR, %010=FPSR, %001=FPIAR
                    177: function regmask($regnum)
                    178: {
                    179:        $masks = array(
                    180:                /*0*/   0,
                    181:                /*1*/   0xffffffff,     // FPIAR
                    182:                /*2*/   0x0ffffff8,     // FPSR
                    183:                /*3*/   0,
                    184:                /*4*/   0x0000fff0,     // FPCR
                    185:        );
                    186:        return $masks[$regnum];
                    187: }
                    188: 
                    189: // EA 番号から命令ワードに。n はすべて0
                    190: function eanum2word($id)
                    191: {
                    192:        switch ($id) {
                    193:         case 0:        // D0
                    194:                return 0 << 3;
                    195:         case 1:        // A0
                    196:                return 1 << 3;
                    197:         case 2:        // (A0)
                    198:                return 2 << 3;
                    199:         case 3:        // (A0)+
                    200:                return 3 << 3;
                    201:         case 4:        // -(An)
                    202:                return 4 << 3;
                    203:         case 5:        // #imm
                    204:                return 0x3c;
                    205:        }
                    206: }
                    207: 
                    208: // EA 番号をラベル文字列に。
                    209: function eanum2label($id)
                    210: {
                    211:        $idstr = array(
                    212:                0 => "dn",
                    213:                1 => "an",
                    214:                2 => "anin",
                    215:                3 => "anpi",
                    216:                4 => "anpd",
                    217:                5 => "imm",
                    218:        );
                    219:        return $idstr[$id];
                    220: }
                    221: 
                    222: // EA 番号をニーモニックに。
                    223: function eanum2mnem($id, $n = 0)
                    224: {
                    225:        switch ($id) {
                    226:         case 0:        return "d{$n}";
                    227:         case 1:        return "a{$n}";
                    228:         case 2:        return "(a{$n})";
                    229:         case 3:        return "(a{$n})+";
                    230:         case 4:        return "-(a{$n})";
1.1.1.3 ! root      231:         case 5:        return "#imm";
1.1       root      232:        }
1.1.1.3 ! root      233:        return "";
1.1       root      234: }
                    235: 
1.1.1.3 ! root      236: function addfunc($name, $dir, $mnem, $cpureg)
1.1       root      237: {
                    238:        global $funclist;
                    239: 
1.1.1.3 ! root      240:        if ($cpureg == "#imm") {
        !           241:                // $cpureg の #imm は常に1つだが
        !           242:                // ニーモニック表記では対向と数を合わせるか。
        !           243:                $cpureg = preg_replace(',([^/]+),', "#imm", $mnem);
        !           244:        }
        !           245:        $text = "fmovem.l ";
        !           246:        if ($dir == "to") {
        !           247:                $text .= "{$cpureg},{$mnem}";
        !           248:        } else {
        !           249:                $text .= "{$mnem},{$cpureg}";
        !           250:        }
        !           251: 
        !           252:        $funclist[$name] = $text;
1.1       root      253:        out("test_{$name}:");
                    254: }
                    255: 
                    256: // 結果表示のサブルーチンコールを出力
                    257: function out_result($msg, $exp, $act)
                    258: {
                    259:        out("   pea.l   {$msg}(pc)");
                    260:        out("   move.l  {$exp},-(sp)");
                    261:        out("   move.l  {$act},-(sp)");
                    262:        out("   bsr     result");
                    263:        out("   lea.l   12(sp),sp");
                    264: }
                    265: 
1.1.1.3 ! root      266: // 許されない組み合わせのテスト。hard の時だけ検査する。
1.1       root      267: // Fライン例外が起きることをチェックする。
                    268: function subr_fail($dir, $regs, $id)
                    269: {
1.1.1.3 ! root      270:        $cpureg = eanum2mnem($id);
1.1       root      271:        $regnum = reg2num($regs);
                    272:        $mnem = regnum2mnemonic($regnum);
                    273:        $label = eanum2label($id);
                    274: 
                    275:        $funcname = ($dir == "to")
                    276:                ? "fmovem_{$label}_to_{$regs}"
                    277:                : "fmovem_{$regs}_to_{$label}";
1.1.1.3 ! root      278:        addfunc($funcname, $dir, $mnem, $cpureg);
1.1       root      279: 
                    280:        $w1 = 0xf200 | eanum2word($id);
                    281:        $w2 = 0x8000 | ($regnum << 10);
                    282:        if ($dir == "from")
                    283:                $w2 |= 0x2000;
                    284: 
1.1.1.3 ! root      285:        out("   tst.b   is_hard(pc)");
        !           286:        out("   bne             @f");
        !           287:        out("   rts");
        !           288:        out("@@:");
        !           289:        out("   PRINT   msg_{$funcname}");
1.1       root      290:        out("   SET_FLINE_TRAP");
                    291:        out("   moveq.l #0,d7");
                    292:        out("   lea.l   @f,a3");
                    293:        // アセンブルできない可能性があるので命令はバイナリを出力。
                    294:        out("   .dc.w   $%04x, $%04x", $w1, $w2);
                    295:        out("@@:");
                    296: 
                    297:        out("   RESTORE_FLINE_TRAP");
                    298:        // 例外が起きるはずなので D7 が非ゼロなら成功(次へ)
                    299:        out("   tst.l   d7");
                    300:        out("   bne     @f");
                    301:        out("   PRINT   msg_fail_notrap");
                    302:        out("   rts");
                    303:        out("@@:");
                    304:        out("   PRINT   msg_oktrap");
                    305:        out("   rts");
                    306:        out("");
                    307: }
                    308: 
                    309: // アクセス可能な場合のテスト。FMOVEM <ea>,<FPcr>
                    310: function subr_success_to($regs, $id)
                    311: {
1.1.1.3 ! root      312:        $cpureg = eanum2mnem($id);
1.1       root      313:        $regnum = reg2num($regs);
                    314:        $mnem = regnum2mnemonic($regnum);
                    315:        $label = eanum2label($id);
                    316: 
                    317:        $funcname = "fmovem_{$label}_to_{$regs}";
1.1.1.3 ! root      318:        addfunc($funcname, "to", $mnem, $cpureg);
        !           319:        out("   PRINT   msg_{$funcname}");
1.1       root      320: 
                    321:        $w1 = 0xf200 | eanum2word($id);
                    322:        $w2 = 0x8000 | ($regnum << 10);
                    323:        // count は指定されたレジスタ数 (0..3)
                    324:        // txcount は転送するレジスタ数 (1..3)
                    325:        $count = regnum2count($regnum);
                    326:        $txcount = ($count == 0) ? 1 : $count;
                    327: 
                    328:        // FPcr を空にしておく
                    329:        out("   fmove.l #0,fpcr");
                    330:        out("   fmove.l #0,fpsr");
                    331:        out("   fmove.l #0,fpiar");
                    332:        // 準備
                    333:        switch ($id) {
                    334:         case 0:        // Dn (singleのみ)
                    335:                out("   move.l  #\$55555555,d0");
                    336:                break;
                    337:         case 1:        // An (singleのみ)
                    338:                out("   move.l  #\$55555555,a0");
                    339:                break;
                    340:         case 2:        // (An)
                    341:         case 3:        // (An)+
                    342:         case 4:        // -(An)
                    343:                out("   move.l  #\$55555555,workarea");
                    344:                if ($count >= 2)
                    345:                        out("   move.l  #\$aaaaaaaa,workarea+4");
                    346:                if ($count == 3)
                    347:                        out("   move.l  #\$33333333,workarea+8");
                    348: 
                    349:                if ($id == 4) {
                    350:                        // 後ろ基準
                    351:                        // nofpc でも転送は発生する
                    352:                        out("   lea.l   workarea+%d(pc),a0", $txcount * 4);
                    353:                } else {
                    354:                        // 前から
                    355:                        out("   lea.l   workarea(pc),a0");
                    356:                }
                    357:                break;
                    358:         case 5:        // #imm
                    359:                $cpureg = "#\$55555555";
                    360:                if ($count >= 2)
                    361:                        $cpureg .= ",#\$aaaaaaaa";
                    362:                if ($count == 3)
                    363:                        $cpureg .= ",#\$33333333";
                    364:                break;
                    365:        }
                    366: 
                    367:        out("   SET_FLINE_TRAP");
                    368:        out("   moveq.l #0,d7");
                    369:        out("   lea.l   @f,a3");
                    370:        // 実行
                    371:        if ($mnem == "nofpc") {
                    372:                out("   .dc.w   $%04x, $%04x", $w1, $w2);
                    373:                // #imm,nofpc はアセンブル出来ないのでここで即値をおく
                    374:                if ($id == 5/*imm*/ && $count == 0) {
                    375:                        out("   .dc.l \$55555555");
                    376:                }
                    377:        } else {
                    378:                out("   fmovem.l {$cpureg},{$mnem}");
                    379:        }
                    380:        out("@@:");
                    381: 
                    382:        out("   RESTORE_FLINE_TRAP");
                    383:        // 例外は起きないはずなので D7 はゼロなら成功(次へ)
                    384:        out("   tst.l   d7");
                    385:        out("   beq     @f");
                    386:        out("   PRINT   msg_fail_trap");
                    387:        out("   rts");
                    388:        out("@@:");
                    389: 
                    390:        // 検証
                    391:        $expected = array(
                    392:                0x55555555,
                    393:                0xaaaaaaaa,
                    394:                0x33333333,
                    395:        );
                    396:        $i = 0;
                    397: 
                    398:        // An の変化量が正しいか。
                    399:        // この後のレジスタの検証で A0 を使うのでその前に行う。
                    400:        // (An) なら workarea から変化しない
                    401:        // (An)+ なら workarea+count*4
                    402:        // -(An) なら workarea に戻ってくる (最初にオフセットつけてるので)
                    403:        switch ($id) {
                    404:         case 2:        // (An)
                    405:         case 4:        // -(An)
                    406:                out("   lea.l   workarea(pc),a1");
                    407:                out("   cmpa.l  a1,a0");
                    408:                out("   beq     @f");
                    409:                out_result("msg_fail_addr", "a1", "a0");
                    410:                out("@@:");
                    411:                break;
                    412:         case 3:        // (An)+
                    413:                out("   lea.l workarea+%d(pc),a1", $txcount * 4);
                    414:                out("   cmpa.l  a1,a0");
                    415:                out("   beq     @f");
                    416:                out_result("msg_fail_addr", "a1", "a0");
                    417:                out("@@:");
                    418:                break;
                    419:        }
                    420: 
                    421:        // FPCR
                    422:        out("   fmove.l fpcr,d0");
                    423:        if (($regnum & 4)) {
                    424:                out("   move.l  #$%08x,d1", $expected[$i] & regmask(4));
                    425:                $i++;
                    426:        } else {
                    427:                out("   moveq.l #0,d1");
                    428:        }
                    429:        out("   cmp.l   d1,d0");
                    430:        out("   beq     @f");
                    431:        out_result("msg_fail_cr", "d1", "d0");
                    432:        out("@@:");
                    433: 
                    434:        // FPSR
                    435:        out("   fmove.l fpsr,d0");
                    436:        if (($regnum & 2)) {
                    437:                out("   move.l  #$%08x,d1", $expected[$i] & regmask(2));
                    438:                $i++;
                    439:        } else {
                    440:                out("   moveq.l #0,d1");
                    441:        }
                    442:        out("   cmp.l   d1,d0");
                    443:        out("   beq     @f");
                    444:        out_result("msg_fail_sr", "d1", "d0");
                    445:        out("@@:");
                    446: 
                    447:        // FPIAR
                    448:        out("   fmove.l fpiar,a0");
                    449:        // fmovem *,nofpc は FPIAR が受け取ってしまうようだ
                    450:        if (($regnum & 1) || $regnum == 0) {
                    451:                out("   move.l  #$%08x,a1", $expected[$i] & regmask(1));
                    452:                $i++;
                    453:        } else {
                    454:                out("   move.l  d7,a1   ; d7=0");
                    455:        }
                    456:        out("   cmpa.l  a1,a0");
                    457:        out("   beq     @f");
                    458:        out_result("msg_fail_ir", "a1", "a0");
                    459:        out("@@:");
                    460: 
                    461:        out("   tst.l   d7");
                    462:        out("   bne     @f");
                    463:        out("   PRINT   msg_ok");
                    464:        out("@@:");
                    465:        out("   rts");
                    466:        out("");
                    467: }
                    468: 
                    469: // アクセス可能な場合のテスト。FMOVEM <FPcr>,<ea>
                    470: function subr_success_from($regs, $id)
                    471: {
1.1.1.3 ! root      472:        $cpureg = eanum2mnem($id);
1.1       root      473:        $regnum = reg2num($regs);
                    474:        $mnem = regnum2mnemonic($regnum);
                    475:        $label = eanum2label($id);
                    476: 
                    477:        $funcname = "fmovem_{$regs}_to_{$label}";
1.1.1.3 ! root      478:        addfunc($funcname, "from", $mnem, $cpureg);
        !           479:        out("   PRINT   msg_{$funcname}");
1.1       root      480: 
                    481:        $w1 = 0xf200 | eanum2word($id);
                    482:        $w2 = 0xa000 | ($regnum << 10);
                    483:        // count は指定されたレジスタ数 (0..3)
                    484:        // txcount は転送するレジスタ数 (1..3)
                    485:        $count = regnum2count($regnum);
                    486:        $txcount = ($count == 0) ? 1 : $count;
                    487: 
                    488:        // FPcr に初期値をセット
                    489:        // nofpc の時は FPIAR
                    490:        $expected = array(
                    491:                0x55555555,
                    492:                0xaaaaaaaa,
                    493:                0x33333333,
                    494:        );
                    495:        $i = 0;
                    496:        out("   fmove.l #$%08x,fpcr", ($regnum & 4) ? $expected[$i++] : 0);
                    497:        out("   fmove.l #$%08x,fpsr", ($regnum & 2) ? $expected[$i++] : 0);
                    498:        out("   fmove.l #$%08x,fpiar",
                    499:                (($regnum & 1) || $count == 0) ? $expected[$i++] : 0);
                    500: 
                    501:        // 準備
                    502:        switch ($id) {
                    503:         case 2:        // (An)
                    504:         case 3:        // (An)+
                    505:                out("   lea.l   workarea(pc),a0");
                    506:                break;
                    507:         case 4:        // -(An)
                    508:                // nofpc でも転送は発生する
                    509:                out("   lea.l   workarea+%d(pc),a0", $txcount * 4);
                    510:                break;
                    511:         case 5:        // #imm は dst にならない
                    512:                break;
                    513:        }
                    514: 
                    515:        out("   SET_FLINE_TRAP");
                    516:        out("   moveq.l #0,d7");
                    517:        out("   lea.l   @f,a3");
                    518:        // 実行
                    519:        if ($mnem == "nofpc")
                    520:                out("   .dc.w   $%04x, $%04x", $w1, $w2);
                    521:        else
                    522:                out("   fmovem.l {$mnem},{$cpureg}");
                    523:        out("@@:");
                    524: 
                    525:        out("   RESTORE_FLINE_TRAP");
                    526:        // 例外は起きないはずなので D7 はゼロなら成功(次へ)
                    527:        out("   tst.l   d7");
                    528:        out("   beq     @f");
                    529:        out("   PRINT   msg_fail_trap");
                    530:        out("   rts");
                    531:        out("@@:");
                    532: 
                    533:        // 検証
                    534: 
                    535:        // An の変化量が正しいか
                    536:        // (An) なら workarea から変化しない
                    537:        // (An)+ なら workarea+count*4
                    538:        // -(An) なら workarea に戻ってくる (最初にオフセットつけてるので)
                    539:        switch ($id) {
                    540:         case 2:        // (An)
                    541:         case 4:        // -(An)
                    542:                out("   lea.l   workarea(pc),a1");
                    543:                out("   cmpa.l  a1,a0");
                    544:                out("   beq     @f");
                    545:                out_result("msg_fail_addr", "a1", "a0");
                    546:                out("@@:");
                    547:                break;
                    548:         case 3:        // (An)+
                    549:                out("   lea.l workarea+%d(pc),a1", $txcount * 4);
                    550:                out("   cmpa.l  a1,a0");
                    551:                out("   beq     @f");
                    552:                out_result("msg_fail_addr", "a1", "a0");
                    553:                out("@@:");
                    554:                break;
                    555:        }
                    556: 
                    557:        $i = 0;
                    558:        switch ($id) {
                    559:         case 0:        // Dn
                    560:                for ($r = 4; $r >= 1; $r >>= 1) {
                    561:                        // 各 fpn の該当する時か、nofpc なら FPIAR
                    562:                        if (($regnum & $r) || ($r == 1 && $count == 0)) {
                    563:                                out("   move.l  #$%08x,d1", $expected[$i] & regmask($r));
                    564:                                $i++;
                    565:                                out("   cmp.l   d1,d0");
                    566:                                out("   beq     @f");
                    567:                                out_result("msg_fail", "d1", "d0");
                    568:                                out("@@:");
                    569:                        }
                    570:                }
                    571:                break;
                    572:         case 1:        // An
                    573:                for ($r = 4; $r >= 1; $r >>= 1) {
                    574:                        // 各 fpn の該当する時か、nofpc なら FPIAR
                    575:                        if (($regnum & $r) || ($r == 1 && $count == 0)) {
                    576:                                out("   movea.l #$%08x,a1", $expected[$i] & regmask($r));
                    577:                                $i++;
                    578:                                out("   cmp.l   a1,a0");
                    579:                                out("   beq     @f");
                    580:                                out_result("msg_fail", "a1", "a0");
                    581:                                out("@@:");
                    582:                        }
                    583:                }
                    584:                break;
                    585:         case 2:        // (An)
                    586:         case 3:        // (An)+
                    587:         case 4:        // -(An)
                    588:                for ($r = 4; $r >= 1; $r >>= 1) {
                    589:                        // 各 fpn の該当する時か、nofpc なら FPIAR
                    590:                        if (($regnum & $r) || ($r == 1 && $count == 0)) {
                    591:                                out("   move.l  #$%08x,d1", $expected[$i] & regmask($r));
                    592:                                out("   cmp.l   workarea+%d,d1", $i * 4);
                    593:                                $i++;
                    594:                                out("   beq     @f");
                    595:                                out_result("msg_fail", "d1", sprintf("workarea+%d", $i * 4));
                    596:                                out("@@:");
                    597:                        }
                    598:                }
                    599:                break;
                    600:        }
                    601: 
                    602:        out("   tst.l   d7");
                    603:        out("   bne     @f");
                    604:        out("   PRINT   msg_ok");
                    605:        out("@@:");
                    606:        out("   rts");
                    607:        out("");
                    608: }
                    609: ?>
                    610: <?php
                    611: // lea.l $0000002c.l,a5 だと has.x に絶対アドレッシングだと
                    612: // 怒られてしまうため仕方なく
                    613: ?>
1.1.1.3 ! root      614: start2:
1.1       root      615:        clr.l   -(sp)
                    616:        DOS     _SUPER
                    617:        movem.l d7/a3-a5,-(sp)
1.1.1.3 ! root      618:        ; rough argument check
        !           619:        cmpi.b  #4,(a2)+        ; strlen(arg)>=4 ?
        !           620:        bcs     @f
        !           621:        cmpi.l  #$68617264,(a2) ; "hard"
        !           622:        seq.b   is_hard
        !           623: @@:
        !           624:        tst.b   is_hard(pc)
        !           625:        beq             disp_easy
        !           626: disp_hard:
        !           627:        PRINT   msg_hard
        !           628:        bra             @f
        !           629: disp_easy:
        !           630:        PRINT   msg_easy
        !           631: @@:
        !           632: 
1.1       root      633:        moveq.l #$2c,d0         ; alternate of "lea.l $2c,a5"
                    634:        move.l  d0,a5           ;
                    635: <?php
1.1.1.3 ! root      636:        foreach ($funclist as $name => $text) {
        !           637:                // FPcr が1つもないケースは hard の時だけ実行。
        !           638:                $undef_case = preg_match("/____/", $name);
        !           639:                if ($undef_case) {
        !           640:                        out("   tst.b   is_hard(pc)");
        !           641:                        out("   beq             @f");
        !           642:                }
1.1       root      643:                out("   bsr     test_{$name}");
1.1.1.3 ! root      644:                if ($undef_case) {
        !           645:                        out("@@:");
        !           646:                }
1.1       root      647:        }
                    648: ?>
                    649:        movem.l (sp)+,d7/a3-a5
                    650:        DOS     _EXIT
                    651: 
                    652: ; 結果表示
                    653: ; スタックには、メッセージ、期待値、実際の値の順で積む。
                    654: result:
                    655:        link    a6,#0
                    656:        movem.l d0/a0,-(sp)
                    657: 
                    658:        move.l  8+8(a6),-(sp)
                    659:        DOS     _PRINT
                    660:        addq.l  #4,sp
                    661: 
                    662:        move.l  8+4(a6),d0
                    663:        lea.l   buf(pc),a0
                    664:        bsr     hexstr_long
                    665:        PRINT   buf
                    666:        PRINT   msg_but
                    667: 
1.1.1.3 ! root      668:        move.l  8+0(a6),d0
1.1       root      669:        lea.l   buf(pc),a0
                    670:        bsr     hexstr_long
                    671:        PRINT   buf
                    672:        PRINT   msg_crlf
                    673: 
                    674:        addq.l  #1,d7   ; errcnt
                    675:        movem.l (sp)+,d0/a0
                    676:        unlk    a6
                    677:        rts
                    678: 
                    679: ; Fライン例外ハンドラ
                    680: ; a3 に戻りアドレスをセットしてあること
                    681: ; d7 を 1 にして帰る
                    682: fline_handler:
                    683:        moveq.l #1,d7
                    684:        move.l  a3,2(sp)
                    685:        rte
                    686: 
1.1.1.3 ! root      687: msg_hard:      .dc.b   "hard mode",$d,$a,0
        !           688: msg_easy:      .dc.b   "easy mode",$d,$a,0
1.1       root      689: msg_oktrap:    .dc.b   $9,"ok(trap)",$d,$a,0, 0,0
                    690: msg_fail_notrap:       .dc.b   $9,"FAIL: trap expected but not occured",$d,$a,0
                    691: msg_fail_trap: .dc.b   $9,"FAIL: unexpected trap occured",$d,$a,0
                    692: 
                    693: msg_ok:                .dc.b   $9,"ok",$d,$a,0
                    694: msg_fail:      .dc.b   $9,"fail",$d,$a,0
                    695: msg_fail_cr:   .dc.b   $9,"FAIL: fpcr expects ",0
                    696: msg_fail_sr:   .dc.b   $9,"FAIL: fpsr expects ",0
                    697: msg_fail_ir:   .dc.b   $9,"FAIL: fpiar expects ",0
                    698: msg_fail_addr: .dc.b   $9,"FAIL: an expects ",0
                    699: msg_but:       .dc.b   " but ",0
                    700: msg_crlf:      .dc.b   $d,$a,0
                    701: 
                    702: 
                    703: <?php
1.1.1.3 ! root      704:        foreach ($funclist as $name => $text) {
        !           705:                out("msg_{$name}:       .dc.b   \"{$text}\",0");
1.1       root      706:        }
                    707: ?>
                    708: 
                    709:        .data
                    710:        .even
                    711: workarea:      .ds.b   24
1.1.1.3 ! root      712: buf:           .ds.b   20
        !           713: is_hard:       .ds.b   1
1.1       root      714: 
                    715:        .end    start

unix.superglobalmegacorp.com

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