lkml.org 
[lkml]   [2000]   [Jul]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: asm in C slightly OT
> ...
> > dummy()
> > {
> > asm(".equ STUFF_OFFSET,%0"::"i" (OFFSETOF(thing, stuff)));
> > }
> Or maybe: asm(".equ STUFF_OFFSET,%0"::"i" (things.stuff))); where we
> have bound: struct thing things;

Not too sure what you mean here.. the "i" requires an immediate
argument (an integer). So you need some construct which will allow the
compiler to generate a constant. You could use

(char *)&things.stuff - (char *)&things


I'd expect the compiler to turn that into a constant, but it doesn't
make much diff.

> This is close to what I did. If you look at the asm code produced when
> you wrap the asm with a dummy() you find that there are a few
> instructions before and after the asm. In the case in point this did
> not matter as the entry is by a jmp and the last instruction jmped out.
> In fact, by doing the wrap I was able to:
>
> dummy()
> {
> asm(.....);
> ++things.stuff;
> asm(....);
> }

This is different. The example I sent only used `dummy' so that the
`.equ' asm was within function context. It'll generate something like:

.globl dummy
dummy:
.equ STUFF_OFFSET,$8
ret

`dummy' will never be called. You can place any number of `.equ'
pseudo-ops in `dummy'.

> Careful inspection proved that this was as good as I could do in asm and
> keeps everything tracking the structures. Cost: about 4 wasted
> instructions.
>

Good!

The .equ hack merits more playing with, because it could be used to cure
the awkward stuff in entry.S. It may cause the generation of 16 bit
offsets where 8 bit would suffice, but that may be fixable. I'll append
it to my TTD list :)

-
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/

\
 
 \ /
  Last update: 2005-03-22 13:57    [from the cache]
©2003-2011 Jasper Spaans