1

并感谢您之前在How to make "%bp.hap.run-until name = X86_HLT_Instr" 中提供的帮助?

我的下一个障碍是当我开始跑步时 %rip 神奇地变为零。

我的测试程序:

#include <simics/magic-instruction.h>
__attribute__((noinline))
void MagicBreakpoint() {
  MAGIC_BREAKPOINT;
  asm volatile ("hlt");
}
extern "C" void _start() {
  asm volatile ("mov $42, %rax");
  MagicBreakpoint();
}

0000000000401000 <_Z15MagicBreakpointv>:
  401000:   53                      push   %rbx
  401001:   b8 11 47 00 00          mov    $0x4711,%eax
  401006:   0f a2                   cpuid  
  401008:   f4                      hlt    
  401009:   5b                      pop    %rbx
  40100a:   c3                      retq   
  40100b:   0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)

0000000000401010 <_start>:
  401010:   48 c7 c0 2a 00 00 00    mov    $0x2a,%rax
  401017:   e9 e4 ff ff ff          jmpq   401000 <_Z15MagicBreakpointv>


我想看到的是从_start开始执行,将%rax设置为42,然后点击魔术指令,然后退出。相反,执行从 %rip=0 开始。

我的脚本:

run-command-file "%simics%/targets/qsp-x86/firststeps-no-network.simics"

$start = ($system.mb.cpu0.core[0][0].load-binary ./small)
$system.mb.cpu0.core[0][0].set-pc $start   ## Special command for the PC
$system.mb.cpu0.core[0][0].write-reg "rsp" 0x7fffffffdf50

enable-magic-breakpoint

print -x %rip
print -x %rsp

step-instruction
print -x %rip
quit

./simics -no-gui t2.simics 
Intel Simics 6 (build 6096 linux64) Copyright 2010-2021 Intel Corporation


Use of this software is subject to appropriate license.
Type 'copyright' for details on copyright and 'help' for on-line documentation.

[board.mb.cpu0.core[0][0] info] VMP disabled. Failed to open device.

WARNING: Simics failed to enable VMP. Enabling VMP substantially improves
         simulation performance. The problem is most likely caused by the
         vmxmon kernel module not being properly installed or updated.
         See the "Simics User's Guide", the "Performance" section,
         for instructions how to setup VMP.


Welcome to Simics!

An x86 target machine, referred to as a Quick Start Platform (QSP)
in the documentation, has been just created.
To start the simulation, enter the command "run" (or simply "r") at
the Simics prompt. This will boot Linux and automatically log you in.
You will see the login appear in the serial console window.

Note that during the boot Linux will emit a couple
of harmless warning messages related to ACPI errors.

To pause the simulation, use the command "stop". To resume simulation,
enter the command "run" again.

0x401010
0x7fffffffdf50
[board.mb.cpu0.core[0][0]] Exception: General_Protection_Exception
0x0

如您所见,在执行之前step-instruction%rip0x401010,而在执行之后step-instruction%rip是零。

4

1 回答 1

2

您的问题是 x86 cpu 以 16 位传统模式启动,但您的代码以 64 位代码启动。

使用此目标,您可以尝试运行它直到它达到 64 位模式,然后再加载和执行二进制文件:

simics> bp.hap.run-直到名称 = Core_Mode_Switch 索引 = 5

当模拟停止时,您应该处于 64 位模式(索引 5 将指定)。您可以通过运行pregs命令检查当前执行模式。此时,它应该可以运行以“$start =”开头的代码。

于 2021-08-10T13:08:49.547 回答