OK, i think i got the compiler to support AXRT ABIv11 syscalls for target Linux.
However, things did not go entirely as expected (probably my wrongdoing).
Given the following Free Pascal source-code (i cleaned up the empty space/comments a little before posting so the linenumber might be a bit off).
program linuxaxrttest;
{$MODE OBJFPC}{$H+}
uses
ctypes, dynlibs;
const
n_axrt = './libaxrt-4.0.so';
RT_STARTUP = 3;
RT_ABI = 4;
RT_VERSION = 41;
RT_REVISION = 1;
RT_VER = ( (RT_STARTUP shl 28) or (RT_ABI shl 24) or (RT_VERSION shl or (RT_REVISION shl 0) );
var
h_axrt : TLibHandle = 0;
memlocation : pointer;
funname : string;
__set_runtime_env : procedure(x: cint); cdecl;
__kick_start : procedure(p: pointer; x: cint); cdecl;
var
AOS_ExecBase : Pointer;
IntuitionBase: Pointer;
type
// exec.library functionality
ULONG = LongWord;
STRPTR = pchar;
PLibrary = Pointer;
function AvailMem(Requirements: ULONG): ULONG; syscall AOS_ExecBase 36;
function OpenLibrary(const LibName: STRPTR; Version: ULONG): PLibrary; syscall AOS_ExecBase 92;
procedure CloseLibrary(Library_: PLibrary); syscall AOS_ExecBase 69;
function __startup_entry(argstr: pchar; argsize: longint; SysBase: pointer): cint; cdecl;
begin
Result := 0;
AOS_ExecBase := SysBase;
writeln('hello axrt from fpc - still linux');
writeln('before AvailMem');
writeln('AvailMem(0) = ', Availmem(0));
writeln('after AvailMem');
writeln('are we still alive ?');
writeln('before AvailMem');
writeln('AvailMem(0) = ', Availmem(0));
writeln('after AvailMem');
writeln('still living ?');
// open intuition library
writeln('attempt to open library');
IntuitionBase := OpenLibrary('intuition.library', 0);
writeln('Open Library ', HexStr(IntuitionBase));
// close intuition library
writeln('attempt to close library');
if assigned(IntuitionBase) then CloseLibrary(IntuitionBase);
end;
begin
writeln('begin');
// load dynlib libaxrt
h_axrt := LoadLibrary(n_axrt);
// if libaxrt loaded successfully
if h_axrt <> NilHandle then
begin
writeln('loaded ax runtime library');
// #######################
writeln('retrieving libaxrt function pointers');
funname := '__set_runtime_env';
memlocation := GetProcedureAddress(h_axrt, funname);
if assigned(memlocation) then pointer(__set_runtime_env) := memlocation else writeln('unable to locate function ' + funname);
funname := '__kick_start';
memlocation := GetProcedureAddress(h_axrt, funname);
if assigned(memlocation) then pointer(__kick_start) := memlocation else writeln('unable to locate function ' + funname);
// assume everything went ok.
writeln('set runtime environment');
__set_runtime_env(RT_VER);
writeln('kick start startup entry');
__kick_start(@__startup_entry, RT_VER);
// #######################
if unloadlibrary(h_axrt)
then writeln('unloaded ax runtime library')
else writeln('failed unloading ax runtime library');
end
else writeln('failed to load ax runtime library');
writeln('end');
end.
Which translates into the following assembler source-code (debug enabled, again note that the line numbers might differ a little):
Assembler source code attached inside zipfile because the board is limited to 20000 characters per post).
And then running it with AXRT, the output from the terminal becomes:
begin
loaded ax runtime library
retrieving libaxrt function pointers
set runtime environment
<<INFO>>: AxRT 41.1
<<INFO>>: Using absolute paths.
<<INFO>>: AXRT_ROOT environment variable set
<<INFO>>: RUNTIME_ROOT: /home/magorium/bin/AXRT_411/
<<INFO>>: AXRTSYS : ROOT:home/magorium/bin/AXRT_411/
<<INFO>>: USERSYS : ROOT:home/magorium/.axrt/
kick start startup entry
libaxrt-4.0.so: cannot open shared object file: No such file or directory
<<INFO>>: CURRENT_DIR : ROOT:home/magorium/bin/AXRT_411/Work/fpc/
<<INFO>>: PROGRAM DIR : ROOT:home/magorium/bin/AXRT_411/Work/fpc/
<<INFO>>: PROGRAM NAME: linuxaxrttest
hello axrt from fpc - still linux
before AvailMem
Runtime error 216 at $000000000040121D
$000000000040121D __STARTUP_ENTRY, line 60 of linuxaxrttest.pas
$00007FF2C33DDB91 line 225 of /media/ramdisk/repo411/AROS/arch/all-runtime/axrt/startup/startup_lib.c
$00007FF2C224C693 line 85 of /media/ramdisk/repo411/AROS/rom/dos/./boot.c
$00007FF2C222FBFD line 134 of /media/ramdisk/repo411/AROS/rom/dos/./exit.c
$00007FF2C222A384 line 739 of /media/ramdisk/repo411/AROS/rom/dos/./createnewproc.c
$00007FF2C29ADFEB line 308 of /media/ramdisk/repo411/AROS/rom/exec/./newaddtask.c
$00007FF2C33A0FA3
AvailMem(0) =
running it with gdb shows:
Starting program: /home/magorium/bin/AXRT_411/Work/fpc/linuxaxrttest
begin
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
loaded ax runtime library
retrieving libaxrt function pointers
set runtime environment
<<INFO>>: AxRT 41.1
<<INFO>>: Using absolute paths.
<<INFO>>: AXRT_ROOT environment variable set
<<INFO>>: RUNTIME_ROOT: /home/magorium/bin/AXRT_411/
<<INFO>>: AXRTSYS : ROOT:home/magorium/bin/AXRT_411/
<<INFO>>: USERSYS : ROOT:home/magorium/.axrt/
kick start startup entry
[New Thread 0x7ffff7bc1700 (LWP 30833)]
[New Thread 0x7ffff6b3d700 (LWP 30834)]
[New Thread 0x7ffff633c700 (LWP 30835)]
[New Thread 0x7ffff5b3b700 (LWP 30836)]
[New Thread 0x7ffff533a700 (LWP 30837)]
[New Thread 0x7ffff4b39700 (LWP 30838)]
[New Thread 0x7fffe7fff700 (LWP 30839)]
[New Thread 0x7fffe71e0700 (LWP 30840)]
[New Thread 0x7fffe651a700 (LWP 30841)]
[New Thread 0x7fffe5d19700 (LWP 30842)]
[New Thread 0x7fffe5518700 (LWP 30843)]
[New Thread 0x7fffe4d17700 (LWP 30844)]
[Thread 0x7ffff7bc1700 (LWP 30833) exited]
libaxrt-4.0.so: cannot open shared object file: No such file or directory
[New Thread 0x7ffff7bc1700 (LWP 30845)]
[Thread 0x7fffe5d19700 (LWP 30842) exited]
<<INFO>>: CURRENT_DIR : ROOT:home/magorium/bin/AXRT_411/Work/fpc/
<<INFO>>: PROGRAM DIR : ROOT:home/magorium/bin/AXRT_411/Work/fpc/
<<INFO>>: PROGRAM NAME: linuxaxrttest
[New Thread 0x7fffcbfff700 (LWP 30846)]
hello axrt from fpc - still linux
before AvailMem
Thread 14 "New Process" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7bc1700 (LWP 30845)]
0x000000000040121d in __STARTUP_ENTRY (ARGSTR=0x0, ARGSIZE=0, SYSBASE=0x7ffff0001780)
at linuxaxrttest.pas:60
60 writeln('AvailMem(0) = ', Availmem(0));
The gdb backtrace:
#0 0x000000000040121d in __STARTUP_ENTRY (ARGSTR=0x0, ARGSIZE=0, SYSBASE=0x7ffff0001780)
at linuxaxrttest.pas:60
#1 0x00007ffff7dcfb91 in RunProgram (sysbase=0x7ffff0001780, _m=0x7fffffffced0)
at /media/ramdisk/repo411/AROS/arch/all-runtime/axrt/startup/startup_lib.c:225
#2 0x00007ffff6c3e693 in __program_trampoline () at /media/ramdisk/repo411/AROS/rom/dos/./boot.c:85
#3 0x00007ffff6c21bfd in CallEntry (argptr=0x0, argsize=0,
entry=0x7ffff6c3e58e <__program_trampoline>, me=0x7fffcc017aa0)
at /media/ramdisk/repo411/AROS/rom/dos/./exit.c:134
#4 0x00007ffff6c1c384 in DosEntry () at /media/ramdisk/repo411/AROS/rom/dos/./createnewproc.c:739
#5 0x00007ffff739ffeb in __pthread_trampoline (ptr=0x7fffcc016c70)
at /media/ramdisk/repo411/AROS/rom/exec/./newaddtask.c:308
#6 0x00007ffff7d92fa3 in start_thread (arg=<optimized out>) at pthread_create.c:486
#7 0x00007ffff7edd4cf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
See also attached zip file which includes all the relevant information.
posted in stages because the stupid board software removes all perfectly fine and accepted text whenever you post a single line that isn't supposedly valid so then need to start your whole post all over again, in the hopes you are able to identify that one single line that is suppose to be invalid.
If everything went ok then this post is done now.
edit: I have looked at the asm code a little longer but i am still unable to see the (probably) obvious. I also made a better test, not combining pascal rtl calls with axrt ABI calls and it crashes at assigning the return-value from a syscall to availmem to a ULONG variable (and not writing the result value directly). A.t.m. i have no idea how to continue forward from this point. Do you perhaps have any idea deadw00d (or someone else for that matter).