Using kmBranch to add a branch from one address to another causes exceptions while linking
When trying to use the kmBranch function to redirect a certain address to another, one will be met with the following exceptions while linking:
at Kamek.Word.op_GreaterThanOrEqual(Word a, Word b)
at Kamek.KamekFile.Contains(Word addr)
at Kamek.Commands.BranchCommand.Apply(KamekFile file)
at Kamek.KamekFile.ApplyStaticCommands()
at Kamek.KamekFile.LoadFromLinker(Linker linker)
at Kamek.Program.Main(String[] args)
In this case, I am trying to redirect a function to a more optimized version found elsewhere, by using
kmBranch(0x80005f34, 0x801D17F8);
Maybe I am thinking about it wrong, but is there any reason why the function to add a branch wouldn't be able to insert a branch?
You should define the destination as an extern function. That way should work and will be auto-ported.
After defining the dest as an extern void function, adding the function to the symbol file, and replacing the address with the function name in the kmBranch results in the same error.
The original intended use of kmBranch was to branch to new functions in your own code:
void example() {
// ...
}
kmBranch(0x80005f34, example);
So the way in which you're using it was probably never tested. But it does make sense to support it, so I've opened PR #30 to fix it.
The original intended use of
kmBranchwas to branch to new functions in your own code
Yeah I figured this was the case
But it does make sense to support it, so I've opened PR #30 to fix it. Thanks for this, it should be able to get the job done!