RDRAND eax crashes in Bochs

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mihe
Member
Member
Posts: 38
Joined: Sun Oct 21, 2018 1:37 pm

RDRAND eax crashes in Bochs

Post 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
nullplan
Member
Member
Posts: 1801
Joined: Wed Aug 30, 2017 8:24 am

Re: RDRAND eax crashes in Bochs

Post 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).
Carpe diem!
mihe
Member
Member
Posts: 38
Joined: Sun Oct 21, 2018 1:37 pm

Re: RDRAND eax crashes in Bochs

Post 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!
FusT
Member
Member
Posts: 91
Joined: Wed Sep 19, 2012 3:43 am
Location: The Netherlands

Re: RDRAND eax crashes in Bochs

Post by FusT »

What does your bochs log say?
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: RDRAND eax crashes in Bochs

Post by iansjack »

What is the version number of your Bochs?
MichaelPetch
Member
Member
Posts: 799
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: RDRAND eax crashes in Bochs

Post 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
stlw
Member
Member
Posts: 357
Joined: Fri Apr 04, 2008 6:43 am
Contact:

Re: RDRAND eax crashes in Bochs

Post 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
mihe
Member
Member
Posts: 38
Joined: Sun Oct 21, 2018 1:37 pm

Re: RDRAND eax crashes in Bochs

Post 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!!
mihe
Member
Member
Posts: 38
Joined: Sun Oct 21, 2018 1:37 pm

Re: RDRAND eax crashes in Bochs

Post 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.
mihe
Member
Member
Posts: 38
Joined: Sun Oct 21, 2018 1:37 pm

Re: RDRAND eax crashes in Bochs

Post 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!
feryno
Member
Member
Posts: 73
Joined: Thu Feb 09, 2012 6:53 am
Location: Czechoslovakia
Contact:

Re: RDRAND eax crashes in Bochs

Post 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)
hypervisor-based solutions developer (Intel, AMD)
linguofreak
Member
Member
Posts: 510
Joined: Wed Mar 09, 2011 3:55 am

Re: RDRAND eax crashes in Bochs

Post 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.
mihe
Member
Member
Posts: 38
Joined: Sun Oct 21, 2018 1:37 pm

Re: RDRAND eax crashes in Bochs

Post 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.
mihe
Member
Member
Posts: 38
Joined: Sun Oct 21, 2018 1:37 pm

Re: RDRAND eax crashes in Bochs

Post 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!!
Post Reply