2011-05-11 08:49:42     bfin-elf: CPLB protection violation on using printf and floating point emulation

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

2011-05-11 08:49:42     bfin-elf: CPLB protection violation on using printf and floating point emulation

Frank Lorenz (GERMANY)

Message: 100578   

 

Hi,

 

 

 

I am facing a problem that the Blackin (BF534) issues an Exception with code 0x23 (Data access CPLB protection violation) in my bare metal (bfin-elf) application.

 

As far as I understand, this happens when a printf(...) is interrupted by a timer IRQ which then uses some floating point arithmetics. I have attached a screenshot of the call stack and the disassembly of the last operation that seems to cause the exception.

 

 

 

As printf needs a _write() function, i have written a very simple implementation which just writes out the buffer to an uart (no protection for re-entrant etc.).

 

 

 

The code which causes the exception inside the IRQ is:

 

cfg_width  = (uint32) ( (double)period_ns * ( (double)SCLK_KHZ / 1000000. ) );

 

 

 

 

 

Do you have some idea what happens here?

 

callstack.jpg

disassembly.jpg

TranslateQuoteReplyEditDelete

 

 

2011-05-11 10:57:48     Re: bfin-elf: CPLB protection violation on using printf and floating point emulation

Mike Frysinger (UNITED STATES)

Message: 100582   

 

perhaps you interrupt entry point isnt properly saving context and setting up a new valid C runtime env ?

QuoteReplyEditDelete

 

 

2011-05-11 11:22:54     Re: bfin-elf: CPLB protection violation on using printf and floating point emulation

Frank Lorenz (GERMANY)

Message: 100585   

 

You are probably right. Can you point me to some info about this?

TranslateQuoteReplyEditDelete

 

 

2011-05-11 11:27:35     Re: bfin-elf: CPLB protection violation on using printf and floating point emulation

Mike Frysinger (UNITED STATES)

Message: 100586   

 

we dont really have any general documentation on this topic.  we've implemented it for our OS's, but that's about it.  you could refer to the linux-2.6.x/arch/blackfin/include/asm/context.S file to see how we do it.

 

basically, make sure all your exception/interrupt entry points save the entire register file, and then zero out the L regs.  and then when returning, restore the entire register file.

QuoteReplyEditDelete

 

 

2011-05-12 02:28:04     Re: bfin-elf: CPLB protection violation on using printf and floating point emulation

Frank Lorenz (GERMANY)

Message: 100594   

 

O.k., thanks.

 

 

 

Could you give me some more information what exactly happens here to the Blackfin? I have encountered this CPLB exception several times and did not get an exact idea what's the problem - the info in the programming reference manual doesn't help me either.

 

Because I run in Supervisor mode (IRQ 15 handling) all the time and do not use CPLB functionality, I assume my problem is "A simultaneous, dual access to two MMRs using the data address generators[...]" (Programming Reference, Table 4-11). But what does this mean? Doesn't the Blackfin finish one access to an MMR first before starting IRQ handling?

TranslateQuoteReplyEditDelete

 

 

2011-05-12 11:47:36     Re: bfin-elf: CPLB protection violation on using printf and floating point emulation

Mike Frysinger (UNITED STATES)

Message: 100617   

 

if CPLBs are not enabled ([DI]MEM_CONTROL have EN[DI]CPLB bit set), then i'm not sure under what conditions you could still get a CPLB fault.  i wouldnt be surprised if the HRM was indeed not clear on this point.  most issues change from exceptions to hardware errors (IVG5).

 

i put together a simple test (see attached) and it does show that DAG1 accesses to the MMR space show up as DCPLB protection violations even when CPLBs are not enabled.  but if your code is crashing in math funcs, it sounds more like the stack is corrupted and its being given bad arguments ...

 

you should look at the SEQSTAT/RETX registers are see what the exception reason is about and then at [ID]CPLB_FAULT_ADDR to see the real source.

 

test.s

QuoteReplyEditDelete

 

 

2011-05-13 09:24:30     Re: bfin-elf: CPLB protection violation on using printf and floating point emulation

Frank Lorenz (GERMANY)

Message: 100647   

 

Hi Mike,

 

 

 

thanks for the info - I will debug my problem this way.

 

 

 

I have an issue running your test.s:

 

1. compile it:

 

     bfin-elf-gcc -nostartfiles test.s -o test.elf -Iinclude -D__ASSEMBLY__ -mcpu=bf534

 

2. start gdb:

 

     bfin-elf-gdb test.elf

 

3. load to target:

 

     target remote :2000

 

     monitor reset

 

     load test.elf

 

4. start...

 

     c

 

 

 

It seems like no breakpoint / trap is hit, because the processor runs unti i stop it via CTRL-C. In fact it starts u-boot and my application which are in the flash of my target...

 

If I understand your test.s correctly, the line 

 

MNOP || NOP || R1 = [I0];

 

should cause an exception which jumps back to _start, which calls again __low ... (endless loop) -- but instead the Blackfin starts the application from flash. Additionally, I would expect GDB would stop on every emuexcpt instruction.

 

What am I doing wrong?

 

 

 

Info: I use the ICEBear debugger from section5.ch, which brings his own gdbproxy and bfin-elf-gdb - I of course use this tools for the test. But I expect this souldn't matter?

TranslateQuoteReplyEditDelete

 

 

2011-05-13 12:27:00     Re: bfin-elf: CPLB protection violation on using printf and floating point emulation

Mike Frysinger (UNITED STATES)

Message: 100650   

 

run `bfin-gdbproxy bfin --reset` so that when you connect over jtag, the part is forced into a sane state

QuoteReplyEditDelete

 

 

2011-05-17 09:11:45     Re: bfin-elf: CPLB protection violation on using printf and floating point emulation

Frank Lorenz (GERMANY)

Message: 100695   

 

Hm, no luck, the gdbproxy delivered by section 5 does not seem to support --reset:

 

 

 

> gdbproxy  bfin --reset

 

Remote proxy for GDB, v0.9.1, Copyright (C) 1999 Quality Quorum Inc.

 

Blackfin/ICEbear adaption (C) 2005-2010 Martin Strubel <hackfin@section5.ch>

 

bfin: unrecognized option '--reset'

 

notice:    bfin: Use `gdbproxy --help bfin' to see a complete list of options

 

 

 

>  gdbproxy  --help bfin

 

Remote proxy for GDB, v0.9.1, Copyright (C) 1999 Quality Quorum Inc.

 

Blackfin/ICEbear adaption (C) 2005-2010 Martin Strubel <hackfin@section5.ch>

 

JTAG proxy driver for single Blackfin core debugging

 

v1.4 // (c) 2004-2009 Martin Strubel <hackfin@section5.ch>

 

Optional extra parameters:

 

--dev <device index> : JTAG device index

 

--cpu=[0-7]          : cpu index in multi core system

 

--config <file.ini>  : JTAG configuration file

 

--debug              : enable debug output

 

--auxport=<port>     : choose port for auxiliary TCP server

 

--speed=[0-255]      : 0: fastest, 255: slowest (default: 0)

 

--buffersize=<size>  : Write cache buffer size, 0: cache off

 

 

 

 

 

I think the "monitor reset" command I use before loading does the same -- but without success.

TranslateQuoteReplyEditDelete

Attachments

Outcomes