This is from dictation. There may be some errors.Okay, now I have an idea of what you're trying to do.
There are a number of different free boot loaders available out there. But only a few of these have source code available. And of these, I think there is only one that would be useful to you. I am thinking about a version of GRUB used by the Linux community for booting both Linux and Windows on one computer. It is called GRUB 2 and here is a link on Wikipedia that covers all the major boot loaders in common use.
https://en.wikipedia.org/wiki/Comparison_of_boot_loadersIf you have not already done so, please look over this article very carefully. It has the information you need to help you write your own boot loader, if that is what you want to do.
Also, note that some boot loaders are not scriptable. When they say scriptable, it means the boot loader can be programmed with a script that gives it the behaviors you want to load the operating system you want. That is a much better option than trying to write everything yourself from scratch. The script adds very little overhead to the total size of the boot loader and has little impact on the speed of the book loader. The boot load speed is mostly a function of the size of the system and the speed of the hard drive and not a function of how big the script is.
Another alternative would be to purchase one of the commercial boot loaders that have been designed to handle both Windows, Linux and the new firmware now in use on personal computers.
This is the best I can do for you. I've used boot loaders for many years and have learned how to boot different versions of Windows and Linux. But trying to boot from another drive gets to be an issue. The computer firmware wants to boot from just one device. If that device is not available, it tries the next device in the list.
Microsoft has made some adjustments to Windows so that you can now boot Windows from a USB device. With older versions of Windows that was not possible.
I hope this is of some help to you.
And yes, it is possible to use GRUB to boot to either Linux or Windows or even an operating system on another drive. Somewhere in the documentation it's there, but I was not able to find it myself and I ended up needing to use the firmware to switch to another device.
End of my dictation.