Search code examples
gccassemblyinline-assemblysparc

Use sparc extended asm in global function


I am trying to write an assembly function without using c prototypes. For some reason it looks like the gcc doesn't allow to use extended asm in the global context.

Please consider the following code that compiles succssefully:

void *g_var;
void foo()
{
    asm ("stx       %%i7, [%0]"
        :"=r" (g_var));
}

When I am also trying to define the prototype using asm, as follows:

asm(".global foo2\n\t"
    "foo2:\n\t");
asm ("stx       %%i7, [%0]"
    :"=r" (g_var));

the compiler give me the following error as if extended asm cannot be used in global context.

foo.c:151:2: error: expected ')' before ':' token :"=r" (return_addr)); ^

Please note that when I don't use extened asm as follows, the compiler approves the code:

asm(".global foo2\n\t"
    "foo2:\n\t");
asm("jmpl       %o7 + 8, %g0\n\t");

Thanks.


Solution

  • From the GCC Documentation:

    Note that extended asm statements must be inside a function. Only basic asm may be outside functions (see Basic Asm). Functions declared with the naked attribute also require basic asm (see Function Attributes).

    So the answer to your question is that - no it isn't possible to use extended assembler templates outside a function in the global context. As you have found basic assembler statements are allowed.