undefined symbol in powerpc assembler code - VxWorks

This is a discussion on undefined symbol in powerpc assembler code - VxWorks ; Hi all, I'm working on a PowerPc E500, vxworks 5.5, Tornado 2.2, diab compiler. I'm trying to intermix assembly and source code in a *.c file using asm macros as explained in documentation "Embedding assembly code " of diab compiler. ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: undefined symbol in powerpc assembler code

  1. undefined symbol in powerpc assembler code

    Hi all,

    I'm working on a PowerPc E500, vxworks 5.5, Tornado 2.2, diab
    compiler.

    I'm trying to intermix assembly and source code in a *.c file using
    asm macros as explained in documentation "Embedding assembly code " of
    diab compiler. What I need is atomic increment and decrement function.
    This is my code snippet inside "source.c" file:

    The code compiles with no problems, however the dld linker issues the
    error "Undefined symbol 'r4' in file 'partialImage.o".

    Code snippet:

    >> asm UINT32 uint32AtomicReturnAdd ( void *addr)
    >> {
    >> % reg addr; lab retry
    >> ! "r3", "r4", "r5" /* scratch registers used */
    >> retry:
    >> lwarx r4, 0, r3 //r4 = *addr; We'll call *addr "value"
    >> addi r5, 0, r4 //copy value to r5
    >> addi r5, r5, 1 //value = value + 1
    >> stwcx. r5, 0, r3
    >> bne- retry
    >> addi r3, 0, r4 //copy value to return register
    >> blr
    >> }
    >> asm UINT32 uint32AtomicDecReturn ( void *addr)
    >> {
    >> % reg addr; lab retry
    >> ! "r3", "r4" /* scratch registers used */
    >> retry:
    >> lwarx r4, 0, r3 //r4 = *addr; We'll call *addr "value"
    >> addi r4, r4, -1 //value = value -1
    >> stwcx. r4, 0, r3
    >> bne- retry
    >> addi r3, 0, r4 //copy value to return register
    >> blr
    >> }
    >> #define PUSH_BUF(x) \
    >> {\
    >> if(g_BufStackIx >0) \
    >> g_BufStack[uint32AtomicDecReturn(&g_BufStackIx)] =x; \
    >> }


    #define POP_BUF ((g_BufStackIx g_BufStack[uint32AtomicReturnAdd(&g_BufStackIx)] :0 )

    Using nmppc actually shows that the symbol is undefined in "source.o"
    itself.

    I am puzzled since "r4" seems to be treated as a variable while it
    should only be visible by the assembler as a register... :S

    This is the first time I try to do this so I feel like I'm missing
    some important point... any help would be really appreciated

    Bye

    Giacomo

  2. Re: undefined symbol in powerpc assembler code

    On 2008-09-08, benelli.giacomo@gmail.com wrote:
    >>> addi r5, 0, r4 //copy value to r5


    Well, I've not used the DIAB compiler, not tried to embed assembly code
    with it, and don't have my PowerPC documentation handy, but I'm pretty
    certain you need to be using a different instruction here. Like just a
    plain old add instead of an addimmediate.
    --
    roger ivie
    rivie@ridgenet.net

  3. Re: undefined symbol in powerpc assembler code

    On Sep 8, 12:42 pm, Roger Ivie wrote:

    > On 2008-09-08, benelli.giac...@gmail.com wrote:
    >
    > >>> addi r5, 0, r4 //copy value to r5

    >
    > Well, I've not used the DIAB compiler, not tried to embed assembly code
    > with it, and don't have my PowerPC documentation handy, but I'm pretty
    > certain you need to be using a different instruction here. Like just a
    > plain old add instead of an addimmediate.
    > --
    > roger ivie
    > ri...@ridgenet.net


    This is correct. The source arguments to addi are assumed to either be
    constants or addresses, so here the assembler thinks you're telling it
    "add 0 to the value stored at the address denoted by the symbol r4 and
    put the result in r5." The assembler is therefore automatically
    creating a reference to a symbol named "r4."

    To make it easy on yourself, you can use:

    mr r5, r4 # move contents of r4 to r5

    This is a shortcut mnemonic (Move Register) that's actuallty
    equivalent to:

    or r5, r4, r4

    This says "OR r4 with itself, and put the results in r5." ORing a
    value with itself is a no-op, so the end result is just to copy what's
    in r4 to r5. There are some other variants that will work too.

    -Bill

  4. Re: undefined symbol in powerpc assembler code

    On Sep 9, 12:28*am, noiset...@gmail.com wrote:
    > On Sep 8, 12:42 pm, Roger Ivie wrote:
    >
    > > On 2008-09-08, benelli.giac...@gmail.com wrote:

    >
    > > >>> * * * * *addi * *r5, 0, r4 //copy value to r5

    >
    > > Well, I've not used the DIAB compiler, not tried to embed assembly code
    > > with it, and don't have my PowerPC documentation handy, but I'm pretty
    > > certain you need to be using a different instruction here. Like just a
    > > plain old add instead of an addimmediate.
    > > --
    > > roger ivie
    > > ri...@ridgenet.net

    >
    > This is correct. The source arguments to addi are assumed to either be
    > constants or addresses, so here the assembler thinks you're telling it
    > "add 0 to the value stored at the address denoted by the symbol r4 and
    > put the result in r5." The assembler is therefore automatically
    > creating a reference to a symbol named "r4."
    >
    > To make it easy on yourself, you can use:
    >
    > * * * * * * * * * * mr r5, r4 * * * * *# move contents of r4 to r5
    >
    > This is a shortcut mnemonic (Move Register) that's actuallty
    > equivalent to:
    >
    > * * * * * * * * * * or r5, r4, r4
    >
    > This says "OR r4 with itself, and put the results in r5." ORing a
    > value with itself is a no-op, so the end result is just to copy what's
    > in r4 to r5. There are some other variants that will work too.
    >
    > -Bill


    You are certainly right! I guess this is why they created higher-level
    languages, so distracted people like me can have the chance to write
    some working lines

    I cannot try out this immediately, but I'm sure this is the problem.
    Thanks also for the "rm" instruction, it's the more appropriate in
    that case.

    Thanks again for you help! Bye

    Giacomo

+ Reply to Thread