02.03.2014 Views

BSP Developer's Guide

BSP Developer's Guide

BSP Developer's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

VxWorks 5.5<br />

<strong>BSP</strong> Developer’s <strong>Guide</strong><br />

Analysis of Wind River’s existing code base reveals three main areas where<br />

non-ANSI compiler features are used to generate run-time code:<br />

■<br />

■<br />

■<br />

packed structure definitions<br />

in-line assembly code<br />

alignment of data elements<br />

NOTE: This chapter is limited in scope to insuring that code is portable specifically<br />

between the GNU and Diab compilers.<br />

NOTE: The scope of this chapter is further limited to specify GCC version 2.96 and<br />

Diab version 5.0 as the baseline compilers. Earlier versions are not truly compatible<br />

with each other and may not have all the necessary support to implement the<br />

conventions introduced here.<br />

8.1 Portable C Code<br />

8.1.1 Data Structures<br />

Some structure definitions are bound by external restrictions. It is common<br />

practice to use a structure definition to document the register layout of hardware<br />

devices. Using a structure to define the layout of data packet contents received<br />

from another system is also common. This can create problems because the ANSI<br />

specification allows compilers to insert padding elements within structure<br />

definitions in order to optimize data element accesses. In these situations, doing so<br />

would make the structure declaration incompatible with the expectations and<br />

restrictions of the outside world. The compiler offsets from the start of the structure<br />

to the start of the data element would not match what is expected. A method is<br />

required for identifying certain structures as requiring special compiler treatment,<br />

while allowing other structures to be optimized for efficiency.<br />

The common term for a structure definition without any padding is packed. Each of<br />

the major compilers has a means to specify packing for a structure, but there is no<br />

single recognized standard. GNU and Diab use an attribute statement as part of<br />

the declaration. Microsoft compilers use #pragma statements.<br />

To specify packing in a compiler-independent manner a macro has been created for<br />

use when defining the structure. The _WRS_PACK_ALIGN(x) macro is used as an<br />

160

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

Saved successfully!

Ooh no, something went wrong!