running 32-bit code in LM64
Posted: Wed Aug 16, 2023 5:04 pm
I have had success in getting Win64 executables to
run under UEFI with a relatively small amount of
"glue" to switch formats. That's what the original
UCX64 at http://pdos.org is.
I decided to see if I could get Win32 executables
to run instead of Win64, using different - more
complicated - "glue".
Here is a simple call to puts, but written in assembler
(so I need a C compiler to generate assembler that
looks like this - a separate exercise):
https://sourceforge.net/p/pdos/gitcode/ ... demo32.asm
So this is dependent on msvcrt.dll, and then this loader code:
https://sourceforge.net/p/pdos/gitcode/ ... /exeload.c
(search for second occurrence of w32puts) will put in the stubs for the win32
executable, and the puts stub can be found here:
https://sourceforge.net/p/pdos/gitcode/ ... 32hack.asm
So anyway, with this in place, it means I can write a 32-bit
windows executable that works on anything from win 95
to win 11, and it also runs on an appropriate 64-bit UEFI-based
system (basically just UCX64 from http://pdos.org). Note that
this is running 32-bit code in long mode (not CM32). And note
that I don't exit boot services.
This has been tested under qemu and on real hardware.
There will be issues for something like printf, where I don't
know how many parameters there are. I could potentially get
around that by making it mandatory for (my) Win32 executables
to call getmainargs and if argc is (faked to be) greater than
x'80000000' (I did something similiar in PDPCLIB for the Amiga)
then it means that argv is also faked, and is a structure, and
you need to go there to fetch the real values of argc and argv,
as well as a "global" variable that contains the number of
arguments when you call a variable-argument function. The
compiler would generate code to say that if that global pointer
is not NULL then set it to the argument count, otherwise, take
no action as you are running under a normal Win32 environment.
I've only done proof of concept for 2 functions so far. Maybe
there is some show-stopper I will find later?
Any thoughts/improvements?
You can download a disk image containing the system from http://pdos.org
at the bottom of the University Challenge x64 section.
Thanks. Paul.
run under UEFI with a relatively small amount of
"glue" to switch formats. That's what the original
UCX64 at http://pdos.org is.
I decided to see if I could get Win32 executables
to run instead of Win64, using different - more
complicated - "glue".
Here is a simple call to puts, but written in assembler
(so I need a C compiler to generate assembler that
looks like this - a separate exercise):
https://sourceforge.net/p/pdos/gitcode/ ... demo32.asm
So this is dependent on msvcrt.dll, and then this loader code:
https://sourceforge.net/p/pdos/gitcode/ ... /exeload.c
(search for second occurrence of w32puts) will put in the stubs for the win32
executable, and the puts stub can be found here:
https://sourceforge.net/p/pdos/gitcode/ ... 32hack.asm
So anyway, with this in place, it means I can write a 32-bit
windows executable that works on anything from win 95
to win 11, and it also runs on an appropriate 64-bit UEFI-based
system (basically just UCX64 from http://pdos.org). Note that
this is running 32-bit code in long mode (not CM32). And note
that I don't exit boot services.
This has been tested under qemu and on real hardware.
There will be issues for something like printf, where I don't
know how many parameters there are. I could potentially get
around that by making it mandatory for (my) Win32 executables
to call getmainargs and if argc is (faked to be) greater than
x'80000000' (I did something similiar in PDPCLIB for the Amiga)
then it means that argv is also faked, and is a structure, and
you need to go there to fetch the real values of argc and argv,
as well as a "global" variable that contains the number of
arguments when you call a variable-argument function. The
compiler would generate code to say that if that global pointer
is not NULL then set it to the argument count, otherwise, take
no action as you are running under a normal Win32 environment.
I've only done proof of concept for 2 functions so far. Maybe
there is some show-stopper I will find later?
Any thoughts/improvements?
You can download a disk image containing the system from http://pdos.org
at the bottom of the University Challenge x64 section.
Thanks. Paul.