Sign in Join
Wiki copytemporary

m68k

The contents of this article reflect the status in FPC main (git). Some features listed here might not be available in the latest stable version.

Introduction

Historically, the Motorola 680x0 (abbreviated as "m68k") port was the first Free Pascal port to CPU architectures other than i386. During the big refactoring for FPC 2.0, the code left without maintenance and the support broke and was partly removed. The Motorola 680x0 code generator got revived more than 10 years later, before FPC 3.0. It still shares some components with the old 1.x source code, like parts of the inline assembler reader, but most of the code is new.

Supported CPU types

The current Motorola 680x0 backend supports the following CPU and FPU types:

Notes:

Supported Targets

Free Pascal currently supports the following operating systems as target platforms on m68k:

Support is planned for the following targets:

Defaults

The default target for a cross-compiler is Linux, when running natively it's the host platform. In either case, any supported target is available, using the -T argument, the cross-compiler binary is only CPU specific, not OS specific. The default CPU target settings are 68020+68881 for Linux and NetBSD, 68000+SoftFPU for PalmOS and the Sinclair QL, and 68020+SoftFPU for all other supported OS targets.

Performance

Most members of the old Motorola 680x0 CPU family are not fast enough to run the compiler natively, although high-end 68060 systems and various fast JIT-based m68k emulators with enough memory are capable to do so. Therefore it is recommended to use a cross-compiler when targeting most m68k systems. Apart from the performance issues the code generator is mature enough to compile the compiler itself, make cycle works. Amiga, Linux and NetBSD are supported as compilation hosts.

Registers

When compiling for the Motorola 68k, Free Pascal uses the following conventions with registers. This matches, or closely matches most C compilers and most operating systems on this platform. Any additional differences are documented at the specific platform's documentation.

Inline assembler

The inline assembler follows the Motorola syntax. The register alias fp points to a5 or a6 register, respectively. The register alias sp points to a7.

Calling Conventions

The Motorola 68k CPU target supports several different calling conventions.

The current default calling convention is register.

Return values

Unaligned access support

Some members of the m68k CPU family doesn't support larger than byte accesses of odd addresses. Most notably this includes the original 68000, the 68008, the 68010 and some members of the CPU32 subfamily. The compiler supports generating special unaligned access code for these scenarios, when targeting these CPU. However, this unaligned access code is slow, as it involves several individual byte accesses plus shifts, so it should be avoided whenever possible. Unaligned access code will be generated at:

Because of the last two points, it's discouraged to use packed records on these CPU in performance critical code.

Round/Trunc fast path and special handling

The m68k family, and its associated FPU has no floating point to 64bit integer rounding instruction, which is mandatory to fully implement the System unit's Round and Trunc functions as inline nodes. Nevertheless, the compiler contains a fast path to avoid the slow Round/Trunc helper functions, when rounding towards 8, 16, and 32bit signed integers, 8, and 16bit unsigned integers. This fast path is only enabled with optimization level -O4, or with -OoFASTMATH optimization. It's only enabled as uncertain optimization, because if the result of the rounding doesn't fit into the target variable it will be undefined, while it's defined with Round/Trunc, and should just contain the lower bits of the otherwise 64bit result. Please also note the Round/Trunc fast path needs a hardware FPU and it's not available with the SoftFPU.

Stack

Due to performance reasons caused by addressing modes constraints, it's highly advised to not use more than 32KiB stack in any function on an m68k CPU. The code generator backend supports larger than 32KiB stacks for single functions, but this will be always slower, and wasn't tested extensively. Also please note that most m68k systems are low-end with limited amount of memory, and usually with a fixed, limited size stack, where using large amounts of stack can be problematic.

Compile time detection of CPU type

To detect the current CPU and FPU targets during compile time, the following defines exist:

Runtime detection of CPU type

The RTL provides two m68k specific variables, to allow the user code to detect the CPU easily, in case it is necessary. These are:

Example:

pascal
program hello68k;

begin
  writeln('Hello World!');
  write('Running on 680',Test68000,'0 CPU');
  case Test68881 of
    0: writeln(' without FPU');
    1,2: writeln(' with 6888',Test68881,' FPU');
  else
    writeln(' with internal FPU');
  end;
end.

Notes:


From the Free Pascal wiki, page "m68k", as it stood on 2023-11-19 after a change by Bart, 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 1, last changed by WikiArchive .

Talk about this page

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