Running 64-bit code in 32-bit x86 OS
Posted: Wed Aug 15, 2012 12:52 am
Is there a convinient way of running some 64-bit executables with a 32-bit kernel? When AMD designed x86-64, they assumed that the kernel is 64-bit, and that it uses a sub-mode for running 32-bit code. However, that is not a possible option in this case as I don't want a 64-bit kernel that runs protected mode applications in an "emulation mode".
IOW, when kernel code or 32-bit applications are running, the system should be in 32-bit mode, and syscalls should enter a 32-bit kernel. When an 64-bit application is running, the system must be setup in 64-bit mode, and needs to switch to 32-bit mode when syscalls are executed (in addition to some pointer relocations that might be needed and that can be handled with paging).
The issue is if it is feasible to switch between 32-bit and 64-bit mode relatively frequently? A special problem is IRQs, that in 64-bit mode will need to execute some dummy 64-bit IRQ stub which switches to 32-bit mode and executes the correct 32-bit IRQ (later some IRQs might provide bimodal handlers, but initially switching to 32-bit mode will be needed).
So, what is the overhead of switching from 64-bit mode to 32-bit mode and the reverse? What exactly would need to be reloaded? The IDTR would be obvious, but how about GDTR (shouldn't be needed as 64-bit mode is non-segmented)? Also, there would be a need to reload CR3 to change paging, but 32-bit and 64-bit paging could live more or less side-by-side, with 64-bit paging just mapping the kernel like the 32-bit paging does (which would be static), and mapping it's own userland space.
IOW, when kernel code or 32-bit applications are running, the system should be in 32-bit mode, and syscalls should enter a 32-bit kernel. When an 64-bit application is running, the system must be setup in 64-bit mode, and needs to switch to 32-bit mode when syscalls are executed (in addition to some pointer relocations that might be needed and that can be handled with paging).
The issue is if it is feasible to switch between 32-bit and 64-bit mode relatively frequently? A special problem is IRQs, that in 64-bit mode will need to execute some dummy 64-bit IRQ stub which switches to 32-bit mode and executes the correct 32-bit IRQ (later some IRQs might provide bimodal handlers, but initially switching to 32-bit mode will be needed).
So, what is the overhead of switching from 64-bit mode to 32-bit mode and the reverse? What exactly would need to be reloaded? The IDTR would be obvious, but how about GDTR (shouldn't be needed as 64-bit mode is non-segmented)? Also, there would be a need to reload CR3 to change paging, but 32-bit and 64-bit paging could live more or less side-by-side, with 64-bit paging just mapping the kernel like the 32-bit paging does (which would be static), and mapping it's own userland space.