Level: Intermediate Matt Tyrlik, Senior Engineer, IBM
01 Aug 2004 Updated 16 Sep 2005 The IBM PowerPC® 970FX processor is great for embedded programming, but it has a few features, such as 64-bit support, that many embedded developers might not know just how to exploit. Read on to get up-to-speed and learn what you need to know.
Introduction to the IBM PowerPC 64-bit architecture
The IBM PowerPC architecture describes two computation modes: 32- and 64-bit. The IBM PowerPC 403GCX, PowerPC 405GP, PowerPC 440GX, and Power PC750FX microprocessors are examples of processors that implement only 32-bit computation mode. The PowerPC 970FX processor implements both computation modes. Generally, PowerPC processors that implement only 32-bit computation mode are referred to as 32-bit PowerPC processors. Processors that implement both computation modes are referred to as 64-bit PowerPC processors. If a processor implements the 64-bit computation mode, it also must implement the 32-bit computation mode.
All the user-level registers (except for floating-point registers, which are 64-bit wide) implemented by the 32-bit PowerPC processors are 32-bit wide. High-level language compilers generate user-level instructions, which in turn use the user-level registers. In 32-bit PowerPC processors, all the supervisor-level registers are 32 bits wide. The supervisor-level registers are typically accessed only by system software (operating system) and device drivers. The machine state register (MSR) is 32 bits wide in the 32-bit PowerPC processors.
Most user-level registers implemented by the 64-bit PowerPC processors (PowerPC 970FX) are 64-bit wide. Only the condition register (CR) and the floating-point status and control register (FPSCR) are 32-bit wide. Although the PowerPC 970FX processor implements both 32- and 64-bit computational modes, there is only one set of user- and supervisor-level registers. The single set of registers is used for both computation modes. In the PowerPC 970FX processor, the supervisor-level registers are a mix of 32- and 64-bit registers. For example, the processor version register (PVR) is 32 bits wide, but the hardware implementation register 0 (HID0) is 64 bits wide. The MSR is 64 bits wide in the PowerPC 970FX processor. The computation mode of the PowerPC 970FX processor is controlled by the setting of the MSR's Sixty-Four-Bit Mode bit. Changing this bit alters the processor's computation mode.
All the PowerPC instructions are 32 bits wide irrespective of the computation mode or processor implementation. The PowerPC 970FX processor can execute all user-level instructions implemented by the 32-bit PowerPC processors. The PowerPC 970FX processor can also execute a number of new user-level instructions that are valid only for 64-bit PowerPC implementations. The instructions implemented by the 32-bit PowerPC processors and the new 64-bit PowerPC instructions execute using the same processor execution units and use the same registers in the PowerPC 970FX processor. There is no performance penalty associated with execution of either instruction set on the PowerPC 970FX processor, regardless of the computation mode.
User-level instructions that are specific to the 64-bit PowerPC processor implementations include load and store double-word instructions as well as arithmetic and logical instructions that use 64-bit-wide operands. The user-level instructions that are specific to the 64-bit PowerPC processor implementations and the instructions implemented by the 32-bit PowerPC processor can be executed in either computation mode.
PowerPC 64-bit ELF ABI
The Application Binary Interface (ABI) describes various aspects of the execution environment for compiled programs. The PowerPC 64-bit ELF ABI is used for application programs executing in 64-bit computation mode. The PowerPC 64-bit ELF ABI is implemented by the GNU GCC compiler and by the GNU binary utilities package. The 64-bit IBM PowerOpen™
ABI is used by the IBM AIX® operating system and has the same calling convention as the PowerPC 64-bit ELF ABI. The PowerPC 64-bit ELF ABI is basically an adaptation of the 64-bit PowerOpen ABI to the ELF object file format.
Code executing in 32-bit computation mode should use the PowerPC 32-bit Embedded Application Binary Interface (EABI) or a comparable 32-bit PowerPC ABI. Code using the 32-bit PowerPC ABI can execute assembly instruction functions in 64-bit computation mode. The assembly language function can switch to the 64-bit computation mode, execute a series of instructions, and then switch back to 32-bit computation mode.
Multiprocess operating systems (for example, Linux®) can switch between application programs running in 32-bit computation mode using a 32-bit ABI, and programs running in 64-bit computation mode using the PowerPC 64-bit ELF ABI. In order to support both the 32- and 64-bit computation mode application programs, the operating system itself must execute in 64-bit computation mode and must have the ability to load multiple executable files. A single executable file cannot contain code that executes using the PowerPC 64-bit ELF ABI and PowerPC 32-bit EABI.
Single-process operating systems such as VxWorks can only execute application programs using a single ABI. It is not possible to create a single executable file with a mixture of object files compiled using PowerPC 64-bit ELF ABI and PowerPC 32-bit EABI.
The PowerPC 64-bit ELF ABI covers the following topics:
- C and C++ language fundamental data type size and alignment
- Register usage
- Stack layout
- Table of content format
- Function descriptors
- Traceback tables structure
- Object file format
Development tools
Tools supporting the PowerPC 64-bit ELF ABI have to be used for 64-bit computation mode program development. Tools supporting one of the existing 32-bit PowerPC ABIs have to be used for application programs executing in 32-bit computation mode. Assembly language functions executing in 64-bit computation mode can be written using 32-bit PowerPC tools. Because the tools supporting the PowerPC 64-bit ELF ABI produce 64-bit ELF object files, and 32-bit PowerPC ABI tools typically produce 32-bit ELF object files, the output from both tool chains cannot be combined into a single executable program. It is possible to write assembly language functions that execute in 64-bit computation mode using the 32-bit tools, though.
The GNU GCC compiler and GNU binary utilities (linker, assembler, archiver) can be used for both PowerPC 970FX 64- and 32-bit computation mode application-program development. However, a single instance of the GNU GCC compiler can't support both the PowerPC 64-bit ELF ABI and 32-bit PowerPC EABI. Two independent copies of the compiler and the tools have to be created when developing software for the 32-bit computation and 64-bit computation mode. For more information on building the GNU development tools, see the
"Building a GNU Toolset For Use In Embedded PowerPC Cross Development"
application note (see Resources for a link). Version 3.3.1 or later of the GNU GCC compiler and Version 2.14 or later of the GNU binary utilities support the PowerPC 64-bit ELF ABI.
The RISCWatch debugger currently supports debugging of the software running on the PowerPC 970FX processor. RISCWatch is typically attached to the PowerPC 970FX processor using a Joint Test Action Group (JTAG) port. RISCWatch supports the debugging of low-level system software as well as application programs written in the C as well as the C++ language. RISCWatch supports debugging of programs using PowerPC 64-bit ELF or PowerPC 32-bit EABI.
Porting PowerPC 32-bit software to PowerPC 970FX 64-bit computation mode
Most software programs written in the C or C++ language can be easily migrated to the 64-bit computation mode of the PowerPC 970FX processor. In the C language, only long and pointer data types are different between the PowerPC 32-bit EABI and PowerPC 64-bit ELF ABI. The change in size of long and pointer data types affects the structure element alignment and structure padding, which is important if the data is accessed in multiple contexts (for example, C language and assembler). The data type change also affects results of certain assignment and arithmetic operations.
A compiler can also insert padding at the end of a structure. Structure-end padding is required in case the structure is used as an element of an array. Such padding is not required if this structure is compiled for the 32-bit ABI. Care must be taken if a structure size or field alignment is restricted. The structure mapping can be restricted because it represents data that is transmitted over the network (for example, a TCP header structure).
Another example of a problem is related to the change in size of the pointer data type as illustrated in the following sample code:
int test;
void *p;
test=(int)p;
|
The sample code running in 32-bit computation mode executes correctly because the size of the pointer variable is the same as the size of the integer variable. In 64-bit computation mode, the code sample might not execute correctly if the pointer value is greater than 232. The GNU GCC compiler produces a warning message when compiling this code even though an explicit cast is used. Any pointer arithmetic should be performed using variables of type long, regardless of the computation mode. Pointer assignment should only be performed between other pointers or variables of type long. In general, the use of pointers as well as the long data type might need to be examined when porting 32-bit PowerPC programs. Care must also be taken then when displaying long or pointer values because the number of characters required to display these values is different.
The use of function descriptors by the PowerPC 64-bit ELF ABI requires that changes be made to code that manipulates function addresses. In order to access function addresses, the following code can be used:
int function_name(int arg1, int arg2);
typedef struct function_descriptor {
void *addr;
unsigned long toc;
unsigned long env;
} f_desc_t;
function_address=(unsigned long)(((f_desc_t *)function_name)->addr);
|
The process of porting current 32-bit software targeted for the 64-bit computation mode of the PowerPC 970FX is in large measure limited to changes in the programs that will execute in Supervisor mode.
Porting PowerPC 32-bit software to PowerPC 970FX 32-bit computation mode
User-level 32-bit PowerPC application programs do not require any changes in order to be executed in the 32-bit computation mode on the PowerPC 970FX processor. The 32-bit computation mode is chosen by setting the SF bit in the MSR register to 0. In order to exploit some of the 64-bit capabilities of the PowerPC 970FX processor, changes in the original 32-bit PowerPC user-level application programs can be made. For example, if 32-bit software is performing 64-bit scalar arithmetic operations, the arithmetic operations can be written in assembly language. Such assembly function can be called from high-level languages. The values passed to the function that is performing 64-bit arithmetic and the return value must be contained in lower 32-bits of general-purpose registers (GPRs).
The process of porting current 32-bit software targeted for the 32-bit computation mode of the PowerPC 970FX is in large measure limited to changes in the programs that will execute in Supervisor mode.
Summary
The PowerPC 970FX processor can execute application programs in both 32-bit computation mode and in 64-bit computation mode. Because the PowerPC architecture from the beginning described a 32-bit computation mode and a 64-bit computation mode, PowerPC 32-bit software can be ported with minimal effort to the 64-bit computation mode of the PowerPC 970FX processor. The ease of porting existing 32-bit PowerPC applications is facilitated in part by the PowerPC 64-bit ELF ABI because it offers logical extension to the 32-bit PowerPC EABI. Existing user-level PowerPC 32-bit software can be executed in 32-bit computation mode without any changes. The tasks required to port supervisor-level PowerPC 32-bit software to the PowerPC 970FX processor are not significantly different from the tasks required to port supervisor-level software between different 32-bit PowerPC processor implementations. The PowerPC 970FX 32-bit computation mode and the 64-bit computation mode programs share the same processor registers and use the same execution units. There is no performance penalty associated with running 32-bit computation mode applications on a PowerPC 970FX processor. The
"Developing Embedded Software For The IBM PowerPC 970FX Processor"
application note (see Resources) provides additional information on porting software to the PowerPC 970FX processor.
Resources Learn
Get products and technologies
Discuss
About the author  | |  | Matt Tyrlik is a software engineer working in embedded software development. |
Rate this page
|