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>.rawper thread, holding a flat array of 80-byte records: MacSim’strace_info_cpu_swithout 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_opcodeis the instruction’s XED category (MacSim’sCPU_OPCODE_ENUM), except that names containingNOP,MUL,DIVand the fourPREFETCHhints get MacSim’s special values, just as the Pin tool does. Categories come from a table generated from Intel XED’s own ISA files (seetools/gen_xed_categories.py).- Registers use Pin 3.13’s
REGnumbering of the full register (eax→rax= 10), sorted and de-duplicated, as Pin’sstd::setdoes. All widths of vector register n map tozmmn, so a write toymm3and a read ofxmm3are 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§
- Macsim
Reader - Reads records back from a
.rawfile (for checking and for the CLI). - Macsim
Record - One MacSim x86 trace record (
trace_info_cpu_sminus the last field). - Macsim
Writer - Writes one vCPU’s MacSim
.rawstream. - Static
Info - The static half of a record, computed once per instruction.
Enums§
- Category
Source - How the opcode of an instruction was determined (for coverage statistics).
- CfType
- MacSim’s control-flow types (
CF_TYPEintrace_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 (fromsrc/trace_read.h). - RECORD_
SIZE - Size of one record in a
.rawfile (MacSim’sCPU_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
REGid of the full register containingr, orNonefor registers Pin’s MacSim tool never reports. - raw_
path - Path of thread
tid’s raw file for trace base namebase. - selected_
accesses - Which of
rec.accessesa MacSim record with this template holds: the firstnum_ldreads (ld_vaddr1,ld_vaddr2) and, ifhas_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>.txtheader MacSim opens first.