rosco_m68k icon indicating copy to clipboard operation
rosco_m68k copied to clipboard

WIP: Link stage2 against stage1

Open 0xTJ opened this issue 1 month ago • 0 comments

The main goal of these changes is to allow firmware stage2 to be linked against stage1, so that we can eliminate some duplicated code. I noticed in the code a comment that math functions like divmod were duplicated (some machine print functions were too), so figured I'd clean that up.

This PR does this by first doing partial linking on the stage1 objects, producing an ELF file where most addresses have been resolved to absolute values, but some (stage2 ZIP start and end) still need to be relocated. Then stage2 is linked, using that ELF as only a source of symbols, then compressed and turned into an object. Finally the top-level Makefile links together the stage1 and stage2 objects. As the kernel was already been linked into a static library with its own Makefile, I've also pulled it out to the same level as stage1 and stage2.

There were a number of places with duplicated Makefile contents, so I've also moved that out to a common.mk file. The part I've had the hardest time in figuring out is how to pass around config options. What I've currently settled on is exporting them all in the top-level Makefile, to be used by the stage1 and stage2, but I'm open to thoughts on if they should be moved to a "config.mk" that gets included in each Makefile.

Another alternative would be to have the top-level, stage1, and stage2 all be in one make execution, include-ing instead of using recursive make.

The initial changes kept the original structure, without pulling so many things out of the Makefiles, so if this is too much of a change, I'm also happy to move back to that, and just keep the partial linking changes. I've got this as WIP for now to gather some thoughts.

0xTJ avatar May 22 '24 12:05 0xTJ