Technical notes on using Analog Devices DSPs, processors and development tools
Contact our technical support at dsp.support@analog.com and at dsptools.support@analog.com
Or vi sit our o n-li ne r esou rces htt p:/ /www.analog.com/ee-notes and http://www.analog.com/processors
Configuring the C/C++ Run-Time Header for Blackfin® Processors
Contributed by Steve K Rev 1 – May 18, 2004
Introduction
The C/C++ run-time header (CRT) is the library
code that is executed when the processor jumps
to the
machine into a known state and calls
start address on reset. The CRT sets the
_main
1
. This
EE-Note describes the Blackfin® processor’s
CRT, and explains how to rebuild or reconfigure
it.
The document begins with an overview of the
CRT, which describes what the CRT does and
does not do. Each CRT activity is then examined,
followed by configuration instructions.
CRT Overview
global data declared by the application have been
initialized as required by the C/C++ standards.
It arranges things so that
_main appears to be
“just another function” invoked by the normal
function invocation procedure.
Not all applications require the same
configuration. For example, C++ constructors are
invoked only for applications that contain C++
code. The list of optional configuration items is
long enough that determining whether to invoke
each one in turn at runtime would be overly
costly. As a convenience, the Blackfin
processor’s CRT is supplied pre-built in several
different configurations, which can be specified
at link-time via LDF macros.
The CRT:
The CRT is used for projects that use C or C++.
Projects configured with VDK use a different
• Sets up required system services, such as
stack and event-handling
• Disables system services that power up in an
undefined state, such as circular buffers and
hardware loops
• Initializes standard library facilities, such as
standard input/output (
stdio)
• Invokes C++ constructors, as required
The CRT ensures that when execution enters
_main, the processor’s state obeys the C
Application Binary Interface (ABI), and that
1
In this document, all symbols are written with assembly
linkage, except where otherwise noted. Thus,
used, rather than
Copyright 2004, Analog Devices, Inc. All rights reserved. Analog Devices assumes no responsibility for customer product design or the use or application of
customers’ products or for any infringements of patents or rights of others which may result from Analog Devices assistance. All trademarks and logos are property
of their respective holders. Information furnished by Analog Devices applications and development tools engineers is believed to be accurate and reliable, however
no responsibility is assumed by Analog Devices regarding technical accuracy and topicality of the content provided in Analog Devices’ Engineer-to-Engineer Notes.
main().
_main is
run-time header, not described here (although the
principles are the same). Assembly language
projects do not provide a default run-time
header; you must provide your own.
The source for the Blackfin processor’s CRT is
located under the VisualDSP++® installation
directory, in the file
Blackfin\lib\src\libc\crt.
basiccrt.s, in the directory
The list of operations performed by the CRT can
include (not necessarily in the following order):
• Setting registers to known/required values
• Disabling hardware loops
• Disabling circular buffers
• Setting up default event handlers and
enabling interrupts
a
• Initializing the Stack and Frame Pointers
• Enabling the cycle counter
• Configuring the memory ports used by the
two DAGs
• Setting the processor clock speed
• Copying data from flash to RAM
• Initializing device drivers
• Setting up memory protection and caches
• Changing processor interrupt priority
• Initializing profiling support
• Invoking C++ constructors
• Invoking
• Invoking
_main, with supplied parameters
_exit on termination
What the CRT Does Not Do
The CRT does not set up physical memory
hardware. For example, external SDRAM is not
configured by the CRT in any way. This is left to
the boot loader because it is possible (and even
likely) that the CRT itself will need to be moved
into external memory before being executed.
The CRT in Detail
The CRT is provided as a single assembly source
file. It is assembled different ways to serve
different types of applications, running on
different processors. One source file is used to
generate CRTs for the following devices:
• ADSP-BF531 Blackfin processors
• ADSP-BF532 Blackfin processors
• ADSP-BF533 Blackfin processors
• ADSP-BF535 Blackfin processors
• ADSP-BF561 Blackfin processors
• AD6532 processors
platform-definition header and set up a few
constants:
IVBl and IVBh give the address of the Event
Vector Table.
UNASSIGNED_VAL is a bit pattern that indicates that
the register/memory location has not yet been
written to by the application. This value forms a
marker at the end of the call stack, and, if
UNASSIGNED_FILL is non-zero, will be written into
the Dregs and Pregs.
INTERRUPT_BITS is the default interrupt mask.
By default, it enables the lowest-priority
interrupt,
IVG15. This default mask can also be
overridden at runtime by your own version of
__install_default_handlers; see the Default
Event Handlers section for details.
For some platforms,
SYSCFG_VALUE is the
initialization value for the System Configuration
register (
SET_CLOCK_SPEED determines whether the CRT
SYSCFG).
will attempt to improve the processor’s default
clock speed. For ADSP-BF561 Blackfin
processors, ADSP-BF535 Blackfin processors,
and AD6532 processors, the clock speed is not
altered. For other processors, clock speed
depends on the silicon revision; a number of
accompanying definitions follow which may be
used to change the clock speed up to
approximately 600 MHz.
start and Register Settings
The CRT declares its first code label as start.
This required label is referenced by
.LDF files,
which explicitly resolve this label to the
processor’s reset address.
First, the CRT disables facilities that could be
enabled on start-up, due to their random powerup states, as follows:
•
Declarations
The CRT begins with a number of preprocessor
directives that “include” the appropriate
Configuring the C/C++ Run-Time Header for Blackfin® Processors (EE-238) Page 2 of 8
SYSCFG is set to SYSCFG_VALUE, according to
anomaly
#42 for ADSP-BF532 Blackfin
processors, anomaly #22 for ADSP-BF531
and ADSP-BF533 Blackfin processors, and
a
anomaly #12 for ADSP-BF561 Blackfin
processors.
• Hardware loops are disabled. This prevents
the jump-back-to-loop-start behavior should
the “loop bottom” register correspond to the
start of an instruction.
• Circular buffer lengths are set to zero. The
CRT makes use of the Iregs and calls
functions that may use them. Furthermore,
the C/C++ ABI requires that circular buffers
are disabled on entry to (and exit from)
compiled functions, so the circular buffers
must be disabled before invoking
Event Vector Table
_main.
The Event Vector Table is cleared. No event
handlers are defined except the reset vector
(fixed), emulation events (not touched by the C
ABI), and
event,
IVG15. The processor’s lowest-priority
IVG15, is set to point to supervisor_mode,
a label that appears later in the CRT.
The
___cplb_ctrl control variable is examined to
determine whether caching or memory protection
is required. If it is, an exception handler is
required to process possible events raised by the
memory system. Therefore, the default handler,
___cplb_hdr, is installed into the exception entry
of the Event Vector Table.
For details on
___cplb_ctrl, refer to “Caching
and Memory Protection” in the VisualDSP++
3.5 C/C++ Compiler and Library Manual for
Blackfin Processors [1].
Stack Pointer and Frame Pointer
The Stack Pointer (SP) is set to point to the top of
the stack, as defined in the
symbol
ldf_stack_end. Specifically, the Stack
.LDF file by the
Pointer is set to point just past the top of the
stack. Because stack pushes are pre-decrement
operations, the first push first moves the Stack
Pointer so that it refers to the actual stack top.
The User Stack Pointer (
(
FP) are set to point to the same address.
USP) and Frame Pointer
Twelve bytes are then claimed from the stack.
This is because the C ABI requires callers to
allocate stack space for the parameters of callees,
and that all functions require at least twelve bytes
of stack space for registers
R0-R2. Therefore, the
CRT claims these twelve bytes as the incoming
parameters for functions called before invoking
_main.
Default Event Handlers
The CRT sets up one or two event handlers (one
for changing processor mode; optionally, another
for handling memory system events), as reflected
by the event-enable bit mask. You may install
additional handlers; for your convenience, the
CRT calls a function to do this. The function,
__install_default_handlers, is an empty stub,
which you may replace with your own function
that installs additional or alternative handlers,
before the CRT enables events.
The function’s C prototype is:
short _install_default_handlers(short mask);
The CRT passes the default enable mask,
(
INTERRUPT_BITS) as a parameter, and considers
the return value to be an updated enable mask; if
you install additional handlers, you must return
an updated enable mask to reflect this.
Cycle Counter
The CRT enables the cycle counter, so that the
CYCLES and CYCLES2 registers are updated. This is
not necessary for general program operation, but
is desirable for measuring performance.
DAG Port Selection
For ADSP-BF531, ADSP-BF532, ADSP-BF533,
and ADSP-BF561 Blackfin processors, the CRT
configures the DAGs to use different ports for
accessing memory. This reduces stalls when the
DAGs issue memory accesses in parallel.
Configuring the C/C++ Run-Time Header for Blackfin® Processors (EE-238) Page 3 of 8
Loading...
+ 5 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.