What are pseudo-instructions for in gem5?

不羁岁月 提交于 2021-02-05 08:18:10

问题


So, I was seeing how some simulations in gem5 are implemented, more specifically, I was having a look at PIMSim (https://github.com/vineodd/PIMSim). I saw they had implemented some pseudo-instructions for the x86 architecture. I have seen these pseudo-instructions are only used in full system mode. For that they have modified the following files:

  • include/gem5/m5ops.h
  • util/m5/m5op_x86.S
  • src/arch/x86/isa/decoder/two_byte_opcodes.isa
  • src/sim/pseudo_inst.hh(cc)

I have understood what changes are neccessary to implement a custom pseudo-instruction, but what I do not understand is what they are and how they are used. I do not find any place outside these files this functions are called. Any help? Thanks in advance!


回答1:


Pseudo ops are ways to make magic simulation operations from the inside the guest, this type of technique is more generally known as guest instrumentation

They can be used/implemented either as:

  • magic instructions placed in unused encoding space of the real ISA

    I think this is always enabled, except in KVM where the host CPU takes over and just crashes if those unknown instructions are seen.

  • access to a magic memory address. This is configured/enabled from the Python configs, System.py contains:

    m5ops_base = Param.Addr(
        0xffff0000 if buildEnv['TARGET_ISA'] == 'x86' else 0,
        "Base of the 64KiB PA range used for memory-mapped m5ops. Set to 0 "
        "to disable.")
    
  • ARM semihosting: some custom semihosting operations were wired to m5ops recently. It is worth nothing that there is some overlap between what some m5ops and what some of the standardized semihosting operations can achieve, like quitting the simulator.

Some of the most commons m5ops ones are:

  • m5 exit: quit simulator
  • m5 checkpoint: take a checkpoint
  • m5 dumpstats: dump stats
  • m5 resetstats: zero out the stats and restart counting for the next m5 dumpstats
  • m5 readfile: read the value of host fs.py --script option contents, very useful to run different workloads after Linux boot checkpoint

m5ops are useful because it is often hard to determine when you want to do the above operations in other ways, e.g.: do something when Linux finishes boot. E.g., to do it natively naively from the simulator, you'd need to know in advance at what tick that happens. You could mess around with checking if the PC matches some address (already done e.g. for Linux panic checking), but that's a bit harder.

There also exists the in-tree m5 tool that you can cross compile and place in your full system guest to exposes the magic instructions from an executable CLI interface.

But you can just hard code them in your binaries as well to get more precise results if needed, e.g. hardcoding as in X86

#define LKMC_M5OPS_CHECKPOINT __asm__ __volatile__ (".word 0x040F; .word 0x0043;" : : "D" (0), "S" (0) :)
#define LKMC_M5OPS_DUMPSTATS  __asm__ __volatile__ (".word 0x040F; .word 0x0041;" : : "D" (0), "S" (0) :)

more hardcode examples at: https://github.com/cirosantilli/linux-kernel-module-cheat/blob/4f82f79be7b0717c12924f4c9b7c4f46f8f18e2f/lkmc/m5ops.h Or you can also use them more nicely and laboriously from the mainline tree as shown at: How to use m5 in gem5-20

Some more info can also be found at: https://cirosantilli.com/linux-kernel-module-cheat/#m5ops



来源:https://stackoverflow.com/questions/63488050/what-are-pseudo-instructions-for-in-gem5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!