Sign in Join
Wiki copytemporary

AmigaOS: what changed

Revision 1 to 2. 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
2727` struct Task equals to TTask`\
2828` struct Task * equals to PTask`
2929
3030## Threading
3131
3232Threading is supported on Amiga-like systems since Free Pascal 3.0, using the [[AThreads]] unit. Read there for possible caveats and unsupported features.
3333
3434## Cross compiling
3535
3636While 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.
3737
3838### Cross compiling from Linux
3939
4040It'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.
4141
4242To build an AmigaOS4 cross-compiler, use the following steps:
4343
44441. 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.
45452. Check out FPC SVN trunk into a directory.
46463. Make sure the aforementioned cross-binutils are actually in the PATH.
47474. Go to the trunk's main directory and use the following command to build an FPC to AmigaOS4 cross-compiler running on Linux:
4848
4949``` bash
5050 make clean crossall crossinstall OS_TARGET=amiga CPU_TARGET=powerpc BINUTILSPREFIX=ppc-amigaos- INSTALL_PREFIX="<path/to/install>"
5151```
5252
5353If you've done everything right, you should find a working AmigaOS4 cross-compiler in the install path you've specified.
5454
5555Now, 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:
5656
5757`#IFDEF CPUPOWERPC`\
5858`-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET`\
5959`-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET/*`\
6060`#IFDEF AMIGAOS4`\
6161`-FD</path/to/amigaos4-cross-binutils>`\
6262`-XPppc-amigaos-`\
6363`#ENDIF`\
6464`#ENDIF`
6565
6666Optionally 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:
6767
6868`ppcrossppc -Tamiga <source.pas>`
6969
7070Copy the resulting executable to AmigaOS4, and that's it!
7171
7272### Bootstrapping a compiler from Linux
7373
7474To bootstrap a Free Pascal Compiler from Linux to AmigaOS4, first please complete the previous section.
7575
7676After you have a working cross compiler, go to the SVN **trunk/compiler** directory, and issue the following commands:
7777
7878``` bash
7979 make compiler OS_TARGET=amiga CPU_TARGET=powerpc FPC="<path/to/install>/lib/fpc/3.1.1/ppcrossppc"
8080```
8181
8282Copy 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:
8383
8484`set PATH=/SDK/Local/C`\
8585`gmake cycle FPC=/path/to/ppcppc`
8686
8787Please 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**.
8888
8989At 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!
9090
9191## Assembler and Linker
9292
9393Free 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).
9494
9595You can change the linker back to **GNU ld** by adding *-XV-* argument when compiling. For cross compilers *-XV* argument enables vlink.
9696
9797### Linker problems
9898
9999The 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.
100100
101101### Assembler problems
102102
103103Some 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.
104104
105105## Preliminary information about language elements to support the port
106106
107107**BIG FAT WARNING!** All information below this line is preliminary, and subject to change without any further notice. OK, you've been warned.
108108
109109### Library interfaces and Syscalls
110110
111111Syscalls are used in AmigaOS4, to provide calls to libraries through OS4 interfaces. Syntax is proposed to be the following:
112112
113113``` pascal
114114var
115115 myLibBase: PLibrary;
116116
117117type
118118 TmyLibIface = record
119119 Data: TInterface;
120120
121121 Obtain: function(self as hidden): longword; SysCall;
122122 Release: function(self as hidden): longword; SysCall;
123123 Expunge: procedure(self as hidden); SysCall;
124124 Clone: function(self as hidden): POS4Interface; SysCall;
125125
126126 myCallFoo: function(self as hidden; a: longint; b: pointer): pointer; SysCall;
127127 myCallBar: procedure(self as hidden; c: pchar; d: byte); SysCall;
128128 end;
129129 PmyLibIface = ^TmyLibIface;
130130
131131var
132132 ImyLib: PmyLibIface;
133133begin
134134 // here the opening the library and interface, blah...
135135
136136 ImyLib^.myCallFoo(0,nil);
137137 ImyLib^.myCallBar('a',1);
138138
139139 // releasing stuff
140140end;
141141```
142142
143-The above example calls will pass pointer pointer to the interface in <b>r3</b>, 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.
143+The 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.
144144
145145An 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.
146146
147147## More information
148148
149149More 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.
150150
151151---
152152*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).*
153153Category: AmigaOS
154154Category: Operating Systems and Platforms

Back to history