public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* function arguments are passed in registers
@ 2008-01-02  9:26 Zheng Da
  2008-01-02 10:58 ` Andrew Haley
  0 siblings, 1 reply; 8+ messages in thread
From: Zheng Da @ 2008-01-02  9:26 UTC (permalink / raw)
  To: gcc-help

Hello,

I need to do something like this:
in one program, the arguments of one specific function are passed in
the registers, and others are passed in the stack.
I know I can do it by using some inline assembly, but is there any better way?
I was looking for it in the internet. FUNCTION_ARG seems to work. But
I don't understand its explanation, and don't know how to use it.
So can anyone help me?

Best,
Zheng Da

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: function arguments are passed in registers
  2008-01-02  9:26 function arguments are passed in registers Zheng Da
@ 2008-01-02 10:58 ` Andrew Haley
  2008-01-03  7:55   ` Zheng Da
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Haley @ 2008-01-02 10:58 UTC (permalink / raw)
  To: Zheng Da; +Cc: gcc-help

Zheng Da writes:
 > Hello,
 > 
 > I need to do something like this:
 > in one program, the arguments of one specific function are passed in
 > the registers, and others are passed in the stack.
 > I know I can do it by using some inline assembly, but is there any better way?
 > I was looking for it in the internet. FUNCTION_ARG seems to work. But
 > I don't understand its explanation, and don't know how to use it.
 > So can anyone help me?

We can't really tell what you need.  Can you explain to us what you
are trying to do?

Andrew.

-- 
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: function arguments are passed in registers
  2008-01-02 10:58 ` Andrew Haley
@ 2008-01-03  7:55   ` Zheng Da
  2008-01-03 11:26     ` Tom St Denis
  0 siblings, 1 reply; 8+ messages in thread
From: Zheng Da @ 2008-01-03  7:55 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

Suppose I have two libraries, A and B.
In library A, there is function a() whose arguments are passed in registers.
In library B, there is b() whose arguments are passed in the stack.
Now I have to use a() and b() in my program.
But how do I tell GCC that they use different ways to pass the
arguments and which is the right way.

Zheng Da

On Jan 2, 2008 11:53 AM, Andrew Haley <aph@redhat.com> wrote:
>
> Zheng Da writes:
>  > Hello,
>  >
>  > I need to do something like this:
>  > in one program, the arguments of one specific function are passed in
>  > the registers, and others are passed in the stack.
>  > I know I can do it by using some inline assembly, but is there any better way?
>  > I was looking for it in the internet. FUNCTION_ARG seems to work. But
>  > I don't understand its explanation, and don't know how to use it.
>  > So can anyone help me?
>
> We can't really tell what you need.  Can you explain to us what you
> are trying to do?
>
> Andrew.
>
> --
> Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
> Registered in England and Wales No. 3798903
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: function arguments are passed in registers
  2008-01-03  7:55   ` Zheng Da
@ 2008-01-03 11:26     ` Tom St Denis
  2008-01-03 12:31       ` Tom St Denis
  2008-01-04 15:23       ` Zheng Da
  0 siblings, 2 replies; 8+ messages in thread
From: Tom St Denis @ 2008-01-03 11:26 UTC (permalink / raw)
  To: Zheng Da; +Cc: Andrew Haley, gcc-help

