Excluding the boot sector (because of size limits), I have come to the conclusion that all BIOS interrupt calls should be routed via wrapper procedures: all registers (including segments) are saved, input parameters are set, all irrelevant registers are cleared, a call is made, registers are saved (return values), and original register values are restored. If the CPU is at least 32-bit, the high bytes of registers are taken into account.
Is this inefficient? It surely is but I believe it is worth it. We are only talking about boot loaders here and the efficiency is not extremely critical. The main benefit: this will forcibly drive off many bugs. When BIOS interrupts calls are always made from the known state, it is also quite clean for BIOS (not that it matters). Here is an example:
Code: Select all
[assembly code...]
[set input parameters]
[int 0x??]
What if we had tested this extensively and noticed that it works and we then made a change:
Code: Select all
[UPDATED assembly code...]
[set input parameters]
[int 0x??]
The line "[assembly code...]" always left certain values to some registers but now we added the line "[UPDATED assembly code...]" that makes this whole thing unstable. Of course, we should not have any problems with this but the reality is different. We might have "accidentally" left good register values from previous code and that made it work. If we set all registers to known values before a call, it would be much more robust.
Especially for us, because usually we are not able to test our code on every computer, this would be an easy way to get rid of some hidden bugs. Also, this would not significantly increase the size of code. Only the efficiency would decrease a little bit.