Sign in Join
Wiki copytemporary

AmigaOS: what changed

Revision 2 to 3. 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-` struct Task equals to TTask`\
28-` struct Task * equals to PTask`
27+```
28+ struct Task equals to TTask
29+ struct Task * equals to PTask
30+```
2931
3032## Threading
3133
3234Threading is supported on Amiga-like systems since Free Pascal 3.0, using the [[AThreads]] unit. Read there for possible caveats and unsupported features.
3335
3436## Cross compiling
3537
3638While 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.
3739
3840### Cross compiling from Linux
3941
4042It'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.
4143
4244To build an AmigaOS4 cross-compiler, use the following steps:
4345
44461. 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.
45472. Check out FPC SVN trunk into a directory.
46483. Make sure the aforementioned cross-binutils are actually in the PATH.
47494. Go to the trunk's main directory and use the following command to build an FPC to AmigaOS4 cross-compiler running on Linux:
4850
4951``` bash
5052 make clean crossall crossinstall OS_TARGET=amiga CPU_TARGET=powerpc BINUTILSPREFIX=ppc-amigaos- INSTALL_PREFIX="<path/to/install>"
5153```
5254
5355If you've done everything right, you should find a working AmigaOS4 cross-compiler in the install path you've specified.
5456
5557Now, 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:
5658
57-`#IFDEF CPUPOWERPC`\
58-`-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET`\
59-`-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET/*`\
60-`#IFDEF AMIGAOS4`\
61-`-FD</path/to/amigaos4-cross-binutils>`\
62-`-XPppc-amigaos-`\
63-`#ENDIF`\
64-`#ENDIF`
59+```
60+#IFDEF CPUPOWERPC
61+-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET
62+-Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET/*
63+#IFDEF AMIGAOS4
64+-FD</path/to/amigaos4-cross-binutils>
65+-XPppc-amigaos-
66+#ENDIF
67+#ENDIF
68+```
6569
6670Optionally 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:
6771
68-`ppcrossppc -Tamiga <source.pas>`
72+```
73+ppcrossppc -Tamiga <source.pas>
74+```
6975
7076Copy the resulting executable to AmigaOS4, and that's it!
7177
7278### Bootstrapping a compiler from Linux
7379
7480To bootstrap a Free Pascal Compiler from Linux to AmigaOS4, first please complete the previous section.
7581
7682After you have a working cross compiler, go to the SVN **trunk/compiler** directory, and issue the following commands:
7783
7884``` bash
7985 make compiler OS_TARGET=amiga CPU_TARGET=powerpc FPC="<path/to/install>/lib/fpc/3.1.1/ppcrossppc"
8086```
8187
8288Copy 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:
8389
84-`set PATH=/SDK/Local/C`\
85-`gmake cycle FPC=/path/to/ppcppc`
90+```
91+set PATH=/SDK/Local/C
92+gmake cycle FPC=/path/to/ppcppc
93+```
8694
8795Please 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**.
8896
8997At 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!
9098
9199## Assembler and Linker
92100
93101Free 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).
94102
95103You can change the linker back to **GNU ld** by adding *-XV-* argument when compiling. For cross compilers *-XV* argument enables vlink.
96104
97105### Linker problems
98106
99107The 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.
100108
101109### Assembler problems
102110
103111Some 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.
104112
105113## Preliminary information about language elements to support the port
106114
107115**BIG FAT WARNING!** All information below this line is preliminary, and subject to change without any further notice. OK, you've been warned.
108116
109117### Library interfaces and Syscalls
110118
111119Syscalls are used in AmigaOS4, to provide calls to libraries through OS4 interfaces. Syntax is proposed to be the following:
112120
113121``` pascal
114122var
115123 myLibBase: PLibrary;
116124
117125type
118126 TmyLibIface = record
119127 Data: TInterface;
120128
121129 Obtain: function(self as hidden): longword; SysCall;
122130 Release: function(self as hidden): longword; SysCall;
123131 Expunge: procedure(self as hidden); SysCall;
124132 Clone: function(self as hidden): POS4Interface; SysCall;
125133
126134 myCallFoo: function(self as hidden; a: longint; b: pointer): pointer; SysCall;
127135 myCallBar: procedure(self as hidden; c: pchar; d: byte); SysCall;
128136 end;
129137 PmyLibIface = ^TmyLibIface;
130138
131139var
132140 ImyLib: PmyLibIface;
133141begin
134142 // here the opening the library and interface, blah...
135143
136144 ImyLib^.myCallFoo(0,nil);
137145 ImyLib^.myCallBar('a',1);
138146
139147 // releasing stuff
140148end;
141149```
142150
143151The 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.
144152
145153An 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.
146154
147155## More information
148156
149157More 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.
150158
151159---
152160*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).*
153161Category: AmigaOS
154162Category: Operating Systems and Platforms

Back to history