FPGA開発日記

FPGAというより、コンピュータアーキテクチャかもね! カテゴリ別記事インデックス https://sites.google.com/site/fpgadevelopindex/

Calling Conventionモードに応じてISSのログの表記を変更する

レジスタのCalling Conventionとは。

呼出規約 - Calling Convention(コーリングコンベンション)

レジスタはハードウェア的にはFFの塊だが、ソフトウェアとしては、どのレジスタをどの役割として使うかが決められている。 また、それに応じて、レジスタの名前も決められている。

MIPS instruction set - Wikipedia, the free encyclopedia

Name Number Use Callee must preserve?
$zero $0 constant 0 N/A
$at $1 assembler temporary No
$v0–$v1 $2–$3 values for function returns and expression evaluation No
$a0–$a3 $4–$7 function arguments No
$t0–$t7 $8–$15 temporaries No
$s0–$s7 $16–$23 saved temporaries Yes
$t8–$t9 $24–$25 temporaries No
$k0–$k1 $26–$27 reserved for OS kernel N/A
$gp $28 global pointer Yes (except PIC code)
$sp $29 stack pointer Yes
$fp $30 frame pointer Yes
$ra $31 return address N/A

という訳で、モードによって、レジスタの表記が変わるようにISSを変更しよう。

github.com

    AbiRegType m_reg_print_type;

    const std::string m_abi_regs[REG_R31+1] = {
        "zero",
        "at",
        "v0", "v1",
        "a0", "a1", "a2", "a3",
        "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
        "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
        "t8", "t9",
        "k0", "k1",
        "gp", "sp",
        "fp", "ra"};

このようにレジスタに応じて名前を規定する。これをトレース表示関数で呼び出すようにしておく。

        case traceInfo::trace_regwrite :
            if (GetTrace()->GetTraceAddr (trace_count) == REG_PC) {
                (*operand_str) << "pc<=" << std::hex << std::setw(8) << GetTrace()->GetTraceValue (trace_count) << " ";
            } else {
                RegAddr_t reg_addr = GetTrace()->GetTraceAddr (trace_count);
                if (GetPrintRegStyle () == ABI_REG_HARD_NAME) {
                    (*operand_str) << "r"  << std::dec << std::setw(2) << std::setfill('0') << static_cast<uint32_t>(reg_addr);
                } else {
                    (*operand_str) << m_abi_regs[reg_addr];
                }
                (*operand_str) << "<=" << std::hex << std::setw(8) << std::setfill('0') << GetTrace()->GetTraceValue (trace_count) << " ";
            }
            break;
        case traceInfo::trace_regread : {
            RegAddr_t reg_addr = GetTrace()->GetTraceAddr (trace_count);
            if (GetPrintRegStyle () == ABI_REG_HARD_NAME) {
                (*operand_str) << "r"  << std::dec << std::setw(2) << std::setfill('0') << static_cast<uint32_t>(reg_addr);
            } else {
                (*operand_str) << m_abi_regs[reg_addr];
            }
            (*operand_str) << "=>" << std::hex << std::setw(8) << std::setfill('0') << GetTrace()->GetTraceValue (trace_count) << ' ';
            break;
        }

オプションで切り替えるようにしておく。--reg_abi softでソフト表記、--reg_abi hard でハードウェア表記とする。

