oxidecomputer / phbl

Pico Host Boot Loader
Mozilla Public License 2.0
98 stars 7 forks source link

kernel entry: clear argument registers #53

Open dancrossnyc opened 5 days ago

dancrossnyc commented 5 days ago

At one point, we experimented with passing additional arguments into the Unix kernel from phbl. While we ultimately backed away from that design, something that has long bothered me about it is that doing so would require a flag day to coordinate between the kernel and loader, as phbl did not take care to clear argument registers when invoking the kernel's entry point, so a kernel expecting a new argument must be paired with an updated loader. While in practice this isn't an issue, since we ship the operating system image inside of the loader itself, it does require another coordination point between helios and phbl, and aesthetically it wasn't pleasing. In order to future-proof things, phbl really ought to clear the argument registers its not using on kernel entry.

Fortunately, this is relatively easy to do: when we transmute the ELF entry point value into a variable of function type, we just say it's a function that takes 6 values (the ABI specifies that the first six arguments are passed in registers), and we pass explicit 0's for anything we don't actually use.

In doing this, I did allow myself an aesthetic conceit in that disliked calling the function with all six arguments after finding the entry point; the workaround for this is to wrap its invocation in a closure that's returned from the loader. The downside is that the unsafe block in main is gone, and we're no longer printing the address of the entry point, but those seem minor.