Check the compiler manual about how far function pointers and far data/object pointers are represented.
They are basically differently encoded, data pointers are using a big endian byte ordering, far function pointers are using the ordering as expected by the CALL instruction.
I thought this topic was mentioned in the forum before, but with a quick search, I did not find anything.
You could:
- Place the function into a near section, and changing the calling convention to __near too.
__near function and (__near or __far) data pointers are "compatible".
- or converting the pointer manually. See the manual of which bytes to swap.
- or place the function into a dedicated section and use the linker defined object to get the address of the section. This would also offer to get the size of the function. Also as the code to be copied should conceptually be position independent, the PIC (position independent code) section qualifier could be added (did not use PIC recently, my memory is a bit rusty here, is the qualifier __PIC_SEG? Note that the code probably works without PIC too, but certain C patterns do generate non PIC code without telling the compiler to generate PIC code).
Daniel