07.04.2013 Views

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.14.2 String Literals as Arguments<br />

Run Time Environment<br />

In addition to being used as initializers, string literals may also be used as function<br />

arguments. For example:<br />

myputs("Enter the Dragon code:\n");<br />

Here allocation of the string literal depends on the surrounding code. If the statement<br />

appears in a boot or secure function, the literal will be allocated in a corresponding PSV<br />

constant section. Otherwise it will be placed in general (non-secure) memory,<br />

according to the constants memory model.<br />

Recall that data stored in a secure segment can not be read by any other segment. For<br />

example, it is not possible to call the st<strong>and</strong>ard C library function puts() with a string<br />

that has been allocated in a secure segment. There<strong>for</strong>e literals which appear as function<br />

arguments can only be passed to functions in the same security segment. This is<br />

also true <strong>for</strong> objects referenced by pointers <strong>and</strong> arrays. Simple scalar types such as<br />

char, int, <strong>and</strong> float, which are passed by value, may be passed to functions in<br />

different segments.<br />

4.14.3 Const-qualified Variables in Secure Flash<br />

const-qualified variables with initializers can be supported in secure Flash segments<br />

using PSV constant sections managed by the compiler. For example:<br />

const int __attribute__((boot)) time_delay = 55;<br />

If the const qualifier was omitted from the definition of time_delay, this statement<br />

would be rejected with an error message. (Initialized variables in secure RAM are not<br />

supported).<br />

Since the const qualifier has been specified, variable time_delay can be allocated<br />

in a PSV constant section that is owned by the boot segment. It is also possible to specify<br />

the PSV constant section explicitly with the space(auto_psv) attribute:<br />

int __attribute__((boot,space(auto_psv))) bebop = 20;<br />

Pointer variables initialized with string literals require special processing. For example:<br />

char * const foo __attribute__((boot)) = "eek";<br />

The compiler will recognize that string literal "eek" must be allocated in the same PSV<br />

constant section as pointer variable foo. The logic <strong>for</strong> making that association is<br />

already supported in the compiler <strong>for</strong> named PSV sections.<br />

4.14.4 Object Compatibility Model<br />

Since functions in secure segments set PSVPAG to their respective psv constant sections,<br />

a convention must be established <strong>for</strong> managing multiple values of the PSVPAG<br />

register. In previous versions of the compiler, a single value of PSVPAG was set during<br />

program startup if the default constants-in-code memory model was selected. The<br />

compiler relied upon that preset value <strong>for</strong> accessing const variables <strong>and</strong> string literals,<br />

as well as any variables specifically nominated with space(auto_psv).<br />

<strong>Compiler</strong> v3.0 will provide automatic support <strong>for</strong> multiple values of PSVPAG. Variables<br />

declared with space(auto_psv) may be combined with secure segment constant<br />

variables <strong>and</strong>/or managed psv pointer variables in the same source file. Precompiled<br />

objects that assume a single, pre-set value of PSVPAG will be link-compatible with<br />

objects that define secure segment psv constants or managed psv variables.<br />

Even though PSVPAG is now considered to be a compiler-managed resource, there is<br />

no change to the function calling conventions. Objects <strong>and</strong> libraries created with earlier<br />

versions are compatible with 3.0 objects, with the exception of some Interrupt Service<br />

Routines as noted in Section 8.10 “PSV Usage with Interrupt Service Routines”.<br />

© 2008 <strong>Microchip</strong> Technology Inc. DS51284H-page 77

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!