swimmer_mips --binfile ../benchmarks/releases/coremark_v1.0_mips4_gcc51_O2/coremark.bin --debug --out debug.log --reg_abi hard
less debug.log
<Finish loading global variable table>
         0 : [bfc00000] 3c1c7f00 : lui     r28,0x7f00              r28<=7f000000
         1 : [bfc00004] 279c0010 : addiu   r28,r28,0x0010          r28=>7f000000 r28<=7f000010
         2 : [bfc00008] 3c1d7f00 : lui     r29,0x7f00              r29<=7f000000
         3 : [bfc0000c] 27bd4008 : addiu   r29,r29,0x4008          r29=>7f000000 r29<=7f004008
         4 : [bfc00010] 00000820 : add     r01,r00,r00             r00=>00000000 r00=>00000000 r01<=00000000
         5 : [bfc00014] 00001020 : add     r02,r00,r00             r00=>00000000 r00=>00000000 r02<=00000000
         6 : [bfc00018] 00001820 : add     r03,r00,r00             r00=>00000000 r00=>00000000 r03<=00000000
         7 : [bfc0001c] 00002020 : add     r04,r00,r00             r00=>00000000 r00=>00000000 r04<=00000000
         8 : [bfc00020] 00002820 : add     r05,r00,r00             r00=>00000000 r00=>00000000 r05<=00000000
         9 : [bfc00024] 00003020 : add     r06,r00,r00             r00=>00000000 r00=>00000000 r06<=00000000
        10 : [bfc00028] 00003820 : add     r07,r00,r00             r00=>00000000 r00=>00000000 r07<=00000000
        11 : [bfc0002c] 00004020 : add     r08,r00,r00             r00=>00000000 r00=>00000000 r08<=00000000
        12 : [bfc00030] 00004820 : add     r09,r00,r00             r00=>00000000 r00=>00000000 r09<=00000000
        13 : [bfc00034] 00005020 : add     r10,r00,r00             r00=>00000000 r00=>00000000 r10<=00000000
        14 : [bfc00038] 00005820 : add     r11,r00,r00             r00=>00000000 r00=>00000000 r11<=00000000
        15 : [bfc0003c] 00006020 : add     r12,r00,r00             r00=>00000000 r00=>00000000 r12<=00000000
        16 : [bfc00040] 00006820 : add     r13,r00,r00             r00=>00000000 r00=>00000000 r13<=00000000
        17 : [bfc00044] 00007020 : add     r14,r00,r00             r00=>00000000 r00=>00000000 r14<=00000000
        18 : [bfc00048] 00007820 : add     r15,r00,r00             r00=>00000000 r00=>00000000 r15<=00000000
        19 : [bfc0004c] 00008020 : add     r16,r00,r00             r00=>00000000 r00=>00000000 r16<=00000000
        20 : [bfc00050] 00008820 : add     r17,r00,r00             r00=>00000000 r00=>00000000 r17<=00000000
        21 : [bfc00054] 00009020 : add     r18,r00,r00             r00=>00000000 r00=>00000000 r18<=00000000
        22 : [bfc00058] 00009820 : add     r19,r00,r00             r00=>00000000 r00=>00000000 r19<=00000000
        23 : [bfc0005c] 0000a020 : add     r20,r00,r00             r00=>00000000 r00=>00000000 r20<=00000000
        24 : [bfc00060] 0000a820 : add     r21,r00,r00             r00=>00000000 r00=>00000000 r21<=00000000
        25 : [bfc00064] 0000b020 : add     r22,r00,r00             r00=>00000000 r00=>00000000 r22<=00000000
        26 : [bfc00068] 0000b820 : add     r23,r00,r00             r00=>00000000 r00=>00000000 r23<=00000000
        27 : [bfc0006c] 0000c020 : add     r24,r00,r00             r00=>00000000 r00=>00000000 r24<=00000000
        28 : [bfc00070] 0000c820 : add     r25,r00,r00             r00=>00000000 r00=>00000000 r25<=00000000
        29 : [bfc00074] 0000d020 : add     r26,r00,r00             r00=>00000000 r00=>00000000 r26<=00000000
        30 : [bfc00078] 0000d820 : add     r27,r00,r00             r00=>00000000 r00=>00000000 r27<=00000000
        31 : [bfc0007c] 0000f020 : add     r30,r00,r00             r00=>00000000 r00=>00000000 r30<=00000000
        32 : [bfc00080] 0000f820 : add     r31,r00,r00             r00=>00000000 r00=>00000000 r31<=00000000

一方で、--reg_abi softの場合、

