AmigaOS

From Lazarus wiki
Revision as of 19:08, 14 April 2016 by Chain-Q (talk | contribs) (some more copy&paste and search&replace from elsewhere)
Jump to navigationJump to search

This page contains information about the AmigaOS4 on PowerPC port, which is in an early proof-of-concept, experimental stage. About classic Amiga (OS 3.x, Motorola 680x0) port, please see the 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.

The initial AmigaOS4 port was done by Karoly 'Chain-Q' Balogh, maintainer of MorphOS and classic Amiga port.

Identification

To identify AmigaOS4 exclusively during compile-time, use {$IFDEF AMIGAOS4}. To identify classic Amiga or AmigaOS4, use {$IFDEF AMIGA}. To identify any Amiga-like systems, 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.

Stack

On 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. You can also reduce the stack size, but note that AmigaOS4 won't allow stack sizes below 32 KiB.

Naming conventions

This section describes the differences between the official AmigaOS4 SDK, which is for C language, and the AmigaOS4-specific units in FPC RTL.

Constants

System constants are named exactly like in the AmigaOS4 SDK.

Structures and types

System 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:

 struct Task equals to TTask
 struct Task * equals to PTask

Threading

Threading is supported on Amiga-like systems since Free Pascal 3.0, using the AThreads unit. Read there for possible caveats and unsupported features. Please note that the threading feature on AmigaOS4 is compiled, but at this time it is entirely untested.

Linker problems

The 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.

The current VLink, as used on other Amiga-like platforms, has an issue which causes a crash while trying to link FPC-generated objects to AmigaOS4 executables. The author of VLink has been notified about this issue.

Preliminary information about language elements to support the port

BIG FAT WARNING! All information below this line is preliminary, and subject to change without any further notice. OK, you've been warned.

Library interfaces and Syscalls

Syscalls are used in AmigaOS4, to provide calls to libraries through OS4 interfaces. Syntax is proposed to be the following:

var
  myLibBase: PLibrary;
 
type
  TmyLibIface = record
    Data: TInterface;
 
    Obtain: function(self as hidden): longword; SysCall;
    Release: function(self as hidden): longword; SysCall;
    Expunge: procedure(self as hidden); SysCall;
    Clone: function(self as hidden): POS4Interface; SysCall;
     
    myCallFoo: function(self as hidden; a: longint; b: pointer): pointer; SysCall;
    myCallBar: procedure(self as hidden; c: pchar; d: byte); SysCall;
  end;
  PmyLibIface = ^TmyLibIface;
 
var
  ImyLib: PmyLibIface;
begin
  // here the opening the library and interface, blah...
  
  ImyLib^.myCallFoo(0,nil);
  ImyLib^.myCallBar('a',1);   

  // releasing stuff
end;

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.

An 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.