Sign in Join
Wiki copytemporary

AmigaOS: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11*(AmigaOS only)*
22
33This page contains information about the AmigaOS4 on PowerPC port, which is in an **experimental** stage. About classic [[Amiga]] (OS 3.x, Motorola 680x0) port, please see the [[Amiga|relevant page]]. About other Amiga-like systems supported by Free Pascal, see [[AROS]] and [[MorphOS]] pages. **The AmigaOS4 port has no official maintainer at this point, which means no new features are being added.**
44
55The initial AmigaOS4 port was done by Karoly 'Chain-Q' Balogh, maintainer of [[MorphOS]] and classic [[Amiga]] ports.
66
77## Identification
88
99To identify AmigaOS4 exclusively during compile-time, use **{\$IFDEF AMIGAOS4}**. To identify classic Amiga or AmigaOS4, use **{\$IFDEF AMIGA}**. To identify any Amiga-like system, including [[AROS]] and [[MorphOS]], use **{\$IFDEF HASAMIGA}**. This is similar to **HASUNIX** which is defined across Unix systems. Please note that **HASAMIGA** define is only available in Free Pascal 3.0 and up.
1010
1111## Stack
1212
1313On AmigaOS4, the default stack is set to 256 KiB. Stack size can be set directly by the programmer with a compiler switch (-Cs), or with the **{\$MEMORY}** directive. On AmigaOS4 this feature just sets the "stack cookie" in the executable, [as described here](http://wiki.amigaos.net/wiki/Controlling_Application_Stack). You can also reduce the stack size, but note that AmigaOS4 won't allow stack sizes below 32 KiB.
1414
1515## Naming conventions
1616
1717This section describes the differences between the official AmigaOS4 SDK, which is for C language, and the AmigaOS4-specific units in FPC RTL.
1818
1919### Constants
2020
2121System constants are named exactly like in the AmigaOS4 SDK.
2222
2323### Structures and types
2424
2525System structures are named similar like in the AmigaOS4 SDK, but follows the Pascal convention about type naming, so structure names has a T before, and each type has a pointer to type with P before the name. The following example should make things trivial:
2626
27-```
27+```text
2828 struct Task equals to TTask
2929 struct Task * equals to PTask
3030```
3131
3232## Threading
3333
3434Threading is supported on Amiga-like systems since Free Pascal 3.0, using the [[AThreads]] unit. Read there for possible caveats and unsupported features.
3535
3636## Cross compiling
3737
3838While the following sections describe cross-compiling from Linux, you can use Mac OS X and Windows as well, as long as you can provide the required cross-binutils. Also on other systems some paths might be different from the ones described below.
3939
4040### Cross compiling from Linux
4141
4242It's possible to cross-build the AmigaOS4 compiler from Linux/i386 and Linux/x86-64 (probably other CPUs too, but it was not tested). To do that, you need Linux to AmigaOS4 cross-binutils, mainly GNU as, ld, and optionally ar and strip. It's best if you build these from GNU sources, along with the rest of cross-build GNU toolchain.
4343
4444To build an AmigaOS4 cross-compiler, use the following steps:
4545
46461. Install FPC the latest stable compiler, at the time of the writing of this article this is FPC 3.0.0. This will be used as the startup compiler.
47472. Check out FPC SVN trunk into a directory.
48483. Make sure the aforementioned cross-binutils are actually in the PATH.
49494. Go to the trunk's main directory and use the following command to build an FPC to AmigaOS4 cross-compiler running on Linux:
5050
5151``` bash
5252 make clean crossall crossinstall OS_TARGET=amiga CPU_TARGET=powerpc BINUTILSPREFIX=ppc-amigaos- INSTALL_PREFIX="<path/to/install>"
5353```
5454
5555If you've done everything right, you should find a working AmigaOS4 cross-compiler in the install path you've specified.
5656
5757Now, lets create a default fpc.cfg for AmigaOS4 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:
5858
59-```
59+```text
6060#IFDEF CPUPOWERPC
6161-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET
6262-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET/*
6363#IFDEF AMIGAOS4
6464-FD</path/to/amigaos4-cross-binutils>
6565-XPppc-amigaos-
6666#ENDIF
6767#ENDIF
6868```
6969
7070Optionally 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 AmigaOS4 executables from Pascal source on Linux the following way:
7171
72-```
72+```text
7373ppcrossppc -Tamiga <source.pas>
7474```
7575
7676Copy the resulting executable to AmigaOS4, and that's it!
7777
7878### Bootstrapping a compiler from Linux
7979
8080To bootstrap a Free Pascal Compiler from Linux to AmigaOS4, first please complete the previous section.
8181
8282After you have a working cross compiler, go to the SVN **trunk/compiler** directory, and issue the following commands:
8383
8484``` bash
8585 make compiler OS_TARGET=amiga CPU_TARGET=powerpc FPC="<path/to/install>/lib/fpc/3.1.1/ppcrossppc"
8686```
8787
8888Copy the resulting **ppcppc** executable to AmigaOS4. On the OS4 box, try to cycle a compiler the following way in the SVN's **trunk/compiler** directory:
8989
90-```
90+```text
9191set PATH=/SDK/Local/C
9292gmake cycle FPC=/path/to/ppcppc
9393```
9494
9595Please note you need to use **gmake** not **make**, on AmigaOS4. The resulting required compiler is **trunk/compiler/ppcppc**, the RTL files are in **rtl/units/powerpc-amiga**.
9696
9797At the end of the cycle, you might an error, but this is caused by a linker or an assembler problem and it doesn't affects the compiler's functionality. Read the relevant section below. Congratulations, you've just successfully bootstrapped Free Pascal on AmigaOS4!
9898
9999## Assembler and Linker
100100
101101Free Pascal for AmigaOS4 uses **vlink** by Frank Wille as the default linker, when running natively on AmigaOS4. The cross-compilers still default to **GNU ld**. **vlink** is open source, and it is available [here](http://sun.hasenbraten.de/vlink). Binaries are available as part of the [vbcc compiler package](http://sun.hasenbraten.de/vbcc).
102102
103103You can change the linker back to **GNU ld** by adding *-XV-* argument when compiling. For cross compilers *-XV* argument enables vlink.
104104
105105### Linker problems
106106
107107The native GNU LD on AmigaOS4 has a problem, which prevents FPC's **make cycle** to succeed natively. To fulfill some requirements of the system, it pads sections in unstriped executables, but it does so using random memory data. This means the binaries will be different, depending on the memory state during compile time. This makes the final binary verification of **make cycle** to fail. Note that the resulting *ppcppc* binary is still fully functional. Note that the AmigaOS4 developers know about this problem, but they consider it "harmless". For us, it's a blocker. Also the AmigaOS4 port doesn't support striping with GNU LD currently, which is a missing feature on our side.
108108
109109### Assembler problems
110110
111111Some native GNU AS versions distributed in binary might have an issue, which causes the branch-prediction hint bits of some PowerPC branch instructions to change randomly. This causes no directly observable functional differences, but might cause a penalty hit with time critical code, and might cause FPC's own build process to fail (due to binary sanity checks). GNU AS 2.18 as distributed with Hyperion's SDK is not affected.
112112
113113## Preliminary information about language elements to support the port
114114
115115**BIG FAT WARNING!** All information below this line is preliminary, and subject to change without any further notice. OK, you've been warned.
116116
117117### Library interfaces and Syscalls
118118
119119Syscalls are used in AmigaOS4, to provide calls to libraries through OS4 interfaces. Syntax is proposed to be the following:
120120
121121``` pascal
122122var
123123 myLibBase: PLibrary;
124124
125125type
126126 TmyLibIface = record
127127 Data: TInterface;
128128
129129 Obtain: function(self as hidden): longword; SysCall;
130130 Release: function(self as hidden): longword; SysCall;
131131 Expunge: procedure(self as hidden); SysCall;
132132 Clone: function(self as hidden): POS4Interface; SysCall;
133133
134134 myCallFoo: function(self as hidden; a: longint; b: pointer): pointer; SysCall;
135135 myCallBar: procedure(self as hidden; c: pchar; d: byte); SysCall;
136136 end;
137137 PmyLibIface = ^TmyLibIface;
138138
139139var
140140 ImyLib: PmyLibIface;
141141begin
142142 // here the opening the library and interface, blah...
143143
144144 ImyLib^.myCallFoo(0,nil);
145145 ImyLib^.myCallBar('a',1);
146146
147147 // releasing stuff
148148end;
149149```
150150
151151The above example calls will pass pointer pointer to the interface in r3, pass the remaining arguments according to SysV ABI. Syscall is needed to enable the passing of the hidden argument, which is only supported for syscalls. A hidden argument can be any integer or pointer variable. They're not need to be specified in the actual calls in the code, but they're still passed to called function. On AmigaOS4, identifier "Self" has a special meaning, and means a pointer to the actual interface.
152152
153153An utility which helps creating a Pascal headers from interface definition files for existing libraries, similar to what IDLTool does for C language, would be highly recommended.
154154
155155## More information
156156
157157More information regarding Free Pascal and AmigaOS can be read on the [Free Pascal 4 Amiga wiki](http://fpcamigawiki.alb42.de). This wiki also contains links to (unofficial) nightly downloads and other (additional) information for AmigaOS.
158158
159159---
160160*From the Free Pascal wiki, page "AmigaOS", as it stood on 2020-07-21 after a change by Chain-Q, 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](/wiki-contact).*
161161Category: AmigaOS
162162Category: Operating Systems and Platforms

Back to history