llvm-mos / llvm-mos-sdk

SDK for developing with the llvm-mos compiler

Home Page:https://www.llvm-mos.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`.begin` subsection for memory regions

mysterymath opened this issue · comments

It's useful to be able to place binary blobs at fixed addresses, e.g., to incorporate code produces by another assembler. There isn't a general feature that allows for this for arbitrary addresses, but by adding a .begin and .end section assigned to memory regions in the SDK, a blob placed in either section could have a fixed address without futzing with the linker scripts: the start of the region in the former case, and the end of the region minus the size of the blob in the latter case. This bears some experimentation; .end might not be possible to express.

This issue is a little unclear to me; perhaps you're looking for llvm-objcopy --add-section or --update-section?

Don't think those would help here.

The broad scenario:
You've got a blob of 6502 code produced by some external process. That requires some ZP locations, some code locations, and some memory locations to do its work. Say you can get it so that there's three contiguous blocks, and if you know the address those blocks will be placed, then you can perform some external process to relocate the code accordingly.

Being able to .incbin in these blobs to .begin or .end sections would allow you to be certain what the final runtime addresses would be, regardless of how lld places other sections. The beginning and ending of a memory region are special in that regard, since their addresses are fixed and statically known; so only the first and possibly last section in a region can have addresses that don't depend on the addresses of other sections. Only one blob could be .incbined per section while maintaining this property.

Closing this; we can now incorporate ca65 object files directly, which was the main impetus for the feature.