Hi! On Mon, Jun 17, 2019 at 10:28:37PM +0200, Vincent Rivière wrote: > My goal is to create optimal C bindings for Atari ST system calls, using > m68k-elf-gcc (tested with version 7.1.0). Basically, system calls are > similar to function calls: parameters are stacked in the reverse order, > last one being a function number. But there are 2 differences from standard > C calling convention: > - actual jump to subroutine is replaced by trap #1 > - clobbered registers include d2/a2 in addition to standard d0-d1/a0-a1 > > Here is the problem. If I use "g" as parameter constraint, everything looks > fine, but GCC may replace the parameter token with a reference to a stack > location (specially when compiling with -fomit-frame-pointer). If another > parameter has already been pushed on the stack, the reference to the second > one is not properly adjusted, so the pushed address is wrong.
You could make a builtin for this, so that you can say something like retval = __builtin_syscall_m68k_st (syscall_nr, arg0, arg1); (which can be varargs, take any number of args you support). We could have a generic builtin for this, hrm... Like retval = __builtin_syscall (STYLE, syscall_nr, arg0, arg1); with some target hook that checks if the STYLE is something it supports, and then if the number and type of remaining args are okay. I've never seen a target that could define their syscalls perfectly with just existing facilities, inline asm is such a blunt intrument in some ways. Segher