Browse Source

+ RTL for AIX

git-svn-id: trunk@20786 -
Jonas Maebe 13 years ago
parent
commit
8d8fc0fdee

+ 23 - 0
.gitattributes

@@ -7073,6 +7073,29 @@ rtl/COPYING.txt svneol=native#text/plain
 rtl/Makefile svneol=native#text/plain
 rtl/Makefile svneol=native#text/plain
 rtl/Makefile.fpc svneol=native#text/plain
 rtl/Makefile.fpc svneol=native#text/plain
 rtl/README.txt svneol=native#text/plain
 rtl/README.txt svneol=native#text/plain
+rtl/aix/Makefile.fpc svneol=native#text/plain
+rtl/aix/clocale.inc svneol=native#text/plain
+rtl/aix/dlaix.inc svneol=native#text/plain
+rtl/aix/errno.inc svneol=native#text/plain
+rtl/aix/errnostr.inc svneol=native#text/plain
+rtl/aix/osdefs.inc svneol=native#text/plain
+rtl/aix/osmacro.inc svneol=native#text/plain
+rtl/aix/ostypes.inc svneol=native#text/plain
+rtl/aix/pthread.inc svneol=native#text/plain
+rtl/aix/ptypes.inc svneol=native#text/plain
+rtl/aix/sighnd.inc svneol=native#text/plain
+rtl/aix/sighndh.inc svneol=native#text/plain
+rtl/aix/signal.inc svneol=native#text/plain
+rtl/aix/suuid.inc svneol=native#text/plain
+rtl/aix/sysos.inc svneol=native#text/plain
+rtl/aix/sysosh.inc svneol=native#text/plain
+rtl/aix/system.pp svneol=native#text/plain
+rtl/aix/termio.pp svneol=native#text/plain
+rtl/aix/termios.inc svneol=native#text/plain
+rtl/aix/termiosproc.inc svneol=native#text/plain
+rtl/aix/unxconst.inc svneol=native#text/plain
+rtl/aix/unxfunc.inc svneol=native#text/plain
+rtl/aix/unxsockh.inc svneol=native#text/plain
 rtl/amiga/Makefile svneol=native#text/plain
 rtl/amiga/Makefile svneol=native#text/plain
 rtl/amiga/Makefile.fpc svneol=native#text/plain
 rtl/amiga/Makefile.fpc svneol=native#text/plain
 rtl/amiga/classes.pp svneol=native#text/plain
 rtl/amiga/classes.pp svneol=native#text/plain

+ 310 - 0
rtl/aix/Makefile.fpc

