Start x86_64 code on x86 (32bit) Linux, running on x86_64 CPU
Asked Answered
P

3

2

?Is it possible to start an x86_64 code on i686 Linux (x86, 32-bit)? My CPU is modern Core 2 and it can run x86_64 64-bit code itself, but the OS is 32bit.

The code to start is pure mathematic, and it need almost no interaction with OS.

I want to measure, how fast will be my program in 64bit mode comparing with 32-bit mode. The program is to solve huge combinatoric problem and full size run is dozens of hours.

I can start 64bit code with qemu, but it will be not native execution and speed in qemu will be not related to real cpu speed.

Peckham answered 2/6, 2011 at 11:58 Comment(1)
In theory you can write a kernel module to take over the kernel and replace it with a 64-bit kernel, while at the same time keeping the data structures(with some conversion) intact. But I'm going to guess you're not doing that.Niel
H
4

You won't be able to run x86_64 programs on a 32bit kernel without some form of emulation. (The other way around works just fine though, with no emulation.)

To be able to run 64bit code on x86_64, you have to enter "long mode" which requires the appropriate page tables to be set up (among other things). A 32bit kernel won't have done any 64bit page tables or mappings. So userspace code can't enter 64bit mode. It might be possible with some kernel help, but a 32bit kernel is simply not prepared for that kind of thing.

And since you can run 32bit code just fine with a 64bit kernel, there is no real reason not to use a 64bit kernel these days, especially if you have some code that could benefit from 64bit mode (more registers in particular).

Why don't you just boot from a 64bit live-cd? Or install a 64bit distribution on a separate disk or partition?

Havens answered 2/6, 2011 at 12:18 Comment(7)
Why "won't be able to run x86_64 programs on a 32bit kernel" ? The i686 linux can't be turned off and|or replaced due to policy.Peckham
Clarified my answer. The memory/page table structure for 64bit mode is different from the 32bit one (large sizes, one more indirection level, possibility of different page sizes), and that has to be set up by the kernel.Havens
due to policy I cant change a kernel.Peckham
then you'll have to emulate, or keep running in 64bit mode, or use a live-cd to test.Havens
but my linux "can't be turned off and|or replaced". Emulation will not give me a real speed comparability between 32 and 64 code, will it?Peckham
I second the idea about the live CD. Most of them nowadays will even come with enough tools to allow you to build your program while running on the live CD :)Lykins
but my linux "can't be turned off", it is a 24/7 turned on machine. Shall I buy a notebook and use it? Also, live usb is more comfort than cd/dvd, just created one.Peckham
E
3

Use vmware; it will work just fine running a 64-bit VM on a 32-bit host OS provided the CPU supports it.

Equinox answered 3/6, 2011 at 16:23 Comment(4)
And will vmware work fine with 64-bit guest on 32-bit CPU? Qemu will.Peckham
No, but vmware will run the VM at a usable speed. Emulating instructions is not cool, unless you're trying to run a very old or slow system.Equinox
Also, you can't buy 32-bit CPUs any more.Equinox
I can. There are used CPUs, there are older Atom, there are VIA and other nano-x86 producers. Also, there are trillions of 32-bit x86 CPU already used.Peckham
P
0

There is a cycle-accurate simulator for x86/x86_64. By default it will emulate AMD's K8

PTLsim is a state of the art cycle accurate microprocessor simulator and virtual machine for the x86 and x86-64 instruction sets. PTLsim models a full out of order processor core, featuring extensive memory and branch speculation with replay, a highly configurable clustered microarchitecture with various issue queue designs, a full cache hierarchy and memory subsystem and supporting hardware.

Unfortunately it can't run an x86_64 code on 32-bit x86 (cite from FAQ)

Of course, the 32-bit version of PTLsim will lack x86-64 support

But the speed should correlate with real run and a lot of information is available.

Peckham answered 2/8, 2011 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.