I'm currently working on an emulated CPU (which does not exist in reality) and no tools exist for that type of CPU.
The idea is to write an assembler which outputs "assembly" files only containing .byte
lines so I can use the "x86 binutils" tool chain to create the executable (my-as
-> x86-as
-> ld
-> objcopy
).
Example:
input.s:
instx r1, 0x12
insty r2, 0x34
instz r3, 0x5678
output.s:
.byte 0xa1, 0x12 # instx r1, 0x12
.byte 0xb2, 0x34 # insty r2, 0x34
.byte 0xc3, 0x56, 0x78 # instz r3, 0x5678
My problem are the relocations. Example:
input.s:
instxy r4, symbol
output.s:
.byte 0xd4, (((symbol&0xF000)>>8)|((symbol&0xF0000)>>16))
... but "symbol" is some symbol defined in another object file or a label whose address is not known before link time.
There seem to be other developers having more or less the same problem: Non-standard relocations; so at least I'm not the first person in need of this feature.
So my question is if the GNU binutils tool chain (or an additional GNU tool) already provides an easy way of defining "user-defined" relocation types?
Maybe there are other object file formats supporting this feature?
I already have an idea how to implement an additional tool adding this capability to the existing "binutils" tool chain but I want to avoid spending time implementing a new tool when this feature is already implemented.
EDIT
As it seems that such a feature does not exist, yet, I implemented my solution and published it on SourceForge - just for the case someone else needs such a feature.