Difference between revisions of "PalmOS port"

From Lazarus wiki
Jump to navigationJump to search
m (changed prc-tools-remix URL to my fork, until (and if) my pull request with build fixes is accepted)
(→‎Building Tutorial: updated building information to be from this decade at least)
Line 30: Line 30:
 
==Building Tutorial==
 
==Building Tutorial==
  
During the tutorial some paths will be supposed to demonstrate the build process. Just substitute those paths with the ones on your system.
+
The section below details building an m68k-palmos Free Pascal cross compiler. The ARM building process is the same with the different CPU name. Note that the ARM PalmOS support is non functional at the moment.
  
 
===Cross binutils===
 
===Cross binutils===
  
The older version of GNU binutils included in [http://prc-tools.sourceforge.net prc-tools] is difficult to build on modern systems, like macOS/Darwin 10.12 or any 64-bit Linux. It is recommended to use the [https://github.com/chainq/prc-tools-remix prc-tools-remix] repository instead. This supports both m68k and ARM prc tools, and it is fixed to build and work on current systems. It also provides up to date installation instructions, see there.
+
The older version of GNU binutils included in [http://prc-tools.sourceforge.net prc-tools] is difficult to build on modern systems, like macOS/Darwin 10.12+ or any 64-bit Linux. It is recommended to use the [https://github.com/chainq/prc-tools-remix prc-tools-remix] repository instead. This supports both m68k and ARM prc tools, and it is fixed to build and work on current systems. It also provides up to date installation instructions, see there.
  
 
===Cross compiler===
 
===Cross compiler===
  
We will suppose that your are using debian linux installation (sid) and fpc compiler is already installed and correctly configured.  Under debian linux (sid) you may install the '''[http://packages.debian.org/unstable/devel/fp-compiler fp-compiler]''' package ("apt-get install fp-compiler")
+
PalmOS is a cross-compiler only target. The following steps build a PalmOS cross-compiler:
  
Now you need to build fpc cross compiler for ARM processor. To do that you need latest fpc 2.1.x sources in addition to your working installation of fpc 2.0.2 or 2.0 already mentioned. Get the latest 2.1.x source repository from Subversion: http://www.freepascal.org/develop.html#svn
+
# Install the latest stable Free Pascal Compiler. This will be used as the startup compiler.
 +
# Check out FPC SVN trunk into a directory.
 +
# Make sure the [[#Cross binutils|cross-binutils]] are properly built, and its binaries are actually in the '''PATH'''.
 +
# Go to the SVN trunk root directory and use the following command to build an m68k-palmos cross-compiler:
 +
<syntaxhighlight lang="bash">
 +
  make clean crossall crossinstall OS_TARGET=palmos CPU_TARGET=m68k CROSSOPT="-XX -CX" INSTALL_PREFIX="<path/to/install>"
 +
</syntaxhighlight>
  
===Environment===
+
If everything went correctly, you should find a working PalmOS cross-compiler at the install path you specified.
  
We will suppose your Free Pascal 2.1.x source code is located here: <tt>${FPC_SRC}</tt>
+
Now, lets create a default fpc.cfg for PalmOS cross compiling. Create a file called '''<path/to/install>/lib/fpc/etc/fpc.cfg'''. Put the following lines into that file, and fix up the paths:
  
<tt>PATH="/bin:/usr/bin:/usr/bin/X11:/usr/local/bin:${FPC_SRC}/compiler"</tt>
+
#IFDEF CPUM68K
 +
-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET
 +
-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET/*
 +
#IFDEF PALMOS
 +
-FD</path/to/m68k-palmos-binutils>
 +
-XPm68k-palmos-
 +
-XX
 +
-CX
 +
#ENDIF
 +
#ENDIF
  
===The Build process===
+
Note the '''-CX''' and '''-XX''' options used for both the build and the config file. They enable smartlinking by default.
  
In order to build the cross compiler it is necessary to have a correct <tt>PATH</tt> environment variable. Please ensure that your path is correct:
+
'''<font color="red">Due to the size constraints PalmOS puts on the executables, and the limitations of the old prc-tools binutils, building and compiling without smartlinking is not supported.</font>'''
  
<pre>
+
Optionally add '''<path/to/install>/lib/fpc/3.1.1/''' directory to the PATH, so you'll have direct access to the cross compiler. If you've done everything right, you now should be able to build PalmOS executables from a Pascal source the following way:
make all CPU_TARGET=arm OS_TARGET=palmos
 
</pre>
 
  
On the end of the compile you should not see any errors.  
+
ppcross68k -Tpalmos <source.pas>
  
You should have a <tt>ppccrossarm</tt> in <tt>${FPC_SRC}/compiler</tt> and some <tt>.o</tt> and <tt>.ppu</tt> files in <tt>${FPC_SRC}/rtl/units/arm-palmos</tt>
+
Copy the resulting .prc executable to your PalmOS device using HotSync or your preferred method.
 
 
Now copy those files to your Free Pascal installation. The cross compiler <tt>ppccrossarm</tt> should go to <tt>/usr/local/bin/arm-palmos</tt> and the units to <tt>/usr/local/lib/fpc/units/arm-palmos</tt>
 
 
 
===Configuration file===
 
 
 
Now you need to edit your FPC configuration file <tt>${HOME}/.fpc.cfg</tt> in order to use <tt>ppccrossarm.exe</tt> easy and add the following lines to it:
 
<pre>
 
#IFDEF FPC_CROSSCOMPILING
 
-Tpalmos
 
-Fu${FPC_SRC}/rtl/units/arm-palmos
 
-XParm-palmos-
 
#ENDIF
 
</pre>
 
  
 
==Compiling a Test Project==
 
==Compiling a Test Project==

Revision as of 10:01, 9 January 2018

English (en) español (es) português (pt)

Currently, the PalmOS port is a retro, "just for fun" port of the compiler and runtime libraries, based on an earlier, incomplete effort from over a decade ago. The port was originally started by Mazen Neifer. Peter Vreman ported PalmOS API headers. m68k port and 3.1.x+ compiler support and maintenance by Károly Balogh. The PalmOS port is a crosscompiler-only target.

Status

  • The 3.1.x compiler has compiler support (very experimental) for PalmOS.
  • m68k CPU is supported, including syscall generation support. Only small code is supported at the moment.
  • ARM CPU is not yet supported
  • Base RTL units are buildable but functionality is minimal.
  • There's a palmunits package, basic functionality was tested successfully.
  • Resource compilation is broken at the moment.

CPU Defaults

The m68k PalmOS port defaults to 68000 CPU subarchitecture and no FPU. Note that by default, the PalmOS port doesn't include the RTL's SoftFPU. For floating point calculations, one can use the OS supplied floating point unit helper API, or recompile the RTL with the SoftFPU included, using argument -CfSOFT.

Identification

To identify PalmOS exclusively during compile-time, use {$IFDEF PALMOS}.

SysCalls

It's not required to use inline assembly to do system calls. Any trap function can be defined the following way:

function MemPtrNew(size: UInt32): MemPtr; syscall $A013;

Note the syscall modifier in the function declaration. The argument to the syscall modifier is the trap number to call. The arguments to a syscall function are always passed on the stack and they're word (2 byte) aligned. Optionally, the numerical trap ID (here shown in hexadecimal) can be defined by a constant. For further examples, see the file rtl/palmos/palmos.inc in the RTL source or the palmunits package.

Building Tutorial

The section below details building an m68k-palmos Free Pascal cross compiler. The ARM building process is the same with the different CPU name. Note that the ARM PalmOS support is non functional at the moment.

Cross binutils

The older version of GNU binutils included in prc-tools is difficult to build on modern systems, like macOS/Darwin 10.12+ or any 64-bit Linux. It is recommended to use the prc-tools-remix repository instead. This supports both m68k and ARM prc tools, and it is fixed to build and work on current systems. It also provides up to date installation instructions, see there.

Cross compiler

PalmOS is a cross-compiler only target. The following steps build a PalmOS cross-compiler:

  1. Install the latest stable Free Pascal Compiler. This will be used as the startup compiler.
  2. Check out FPC SVN trunk into a directory.
  3. Make sure the cross-binutils are properly built, and its binaries are actually in the PATH.
  4. Go to the SVN trunk root directory and use the following command to build an m68k-palmos cross-compiler:
  make clean crossall crossinstall OS_TARGET=palmos CPU_TARGET=m68k CROSSOPT="-XX -CX" INSTALL_PREFIX="<path/to/install>"

If everything went correctly, you should find a working PalmOS cross-compiler at the install path you specified.

Now, lets create a default fpc.cfg for PalmOS cross compiling. Create a file called <path/to/install>/lib/fpc/etc/fpc.cfg. Put the following lines into that file, and fix up the paths:

#IFDEF CPUM68K
-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET
-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET/*
#IFDEF PALMOS
-FD</path/to/m68k-palmos-binutils>
-XPm68k-palmos-
-XX
-CX
#ENDIF
#ENDIF

Note the -CX and -XX options used for both the build and the config file. They enable smartlinking by default.

Due to the size constraints PalmOS puts on the executables, and the limitations of the old prc-tools binutils, building and compiling without smartlinking is not supported.

Optionally add <path/to/install>/lib/fpc/3.1.1/ directory to the PATH, so you'll have direct access to the cross compiler. If you've done everything right, you now should be able to build PalmOS executables from a Pascal source the following way:

ppcross68k -Tpalmos <source.pas>

Copy the resulting .prc executable to your PalmOS device using HotSync or your preferred method.

Compiling a Test Project

You compiled the compiler! Now, what can I do with it? This is a tutorial to create a hello world like software with your new compiler.

Installing and Configuring the Emulator

First of all, you need to install the Palm Device Emulator. This is a windows binary, but works well with WINE on a Debian Linux (sid) box. TODO

Compiling

A example file to compile:

program test;

{$apptype console}

var
  Str: string;
begin
  WriteLn('Software Developed with:');
  WriteLn('The Free Pascal Compiler');
  WriteLn('');
  WriteLn('Please, enter your name:');
  ReadLn(Str);
  WriteLn('Your name is: ' + Str);
end.

Sample command line to compile test.pas:

ppcrossarm test.pas

You should get test.prc executable file. Copy it to your Palm device and run it.

Debugging PalmOS applications

This section is not yet available

Building FPC libraries

If you want to build libraries available with FPC, for example you want to build FCL then execute the commands above.

*
cd ${FPC_SRC}/fpc
make OS_TARGET=palmos CPU_TARGET=arm PP=ppcrossarm fcl

You will get FCL units in ${FPC_SRC}/fpc/fcl/units/arm-palmos.

Documentation

PalmOS port notes

  • PalmOS does not have support for console applications by default. But you can install console support by yourself. Please note that FPC creates GUI applications for PalmOS target by default. To create console application you should use -WC compiler switch or put {$APPTYPE CONSOLE} directive to source code.

Links

  • Buildfaq is a general FAQ about how to build and configure FPC.

Here are some links related to ARM CPU Architecture

Contacts

Mazen NEIFER