This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Avoid stack references in inline assembly


On 6/17/19 2:28 PM, Vincent Rivière wrote:
> Hi,
> 
> 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.
> 
> My wish is to add a parameter constraint telling: "use whatever you want
> as parameter, but nothing relative to the stack".
> Any idea how to achieve that?
> I know that I can use "r" as constraint to force GCC to put data into
> registers before calling the assembler template, but that produces extra
> instructions, hence suboptimal code.
> Ideally, GCC should be able to adjust the stack offsets depending on
> what has already been pushed. But I know this is not possible as GCC
> doesn't interpret the assembly template, so it can't understand that it
> contains stack pushes.
So what you have here is two different ABIs that have to coexist together?

This is best addressed by changing GCC itself to know about the
different ABIs.  Trying to tackle in ASMs is going to be painful,
particularly since your asms change the stack pointer and that's
generally verboten for an ASM.

If you're going to insist on doing this with an ASM you're likely going
to need to only use registers and constants for constraints since
otherwise you run the risk of getting a stack address.

Jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]