Beispiel #1
0
def _process_core_sim_log_fd(log_fd, csv_fd, full_trace=True):
    """Process core simulation log.

    Reads from log_fd, which should be a file object containing a trace from an
    core simulation. Writes in a standard CSV format to csv_fd, which should be
    a file object opened for writing.

    If full_trace is true, this dumps information about operands for, replacing
    absolute branch destinations with offsets relative to the current pc.

    """
    instr_cnt = 0

    trace_csv = RiscvInstructionTraceCsv(csv_fd)
    trace_csv.start_new_trace()

    trace_entry = None

    for line in log_fd:
        if re.search("ecall", line):
            instr_cnt += 1
            # Extract instruction information
            m = ECALL_RE.search(line)
            if m:
                # Write the extracted instruction to a csvcol buffer file
                trace_entry = RiscvInstructionTraceEntry()
                trace_entry.instr_str = "ecall"
                trace_entry.pc = m.group("pc")
                trace_entry.binary = m.group("bin")
                trace_csv.write_trace_entry(trace_entry)
            break

        # Extract instruction information
        m = INSTR_RE.search(line)
        if m:
            instr_cnt += 1
            # Write the extracted instruction to a csvcol buffer file
            trace_entry = RiscvInstructionTraceEntry()
            trace_entry.instr_str = m.group("instr")
            trace_entry.instr = m.group("instr").split()[0]
            trace_entry.pc = m.group("pc")
            trace_entry.binary = m.group("bin")
            if full_trace:
                # Convert the operands into ABI format for
                # the functional coverage flow
                operands = m.group("instr").split()[1]
                trace_entry.operand = operands
                process_operands(trace_entry)
                trace_entry.operand = convert_operands_to_abi(
                    trace_entry.operand)
                process_trace(trace_entry)

        c = RD_RE.search(line)
        if c:
            trace_entry.gpr.append('{}:{}'.format(
                gpr_to_abi("x%0s" % c.group("rd")), c.group("rd_val")))
            trace_csv.write_trace_entry(trace_entry)

    return instr_cnt
Beispiel #2
0
def _process_ibex_sim_log_fd(log_fd, csv_fd, full_trace=True):
    """Process ibex simulation log.

    Reads from log_fd, which should be a file object containing a trace from an
    Ibex simulation. Writes in a standard CSV format to csv_fd, which should be
    a file object opened for writing.

    If full_trace is true, this dumps information about operands for, replacing
    absolute branch destinations with offsets relative to the current pc.

    """
    instr_cnt = 0

    trace_csv = RiscvInstructionTraceCsv(csv_fd)
    trace_csv.start_new_trace()

    trace_entry = None

    for line in log_fd:
        if re.search("ecall", line):
            break

        # Extract instruction information
        m = INSTR_RE.search(line)
        if m is None:
            continue

        instr_cnt += 1
        # Write the extracted instruction to a csvcol buffer file
        trace_entry = RiscvInstructionTraceEntry()
        trace_entry.instr_str = m.group("instr")
        trace_entry.instr = m.group("instr").split()[0]
        trace_entry.pc = m.group("pc")
        trace_entry.binary = m.group("bin")
        if full_trace:
            expand_trace_entry(trace_entry, m.group("instr").split()[1])

        c = RD_RE.search(line)
        if c:
            abi_name = gpr_to_abi("x{}".format(c.group("rd")))
            gpr_entry = "{}:{}".format(abi_name, c.group("rd_val"))
            trace_entry.gpr.append(gpr_entry)

        trace_csv.write_trace_entry(trace_entry)

    return instr_cnt
Beispiel #3
0
def convert_operands_to_abi(operand_str):
    """Convert the operand string to use ABI register naming.

    At this stage in the conversion of the Ibex log to CSV format, the operand
    string is in this format:
        "x6,x6,1000".
    This function converts the register names to their ABI equivalents as shown below:
        "t1,t1,1000".
    This step is needed for the RISCV-DV functional coverage step, as it assumes that
    all operand registers already follow the ABI naming scheme.

    Args:
        operand_str : A string of the operands for a given instruction

    Returns:
        A string of the operands for the instruction, with register names converted to ABI.
    """
    operand_list = operand_str.split(",")
    for i in range(len(operand_list)):
        converted_op = gpr_to_abi(operand_list[i])
        if converted_op != "na":
            operand_list[i] = converted_op
    return ",".join(operand_list)