Re: asm in C slightly OT

From: Michael Meissner (meissner@spectacle-pond.org)
Date: Sun Jul 23 2000 - 19:20:47 EST


On Sun, Jul 23, 2000 at 05:51:10PM -0700, George Anzinger wrote:
> "H. Peter Anvin" wrote:
> >
> > Followup to: <39795FCE.65EE2768@pioneer.net>
> > By author: George Anzinger <george@pioneer.net>
> > In newsgroup: linux.dev.kernel
> > >
> > > The first line looks like a function proto type. It is unclear how it
> > > is related to the rest of the macro. This macro generates a bit of code
> > > that is not a function in any way. It has an entry label
> > > "common_interrupt" and ends with a jmp. What I really want to know is
> > > how to refer to a C variable inside of such a construct. The gcc
> > > documentation talks about how to do it in more standard asm. I would
> > > like, for example to add to the above macro, for example:
> > >
> > > "incl foo.bar" where bar is a member of structure foo.
> > >
> > > I know this could be done as: "incl foo+xxx" where xxx is the offset
> > > of bar in foo, but I would like the compiler to figure this for me so as
> > > to follow structure changes.
> > >
> >
> > RTFM(info gcc)
> >
> > asm("incl (%0)" :: "i" (&foo.bar));
>
> I wish it was that easy. As it turns out the asm statement is not
> inside a function. This seems to turn off the ability to use the ":"
> construct. Why? Wish I knew. At this point I think I must use hand
> computed offsets for members of structures refered to from asm code that
> is not in a function.

Why, because outside of a function, it doesn't do register allocation, thus GCC
believes it shouldn't give you the option of specifying variables. Basically
it just dumps the text into the asm input file.

-- 
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Jul 23 2000 - 21:00:21 EST