Page 1 of 1

RDRAND eax crashes in Bochs

Posted: Thu Dec 13, 2018 3:19 pm
by mihe
Hello,

does anyone know why RDRAND eax crashes in bochs in Protected Mode?

For what I have seen, it seems to be implemented (http://bochs.sourceforge.net/cgi-bin/lx ... /rdrand.cc)

Checking some documentation I found this exceptions for Protected Mode (and others)

#UD If the LOCK prefix is used.
If the F2H or F3H prefix is used.
If CPUID.01H:ECX.RDRAND[bit 30] = 0.

I think the last one means that the CPU does not support RDRAND, but I cannot understand the meaning of the first two.

Any help will be very welcomed !!

Thanks in advance

Re: RDRAND eax crashes in Bochs

Posted: Thu Dec 13, 2018 11:21 pm
by nullplan
LOCK can't be used with RDRAND, and you'll get #UD if you try. Same with the REP prefixes (F2 and F3).

Re: RDRAND eax crashes in Bochs

Posted: Fri Dec 14, 2018 1:37 am
by mihe
nullplan wrote:LOCK can't be used with RDRAND, and you'll get #UD if you try. Same with the REP prefixes (F2 and F3).
Hello nullplan, first of all thanks for your answer!

I am simply using:

RDRAND eax , and trying to compile it with NASM. In runtime, it is executed in 32bits, Protected Mode, but Bochs simply crashes.

Those exceptions is just documentation I found about the RDRAND instructions, trying to figure out why it crashes.

Thanks!

Re: RDRAND eax crashes in Bochs

Posted: Fri Dec 14, 2018 1:52 am
by FusT
What does your bochs log say?

Re: RDRAND eax crashes in Bochs

Posted: Fri Dec 14, 2018 4:48 am
by iansjack
What is the version number of your Bochs?

Re: RDRAND eax crashes in Bochs

Posted: Fri Dec 14, 2018 5:27 am
by MichaelPetch
I suspect that your BOCHs hasn't been compiled with the support needed. You'll need to get the latest version 2.6.9 (or latest SVN snapshot) of the source code. You'll have to build it with at least these options: --enable-x86-64 --enable-cpu-level=6 --enable-avx. If using Linux with X-windows then configuring with this command should suffice:

Code: Select all

./configure --enable-x86-64 --enable-cpu-level=6 --enable-avx --enable-smp --enable-all-optimizations --enable-pci --enable-debugger --enable-disasm --enable-debugger-gui --enable-logging --enable-fpu --enable-3dnow --enable-cdrom --enable-x86-debugger --enable-iodebug --disable-plugins --disable-docbook --with-x --with-x11 --with-term
make
sudo make install
Then you'll need to edit the CPU options and select at least a corei7_ivy_bridge_3770k that supports rdrand. You can tell what CPUs your BOCHs supports with: bochs -help cpu. If skylake/haswell/ivybridge aren't listed you will need to build a new version.When compiling your own, unless you override the prefix the installed bochs will be at /usr/local/bin/bochs

Re: RDRAND eax crashes in Bochs

Posted: Fri Dec 14, 2018 6:27 am
by stlw
What does it mean - crashes ? Segfaults and dies ? Or emulated app closes with some error ?

Also - which version are you trying ?
RDRAND support (fake of course, Bochs just uses rand() function to produce RDRAND output) was introduced in Bochs 2.6.1 with bug in decoder.
The bug was fixed in 2.6.6 version.
You may also try latest SVN snapshot and see if the issue still there.

Stanislav

Re: RDRAND eax crashes in Bochs

Posted: Fri Dec 14, 2018 1:29 pm
by mihe
MichaelPetch wrote:I suspect that your BOCHs hasn't been compiled with the support needed. You'll need to get the latest version 2.6.9 (or latest SVN snapshot) of the source code. You'll have to build it with at least these options: --enable-x86-64 --enable-cpu-level=6 --enable-avx. If using Linux with X-windows then configuring with this command should suffice:

Code: Select all

./configure --enable-x86-64 --enable-cpu-level=6 --enable-avx --enable-smp --enable-all-optimizations --enable-pci --enable-debugger --enable-disasm --enable-debugger-gui --enable-logging --enable-fpu --enable-3dnow --enable-cdrom --enable-x86-debugger --enable-iodebug --disable-plugins --disable-docbook --with-x --with-x11 --with-term
make
sudo make install
Then you'll need to edit the CPU options and select at least a corei7_ivy_bridge_3770k that supports rdrand. You can tell what CPUs your BOCHs supports with: bochs -help cpu. If skylake/haswell/ivybridge aren't listed you will need to build a new version.When compiling your own, unless you override the prefix the installed bochs will be at /usr/local/bin/bochs
Hello Michael,

I think that is going to be the issue, because my current setup of Bochs does not support Ivy_bridge.

Supported CPU models:

bx_generic
pentium
pentium_mmx
amd_k6_2_chomper
p2_klamath
p3_katmai
p4_willamette
core_duo_t2400_yonah
atom_n270
p4_prescott_celeron_336
athlon64_clawhammer
athlon64_venice
turion64_tyler
phenom_8650_toliman
core2_penryn_t9600
corei5_lynnfield_750
corei5_arrandale_m520
corei7_sandy_bridge_2600k


I will compile with the latest one. thanks for your help!!

Re: RDRAND eax crashes in Bochs

Posted: Fri Dec 14, 2018 1:31 pm
by mihe
stlw wrote:What does it mean - crashes ? Segfaults and dies ? Or emulated app closes with some error ?

Also - which version are you trying ?
RDRAND support (fake of course, Bochs just uses rand() function to produce RDRAND output) was introduced in Bochs 2.6.1 with bug in decoder.
The bug was fixed in 2.6.6 version.
You may also try latest SVN snapshot and see if the issue still there.

Stanislav
Sorry for the using the wrong semantics here. I used the term crash because I do not know how to denominate when Bochs stops executing your code and jumps to the BIOS code in FFFFF0.

Re: RDRAND eax crashes in Bochs

Posted: Fri Dec 14, 2018 1:32 pm
by mihe
iansjack wrote:What is the version number of your Bochs?
2.6.9 but following the instructions written by Michael it seems that it needs to support Ivy Bridge, which I guess it should be one of the latest in the SVN. I will compile it later to test.

Thanks!

Re: RDRAND eax crashes in Bochs

Posted: Tue Dec 25, 2018 1:06 am
by feryno
mihe don't forget to execute the cpuid you mentioned prior the rdrand instruction to know whether it is supported (good practice for every newly introduced instruction)

Re: RDRAND eax crashes in Bochs

Posted: Wed Dec 26, 2018 8:46 pm
by linguofreak
mihe wrote:
Sorry for the using the wrong semantics here. I used the term crash because I do not know how to denominate when Bochs stops executing your code and jumps to the BIOS code in FFFFF0.
"Crash" describes that well enough, but he asked what you meant because there's a need to know what exactly is crashing. If your OS code is crashing, causing the emulated computer to triple fault or otherwise reset, that likely indicates an problem with your code or an incompatibility between your code and your current bochs setup (as turned out to be the case). If the bochs process itself crashes when a specific instruction is executed, that indicates a bug in bochs.

Re: RDRAND eax crashes in Bochs

Posted: Thu Dec 27, 2018 12:03 pm
by mihe
linguofreak wrote:
mihe wrote:
Sorry for the using the wrong semantics here. I used the term crash because I do not know how to denominate when Bochs stops executing your code and jumps to the BIOS code in FFFFF0.
"Crash" describes that well enough, but he asked what you meant because there's a need to know what exactly is crashing. If your OS code is crashing, causing the emulated computer to triple fault or otherwise reset, that likely indicates an problem with your code or an incompatibility between your code and your current bochs setup (as turned out to be the case). If the bochs process itself crashes when a specific instruction is executed, that indicates a bug in bochs.
Thanks for the clarification. It was just a "crash" inside Bochs, not the Bochs process itself crashing.

Re: RDRAND eax crashes in Bochs

Posted: Thu Dec 27, 2018 12:05 pm
by mihe
feryno wrote:mihe don't forget to execute the cpuid you mentioned prior the rdrand instruction to know whether it is supported (good practice for every newly introduced instruction)
Thanks for the tip!!