Skip to main content

Module macsim

Module macsim 

Source
Expand description

Writing (and reading) traces in MacSim’s x86 format.

MacSim reads x86 traces produced by its Pin tool (tools/x86_trace_generator). A trace is a directory entry made of

  • a text file NAME.txt:
    x86 1.3
    <thread count>
    <thread id> <start instruction count>
    ...
  • one gzip-compressed file NAME_<tid>.raw per thread, holding a flat array of 80-byte records: MacSim’s trace_info_cpu_s without its last field (m_instruction_next_addr, which the reader fills in itself).

This module produces exactly that, one MacSim thread per guest vCPU, so a trace from this crate drops into MacSim where a Pin trace would. MacsimRecord mirrors the C struct field by field; the layout is checked against MacSim’s own header by a test.

§How an instruction becomes a record

The static fields (opcode category, registers, branch type) are filled in exactly the way the Pin tool fills them, using the same rules:

  • m_opcode is the instruction’s XED category (MacSim’s CPU_OPCODE_ENUM), except that names containing NOP, MUL, DIV and the four PREFETCH hints get MacSim’s special values, just as the Pin tool does. Categories come from a table generated from Intel XED’s own ISA files (see tools/gen_xed_categories.py).
  • Registers use Pin 3.13’s REG numbering of the full register (eax → rax = 10), sorted and de-duplicated, as Pin’s std::set does. All widths of vector register n map to zmmn, so a write to ymm3 and a read of xmm3 are seen as dependent.
  • At most two loads and one store fit in a record. Instructions with more (gathers, some string and stack instructions) keep the first ones, like the Pin tool, and are flagged in the extended trace.

Structs§

MacsimReader
Reads records back from a .raw file (for checking and for the CLI).
MacsimRecord
One MacSim x86 trace record (trace_info_cpu_s minus the last field).
MacsimWriter
Writes one vCPU’s MacSim .raw stream.
StaticInfo
The static half of a record, computed once per instruction.

Enums§

CategorySource
How the opcode of an instruction was determined (for coverage statistics).
CfType
MacSim’s control-flow types (CF_TYPE in trace_read.h).

Constants§

GENERATOR_VERSION
The trace-generator version MacSim’s reader expects (t_gen_ver).
MAX_DST
Most destination registers a record holds (MAX_DST_NUM).
MAX_SRC
Most source registers a record holds (MAX_SRC_NUM).
OPCODE_NAMES
MacSim’s CPU_OPCODE_ENUM, in order (from src/trace_read.h).
RECORD_SIZE
Size of one record in a .raw file (MacSim’s CPU_TRACE_SIZE).

Functions§

fill_dynamic
Fills the dynamic fields of a record whose static fields came from static_info: addresses, sizes, direction, branch outcome. Returns true if the instruction had more accesses than the record can hold.
opcode_for
The MacSim opcode for an instruction, following the Pin tool’s rules.
pin_reg
Pin 3.13 REG id of the full register containing r, or None for registers Pin’s MacSim tool never reports.
raw_path
Path of thread tid’s raw file for trace base name base.
selected_accesses
Which of rec.accesses a MacSim record with this template holds: the first num_ld reads (ld_vaddr1, ld_vaddr2) and, if has_st, the first write (st_vaddr), in that order. Instruction fetches and suppressed accesses are never in a record. The second value is true if some data access did not fit.
static_info
Computes the static fields of a MacSim record for an instruction.
write_config
Writes the <base>.txt header MacSim opens first.