On 15/09/15 14:24, Gavin Wraith wrote:
> Those of a delicate disposition should avert their eyes from this
> post, because I am asking for the best, I hesitate to say official,
> way to do a dirty coercive hack with C code.
>
> BBC BASIC conflates addresses with integers. Alas, there is no way
> to communicate with RISC OS SWIs without doing this. I tried to do
> this in early versions of RiscLua, but eventually found it more
> practical to adopt the evil ways of BBC BASIC. Using the Norcroft
> C compiler and Objasm my method basically consisted of having
> a piece of assembler code
>
> AREA HACK
> EXPORT hack
>
> hack MOV PC, R14
> END
>
> with a header file containing
>
> extern void *hack(int n);
>
> You get the idea? It means wasting time with an extra call to an identity
> function. I have just been reading up on GCC's inline assembler
> and I find that its syntax has been designed to thwart this kind of
> cavalier behaviour with types. Obviously I should be using a macro to avoid
> unnecessary function calls. But what is the pukka way to do the hack?
Usually, you just use a cast:
int number;
void *number_is_now_a_pointer = (void *)number;
There are some good examples of inline assembler SWI veneers here:
<http://www.riscos.info/websvn/filedetails.php?repname=gccsdk&path=%2Ftrunk%2Fgcc4%2Frecipe%2Ffiles%2Fgcc%2Flibunixlib%2Fincl-local%2Fsys%2Fsocket.h>
Lee.
_______________________________________________
GCCSDK mailing list gcc@gccsdk.riscos.info
Bugzilla: http://www.riscos.info/bugzilla/index.cgi
List Info: http://www.riscos.info/mailman/listinfo/gcc
Main Page: http://www.riscos.info/index.php/GCCSDK
No comments:
Post a Comment