@@ -0,0 +1,310 @@
+#
+#   Makefile.fpc for Free Pascal AIX RTL
+#
+
+[package]
+main=rtl
+
+[target]
+loaders=
+units=$(SYSTEMUNIT) unixtype ctypes strings objpas iso7185 macpas \
+      heaptrc lineinfo \
+      baseunix unixutil \
+      termio unix initc cmem \
+      crt printer \
+      sysutils typinfo math fgl classes matrix varutils \
+      charset ucomplex getopts \
+      errors sockets \
+      # ipc serial
+      terminfo dl dynlibs \
+      video mouse \
+      keyboard variants types dateutils sysconst \
+      strutils fmtbcd rtlconsts cthreads \
+      convutils stdconvs \
+      dos objects \
+      cwstring fpintres clocale $(CPU_UNITS)
+
+implicitunits=exeinfo
+
+rsts=math varutils typinfo classes variants dateutils sysconst rtlconst stdconvs
+
+[require]
+nortl=y
+
+[install]
+fpcpackage=y
+
+[default]
+fpcdir=../..
+target=aix
+
+[compiler]
+includedir=$(INC) $(PROCINC) $(UNIXINC) # $(OSPROCINC)
+sourcedir=$(INC) $(PROCINC) $(UNIXINC) $(COMMON)
+
+
+[lib]
+libname=libfprtl.so
+libversion=2.0.0
+libunits=$(SYSTEMUNIT) objpas strings \
+      unix  \
+      dos crt objects printer \
+      sysutils typinfo math \
+      $(CPU_UNITS) getopts heaptrc \
+      errors sockets ipc
+
+[prerules]
+RTL=..
+INC=$(RTL)/inc
+COMMON=$(RTL)/common
+PROCINC=$(RTL)/$(CPU_TARGET)
+OSPROCINC=$(RTL)/aix/$(CPU_TARGET)
+UNIXINC=$(RTL)/unix
+UNITPREFIX=rtl
+CPU_UNITS=
+
+SYSTEMUNIT=system
+
+
+ifeq ($(ARCH),i386)
+CPU_UNITS=cpu mmx
+endif
+
+ifeq ($(ARCH),x86_64)
+CPU_UNITS=cpu
+SYSINIT_UNITS=   # si_prc si_c si_dll
+endif
+
+
+# Use new feature from 1.0.5 version
+# that generates release PPU files
+# which will not be recompiled
+ifdef RELEASE
+override FPCOPT+=-Ur
+endif
+
+# AIX requires libc, no syscalls, no mouse
+override FPCOPT+=-dFPC_USE_LIBC -dNOMOUSE
+
+# Paths
+OBJPASDIR=$(RTL)/objpas
+GRAPHDIR=$(INC)/graph
+
+# Use new graph unit ?
+# NEWGRAPH=YES
+# Use LibGGI ?
+# Use
+#
+ifndef USELIBGGI
+USELIBGGI=NO
+endif
+
+
+[rules]
+.NOTPARALLEL:
+# Get the system independent include file names.
+# This will set the following variables :
+# SYSINCNAMES
+include $(INC)/makefile.inc
+SYSINCDEPS=$(addprefix $(INC)/,$(SYSINCNAMES))
+
+# Get the processor dependent include file names.
+# This will set the following variables :
+# CPUINCNAMES
+include $(PROCINC)/makefile.cpu
+SYSCPUDEPS=$(addprefix $(PROCINC)/,$(CPUINCNAMES))
+
+# Put system unit dependencies together.
+SYSDEPS=$(SYSINCDEPS) $(SYSCPUDEPS)
+
+
+#
+# System Units (System, Objpas, Strings)
+#
+
+$(SYSTEMUNIT)$(PPUEXT) : $(SYSTEMUNIT).pp $(SYSDEPS)
+        $(COMPILER) -Us -Sg $(SYSTEMUNIT).pp
+
+objpas$(PPUEXT): $(OBJPASDIR)/objpas.pp $(INC)/except.inc $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) -I$(OBJPASDIR) $(OBJPASDIR)/objpas.pp
+
+
+dateutils$(PPUEXT): objpas$(PPUEXT) sysutils$(PPUEXT) math$(PPUEXT) types$(PPUEXT) sysconst$(PPUEXT) $(OBJPASDIR)/dateutils.pp baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) -I$(OBJPASDIR) $(OBJPASDIR)/dateutils.pp
+
+
+strings$(PPUEXT) : $(INC)/strings.pp $(INC)/stringsi.inc \
+                   $(PROCINC)/strings.inc $(PROCINC)/stringss.inc \
+                   $(SYSTEMUNIT)$(PPUEXT)
+
+#
+# System Dependent Units
+#
+
+baseunix$(PPUEXT) : unixtype$(PPUEXT) errno.inc ptypes.inc $(UNIXINC)/ctypes.inc \
+  signal.inc $(UNIXINC)/bunxh.inc \
+  ostypes.inc osmacro.inc $(UNIXINC)/gensigset.inc \
+  $(UNIXINC)/genfuncs.inc $(SYSTEMUNIT)$(PPUEXT)
+
+unixtype$(PPUEXT) : $(UNIXINC)/unixtype.pp ptypes.inc $(UNIXINC)/ctypes.inc $(SYSTEMUNIT)$(PPUEXT)
+
+unix$(PPUEXT) : unixtype$(PPUEXT) baseunix$(PPUEXT) unixutil$(PPUEXT) strings$(PPUEXT) $(UNIXINC)/unix.pp strings$(PPUEXT) $(INC)/textrec.inc $(INC)/filerec.inc \
+                 unxconst.inc $(UNIXINC)/timezone.inc \
+                 unxfunc.inc baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+unixutil$(PPUEXT) : $(SYSTEMUNIT)$(PPUEXT)
+
+
+#
+# TP7 Compatible RTL Units
+#
+
+dos$(PPUEXT) : strings$(PPUEXT) unix$(PPUEXT) $(UNIXINC)/dos.pp $(INC)/filerec.inc $(INC)/textrec.inc strings$(PPUEXT) \
+               unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+crt$(PPUEXT) : unix$(PPUEXT) termio$(PPUEXT) $(UNIXINC)/crt.pp $(INC)/textrec.inc unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+objects$(PPUEXT) : dos$(PPUEXT) $(INC)/objects.pp $(SYSTEMUNIT)$(PPUEXT)
+
+printer$(PPUEXT) : unix$(PPUEXT) strings$(PPUEXT) baseunix$(PPUEXT) $(UNIXINC)/printer.pp $(INC)/textrec.inc unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+#
+# Graph
+#
+
+#
+# Delphi Compatible Units
+#
+
+sysutils$(PPUEXT) : $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \
+                    objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) sysconst$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) -Fi$(OBJPASDIR)/sysutils $(UNIXINC)/sysutils.pp
+
+classes$(PPUEXT) : $(UNIXINC)/classes.pp $(wildcard $(OBJPASDIR)/classes/*.inc) \
+                   sysutils$(PPUEXT) typinfo$(PPUEXT) rtlconsts$(PPUEXT) types$(PPUEXT) \
+		   $(SYSTEMUNIT)$(PPUEXT) fgl$(PPUEXT)
+        $(COMPILER) -Fi$(OBJPASDIR)/classes $(UNIXINC)/classes.pp
+
+fgl$(PPUEXT) : $(OBJPASDIR)/fgl.pp objpas$(PPUEXT) types$(PPUEXT) system$(PPUEXT) sysutils$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/fgl.pp
+
+typinfo$(PPUEXT): $(OBJPASDIR)/typinfo.pp objpas$(PPUEXT) sysutils$(PPUEXT) rtlconsts$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) -Sg $(OBJPASDIR)/typinfo.pp
+
+math$(PPUEXT): $(OBJPASDIR)/math.pp objpas$(PPUEXT) sysutils$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/math.pp
+
+gettext$(PPUEXT): $(OBJPASDIR)/gettext.pp objpas$(PPUEXT) sysutils$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/gettext.pp
+
+varutils$(PPUEXT) : $(OBJPASDIR)/cvarutil.inc $(OBJPASDIR)/varutils.inc \
+                    $(OBJPASDIR)/varutilh.inc varutils.pp sysutils$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/varutils.pp
+
+variants$(PPUEXT) : $(INC)/variants.pp sysutils$(PPUEXT) sysconst$(PPUEXT) varutils$(PPUEXT)\
+		    typinfo$(PPUEXT) rtlconsts$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) -Fi$(INC) $(INC)/variants.pp
+
+fmtbcd$(PPUEXT) : $(OBJPASDIR)/fmtbcd.pp objpas$(PPUEXT) sysutils$(PPUEXT) variants$(PPUEXT) classes$(PPUEXT) system$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/fmtbcd.pp
+
+types$(PPUEXT) : $(OBJPASDIR)/types.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/types.pp
+
+sysconst$(PPUEXT) : $(OBJPASDIR)/sysconst.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/sysconst.pp
+
+rtlconsts$(PPUEXT) : $(OBJPASDIR)/rtlconsts.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/rtlconsts.pp
+
+strutils$(PPUEXT) : $(OBJPASDIR)/strutils.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) \
+                    sysutils$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/strutils.pp
+
+convutils$(PPUEXT) : $(OBJPASDIR)/convutils.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) \
+                    sysutils$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/convutils.pp
+
+stdconvs$(PPUEXT) : $(OBJPASDIR)/stdconvs.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) \
+                    sysutils$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/stdconvs.pp
+
+
+#
+# Mac Pascal Model
+#
+
+macpas$(PPUEXT) : $(INC)/macpas.pp objpas$(PPUEXT) math$(PPUEXT)
+        $(COMPILER) $(INC)/macpas.pp $(REDIR)
+
+#
+# Other system-independent RTL Units
+#
+
+video$(PPUEXT) : $(SYSTEMUNIT)$(PPUEXT) $(INC)/video.inc $(INC)/videoh.inc $(UNIXINC)/video.pp \
+	baseunix$(PPUEXT) strings$(PPUEXT) terminfo$(PPUEXT) termio$(PPUEXT)
+
+keyboard$(PPUEXT) : $(SYSTEMUNIT)$(PPUEXT) $(INC)/keyboard.inc $(INC)/keybrdh.inc $(UNIXINC)/keyboard.pp \
+	strings$(PPUEXT) terminfo$(PPUEXT) termio$(PPUEXT) baseunix$(PPUEXT) mouse$(PPUEXT)
+
+mouse$(PPUEXT) : $(UNIXINC)/mouse.pp $(SYSTEMUNIT)$(PPUEXT) baseunix$(PPUEXT) video$(PPUEXT)
+
+matrix$(PPUEXT) : $(INC)/matrix.pp $(SYSTEMUNIT)$(PPUEXT)
+
+ifeq ($(ARCH),x86_64)
+cpu$(PPUEXT) : $(PROCINC)/cpu.pp $(SYSTEMUNIT)$(PPUEXT) sysutils$(PPUEXT)
+else
+cpu$(PPUEXT) : $(PROCINC)/cpu.pp $(SYSTEMUNIT)$(PPUEXT)
+endif
+
+mmx$(PPUEXT) : $(PROCINC)/mmx.pp cpu$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+getopts$(PPUEXT) : $(INC)/getopts.pp $(SYSTEMUNIT)$(PPUEXT)
+
+heaptrc$(PPUEXT) : $(INC)/heaptrc.pp $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) -Sg $(INC)/heaptrc.pp
+
+lineinfo$(PPUEXT) : $(INC)/lineinfo.pp $(SYSTEMUNIT)$(PPUEXT) strings$(PPUEXT)
+
+lnfodwrf$(PPUEXT) : $(INC)/lnfodwrf.pp $(SYSTEMUNIT)$(PPUEXT)
+
+charset$(PPUEXT) : $(INC)/charset.pp objpas$(PPUEXT)
+
+ucomplex$(PPUEXT) : $(INC)/ucomplex.pp math$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) math$(PPUEXT)
+
+#
+# Other system-dependent RTL Units
+#
+
+sockets$(PPUEXT) : sockets.pp $(INC)/textrec.inc $(INC)/filerec.inc \
+                   unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+errors$(PPUEXT) : errors.pp strings$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+dynlibs$(PPUEXT) : $(INC)/dynlibs.pas $(UNIXINC)/dynlibs.inc dl$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+ipc$(PPUEXT) : ipc.pp unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+termio$(PPUEXT) : termio.pp unixtype$(PPUEXT) baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+terminfo$(PPUEXT) : terminfo.pp unix$(PPUEXT)
+
+callspec$(PPUEXT) : $(INC)/callspec.pp $(SYSTEMUNIT)$(PPUEXT)
+
+cmem$(PPUEXT) : $(INC)/cmem.pp $(SYSTEMUNIT)$(PPUEXT)
+
+cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp sysutils$(PPUEXT) baseunix$(PPUEXT) unixtype$(PPUEXT) unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+
+cwstring$(PPUEXT) : $(UNIXINC)/cwstring.pp $(SYSTEMUNIT)$(PPUEXT) sysutils$(PPUEXT) baseunix$(PPUEXT) unix$(PPUEXT) unixtype$(PPUEXT) ctypes$(PPUEXT) dynlibs$(PPUEXT)
+
+gpm$(PPUEXT): gpm.pp unix$(PPUEXT) baseunix$(PPUEXT) sockets$(PPUEXT)
+
+ctypes$(PPUEXT) :  $(INC)/ctypes.pp $(SYSTEMUNIT)$(PPUEXT) unixtype$(PPUEXT)
+
+fpcylix$(PPUEXT) :  fpcylix.pp $(SYSTEMUNIT)$(PPUEXT) dynlibs$(PPUEXT) objpas$(PPUEXT)
+
+dl$(PPUEXT) : $(SYSTEMUNIT)$(PPUEXT)
+
+initc$(PPUEXT) : $(SYSTEMUNIT)$(PPUEXT)
+
+console$(PPUEXT) : baseunix$(PPUEXT) termio$(PPUEXT)

+ 136 - 0
rtl/aix/clocale.inc

@@ -0,0 +1,136 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2008 by the Free Pascal development team.
+
+    Init rtl formating variables based on BSD like libc locales
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ **********************************************************************}
+
+{ Initial FreeBSD Implementation by Marco van de Voort.
+  Crosschecked with OS X 10.4/ppc headers.
+  To some symbols leading underscores were added. If these values are
+   ever exposed in an interface this has to be reevaluated.
+}
+
+{$IFDEF FPC}
+{$PACKRECORDS C}
+{$ENDIF}
+
+  __LC_ALL          = -1;
+  __LC_COLLATE      = 0;
+  __LC_CTYPE        = 1;
+  __LC_MONETARY     = 2;
+  __LC_NUMERIC      = 3;
+  __LC_TIME         = 4;
+  __LC_MESSAGES     = 5;
+  _LC_LAST         = 6;              { marks end }
+
+
+Type
+     lconv = record
+          decimal_point     : pchar;
+          thousands_sep     : pchar;
+          grouping          : pchar;
+          int_curr_symbol   : pchar;
+          currency_symbol   : pchar;
+          mon_decimal_point : pchar;
+          mon_thousands_sep : pchar;
+          mon_grouping      : pchar;
+          positive_sign     : pchar;
+          negative_sign     : pchar;
+          int_frac_digits   : char;
+          frac_digits       : char;
+          p_cs_precedes     : char;
+          p_sep_by_space    : char;
+          n_cs_precedes     : char;
+          n_sep_by_space    : char;
+          p_sign_posn       : char;
+          n_sign_posn       : char;
+          left_parenthesis  : char;
+          right_parenthesis : char;
+          int_p_cs_precedes : char;
+          int_p_sep_by_space: char;
+          int_n_cs_precedes : char;
+          int_n_sep_by_space: char;
+          int_p_sign_posn   : char;
+          int_n_sign_posn   : char;
+       end;
+     Tlconv = lconv;
+     plconv = ^lconv;
+
+Const
+        CODESET         = 49;     { codeset name }
+        D_T_FMT         = 1;     { string for formatting date and time }
+        D_FMT           = 2;     { date format string }
+        T_FMT           = 3;     { time format string }
+        T_FMT_AMPM      = 55;    { a.m. or p.m. time formatting string }
+        AM_STR          = 4;     { Ante Meridian affix }
+        PM_STR          = 5;     { Post Meridian affix }
+
+{ week day names }
+        DAY_1           = 13;
+        DAY_2           = 14;
+        DAY_3           = 15;
+        DAY_4           = 16;
+        DAY_5           = 17;
+        DAY_6           = 18;
+        DAY_7           = 19;
+
+{ abbreviated week day names }
+        ABDAY_1         = 6;
+        ABDAY_2         = 7;
+        ABDAY_3         = 8;
+        ABDAY_4         = 9;
+        ABDAY_5         = 10;
+        ABDAY_6         = 11;
+        ABDAY_7         = 22;
+
+{ month names }
+        MON_1           = 32;
+        MON_2           = 33;
+        MON_3           = 34;
+        MON_4           = 35;
+        MON_5           = 36;
+        MON_6           = 37;
+        MON_7           = 38;
+        MON_8           = 39;
+        MON_9           = 40;
+        MON_10          = 41;
+        MON_11          = 42;
+        MON_12          = 43;
+
+{ abbreviated month names }
+        ABMON_1         = 20;
+        ABMON_2         = 21;
+        ABMON_3         = 22;
+        ABMON_4         = 23;
+        ABMON_5         = 24;
+        ABMON_6         = 25;
+        ABMON_7         = 26;
+        ABMON_8         = 27;
+        ABMON_9         = 28;
+        ABMON_10        = 29;
+        ABMON_11        = 30;
+        ABMON_12        = 31;
+                        
+        ERA             = 56;      { era description segments }
+        ERA_D_FMT       = 57;      { era date format string }
+        ERA_D_T_FMT     = 58;      { era date and time format string }
+        ERA_T_FMT       = 59;      { era time format string }
+        ALT_DIGITS      = 60;      { alternative symbols for digits }
+        RADIXCHAR       = 44;      { radix char }
+        THOUSEP         = 45;      { separator for thousands }
+
+        YESEXPR         = 61;      { affirmative response expression }
+        NOEXPR          = 62;      { negative response expression }
+        YESSTR          = 46;      { affirmative response for yes/no queries }
+        NOSTR           = 47;      { negative response for yes/no queries }
+        CRNCYSTR        = 48;      { currency symbol }
+
+function localeconv:plconv; cdecl; external clib name 'localeconv';

+ 101 - 0
rtl/aix/dlaix.inc

@@ -0,0 +1,101 @@
+
+
+{ aix 5.3 doesn't have dladdr -> own implementation (from
+  http://root.cern.ch/drupal/content/aix-and-dladdr }
+
+
+  const
+    L_GETINFO = 2;
+
+  type
+    pld_info = ^ld_info;
+    ld_info = record
+      ldinfo_next: cuint;
+{$ifndef cpu64}
+      ldinfo_flags: cuint;
+{$endif}
+      _file: record
+        case byte of
+          0: (_ldinfo_fd: cint);
+          1: (_ldinfo_fp: pointer);
+          2: (_core_offset: ptrint);
+      end;
+      ldinfo_textorg: pointer;
+      ldinfo_textsize: ptrint;
+      ldinfo_dataorg: pointer;
+      ldinfo_datasize: ptrint;
+      ldinfo_filename: pchar;
+    end;
+
+  function loadquery(__lflags: cint; __buffer: pointer; __length: cuint): longint; cdecl; varargs; external;
+
+
+  function aix53_dladdr(Lib: pointer; info: Pdl_info): Longint; cdecl;
+    var
+      buf: array[0..4095] of byte;
+      pbuf: pbyte;
+      ldi: pld_info;
+      text_begin, text_end: pointer;
+    begin
+      fillchar(info^,sizeof(info^),0);
+      aix53_dladdr:=loadquery(L_GETINFO,@buf,sizeof(buf));
+      if aix53_dladdr=-1 then
+        begin
+          aix53_dladdr:=0;
+          exit;
+        end;
+      pbuf:=@buf[0];
+      ldi:=pld_info(pbuf);
+      // First is main(), skip.
+      while ldi^.ldinfo_next<>0 do
+        begin
+          inc(pbuf,ldi^.ldinfo_next);
+          ldi:=pld_info(pbuf);
+          text_begin:=ldi^.ldinfo_textorg;
+          if text_begin<Lib then
+            begin
+              text_end:=text_begin+ldi^.ldinfo_textsize;
+              if text_end>Lib then
+                begin
+                  info^.dli_fname:=ldi^.ldinfo_filename;
+                  info^.dli_fbase:=ldi^.ldinfo_textorg;
+                  { no info about symbols -> leave nil/0 (valid for regular
+                    dladdr call as well) }
+                  aix53_dladdr:=1;
+                  exit;
+                end;
+           end;
+        end;
+      aix53_dladdr:=0;
+    end;
+
+
+  type
+    tdladdrfunc = function(lib: pointer; info: Pdl_info): longint; cdecl;
+
+  function dladdr(Lib: pointer; info: Pdl_info): Longint; cdecl;
+    const
+      dladdrf: tdladdrfunc = nil;
+    var
+      libdl: pointer;
+    begin
+      { dladdr is only available on AIX 6.0 and later.
+
+        AIX does not support undefined weak external symbols, so we cannot
+        simply define dladdr as weakexternal and be done with it -> look up
+        the address of dladdr using dlsym }
+      if not assigned(dladdrf) then
+        begin
+          libdl:=dlopen('libdl.a',RTLD_LAZY);
+          if assigned(libdl) then
+            dladdrf:=tdladdrfunc(dlsym(libdl,'dladdr'));
+          if not assigned(dladdrf) then
+            dladdrf:=@aix53_dladdr;
+          { can't be the last reference that causes it to be unloaded, since
+            most functions from this unit come from it }
+          if assigned(libdl) then
+            dlclose(libdl);
+        end;
+      dladdr:=dladdrf(Lib,info);
+    end;
+

+ 186 - 0
rtl/aix/errno.inc

@@ -0,0 +1,186 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2011 by Jonas Maebe,
+    member of the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{
+  Errno.inc : define all error numbers, AIX 5.3
+}
+
+
+Const
+
+  ESysEPERM             = 1; { Operation not permitted }
+  ESysENOENT            = 2; { No such file or directory }
+  ESysESRCH             = 3; { No such process }
+  ESysEINTR             = 4; { interrupted system call }
+  ESysEIO               = 5; { I/O error }
+  ESysENXIO             = 6; { No such device or address }
+  ESysE2BIG             = 7; { Arg list too long }
+  ESysENOEXEC           = 8; { Exec format error }
+  ESysEBADF             = 9; { Bad file descriptor }
+  ESysECHILD            = 10; { No child processes }
+  ESysEAGAIN            = 11; { Resource temporarily unavailable }
+  ESysENOMEM            = 12; { Not enough space }
+  ESysEACCES            = 13; { Permission denied }
+  ESysEFAULT            = 14; { Bad address }
+  ESysENOTBLK           = 15; { Block device required }
+  ESysEBUSY             = 16; { Resource busy }
+  ESysEEXIST            = 17; { File exists }
+  ESysEXDEV             = 18; { Improper link }
+  ESysENODEV            = 19; { No such device }
+  ESysENOTDIR           = 20; { Not a directory }
+  ESysEISDIR            = 21; { Is a directory }
+  ESysEINVAL            = 22; { Invalid argument }
+  ESysENFILE            = 23; { Too many open files in system }
+  ESysEMFILE            = 24; { Too many open files }
+  ESysENOTTY            = 25; { Inappropriate I/O control operation }
+  ESysETXTBSY           = 26; { Text file busy }
+  ESysEFBIG             = 27; { File too large }
+  ESysENOSPC            = 28; { No space left on device }
+  ESysESPIPE            = 29; { Invalid seek }
+  ESysEROFS             = 30; { Read only file system }
+  ESysEMLINK            = 31; { Too many links }
+  ESysEPIPE             = 32; { Broken pipe }
+  ESysEDOM              = 33; { Domain error within math function }
+  ESysERANGE            = 34; { Result too large }
+  ESysENOMSG            = 35; { No message of desired type }
+  ESysEIDRM             = 36; { Identifier removed }
+  ESysECHRNG            = 37; { Channel number out of range }
+  ESysEL2NSYNC          = 38; { Level 2 not synchronized }
+  ESysEL3HLT            = 39; { Level 3 halted }
+  ESysEL3RST            = 40; { Level 3 reset }
+  ESysELNRNG            = 41; { Link number out of range }
+  ESysEUNATCH           = 42; { Protocol driver not attached }
+  ESysENOCSI            = 43; { No CSI structure available }
+  ESysEL2HLT            = 44; { Level 2 halted }
+  ESysEDEADLK           = 45; { Resource deadlock avoided }
+
+  ESysENOTREADY         = 46; { Device not ready }
+  ESysEWRPROTECT        = 47; { Write-protected media }
+  ESysEFORMAT           = 48; { Unformatted media }
+
+  ESysENOLCK            = 49; { No locks available }
+
+  ESysENOCONNECT            = 50; { no connection }
+  ESysESTALE            = 52; { no filesystem }
+  ESysEDIST             = 53; { old, currently unused AIX errno }
+
+  (* non-blocking and interrupt i/o *)
+  (*
+   * AIX returns EAGAIN where 4.3BSD used EWOULDBLOCK;
+   * but, the standards insist on unique errno values for each errno.
+   * A unique value is reserved for users that want to code case
+   * statements for systems that return either EAGAIN or EWOULDBLOCK.
+   *)
+  ESysEWOULDBLOCK = ESysEAGAIN; { Operation would block }
+
+  ESysEINPROGRESS   = 55; { Operation now in progress }
+  ESysEALREADY      = 56; { Operation already in progress }
+
+  (* ipc/network software *)
+
+    (* argument errors *)
+  ESysENOTSOCK          = 57; { Socket operation on non-socket }
+  ESysEDESTADDRREQ      = 58; { Destination address required }
+  ESysEDESTADDREQ       = ESysEDESTADDRREQ; { Destination address required }
+  ESysEMSGSIZE          = 59; { Message too long }
+  ESysEPROTOTYPE        = 60; { Protocol wrong type for socket }
+  ESysENOPROTOOPT       = 61; { Protocol not available }
+  ESysEPROTONOSUPPORT   = 62; { Protocol not supported }
+  ESysESOCKTNOSUPPORT   = 63; { Socket type not supported }
+  ESysEOPNOTSUPP        = 64; { Operation not supported on socket }
+  ESysEPFNOSUPPORT      = 65; { Protocol family not supported }
+  ESysEAFNOSUPPORT      = 66; { Address family not supported by protocol family }
+  ESysEADDRINUSE        = 67; { Address already in use }
+  ESysEADDRNOTAVAIL     = 68; { Can't assign requested address }
+
+    (* operational errors *)
+  ESysENETDOWN          = 69; { Network is down }
+  ESysENETUNREACH       = 70; { Network is unreachable }
+  ESysENETRESET         = 71; { Network dropped connection on reset }
+  ESysECONNABORTED      = 72; { Software caused connection abort }
+  ESysECONNRESET        = 73; { Connection reset by peer }
+  ESysENOBUFS           = 74; { No buffer space available }
+  ESysEISCONN           = 75; { Socket is already connected }
+  ESysENOTCONN          = 76; { Socket is not connected }
+  ESysESHUTDOWN         = 77; { Can't send after socket shutdown }
+
+  ESysETIMEDOUT         = 78; { Connection timed out }
+  ESysECONNREFUSED      = 79; { Connection refused }
+
+  ESysEHOSTDOWN         = 80; { Host is down }
+  ESysEHOSTUNREACH      = 81; { No route to host }
+
+  (* ERESTART is used to determine if the system call is restartable *)
+  ESysERESTART          = 82; { restart the system call }
+
+  (* quotas and limits *)
+  ESysEPROCLIM          = 83; { Too many processes }
+  ESysEUSERS            = 84; { Too many users }
+  ESysELOOP             = 85; { Too many levels of symbolic links }
+  ESysENAMETOOLONG      = 86; { File name too long }
+
+  (*
+   * AIX returns EEXIST where 4.3BSD used ENOTEMPTY;
+   * but, the standards insist on unique errno values for each errno.
+   * A unique value is reserved for users that want to code case
+   * statements for systems that return either EEXIST or ENOTEMPTY.
+   *)
+  ESysENOTEMPTY         = ESysEEXIST; { Directory not empty }
+
+  (* disk quotas *)
+  ESysEDQUOT            = 88; { Disc quota exceeded }
+
+  ESysECORRUPT          = 89; { Invalid file system control data }
+
+  (* errnos 90-92 reserved for future use compatible with AIX PS/2 *)
+
+  (* network file system *)
+  ESysEREMOTE           = 93; { Item is not local to host }
+
+  (* errnos 94-108 reserved for future use compatible with AIX PS/2 *)
+
+  ESysENOSYS            = 109; { Function not implemented  POSIX }
+
+  (* disk device driver *)
+  ESysEMEDIA            = 110; { media surface error }
+  ESysESOFT             = 111; { I/O completed, but needs relocation }
+
+  (* security *)
+  ESysENOATTR           = 112; { no attribute found }
+  ESysESAD              = 113; { security authentication denied }
+  ESysENOTRUST          = 114; { not a trusted program }
+
+  (* BSD 4.3 RENO *)
+  ESysETOOMANYREFS      = 115; { Too many references: can't splice }
+
+  ESysEILSEQ            = 116; { Invalid wide character }
+  ESysECANCELED         = 117; { asynchronous i/o cancelled }
+
+  (* SVR4 STREAMS *)
+  ESysENOSR             = 118; { temp out of streams resources }
+  ESysETIME             = 119; { I_STR ioctl timed out }
+  ESysEBADMSG           = 120; { wrong message type at stream head }
+  ESysEPROTO            = 121; { STREAMS protocol error }
+  ESysENODATA           = 122; { no message ready at stream head }
+  ESysENOSTR            = 123; { fd is not a stream }
+
+  ESysECLONEME          = ESysERESTART; { this is the way we clone a stream ... }
+
+  ESysENOTSUP           = 124; { POSIX threads unsupported value }
+
+  ESysEMULTIHOP         = 125; { multihop is not allowed }
+  ESysENOLINK           = 126; { the link has been severed }
+  ESysEOVERFLOW         = 127; { value too large to be stored in data type }
+
+

+ 22 - 0
rtl/aix/errnostr.inc

@@ -0,0 +1,22 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2006 by Florian Klaempfl
+
+    Contains SunOS specific errors for error.pp in rtl/unix
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+const
+  sys_errn = 128;
+
+{ since we're libc-based, just just the libc version }
+var
+  sys_errlist:array[0..sys_errn-1] of pchar; cvar; external;
+

+ 24 - 0
rtl/aix/osdefs.inc

@@ -0,0 +1,24 @@
+{
+    Copyright (c) 2000-2002 by Marco van de Voort
+
+    Target dependent defines used when compileing the baseunix unit
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************}
+
+{define usedomain}             // Allow uname with "domain" entry.
+                                // (which is a GNU extension)
+

+ 90 - 0
rtl/aix/osmacro.inc

@@ -0,0 +1,90 @@
+{
+    Copyright (c) 2000-2002 by Marco van de Voort
+
+    The "linux" posixy macro's that are used both in the Baseunx unit as the
+    system unit. Not aliased via public names because I want these to be
+    inlined as much as possible in the future.
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+
+function FpS_ISDIR(m : TMode): boolean;
+
+begin
+  FpS_ISDIR:=((m and S_IFMT) = S_IFDIR);
+end;
+
+function FpS_ISCHR(m : TMode): boolean;
+begin
+  FpS_ISCHR:=((m and S_IFMT) = S_IFCHR);
+end;
+
+function FpS_ISBLK(m : TMode): boolean;
+begin
+ FpS_ISBLK:=((m and S_IFMT) = S_IFBLK);
+end;
+
+function FpS_ISREG(m : TMode): boolean;
+begin
+ FpS_ISREG:=((m and S_IFMT) = S_IFREG);
+end;
+
+function FpS_ISFIFO(m : TMode): boolean;
+begin
+ FpS_ISFIFO:=((m and S_IFMT) = S_IFIFO);
+end;
+
+Function FPS_ISLNK(m:TMode):boolean;
+
+begin
+ FPS_ISLNK:=((m and S_IFMT) = S_IFLNK);
+end;
+
+Function FPS_ISSOCK(m:TMode):boolean;
+
+begin
+ FPS_ISSOCK:=((m and S_IFMT) = S_IFSOCK);
+end;
+
+function wifexited(status : cint): boolean;
+begin
+ wifexited:=(status AND $7f) =0;
+end;
+
+function wexitstatus(status : cint): cint;
+begin
+ wexitstatus:=(status and $FF00) shr 8;
+end;
+
+function wstopsig(status : cint): cint;
+begin
+ wstopsig:=(status and $FF00) shr 8;
+end;
+
+const wstopped=127;
+
+function wifsignaled(status : cint): boolean;
+begin
+ wifsignaled:=((status and $FF)<>wstopped) and ((status and 127)<>0);
+end;
+
+function wtermsig(status : cint):cint;
+
+begin
+ wtermsig:=cint(status and 127);
+end;
+

+ 284 - 0
rtl/aix/ostypes.inc

@@ -0,0 +1,284 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2001 by Free Pascal development team
+
+    Types and structures for the BaseUnix unit.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ ***********************************************************************}
+
+{***********************************************************************}
+{                         Base Unix Structures                          }
+{***********************************************************************}
+
+{$IFDEF FPC_IS_SYSTEM}
+  {$i ptypes.inc}
+{$ENDIF}
+
+{ note: all constants/types are taken from the case that the headers are parsed
+  with:
+    -D_LARGE_FILES
+    -U_POSIX_SOURCE
+    -U_ANSI_C_SOURCE
+}
+
+CONST
+   FD_MAXFDSET     = 65534;
+   BITSINWORD      = 8*sizeof(clong);
+   wordsinsigset   = (SIG_MAXSIG+1+BITSINWORD-1) DIV BITSINWORD;         // words in sigset_t
+   wordsinfdset    = (FD_MAXFDSET+1+BITSINWORD-1) DIV BITSINWORD;        // words in fdset_t
+{$ifdef cpu64}
+   ln2bitsinword   = 6;         { 64bit : ln(64)/ln(2)=5 }
+{$else}
+   ln2bitsinword   = 5;         { 32bit : ln(32)/ln(2)=5 }
+{$endif}
+   ln2bitmask      = 1 shl ln2bitsinword - 1;
+
+    UTSNAME_LENGTH = 31;
+    UTSNAME_NODENAME_LENGTH = 31;
+
+TYPE
+    blksize_t = {$ifdef cpu64}clong{$else}cint{$endif};
+    blkcnt_t = {$ifdef cpu64}clong{$else}cint{$endif};
+
+   { file characteristics services }
+   stat = record
+     st_dev : dev_t;
+     st_ino : ino_t;
+     st_mode : mode_t;
+     st_nlink : nlink_t;
+     st_flag : cushort;
+     st_uid : uid_t;
+     st_gid : gid_t;
+     st_rdev : dev_t;
+     st_ssize : cint;
+     st_atime : time_t;
+     st_atimens : cint;    { access time nanosecond field         }
+
+     st_mtime : time_t;
+     st_mtimens : cint;    { modification time nanosecond field   }
+     st_ctime : time_t;
+     st_ctimens : cint;    { modification time nanosecond field   }
+     st_blksize : blksize_t;
+     st_blocks : blkcnt_t;
+     st_vfstype: cint;     { Type of fs (see vnode.h) }
+     st_vfs    : cuint;    { Vfs number }
+     st_type   : cuint;    { Vnode type }
+     st_gen    : cuint;    { Inode generation number }
+     st_reserved : array [0..9] of cuint;
+     st_size   : off_t;    { 64 bit file size in bytes }
+   end;
+   TStat             = Stat;
+   PStat             = ^Stat;
+
+   flock    = record
+                l_type  : cshort;       { lock type: read/write, etc. }
+                l_whence: cshort;       { type of l_start }
+                l_sysid : cuint;
+                l_pid   : pid_t;        { lock owner }
+                l_vfs   : cint;
+                l_start : off_t;
+                l_len   : off_t;
+                end;
+   TFlock   = flock;
+   pFlock   = ^flock;
+
+   TFDSet    = array[0..wordsinfdset-1] of culong;
+   pFDSet    = ^TFDSet;
+
+   timezone = record
+     tz_minuteswest,tz_dsttime:cint;
+   end;
+   ptimezone =^timezone;
+   TTimeZone = timezone;
+
+   { system information services }
+   utsname = record
+     sysname : array[0..UTSNAME_LENGTH] of char;
+     nodename : array[0..UTSNAME_LENGTH] of char;
+     release : array[0..UTSNAME_LENGTH] of char;
+     version : array[0..UTSNAME_LENGTH] of char;
+     machine : array[0..UTSNAME_LENGTH] of char;
+   end;
+
+   UTimBuf   = Record
+                 actime  : time_t;
+                 modtime : time_t;
+                end;
+   TUtimBuf  = UtimBuf;
+   pUtimBuf  = ^UtimBuf;
+
+   { directory services }
+   pdirent = ^dirent;
+   { actually dirent64 }
+   dirent = record    { directory entry record }
+     case integer of
+       1 : (
+             d_off : cuint64;                  {* offset of disk directory entry *}
+             d_ino : ino64_t;                  {* "inode number" of entry *}
+             d_reclen : cushort;             {* length of this record *}
+             d_namelen : cushort;
+             d_name : array[0..255] of char; { name of file            }
+            );
+       { overlay with alias }
+       2 : (
+            dummy    : cuint64;
+            d_fileno : ino64_t;
+           ); 
+   end;
+
+
+   pdir = ^dir;
+   dir = record
+    case integer of
+      1 : (
+           d_fd : cint;               {* file descriptor *}
+           d_loc : cint;              {* offset in block *}
+           d_size : cint;             {* amount of valid data *}
+           d_buf : pchar;             { directory block   }
+          );
+      { overlay for posix compatibility }
+      2 : (
+           dd_fd : cint;               {* file descriptor *}
+           dd_loc : cint;              {* offset in block *}
+           dd_size : cint;             {* amount of valid data *}
+           dd_buf : pchar;             { directory block   }
+          );
+   end;
+
+
+
+{***********************************************************************}
+{                  POSIX CONSTANT ROUTINE DEFINITIONS                   }
+{***********************************************************************}
+CONST
+    { access routine - these maybe OR'ed together }
+    F_OK        = 0;   { test for existence of file }
+    R_OK        = 4;   { test for read permission on file }
+    W_OK        = 2;   { test for write permission on file }
+    X_OK        = 1;   { test for execute or search permission }
+    { seek routine }
+    SEEK_SET    = 0;    { seek from beginning of file }
+    SEEK_CUR    = 1;    { seek from current position  }
+    SEEK_END    = 2;    { seek from end of file       }
+    { open routine                                 }
+    { File access modes for `open' and `fcntl'.    }
+    O_RDONLY    = 0;    { Open read-only.  }
+    O_WRONLY    = 1;    { Open write-only. }
+    O_RDWR      = 2;    { Open read/write. }
+    { Bits OR'd into the second argument to open.  }
+    O_CREAT     = $100; { Create file if it doesn't exist.  }
+    O_EXCL      = $400; { Fail if file already ??????.      }
+    O_TRUNC     = $200; { Truncate file to zero length.     }
+    O_NOCTTY    = $800; { Don't assign a controlling terminal. }
+    { File status flags for `open' and `fcntl'.  }
+    O_APPEND    =  $08; { Writes append to the file.        }
+    O_NONBLOCK  =  $04; { Non-blocking I/O.                 }
+
+
+    { mode_t possible values                                 }
+    S_IRUSR = $100;           { Read permission for owner   }
+    S_IWUSR = $080;           { Write permission for owner  }
+    S_IXUSR = $040;           { Exec  permission for owner  }
+    S_IRGRP = $020;           { Read permission for group   }
+    S_IWGRP = $010;           { Write permission for group  }
+    S_IXGRP = $008;           { Exec permission for group   }
+    S_IROTH = $004;           { Read permission for world   }
+    S_IWOTH = $002;           { Write permission for world  }
+    S_IXOTH = $001;           { Exec permission for world   }
+
+    { Used for waitpid }
+    WNOHANG   = $01;            { don't block waiting               }
+    WUNTRACED = $02;            { report status of stopped children }
+
+Const
+  S_IFMT  = $F000;
+  S_IFIFO = $1000;
+  S_IFCHR = $2000;
+  S_IFDIR = $4000;
+  S_IFBLK = $6000;
+  S_IFREG = $8000;
+  S_IFLNK = $A000;
+  S_IFSOCK= $C000;
+//  S_IFWHT = 57344;
+  S_ISVTX = $200;
+
+  { For File control mechanism }
+  F_GetFd  = 1;
+  F_SetFd  = 2;
+  F_GetFl  = 3;
+  F_SetFl  = 4;
+  F_GetLk  = 5;
+  F_SetLk  = 6;
+  F_SetLkW = 7;
+  F_SetOwn = 9;
+  F_GetOwn = 8;
+
+Const
+ { Constansts for MMAP }
+ {$ifdef FPC_IS_SYSTEM}
+  MAP_PRIVATE   =2;
+ {$endif}
+  MAP_ANONYMOUS =$10;
+
+type
+  rlim_t = cULong;
+  PRLimit = ^TRLimit;
+  TRLimit = record
+    rlim_cur : rlim_t;
+    rlim_max : rlim_t;
+  end;
+
+{$i signal.inc}
+
+  iovec = record
+            iov_base : pointer;
+	    iov_len  : size_t;
+	   end;
+  tiovec=iovec;
+  piovec=^tiovec;		
+
+ tms = packed record
+         tms_utime  : clock_t;  { User CPU time }
+         tms_stime  : clock_t;  { System CPU time }
+         tms_cutime : clock_t;  { User CPU time of terminated child procs }
+         tms_cstime : clock_t;  { System CPU time of terminated child procs }
+         end;
+ TTms= tms;
+ pTms= ^tms;
+
+const
+  POLLIN      = $0001;
+  POLLPRI     = $0004;
+  POLLOUT     = $0002;
+  POLLERR     = $4000;
+  POLLHUP     = $2000;
+  POLLNVAL    = $8000;
+
+  { XOpen, XPG 4.2 }
+  POLLRDNORM  = $0010;
+  POLLRDBAND  = $0020;
+  POLLWRNORM  = POLLOUT;
+  POLLWRBAND  = $0040;
+
+type
+  pollfd = record
+    { int on 64 bit = long on 32 bit, but this is how the C header does it }
+{$ifdef cpu64}
+    fd: cint;
+{$else}
+    fd: clong;
+{$endif}
+    events: cshort;
+    revents: cshort;
+  end;
+  tpollfd = pollfd;
+  ppollfd = ^pollfd;
+
+

+ 128 - 0
rtl/aix/pthread.inc

@@ -0,0 +1,128 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by Peter Vreman
+    Copyright (c) 2011 by Jonas Maebe
+    members of the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This file contains a pthread.h headerconversion,
+    and should contain an interface to the threading library to be
+    used by systhrd, preferably in a somewhat compatible notation
+    (compared to the other OSes).
+
+    As a start, I simply used libc_r
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+  const
+    PTHREAD_EXPLICIT_SCHED       = 1;
+    PTHREAD_INHERIT_SCHED        = 0;
+    PTHREAD_CREATE_DETACHED      = 1;
+    PTHREAD_SCOPE_PROCESS        = 1;
+
+    _PTHREAD_MUTEX_NORMAL        = 5;
+    _PTHREAD_MUTEX_ERRORCHECK    = 3;
+    _PTHREAD_MUTEX_RECURSIVE     = 4;
+    
+  type
+    sched_param = record
+      __sched_priority: cint;
+      __sched_policy  : cint;
+      __sched_reserved: array[0..5] of cint;
+    end;
+
+    sem_t = cint;
+
+    psem_t      = ^sem_t;
+    TSemaphore  = sem_t;
+    PSemaphore  = ^TSemaphore;
+
+
+    ppthread_t           = ^pthread_t;
+    ppthread_key_t       = ^pthread_key_t;
+    ppthread_mutex_t     = ^pthread_mutex_t;
+    ppthread_attr_t      = ^pthread_attr_t;
+    __destr_func_t       = procedure (p :pointer);cdecl;
+    __startroutine_t     = function (p :pointer):pointer;cdecl;
+    ppthread_mutexattr_t = ^pthread_mutexattr_t;
+    ppthread_cond_t      = ^pthread_cond_t;
+    ppthread_condattr_t  = ^pthread_condattr_t;
+
+    pthread_spinlock_t = record
+{$ifdef cpu64}
+      __sp_word: array[0..2] of clong;
+{$else}
+      __sp_word: array[0..5] of cint;
+{$endif}
+    end;
+
+    _once = record
+{$ifdef cpu64}
+      __on_word: array[0..8] of clong;
+{$else}
+      __on_word: array[0..27] of cint;
+{$endif}
+    end;
+
+    pthread_once_t = _once;
+
+    pthread_barrier_t = record
+{$ifdef cpu64}
+      __ba_word: array[0..4] of clong;
+{$else}
+      __ba_word: array[0..7] of cint;
+{$endif}
+    end;
+
+    pthread_barrierattr_t = pointer;
+
+function  pthread_getspecific      (t : pthread_key_t):pointer; cdecl; external 'c';
+function  pthread_setspecific      (t : pthread_key_t;p:pointer):cint; cdecl; external 'c';
+function  pthread_key_create       (p : ppthread_key_t;f: __destr_func_t):cint; cdecl;external 'c';
+function  pthread_attr_init           (p : ppthread_key_t):cint; cdecl; external 'c';
+function  pthread_attr_setinheritsched(p : ppthread_attr_t;i:cint):cint; cdecl; external 'c';
+function  pthread_attr_setscope      (p : ppthread_attr_t;i:cint):cint;cdecl;external 'c';
+function  pthread_attr_setdetachstate (p : ppthread_attr_t;i:cint):cint;cdecl;external 'c';
+function  pthread_attr_setstacksize(p: ppthread_attr_t; stacksize: size_t):cint;cdecl;external 'c';
+function  pthread_create ( p: ppthread_t;attr : ppthread_attr_t;f:__startroutine_t;arg:pointer):cint;cdecl;external 'c';
+procedure pthread_exit  ( p: pointer); cdecl;external 'c';
+function  pthread_self:pthread_t; cdecl;external 'c';
+function  pthread_mutex_init (p:ppthread_mutex_t;o:ppthread_mutexattr_t):cint; cdecl;external 'c';
+function  pthread_mutex_destroy (p:ppthread_mutex_t):cint; cdecl;external 'c';
+function  pthread_mutex_lock    (p:ppthread_mutex_t):cint; cdecl;external 'c';
+function  pthread_mutex_trylock (p:ppthread_mutex_t):cint; cdecl;external 'c';
+function  pthread_mutex_unlock  (p:ppthread_mutex_t):cint; cdecl;external 'c';
+function  pthread_cancel(_para1:pthread_t):cint;cdecl;external 'c';
+function  pthread_detach(_para1:pthread_t):cint;cdecl;external 'c';
+function  pthread_join(_para1:pthread_t; _para2:Ppointer):cint;cdecl;external 'c';
+function  pthread_cond_destroy(_para1:Ppthread_cond_t):cint;cdecl;external 'c' name 'pthread_cond_destroy';
+function  pthread_cond_init(_para1:Ppthread_cond_t;_para2:Ppthread_condattr_t):cint;cdecl;external  'c' name 'pthread_cond_init';
+function  pthread_cond_signal(_para1:Ppthread_cond_t):cint;cdecl;external 'c' name 'pthread_cond_signal';
+function  pthread_cond_broadcast(_para1:Ppthread_cond_t):cint;cdecl;external 'c' name 'pthread_cond_broadcast';
+function  pthread_cond_wait(_para1:Ppthread_cond_t;_para2:Ppthread_mutex_t):cint;cdecl;external 'c' name 'pthread_cond_wait';
+function pthread_kill(__thread:pthread_t; __signo:cint):cint;cdecl;external 'c';
+function pthread_sigmask(how: cint; nset: psigset; oset: psigset): cint; cdecl; external 'c';
+
+function sem_init(__sem:Psem_t; __pshared:cint;__value:cuint):cint;cdecl; external 'c' name 'sem_init';
+function sem_destroy(__sem:Psem_t):cint;cdecl;external 'c' name 'sem_destroy';
+function sem_close(__sem:Psem_t):cint;cdecl;external 'c'  name 'sem_close';
+function sem_unlink(__name:Pchar):cint;cdecl;external 'c' name 'sem_unlink';
+function sem_wait(__sem:Psem_t):cint;cdecl;external 'c'  name 'sem_wait';
+function sem_timedwait(__sem: Psem_t; const __timespec: ptimespec): cint;cdecl; external 'c' name 'sem_timedwait';
+function sem_trywait(__sem:Psem_t):cint;cdecl;external 'c'  name 'sem_trywait';
+function sem_post(__sem:Psem_t):cint;cdecl;external 'c'  name 'sem_post';
+function sem_getvalue(__sem:Psem_t; __sval:Pcint):cint;cdecl;external 'c'  name 'sem_getvalue';
+
+
+function pthread_mutexattr_init(_para1:Ppthread_mutexattr_t):cint;cdecl;external 'c' name 'pthread_mutexattr_init';
+function pthread_mutexattr_destroy(_para1:Ppthread_mutexattr_t):cint;cdecl;external 'c' name 'pthread_mutexattr_destroy';
+function pthread_mutexattr_gettype(_para1:Ppthread_mutexattr_t; _para2:Pcint):cint;cdecl;external 'c' name 'pthread_mutexattr_gettype';
+function pthread_mutexattr_settype(_para1:Ppthread_mutexattr_t; _para2:cint):cint;cdecl;external 'c' name 'pthread_mutexattr_settype';
+function pthread_cond_timedwait(__cond:ppthread_cond_t; __mutex:ppthread_mutex_t; __abstime:ptimespec):cint; cdecl;external 'c' name 'pthread_cond_timedwait';
+

+ 251 - 0
rtl/aix/ptypes.inc

@@ -0,0 +1,251 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2001 by Free Pascal development team
+    Copyright (c) 2011 by Jonas Maebe
+
+    This file implements all the base types and limits required
+    for a minimal POSIX compliant subset required to port the compiler
+    to a new OS.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{***********************************************************************}
+{                       POSIX TYPE DEFINITIONS                          }
+{***********************************************************************}
+
+{ Introduced defines
+    - 64bitfs   (should be on if libc switches to a 64-bit system.
+
+All three tested systems (PPC,Alpha,2x i386) gave the same POSIX limits,
+and all three 32-bit systems returned completely identical types too
+(everything 32-bit except dev_t, which is assumed to be a result of devfs
+introduction)
+}
+
+{$I ctypes.inc}
+{$packrecords c}
+
+Type
+
+    dev_t    = {$ifdef cpu64}culong{$else}cuint{$endif};
+    TDev     = dev_t;
+    pDev     = ^dev_t;
+
+    gid_t    = cuint;         { used for group IDs           }
+    TGid     = gid_t;
+    pGid     = ^gid_t;
+    TIOCtlRequest = cInt;
+
+    ino_t    = {$ifdef cpu64}culong{$else}cuint{$endif};           { used for file serial numbers }
+    TIno     = ino_t;
+    pIno     = ^ino_t;
+    ino64_t  = cuint64;
+
+    mode_t   = cuint;         { used for file attributes     }
+    TMode    = mode_t;
+    pMode    = ^mode_t;
+
+    nlink_t  = cshort;        { used for link counts         }
+    TnLink   = nlink_t;
+    pnLink   = ^nlink_t;
+
+    off_t    = clonglong;     { used for file sizes          }
+    TOff     = off_t;
+    pOff     = ^off_t;
+
+    pid_t    = cint;          { used as process identifier   }
+    TPid     = pid_t;
+    pPid     = ^pid_t;
+
+    size_t   = culong;         { as definied in the C standard}
+    ssize_t  = clong;          { used by function for returning number of bytes }
+    clock_t  = cint;
+    time_t   = {$ifdef cpu64}clong{$else}cint{$endif};           { used for returning the time  }
+    wint_t    = cint;
+    TSize     = size_t;
+    pSize     = ^size_t;
+    psize_t   = pSize;
+    TSSize    = ssize_t;
+    pSSize    = ^ssize_t;
+    TClock    = clock_t;
+    pClock    = ^clock_t;
+    // TTime    = time_t;    // Not allowed in system unit, -> unixtype
+
+    pTime     = ^time_t;
+    ptime_t   = ^time_t;
+    clockid_t = clonglong;
+    caddr_t   = ^char;
+
+    uint32_t = cuint32;
+    int32_t = cint32;
+//    caddr32_t = uint32_t;
+    daddr32_t = cint;
+//    off32_t = cuint;
+    ino32_t = cuint;
+    blkcnt32_t = cint;
+//    fsblkcnt32_t = uint32_t;
+//    fsfilcnt32_t = uint32_t;
+//    id32_t = int32_t;
+//    major32_t = uint32_t;
+//    minor32_t = uint32_t;
+//    key32_t = int32_t;
+//    mode32_t = uint32_t;
+//    uid32_t = int32_t;
+//    gid32_t = int32_t;
+//    nlink32_t = uint32_t;
+    dev32_t = cuint;
+    pid32_t = cuint;
+//    size32_t = uint32_t;
+//    ssize32_t = int32_t;
+    time32_t = cint;
+
+
+    uint16_t = cuint16;
+//    upad64_t  = qword;
+    uintptr_t = ^cuint;
+    uint_t    = cuint;
+
+    fsid_t = record
+      val: array[0..1] of cuint;
+    end;
+
+    fsid64_t = record
+      val: array[0..1] of cuint64;
+    end;
+
+
+{$ifdef cpu64}
+    wchar_t   = cuint;
+{$else cpu64}
+    wchar_t   = cushort; { utf-16! }
+{$endif cpu64}
+    pwchar_t  = ^wchar_t;
+
+    uid_t    = cuint;         { used for user ID type        }
+    TUid     = uid_t;
+    pUid     = ^uid_t;
+
+    socklen_t= cuint32;
+    TSockLen = socklen_t;
+    pSockLen = ^socklen_t;
+
+  suseconds_t = cint;
+  timeval     = record
+                 tv_sec  : time_t;
+                 tv_usec : suseconds_t;
+                end;
+  ptimeval    = ^timeval;
+  TTimeVal    = timeval;
+
+  timespec    =  record
+                 tv_sec   : time_t;
+                 tv_nsec  : suseconds_t;
+                end;
+  ptimespec   = ^timespec;
+  TTimeSpec   = timespec;
+
+  fsblkcnt_t = culong;
+
+  TStatfs = record
+    f_version : cint;  { version/type of statfs, 0 for now }
+    f_type    : cint;  { type of info, zero for now }
+    bsize     : culong;  { fundamental file system block size  }
+    blocks,            { total data blocks in file system }
+    bfree,             { free blocks in fs }
+    bavail,            { free blocks avail to non-superuser }
+    files,             { total file nodes in file system }
+    ffree   : fsblkcnt_t;   { free file nodes in fs }
+{$ifdef cpu64}
+    fsid    : fsid64_t;{ File system ID }
+{$else}
+    fsid    : fsid_t;
+{$endif}
+    vfstype : cint;    { what type of vfs this is }
+    fsize   : culong;  { fundamental file system block size }
+    vfsnumber : cint;  { vfs indentifier number }
+    vfsoff : cint;     { reserved, for vfs specific data offset }
+    vfslen : cint;     { reserved, for len of vfs specific data }
+    vfsvers : cint;    { reserved, for vers of vfs specific data }
+    fstr   : array[0..31] of char; { fname in C header, file system name (usually mount pt.) }
+    fpack   : array[0..31] of char; { file system pack name }
+    namelen : cint; { maximum component name length for posix }
+  end;
+  PStatFS=^TStatFS;
+
+  mbstate_t = pointer;
+  pmbstate_t = ^mbstate_t;
+  
+
+//  clock32_t = int32_t;
+  timeval32 = record
+{ seconds  }
+       tv_sec : int32_t;
+{ and microseconds  }
+       tv_usec : int32_t;
+    end;
+
+
+const
+   { System limits, POSIX value in parentheses, used for buffer and stack allocation }
+   { took idefix' values}
+
+    ARG_MAX        = 24576;    { Maximum number of argument size     }
+    // depends on file system, must use pathconf() or fpathconf() instead of constant!
+    NAME_MAX       = 255;      { Maximum number of bytes in filename }
+    PATH_MAX       = 1023;     { Maximum number of bytes in pathname }
+    SYS_NMLN       = 32;
+{$ifdef cpu64}
+    SIG_MAXSIG      = 255;     // highest signal number
+{$else}
+    SIG_MAXSIG      = 63;      // highest signal number
+{$endif}
+
+ { For getting/setting priority }
+  Prio_Process = 0;
+  Prio_PGrp    = 1;
+  Prio_User    = 2;
+
+
+ type
+    pthread_t = cuint;
+
+    pthread_attr_t = pointer;
+
+    pthread_mutexattr_t = pointer;
+
+    pthread_cond_t = record
+{$ifdef cpu64}
+       __co_word: array[0..5] of clong;
+{$else}
+       __co_word: array[0..10] of cint;
+{$endif}
+    end;
+
+    pthread_condattr_t = pointer;
+
+    pthread_key_t = cuint;
+
+    pthread_mutex_t = record
+{$ifdef cpu64}
+      __mt_word: array[0..7] of clong;
+{$else}
+      __mt_word: array[0..12] of cint;
+{$endif}
+   end;
+
+    pthread_rwlock_t = record
+ {$ifdef cpu64}
+       __rw_word: array[0..9] of clong;
+ {$else}
+       __rw_word: array[0..51] of cint;
+ {$endif}
+    end;
+
+    sem_t = cint;

+ 68 - 0
rtl/aix/sighnd.inc

@@ -0,0 +1,68 @@
+{
+   This file is part of the Free Pascal run time library.
+   (c) 2000-2003 by Marco van de Voort
+   (c) 2011 by Jonas Maebe
+   members of the Free Pascal development team.
+
+   See the file COPYING.FPC, included in this distribution,
+   for details about the copyright.
+
+   Signalhandler for FreeBSD/i386
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY;without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+}
+
+procedure SignalToRunerror(Sig: cint; info : PSigInfo; SigContext:PSigContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
+
+var
+  res : word;
+
+begin
+  res:=0;
+  case sig of
+    SIGFPE :
+      begin
+        Case Info^.si_code Of
+          FPE_FLTDIV,
+          FPE_INTDIV : Res:=200;  { floating point divide by zero }
+          FPE_FLTOVF : Res:=205;  { floating point overflow }
+          FPE_FLTUND : Res:=206;  { floating point underflow }
+          FPE_FLTRES,             { floating point inexact result }
+          FPE_FLTINV : Res:=207;  { invalid floating point operation }
+          Else
+            Res:=207; {coprocessor error}
+        end;
+        { FPU exceptions are completely disabled by the kernel if one occurred, it  }
+        { seems this is necessary to be able to return to user mode. They can be    }
+        { enabled by executing a sigreturn, however then the exception is triggered }
+        { again immediately if we don't turn off the "exception occurred" flags     }
+        { in fpscr                                                                  }
+        SigContext^.uc_mcontext.fpscr := SigContext^.uc_mcontext.fpscr and not($fffe0700);
+      end;
+    SIGILL,
+    SIGBUS,
+    SIGSEGV :
+        res:=216;
+    SIGINT:
+        res:=217;
+    SIGQUIT:
+        res:=233;
+  end;
+  {$ifdef FPC_USE_SIGPROCMASK}
+   reenable_signal(sig);
+  {$endif }
+
+  { return to trampoline }
+  if res <> 0 then
+    begin
+      SigContext^.uc_mcontext.gpr[3] := res;
+      SigContext^.uc_mcontext.gpr[4] := SigContext^.uc_mcontext.iar;
+      SigContext^.uc_mcontext.gpr[5] := SigContext^.uc_mcontext.gpr[1];
+      { the address of a function is a descriptor, and we need the actual
+        address here -> dereference }
+      pointer(SigContext^.uc_mcontext.iar) := ppointer(@HandleErrorAddrFrame)^;
+    end;
+end;
+

+ 120 - 0
rtl/aix/sighndh.inc

@@ -0,0 +1,120 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2011 by Free Pascal development team
+
+    This file implements all the types/constants related
+    to signals for AIX.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+type
+  plabel_t = ^label_t;
+  label_t = record
+    prev: plabel_t;
+    iar: culong;
+    stack: culong;
+    toc: culong;
+    cr: culong;
+    intpri: culong;
+    reg: array[0..18] of culong; // non-volatile regs (13..31)
+  end;
+
+  padspace_t = ^adspace_t;
+  adspace_t = record
+    alloc: culong;
+    srval: array[0..15] of cuint;
+  end;
+
+  pmstsave = ^mstsave;
+  mstsave = record
+    prev: pmstsave;
+    kjmpbuf: plabel_t;
+    stackfix: pchar;
+    intpri: byte;
+    backt: byte;
+    rsvd: array[0..1] of byte;
+    curid: pid_t;
+
+    excp_type: cint;
+    iar: culong; // instruction address register
+    msr: culong;
+    cr: culong;
+    lr: culong;
+    ctr: culong;
+    xer: culong;
+    mq: culong;
+    tid: culong;
+    fpscr: culong;
+    fpeu: bytebool;
+    fpinfo: byte;
+    pad: array[0..1] of byte;
+    except_: array[0..4] of culong;
+    pad1: array[0..3] of byte;
+    o_iar: culong;
+    o_toc: culong;
+    o_arg1: culong;
+    excbranch: culong;
+    fpscrx: culong;
+    o_vaddr: culong;
+    cachealign: array[0..6] of culong;
+    as_: adspace_t;
+    gpr: array[0..31] of culong;
+    fpr: array[0..31] of double;
+  end;
+
+  pstack_t = ^stack_t;
+  stack_t = record
+    ss_sp: pointer;
+    ss_size: size_t;
+    ss_flags: cint;
+    __pad: array[0..3] of cint;
+  end;
+
+  __vmxreg_t = record
+    __v: array[0..3] of cint;
+  end;
+
+  __vmx_context = record
+    __vr: array[0..31] of __vmxreg_t;
+    __pad1: array[0..2] of cuint;
+    __vscr: cuint;
+    __vrsave: cuint;
+    __pad2: array[0..1] of cuint;
+  end;
+
+  p__extctx_t = ^__extctx_t;
+  __extctx_t = record
+    __flags: cuint;
+    __rsvd1: array[0..2] of cuint;
+    __u1: record
+      __vmx: __vmx_context
+    end;
+    __ukeys: cuint;
+    __reserved: array[0..4096-sizeof(__vmx_context)-7*sizeof(cint)-1] of byte;
+    __extctx_magic: cint;
+  end;
+
+
+  mcontext_t = mstsave;
+
+  pucontext_t = ^tucontext_t;
+  PSigContext = pucontext_t;
+  tucontext_t = record
+    __sc_onstack: cint;
+    uc_sigmask: sigset_t;
+    __sc_uerror: cint;
+    uc_mcontext: mcontext_t;
+    uc_link: ^pucontext_t;
+    uc_stack: stack_t;
+    __extctx: __extctx_t;
+    __extctx_magic: cint;
+    __pad: array[0..{$ifdef cpu64}1{$else}0{$endif}] of cint;
+  end;
+

+ 194 - 0
rtl/aix/signal.inc

@@ -0,0 +1,194 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2011 by Free Pascal development team
+
+    This file implements all the types/constants related
+    to signals for AIX.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+const
+  {************************ signals *****************************}
+  { more can be provided. Herein are only included the required  }
+  { values.                                                      }
+  {**************************************************************}
+  SIGHUP     =  1;     { Hangup                         }
+  SIGINT     =  2;     { Interactive attention signal   }
+  SIGQUIT    =  3;     { Interactive termination signal }
+  SIGILL     =  4;     { Illegal instruction            }
+  SIGABRT    =  6;     { abnormal termination           }
+  SIGFPE     =  8;     { illegal arithmetic operation   }
+  SIGKILL    =  9;     { Kill, cannot be caught         }
+  SIGBUS     = 10;     { Access to undefined memory        }
+  SIGSEGV    = 11;     { Detection of invalid memory reference }
+  SIGPIPE    = 13;     { Broken pipe signal             }
+  SIGALRM    = 14;     { alarm clock (used with alarm() }
+  SIGTERM    = 15;     { Termination request           }
+  SIGUSR1    = 30;
+  SIGUSR2    = 31;
+  SIGSTOP    = 17;     { Stop signal. cannot be cuaght     }
+  SIGSTP     = 18;     { Interactive stop signal           }
+  SIGCONT    = 19;     { Continue if stopped               }
+  SIGCHLD    = 20;     { Child process terminated / stopped }
+  SIGTSTP    = SIGSTP; { AIX name for SIGSTP               }
+  SIGTTIN    = 21;     { Background read from TTY          }
+  SIGTTOU    = 22;     { Background write to TTY           }
+
+  { AIX specific signals                               }
+
+  SIGTRAP    =  5;      { trace trap (not reset when caught) }
+  SIGIOT     = SIGABRT; { IOT instruction }
+  SIGLOST    = SIGIOT;  { resource lost (eg, record-lock lost) }
+  SIGEMT     =  7;      { EMT instruction }
+  SIGSYS     = 12;      { bad argument to system call }
+  SIGCLD     = SIGCHLD; { child status change }
+  SIGURG     = 16;      { (+) urgent contition on I/O channel  }
+  SIGPOLL    = 23;      { pollable event occured }
+  SIGXCPU    = 24;      { exceeded cpu limit }
+  SIGXFSZ    = 25;
+  SIGMSG     = 27;
+  SIGWINCH   = 28;      { window size change }
+  SIGPWR     = 29;      { power-fail restart }
+  SIGIO      = SIGPOLL; { socket I/O possible (SIGPOLL alias) }
+  SIGAIO     = SIGIO;
+  SIGPTY     = SIGIO;
+  SIGPROF    = 32;      { profiling timer expired }
+  SIGVTALRM  = 34;      { virtual timer expired }
+  SIGMIGRATE = 35;      { exceeded file size limit }
+  SIGPRE     = 36;
+  SIGVIRT    = 37;
+  SIGALARM1  = 38;
+  SIGWAITING = 39;      { process's lwps are blocked }
+  SIGRECONFIG = 58;
+  SIGCPUFAIL = 59;
+  SIGKAP     = 60;
+  SIGGRANT   = SIGKAP;
+  SIGRETRACT = 61;
+  SIGSOUND   = 62;
+  SIGSAK     = 63;
+
+  SIG_BLOCK   = 1;
+  SIG_UNBLOCK = 2;
+  SIG_SETMASK = 3;
+
+  SIG_DFL = pointer(0) ;
+  SIG_IGN = pointer(1) ;
+  SIG_ERR = pointer(-1) ;
+
+  { definitions for the sa_flags field }
+  SA_ONSTACK   = $00000001;
+  SA_RESETHAND = $00000002;
+  SA_RESTART   = $00000008;
+  SA_SIGINFO   = $00000100;
+  SA_NODEFER   = $00000200;
+  SA_NOCLDWAIT = $00000400;
+
+  SI_USER = 0;
+  SI_UNDEFINED = 8;
+  SI_EMPTY = 9;
+{ SIGBUS }
+  BUS_ADRALN = 1;
+  BUS_ADRERR = 2;
+  BUS_OBJERR = 3;
+  BUS_UEGARD = 4;
+{ SIGCHLD }
+  CLD_EXITED = 10;
+  CLD_KILLED = 11;
+  CLD_DUMPED = 12;
+  CLD_TRAPPED = 13;
+  CLD_STOPPED = 14;
+  CLD_CONTINUED = 15;
+{ SIGFPE }
+  FPE_INTDIV = 20;
+  FPE_INTOVF = 21;
+  FPE_FLTDIV = 22;
+  FPE_FLTOVF = 23;
+  FPE_FLTUND = 24;
+  FPE_FLTRES = 25;
+  FPE_FLTINV = 26;
+  FPE_FLTSUB = 27;
+{ SIGILL }
+  ILL_ILLOPC = 30;
+  ILL_ILLOPN = 31;
+  ILL_ILLADR = 32;
+  ILL_ILLTRP = 33;
+  ILL_PRVOPC = 34;
+  ILL_PRVREG = 35;
+  ILL_COPROC = 36;
+  ILL_BADSTK = 37;
+{ SIGPOLL }
+  POLL_IN = 40;
+  POLL_OUT = 41;
+  POLL_MSG = -3;
+  POLL_ERR = 43;
+  POLL_PRI = 44;
+  POLL_HUP = 45;
+{ SIGSEGV }
+  SEGV_MAPERR = 50;
+  SEGV_ACCERR = 51;
+  SEGV_KEYERR = 52;
+{ SIGTRAP }
+  TRAP_BRKPT = 60;
+  TRAP_TRACE = 61;
+{ GENERAL }
+  SI_QUEUE = 71;
+  SI_TIMER = 72;
+  SI_ASYNCIO = 73;
+  SI_MESGQ = 74;
+
+
+type
+  SigSet  =  array[0..wordsinsigset-1] of clong;
+  sigset_t= SigSet;
+  PSigSet = ^SigSet;
+  psigset_t=psigset;
+  TSigSet = SigSet;
+
+  psiginfo = ^tsiginfo;
+  tsiginfo = record
+       si_signo : cint;
+       si_errno : cint;
+       si_code  : cint;
+       si_pid   : pid_t;
+       si_uid   : uid_t;
+{$ifdef cpu64}
+       si_status: cint;
+       si_addr  : pointer;
+{$else cpu64}
+       si_addr  : pointer;
+       si_status: cint;
+{$endif cpu64}
+       si_band  : clong;
+       __si_flags: cint;
+{$ifdef cpu64}
+       __pad: array[0..2] of cint;
+{$else cpu64}
+       __pad: array[0..5] of cint;
+{$endif cpu64}
+    end;
+
+{ CPU dependent TSigContext }
+{$i sighndh.inc}
+
+type
+  SignalHandler   = Procedure(Sig : Longint);cdecl;
+  PSignalHandler  = ^SignalHandler;
+  SignalRestorer  = Procedure;cdecl;
+  PSignalRestorer = ^SignalRestorer;
+  SigActionHandler = procedure(sig : longint; SigInfo: PSigInfo; SigContext: PSigContext);cdecl;
+
+  SigActionRec = record  // this needs correct 8-byte alignment for hander
+    sa_handler  : SigActionHandler;
+    Sa_Mask     : SigSet;
+    Sa_Flags    : cint;
+  end;
+  TSigActionRec = SigActionRec;
+  PSigActionRec = ^SigActionRec;
+

+ 54 - 0
rtl/aix/suuid.inc

@@ -0,0 +1,54 @@
+{
+    $Id: sysutils.pp,v 1.59 2005/03/25 22:53:39 jonas Exp $
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2006 by Florian Klaempfl
+    member of the Free Pascal development team
+
+    uuidgen for Solaris
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+Const
+  RandomDevice  = '/dev/urandom';
+
+
+Function GetURandomBytes(Var Buf; NBytes : Integer) : Boolean;
+
+Var
+  fd,I : Integer;
+  P : PByte;
+
+begin
+  P:=@Buf;
+  fd:=FileOpen(RandomDevice,fmOpenRead);
+  Result:=(fd>=0);
+  if Result then
+    Try
+      While (NBytes>0) do
+        begin
+        I:=FileRead(fd,P^,nbytes);
+        If I>0 then
+          begin
+          Inc(P,I);
+          Dec(NBytes,I);
+          end;
+        end;
+    Finally
+      FileClose(Fd);
+    end;
+end;
+
+
+Function SysCreateGUID(out GUID : TGUID) : Integer;
+
+begin
+  if not GetUrandomBytes(Guid,SizeOf(GUID)) then
+    GetRandomBytes(GUID,SizeOf(Guid));
+  Result:=0;
+end;

+ 103 - 0
rtl/aix/sysos.inc

@@ -0,0 +1,103 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2001 by Free Pascal development team
+
+    This file implements all the base types and limits required
+    for a minimal POSIX compliant subset required to port the compiler
+    to a new OS.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+const clib = 'c';
+
+type libcint=longint;
+     plibcint=^libcint;
+
+function geterrnolocation: Plibcint; cdecl;external clib name '_Errno';
+
+function geterrno:libcint; [public, alias: 'FPC_SYS_GETERRNO'];
+begin
+ geterrno:=geterrnolocation^;
+end;
+
+procedure seterrno(err:libcint); [public, alias: 'FPC_SYS_SETERRNO'];
+begin
+  geterrnolocation^:=err;
+end;
+
+{ OS dependant parts  }
+
+{$I errno.inc}                          // error numbers
+{$I ostypes.inc}                        // c-types, unix base types, unix base structures
+{$I osmacro.inc}
+
+{$Linklib c}
+{$i oscdeclh.inc}
+{$i oscdecl.inc}
+
+{*****************************************************************************
+                            Error conversion
+*****************************************************************************}
+
+Function PosixToRunError  (PosixErrno : longint) : longint;
+{
+  Convert ErrNo error to the correct Inoutres value
+}
+
+begin
+  if PosixErrNo=0 then { Else it will go through all the cases }
+   exit(0);
+  case PosixErrNo of
+   ESysENFILE,
+   ESysEMFILE : Inoutres:=4;
+   ESysENOENT : Inoutres:=2;
+    ESysEBADF : Inoutres:=6;
+   ESysENOMEM,
+   ESysEFAULT : Inoutres:=217;
+   ESysEINVAL : Inoutres:=218;
+    ESysEPIPE,
+    ESysEINTR,
+      ESysEIO,
+   ESysEAGAIN,
+   ESysENOSPC : Inoutres:=101;
+ ESysENAMETOOLONG : Inoutres := 3;
+    ESysEROFS,
+   ESysEEXIST,
+   ESysEACCES : Inoutres:=5;
+   ESysEISDIR : InOutRes:=5;
+  else
+    begin
+       InOutRes := Integer(PosixErrno);
+    end;
+  end;
+ PosixToRunError:=InOutRes;
+end;
+
+Function Errno2InoutRes : longint;
+
+begin
+  Errno2InoutRes:=PosixToRunError(getErrno);
+  InoutRes:=Errno2InoutRes;
+end;
+
+
+
+{*****************************************************************************
+                          Low Level File Routines
+*****************************************************************************}
+
+function do_isdevice(handle:longint):boolean;
+begin
+  do_isdevice:= (handle=StdInputHandle) or
+                (handle=StdOutputHandle) or
+                (handle=StdErrorHandle);
+end;
+
+

+ 31 - 0
rtl/aix/sysosh.inc

@@ -0,0 +1,31 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2001 by Free Pascal development team
+
+    This file implements all the base types and limits required
+    for a minimal POSIX compliant subset required to port the compiler
+    to a new OS.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+type
+  THandle = Longint;
+  TThreadID = Cardinal;
+  
+  PRTLCriticalSection = ^TRTLCriticalSection;
+  TRTLCriticalSection = record
+{$ifdef cpu64}
+      __mt_word: array[0..7] of int64;
+{$else}
+      __mt_word: array[0..12] of longint;
+{$endif}
+  end;
+
+

+ 267 - 0
rtl/aix/system.pp

@@ -0,0 +1,267 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by the Free Pascal development team.
+
+    AIX system unit
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+unit System;
+
+interface
+
+{$define FPC_IS_SYSTEM}
+
+{$linklib m}
+
+{ include system-independent routine headers }
+
+{$I sysunixh.inc}
+
+var argc:longint;
+    argv:PPchar;
+    envp:PPchar;
+
+implementation
+
+
+{ OS independant parts}
+
+{$I system.inc}
+
+{*****************************************************************************
+                       Misc. System Dependent Functions
+*****************************************************************************}
+
+procedure pascalmain;cdecl;external name 'PASCALMAIN';
+
+procedure FPC_SYSTEMMAIN(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];
+
+begin
+  argc:=argcparam;
+  argv:=argvparam;
+  envp:=envpparam;
+  pascalmain;  {run the pascal main program}
+end;
+
+
+procedure System_exit;
+begin
+   Fpexit(cint(ExitCode));
+End;
+
+
+Function ParamCount: Longint;
+Begin
+  Paramcount:=argc-1
+End;
+
+
+function BackPos(c:char; const s: shortstring): integer;
+var
+ i: integer;
+Begin
+  for i:=length(s) downto 0 do
+    if s[i] = c then break;
+  if i=0 then
+    BackPos := 0
+  else
+    BackPos := i;
+end;
+
+
+function paramstr(l: longint) : string;
+ var
+  s: string;
+  s1: string;
+ begin
+   { stricly conforming POSIX applications  }
+   { have the executing filename as argv[0] }
+     if (l < argc) then
+       paramstr:=strpas(argv[l])
+     else
+       paramstr:='';
+ end;
+
+Procedure Randomize;
+Begin
+  randseed:=longint(Fptime(nil));
+End;
+
+
+{*****************************************************************************
+                         SystemUnit Initialization
+*****************************************************************************}
+
+function  reenable_signal(sig : longint) : boolean;
+var
+  e,oe : TSigSet;
+  i,j : byte;
+  olderrno: cint;
+begin
+  fillchar(e,sizeof(e),#0);
+  fillchar(oe,sizeof(oe),#0);
+  { set is 1 based PM }
+  dec(sig);
+  i:=sig mod sizeof(clong);
+  j:=sig div sizeof(clong);
+  e[j]:=1 shl i;
+  { this routine is called from a signal handler, so must not change errno }
+  olderrno:=geterrno;
+  fpsigprocmask(SIG_UNBLOCK,@e,@oe);
+  reenable_signal:=geterrno=0;
+  seterrno(olderrno);
+end;
+
+{$i sighnd.inc}
+
+procedure InstallDefaultSignalHandler(signum: longint; out oldact: SigActionRec); public name '_FPC_INSTALLDEFAULTSIGHANDLER';
+var
+  act: SigActionRec;
+begin
+  { Initialize the sigaction structure }
+  { all flags and information set to zero }
+  FillChar(act, sizeof(SigActionRec),0);
+  { initialize handler                    }
+  act.sa_handler:=@SignalToRunError;
+  act.sa_flags:=SA_SIGINFO;
+  FpSigAction(signum,act,oldact);
+end;
+
+var
+  oldsigfpe: SigActionRec; public name '_FPC_OLDSIGFPE';
+  oldsigsegv: SigActionRec; public name '_FPC_OLDSIGSEGV';
+  oldsigbus: SigActionRec; public name '_FPC_OLDSIGBUS';
+  oldsigill: SigActionRec; public name '_FPC_OLDSIGILL';
+
+Procedure InstallSignals;
+begin
+  InstallDefaultSignalHandler(SIGFPE,oldsigfpe);
+  InstallDefaultSignalHandler(SIGSEGV,oldsigsegv);
+  InstallDefaultSignalHandler(SIGBUS,oldsigbus);
+  InstallDefaultSignalHandler(SIGILL,oldsigill);
+end;
+
+Procedure RestoreOldSignalHandlers;
+begin
+  FpSigAction(SIGFPE,@oldsigfpe,nil);
+  FpSigAction(SIGSEGV,@oldsigsegv,nil);
+  FpSigAction(SIGBUS,@oldsigbus,nil);
+  FpSigAction(SIGILL,@oldsigill,nil);
+end;
+
+
+procedure SetupCmdLine;
+var
+  bufsize,
+  len,j,
+  size,i : longint;
+  found  : boolean;
+  buf    : pchar;
+
+  procedure AddBuf;
+  begin
+    reallocmem(cmdline,size+bufsize);
+    move(buf^,cmdline[size],bufsize);
+    inc(size,bufsize);
+    bufsize:=0;
+  end;
+
+begin
+  GetMem(buf,ARG_MAX);
+  size:=0;
+  bufsize:=0;
+  i:=0;
+  while (i<argc) do
+   begin
+     len:=strlen(argv[i]);
+     if len>ARG_MAX-2 then
+      len:=ARG_MAX-2;
+     found:=false;
+     for j:=1 to len do
+      if argv[i][j]=' ' then
+       begin
+         found:=true;
+         break;
+       end;
+     if bufsize+len>=ARG_MAX-2 then
+      AddBuf;
+     if found then
+      begin
+        buf[bufsize]:='"';
+        inc(bufsize);
+      end;
+     move(argv[i]^,buf[bufsize],len);
+     inc(bufsize,len);
+     if found then
+      begin
+        buf[bufsize]:='"';
+        inc(bufsize);
+      end;
+     if i<argc then
+      buf[bufsize]:=' '
+     else
+      buf[bufsize]:=#0;
+     inc(bufsize);
+     inc(i);
+   end;
+  AddBuf;
+  FreeMem(buf,ARG_MAX);
+end;
+
+
+procedure SysInitStdIO;
+begin
+  OpenStdIO(Input,fmInput,StdInputHandle);
+  OpenStdIO(Output,fmOutput,StdOutputHandle);
+  OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
+  OpenStdIO(StdOut,fmOutput,StdOutputHandle);
+  OpenStdIO(StdErr,fmOutput,StdErrorHandle);
+end;
+
+
+function GetProcessID: SizeUInt;
+begin
+ GetProcessID := SizeUInt (fpGetPID);
+end;
+
+function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
+begin
+  result := stklen;
+end;
+
+Begin
+  IsConsole := TRUE;
+  StackLength := CheckInitialStkLen(InitialStkLen);
+  StackBottom := Sptr - StackLength;
+  { Set up signals handlers (may be needed by init code to test cpu features) }
+  InstallSignals;
+
+  SysResetFPU;
+  if not(IsLibrary) then
+    SysInitFPU;
+
+{ Setup heap }
+  InitHeap;
+  SysInitExceptions;
+
+  initunicodestringmanager;
+
+{ Setup stdin, stdout and stderr }
+  SysInitStdIO;
+{ Reset IO Error }
+  InOutRes:=0;
+{ Arguments }
+  SetupCmdLine;
+  InitSystemThreads;
+  initvariantmanager;
+  { restore original signal handlers in case this is a library }
+  if IsLibrary then
+    RestoreOldSignalHandlers;
+End.

+ 41 - 0
rtl/aix/termio.pp

@@ -0,0 +1,41 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by Peter Vreman
+    member of the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This file contains the termios interface.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+unit termio;
+
+interface
+{$inline on}
+Uses UnixType,BaseUnix,ctypes;          // load base unix typing
+
+// load types + consts
+
+{$i termios.inc}
+
+// load default prototypes from unix dir.
+
+{$i termiosh.inc}
+
+implementation
+
+{$i textrec.inc}
+
+// load implementation for prototypes from current dir.
+{$i termiosproc.inc}
+
+// load ttyname from unix dir.
+{$i ttyname.inc}
+
+end.

+ 615 - 0
rtl/aix/termios.inc

@@ -0,0 +1,615 @@
+{$PACKRECORDS C}
+
+const
+  CBELL = #7;
+{ delete  }
+  CDEL = #127;
+{ ^D  }
+  CEOF = #4;
+{ ^H  }
+  CERASE = #8;
+{ back-slash  }
+  CESC = '\';
+{ ^L  }
+  CFORM = #12;
+{ ^C  }
+  CINTR = #3;
+{ ^U  }
+  CKILL = #21;
+{ null char  }
+  CNUL = #0;
+{ ^\  }
+  CQUIT = #28;
+{ ^Q  }
+  CSTART = #17;
+{ ^S  }
+  CSTOP = #19;
+{ ^K  }
+  CVT = #11;
+{
+ * Ioctl control packet
+  }
+  NCC = 8;
+
+{
+ *  Structure, defines for setting page length
+  }
+{ Set Page Length (Ioctl TCSLEN)  }
+
+const
+  PAGE_SETL = 04;
+{ Paging Ioctl Command Mask (TCSLEN)  }
+  PAGE_MSK = 03;
+{ Enable Paging (TCSLEN)  }
+  PAGE_ON = 01;
+{ Disable Paging (TCSLEN)  }
+  PAGE_OFF = 02;
+{$ifndef PAGE_ENB}
+{ For compatibility with older version  }
+
+const
+  PAGE_ENB = PAGE_ON;
+{$endif}
+type
+  Ptty_page = ^tty_page;
+  tty_page = record
+      tp_flags : char;
+      tp_slen : byte;
+    end;
+
+  twinsize = record
+    ws_row, ws_col, ws_xpixel, ws_ypixel: cushort;
+  end;
+
+
+const
+  IOC_VOID = $20000000;
+  IOC_OUT = $40000000;
+  IOC_IN  = $40000000 shl 1;
+  IOCPARM_MASK = $7f;
+
+  TIOCGETD = 	IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 0;	{ get line discipline }
+  TIOCSETD = 	IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 1;	{ set line discipline }
+  TIOCHPCL = 	IOC_VOID or (ord('t') shl 8) or 2;		{ hang up on last close }
+  TIOCMODG = 	IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 3;	{ get modem control state }
+  TIOCMODS = 	IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 4;	{ set modem control state }
+  TIOCM_LE = 	0001;		{ line enable }
+  TIOCM_DTR = 	0002;		{ data terminal ready }
+  TIOCM_RTS = 	0004;		{ request to send }
+  TIOCM_ST = 	0008;		{ secondary transmit }
+  TIOCM_SR = 	0016;		{ secondary receive }
+  TIOCM_CTS = 	0032;		{ clear to send }
+  TIOCM_CAR = 	0064;		{ carrier detect }
+  TIOCM_CD = 	TIOCM_CAR;
+  TIOCM_RNG = 	0128;		{ ring }
+  TIOCM_RI = 	TIOCM_RNG;
+  TIOCM_DSR = 	0256;		{ data set ready }
+//  TIOCGETP = 	IOC_OUT or ((sizeof(struct sgttyb) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 8{ get parameters -- gtty }
+//  TIOCSETP = 	IOC_IN or ((sizeof(struct sgttyb) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 9{ set parameters -- stty }
+//  TIOCSETN = 	IOC_IN or ((sizeof(struct sgttyb) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 10{ as above, but no flushtty }
+  TIOCEXCL = 	IOC_VOID or (ord('t') shl 8) or 13;		{ set exclusive use of tty }
+  TIOCNXCL = 	IOC_VOID or (ord('t') shl 8) or 14;		{ reset exclusive use of tty }
+  TIOCFLUSH = 	IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 16;	{ flush buffers }
+//  TIOCSETC = 	IOC_IN or ((sizeof(struct tchars) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 17{ set special characters }
+//  TIOCGETC = 	IOC_OUT or ((sizeof(struct tchars) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 18{ get special characters }
+  TANDEM = 		$00000001;	{ send stopc on out q full }
+  CBREAK = 		$00000002;	{ half-cooked mode }
+  LCASE = 		$00000004;	{ simulate lower case }
+
+  ECHO = 		$00000008;	{ echo input }
+
+  CRMOD = 		$00000010;	{ map \r to \r\n on output }
+  RAW = 		$00000020;	{ no i/o processing }
+  ODDP = 		$00000040;	{ get/send odd parity }
+  EVENP = 		$00000080;	{ get/send even parity }
+  ANYP = 		$000000c0;	{ get any parity/send none }
+  CRDELAY = 		$00000300;	{ \r delay }
+  CR0 = 	$00000000;
+  CR1 = 	$00000100;	{ tn 300 }
+  CR2 = 	$00000200;	{ tty 37 }
+  CR3 = 	$00000300;	{ concept 100 }
+  TBDELAY = 		$00000c00;	{ horizontal tab delay }
+  TAB0 = 	$00000000;
+
+  TAB1 = 	$00000400;	{ tty 37 }
+  TAB2 = 	$00000800;
+
+  XTABS = 		$00000c00;	{ expand tabs on output }
+  BSDELAY = 		$00001000;	{ \b delay }
+  BS0 = 	$00000000;
+
+  BS1 = 	$00001000;
+
+  VTDELAY = 		$00002000;	{ vertical tab delay }
+  FF0 = 	$00000000;
+
+  FF1 = 	$00002000;	{ tty 37 }
+
+  NLDELAY = 		$0000c000;	{ \n delay }
+
+  NL0 = 	$00000000;
+  NL1 = 	$00004000;	{ tty 37 }
+  NL2 = 	$00008000;	{ vt05 }
+  NL3 = 	$0000c000;
+
+  ALLDELAY = 	(NLDELAY or TBDELAY or CRDELAY or VTDELAY or BSDELAY);
+
+  TOSTOP = 		$00010000;	{ SIGSTOP on bckgnd output }
+
+  PRTERA = 		$00020000;	{ \ ... / erase }
+  CRTERA = 		$00040000;	{ " \b " to wipe out char }
+  TILDE = 		$00080000;	{ hazeltine tilde kludge }
+
+  FLUSHO = 		$00100000;	{ flush output to terminal }
+
+  LITOUT = 		$00200000;	{ literal output }
+  CRTBS = 		$00400000;	{ do backspacing for crt }
+  MDMBUF = 		$00800000;	{ dtr pacing }
+  NOHANG = 		$01000000;	{ no SIGHUP on carrier drop }
+  L001000 = 		$02000000;
+  CRTKIL = 		$04000000;	{ kill line with " \b " }
+  PASS8 = 		$08000000;
+  CTLECH = 		$10000000;	{ echo control chars as ^X }
+
+  PENDIN = 		$20000000;	{ tp->t_rawq needs reread }
+
+  DECCTQ = 		$40000000;	{ only ^Q starts after ^S }
+  NOFLUSH = 		$80000000;	{ no output flush on signal }
+
+
+{ SYS V REL. 4 PTY IOCTLs    }
+  UNLKPT =           IOC_VOID or (ord('t') shl 8) or 70;             { unlock slave pty }
+  ISPTM =            IOC_VOID or (ord('t') shl 8) or 71;             { ret. maj+min of pty master }
+  ISPTS =            IOC_VOID or (ord('t') shl 8) or 73;             { return maj+min of slave }
+  GRTPT =            IOC_VOID or (ord('t') shl 8) or 74;             { grantpt slave pty}
+  RLOGIND =          IOC_VOID or (ord('t') shl 8) or 75;             { for rlogind protocol in ptydd }
+  TELNETDP =         IOC_VOID or (ord('t') shl 8) or 76;             { for telnetd protocol in ptydd }
+
+  TIOCCONS = 	IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 98;	{ become virtual console }
+  TIOCGSID = 	IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 72;	{ get the tty session id }
+
+
+  TIOCLBIS =         IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 127;     { bis local mode bits }
+  TIOCLBIC =         IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 126;     { bic local mode bits }
+  TIOCLSET =         IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 125;     { set entire mode word }
+  TIOCLGET =         IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 124;     { get local modes }
+  LCRTBS =           (CRTBS>>16);
+  LPRTERA =          (PRTERA>>16);
+  LCRTERA =          (CRTERA>>16);
+  LTILDE =           (TILDE>>16);
+  LMDMBUF =          (MDMBUF>>16);
+  LLITOUT =          (LITOUT>>16);
+  LTOSTOP =          (TOSTOP>>16);
+  LFLUSHO =          (FLUSHO>>16);
+  LNOHANG =          (NOHANG>>16);
+  LCRTKIL =          (CRTKIL>>16);
+  LPASS8 =           (PASS8>>16);
+  LCTLECH =          (CTLECH>>16);
+  LPENDIN =          (PENDIN>>16);
+  LDECCTQ =          (DECCTQ>>16);
+  LNOFLSH =          (NOFLUSH>>16);
+  TIOCSBRK =         IOC_VOID or (ord('t') shl 8) or 123;           { set break bit }
+  TIOCCBRK =         IOC_VOID or (ord('t') shl 8) or 122;           { clear break bit }
+  TIOCSDTR =         IOC_VOID or (ord('t') shl 8) or 121;           { set data terminal ready }
+  TIOCCDTR =         IOC_VOID or (ord('t') shl 8) or 120;           { clear data terminal ready }
+  TIOCGPGRP =        IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 119;     { get process group }
+  TIOCSPGRP =        IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 118;      { set process group }
+//  TIOCSLTC =         IOC_IN or ((sizeof(struct ltchars) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 117{ set local special chars }
+//  TIOCGLTC =         IOC_OUT or ((sizeof(struct ltchars) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 116{ get local special chars }
+  TIOCOUTQ =         IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 115;     { output queue size }
+  TIOCSTI =          IOC_IN or ((sizeof(char) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 114;    { simulate terminal input }
+  TIOCNOTTY =        IOC_VOID or (ord('t') shl 8) or 113;           { void tty association }
+  TIOCPKT =          IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 112;     { pty: set/clear packet mode }
+  TIOCPKT_DATA =             $00;    { data packet }
+  TIOCPKT_FLUSHREAD =        $01;    { flush packet }
+  TIOCPKT_FLUSHWRITE =       $02;    { flush packet }
+  TIOCPKT_STOP =             $04;    { stop output }
+  TIOCPKT_START =            $08;    { start output }
+  TIOCPKT_NOSTOP =           $10;    { no more ^S, ^Q }
+  TIOCPKT_DOSTOP =           $20;    { now do ^S ^Q }
+  TIOCSTOP =         IOC_VOID or (ord('t') shl 8) or 111;           { stop output, like ^S }
+  TIOCSTART =        IOC_VOID or (ord('t') shl 8) or 110;           { start output, like ^Q }
+  TIOCMSET =         IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 109;     { set all modem bits }
+  TIOCMBIS =         IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 108;     { bis modem bits }
+  TIOCMGET =         IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 106;     { get all modem bits }
+  TIOCREMOTE =       IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 105;     { remote input editing }
+  TIOCGWINSZ =       IOC_OUT or ((sizeof(twinsize) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 104;  { get window size }
+  TIOCSWINSZ =       IOC_IN or ((sizeof(twinsize) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 103;  { set window size }
+  TIOCUCNTL =        IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 102;     { pty: set/clr usr cntl mode }
+  TIOCMIWAIT =       IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 100;     { wait for modem stat change }
+{ SLIP (Serial Line IP) ioctl's }
+  SLIOCGUNIT =       IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 101;     { get slip unit number }
+  SLIOCSFLAGS =      IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 89;      { set configuration flags }
+  SLIOCGFLAGS =      IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 90;      { get configuration flags }
+  SLIOCSATTACH =     IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('t') shl 8) or 91;     { Attach slip i.f. to tty  }
+//  UIOCCMD(n) =       IOC_VOID or (ord('u') shl 8) or n;             { usr cntl op "n" }
+
+  OTTYDISC =         0;               { old, v7 std tty driver }
+  NETLDISC =         1;               { line discip for berk net }
+  NTTYDISC =         2;               { new tty discipline }
+  TABLDISC =         3;               { tablet discipline }
+  SLIPDISC =         4;               { serial IP discipline }
+
+  FIOCLEX =          IOC_VOID or (ord('f') shl 8) or 1;             { set close on exec    }
+  FIONCLEX =         IOC_VOID or (ord('f') shl 8) or 2;             { clear close on exec  }
+{ another local }
+
+  FIONREAD =         IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('f') shl 8) or 127;     { get # bytes to read }
+  FIONBIO =          IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('f') shl 8) or 126;     { set/clear non-blocking i/o }
+  FIOASYNC =         IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('f') shl 8) or 125;     { set/clear async i/o }
+
+  FIOSETOWN =        IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('f') shl 8) or 124;     { set owner }
+  FIOGETOWN =        IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('f') shl 8) or 123;     { get owner }
+  FIOASYNCQX =       IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('f') shl 8) or 122;     { set/clear async queueing }
+
+{ socket i/o controls }
+  SIOCSHIWAT =       IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('s') shl 8) or 0;              { set high watermark }
+  SIOCGHIWAT =       IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('s') shl 8) or 1;              { get high watermark }
+  SIOCSLOWAT =       IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('s') shl 8) or 2;              { set low watermark }
+  SIOCGLOWAT =       IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('s') shl 8) or 3;              { get low watermark }
+  SIOCATMARK =       IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('s') shl 8) or 7;              { at oob mark? }
+  SIOCSPGRP =        IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('s') shl 8) or 8;              { set process group }
+  SIOCGPGRP =        IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('s') shl 8) or 9;              { get process group }
+
+//  SIOCADDRT =        cint(IOC_IN or ((sizeof(struct ortentry) and IOCPARM_MASK) shl 16) or (ord('r') shl 8) or 10);     { add route }
+//  SIOCDELRT =        cint(IOC_IN or ((sizeof(struct ortentry) and IOCPARM_MASK) shl 16) or (ord('r') shl 8) or 11);     { delete route }
+
+//  SIOCSIFADDR =      cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 12);       { set ifnet address }
+//  OSIOCGIFADDR =     (int)_IOWR('i',13, struct oifreq);       { get ifnet address }
+//  SIOCGIFADDR =      (int)_IOWR('i',33, struct oifreq);       { get ifnet address }
+  SIOCGIFADDRS =     cint(IOC_VOID or (ord('i') shl 8) or 140);       { get ifnet addresses for an if}
+//  SIOCSIFDSTADDR =   cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 14);       { set p-p address }
+//  OSIOCGIFDSTADDR =  (int)_IOWR('i',15, struct oifreq);       { get p-p address }
+//  SIOCGIFDSTADDR =   (int)_IOWR('i',34, struct oifreq);       { get p-p address }
+//  SIOCSIFFLAGS =     cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 16);       { set ifnet flags }
+//  SIOCGIFFLAGS =     (int)_IOWR('i',17, struct oifreq);       { get ifnet flags }
+//  OSIOCGIFBRDADDR =  (int)_IOWR('i',18, struct oifreq);       { get broadcast addr }
+//  SIOCGIFBRDADDR =   (int)_IOWR('i',35, struct oifreq);       { get broadcast addr }
+//  SIOCSIFBRDADDR =   cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 19);        { set broadcast addr }
+//  OSIOCGIFCONF =     (int)_IOWR('i',20, struct ifconf);       { get ifnet list }
+//  CSIOCGIFCONF =     (int)_IOWR('i',36, struct ifconf);       { get ifnet list }
+//  SIOCGIFCONF =      (int)_IOWR('i',69, struct ifconf);       { get ifnet list }
+//  OSIOCGIFNETMASK =  (int)_IOWR('i',21, struct oifreq);       { get net addr mask }
+//  SIOCGIFNETMASK =   (int)_IOWR('i',37, struct oifreq);       { get net addr mask }
+//  SIOCSIFNETMASK =   cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 22);        { set net addr mask }
+//  SIOCGIFMETRIC =    (int)_IOWR('i',23, struct oifreq);       { get IF metric }
+//  SIOCSIFMETRIC =    cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 24);        { set IF metric }
+//  SIOCDIFADDR =      cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 25);        { delete IF addr }
+//  SIOCAIFADDR =      cint(IOC_IN or ((sizeof(struct ifaliasreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 26);    { add/chg IF alias }
+//  SIOCSIFSUBCHAN =   cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 27);        { set subchannel adr.}
+//  SIOCSIFNETDUMP =   cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 28);        { set netdump fastwrt}
+
+//  SIOUPDROUTE =      cint(IOC_IN or ((sizeof(struct ifaliasreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 29);    { Update Routing table }
+//  SIOCSARP =         cint(IOC_IN or ((sizeof(struct arpreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 30);       { set arp entry }
+//  OSIOCGARP =        (int)_IOWR('i',31, struct arpreq);       { get arp entry }
+//  SIOCGARP =         (int)_IOWR('i',38, struct arpreq);       { get arp entry }
+//  SIOCDARP =         cint(IOC_IN or ((sizeof(struct arpreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 32);       { delete arp entry }
+
+//  SIOCSIFOPTIONS =   cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 41);       { set ifnet options }
+//  SIOCGIFOPTIONS =   (int)_IOWR('i',42, struct oifreq);       { get ifnet options }
+//  SIOCADDMULTI =     cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 49);        { add multicast addr }
+//  SIOCDELMULTI =     cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 50);        { del multicast addr }
+//  SIOCGETVIFCNT =    (int)_IOWR('u', 51, struct sioc_vif_req){ vif pkt cnt }
+//  SIOCGETSGCNT =     (int)_IOWR('u', 52, struct sioc_sg_req); { s,g pkt cnt }
+
+//  SIOCADDNETID =     cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 87);        { set netids }
+//  SIOCSIFMTU =       cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 88);        { set mtu }
+//  SIOCGIFMTU =       (int)_IOWR('i',86, struct oifreq);       { get mtu }
+
+//  SIOCSNETOPT =      cint(IOC_IN or ((sizeof(struct optreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 90); { set network option }
+//  SIOCGNETOPT =      (int)_IOWR('i', 91, struct optreq); { get network option }
+//  SIOCDNETOPT =      (int)_IOWR('i', 128, struct optreq); { set default }
+//  SIOCGNETOPT1 =     (int)_IOWR('i', 129, struct optreq1); { get network option }
+//  SIOCGLOADF =       (int)_IOWR('i', 130, int); { get flag: if loadtime passed }
+//  SIOCSLOADF =       (int)_IOWR('i', 131, int); { set flag: if loadtime passed }
+//  SIOCGTUNEPHASE =   (int)_IOWR('i', 138, int); { get tuning_phase }
+
+//  SIOCSX25XLATE =    cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 99);       { set xlate tab }
+//  SIOCGX25XLATE =    (int)_IOWR('i',100, struct oifreq);      { get xlate tab }
+//  SIOCDX25XLATE =    cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 101);      { delete xlate tab }
+
+//  SIOCIFDETACH =     cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 102);       { detach an ifnet }
+//  SIOCIFATTACH =     cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 103);       { attach an ifnet }
+
+  SIOCGNMTUS =       cint(IOC_VOID or (ord('i') shl 8) or 110); { get NMTUs }
+  SIOCGETMTUS =      cint(IOC_VOID or (ord('i') shl 8) or 111); { get common_mtus }
+  SIOCADDMTU =       cint(IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 112); { add mtu  }
+  SIOCDELMTU =       cint(IOC_IN or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 113); { delete mtu }
+
+  SIOCGIFGIDLIST =   cint(IOC_VOID or (ord('i') shl 8) or 104);                   { get gidlist }
+  SIOCSIFGIDLIST =   cint(IOC_VOID or (ord('i') shl 8) or 105);                   { set gidlist }
+
+  SIOCGSIZIFCONF =   cint(IOC_OUT or ((sizeof(cint) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 106); { get size for SIOCGIFCONF }
+
+//  SIOCIF_ATM_UBR =           cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 120);  { set ubr rate }
+//  SIOCIF_ATM_SNMPARP =       cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 121);  { atm snmp arp }
+//  SIOCIF_ATM_IDLE =          cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 122);  { set idle time }
+//  SIOCIF_ATM_DUMPARP =       cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 123);  { atm dump arp }
+//  SIOCIF_ATM_SVC =           cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 124);  { atmif init }
+//  SIOCIF_ATM_DARP =          cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 125);  { del atmarp }
+//  SIOCIF_ATM_GARP =          cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 126);  { get atmarp }
+//  SIOCIF_ATM_SARP =          cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 127);  { set atmarp };
+
+{ For IP over Infiniband }
+
+//  SIOCIF_IB_DUMP_ARP =       cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 128); { ib dump arp }
+//  SIOCIF_IB_DEL_ARP =        cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 129); { if_ib del  ibarp }
+//  SIOCIF_IB_GET_ARP =        cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 130); { get ibarp }
+//  SIOCIF_IB_SET_ARP =        cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 131); { set ibarp }
+//  SIOCIF_IB_SET_PKEY =       cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 132); { set ib port  pkey value }
+//  SIOCIFGETPKEY =            cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 101); { set ubr rate }
+//  SIOCIF_IB_SET_PORT =       cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 133); { set ubr rate }
+//  SIOCIF_IB_SET_QSIZE =      cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 134); { set ib qsize  }
+//  SIOCIF_IB_RESIZE_CQ =      cint(IOC_IN or ((sizeof(struct ifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 135); { set resize IB CQ  }
+
+
+
+
+//  SIOCGISNO =        (int)_IOWR('i',107, struct oifreq);      { get IF network options }
+//  SIOCSISNO =        cint(IOC_IN or ((sizeof(struct oifreq) and IOCPARM_MASK) shl 16) or (ord('i') shl 8) or 108);      { set IF network options }
+//  SIOCGIFBAUDRATE =  (int)_IOWR('i', 109, struct oifreq);     { get ifnet's if_baudrate }
+
+  SIOCADDIFVIPA =    cint(IOC_VOID or (ord('i') shl 8) or 66);       { specify interfaces that should use this vipa }
+  SIOCDELIFVIPA =    cint(IOC_VOID or (ord('i') shl 8) or 67);       { unconfigure interfaces using this vipa       }
+  SIOCLISTIFVIPA =   cint(IOC_VOID or (ord('i') shl 8) or 68);       { list interfaces using this vipa              }
+
+  TIOC = ord('T') shl 8;
+  TCGETS = TIOC or 1;
+  TCSETS = TIOC or 2;
+  TCSETSW = TIOC or 3;
+  TCSETSF = TIOC or 4;
+  TCGETA = TIOC or 5;
+  TCSETA = TIOC or 6;
+  TCSETAW = TIOC or 7;
+  TCSETAF = TIOC or 8;
+{ SVID interface  }
+  TCSBRK = TIOC or 9;
+{ 0->.25 seconds else <arg>ms  }
+  TCSBREAK = TIOC or 10;
+  TCXONC = TIOC or 11;
+  TCFLSH = TIOC or 12;
+  TCGLEN = TIOC or 13;
+  TCSLEN = TIOC or 14;
+  TCSAK = TIOC or 15;
+  TCQSAK = TIOC or 16;
+  TCTRUST = TIOC or 17;
+  TCQTRUST = TIOC or 18;
+  TCSMAP = TIOC or 19;
+  TCGMAP = TIOC or 20;
+  TCKEP = TIOC or 21;
+  TCGSAK = TIOC or 22;
+  TCLOOP = TIOC or 23;
+  TCVPD = TIOC or 24;
+  TCREG = TIOC or 25;
+  TCGSTATUS = TIOC or 26;
+  TCSCONTROL = TIOC or 27;
+  TCSCSMAP = TIOC or 28;
+  TCGCSMAP = TIOC or 29;
+  TCMGR = TCSAK;
+  TCQMGR = TCQSAK;
+  TIONREAD = FIONREAD;
+{ used with TCSAK and TCQSAK  }
+  TCSAKOFF = 0;
+  TCSAKON = 1;
+{ used with TCTRUST and TCQTRUCT  }
+  TCUNTRUSTED = 0;
+  TCTRUSTED = 1;
+
+
+type
+  Ptcflag_t = ^tcflag_t;
+  tcflag_t = dword;
+
+  Pcc_t = ^cc_t;
+  cc_t = byte;
+
+const
+  NCCS = 16;  
+type
+  Pspeed_t = ^speed_t;
+  speed_t = dword;
+{
+ * Ioctl control packet
+  }
+{ input modes  }
+{ output modes  }
+{ control modes  }
+{ line discipline modes  }
+{ control chars  }
+  Ptermios = ^termios;
+  termios = record
+      c_iflag : tcflag_t;
+      c_oflag : tcflag_t;
+      c_cflag : tcflag_t;
+      c_lflag : tcflag_t;
+      c_cc : array[0..(NCCS)-1] of cc_t;
+    end;
+
+{ use POSIX required prototypes  }
+function tcgetattr(_para1:longint; var _para2:termios):longint;cdecl;external;
+function tcgetsid(_para1:longint):pid_t;cdecl;external;
+(* Const before type ignored *)
+
+function tcsetattr(_para1:longint; _para2:longint; constref _para3:termios):longint;cdecl;external;
+//function tcsendbreak(_para1:longint; _para2:longint):longint;cdecl;external;
+//function tcdrain(_para1:longint):longint;cdecl;external;
+//function tcflush(_para1:longint; _para2:longint):longint;cdecl;external;
+///function tcflow(_para1:longint; _para2:longint):longint;cdecl;external;
+(* Const before type ignored *)
+function cfgetospeed(var _para1:termios):speed_t;cdecl;external;
+(* Const before type ignored *)
+function cfgetispeed(var _para1:termios):speed_t;cdecl;external;
+function cfsetospeed(constref _para1:termios; _para2:speed_t):longint;cdecl;external;
+function cfsetispeed(var _para1:termios; _para2:speed_t):longint;cdecl;external;
+
+{ mask name symbols for c_lflag  }
+{ values for optional_actions arguments to tcsetattr()  }
+
+const
+  TCSANOW = 0;  
+  TCSADRAIN = 1;  
+  TCSAFLUSH = 2;  
+{ values for the queue_selector argument to tcflush()  }
+  TCIFLUSH = 0;  
+  TCOFLUSH = 1;  
+  TCIOFLUSH = 2;  
+{ values for the action argument to tcflow()  }
+  TCOOFF = 0;  
+  TCOON = 1;  
+  TCIOFF = 2;  
+  TCION = 3;  
+{ control characters  }
+  VINTR = 0;  
+  VQUIT = 1;  
+  VERASE = 2;  
+  VKILL = 3;  
+  VEOF = 4;  
+  VEOL = 5;  
+  VSTART = 7;  
+  VSTOP = 8;  
+  VSUSP = 9;  
+  VMIN = 4;  
+  VTIME = 5;  
+  VEOL2 = 6;  
+  VDSUSP = 10;  
+  VREPRINT = 11;  
+  VDISCRD = 12;  
+  VWERSE = 13;  
+  VLNEXT = 14;  
+{ 5.4 compatability  }
+  VSTRT = VSTART;  
+
+const
+  B0 = $00000000;  
+  B50 = $00000001;  
+  B75 = $00000002;  
+  B110 = $00000003;  
+  B134 = $00000004;  
+  B150 = $00000005;  
+  B200 = $00000006;  
+  B300 = $00000007;  
+  B600 = $00000008;  
+  B1200 = $00000009;  
+  B1800 = $0000000a;  
+  B2400 = $0000000b;  
+  B4800 = $0000000c;  
+  B9600 = $0000000d;  
+  B19200 = $0000000e;  
+  B38400 = $0000000f;  
+  EXTA = B19200;  
+  EXTB = B38400;  
+{ _ALL_SOURCE  }
+{ c_iflag bits  }
+
+const
+  IGNBRK = $00000001;  
+  BRKINT = $00000002;  
+  IGNPAR = $00000004;  
+  PARMRK = $00000008;  
+  INPCK = $00000010;  
+  ISTRIP = $00000020;  
+  INLCR = $00000040;  
+  IGNCR = $00000080;  
+  ICRNL = $00000100;  
+  IXON = $00000200;  
+  IXOFF = $00000400;  
+const
+  IUCLC = $00000800;  
+
+const
+  IXANY = $00001000;  
+  IMAXBEL = $00010000;  
+{ c_oflag bits  }
+
+const
+  OPOST = $00000001;  
+const
+  OLCUC = $00000002;  
+
+const
+  ONLCR = $00000004;  
+  OCRNL = $00000008;  
+  ONOCR = $00000010;  
+  ONLRET = $00000020;  
+  OFILL = $00000040;  
+  OFDEL = $00000080;  
+  CRDLY = $00000300;  
+//  CR0 = $00000000;
+//  CR1 = $00000100;
+//  CR2 = $00000200;
+//  CR3 = $00000300;
+  TABDLY = $00000c00;  
+//  TAB0 = $00000000;
+//  TAB1 = $00000400;
+//  TAB2 = $00000800;
+//  TAB3 = $00000c00;
+  BSDLY = $00001000;  
+//  BS0 = $00000000;
+//  BS1 = $00001000;
+  FFDLY = $00002000;  
+//  FF0 = $00000000;
+//  FF1 = $00002000;
+  NLDLY = $00004000;  
+//  NL0 = $00000000;
+//  NL1 = $00004000;
+  VTDLY = $00008000;  
+  VT0 = $00000000;  
+  VT1 = $00008000;  
+  DLY_MASK = ((((NLDLY or CRDLY) or TABDLY) or BSDLY) or VTDLY) or FFDLY;  
+{ expand tabs to spaces added     	 }
+  OXTABS = $00040000;  
+{ on 08/05/92.                          }
+{ discard EOT's (^D) on output    	 }
+  ONOEOT = $00080000;  
+{ added on 08/05/92.                    }
+{ c_cflag bits  }
+
+const
+  _CBAUD = $0000000f;  
+  CBAUD = _CBAUD;
+  CSIZE = $00000030;
+  CS5 = $00000000;  
+  CS6 = $00000010;  
+  CS7 = $00000020;  
+  CS8 = $00000030;  
+  CSTOPB = $00000040;  
+  CREAD = $00000080;  
+  PARENB = $00000100;  
+  PARODD = $00000200;  
+  HUPCL = $00000400;  
+  CLOCAL = $00000800;  
+  _CIBAUD = $000f0000;  
+  _IBSHIFT = 16;  
+  CIBAUD = _CIBAUD;  
+  IBSHIFT = _IBSHIFT;  
+  PAREXT = $00100000;  
+{ c_lflag bits  }
+
+const
+  ISIG = $00000001;  
+  ICANON = $00000002;  
+
+const
+  XCASE = $00000004;  
+
+const
+//  ECHO = $00000008;
+  ECHOE = $00000010;  
+  ECHOK = $00000020;  
+  ECHONL = $00000040;  
+  NOFLSH = $00000080;  
+//  TOSTOP = $00010000;
+  ECHOCTL = $00020000;  
+  ECHOPRT = $00040000;  
+  ECHOKE = $00080000;  
+//  FLUSHO = $00100000;
+{ use alternate WERASE    	 }
+  ALTWERASE = $00400000;  
+{ algorithm, added ALTWERASE    }
+{ on 08/05/92.                  }
+//  PENDIN = $20000000;
+{ ALL_SOURCE  }
+
+const
+  IEXTEN = $00200000;  
+

+ 100 - 0
rtl/aix/termiosproc.inc

@@ -0,0 +1,100 @@
+{
+   This file is part of the Free Pascal run time library.
+   (c) 2000-2003 by Marco van de Voort
+   member of the Free Pascal development team.
+
+   See the file COPYING.FPC, included in this distribution,
+   for details about the copyright.
+
+   Termios implementation for FreeBSD
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY;without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+}
+
+
+{******************************************************************************
+                         IOCtl and Termios calls
+******************************************************************************}
+
+Procedure CFMakeRaw(var tios:TermIOS);
+begin
+  with tios do
+   begin
+     c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
+                PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
+                IGNPAR));
+     c_iflag:=c_iflag OR IGNBRK;
+     c_oflag:=c_oflag and (not OPOST);
+     c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
+                                ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
+     c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
+     c_cc[VMIN]:=1;
+     c_cc[VTIME]:=0;
+   end;
+end;
+
+
+Function real_tcsendbreak(fd,duration:cint):cint;cdecl;external name 'tcsendbreak';
+
+Function TCSendBreak(fd,duration:cint):cint; {$ifdef VER2_0}inline;{$endif}
+begin
+  TCSendBreak:=real_tcsendbreak(fd,duration);
+end;
+
+
+
+Function TCSetPGrp(fd,id:cint):cint; {$ifdef VER2_0}inline;{$endif}
+begin
+  TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(id));
+end;
+
+
+Function TCGetPGrp(fd:cint;var id:cint):cint; {$ifdef VER2_0}inline;{$endif}
+begin
+  TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
+end;
+
+Function real_tcdrain(fd:cint):cint;cdecl;external name 'tcdrain';
+
+Function  TCDrain(fd:cint)     :cint;inline;
+begin
+  TCDrain:=real_tcdrain(fd);
+end;
+
+
+Function real_tcflow(fd,act:cint):cint;cdecl;external name 'tcflow';
+
+Function  TCFlow(fd,act:cint) :cint;inline;
+begin
+  TCFlow:=real_tcflow(fd,act);
+end;
+
+
+Function real_tcflush(fd,qsel:cint):cint;cdecl;external name 'tcflush';
+
+Function  TCFlush(fd,qsel:cint):cint; inline;
+begin
+  TCFlush:=real_tcflush(fd,qsel);
+end;
+
+Function IsATTY (Handle:cint):cint;
+{
+  Check if the filehandle described by 'handle' is a TTY (Terminal)
+}
+var
+  t : Termios;
+begin
+ IsAtty:=ord(TCGetAttr(Handle,t) <> -1);
+end;
+
+
+Function IsATTY(var f: text):cint; {$ifdef VER2_0}inline;{$endif}
+{
+  Idem as previous, only now for text variables.
+}
+begin
+  IsATTY:=IsaTTY(textrec(f).handle);
+end;
+

+ 85 - 0
rtl/aix/unxconst.inc

@@ -0,0 +1,85 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by Michael Van Canneyt,
+    member of the Free Pascal development team.
+
+    Constants for Unix unit.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+
+const
+
+  { Things for LSEEK call}
+  Seek_set = 0;
+  Seek_Cur = 1;
+  Seek_End = 2;
+
+  { Things for OPEN call - after include/sys/fcntl.h,
+   BSD specifies these constants in hex }
+  Open_Accmode  = 3;
+  Open_RdOnly   = 0;
+  Open_WrOnly   = 1;
+  Open_RdWr     = 2;
+  Open_NonBlock = 4;
+  Open_Append   = 8;
+//  Open_ShLock   = $10;
+//  Open_ExLock   = $20;
+//  Open_ASync    = $40;
+//  Open_FSync    = $80;
+//  Open_NoFollow = $100;
+  Open_Create   = $100;       {BSD convention}
+  Open_Creat    = $100;       {Linux convention}
+  Open_Trunc    = $200;
+  Open_Excl     = $400;
+  Open_NoCTTY   = $800;
+
+  { The waitpid uses the following options:}
+  Wait_NoHang   = 1;
+  Wait_UnTraced = 2;
+  Wait_Any      = -1;
+  Wait_MyPGRP   = 0;
+
+
+  { Constants to check stat.mode -  checked all STAT constants with BSD}
+  STAT_IFMT   = $f000; {00170000 }
+  STAT_IFSOCK = $c000; {0140000 }
+  STAT_IFLNK  = $a000; {0120000 }
+  STAT_IFREG  = $8000; {0100000 }
+  STAT_IFBLK  = $6000; {0060000 }
+  STAT_IFDIR  = $4000; {0040000 }
+  STAT_IFCHR  = $2000; {0020000 }
+  STAT_IFIFO  = $1000; {0010000 }
+  STAT_ISUID  = $0800; {0004000 }
+  STAT_ISGID  = $0400; {0002000 }
+  STAT_ISVTX  = $0200; {0001000}
+  { Constants to check permissions all }
+  STAT_IRWXO = $7;
+  STAT_IROTH = $4;
+  STAT_IWOTH = $2;
+  STAT_IXOTH = $1;
+
+  STAT_IRWXG = STAT_IRWXO shl 3;
+  STAT_IRGRP = STAT_IROTH shl 3;
+  STAT_IWGRP = STAT_IWOTH shl 3;
+  STAT_IXGRP = STAT_IXOTH shl 3;
+
+  STAT_IRWXU = STAT_IRWXO shl 6;
+  STAT_IRUSR = STAT_IROTH shl 6;
+  STAT_IWUSR = STAT_IWOTH shl 6;
+  STAT_IXUSR = STAT_IXOTH shl 6;
+
+  {Constansts Termios/Ioctl (used in Do_IsDevice) }
+  IOCtl_TCGETS= (ord('T') shl 8) or 1; // TCGETS is also in termios.inc, but the sysunix needs only this
+
+  ITimer_Real    =0;
+  ITimer_Virtual =1;
+  ITimer_Prof    =2;
+

+ 142 - 0
rtl/aix/unxfunc.inc

@@ -0,0 +1,142 @@
+{
+   This file is part of the Free Pascal run time library.
+   Copyright (c) 2000 by Marco van de Voort
+     member of the Free Pascal development team.
+
+   See the file COPYING.FPC, included in this distribution,
+   for details about the copyright.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY;without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+**********************************************************************}
+
+Function PClose(Var F:file) : cint;
+var
+  pl : ^cint;
+  res: cint;
+begin
+  repeat
+    res:=fpclose(filerec(F).Handle);
+  until (res<>-1) or (fpgeterrno<>ESysEINTR);
+{ closed our side, Now wait for the other - this appears to be needed ?? }
+  pl:=@(filerec(f).userdata[2]);
+  pclose := WaitProcess(pl^);
+end;
+
+Function PClose(Var F:text) :cint;
+var
+  pl  : ^cint;
+  res : cint;
+begin
+  repeat
+    res:=fpclose(Textrec(F).Handle);
+  until (res<>-1) or (fpgeterrno<>ESysEINTR);
+{ closed our side, Now wait for the other - this appears to be needed ?? }
+  pl:=@(textrec(f).userdata[2]);
+  pclose:= WaitProcess(pl^);
+end;
+
+
+// can't have oldfpccall here, linux doesn't need it.
+Function AssignPipe(var pipe_in,pipe_out:cint):cint; [public, alias : 'FPC_SYSC_ASSIGNPIPE'];
+{
+  Sets up a pair of file variables, which act as a pipe. The first one can
+  be read from, the second one can be written to.
+  If the operation was unsuccesful, linuxerror is set.
+}
+var
+  ret  : longint;
+  fdis : array[0..1] of cint;
+begin
+ fdis[0]:=pipe_in;
+ fdis[1]:=pipe_out;
+ ret:=pipe(fdis);
+ pipe_in:=fdis[0];
+ pipe_out:=fdis[1];
+ AssignPipe:=ret;
+end;
+
+{$define FPC_HAS_GETTIMEZONEFILE}
+
+function GetTimezoneFile:shortstring;
+var
+  tzenv : pchar;
+  l: longint;
+  s: shortstring;
+  ft : text;
+begin
+  GetTimeZoneFile:='';
+  { the TZ variable holds the name of the timezone (possibly followed by a
+    comma and rules), and the timezone files themselves are stored in
+    /usr/share/lib/zoneinfo }
+  tzenv:=fpgetenv('TZ');
+  if assigned(tzenv) then
+    begin
+      s:=strpas(tzenv);
+      l:=pos(',',s);
+      if l<>0 then
+        s:=copy(s,1,l-1);
+      GetTimeZoneFile:='/usr/share/lib/zoneinfo/'+s;
+    end
+  else
+    exit;
+  assign(ft,GetTimeZoneFile);
+{$push}
+{$I-}  
+  reset(ft);
+  if IOResult=0 then
+    close(ft)
+  else
+    GetTimeZoneFile:='';
+{$pop}
+end;
+
+
+{ should probably be defined in ostypes.inc for all OSes }
+const
+  F_RDLCK =        01;      (* Read lock *)
+  F_WRLCK =        02;      (* Write lock *)
+  F_UNLCK =        03;      (* Remove lock(s) *)
+
+
+Function fpFlock (fd,mode : longint) : cint;
+  var
+    fl : flock;
+    cmd : cint;
+  begin
+    { initialize the flock struct to set lock on entire file }
+    fillchar(fl,sizeof(fl),0);
+
+    { In non-blocking lock, use F_SETLK for cmd, F_SETLKW otherwise }
+    if (mode and LOCK_NB)<>0 then
+      begin
+        cmd:=F_SETLK;
+        { turn off this bit }
+        mode:=mode and not(LOCK_NB);
+      end
+    else
+      cmd:=F_SETLKW;
+
+    case mode of
+      LOCK_UN:
+        fl.l_type:=fl.l_type or F_UNLCK;
+      LOCK_SH:
+        fl.l_type:=fl.l_type or F_RDLCK;
+      LOCK_EX:
+        fl.l_type:=fl.l_type or F_WRLCK;
+      else
+        begin
+          errno:=ESysEINVAL;
+          fpFlock:=-1;
+	  exit;
+        end;
+    end;
+
+    fpFlock:=fpFcntl(fd,cmd,fl);
+
+    if (fpFlock=-1) and (errno=ESysEACCES) then
+       errno:=ESysEWOULDBLOCK;
+  end;
+

+ 425 - 0
rtl/aix/unxsockh.inc

@@ -0,0 +1,425 @@
+{
+   This file is part of the Free Pascal run time library.
+   (c) 2000-2003 by Marco van de Voort
+   member of the Free Pascal development team.
+
+   See the file COPYING.FPC, included in this distribution,
+   for details about the copyright.
+
+   OS dependant part of the header.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY;without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+}
+
+{$linklib libnsl.so}
+
+const
+  {
+   * Address families.
+    }
+
+  { unspecified  }
+    AF_UNSPEC = 0;
+  { local to host (pipes, portals)  }
+    AF_UNIX = 1;
+  { internetwork: UDP, TCP, etc.  }
+    AF_INET = 2;
+  { arpanet imp addresses  }
+    AF_IMPLINK = 3;
+  { pup protocols: e.g. BSP  }
+    AF_PUP = 4;
+  { mit CHAOS protocols  }
+    AF_CHAOS = 5;
+  { XEROX NS protocols  }
+    AF_NS = 6;
+  { ISO protocols  }
+    AF_ISO = 7;
+    AF_OSI = AF_ISO;
+  { european computer manufacturers  }
+    AF_ECMA = 8;
+  { datakit protocols  }
+    AF_DATAKIT = 9;
+  { CCITT protocols, X.25 etc  }
+    AF_CCITT = 10;
+  { IBM SNA  }
+    AF_SNA = 11;
+  { DECnet  }
+    AF_DECnet = 12;
+  { DEC Direct data link interface  }
+    AF_DLI = 13;
+  { LAT  }
+    AF_LAT = 14;
+  { NSC Hyperchannel  }
+    AF_HYLINK = 15;
+  { Apple Talk  }
+    AF_APPLETALK = 16;
+  { Internal Routing Protocol  }
+    AF_ROUTE = 17;
+  { Link layer interface  }
+    AF_LINK = 18;
+  { Moved to _ALL_SOURCE section since it doesn't begin with AF_  }
+    pseudo_AF_XTP = 19;              { eXpress Transfer Protocol (no AF)  }
+  { Debugging use only  }
+    AF_INTF = 20;
+  { raw interface  }
+    AF_RIF = 21;
+    AF_NETWARE = 22;
+    AF_NDD = 23;
+  { IPv6  }
+    AF_INET6 = 24;
+    AF_MAX = 30;
+  {
+   * Protocol families, same as address families for now.
+  }
+  PF_UNSPEC = AF_UNSPEC;
+  PF_UNIX = AF_UNIX;
+  PF_INET = AF_INET;
+  PF_IMPLINK = AF_IMPLINK;
+  PF_PUP = AF_PUP;
+  PF_CHAOS = AF_CHAOS;
+  PF_NS = AF_NS;
+  PF_ISO = AF_ISO;
+  PF_OSI = AF_ISO;
+  PF_ECMA = AF_ECMA;
+  PF_DATAKIT = AF_DATAKIT;
+  PF_CCITT = AF_CCITT;
+  PF_SNA = AF_SNA;
+  PF_DECnet = AF_DECnet;
+  PF_DLI = AF_DLI;
+  PF_LAT = AF_LAT;
+  PF_HYLINK = AF_HYLINK;
+  PF_APPLETALK = AF_APPLETALK;
+  PF_ROUTE = AF_ROUTE;
+  PF_LINK = AF_LINK;
+{ really just proto family, no AF  }
+  PF_XTP = pseudo_AF_XTP;
+  PF_RIF = AF_RIF;
+{ Used by sysx/intf  }
+  PF_INTF = AF_INTF;
+  PF_NDD = AF_NDD;
+  PF_INET6 = AF_INET6;
+
+{ Maximum queue length specifiable by listen.  }
+  SOMAXCONN     = 1024;
+
+   SOL_SOCKET = $FFFF;
+	
+   { turn on debugging info recording  }
+     SO_DEBUG = $0001;
+   { socket has had listen()  }
+     SO_ACCEPTCONN = $0002;
+   { allow local address reuse  }
+     SO_REUSEADDR = $0004;
+   { keep connections alive  }
+     SO_KEEPALIVE = $0008;
+   { just use interface addresses  }
+     SO_DONTROUTE = $0010;
+   { permit sending of broadcast msgs  }
+     SO_BROADCAST = $0020;
+   { bypass hardware when possible  }
+     SO_USELOOPBACK = $0040;
+   { linger on close if data present  }
+     SO_LINGER = $0080;
+   { leave received OOB data in line  }
+     SO_OOBINLINE = $0100;
+   { allow local address & port reuse  }
+     SO_REUSEPORT = $0200;
+   { Interface will supply buffers  }
+     SO_USE_IFBUFS = $0400;
+   { defer checksum until receive  }
+     SO_CKSUMRECV = $0800;
+   { prevent local address reuse  }
+     SO_NOREUSEADDR = $1000;
+   { derive a in-kernel only socket  }
+     SO_KERNACCEPT = $2000;
+   { always use first matching route  }
+     SO_NOMULTIPATH = $4000;
+   { turn on socket auditing  }
+     SO_AUDIT = $8000;
+   {
+    * Additional options, not kept in so_options.
+     }
+   { send buffer size  }
+     SO_SNDBUF = $1001;
+   { receive buffer size  }
+     SO_RCVBUF = $1002;
+   { send low-water mark  }
+     SO_SNDLOWAT = $1003;
+   { receive low-water mark  }
+     SO_RCVLOWAT = $1004;
+   { send timeout  }
+     SO_SNDTIMEO = $1005;
+   { receive timeout  }
+     SO_RCVTIMEO = $1006;
+   { get error status and clear  }
+     SO_ERROR = $1007;
+   { get socket type  }
+     SO_TYPE = $1008;
+   { get peer socket's process id, thread id,
+   							euid and egid  }
+     SO_PEERID = $1009;
+
+   { "Socket"-level control message types:  }
+   { access rights (array of int)  }
+     SCM_RIGHTS = $01;
+   {
+    * Arguments for shutdown().
+     }
+   { shut down for reading  }
+     SHUT_RD = 0;
+   { shut down for writing  }
+     SHUT_WR = 1;
+   { shut down for read & write  }
+     SHUT_RDWR = 2;
+
+  { Flags for send, recv etc. }
+{ process out-of-band data  }
+  MSG_OOB = $1;
+{ peek at incoming message  }
+  MSG_PEEK = $2;
+{ send without using routing tables  }
+  MSG_DONTROUTE = $4;
+{ data completes record  }
+  MSG_EOR = $8;
+{ data discarded before delivery  }
+  MSG_TRUNC = $10;
+{ control data lost before delivery  }
+  MSG_CTRUNC = $20;
+{ wait for full request or error  }
+  MSG_WAITALL = $40;
+{ Message contain MPEG2 data  }
+  MSG_MPEG2 = $80;
+{ Following used within kernel  }
+{ nonblocking request  }
+  MSG_NONBLOCK = $4000;
+{ 4.3-format sockaddr  }
+  MSG_COMPAT = $8000;
+  MSG_MAXIOVLEN    =    16;
+ 
+     TCP_NODELAY = $01;
+  { set maximum segment size  }
+     TCP_MAXSEG = $02;
+  { set keepalive timer  }
+     TCP_KEEPALIVE = $8;
+(*
+     TCP_NOTIFY_THRESHOLD = $10;
+     TCP_ABORT_THRESHOLD = $11;
+     TCP_CONN_NOTIFY_THRESHOLD = $12;
+     TCP_CONN_ABORT_THRESHOLD = $13;
+     TCP_RECVDSTADDR = $14;
+     TCP_INIT_CWND = $15;
+     TCP_KEEPALIVE_THRESHOLD = $16;
+     TCP_KEEPALIVE_ABORT_THRESHOLD = $17;
+     TCP_CORK = $18;
+*)
+
+//from /usr/include/netinet/in.h
+
+    IPPROTO_IP = 0;
+    { IPv6 Hop-by-Hop options  }
+    IPPROTO_HOPOPTS = 0;
+    { control message protocol  }
+    IPPROTO_ICMP = 1;
+    { group mgmt protocol  }
+    IPPROTO_IGMP = 2;
+    { gateway^2 (deprecated)  }
+    IPPROTO_GGP = 3;
+    { IP inside IP  }
+    IPPROTO_IPIP = 4;
+    { tcp  }
+    IPPROTO_TCP = 6;
+    { exterior gateway protocol  }
+    IPPROTO_EGP = 8;
+    { pup  }
+    IPPROTO_PUP = 12;
+    { user datagram protocol  }
+    IPPROTO_UDP = 17;
+    { xns idp  }
+    IPPROTO_IDP = 22;
+    { tp-4 w/ class negotiation  }
+    IPPROTO_TP = 29;
+    { IPv6 into IPv4  }
+    IPPROTO_IPV6 = 41;
+    { IPv6 Routing header  }
+    IPPROTO_ROUTING = 43;
+    { IPv6 fragmentation header  }
+    IPPROTO_FRAGMENT = 44;
+    { Quality of Service  }
+    IPPROTO_QOS = 45;
+    { resource reservation  }
+    IPPROTO_RSVP = 46;
+    IPPROTO_GRE = 47;
+    { encap security payload  }
+    IPPROTO_ESP = 50;
+    { authentication header  }
+    IPPROTO_AH = 51;
+    { ICMPv6/IGMPv6/NDPv6  }
+    IPPROTO_ICMPV6 = 58;
+    { IPv6 no next header  }
+    IPPROTO_NONE = 59;
+    { IPv6 Destination options  }
+    IPPROTO_DSTOPTS = 60;
+    { any local network  }
+    IPPROTO_LOCAL = 63;
+    { ISO cnlp  }
+    IPPROTO_EON = 80;
+    { Banyan Vines  }
+    IPPROTO_BIP = $53;
+    { SCTP  }
+    IPPROTO_SCTP = 132;
+    { IPv6 Mobility Header  }
+    IPPROTO_MH = 135;
+    { raw IP packet  }
+    IPPROTO_RAW = 255;
+    IPPROTO_MAX = 256;
+
+    
+  { buf/ip_opts; set/get IP per-packet options  }
+    IP_OPTIONS = 1;
+  { int; header is included with data (raw)  }
+    IP_HDRINCL = 2;
+  { int; IP type of service and precedence  }
+    IP_TOS = 3;
+  { int; IP time to live  }
+    IP_TTL = 4;
+    IP_UNICAST_HOPS = IP_TTL;
+  { bool; receive all IP options w/datagram  }
+    IP_RECVOPTS = 5;
+  { bool; receive IP options for response  }
+    IP_RECVRETOPTS = 6;
+  { bool; receive IP dst addr w/datagram  }
+    IP_RECVDSTADDR = 7;
+  { ip_opts; set/get IP per-packet options  }
+    IP_RETOPTS = 8;
+  { set/get IP multicast interface   }
+    IP_MULTICAST_IF = 9;
+  { set/get IP multicast timetolive  }
+    IP_MULTICAST_TTL = 10;
+    IP_MULTICAST_HOPS = IP_MULTICAST_TTL;
+  { set/get IP multicast loopback    }
+    IP_MULTICAST_LOOP = 11;
+  { add  an IP group membership      }
+    IP_ADD_MEMBERSHIP = 12;
+  { drop an IP group membership      }
+    IP_DROP_MEMBERSHIP = 13;
+  { bool; receive MAC hdr w/datagram  }
+    IP_RECVMACHDR = 14;
+  { bool; receive IFNET addr  }
+    IP_RECVIFINFO = 15;
+  { set/get IP all points broadcast IF  }
+    IP_BROADCAST_IF = 16;
+  { Used by DHCP  }
+    IP_DHCPMODE = 17;
+    IP_RECVIF = 20;
+  { int; get/set form of returned addrs  }
+    IP_ADDRFORM = 22;
+    IP_DONTFRAG = 25;
+    IP_FINDPMTU = 26;
+    IP_PMTUAGE = 27;
+  { Options 28 to 31 moved to _ALL_SOURCE block.  }
+  { bool; receive inbound interface  }
+    IP_RECVINTERFACE = 32;
+  { Option 33 moved to _ALL_SOURCE block.  }
+  { int; receive TTL/hlim  }
+    IP_RECVTTL = 34;
+  { Option 35 moved to _ALL_SOURCE block.  }
+  { normally limit m'casts to 1 hop   }
+    IP_DEFAULT_MULTICAST_TTL = 1;
+  { normally hear sends if a member   }
+    IP_DEFAULT_MULTICAST_LOOP = 1;
+  { ip_max_membership is incremented by this value to support unlimited multicast group per socket  }
+    IP_INC_MEMBERSHIPS = 20;
+  { ip_max_membership is initialized to 20  }
+    IP_INIT_MEMBERSHIP = 20;
+    {
+     * IPv6 options
+    }
+    IPV6_UNICAST_HOPS = IP_TTL;
+  { u_int  }
+    IPV6_MULTICAST_IF = IP_MULTICAST_IF;
+  { int  }
+    IPV6_MULTICAST_HOPS = IP_MULTICAST_TTL;
+    IPV6_MULTICAST_LOOP = IP_MULTICAST_LOOP;
+    IPV6_ADD_MEMBERSHIP = IP_ADD_MEMBERSHIP;
+    IPV6_JOIN_GROUP = IP_ADD_MEMBERSHIP;
+    IPV6_DROP_MEMBERSHIP = IP_DROP_MEMBERSHIP;
+    IPV6_LEAVE_GROUP = IP_DROP_MEMBERSHIP;
+    IPV6_ADDRFORM = IP_ADDRFORM;
+  { int; don't trigger NUD probes  }
+    IPV6_NOPROBE = 28;
+  { int; receive source route array  }
+    IPV6_RECVSRCRT = 29;
+  { int; receive interface in array  }
+    IPV6_RECVIF = 30;
+  { sockaddr; set outgoing iface  }
+    IPV6_SENDIF = 31;
+  { in6_pktinfo; set packet info  }
+    IPV6_PKTINFO = 33;
+    IPV6_RECVHOPS = IP_RECVTTL;
+  { int; receive packet info  }
+    IPV6_RECVPKTINFO = 35;
+  { ancillary data style  }
+    IPV6_PKTOPTIONS = 36;
+  { IPv6 only communication  }
+    IPV6_V6ONLY = 37;
+  { random generator for flow IDs  }
+    FLOW6_RAND = 49;
+  { ICMPv6 filter socket option  }
+    ICMP6_FILTER = 38;
+  { IPV6_CHECKSUM socket option  }
+    IPV6_CHECKSUM = 39;
+  { ancillary-only option  }
+    IPV6_HOPLIMIT = 40;
+  { receive incoming hop limit  }
+    IPV6_RECVHOPLIMIT = 41;
+  { receive incoming traffic class  }
+    IPV6_RECVTCLASS = 42;
+  { traffic class ancillary value  }
+    IPV6_TCLASS = 43;
+  { use min mtu socket option  }
+    IPV6_USE_MIN_MTU = 44;
+  { do not fragment outgoing pkts  }
+    IPV6_DONTFRAG = 45;
+  { check path MTU for a given dst  }
+    IPV6_PATHMTU = 46;
+  { recv packet too big notifications  }
+    IPV6_RECVPATHMTU = 47;
+  { next hop socket option  }
+    IPV6_NEXTHOP = 48;
+  { routing header option  }
+    IPV6_RTHDR = 50;
+  { receive routing header  }
+    IPV6_RECVRTHDR = 51;
+  { Hop-by-Hop Header  }
+    IPV6_HOPOPTS = 52;
+  { receive hop-by-hop header  }
+    IPV6_RECVHOPOPTS = 53;
+  { Destination Opts Header after Rthdr
+                                          or when there is no Rthdr  }
+    IPV6_DSTOPTS = 54;
+  { Destination Opts Header before Rthdr  }
+    IPV6_RTHDRDSTOPTS = 55;
+  { receive both kinds of Dopt hdrs  }
+    IPV6_RECVDSTOPTS = 56;
+  { deliver IPv6 hdr also  }
+    IPV6_AIXRAWSOCKET = 57;
+
+(*
+    {
+     * protocol-independent multicast membership options.
+    }
+  { join group for all sources  }
+    MCAST_JOIN_GROUP = $29;
+  { leave group  }
+    MCAST_LEAVE_GROUP = $2a;
+  { block specified source  }
+    MCAST_BLOCK_SOURCE = $2b;
+  { unblock specified source  }
+    MCAST_UNBLOCK_SOURCE = $2c;
+  { join group for specified source  }
+    MCAST_JOIN_SOURCE_GROUP = $2d;
+  { leave source/group pair  }
+      MCAST_LEAVE_SOURCE_GROUP = $2e;
+*)

+ 26 - 24
rtl/powerpc/math.inc

@@ -74,7 +74,7 @@ const
         // make d positive
         // make d positive
         fabs    f1,f1
         fabs    f1,f1
         // load 2^32 in f2
         // load 2^32 in f2
-        {$ifndef macos}
+        {$if not defined(macos) and not defined(aix)}
         {$ifdef FPC_PIC}
         {$ifdef FPC_PIC}
         {$ifdef darwin}
         {$ifdef darwin}
         mflr   r0
         mflr   r0
@@ -91,10 +91,10 @@ const
         lis    r4,factor@ha
         lis    r4,factor@ha
         lfd    f2,factor@l(r4)
         lfd    f2,factor@l(r4)
         {$endif FPC_PIC}
         {$endif FPC_PIC}
-        {$else not macos}
+        {$else not macos/aix}
         lwz    r4,factor(r2)
         lwz    r4,factor(r2)
         lfd    f2,0(r4)
         lfd    f2,0(r4)
-        {$endif not macos}
+        {$endif not macos/aix}
         // check if value is < 0
         // check if value is < 0
         // f3 := d / 2^32;
         // f3 := d / 2^32;
         fdiv     f3,f1,f2
         fdiv     f3,f1,f2
@@ -109,7 +109,7 @@ const
         stw      r0,temp
         stw      r0,temp
         xoris    r0,r3,0x8000
         xoris    r0,r3,0x8000
         stw      r0,temp+4
         stw      r0,temp+4
-        {$ifndef macos}
+        {$if not defined(macos) and not defined(aix)}
         {$ifdef FPC_PIC}
         {$ifdef FPC_PIC}
         {$ifdef darwin}
         {$ifdef darwin}
         addis  r4,r5,(longint_to_real_helper-.Lpiclab)@ha
         addis  r4,r5,(longint_to_real_helper-.Lpiclab)@ha
@@ -121,10 +121,10 @@ const
         lis    r4,longint_to_real_helper@ha
         lis    r4,longint_to_real_helper@ha
         lfd    f0,longint_to_real_helper@l(r4)
         lfd    f0,longint_to_real_helper@l(r4)
         {$endif FPC_PIC}
         {$endif FPC_PIC}
-        {$else not macos}
+        {$else not macos/aix}
         lwz    r4,longint_to_real_helper(r2)
         lwz    r4,longint_to_real_helper(r2)
         lfd    f0,0(r4)
         lfd    f0,0(r4)
-        {$endif not macos}
+        {$endif not macos/aix}
         lfd    f3,temp
         lfd    f3,temp
         fsub   f3,f3,f0
         fsub   f3,f3,f0
 
 
@@ -135,7 +135,7 @@ const
         // now, convert to unsigned 32 bit
         // now, convert to unsigned 32 bit
 
 
         // load 2^31 in f2
         // load 2^31 in f2
-        {$ifndef macos}
+        {$if not defined(macos) and not defined(aix)}
         {$ifdef FPC_PIC}
         {$ifdef FPC_PIC}
         {$ifdef darwin}
         {$ifdef darwin}
         addis  r4,r5,(factor2-.Lpiclab)@ha
         addis  r4,r5,(factor2-.Lpiclab)@ha
@@ -147,10 +147,10 @@ const
         lis    r4,factor2@ha
         lis    r4,factor2@ha
         lfd    f2,factor2@l(r4)
         lfd    f2,factor2@l(r4)
         {$endif FPC_PIC}
         {$endif FPC_PIC}
-        {$else not macos}
+        {$else not macos/aix}
         lwz    r4,factor2(r2)
         lwz    r4,factor2(r2)
         lfd    f2,0(r4)
         lfd    f2,0(r4)
-        {$endif not macos}
+        {$endif not macos/aix}
 
 
         // subtract 2^31
         // subtract 2^31
         fsub   f3,f4,f2
         fsub   f3,f4,f2
@@ -201,7 +201,7 @@ const
         // make d positive
         // make d positive
         fabs    f1,f1
         fabs    f1,f1
         // load 2^32 in f2
         // load 2^32 in f2
-        {$ifndef macos}
+        {$if not defined(macos) and not defined(aix)}
         lis    r4,factor@ha
         lis    r4,factor@ha
         lfd    f2,factor@l(r4)
         lfd    f2,factor@l(r4)
         {$else}
         {$else}
@@ -222,7 +222,7 @@ const
         stw      r0,temp
         stw      r0,temp
         xoris    r0,r3,0x8000
         xoris    r0,r3,0x8000
         stw      r0,temp+4
         stw      r0,temp+4
-        {$ifndef macos}
+        {$if not defined(macos) and not defined(aix)}
         lis    r4,longint_to_real_helper@ha
         lis    r4,longint_to_real_helper@ha
         lfd    f0,longint_to_real_helper@l(r4)
         lfd    f0,longint_to_real_helper@l(r4)
         {$else}
         {$else}
@@ -239,7 +239,7 @@ const
         // now, convert to unsigned 32 bit
         // now, convert to unsigned 32 bit
 
 
         // load 2^31 in f2
         // load 2^31 in f2
-        {$ifndef macos}
+        {$if not defined(macos) and not defined(aix)}
         lis    r4,factor2@ha
         lis    r4,factor2@ha
         lfd    f2,factor2@l(r4)
         lfd    f2,factor2@l(r4)
         {$else}
         {$else}
@@ -275,6 +275,8 @@ const
 {****************************************************************************
 {****************************************************************************
                          Int to real helpers
                          Int to real helpers
  ****************************************************************************}
  ****************************************************************************}
+{$ifndef aix}
+{ these helpers somehow don't seem to work on AIX/Power 7 }
 
 
 {$define FPC_SYSTEM_HAS_INT64_TO_DOUBLE}
 {$define FPC_SYSTEM_HAS_INT64_TO_DOUBLE}
 function fpc_int64_to_double(i: int64): double; compilerproc;
 function fpc_int64_to_double(i: int64): double; compilerproc;
@@ -292,7 +294,7 @@ asm
            stw    r0,temp
            stw    r0,temp
            xoris  r3,r3,0x8000
            xoris  r3,r3,0x8000
            stw    r3,temp+4
            stw    r3,temp+4
-           {$ifndef macos}
+           {$if not defined(macos) and not defined(aix)}
            {$ifdef FPC_PIC}
            {$ifdef FPC_PIC}
            {$ifdef darwin}
            {$ifdef darwin}
            mflr   r0
            mflr   r0
@@ -309,14 +311,14 @@ asm
            lis    r3,longint_to_real_helper@ha
            lis    r3,longint_to_real_helper@ha
            lfd    f1,longint_to_real_helper@l(r3)
            lfd    f1,longint_to_real_helper@l(r3)
            {$endif FPC_PIC}
            {$endif FPC_PIC}
-           {$else not macos}
+           {$else not macos/aix}
            lwz    r3,longint_to_real_helper(r2)
            lwz    r3,longint_to_real_helper(r2)
            lfd    f1,0(r3)
            lfd    f1,0(r3)
            {$endif not mac os}
            {$endif not mac os}
            lfd    f0,temp
            lfd    f0,temp
            stw    r4,temp+4
            stw    r4,temp+4
            fsub   f0,f0,f1
            fsub   f0,f0,f1
-           {$ifndef macos}
+           {$if not defined(macos) and not defined(aix)}
            {$ifdef FPC_PIC}
            {$ifdef FPC_PIC}
            {$ifdef darwin}
            {$ifdef darwin}
            addis  r4,r5,(cardinal_to_real_helper-.Lpiclab)@ha
            addis  r4,r5,(cardinal_to_real_helper-.Lpiclab)@ha
@@ -334,13 +336,13 @@ asm
            lfd    f3,temp
            lfd    f3,temp
            lfd    f2,int_to_real_factor@l(r4)
            lfd    f2,int_to_real_factor@l(r4)
            {$endif FPC_PIC}
            {$endif FPC_PIC}
-           {$else not macos}
+           {$else not macos/aix}
            lwz    r4,cardinal_to_real_helper(r2)
            lwz    r4,cardinal_to_real_helper(r2)
            lwz    r3,int_to_real_factor(r2)
            lwz    r3,int_to_real_factor(r2)
            lfd    f3,temp
            lfd    f3,temp
            lfd    f1,0(r4)
            lfd    f1,0(r4)
            lfd    f2,0(r3)
            lfd    f2,0(r3)
-           {$endif not macos}
+           {$endif not macos/aix}
            fsub   f3,f3,f1
            fsub   f3,f3,f1
            fmadd  f1,f0,f2,f3
            fmadd  f1,f0,f2,f3
 end;
 end;
@@ -362,7 +364,7 @@ asm
            stw    r0,temp
            stw    r0,temp
            stw    r3,temp+4
            stw    r3,temp+4
            lfd    f0,temp
            lfd    f0,temp
-           {$ifndef macos}
+           {$if not defined(macos) and not defined(aix)}
            {$ifdef FPC_PIC}
            {$ifdef FPC_PIC}
            {$ifdef darwin}
            {$ifdef darwin}
            mflr   r0
            mflr   r0
@@ -379,14 +381,14 @@ asm
            lis    r3,cardinal_to_real_helper@ha
            lis    r3,cardinal_to_real_helper@ha
            lfd    f1,cardinal_to_real_helper@l(r3)
            lfd    f1,cardinal_to_real_helper@l(r3)
            {$endif FPC_PIC}
            {$endif FPC_PIC}
-           {$else not macos}
+           {$else not macos/aix}
            lwz    r3,longint_to_real_helper(r2)
            lwz    r3,longint_to_real_helper(r2)
            lfd    f1,0(r3)
            lfd    f1,0(r3)
-           {$endif not macos}
+           {$endif not macos/aix}
            stw    r4,temp+4
            stw    r4,temp+4
            fsub   f0,f0,f1
            fsub   f0,f0,f1
            lfd    f3,temp
            lfd    f3,temp
-           {$ifndef macos}
+           {$if not defined(macos) and not defined(aix)}
            {$ifdef FPC_PIC}
            {$ifdef FPC_PIC}
            {$ifdef darwin}
            {$ifdef darwin}
            addis  r4,r5,(int_to_real_factor-.Lpiclab)@ha
            addis  r4,r5,(int_to_real_factor-.Lpiclab)@ha
@@ -398,12 +400,12 @@ asm
            lis    r4,int_to_real_factor@ha
            lis    r4,int_to_real_factor@ha
            lfd    f2,int_to_real_factor@l(r4)
            lfd    f2,int_to_real_factor@l(r4)
            {$endif FPC_PIC}
            {$endif FPC_PIC}
-           {$else not macos}
+           {$else not macos/aix}
            lwz    r4,int_to_real_factor(r2)
            lwz    r4,int_to_real_factor(r2)
            lfd    f2,0(r4)
            lfd    f2,0(r4)
-           {$endif not macos}
+           {$endif not macos/aix}
            fsub   f3,f3,f1
            fsub   f3,f3,f1
            fmadd  f1,f0,f2,f3
            fmadd  f1,f0,f2,f3
 end;
 end;
-
+{$endif}
 
 

+ 2 - 2
rtl/powerpc/strings.inc

@@ -50,7 +50,7 @@ asm
         subi    r4,r4,3
         subi    r4,r4,3
         subi    r9,r9,3
         subi    r9,r9,3
         { setup magic constants }
         { setup magic constants }
-        {$ifdef macos}
+        {$if defined(macos) or defined(aix)}
         {  load constant 0xfefefeff }
         {  load constant 0xfefefeff }
         lis     r8,0xfefe
         lis     r8,0xfefe
         ori     r8,r8,0xfeff
         ori     r8,r8,0xfeff
@@ -124,7 +124,7 @@ asm
         subi    r4,r4,3
         subi    r4,r4,3
         subi    r3,r3,3
         subi    r3,r3,3
         { setup magic constants }
         { setup magic constants }
-        {$ifdef macos}
+        {$if defined(macos) or defined(aix)}
         {  load constant 0xfefefeff }
         {  load constant 0xfefefeff }
         lis     r8,0xfefe
         lis     r8,0xfefe
         ori     r8,r8,0xfeff
         ori     r8,r8,0xfeff

+ 4 - 4
rtl/unix/clocale.pp

@@ -43,8 +43,8 @@ Uses
   SysUtils, unixtype, initc;
   SysUtils, unixtype, initc;
 
 
 Const
 Const
-{$if defined(BSD) or defined(SUNOS)}
-  // Darwin and FreeBSD. Note the lead underscores are added.
+{$if defined(BSD) or defined(SUNOS) or defined(aix)}
+  // Darwin, FreeBSD, Solaris, AIX. Note the lead underscores are added.
  {$i clocale.inc}
  {$i clocale.inc}
 {$else}
 {$else}
 // checked for Linux only, but might be general glibc.
 // checked for Linux only, but might be general glibc.
@@ -224,7 +224,7 @@ const
 var
 var
   i: integer;
   i: integer;
   prec, sep, signp: byte;
   prec, sep, signp: byte;
-  {$if defined(BSD) or defined(SUNOS)}
+  {$if defined(BSD) or defined(SUNOS) or defined(aix)}
    plocale : plconv;
    plocale : plconv;
   {$ENDIF}
   {$ENDIF}
 begin
 begin
@@ -272,7 +272,7 @@ begin
   else
   else
     fmts.LongTimeFormat := TransformFormatStr(fmts.LongTimeFormat);
     fmts.LongTimeFormat := TransformFormatStr(fmts.LongTimeFormat);
 
 
-  {$if defined(BSD) or defined(SUNOS)}
+  {$if defined(BSD) or defined(SUNOS) or defined(aix)}
      plocale:=localeconv;
      plocale:=localeconv;
      // for these fields there is a separate BSD derived POSIX function.
      // for these fields there is a separate BSD derived POSIX function.
      if not assigned(plocale) then exit; // for now.
      if not assigned(plocale) then exit; // for now.

+ 1 - 1
rtl/unix/cthreads.pp

@@ -43,7 +43,7 @@
 {$endif}
 {$endif}
 {$endif}
 {$endif}
 
 
-{$ifdef linux}
+{$if defined(linux) or defined(aix)}
 {$define has_sem_timedwait}
 {$define has_sem_timedwait}
 {$endif}
 {$endif}
 
 

+ 13 - 22
rtl/unix/cwstring.pp

@@ -53,7 +53,7 @@ Const
     libiconvname='textencoding';  // is in libtextencoding under Haiku
     libiconvname='textencoding';  // is in libtextencoding under Haiku
     libprefix='lib';
     libprefix='lib';
   {$else}
   {$else}
-    {$ifdef darwin}
+    {$if defined(darwin) or defined(aix)}
       libiconvname='libiconv';
       libiconvname='libiconv';
       libprefix='';
       libprefix='';
     {$else}
     {$else}
@@ -82,29 +82,25 @@ function mblen(const s: pchar; n: size_t): size_t; cdecl; external clib name 'mb
 
 
 
 
 const
 const
-{$ifdef linux}
+{$if defined(linux)}
   __LC_CTYPE = 0;
   __LC_CTYPE = 0;
   LC_ALL = 6;
   LC_ALL = 6;
   _NL_CTYPE_CLASS = (__LC_CTYPE shl 16);
   _NL_CTYPE_CLASS = (__LC_CTYPE shl 16);
   _NL_CTYPE_CODESET_NAME = (_NL_CTYPE_CLASS)+14;
   _NL_CTYPE_CODESET_NAME = (_NL_CTYPE_CLASS)+14;
   CODESET = _NL_CTYPE_CODESET_NAME;
   CODESET = _NL_CTYPE_CODESET_NAME;
-{$else linux}
-{$ifdef darwin}
+{$elseif defined(darwin)}
   CODESET = 0;
   CODESET = 0;
   LC_ALL = 0;
   LC_ALL = 0;
-{$else darwin}
-{$ifdef FreeBSD} // actually FreeBSD5. internationalisation is afaik not default on 4.
+{$elseif defined(FreeBSD)} // actually FreeBSD5. internationalisation is afaik not default on 4.
   __LC_CTYPE = 0;
   __LC_CTYPE = 0;
   LC_ALL = 0;
   LC_ALL = 0;
   _NL_CTYPE_CLASS = (__LC_CTYPE shl 16);
   _NL_CTYPE_CLASS = (__LC_CTYPE shl 16);
   _NL_CTYPE_CODESET_NAME = (_NL_CTYPE_CLASS)+14;
   _NL_CTYPE_CODESET_NAME = (_NL_CTYPE_CLASS)+14;
   CODESET = 0; // _NL_CTYPE_CODESET_NAME;
   CODESET = 0; // _NL_CTYPE_CODESET_NAME;
-{$else freebsd}
-{$ifdef solaris}
+{$elseif defined(solaris)}
   CODESET=49;
   CODESET=49;
   LC_ALL = 6;
   LC_ALL = 6;
-{$else solaris}
-{$ifdef beos}
+{$elseif defined(beos)}
   {$warning check correct value for BeOS}
   {$warning check correct value for BeOS}
   CODESET=49;
   CODESET=49;
   {$ifdef haiku}
   {$ifdef haiku}
@@ -113,24 +109,19 @@ const
   LC_ALL = 6; // Checked for BeOS
   LC_ALL = 6; // Checked for BeOS
   {$endif}
   {$endif}
   ESysEILSEQ = EILSEQ;
   ESysEILSEQ = EILSEQ;
-{$else}
-{$ifdef OpenBSD}
+{$elseif defined(OpenBSD)}
   CODESET = 51;
   CODESET = 51;
   LC_ALL = 0;
   LC_ALL = 0;
-{$else not OpenBSD}
-{$ifdef NetBSD}
+{$elseif defined(NetBSD)}
   CODESET = 51;
   CODESET = 51;
   LC_ALL = 0;
   LC_ALL = 0;
-{$else not NetBSD}
+{$elseif defined(aix)}
+  CODESET = 49;
+  LC_ALL = -1;
+{$else not aix}
 {$error lookup the value of CODESET in /usr/include/langinfo.h, and the value of LC_ALL in /usr/include/locale.h for your OS }
 {$error lookup the value of CODESET in /usr/include/langinfo.h, and the value of LC_ALL in /usr/include/locale.h for your OS }
 // and while doing it, check if iconv is in libc, and if the symbols are prefixed with iconv_ or libiconv_
 // and while doing it, check if iconv is in libc, and if the symbols are prefixed with iconv_ or libiconv_
-{$endif NetBSD}
-{$endif OpenBSD}
-{$endif beos}
-{$endif solaris}
-{$endif FreeBSD}
-{$endif darwin}
-{$endif linux}
+{$endif}
 
 
 { unicode encoding name }
 { unicode encoding name }
 {$ifdef FPC_LITTLE_ENDIAN}
 {$ifdef FPC_LITTLE_ENDIAN}

+ 19 - 1
rtl/unix/dl.pp

@@ -36,6 +36,15 @@ const
 {$linklib c}
 {$linklib c}
 {$endif}
 {$endif}
 
 
+{$ifdef aix}
+  RTLD_LAZY         = $004;
+  RTLD_NOW          = $002;
+  RTLD_BINDING_MASK = $006;
+  RTLD_GLOBAL       = $10000;
+  RTLD_MEMBER       = $40000;
+  RTLD_NEXT         = pointer(-3);
+  RTLD_DEFAULT      = pointer(-1);
+{$else}
   RTLD_LAZY         = $001;
   RTLD_LAZY         = $001;
   RTLD_NOW          = $002;
   RTLD_NOW          = $002;
   RTLD_BINDING_MASK = $003;
   RTLD_BINDING_MASK = $003;
@@ -48,6 +57,7 @@ const
   RTLD_DEFAULT      = pointer(-2);
   RTLD_DEFAULT      = pointer(-2);
   RTLD_MODEMASK     = RTLD_BINDING_MASK;
   RTLD_MODEMASK     = RTLD_BINDING_MASK;
 {$endif}
 {$endif}
+{$endif}
 
 
 type
 type
   Pdl_info = ^dl_info;
   Pdl_info = ^dl_info;
@@ -68,10 +78,13 @@ function dlerror() : Pchar; cdecl; external libdl;
 { overloaded for compatibility with hmodule }
 { overloaded for compatibility with hmodule }
 function dlsym(Lib : PtrInt; Name : Pchar) : Pointer; cdecl; external Libdl;
 function dlsym(Lib : PtrInt; Name : Pchar) : Pointer; cdecl; external Libdl;
 function dlclose(Lib : PtrInt) : Longint; cdecl; external libdl;
 function dlclose(Lib : PtrInt) : Longint; cdecl; external libdl;
-function dladdr(Lib: pointer; info: Pdl_info): Longint; cdecl; external;
+function dladdr(Lib: pointer; info: Pdl_info): Longint; cdecl; {$ifndef aix}external;{$endif}
 
 
 implementation
 implementation
 
 
+uses
+  ctypes;
+
   function PosLastSlash(const s : string) : longint;
   function PosLastSlash(const s : string) : longint;
     var
     var
       i : longint;
       i : longint;
@@ -102,6 +115,11 @@ implementation
         baseaddr:=nil;
         baseaddr:=nil;
     end;
     end;
 
 
+{$ifdef aix}
+{$i dlaix.inc}
+{$endif}
+
+
 begin
 begin
   UnixGetModuleByAddrHook:=@UnixGetModuleByAddr;
   UnixGetModuleByAddrHook:=@UnixGetModuleByAddr;
 end.
 end.

+ 21 - 4
rtl/unix/dynlibs.inc

@@ -26,11 +26,13 @@ Type
 Const
 Const
   NilHandle = TLibHandle(0);
   NilHandle = TLibHandle(0);
 // these are for easier crossplatform construction of dll names in dynloading libs.
 // these are for easier crossplatform construction of dll names in dynloading libs.
-{$ifdef Darwin}
+{$if defined(Darwin)}
   SharedSuffix = 'dylib';
   SharedSuffix = 'dylib';
-{$else Darwin}
+{$elseif defined(aix)}
+  SharedSuffix = 'a';
+{$else}
   SharedSuffix = 'so';
   SharedSuffix = 'so';
-{$endif Darwin}
+{$endif}
 
 
 {$else}
 {$else}
 
 
@@ -41,9 +43,24 @@ Const
 uses dl;
 uses dl;
 
 
 Function LoadLibrary(const Name : AnsiString) : TLibHandle;
 Function LoadLibrary(const Name : AnsiString) : TLibHandle;
-
+{$ifdef aix}
+var
+  MemberName: AnsiString;
+{$endif}
 begin
 begin
+{$ifndef aix}
   Result:=TLibHandle(dlopen(Pchar(Name),RTLD_LAZY));
   Result:=TLibHandle(dlopen(Pchar(Name),RTLD_LAZY));
+{$else aix}
+  { in aix, most shared libraries are static libraries (archives) that contain
+    a single object: shr.o for 32 bit, shr_64.o for 64 bit. You have to specify
+    this object file explicitly via the RTLD_MEMBER member flag }
+{$ifdef cpu64}
+  MemberName:=Name+'(shr_64.o)';
+{$else cpu64}
+  MemberName:=Name+'(shr.o)';
+{$endif cpu64}
+  Result:=TLibHandle(dlopen(Pchar(MemberName),RTLD_LAZY or RTLD_MEMBER));
+{$endif aix}
 end;
 end;
 
 
 Function GetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
 Function GetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;

+ 4 - 0
rtl/unix/initc.pp

@@ -80,6 +80,10 @@ function geterrnolocation: pcint; cdecl;external clib name '___errno';
 function geterrnolocation: pcint; cdecl;external 'root' name '_errnop';
 function geterrnolocation: pcint; cdecl;external 'root' name '_errnop';
 {$endif}
 {$endif}
 
 
+{$ifdef aix}
+function geterrnolocation: pcint; cdecl;external clib name '_Errno';
+{$endif}
+
 function fpgetCerrno:cint;
 function fpgetCerrno:cint;
 
 
 begin
 begin

+ 173 - 14
rtl/unix/ipc.pp

@@ -58,26 +58,43 @@ Const
   IPC_M      =  1 shl 12;
   IPC_M      =  1 shl 12;
 {$endif}
 {$endif}
 
 
-  IPC_CREAT  =  1 shl 9;  { create if key is nonexistent }
+{$ifdef aix}
+  IPC_R      =  4 shl 6;
+  IPC_W      =  2 shl 6;
+  { no IPC_M }
+{$endif}
+
+{$ifndef aix}
+  IPC_CREAT  =  1 shl 9;  { create if key is non-existent }
+{$else aix}
+  IPC_CREAT  =  2 shl 12;
+{$endif aix}
   IPC_EXCL   =  2 shl 9;  { fail if key exists }
   IPC_EXCL   =  2 shl 9;  { fail if key exists }
   IPC_NOWAIT =  4 shl 9;  { return error on wait }
   IPC_NOWAIT =  4 shl 9;  { return error on wait }
 
 
 {$if defined(FreeBSD) or defined(Darwin) or defined(Linux) or defined(OpenBSD)}
 {$if defined(FreeBSD) or defined(Darwin) or defined(Linux) or defined(OpenBSD)}
-  IPC_PRIVATE : TKey = 0;
+  IPC_PRIVATE = TKey(0);
+{$elseif defined(aix)}
+  IPC_PRIVATE = TKey(-1)
 {$endif}
 {$endif}
 
 
   { Actions for ctl calls }
   { Actions for ctl calls }
 
 
   IPC_RMID = 0;     { remove resource }
   IPC_RMID = 0;     { remove resource }
+{$ifndef aix}
   IPC_SET  = 1;     { set ipc_perm options }
   IPC_SET  = 1;     { set ipc_perm options }
   IPC_STAT = 2;     { get ipc_perm options }
   IPC_STAT = 2;     { get ipc_perm options }
+{$else aix}
+  IPC_SET  = 101;     { set ipc_perm options }
+  IPC_STAT = 102;     { get ipc_perm options }
+{$endif aix}
 {$ifndef Darwin}
 {$ifndef Darwin}
   IPC_INFO = 3;     { see ipcs }
   IPC_INFO = 3;     { see ipcs }
 {$endif}
 {$endif}
 
 
 type
 type
   PIPC_Perm = ^TIPC_Perm;
   PIPC_Perm = ^TIPC_Perm;
-{$ifdef darwin }
+{$if defined(darwin) }
 {$packrecords 4}
 {$packrecords 4}
 { This is also the strcut for FreeBSD up to version 7
 { This is also the strcut for FreeBSD up to version 7
   renamed ipc_perm_old in /usr/include/sys/ipc.h in version 8 and after }
   renamed ipc_perm_old in /usr/include/sys/ipc.h in version 8 and after }
@@ -91,8 +108,7 @@ type
         key   : key_t;    { user specified msg/sem/shm key }
         key   : key_t;    { user specified msg/sem/shm key }
   End;
   End;
 {$packrecords c}
 {$packrecords c}
-{$else }
-{$if defined(NetBSD) or defined(OpenBSD) or defined(FreeBSD) }
+{$elseif defined(NetBSD) or defined(OpenBSD) or defined(FreeBSD) }
   TIPC_Perm = record
   TIPC_Perm = record
         cuid  : uid_t;  { creator user id }
         cuid  : uid_t;  { creator user id }
         cgid  : gid_t;  { creator group id }
         cgid  : gid_t;  { creator group id }
@@ -102,6 +118,16 @@ type
         seq   : cushort;  { sequence # (to generate unique msg/sem/shm id) }
         seq   : cushort;  { sequence # (to generate unique msg/sem/shm id) }
         key   : key_t;    { user specified msg/sem/shm key }
         key   : key_t;    { user specified msg/sem/shm key }
   End;
   End;
+{$elseif defined(aix)}
+  TIPC_Perm = record
+       uid     : uid_t;
+       git     : gid_t;
+       cuid    : uid_t;
+       cgit    : git_t;
+       mode    : mode_t;
+       seq     : cushort;
+       key     : key_t;
+  end;
 {$else } // linux
 {$else } // linux
 
 
 {$ifdef cpu32}
 {$ifdef cpu32}
@@ -141,8 +167,7 @@ type
         seq   : cushort;
         seq   : cushort;
   End;
   End;
 {$endif not(linux_ipc32) and not(FPC_USE_LIBC)}
 {$endif not(linux_ipc32) and not(FPC_USE_LIBC)}
-{$endif not netbsd}
-{$endif not others}
+{$endif}
 
 
 
 
 { Function to generate a IPC key. }
 { Function to generate a IPC key. }
@@ -216,6 +241,27 @@ Type
 {$endif cpux86_64}
 {$endif cpux86_64}
 {$endif}
 {$endif}
 
 
+{$ifdef aix}
+  shmatt_t = {$ifdef cpu64}culong{$else}cushort{$endif};
+  TShmid_ds = record
+    shm_perm      : TIPC_Perm;
+    shm_segsz     : size_t;
+    shm_lpid      : pid_t;
+    shm_cpid      : pid_t;
+    shm_nattch    : shmatt_t;
+    shm_cnattch   : shmatt_t;
+    shm_atime     : time_t;
+    shm_dtime     : time_t;
+    shm_ctime     : time_t;
+    shm_handle    : {$ifdef cpu64}cuint{$else}culong{$endif};
+    shm_extshm    : cint;
+    shm_pagesize  : cint64;
+    shm_lba       : cuint64;
+    shm_reserved0 : cint64;
+    shm_reserved1 : cint64;
+  end;
+{$endif aix}
+
   const
   const
 {$ifdef Linux}
 {$ifdef Linux}
      SHM_R      = 4 shl 6;
      SHM_R      = 4 shl 6;
@@ -233,9 +279,21 @@ Type
 {$ifdef Darwin}
 {$ifdef Darwin}
      SHMLBA     = 4096;
      SHMLBA     = 4096;
 {$endif}
 {$endif}
+{$ifdef aix}
+     SHM_PIN    = 4 shl 9;
+     SHM_LGPAGE = 2 shl 30; { only available with SHM_PIN }
+{$endif}
 
 
+{$ifndef aix}
      SHM_LOCK   = 11;
      SHM_LOCK   = 11;
      SHM_UNLOCK = 12;
      SHM_UNLOCK = 12;
+{$else not aix}
+     SHM_SIZE      = 6;
+     SHM_PAGESIZE  = 200;
+     SHM_LOCK      = 201;
+     SHM_UNLOCK    = 202;
+     SHM_GETLBA    = 203;
+{$endif not aix}
 
 
 {$ifdef FreeBSD}        // ipcs shmctl commands
 {$ifdef FreeBSD}        // ipcs shmctl commands
      SHM_STAT   = 13;
      SHM_STAT   = 13;
@@ -244,6 +302,7 @@ Type
 
 
 type            // the shm*info kind is "kernel" only.
 type            // the shm*info kind is "kernel" only.
   PSHMinfo = ^TSHMinfo;
   PSHMinfo = ^TSHMinfo;
+{$ifndef aix}
   TSHMinfo = record             // comment under FreeBSD/Darwin: do we really need this?
   TSHMinfo = record             // comment under FreeBSD/Darwin: do we really need this?
     shmmax : cint;
     shmmax : cint;
     shmmin : cint;
     shmmin : cint;
@@ -251,6 +310,13 @@ type            // the shm*info kind is "kernel" only.
     shmseg : cint;
     shmseg : cint;
     shmall : cint;
     shmall : cint;
   end;
   end;
+{$else not aix }
+  TSHMinfo = record
+    shmmax : culonglong;
+    shmmin : cint;
+    shmmni : cint;
+  end;
+{$endif not aix}
 
 
 {$if defined(FreeBSD) or defined(OpenBSD) or defined(Linux)}
 {$if defined(FreeBSD) or defined(OpenBSD) or defined(Linux)}
   PSHM_info = ^TSHM_info;
   PSHM_info = ^TSHM_info;
@@ -286,21 +352,40 @@ const
 
 
 type
 type
   msglen_t = culong;
   msglen_t = culong;
+{$ifndef aix}
   msgqnum_t= culong;
   msgqnum_t= culong;
+{$else not aix}
+  msgqnum_t= cuint;
+{$endif not aix}
 
 
 {$ifdef Darwin}
 {$ifdef Darwin}
   user_msglen_t = culonglong;
   user_msglen_t = culonglong;
   user_msgqnum_t= culonglong;
   user_msgqnum_t= culonglong;
 {$endif}
 {$endif}
 
 
+{$ifdef aix}
+  TMsg_Hdr = record
+    mtime : time_t;
+    muid  : uid_t;
+    mgid  : git_t;
+    mpid  : pid_t;
+    mtype : clong;
+  end;
+{$endif aix}
+
   PMSG = ^TMSG;
   PMSG = ^TMSG;
   TMSG = record
   TMSG = record
-{$ifndef FreeBSD}                       // opague in FreeBSD
-   {$ifdef Darwin}
+{$ifndef FreeBSD}                       // opaque in FreeBSD
+   {$if defined(Darwin)}
     msg_next  : PMSG;
     msg_next  : PMSG;
     msg_type  : clong;
     msg_type  : clong;
     msg_ts    : cushort;
     msg_ts    : cushort;
     mac_label : pointer;
     mac_label : pointer;
+   {$elseif defined(aix)}
+    msg_next  : PMSG;
+    msg_attr  : TMsg_Hdr;
+    msg_ts    : cuint;
+    msg_spot  : pchar;
    {$else}
    {$else}
     msg_next  : PMSG;
     msg_next  : PMSG;
     msg_type  : Longint;
     msg_type  : Longint;
@@ -329,7 +414,7 @@ type
     msg_lrpid  : ipc_pid_t;
     msg_lrpid  : ipc_pid_t;
   end;
   end;
 {$else}
 {$else}
-  {$ifdef Darwin}
+  {$if defined(Darwin)}
 {$packrecords 4}
 {$packrecords 4}
      PMSQid_ds = ^TMSQid_ds;
      PMSQid_ds = ^TMSQid_ds;
      TMSQid_ds = record
      TMSQid_ds = record
@@ -350,6 +435,29 @@ type
        msg_pad4   : array [0..3] of cint32;
        msg_pad4   : array [0..3] of cint32;
      end;
      end;
 {$packrecords c}
 {$packrecords c}
+  {$elseif defined(aix)}
+      PMSQid_ds = ^TMSQid_ds;
+      TMSQid_ds = record
+        msg_perm   : TIPC_perm;
+       {$ifdef cpu64}
+        msg_first  : cuint;
+        msg_last   : cuint;
+       {$else cpu64}
+        msg_first  : PMsg;
+        msg_last   : PMsg;
+       {$endif}
+        msg_cbytes : cuint;
+        msg_qnum   : msgqnum_t;
+        msg_qbytes : msglen_t;
+        msg_lspid  : pid_t;
+        msg_lrpid  : pid_t;
+        msg_stime  : time_t;
+        msg_rtime  : time_t;
+        msg_ctime  : time_t;
+        msg_rwait  : cint;
+        msg_wwait  : cint;
+        msg_reqevents : cushort;
+      end;
   {$else}
   {$else}
      PMSQid_ds = ^TMSQid_ds;
      PMSQid_ds = ^TMSQid_ds;
      TMSQid_ds = record
      TMSQid_ds = record
@@ -378,7 +486,7 @@ type
     mtext : array[0..0] of char;
     mtext : array[0..0] of char;
   end;
   end;
 
 
-{$ifdef linux}
+{$if defined(linux)}
   PMSGinfo = ^TMSGinfo;
   PMSGinfo = ^TMSGinfo;
   TMSGinfo = record
   TMSGinfo = record
     msgpool : cint;
     msgpool : cint;
@@ -390,6 +498,14 @@ type
     msgtql  : cint;
     msgtql  : cint;
     msgseg  : cushort;
     msgseg  : cushort;
   end;
   end;
+{$elseif defined(aix)}
+  PMSGinfo = ^TMSGinfo;
+  TMSGinfo = record
+    msgmax,
+    msgmnb,
+    msgmni,
+    msgmnm  : cint;
+  end;
 {$else}
 {$else}
   PMSGinfo = ^TMSGinfo;
   PMSGinfo = ^TMSGinfo;
   TMSGinfo = record
   TMSGinfo = record
@@ -404,7 +520,7 @@ type
 
 
 Function msgget(key: TKey; msgflg:cint):cint; {$ifdef FPC_USE_LIBC} cdecl; external clib name 'msgget'; {$endif}
 Function msgget(key: TKey; msgflg:cint):cint; {$ifdef FPC_USE_LIBC} cdecl; external clib name 'msgget'; {$endif}
 Function msgsnd(msqid:cint; msgp: PMSGBuf; msgsz: size_t; msgflg:cint): cint; {$ifdef FPC_USE_LIBC} cdecl; external clib name 'msgsnd'; {$endif}
 Function msgsnd(msqid:cint; msgp: PMSGBuf; msgsz: size_t; msgflg:cint): cint; {$ifdef FPC_USE_LIBC} cdecl; external clib name 'msgsnd'; {$endif}
-Function msgrcv(msqid:cint; msgp: PMSGBuf; msgsz: size_t; msgtyp:clong; msgflg:cint): {$ifdef Darwin}ssize_t;{$else}cint;{$endif} {$ifdef FPC_USE_LIBC} cdecl; external clib name 'msgrcv'; {$endif}
+Function msgrcv(msqid:cint; msgp: PMSGBuf; msgsz: size_t; msgtyp:clong; msgflg:cint): {$if defined(Darwin) or defined(aix)}ssize_t;{$else}cint;{$endif} {$ifdef FPC_USE_LIBC} cdecl; external clib name 'msgrcv'; {$endif}
 Function msgctl(msqid:cint; cmd: cint; buf: PMSQid_ds): cint; {$ifdef FPC_USE_LIBC} cdecl; external clib name 'msgctl'; {$endif}
 Function msgctl(msqid:cint; cmd: cint; buf: PMSQid_ds): cint; {$ifdef FPC_USE_LIBC} cdecl; external clib name 'msgctl'; {$endif}
 
 
 { ----------------------------------------------------------------------
 { ----------------------------------------------------------------------
@@ -431,6 +547,7 @@ const
   SEM_UNDO = 1 shl 12;
   SEM_UNDO = 1 shl 12;
   MAX_SOPS = 5;
   MAX_SOPS = 5;
 
 
+{$if not defined(aix) and not defined(darwin)}
   SEM_GETNCNT = 3;   { Return the value of sempid {READ}  }
   SEM_GETNCNT = 3;   { Return the value of sempid {READ}  }
   SEM_GETPID  = 4;   { Return the value of semval {READ}  }
   SEM_GETPID  = 4;   { Return the value of semval {READ}  }
   SEM_GETVAL  = 5;   { Return semvals into arg.array {READ}  }
   SEM_GETVAL  = 5;   { Return semvals into arg.array {READ}  }
@@ -438,11 +555,13 @@ const
   SEM_GETZCNT = 7;   { Set the value of semval to arg.val {ALTER}  }
   SEM_GETZCNT = 7;   { Set the value of semval to arg.val {ALTER}  }
   SEM_SETVAL  = 8;   { Set semvals from arg.array {ALTER}  }
   SEM_SETVAL  = 8;   { Set semvals from arg.array {ALTER}  }
   SEM_SETALL  = 9;
   SEM_SETALL  = 9;
+{$endif}
 
 
   { Permissions  }
   { Permissions  }
 
 
   SEM_A = 2 shl 6;  { alter permission  }
   SEM_A = 2 shl 6;  { alter permission  }
   SEM_R = 4 shl 6;  { read permission  }
   SEM_R = 4 shl 6;  { read permission  }
+
 {$endif}
 {$endif}
 
 
 type
 type
@@ -474,7 +593,7 @@ type
   end;
   end;
 {$endif not linux_ipc32}
 {$endif not linux_ipc32}
 {$else Linux}
 {$else Linux}
-   {$ifdef Darwin}
+   {$if defined(Darwin)}
      PSEM = ^TSEM;
      PSEM = ^TSEM;
      TSEM = record
      TSEM = record
        semval  : cushort;
        semval  : cushort;
@@ -495,9 +614,33 @@ type
              sem_pad3 : array[0..3] of cint32;
              sem_pad3 : array[0..3] of cint32;
           end;
           end;
 {$packrecords c}
 {$packrecords c}
+   {$elseif defined(aix)}
+     tid_t = {$ifdef cpu64}clong{$else}cint{$endif};
+     PSEM = ^TSEM;
+     TSEM = record
+       semval   : cushort;
+       flags    : cushort;
+       sempid   : pid_t;
+       semncnt  : cushort;
+       semzcnt  : cushort;
+       semnwait : tid_t;
+       semzwait : tid_t;
+     end;
+     PSEMid_ds = ^TSEMid_ds;
+     TSEMid_ds = record
+       sem_perm: tipc_perm;
+      {$ifdef cpu64}
+       sem_base: cuint;
+      {$else}
+       sem_base: PSEM;
+      {$endif}
+       sem_nsems: cushort;
+       sem_otime: time_t;
+       sem_ctime: time_t;
+     end;
    {$else}
    {$else}
      PSEM = ^TSEM;
      PSEM = ^TSEM;
-     TSEM = record end; // opague
+     TSEM = record end; // opaque
 
 
      PSEMid_ds = ^TSEMid_ds;
      PSEMid_ds = ^TSEMid_ds;
      TSEMid_ds = record
      TSEMid_ds = record
@@ -522,6 +665,7 @@ type
 
 
 
 
   PSEMinfo = ^TSEMinfo;
   PSEMinfo = ^TSEMinfo;
+{$ifndef aix}
   TSEMinfo = record
   TSEMinfo = record
     semmap : cint;
     semmap : cint;
     semmni : cint;
     semmni : cint;
@@ -534,6 +678,17 @@ type
     semvmx : cint;
     semvmx : cint;
     semaem : cint;
     semaem : cint;
   end;
   end;
+{$else not aix}
+  TSEMinfo = record
+    semmni : cint;
+    semmsl : cint;
+    semopm : cint;
+    semume : cint;
+    semusz : cint;
+    semvmx : cint;
+    semaem : cint;
+  end;
+{$endif not aix}
 
 
 { internal mode bits}
 { internal mode bits}
 
 
@@ -562,6 +717,10 @@ Function semctl(semid:cint; semnum:cint; cmd:cint; var arg: tsemun): cint;
 {$ifdef linux}
 {$ifdef linux}
 Function semtimedop(semid:cint; sops: psembuf; nsops: cuint; timeOut: ptimespec): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'semtimedop'; platform; {$else} platform; {$endif}
 Function semtimedop(semid:cint; sops: psembuf; nsops: cuint; timeOut: ptimespec): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'semtimedop'; platform; {$else} platform; {$endif}
 {$endif}
 {$endif}
+{$ifdef aix}
+{ only available as of AIX 6.1 }
+Function semtimedop(semid:cint; sops: psembuf; nsops: size_t; timeOut: ptimespec): cint; {$ifdef FPC_USE_LIBC} cdecl; weakexternal name 'semtimedop'; platform; {$else} platform; {$endif}
+{$endif}
 
 
 implementation
 implementation
 
 

+ 5 - 5
rtl/unix/oscdeclh.inc

@@ -25,7 +25,7 @@ Type TGrpArr = Array [0..0] of TGid;            { C style array workarounds}
      pFilDes = ^TFilDes;
      pFilDes = ^TFilDes;
 
 
 const
 const
-{$if defined(linux) and defined(cpu32) and not defined(fs32bit)}
+{$if (defined(linux) and defined(cpu32) and not defined(fs32bit)) or defined(aix)}
     suffix64bit = '64';
     suffix64bit = '64';
 {$else}    
 {$else}    
     suffix64bit = '';
     suffix64bit = '';
@@ -35,8 +35,8 @@ const
     function  FpChdir   (path : pchar): cint; cdecl; external clib name 'chdir';
     function  FpChdir   (path : pchar): cint; cdecl; external clib name 'chdir';
     Function  FpChown   (path : pChar; owner : TUid; group : TGid): cInt; cdecl; external clib name 'chown';
     Function  FpChown   (path : pChar; owner : TUid; group : TGid): cInt; cdecl; external clib name 'chown';
     function  FpClose   (fd : cint): cint; cdecl; external clib name 'close';
     function  FpClose   (fd : cint): cint; cdecl; external clib name 'close';
-    Function  FpClosedir (var dirp : Dir): cInt; cdecl; external clib name 'closedir';
-    function  FpClosedir (dirp : pdir): cint; cdecl; external clib name 'closedir';
+    Function  FpClosedir (var dirp : Dir): cInt; cdecl; external clib name 'closedir'{$ifdef aix}+suffix64bit{$endif};
+    function  FpClosedir (dirp : pdir): cint; cdecl; external clib name 'closedir'{$ifdef aix}+suffix64bit{$endif};
     function  FpDup     (oldd:cint):cint; cdecl; external clib name 'dup';
     function  FpDup     (oldd:cint):cint; cdecl; external clib name 'dup';
     function  FpDup2    (oldd:cint;newd:cint):cint; cdecl; external clib name 'dup2';
     function  FpDup2    (oldd:cint;newd:cint):cint; cdecl; external clib name 'dup2';
     function  FpExecve  (path : pchar; argv : ppchar; envp: ppchar): cint; cdecl; external clib name 'execve';
     function  FpExecve  (path : pchar; argv : ppchar; envp: ppchar): cint; cdecl; external clib name 'execve';
@@ -51,8 +51,8 @@ const
                                               {$ifdef FPC_IS_SYSTEM}forward;{$endif} inline;
                                               {$ifdef FPC_IS_SYSTEM}forward;{$endif} inline;
     function  __FpOpen  (path: pchar; flags : cint; mode: TMode):cint; 
     function  __FpOpen  (path: pchar; flags : cint; mode: TMode):cint; 
 {$endif}
 {$endif}
-                                                                        cdecl; external clib name 'open';
-    function  FpOpendir (dirname : pchar): pdir; cdecl; external clib name 'opendir';
+                                                                        cdecl; external clib name 'open'{$ifdef aix}+suffix64bit{$endif};
+    function  FpOpendir (dirname : pchar): pdir; cdecl; external clib name 'opendir'{$ifdef aix}+suffix64bit{$endif};
     function  FpRead    (fd: cint; buf: pchar; nbytes : TSize): TSSize; cdecl; external clib name 'read';
     function  FpRead    (fd: cint; buf: pchar; nbytes : TSize): TSSize; cdecl; external clib name 'read';
     function  FpReaddir (dirp : pdir) : pdirent;cdecl; external clib name 'readdir'+suffix64bit;
     function  FpReaddir (dirp : pdir) : pdirent;cdecl; external clib name 'readdir'+suffix64bit;
     Function  FpReaddir (var dirp : Dir) : pDirent;cdecl; external clib name 'readdir'+suffix64bit;
     Function  FpReaddir (var dirp : Dir) : pDirent;cdecl; external clib name 'readdir'+suffix64bit;

+ 1 - 3
rtl/unix/sysunixh.inc

@@ -54,13 +54,11 @@ const
   sLineBreak = LineEnding;
   sLineBreak = LineEnding;
   DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
   DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
 
 
-{$ifndef Solaris}
-{$ifndef Darwin}
+{$if not defined(solaris) and not defined(darwin) and not defined(aix)}
 var argc:longint;external name 'operatingsystem_parameter_argc';
 var argc:longint;external name 'operatingsystem_parameter_argc';
     argv:PPchar;external name 'operatingsystem_parameter_argv';
     argv:PPchar;external name 'operatingsystem_parameter_argv';
     envp:PPchar;external name 'operatingsystem_parameter_envp';
     envp:PPchar;external name 'operatingsystem_parameter_envp';
 {$endif}
 {$endif}
-{$endif}
 
 
 {$ifdef unix}
 {$ifdef unix}
 const
 const

+ 4 - 4
rtl/unix/sysutils.pp

@@ -351,10 +351,10 @@ begin
 {$else}
 {$else}
   if (Handle>=0) then
   if (Handle>=0) then
     begin
     begin
-{$ifdef solaris}
-      { Solaris' flock is based on top of fcntl, which does not allow
-        exclusive locks for files only opened for reading nor shared
-        locks for files opened only for writing.
+{$if defined(solaris) or defined(aix)}
+      { Solaris' & AIX' flock is based on top of fcntl, which does not allow
+        exclusive locks for files only opened for reading nor shared locks
+        for files opened only for writing.
         
         
         If no locking is specified, we normally need an exclusive lock.
         If no locking is specified, we normally need an exclusive lock.
         So create an exclusive lock for fmOpenWrite and fmOpenReadWrite,
         So create an exclusive lock for fmOpenWrite and fmOpenReadWrite,

+ 2 - 2
rtl/unix/termiosh.inc

@@ -14,12 +14,12 @@
  ***********************************************************************}
  ***********************************************************************}
 
 
 { SunOS provides these functions directly }
 { SunOS provides these functions directly }
-{$ifndef SunOS}
+{$if not defined(SunOS) and not defined(aix)}
 Function  TCGetAttr   (fd:cint;var tios:TermIOS):cint; inline;
 Function  TCGetAttr   (fd:cint;var tios:TermIOS):cint; inline;
 Function  TCSetAttr   (fd:cint;OptAct:cint;const tios:TermIOS):cint;
 Function  TCSetAttr   (fd:cint;OptAct:cint;const tios:TermIOS):cint;
 Procedure CFSetISpeed (var tios:TermIOS;speed:Cardinal); inline;
 Procedure CFSetISpeed (var tios:TermIOS;speed:Cardinal); inline;
 Procedure CFSetOSpeed (var tios:TermIOS;speed:Cardinal); inline;
 Procedure CFSetOSpeed (var tios:TermIOS;speed:Cardinal); inline;
-{$endif SunOS}
+{$endif SunOS or aix}
 Procedure CFMakeRaw   (var tios:TermIOS);
 Procedure CFMakeRaw   (var tios:TermIOS);
 Function  TCSendBreak (fd,duration:cint):cint; inline;
 Function  TCSendBreak (fd,duration:cint):cint; inline;
 Function  TCSetPGrp   (fd,id:cint)  :cint;  inline;
 Function  TCSetPGrp   (fd,id:cint)  :cint;  inline;

+ 0 - 1
rtl/unix/timezone.inc

@@ -280,7 +280,6 @@ var
   f,len : longint;
   f,len : longint;
   s : shortstring;
   s : shortstring;
   info : stat;
   info : stat;
-
 begin
 begin
   GetTimezoneFile:='';
   GetTimezoneFile:='';
   f:=fpopen(TimeZoneLocationFile,Open_RdOnly);
   f:=fpopen(TimeZoneLocationFile,Open_RdOnly);

+ 2 - 2
rtl/unix/unix.pp

@@ -624,7 +624,7 @@ begin
      fpseterrno(ESysEBADF);
      fpseterrno(ESysEBADF);
      exit;
      exit;
    end;
    end;
- {$if not(defined(bsd)) and not(defined(solaris)) and not(defined(beos)) }
+ {$if not(defined(bsd)) and not(defined(solaris)) and not(defined(beos)) and not(defined(aix)) }
   p^.dd_nextoff:=fplseek(p^.dd_fd,loc,seek_set);
   p^.dd_nextoff:=fplseek(p^.dd_fd,loc,seek_set);
  {$endif}
  {$endif}
  {$if not(defined(beos))}
  {$if not(defined(beos))}
@@ -1196,7 +1196,7 @@ Function GetDomainName:String;
   end;
   end;
 {$endif sunos}
 {$endif sunos}
 
 
-{$ifdef BSD}
+{$if defined(BSD) or defined(aix)}
 
 
 function intGetDomainName(Name:PChar; NameLen:Cint):cint;
 function intGetDomainName(Name:PChar; NameLen:Cint):cint;
 {$ifndef FPC_USE_LIBC}
 {$ifndef FPC_USE_LIBC}

+ 3 - 3
rtl/unix/unxdeclh.inc

@@ -15,13 +15,13 @@
 
 
 type filedesarray=array[0..1] of cint;
 type filedesarray=array[0..1] of cint;
 
 
-{$ifdef solaris}
+{$if defined(solaris) or defined(aix)}
 Function fpFlock (fd,mode : longint) : cint;{$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
 Function fpFlock (fd,mode : longint) : cint;{$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
-{$else solaris}
+{$else solaris or aix}
 {$ifndef beos}
 {$ifndef beos}
 Function fpFlock (fd,mode : longint) : cint; cdecl; external clib name 'flock';
 Function fpFlock (fd,mode : longint) : cint; cdecl; external clib name 'flock';
 {$endif beos}
 {$endif beos}
-{$endif solaris}
+{$endif solaris or aix}
 
 
 {$if defined(beos) or defined(solaris) }
 {$if defined(beos) or defined(solaris) }
 Function fpfStatFS(Fd:Longint; Info:pstatfs):cint; cdecl; external clib name 'fstatvfs';
 Function fpfStatFS(Fd:Longint; Info:pstatfs):cint; cdecl; external clib name 'fstatvfs';