[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] Porting PureC code to Gcc



I'm more worried about function calling convention. Will it work?
Of course it wont. This is where the real fun starts because it's the most error prone part of the porting process. PureC calling convention is something like put first two integers in d0-d1, if they are pointers -> a0-a1, fpu numbers -> fp0-fp1, the rest on the stack. You must change it in that way everything is fetched from stack, from left to right. For example:

int my_cool_function( int a, float b, char* c );

For PureC:

move.w d0, my_int
fmove.s fp0, my_float
move.l a0, my_pointer

moveq #0, d0   ; return code

would become for gcc:

move.l (4,sp), my_int ; first four bytes = return address + don't forget to change my_int to ds.l if needed
fmove.s (8,sp), my_float
move.l (12,sp), my_pointer

moveq #0, d0; return code

Also be careful about ints! PureC uses 16-bit integers so you either must use -mshort for gcc (and then you'll fetch stuff from stack as +4 (return address if four bytes), +6 (sizeof(int)), +10 (float is still 4 bytes)) or to carefully look for move.w d0, xxx stuff -- you must not use move.w (4,sp) because it will fetch only zeroes (the value is in the lower 16 bits).

Hope this helps.

--
MiKRO / Mystic Bytes
http://mikro.atari.org