Zheng Da wrote:
> Suppose I have two libraries, A and B.
> In library A, there is function a() whose arguments are passed in registers.
> In library B, there is b() whose arguments are passed in the stack.
> Now I have to use a() and b() in my program.
> But how do I tell GCC that they use different ways to pass the
> arguments and which is the right way.
>   
This is why a common ABI exists.  The only "sane" way to accomplish this 
with GCC is to write a "thunking" [iirc that's the term] layer in which 
you pass the parameters in a different convention.

How did you end up with this mess anyways?  Most assembler routines  
that interface with C are written to use the ABI so they're drop in.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: function arguments are passed in registers
  2008-01-03 11:26     ` Tom St Denis
@ 2008-01-03 12:31       ` Tom St Denis
  2008-01-04 15:23       ` Zheng Da
  1 sibling, 0 replies; 8+ messages in thread
From: Tom St Denis @ 2008-01-03 12:31 UTC (permalink / raw)
  To: Zheng Da; +Cc: Andrew Haley, gcc-help

Zheng Da wrote:
> Suppose I have two libraries, A and B.
> In library A, there is function a() whose arguments are passed in registers.
> In library B, there is b() whose arguments are passed in the stack.
> Now I have to use a() and b() in my program.
> But how do I tell GCC that they use different ways to pass the
> arguments and which is the right way.
>   
This is why a common ABI exists.  The only "sane" way to accomplish this 
with GCC is to write a "thunking" [iirc that's the term] layer in which 
you pass the parameters in a different convention.

How did you end up with this mess anyways?  Most assembler routines  
that interface with C are written to use the ABI so they're drop in.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: function arguments are passed in registers
  2008-01-03 11:26     ` Tom St Denis
  2008-01-03 12:31       ` Tom St Denis
@ 2008-01-04 15:23       ` Zheng Da
  2008-01-04 23:41         ` Greg Smith
  1 sibling, 1 reply; 8+ messages in thread
From: Zheng Da @ 2008-01-04 15:23 UTC (permalink / raw)
  To: Tom St Denis; +Cc: Andrew Haley, gcc-help

I'm writing a Linux kernel module which needs to call a static
function in the kernel.
Unfortunately, the static functions are compiled with arguments passed
in registers.
I don't want to change the kernel, so I have to use some trick to pass
arguments in different ways.
Currently, I use inline assembly, but I thought maybe GCC provides a better way.
By the way, how does Linux kernel handle it?
As I know, static functions pass their arguments in registers, and
others in the stack.
How does Linux kernel use them together?

Zheng Da

On Jan 2, 2008 11:45 PM, Tom St Denis <tstdenis@ellipticsemi.com> wrote:
> Zheng Da wrote:
> > Suppose I have two libraries, A and B.
> > In library A, there is function a() whose arguments are passed in registers.
> > In library B, there is b() whose arguments are passed in the stack.
> > Now I have to use a() and b() in my program.
> > But how do I tell GCC that they use different ways to pass the
> > arguments and which is the right way.
> >
> This is why a common ABI exists.  The only "sane" way to accomplish this
> with GCC is to write a "thunking" [iirc that's the term] layer in which
> you pass the parameters in a different convention.
>
> How did you end up with this mess anyways?  Most assembler routines
> that interface with C are written to use the ABI so they're drop in.
>
> Tom
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: function arguments are passed in registers
  2008-01-04 15:23       ` Zheng Da
@ 2008-01-04 23:41         ` Greg Smith
  2008-01-05 11:13           ` Zheng Da
  0 siblings, 1 reply; 8+ messages in thread
From: Greg Smith @ 2008-01-04 23:41 UTC (permalink / raw)
  To: Zheng Da; +Cc: gcc-help

As far as I know, arguments are passed to a function either in registers
or in the stack based on the prototype of the called function.  See the
regparm __attribute__.  My understanding is that this is also arch
dependent, for example s390x always passes arguments in registers (and
then the stack if there are too many).

So your function calling the kernel function should be fine as long as
you have the correct function prototype.

Greg Smith

On Thu, 2008-01-03 at 11:00 +0800, Zheng Da wrote:
> I'm writing a Linux kernel module which needs to call a static
> function in the kernel.
> Unfortunately, the static functions are compiled with arguments passed
> in registers.
> I don't want to change the kernel, so I have to use some trick to pass
> arguments in different ways.
> Currently, I use inline assembly, but I thought maybe GCC provides a better way.
> By the way, how does Linux kernel handle it?
> As I know, static functions pass their arguments in registers, and
> others in the stack.
> How does Linux kernel use them together?
> 
> Zheng Da


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: function arguments are passed in registers
  2008-01-04 23:41         ` Greg Smith
@ 2008-01-05 11:13           ` Zheng Da
  0 siblings, 0 replies; 8+ messages in thread
From: Zheng Da @ 2008-01-05 11:13 UTC (permalink / raw)
  To: Greg Smith; +Cc: gcc-help

You are right. __attribute__((regparm(3))) or fastcall works in my module.
Thanks a lot.

Zheng Da

On Jan 3, 2008 11:26 AM, Greg Smith <gsmith@nc.rr.com> wrote:
> As far as I know, arguments are passed to a function either in registers
> or in the stack based on the prototype of the called function.  See the
> regparm __attribute__.  My understanding is that this is also arch
> dependent, for example s390x always passes arguments in registers (and
> then the stack if there are too many).
>
> So your function calling the kernel function should be fine as long as
> you have the correct function prototype.
>
> Greg Smith
>
>
> On Thu, 2008-01-03 at 11:00 +0800, Zheng Da wrote:
> > I'm writing a Linux kernel module which needs to call a static
> > function in the kernel.
> > Unfortunately, the static functions are compiled with arguments passed
> > in registers.
> > I don't want to change the kernel, so I have to use some trick to pass
> > arguments in different ways.
> > Currently, I use inline assembly, but I thought maybe GCC provides a better way.
> > By the way, how does Linux kernel handle it?
> > As I know, static functions pass their arguments in registers, and
> > others in the stack.
> > How does Linux kernel use them together?
> >
> > Zheng Da
>
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-01-03  6:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-02  9:26 function arguments are passed in registers Zheng Da
2008-01-02 10:58 ` Andrew Haley
2008-01-03  7:55   ` Zheng Da
2008-01-03 11:26     ` Tom St Denis
2008-01-03 12:31       ` Tom St Denis
2008-01-04 15:23       ` Zheng Da
2008-01-04 23:41         ` Greg Smith
2008-01-05 11:13           ` Zheng Da

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).