[parisc-linux] Inline Assembly Help request

John David Anglin dave@hiauly1.hia.nrc.ca
Mon, 9 Sep 2002 13:27:34 -0400 (EDT)


> But I do not yet find explanation about details of the following asm code:
> #define __put_user_asm(stx,x,ptr)                           \
>         __asm__ __volatile__ (                              \
>                 "\n1:\t" stx "\t%2,0(%%sr3,%1)\n"           \
>                 "2:\n"                                      \
>                 "\t.section __ex_table,\"a\"\n"             \
>                  "\t.word\t1b\n"                            \
>                  "\t.word\t(2b-1b)+1\n"                     \
>                  "\t.previous"                              \
>                 : "=r"(__pu_err)                            \
>                 : "r"(ptr), "r"(x), "0"(__pu_err))
> 
> which is more clear with gcc -S:
> 
> 1:      stw     %r21,0(%sr3,%r19)
> 2:
>         .section __ex_table,"a"
>         .word   1b
>         .word   (2b-1b)+1
>         .previous
> 
> My questions are:
> what are the actual means "1:", "2:" (seems like label?)

They are local labels that can be referenced in the asm.  "b" and "f"
mean backwards and forward relative to the current location.  This more
or less doubles the number of labels available.

> and what means the rest
> ".section __ex_table,...
>  ...
>  .previous"
> 
> I do not yet found reference on this part (even in Assembly-HOWTO).
> Where could I found doc on this details?

The GCC manual (extend.texi) has documentation on writing asms.  You
will need to look at the pa-risc architecture manuals for documentation
on PA assembler instructions.

The code is trying to setup a table using local labels generated
in the asm.  The way to do this is highly port dependent.
In particular, indirect function calls are done using plabels on
the PA.  There are also restrictions on the types of relocations
that can be used for constructing tables of this kind.

This is highly complex stuff and isn't very well documented.  You
can read the HP runtime architecture document, the documentation on
ELF relocations and look at the code in the GNU assembler and linker.
The dwarf2 exception tables that you can generate with gcc 3.3
may also give some clue.  Look at the entry for the personality
function and how the labels for C++ catches are encoded in the table.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)