выполнение симуляции голого металла (%rip устанавливается на ноль при запуске)
и спасибо за вашу предыдущую помощь в разделе Как заставить "%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
Как видите, перед выполнением выполняется
0x401010
, и сразу после
step-instruction
,
%rip
равно нулю.
1 ответ
Ваша проблема в том, что процессор x86 запускается в 16-битном устаревшем режиме, но ваш код в 64-битном коде.
С этой целью вы можете попробовать запустить ее, пока она не достигнет 64-битного режима, перед загрузкой и выполнением двоичного файла:
simics> bp.hap.run-until name = Core_Mode_Switch index = 5
Когда симуляция остановится, вы должны перейти в 64-битный режим (который будет указывать в индексе 5). Вы можете проверить текущий режим выполнения, выполнив команду pregs . На этом этапе, вероятно, сработает запуск вашего кода, начинающегося с «$ start =».