bluemoon wrote:Sound like your're working on an binary compatibility layer (For example,
Linux Binary Compatibility).
I'm surprised you do it on bare-bone, since most people would implement it
last when the OS has richer functionality.
Anyway, I'm interested on how many functions you provide in the
bulit-in runtime, since it affect the usability on the whole environment.
Actually, I am not doing that myself, but use this concept on Linux.
Pe2boot's output is a PE32 executable. The runtime it adds to an EXE is only 1216 bytes. Think of it as an empty shell for your app with several handles bolted outside that different loading systems can hook to.
When run on Windows it simply lets you call Win32 functions that you normally import from various DLLs.
When Linux loader sees PE32 signature it calls Wine loader, which handles any Win32 calls. In the hello.c example those are printf() and exit() normally found in MSVCRT.dll just as it would happen on Windows. In addition to Win32 functions, you can also call Linux syscalls via "int 80h" (unless it is blocked by security policy).
When you run on DOS or bare hardware, the runtime will detect available memory, and switch CPU into protected mode and call your app. Your interface to the outside world is int86(regs,regs) function and any port I/O, if you like so.
Normally, if you want to make a system utility that runs and boots on various platforms, you would need to create separate:
- Win32 executable to run on Windows 9x, XP, Vista, 7 (or their server siblings)
ELF executable to run on Linux, FreeBSD, etc...
DOS executable with some sort of 32-bit extender for FreeDOS, MS-DOS, etc...
Bare hardware version of the executable packaged onto
- Bootable CDROM image
Bootable Floppy/USB image
Image for network boot using PXE/BOOTP
Boot from HD partition, CHS/LBA, MBR/EFI, large sector size headaches...
Things will get complicated fast...
If you want to limit number of binaries the first logical step is to use PE32 because, thanks to Wine developers, virtually any linux box could run it or is one apt-get away from being able to.
Then to take care of DOS and direct bare hardware boot you need a small runtime that switches CPU into protected mode. This has been done by many people for the last 25 years (80386 was introduced by Intel in 1985). What I did was adding an integrated dynamic loader that could rebase Win32 code to any address and made entire thing ridiculously small (1216 bytes).
Finally, for various boot methods there are few tricks inside runtime itself and and additional 512 byte FAT1x boot sector that works on CDROMs, Floppies, USB sticks, and HardDrives of various sizes and geometries. It is possible to create a hybrid image that can be both burned onto CD/DVD or rawwritten onto floppy or USB. When you boot from it your app.exe boots, when you insert it under an OS you can run app.exe under that OS.
Conceptually, it might even be possible to create a binary that is a valid PE32 executable, valid PXE/BOOTP binary, valid OPTION ROM image
AND a valid hybrid bootable CDROM/Floppy/USB/HD image all at the same time. But that would be an overkill
Any takers?