swimmer_mips --binfile ../benchmarks/releases/coremark_v1.0_mips4_gcc51_O2/coremark.bin --debug --out debug.log --reg_abi soft
less debug.log
<Finish loading global variable table>
         0 : [bfc00000] 3c1c7f00 : lui     r28,0x7f00              gp<=7f000000
         1 : [bfc00004] 279c0010 : addiu   r28,r28,0x0010          gp=>7f000000 gp<=7f000010
         2 : [bfc00008] 3c1d7f00 : lui     r29,0x7f00              sp<=7f000000
         3 : [bfc0000c] 27bd4008 : addiu   r29,r29,0x4008          sp=>7f000000 sp<=7f004008
         4 : [bfc00010] 00000820 : add     r01,r00,r00             zero=>00000000 zero=>00000000 at<=00000000
         5 : [bfc00014] 00001020 : add     r02,r00,r00             zero=>00000000 zero=>00000000 v0<=00000000
         6 : [bfc00018] 00001820 : add     r03,r00,r00             zero=>00000000 zero=>00000000 v1<=00000000
         7 : [bfc0001c] 00002020 : add     r04,r00,r00             zero=>00000000 zero=>00000000 a0<=00000000
         8 : [bfc00020] 00002820 : add     r05,r00,r00             zero=>00000000 zero=>00000000 a1<=00000000
         9 : [bfc00024] 00003020 : add     r06,r00,r00             zero=>00000000 zero=>00000000 a2<=00000000
        10 : [bfc00028] 00003820 : add     r07,r00,r00             zero=>00000000 zero=>00000000 a3<=00000000
        11 : [bfc0002c] 00004020 : add     r08,r00,r00             zero=>00000000 zero=>00000000 t0<=00000000
        12 : [bfc00030] 00004820 : add     r09,r00,r00             zero=>00000000 zero=>00000000 t1<=00000000
        13 : [bfc00034] 00005020 : add     r10,r00,r00             zero=>00000000 zero=>00000000 t2<=00000000
        14 : [bfc00038] 00005820 : add     r11,r00,r00             zero=>00000000 zero=>00000000 t3<=00000000
        15 : [bfc0003c] 00006020 : add     r12,r00,r00             zero=>00000000 zero=>00000000 t4<=00000000
        16 : [bfc00040] 00006820 : add     r13,r00,r00             zero=>00000000 zero=>00000000 t5<=00000000
        17 : [bfc00044] 00007020 : add     r14,r00,r00             zero=>00000000 zero=>00000000 t6<=00000000
        18 : [bfc00048] 00007820 : add     r15,r00,r00             zero=>00000000 zero=>00000000 t7<=00000000
        19 : [bfc0004c] 00008020 : add     r16,r00,r00             zero=>00000000 zero=>00000000 s0<=00000000
        20 : [bfc00050] 00008820 : add     r17,r00,r00             zero=>00000000 zero=>00000000 s1<=00000000
        21 : [bfc00054] 00009020 : add     r18,r00,r00             zero=>00000000 zero=>00000000 s2<=00000000
        22 : [bfc00058] 00009820 : add     r19,r00,r00             zero=>00000000 zero=>00000000 s3<=00000000
        23 : [bfc0005c] 0000a020 : add     r20,r00,r00             zero=>00000000 zero=>00000000 s4<=00000000
        24 : [bfc00060] 0000a820 : add     r21,r00,r00             zero=>00000000 zero=>00000000 s5<=00000000
        25 : [bfc00064] 0000b020 : add     r22,r00,r00             zero=>00000000 zero=>00000000 s6<=00000000
        26 : [bfc00068] 0000b820 : add     r23,r00,r00             zero=>00000000 zero=>00000000 s7<=00000000
        27 : [bfc0006c] 0000c020 : add     r24,r00,r00             zero=>00000000 zero=>00000000 t8<=00000000
        28 : [bfc00070] 0000c820 : add     r25,r00,r00             zero=>00000000 zero=>00000000 t9<=00000000
        29 : [bfc00074] 0000d020 : add     r26,r00,r00             zero=>00000000 zero=>00000000 k0<=00000000
        30 : [bfc00078] 0000d820 : add     r27,r00,r00             zero=>00000000 zero=>00000000 k1<=00000000
        31 : [bfc0007c] 0000f020 : add     r30,r00,r00             zero=>00000000 zero=>00000000 fp<=00000000
        32 : [bfc00080] 0000f820 : add     r31,r00,r00             zero=>00000000 zero=>00000000 ra<=00000000

トレースの表記が変更されるようになった。これは、RISC-Vバージョンでも適用できている。