2010-08-30 05:06:58     compiling dsp firmware using bfin-elf toolchain

Document created by Aaronwu Employee on Sep 26, 2013
Version 1Show Document
  • View in full screen mode

2010-08-30 05:06:58     compiling dsp firmware using bfin-elf toolchain

Mike Sinkovsky (RUSSIAN FEDERATION)

Message: 92927   

 

I'm trying to compile blackfin dsp firmware using linux toolchain, and have some questions.

 

First, how to customize code in libgloss/bfin/basiccrt.S ?

If I copy this file to my source directory and compile - error:

 

> bfin-elf-gcc -mcpu=bf531-0.3 -T bf531.lds basiccrt.o main.o -o dsp.elf

basiccrt.o: In function `__start':

basiccrt.S:(.text+0x0): multiple definition of `__start'

/opt/bfin-2010-06-15/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/../../../../bfin-elf/lib/basiccrt.o:/TEMP/2010/toolchain/gcc-4.3/libgloss/bfin/basiccrt.S:79: first defined here

QuoteReplyEditDelete

 

 

2010-08-30 09:37:54     Re: compiling dsp firmware using bfin-elf toolchain

Mike Frysinger (UNITED STATES)

Message: 92929   

 

if you're providing your own start files, then use -nostartfiles

QuoteReplyEditDelete

 

 

2010-08-31 09:49:06     Re: compiling dsp firmware using bfin-elf toolchain

Mike Sinkovsky (RUSSIAN FEDERATION)

Message: 92968   

 

Thanks, with  "-nostartfiles" my minimal program compiles and works.

 

Next question - in VDSP was macro "EX_REENTRANT_HANDLER(handler)" for nested interrupts handlers.

In gcc I found only "__attribute__((interrupt_handler)) static void handler(void)", but it is for not nested handlers.

But in my interrupts nesting is required. Is there a way?

QuoteReplyEditDelete

 

 

2010-08-31 10:31:47     Re: compiling dsp firmware using bfin-elf toolchain

Mike Frysinger (UNITED STATES)

Message: 92970   

 

as documented in the wiki, use "nesting"

 

https://docs.blackfin.uclinux.org/doku.php?id=visualdsp:port_c_code

QuoteReplyEditDelete

 

 

2010-09-01 02:27:34     Re: compiling dsp firmware using bfin-elf toolchain

Mike Sinkovsky (RUSSIAN FEDERATION)

Message: 92983   

 

I don't see any effect of __attribute__((nesting))

 

__attribute__((interrupt_handler, nesting)) void handler(void) { ... }

 

compiles to same code as without nesting:

 

.type _handler, STT_FUNC;

_handler:

.LFB25:

[--SP] = ASTAT;

 

....

 

ASTAT = [SP++];

rti;

 

Correct code of nested handler must be like this:

 

.type _handler, STT_FUNC;

_handler:

.LFB25:

[--SP] = RETI;

[--SP] = ASTAT;

 

....

 

ASTAT = [SP++];

RETI = [SP++];

rti;

QuoteReplyEditDelete

 

 

2010-09-01 04:07:21     Re: compiling dsp firmware using bfin-elf toolchain

Steve Kilbane (UNITED KINGDOM)

Message: 93011   

 

Have you looked further down the code?

 

Using a compiler fom trunk, compiling gcc-4.3/gcc/testsuite/gcc.target/bfin/hdlr-intr-2.c:

 

$ cat hdlr_intr-2.c

/* { dg-do compile } */

/* { dg-final { scan-assembler "\[\t\]rti" } } */

/* { dg-final { scan-assembler-times "RETI" 2 } } */

/* { dg-final { scan-assembler-not "\[\t\]rts" } } */

/* { dg-final { scan-assembler-not "\[\t\]rtn" } } */

/* { dg-final { scan-assembler-not "\[\t\]rtx" } } */

__attribute__((interrupt_handler, nesting)) void

evt_intr(void) {

  /* No code */

}

 

