Sign in Join
Wiki copytemporary

PowerPC64 Port

The PowerPC64 port supports code generation for 64-bit PowerPC systems. Historically it started as entry for the Linux On Power contest.

This page contains a rough outline of what is working and especially what not, some notes about the port and several other related information. More, detailed information (about calling conventions and so on) later.

Status

Installing and Building

Although the current compiler is still beta, and still has a few bugs, it can already be used by interested people. To get a recent working compiler, it is easiest to start on a G5 using a snapshot, and then update it to the latest version using the development sources. Simply download one for the current development version (2.1.1 at the time of writing this) from the FTP. The snapshot for the compiler is located in the powerpc64-linux subdirectory.

Installing the snapshot

Installing the snapshot is easy: Extract it somewhere (e.g. in /usr, the FreePascal default installation base directory), and if necessary set your PATH environment variable to point to the bin directory. Additionally, you need to add a symlink called ppcppc64 pointing to the ppcppc64 binary in the lib directory of the extracted snapshot directory. For example type

text
 ln -s /usr/lib/fpc/2.1.1/ppcppc64 ppcppc64

if you are in the /usr/bin directory.

To be able to use the latest features, it is recommened to update to the most current version using the source code, see below for more information on how to do this.

Updating to the latest version

Another way, in particular if you do not want to install the compiler before updating to the latest version, get the ppcppc64 binary from the snapshot file and use it to cycle the sources. Then do the following: Change into the directory where you have stored the current SVN sources from the current development branch, and enter the following command:

text
 make build PP=<path_to_ppcppc64>/ppcppc64

Take care that the given path must be an absolute path, otherwise the compilation process immediately aborts. For the people which want a much faster binary, add OPT=-O2 to the command line. After a while (and lots of compilation) it should leave you with an empty commandline, and you are ready for installing the compiler. Assuming that you compiled as non-root, do the following:

text
 su   (You will be asked for your root password)
 make install
 exit (To give up root access again)

It is possible that compiling the compiler with the -O2 or other additional options you specified in the OPT parameter does not successfully cycle. In that case, first compile and install a current compiler without any additional options, and retry with that one.

Compiling a program

Compiling a Pascal program should be as easy as typing

text
 fpc <pascal_sourcefile>

after installation completed successfully. If the fpc complains about not finding the ppcppc binary, you have to set a symbolic link to the actual binary in the installation directory as described above.

For further information please also read the offical documentation (PDF) (HTML).

Register usage

The table below shows how the compiler uses the registers for code generation and their meaning. The „volatile“ column indicates whether this register (or register set) is volatile or not, i.e. if a register is marked as volatile, the value is not preserved across function calls, otherwise they are automatically saved and restored by the function prolog and epilog. A value of „N/A“ means that the register is handled in a special way, and in general should not be modified by the programmer. This table basically contains a summary of the information in chapter 3.2.1 of the ABI specification.

Register

Volatile

Description

r0

Y

Volatile register used in function prologs and constant loading (i.e. scratch register)

r1

N/A

Stack frame pointer. The stack must always be quadword (16 byte) aligned

r2

N/A

TOC pointer. Used for the GOT/TOC when enabling generation of PIC code (with -Cg), otherwise unused by Pascal programs.

r3

Y

Parameter register and return value register

r4-r10

Y

Registers used for function parameters

r11

Y

Register used in calls by pointer, otherwise used as scratch register

r12

Y

Register used for glink code and scratch register

r13

N/A

Reserved for use as system thread ID. Never touched by the FreePascal compiler

r14-r31

N

Registers used for local variables

f0

Y

Scratch register

f1

Y

Floating point parameter and return value register

f2-f13

Y

Floating point parameter registers

f14-f31

N

Registers used for local variables

LR

Y

Link register

CTR

Y

Loop counter register. FreePascal uses it for special code patterns, but not in common code

XER

Y

Fixed point exception register

FPSCR

Y

Floating point status and control register

CR0-CR3

Y

Condition code register fields

CR2-CR4

N

Nonvolatile condition code register fields

CR5-CR7

Y

Volatile condition code register fields

Notes

32 bit compatibility

During porting several compatibility problems of 32 bit PowerPC programs with the 32 bit emulation layer of Linux were found. They are:

There may (and I think there are) more issues. These are only those which I could reproducably pinpoint at this time.

Optimizing for PowerPC64

There are a few rules of thumb to make PowerPC64 programs perform well. This section will present at least some of them. Of course, these are rather low-level, often a better algorithm is more advantageous than to do this sort of bean-counting.

(*) Although these optimizations are not implemented yet for the PowerPC64 platform, they surely will be =). Maybe these optimizations will require setting some optimization switch though, or will be disabled for some settings.

Alignment rules

Some rules and information on alignment penalties on the PPC970 processor, taken from the manuals. These are mainly of interest for assembly programmers though:

Debugging and Profiling

This section contains some information on tools to debug and test applications for the PowerPC64 platform generated by the FreePascal compiler.

In general, the FreePascal standard debugging facilities, i.e. enabling debug code generation (-g switch) in conjunction with line information (-gl) and heap tracing (-gh) works. See the FreePascal manual for more information about these things.

Currently FreePascal the integrated debugger in the IDE does not work. You either have to resort to the GNU GDB commandline debugger and any of the backends (for example DDD). Make sure that debugging for the 64 bit PowerPC platform has been compiled in - some Linux distributions only provide a GDB capable of debugging 32 bit applications.

Using the latest FreePascal compiler version, basic profiling can be done with GNU gprof. See the manual on how to enable generation of required code (Note: try the -pg compiler switch). Since gprof seems to be pretty basic and the technique used rather intrusive, requiring some additional code in the executable, make sure to also try the profilers mentioned in the subsection below.

Additional resources

This subsection contains some information for additional debugging or profiling resources on the PowerPC64/Linux platform:

Troubleshooting

This section contains some hints for solving mysterious behaviour of compiled code

Problem: When linking to some C library, the code sometimes crashes.

Solution: Some C libraries (for example OpenGL) sometimes give an "Invalid Floating Point Operation" (Underflow, Overflow) or similar when used in Pascal. This is due to bugs in the C library which are not detected there, because C by default disables these exceptions. Try adding the following assembly code to your main program: asm mtfsfi 6, 1 end;. This disables these exceptions globally (also in the Pascal program). To fix this, tell the maintainers of the library about this bug.

Problem: The compiler gives strange errors, especially after updating to a new version

Solution: Make sure that there are not any stale (old) compiled units lying around, and make sure that the compiler actually uses the recent ones (use the -vt switch to display tried files)

Problem: Debugging information is displayed incorrectly or not at all.

Solution: Enable debugging support using the -g switch to enable generation of debugging information.

More information

This section contains links and notes to further information about the PowerPC64 architecture. This includes links to the ABI specification, general processor descriptions, instruction set documentation and general compiler notes.

Contact

Message to the fpc-devel mailing list, or look for "tom_at_work" in the IRC channel (or of course discuss it here).


From the Free Pascal wiki, page "PowerPC64 Port", as it stood on 2016-11-27 after a change by Jwdietrich, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 3, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.