$ bfin-elf-gcc -S hdlr_intr-2.c

 

$ cat hdlr_intr-2.s

.file "hdlr_intr-2.c";

.text;

        .align 4

.global _evt_intr;

.type _evt_intr, STT_FUNC;

_evt_intr:

        [--SP] = ASTAT;

        [--SP] = LC0;

        [--SP] = LC1;

        [--sp] = ( p5:5 );

        CC = R0 == R0;

        P5.H = 65472;

        P5.L = 20;

        if cc jump 4;

        r7 = [P5];

        [--SP] = RETI;

        LINK 0;

        UNLINK;

        RETI = [SP++];

        ( p5:5 ) = [sp++];

        LC1 = [SP++];

        LC0 = [SP++];

        ASTAT = [SP++];

        rti;

        .size   _evt_intr, .-_evt_intr

        .ident  "GCC: (ADI-trunk/svn-4790) 4.3.5"

 

(emphasis added)

 

The compiler has to insert some additional code for anomaly workarounds, and that delays when RETI can be pushed to re-enable interrupts.

 

steve

QuoteReplyEditDelete

 

 

2010-09-01 04:39:46     Re: compiling dsp firmware using bfin-elf toolchain

Mike Sinkovsky (RUSSIAN FEDERATION)

Message: 93013   

 

Hm, yes. But VDSP always place this operation first in function without any checks,

From ADSP-BF533 Blackfin® Processor Hardware Reference:

 

If interrupts require nesting, the return address to the interrupted point in

the original interrupt service routine must be explicitly saved and subse-

quently restored when execution of the nested interrupt service routine

has completed. The first instruction in an interrupt service routine that

supports nesting must save the return address currently held in RETI by

pushing it onto the Supervisor stack ([--SP]=RETI). This clears the glo-

bal interrupt disable bit IPEND[4], enabling interrupts. Next, all registers

that are modified by the interrupt service routine are saved onto the

Supervisor stack. Processor state is stored in the Supervisor stack, not in

the User stack. Hence, the instructions to push RETI ([--SP]=RETI) and

pop RETI (RETI=[SP++]) use the Supervisor stack

QuoteReplyEditDelete

 

 

2010-09-01 05:34:58     Re: compiling dsp firmware using bfin-elf toolchain

Steve Kilbane (UNITED KINGDOM)

Message: 93014   

 

> Hm, yes. But VDSP always place this operation first in function without any checks,

 

 

 

Not true. If you're compiling with -si-revision none, or for a processor/revision that doesn't suffer from 05-00-023, and you're optimising (so the link/unlink get removed), then you're right - the RETI push is first. But if you're compiling for a processor/revision with 05-00-023, then you get very similar code to GCC (unsurprisingly):

 

    [--SP] = ASTAT;                         // Inserted 3 instrs to fix anomaly w05_00_0283 .

    [--SP] = P0;

    P0 = 20 /* -4194284 */;

    P0.H = -64 /* -4194284 */;

    CC = R7 == R7;                          // Inserted 2 instrs to fix anomaly w05_00_0283.

    if CC jump .P34L0 ;

 

.P34L2:

    R7 = [P0 + 0];                          // Inserted to fix anomaly w05_00_0283 .

 

.P34L0:

    P0 = [SP++];                            // Inserted 2 instrs to fix anomaly w05_00_0283 .

    ASTAT = [SP++];

    LINK 0;

    [--SP] = RETI;

    [--SP] = R0;

    R0 = [SP++];

    RETI = [SP++];

    UNLINK;

    RTI;

 

 

steve

 

QuoteReplyEditDelete

 

 

2010-09-01 05:54:22     Re: compiling dsp firmware using bfin-elf toolchain

Steve Kilbane (UNITED KINGDOM)

Message: 93015   

 

Incidentally, a documentation bug (878) has been entered against the HRM, so that the text doesn't require the RETI push to be the first instruction. The manual will be updated in due course.

 

steve

Attachments

    Outcomes