* first working version of the Darwin/Mac OS X (for PowerPC) RTL

Several non-essential units are still missing, but make cycle works
This commit is contained in:
Jonas Maebe 2004-01-04 20:05:38 +00:00
parent 8b43ff0b0b
commit 82343a6dc6
15 changed files with 5876 additions and 105 deletions

View File

@ -1,8 +1,8 @@
#
# Don't edit, this file is generated by FPCMake Version 1.1 [2003/10/28]
# Don't edit, this file is generated by FPCMake Version 1.1 [2004/01/08]
#
default: all
MAKEFILETARGETS=linux go32v2 win32 os2 freebsd beos netbsd amiga atari sunos qnx netware openbsd wdosx palmos macos darwin emx watcom
MAKEFILETARGETS=darwin
override PATH:=$(subst \,/,$(PATH))
ifeq ($(findstring ;,$(PATH)),)
inUnix=1
@ -91,7 +91,7 @@ endif
endif
export ECHO
endif
override OS_TARGET_DEFAULT=freebsd
override OS_TARGET_DEFAULT=darwin
override DEFAULT_FPCDIR=../..
ifndef FPC
ifdef PP
@ -211,31 +211,28 @@ INC=$(RTL)/inc
PROCINC=$(RTL)/$(CPU_TARGET)
BSDINC=$(RTL)/bsd
BSDPROCINC=$(BSDINC)/$(CPU_TARGET)
OSPROCINC=$(RTL)/darwin/$(CPU_TARGET)
UNIXINC=$(RTL)/unix
UNITPREFIX=rtl
ifeq ($(findstring 1.0.,$(FPC_VERSION)),)
SYSTEMUNIT=system
LINUXUNIT=
PRT0=prt0
override FPCOPT+=-dNOMOUSE
else
SYSTEMUNIT=sysbsd
LINUXUNIT=linux
override FPCOPT+=-dUNIX
PRT0=prt0_10
SYSTEMUNIT="Error: Darwin is not supported for 1.0"
endif
ifdef RELEASE
override FPCOPT+=-Ur
endif
override FPCOPT+=-dFPC_USE_LIBC
OBJPASDIR=$(RTL)/objpas
GRAPHDIR=$(INC)/graph
ifndef USELIBGGI
USELIBGGI=NO
endif
override TARGET_UNITS+=$(SYSTEMUNIT) objpas strings baseunix $(LINUXUNIT) unix initc dos crt objects printer sysutils typinfo math varutils cpu mmx charset ucomplex getopts heaptrc lineinfo errors sockets gpm ipc terminfo video mouse keyboard console serial variants types systhrds sysctl
override TARGET_LOADERS+=prt0 cprt0
override TARGET_RSTS+=math varutils typinfo
override TARGET_UNITS+=$(SYSTEMUNIT) objpas strings sysctl baseunix unixutil unix initc dos dl objects printer sysutils typinfo systhrds classes math varutils charset ucomplex getopts heaptrc lineinfo errors terminfo variants types sysctl dateutils sysconst cthreads
override TARGET_RSTS+=math varutils typinfo classes variants dateutils sysconst
override INSTALL_FPCPACKAGE=y y
override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(BSDINC) $(BSDPROCINC)
override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(BSDINC) $(BSDPROCINC) $(OSPROCINC)
override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(BSDINC)
override COMPILER_TARGETDIR+=.
ifdef REQUIRE_UNITSDIR
@ -1047,21 +1044,6 @@ ifeq ($(FULL_SOURCE),$(FULL_TARGET))
EXECPPAS:=@$(PPAS)
endif
endif
.PHONY: fpc_loaders
ifdef TARGET_LOADERS
override ALLTARGET+=fpc_loaders
override CLEANTARGET+=fpc_loaders_clean
override INSTALLTARGET+=fpc_loaders_install
override LOADEROFILES:=$(addsuffix $(OEXT),$(TARGET_LOADERS))
endif
%$(OEXT): %$(LOADEREXT)
$(AS) -o $*$(OEXT) $<
fpc_loaders: $(LOADEROFILES)
fpc_loaders_clean:
-$(DEL) $(LOADEROFILES)
fpc_loaders_install:
$(MKDIR) $(INSTALL_UNITDIR)
$(INSTALL) $(LOADEROFILES) $(INSTALL_UNITDIR)
.PHONY: fpc_units
ifdef TARGET_UNITS
override ALLTARGET+=fpc_units
@ -1349,34 +1331,34 @@ SYSINCDEPS=$(addprefix $(INC)/,$(SYSINCNAMES))
include $(PROCINC)/makefile.cpu
SYSCPUDEPS=$(addprefix $(PROCINC)/,$(CPUINCNAMES))
SYSDEPS=$(SYSINCDEPS) $(SYSCPUDEPS)
prt0$(OEXT) : $(CPU_TARGET)/$(PRT0).as
$(AS) -o prt0$(OEXT) $(CPU_TARGET)/$(PRT0).as
cprt0$(OEXT) : $(CPU_TARGET)/cprt0.as
$(AS) -o cprt0$(OEXT) $(CPU_TARGET)/cprt0.as
$(SYSTEMUNIT)$(PPUEXT) : $(BSDINC)/$(SYSTEMUNIT).pp sysconst.inc systypes.inc syscalls.inc $(SYSDEPS)
$(SYSTEMUNIT)$(PPUEXT) : $(BSDINC)/$(SYSTEMUNIT).pp sysconst.inc $(SYSDEPS)
$(COMPILER) -Us -Sg $(BSDINC)/$(SYSTEMUNIT).pp
objpas$(PPUEXT): $(OBJPASDIR)/objpas.pp $(INC)/except.inc $(SYSTEMUNIT)$(PPUEXT)
$(COMPILER) -I$(OBJPASDIR) $(OBJPASDIR)/objpas.pp
dateutils$(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)
baseunix$(PPUEXT) : $(UNIXINC)/errno.inc $(BSDINC)/bunxtype.inc ptypes.inc $(BSDINC)/ctypes.inc \
signal.inc $(UNIXINC)/bunxh.inc $(BSDINC)/bunxmain.inc $(BSDINC)/ostypes.inc \
$(BSDINC)/bunxfunc.inc $(BSDPROCINC)/syscallh.inc sysnr.inc \
$(BSDINC)/ostypes.inc $(BSDINC)/ossysch.inc $(BSDINC)/bunxmacr.inc $(UNIXINC)/gensigset.inc \
$(UNIXINC)/genfuncs.inc $(SYSTEMUNIT)$(PPUEXT)
baseunix$(PPUEXT) : errno.inc $(BSDINC)/bunxtype.inc ptypes.inc $(BSDINC)/ctypes.inc \
signal.inc $(UNIXINC)/bunxh.inc $(BSDINC)/bunxmain.inc $(BSDINC)/ostypes.inc \
$(BSDINC)/bunxfunc.inc \
$(BSDINC)/ostypes.inc $(BSDINC)/ossysch.inc $(BSDINC)/bunxmacr.inc $(UNIXINC)/gensigset.inc \
$(UNIXINC)/genfuncs.inc $(SYSTEMUNIT)$(PPUEXT)
unix$(PPUEXT) : $(UNIXINC)/unix.pp strings$(PPUEXT) $(INC)/textrec.inc $(INC)/filerec.inc \
syscalls.inc systypes.inc sysconst.inc $(UNIXINC)/timezone.inc \
sysconst.inc $(UNIXINC)/timezone.inc \
unixsysc.inc baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
linux$(PPUEXT) : baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
dos$(PPUEXT) : $(UNIXINC)/dos.pp $(INC)/filerec.inc $(INC)/textrec.inc strings$(PPUEXT) \
unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
crt$(PPUEXT) : $(UNIXINC)/crt.pp $(INC)/textrec.inc unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
objects$(PPUEXT) : $(INC)/objects.pp $(SYSTEMUNIT)$(PPUEXT)
printer$(PPUEXT) : $(UNIXINC)/printer.pp $(INC)/textrec.inc unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
sysutils$(PPUEXT) : $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/*.inc) \
objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT)
$(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/sysutils.pp
sysutils$(PPUEXT) : $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \
objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) $(OBJPASDIR)/sysconst$(PPUEXT)
$(COMPILER) -Fi$(OBJPASDIR)/sysutils $(UNIXINC)/sysutils.pp
classes$(PPUEXT) : classes.pp $(wildcard $(OBJPASDIR)/classes/*.inc) \
sysutils$(PPUEXT) typinfo$(PPUEXT)
$(COMPILER) -Fi$(OBJPASDIR)/classes classes.pp
typinfo$(PPUEXT): $(OBJPASDIR)/typinfo.pp objpas$(PPUEXT)
$(COMPILER) -Sg $(OBJPASDIR)/typinfo.pp
math$(PPUEXT): $(OBJPASDIR)/math.pp objpas$(PPUEXT) sysutils$(PPUEXT)
@ -1386,8 +1368,10 @@ gettext$(PPUEXT): $(OBJPASDIR)/gettext.pp objpas$(PPUEXT) sysutils$(PPUEXT)
varutils$(PPUEXT) : $(OBJPASDIR)/cvarutil.inc $(OBJPASDIR)/varutils.inc \
$(OBJPASDIR)/varutilh.inc varutils.pp
$(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/varutils.pp
types$(PPUEXT) : $(OBJPASDIR/types.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
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
cpu$(PPUEXT) : $(PROCINC)/cpu.pp $(SYSTEMUNIT)$(PPUEXT)
mmx$(PPUEXT) : $(PROCINC)/mmx.pp cpu$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
getopts$(PPUEXT) : $(INC)/getopts.pp $(SYSTEMUNIT)$(PPUEXT)
@ -1403,3 +1387,4 @@ ipc$(PPUEXT) : $(UNIXINC)/ipc.pp unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
terminfo$(PPUEXT) : terminfo.pp unix$(PPUEXT)
callspec$(PPUEXT) : $(INC)/callspec.pp $(SYSTEMUNIT)$(PPUEXT)
sysctl$(PPUEXT) : $(BSDINC)/sysctl.pp $(SYSTEMUNIT)$(PPUEXT)
cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp systhrds$(PPUEXT)

View File

@ -1,5 +1,5 @@
#
# Makefile.fpc for Free Pascal FreeBSD RTL
# Makefile.fpc for Free Pascal Darwin RTL
#
[package]
@ -8,16 +8,19 @@ main=rtl
[install]
fpcpackage=y
# disabled units: termio crt video keyboard serial sockets ipc mouse console
[target]
loaders=prt0 cprt0
units=$(SYSTEMUNIT) objpas strings baseunix \
$(LINUXUNIT) unix initc \
dos crt objects printer \
sysutils typinfo math varutils \
cpu mmx charset ucomplex getopts heaptrc lineinfo \
errors sockets gpm ipc terminfo \
video mouse keyboard console serial variants types systhrds sysctl sysconst
rsts=math varutils typinfo sysconst
loaders=
units=$(SYSTEMUNIT) objpas strings sysctl baseunix unixutil \
unix initc \
dos dl objects printer \
sysutils typinfo systhrds classes math varutils \
charset ucomplex getopts heaptrc lineinfo \
errors terminfo \
variants types sysctl dateutils \
sysconst cthreads
rsts=math varutils typinfo classes variants dateutils sysconst
[require]
nortl=y
@ -27,10 +30,10 @@ fpcpackage=y
[default]
fpcdir=../..
target=freebsd
target=darwin
[compiler]
includedir=$(INC) $(PROCINC) $(UNIXINC) $(BSDINC) $(BSDPROCINC)
includedir=$(INC) $(PROCINC) $(UNIXINC) $(BSDINC) $(BSDPROCINC) $(OSPROCINC)
sourcedir=$(INC) $(PROCINC) $(UNIXINC) $(BSDINC)
targetdir=.
@ -50,18 +53,15 @@ INC=$(RTL)/inc
PROCINC=$(RTL)/$(CPU_TARGET)
BSDINC=$(RTL)/bsd
BSDPROCINC=$(BSDINC)/$(CPU_TARGET)
OSPROCINC=$(RTL)/darwin/$(CPU_TARGET)
UNIXINC=$(RTL)/unix
UNITPREFIX=rtl
ifeq ($(findstring 1.0.,$(FPC_VERSION)),)
SYSTEMUNIT=system
LINUXUNIT=
PRT0=prt0
override FPCOPT+=-dNOMOUSE
else
SYSTEMUNIT=sysbsd
LINUXUNIT=linux
override FPCOPT+=-dUNIX
PRT0=prt0_10
SYSTEMUNIT="Error: Darwin is not supported for 1.0"
endif
# Use new feature from 1.0.5 version
@ -71,6 +71,9 @@ ifdef RELEASE
override FPCOPT+=-Ur
endif
# Darwin requires libc, no syscalls
override FPCOPT+=-dFPC_USE_LIBC
# Paths
OBJPASDIR=$(RTL)/objpas
GRAPHDIR=$(INC)/graph
@ -102,26 +105,21 @@ SYSCPUDEPS=$(addprefix $(PROCINC)/,$(CPUINCNAMES))
SYSDEPS=$(SYSINCDEPS) $(SYSCPUDEPS)
#
# Loaders
#
prt0$(OEXT) : $(CPU_TARGET)/$(PRT0).as
$(AS) -o prt0$(OEXT) $(CPU_TARGET)/$(PRT0).as
cprt0$(OEXT) : $(CPU_TARGET)/cprt0.as
$(AS) -o cprt0$(OEXT) $(CPU_TARGET)/cprt0.as
#
# System Units (System, Objpas, Strings)
#
$(SYSTEMUNIT)$(PPUEXT) : $(BSDINC)/$(SYSTEMUNIT).pp sysconst.inc systypes.inc syscalls.inc $(SYSDEPS)
$(SYSTEMUNIT)$(PPUEXT) : $(BSDINC)/$(SYSTEMUNIT).pp sysconst.inc $(SYSDEPS)
$(COMPILER) -Us -Sg $(BSDINC)/$(SYSTEMUNIT).pp
objpas$(PPUEXT): $(OBJPASDIR)/objpas.pp $(INC)/except.inc $(SYSTEMUNIT)$(PPUEXT)
$(COMPILER) -I$(OBJPASDIR) $(OBJPASDIR)/objpas.pp
dateutils$(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)
@ -130,18 +128,17 @@ strings$(PPUEXT) : $(INC)/strings.pp $(INC)/stringsi.inc\
# System Dependent Units
#
baseunix$(PPUEXT) : $(UNIXINC)/errno.inc $(BSDINC)/bunxtype.inc ptypes.inc $(BSDINC)/ctypes.inc \
baseunix$(PPUEXT) : errno.inc $(BSDINC)/bunxtype.inc ptypes.inc $(BSDINC)/ctypes.inc \
signal.inc $(UNIXINC)/bunxh.inc $(BSDINC)/bunxmain.inc $(BSDINC)/ostypes.inc \
$(BSDINC)/bunxfunc.inc $(BSDPROCINC)/syscallh.inc sysnr.inc \
$(BSDINC)/bunxfunc.inc \
$(BSDINC)/ostypes.inc $(BSDINC)/ossysch.inc $(BSDINC)/bunxmacr.inc $(UNIXINC)/gensigset.inc \
$(UNIXINC)/genfuncs.inc $(SYSTEMUNIT)$(PPUEXT)
unix$(PPUEXT) : $(UNIXINC)/unix.pp strings$(PPUEXT) $(INC)/textrec.inc $(INC)/filerec.inc \
syscalls.inc systypes.inc sysconst.inc $(UNIXINC)/timezone.inc \
sysconst.inc $(UNIXINC)/timezone.inc \
unixsysc.inc baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
linux$(PPUEXT) : baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
#
# TP7 Compatible RTL Units
@ -164,9 +161,13 @@ printer$(PPUEXT) : $(UNIXINC)/printer.pp $(INC)/textrec.inc unix$(PPUEXT) $(SYST
# Delphi Compatible Units
#
sysutils$(PPUEXT) : $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/*.inc) \
objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) sysconst$(PPUEXT)
$(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/sysutils.pp
sysutils$(PPUEXT) : $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \
objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) $(OBJPASDIR)/sysconst$(PPUEXT)
$(COMPILER) -Fi$(OBJPASDIR)/sysutils $(UNIXINC)/sysutils.pp
classes$(PPUEXT) : classes.pp $(wildcard $(OBJPASDIR)/classes/*.inc) \
sysutils$(PPUEXT) typinfo$(PPUEXT)
$(COMPILER) -Fi$(OBJPASDIR)/classes classes.pp
typinfo$(PPUEXT): $(OBJPASDIR)/typinfo.pp objpas$(PPUEXT)
$(COMPILER) -Sg $(OBJPASDIR)/typinfo.pp
@ -181,9 +182,12 @@ varutils$(PPUEXT) : $(OBJPASDIR)/cvarutil.inc $(OBJPASDIR)/varutils.inc \
$(OBJPASDIR)/varutilh.inc varutils.pp
$(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/varutils.pp
types$(PPUEXT) : $(OBJPASDIR/types.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
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
#
# Other system-independent RTL Units
#
@ -218,4 +222,8 @@ terminfo$(PPUEXT) : terminfo.pp unix$(PPUEXT)
callspec$(PPUEXT) : $(INC)/callspec.pp $(SYSTEMUNIT)$(PPUEXT)
sysctl$(PPUEXT) : $(BSDINC)/sysctl.pp $(SYSTEMUNIT)$(PPUEXT)
cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp systhrds$(PPUEXT)

80
rtl/darwin/classes.pp Normal file
View File

@ -0,0 +1,80 @@
{
$Id$
This file is part of the Free Component Library (FCL)
Copyright (c) 1999-2000 by Michael Van Canneyt and Florian Klaempfl
Classes unit for linux
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.
**********************************************************************}
{$mode objfpc}
{ determine the type of the resource/form file }
{$define Win16Res}
unit Classes;
interface
uses
sysutils,
typinfo;
{$i classesh.inc}
implementation
uses
baseunix,unix,Systhrds
;
{ OS - independent class implementations are in /inc directory. }
{$i classes.inc}
initialization
CommonInit;
finalization
CommonCleanup;
if ThreadsInited then
DoneThreads;
end.
{
$Log$
Revision 1.1 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
Revision 1.4 2003/12/22 16:16:33 marco
* small 1.0 compat fix
Revision 1.3 2003/11/17 10:05:51 marco
* threads for FreeBSD. Not working tho
Revision 1.2 2003/10/09 10:55:20 marco
* fix for moving classes to rtl while cycling with 1.0 start
Revision 1.1 2003/10/06 21:01:06 peter
* moved classes unit to rtl
Revision 1.1 2003/10/06 20:33:58 peter
* classes moved to rtl for 1.1
* classes .inc and classes.pp files moved to fcl/classes for
backwards 1.0.x compatiblity to have it in the fcl
Revision 1.6 2003/09/20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.5 2002/09/07 15:15:24 peter
* old logs removed and tabs fixed
}

3475
rtl/darwin/console.pp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,110 @@
{
$Id$
Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
@APPLE_LICENSE_HEADER_START@
The contents of this file constitute Original Code as defined in and
are subject to the Apple Public Source License Version 1.1 (the
"License"). You may not use this file except in compliance with the
License. Please obtain a copy of the License at
http://www.apple.com/publicsource and read it before using this file.
This Original Code and all software distributed under the License are
distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
License for the specific language governing rights and limitations
under the License.
@APPLE_LICENSE_HEADER_END@
}
{
Copyright (c) 1992, 1993 NeXT Computer, Inc.
HISTORY
Machine specific signal information.
HISTORY
25-MAR-97 Umesh Vaishampayan (umeshv@NeXT.com)
Ported from m98k and hppa.
13-Jan-92 Peter King (king) at NeXT Computer, Inc.
Filled out struct sigcontext to hold all registers.
Added regs_saved_t to specify which regs stored in the
sigcontext are valid.
09-Nov-92 Ben Fathi (benf) at NeXT, Inc.
Ported to m98k.
09-May-91 Mike DeMoney (mike) at NeXT, Inc.
Ported to m88k.
}
const
_PPC_SIGNAL_ = 1;
type
sig_atomic_t = longint;
{
Machine-dependant flags used in sigvec call.
}
{ Save all regs in sigcontext }
const
SV_SAVE_REGS = $1000;
{
regs_saved_t -- Describes which registers beyond what the kernel cares
about are saved to and restored from this sigcontext.
The default is REGS_SAVED_CALLER, only the caller saved registers
are saved. If the SV_SAVE_REGS flag was set when the signal
handler was registered with sigvec() then all the registers will be
saved in the sigcontext, and REGS_SAVED_ALL will be set. The C
library uses REGS_SAVED_NONE in order to quickly restore kernel
state during a longjmp().
}
{ Only kernel managed regs restored }
{ "Caller saved" regs: rpc, a0-a7,
t0-t4, at, lk0-lk1, xt1-xt20,
xr0-xr1 }
{ All registers }
type
regs_saved_t = (REGS_SAVED_NONE,REGS_SAVED_CALLER,REGS_SAVED_ALL
);
{
Information pushed on stack when a signal is delivered.
This is used by the kernel to restore state following
execution of the signal handler. It is also made available
to the handler to allow it to properly restore state if
a non-standard exit is performed.
}
sigcontextrec = record
{ sigstack state to restore }
sc_onstack : longint;
{ signal mask to restore }
sc_mask : longint;
{ pc }
sc_ir : longint;
{ processor status word }
sc_psw : longint;
{ stack pointer if sc_regs == NULL }
sc_sp : longint;
{ (kernel private) saved state }
sc_regs : pointer;
end;
{
$Log$
Revision 1.1 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
Revision 1.1 2002/09/08 09:01:48 jonas
+ initial revision
}

View File

@ -0,0 +1,63 @@
{
$Id$
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.
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; var info : tsiginfo_t;Var SigContext:SigContextRec); cdecl;
var
res : word;
begin
res:=0;
{ have to verify whether this is necessary }
fpc_enable_ppc_fpu_exceptions;
case sig of
SIGFPE :
begin
Case Info.si_code Of
FPE_INTDIV : Res:=200; {integer divide fault. Div0?}
FPE_FLTOVF : Res:=205; {Overflow trap}
FPE_FLTUND : Res:=206; {Stack over/underflow}
FPE_FLTRES : Res:=208; {Device not available}
FPE_FLTINV : Res:=207; {Invalid floating point operation}
Else
Res:=208; {coprocessor error}
end;
end;
SIGILL,
SIGBUS,
SIGSEGV :
res:=216;
end;
{$ifdef FPC_USE_SIGPROCMASK}
reenable_signal(sig);
{$endif }
{ give runtime error at the position where the signal was raised }
if res<>0 then
begin
HandleErrorAddrFrame(res,Pointer(SigContext.sc_ir),pointer(SigContext.sc_sp));
end;
end;
{
$Log$
Revision 1.1 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
Revision 1.1 2004/01/03 12:29:36 marco
* now separately.
}

72
rtl/darwin/pthread.inc Normal file
View File

@ -0,0 +1,72 @@
{
$Id$
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 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 = 0;
PTHREAD_CREATE_DETACHED = 1;
PTHREAD_SCOPE_PROCESS = 0;
TYPE
pthread_t = pointer;
ppthread_t = ^pthread_t;
pthread_key_t = cint;
ppthread_key_t = ^pthread_key_t;
pthread_mutex_t = TRTLCriticalSection;
ppthread_mutex_t= PRTLCriticalSection;
pthread_attr_t = pointer; // opague
ppthread_attr_t = ^pthread_attr_t; // opague
__destr_func_t = procedure (p :pointer);cdecl;
__startroutine_t= function (p :pointer):pointer;cdecl;
pthread_mutex_attr_t = pointer;
ppthread_mutex_attr_t = ^pthread_mutex_t;
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_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:cint; cdecl;external 'c';
function pthread_mutex_init (p:ppthread_mutex_t;o:ppthread_mutex_attr_t):cint; cdecl;external 'c';
function pthread_mutex_destroy (p:ppthread_mutex_attr_t):cint; cdecl;external 'c';
function pthread_mutex_lock (p:ppthread_mutex_attr_t):cint; cdecl;external 'c';
function pthread_mutex_unlock (p:ppthread_mutex_attr_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';
{
$Log$
Revision 1.1 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
Revision 1.2 2003/11/27 20:24:10 michael
+ Redefined ppthread_mutex_t
Revision 1.1 2003/11/18 22:33:42 marco
* moved from systhrds.pp
}

View File

@ -55,7 +55,7 @@ type
pPid = ^pid_t;
size_t = cuint32; { as definied in the C standard}
TSize = size_t;
TSize = size_t;
pSize = ^size_t;
ssize_t = cint32; { used by function for returning number of bytes }
@ -73,11 +73,28 @@ type
time_t = clong; { used for returning the time }
TTime = time_t;
pTime = ^time_t;
ptime_t = ^time_t;
socklen_t= cuint32;
TSocklen = socklen_t;
pSocklen = ^socklen_t;
timeval = record
tv_sec: cint;
tv_usec: cint;
end;
ptimeval = ^timeval;
TTimeVal = timeval;
timespec = packed record
tv_sec : time_t;
tv_nsec : clong;
end;
ptimespec= ^timespec;
Ttimespec= timespec;
CONST
{ System limits, POSIX value in parentheses, used for buffer and stack allocation }
ARG_MAX = 65536; {4096} { Maximum number of argument size }
@ -86,9 +103,49 @@ CONST
SYS_NMLN = 32; {BSD utsname struct limit}
SIG_MAXSIG = 32; // highest signal version
wordsinsigset = 1; // words in sigset_t
MFSNAMELEN = 15;
MNAMELEN = 90;
type
fsid_t = record
val: array[0..1] of cint32;
end;
tstatfs = record
otype : cint16;
oflags : cint16;
bsize : cint32;
iosize : cint32;
blocks : cint32;
bfree : cint32;
bavail : cint32;
files : cint32;
ffree : cint32;
fsid : fsid_t;
fowner : uid_t;
reserved1 : cint16;
ftype : cint16;
fflags : cint32;
reserved2 : array[0..1] of cint32;
fstypename : array[0..(MFSNAMELEN)-1] of char;
mountpoint : array[0..(MNAMELEN)-1] of char;
mntfromname : array[0..(MNAMELEN)-1] of char;
end;
pstatfs = ^tstatfs;
{
$Log$
Revision 1.2 2003-05-25 12:59:57 jonas
Revision 1.3 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
Revision 1.2 2003/05/25 12:59:57 jonas
* several fixes, addition of Mach trap numbers (thye are simply syscalls
with a negative number)

View File

@ -64,10 +64,10 @@
}
{$ifdef cpupowerpc}
{$include powerpc/signal.inc} { sigcontext }
{$include powerpc/sig_cpu.inc} { sigcontext }
{$else cpupowerpc}
{$ifdef cpui386}
{$include i386/signal.inc} { sigcontext }
{$include i386/sig_cpu.inc} { sigcontext }
{$else cpui386}
{$error Unsupported cpu type!}
{$endif cpui386}
@ -75,6 +75,15 @@
const
SA_NOCLDSTOP = 8;
SA_ONSTACK = $001; { take signal on signal stack }
SA_RESTART = $002; { restart system call on signal return }
SA_RESETHAND = $004; { reset to SIG_DFL when taking signal }
SA_NODEFER = $010; { don't mask the signal we're delivering }
SA_NOCLDWAIT = $020; { don't keep zombies around }
SA_SIGINFO = $040; { signal handler with SA_SIGINFO args }
SA_USERTRAMP = $100; { SUNOS compat: Do not bounce off kernel's sigtramp }
{ hangup }
SIGHUP = 1;
{ interrupt }
@ -144,16 +153,43 @@
SIG_ERR = -1;
type
sigset_t = dword;
sigset_t = array[0..0] of cuint;
Sigval = Record
Case Boolean OF
{ Members as suggested by Annex C of POSIX 1003.1b. }
false : (sigval_int : cint);
True : (sigval_ptr : Pointer);
End;
TSigInfo_t = record
si_signo, { signal number }
si_errno, { errno association }
{
* Cause of signal, one of the SI_ macros or signal-specific
* values, i.e. one of the FPE_... values for SIGFPE. This
* value is equivalent to the second argument to an old-style
* FreeBSD signal handler.
}
si_code, { signal code }
si_pid : cint; { sending process }
si_uid : cuint; { sender's ruid }
si_status : cint; { exit value }
si_addr : Pointer; { faulting instruction }
si_value : SigVal; { signal value }
si_band : cuint; { band event for SIGPOLL }
pad : array[0..6] of cint; { Reserved for Future Use }
end;
SignalHandler = Procedure(Sig : Longint);cdecl;
PSignalHandler = ^SignalHandler;
SignalRestorer = Procedure;cdecl;
PSignalRestorer = ^SignalRestorer;
TSigAction = procedure(Sig: Longint; SigContext: SigContextRec;someptr:pointer);cdecl;
TSigAction = procedure (Sig: cint; var info : tsiginfo_t;Var SigContext:SigContextRec); cdecl;
TSigset=sigset_t;
Sigset=sigset_t;
PSigSet = ^SigSet;
PSigSet = ^TSigSet;
SigActionRec = packed record
{
@ -161,24 +197,16 @@
0: (Sh: SignalHandler; Sa_Flags: longint; Sa_Mask: SigSet);
1: (sa_handler: TSigAction);
}
Sa_Handler: SignalHandler;
Sa_Handler: TSigAction;
Sa_Flags: longint;
Sa_Mask: SigSet;
Sa_Mask: TSigSet;
end;
PSigActionRec = ^SigActionRec;
const
SA_ONSTACK = $0001;
{ restart system on signal return }
SA_RESTART = $0002;
{ disable taking signals on alternate stack }
SA_DISABLE = $0004;
{ do not bounce off kernel's sigtramp }
SA_USERTRAMP = $0100;
{ do not generate SIGCHLD on child stop }
SA_NOCLDSTOP = $0008;
{
Flags for sigprocmask:
}
const
{ block specified signal set }
SIG_BLOCK = 1;
{ unblock specified signal set }
@ -205,19 +233,20 @@
const
MINSIGSTKSZ = 8192;
{ recommended stack size }
SIGSTKSZ = MINSIGSTKSZ + 32768;
{ already defined in another BSD include file }
// SIGSTKSZ = MINSIGSTKSZ + 32768;
{
4.3 compatibility:
Signal vector "template" used in sigvec call.
}
{ signal handler }
{ signal mask to apply }
{ see signal options below }
type
sigvec = record
{ signal handler }
sv_handler : procedure ;
{ signal mask to apply }
sv_mask : longint;
{ see signal options below }
sv_flags : longint;
end;
@ -227,6 +256,16 @@
{ same bit, opposite sense }
SV_INTERRUPT = SA_RESTART;
{ Codes for SIGFPE }
FPE_NOOP = 0; { if only I knew... }
FPE_FLTDIV = 1; { floating point divide by zero }
FPE_INTDIV = FPE_FLTDIV;
FPE_FLTOVF = 2; { floating point overflow }
FPE_FLTUND = 3; { floating point underflow }
FPE_FLTRES = 4; { floating point inexact result }
FPE_FLTINV = 5; { invalid floating point operation }
(*
{
Structure used in sigstack call.
@ -243,7 +282,11 @@
{
$Log$
Revision 1.3 2003-08-21 22:25:17 olle
Revision 1.4 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
Revision 1.3 2003/08/21 22:25:17 olle
- removed parameter from fpc_iocheck
Revision 1.2 2003/05/25 12:59:57 jonas

543
rtl/darwin/sysctlh.inc Normal file
View File

@ -0,0 +1,543 @@
{
$Id$
}
{$PACKRECORDS C}
{
Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
@APPLE_LICENSE_HEADER_START@
The contents of this file constitute Original Code as defined in and
are subject to the Apple Public Source License Version 1.1 (the
"License"). You may not use this file except in compliance with the
License. Please obtain a copy of the License at
http://www.apple.com/publicsource and read it before using this file.
This Original Code and all software distributed under the License are
distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
License for the specific language governing rights and limitations
under the License.
@APPLE_LICENSE_HEADER_END@
}
{ Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved }
{
Copyright (c) 1989, 1993
The Regents of the University of California. All rights reserved.
This code is derived from software contributed to Berkeley by
Mike Karels at Berkeley Software Design, Inc.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by the University of
California, Berkeley and its contributors.
4. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
@(#)sysctl.h 8.1 (Berkeley) 6/2/93
}
{
These are for the eproc structure defined below.
}
{
Definitions for sysctl call. The sysctl call uses a hierarchical name
for objects that can be examined or modified. The name is expressed as
a sequence of integers. Like a file path name, the meaning of each
component depends on its place in the hierarchy. The top-level and kern
identifiers are defined here, and other identifiers are defined in the
respective subsystem header files.
}
{ largest number of components supported }
const
CTL_MAXNAME = 12;
{
Each subsystem defined by sysctl defines a list of variables
for that subsystem. Each name is either a node with further
levels defined below it, or it is a leaf of some particular
type given below. Each sysctl level defines a set of name/type
pairs to be used by sysctl(1) in manipulating the subsystem.
}
{ subsystem name }
{ type of name }
type
ctlname = record
ctl_name : ^char;
ctl_type : longint;
end;
{ Mask for the type }
const
CTLTYPE = $f;
{ name is a node }
CTLTYPE_NODE = 1;
{ name describes an integer }
CTLTYPE_INT = 2;
{ name describes a string }
CTLTYPE_STRING = 3;
{ name describes a 64-bit number }
CTLTYPE_QUAD = 4;
{ name describes a structure }
CTLTYPE_OPAQUE = 5;
{ name describes a structure }
CTLTYPE_STRUCT = CTLTYPE_OPAQUE;
{ Allow reads of variable }
CTLFLAG_RD = $80000000;
{ Allow writes to the variable }
CTLFLAG_WR = $40000000;
CTLFLAG_RW = CTLFLAG_RD or CTLFLAG_WR;
{ XXX Don't Lock }
CTLFLAG_NOLOCK = $20000000;
{ All users can set this var }
CTLFLAG_ANYBODY = $10000000;
{ Permit set only if securelevel<=0 }
CTLFLAG_SECURE = $08000000;
{ deprecated variable, do not display }
CTLFLAG_MASKED = $04000000;
{ do not auto-register }
CTLFLAG_NOAUTO = $02000000;
{ valid inside the kernel }
CTLFLAG_KERN = $01000000;
{
USE THIS instead of a hardwired number from the categories below
to get dynamically assigned sysctl entries using the linker-set
technology. This is the way nearly all new sysctl variables should
be implemented.
e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
}
OID_AUTO = -(1);
{
Top-level identifiers
}
{ unused }
CTL_UNSPEC = 0;
{ "high kernel": proc, limits }
CTL_KERN = 1;
{ virtual memory }
CTL_VM = 2;
{ file system, mount type is next }
CTL_VFS = 3;
{ network, see socket.h }
CTL_NET = 4;
{ debugging parameters }
CTL_DEBUG = 5;
{ generic cpu/io }
CTL_HW = 6;
{ machine dependent }
CTL_MACHDEP = 7;
{ user-level }
CTL_USER = 8;
{ number of valid top-level ids }
CTL_MAXID = 9;
{
CTL_KERN identifiers
}
{ string: system version }
KERN_OSTYPE = 1;
{ string: system release }
KERN_OSRELEASE = 2;
{ int: system revision }
KERN_OSREV = 3;
{ string: compile time info }
KERN_VERSION = 4;
{ int: max vnodes }
KERN_MAXVNODES = 5;
{ int: max processes }
KERN_MAXPROC = 6;
{ int: max open files }
KERN_MAXFILES = 7;
{ int: max arguments to exec }
KERN_ARGMAX = 8;
{ int: system security level }
KERN_SECURELVL = 9;
{ string: hostname }
KERN_HOSTNAME = 10;
{ int: host identifier }
KERN_HOSTID = 11;
{ struct: struct clockrate }
KERN_CLOCKRATE = 12;
{ struct: vnode structures }
KERN_VNODE = 13;
{ struct: process entries }
KERN_PROC = 14;
{ struct: file entries }
KERN_FILE = 15;
{ node: kernel profiling info }
KERN_PROF = 16;
{ int: POSIX.1 version }
KERN_POSIX1 = 17;
{ int: # of supplemental group ids }
KERN_NGROUPS = 18;
{ int: is job control available }
KERN_JOB_CONTROL = 19;
{ int: saved set-user/group-ID }
KERN_SAVED_IDS = 20;
{ struct: time kernel was booted }
KERN_BOOTTIME = 21;
{ string: YP domain name }
KERN_NISDOMAINNAME = 22;
KERN_DOMAINNAME = KERN_NISDOMAINNAME;
{ int: number of partitions/disk }
KERN_MAXPARTITIONS = 23;
{ int: kernel trace points }
KERN_KDEBUG = 24;
{ int: update process sleep time }
KERN_UPDATEINTERVAL = 25;
{ int: OS release date }
KERN_OSRELDATE = 26;
{ node: NTP PLL control }
KERN_NTP_PLL = 27;
{ string: name of booted kernel }
KERN_BOOTFILE = 28;
{ int: max open files per proc }
KERN_MAXFILESPERPROC = 29;
{ int: max processes per uid }
KERN_MAXPROCPERUID = 30;
{ dev_t: device to dump on }
KERN_DUMPDEV = 31;
{ node: anything related to IPC }
KERN_IPC = 32;
{ unused }
KERN_DUMMY = 33;
{ int: address of PS_STRINGS }
KERN_PS_STRINGS = 34;
{ int: address of USRSTACK }
KERN_USRSTACK = 35;
{ int: do we log sigexit procs? }
KERN_LOGSIGEXIT = 36;
{ string: kernel symbol filename }
KERN_SYMFILE = 37;
KERN_PROCARGS = 38;
{ node: pc sampling }
KERN_PCSAMPLES = 39;
{ int: are we netbooted? 1=yes,0=no }
KERN_NETBOOT = 40;
{ node: panic UI information }
KERN_PANICINFO = 41;
{ node: panic UI information }
KERN_SYSV = 42;
{ xxx }
KERN_AFFINITY = 43;
{ xxx }
KERN_CLASSIC = 44;
{ xxx }
KERN_CLASSICHANDLER = 45;
{ int: max aio requests }
KERN_AIOMAX = 46;
{ int: max aio requests per process }
KERN_AIOPROCMAX = 47;
{ int: max aio worker threads }
KERN_AIOTHREADS = 48;
{ __APPLE_API_UNSTABLE }
{ number of valid kern ids }
const
KERN_MAXID = 50;
{ KERN_KDEBUG types }
KERN_KDEFLAGS = 1;
KERN_KDDFLAGS = 2;
KERN_KDENABLE = 3;
KERN_KDSETBUF = 4;
KERN_KDGETBUF = 5;
KERN_KDSETUP = 6;
KERN_KDREMOVE = 7;
KERN_KDSETREG = 8;
KERN_KDGETREG = 9;
KERN_KDREADTR = 10;
KERN_KDPIDTR = 11;
KERN_KDTHRMAP = 12;
{ Don't use 13 as it is overloaded with KERN_VNODE }
KERN_KDPIDEX = 14;
KERN_KDSETRTCDEC = 15;
KERN_KDGETENTROPY = 16;
{ KERN_PCSAMPLES types }
KERN_PCDISABLE = 1;
KERN_PCSETBUF = 2;
KERN_PCGETBUF = 3;
KERN_PCSETUP = 4;
KERN_PCREMOVE = 5;
KERN_PCREADBUF = 6;
KERN_PCSETREG = 7;
KERN_PCCOMM = 8;
{ KERN_PANICINFO types }
{ quad: panic UI image size limit }
KERN_PANICINFO_MAXSIZE = 1;
{ string: path to the panic UI (16 bit) }
KERN_PANICINFO_IMAGE16 = 2;
{ string: path to the panic UI (32 bit) }
KERN_PANICINFO_IMAGE32 = 3;
{
KERN_SYSV identifiers
}
{ int: max shared memory segment size (bytes) }
KSYSV_SHMMAX = 1;
{ int: min shared memory segment size (bytes) }
KSYSV_SHMMIN = 2;
{ int: max number of shared memory identifiers }
KSYSV_SHMMNI = 3;
{ int: max shared memory segments per process }
KSYSV_SHMSEG = 4;
{ int: max amount of shared memory (pages) }
KSYSV_SHMALL = 5;
{ int: max num of semaphore identifiers }
KSYSV_SEMMNI = 6;
{ int: max num of semaphores in system }
KSYSV_SEMMNS = 7;
{ int: max num of undo structures in system }
KSYSV_SEMMNU = 8;
{ int: max num of semaphores per id }
KSYSV_SEMMSL = 9;
{ int: max num of undo entries per process }
KSYSV_SEMUNE = 10;
error1 = 1;
{
KERN_PROC subtypes
}
{ everything }
KERN_PROC_ALL = 0;
{ by process id }
KERN_PROC_PID = 1;
{ by process group id }
KERN_PROC_PGRP = 2;
{ by session of pid }
KERN_PROC_SESSION = 3;
{ by controlling tty }
KERN_PROC_TTY = 4;
{ by effective uid }
KERN_PROC_UID = 5;
{ by real uid }
KERN_PROC_RUID = 6;
{
KERN_PROC subtype ops return arrays of augmented proc structures:
}
{
KERN_IPC identifiers
}
{ int: max size of a socket buffer }
const
KIPC_MAXSOCKBUF = 1;
{ int: wastage factor in sockbuf }
KIPC_SOCKBUF_WASTE = 2;
{ int: max length of connection q }
KIPC_SOMAXCONN = 3;
{ int: max length of link header }
KIPC_MAX_LINKHDR = 4;
{ int: max length of network header }
KIPC_MAX_PROTOHDR = 5;
{ int: max total length of headers }
KIPC_MAX_HDR = 6;
{ int: max length of data? }
KIPC_MAX_DATALEN = 7;
{ struct: mbuf usage statistics }
KIPC_MBSTAT = 8;
{ int: maximum mbuf clusters }
KIPC_NMBCLUSTERS = 9;
{
CTL_VM identifiers
}
{ struct vmmeter }
VM_METER = 1;
{ struct loadavg }
VM_LOADAVG = 2;
{ number of valid vm ids }
VM_MAXID = 3;
{ struct loadavg with mach factor }
VM_MACHFACTOR = 4;
{
CTL_HW identifiers
}
{ string: machine class }
HW_MACHINE = 1;
{ string: specific machine model }
HW_MODEL = 2;
{ int: number of cpus }
HW_NCPU = 3;
{ int: machine byte order }
HW_BYTEORDER = 4;
{ int: total memory }
HW_PHYSMEM = 5;
{ int: non-kernel memory }
HW_USERMEM = 6;
{ int: software page size }
HW_PAGESIZE = 7;
{ strings: disk drive names }
HW_DISKNAMES = 8;
{ struct: diskstats[] }
HW_DISKSTATS = 9;
{ int: 0 for Legacy, else NewWorld }
HW_EPOCH = 10;
{ int: has HW floating point? }
HW_FLOATINGPT = 11;
{ string: machine architecture }
HW_MACHINE_ARCH = 12;
{ int: has HW vector unit? }
HW_VECTORUNIT = 13;
{ int: Bus Frequency }
HW_BUS_FREQ = 14;
{ int: CPU Frequency }
HW_CPU_FREQ = 15;
{ int: Cache Line Size in Bytes }
HW_CACHELINE = 16;
{ int: L1 I Cache Size in Bytes }
HW_L1ICACHESIZE = 17;
{ int: L1 D Cache Size in Bytes }
HW_L1DCACHESIZE = 18;
{ int: L2 Cache Settings }
HW_L2SETTINGS = 19;
{ int: L2 Cache Size in Bytes }
HW_L2CACHESIZE = 20;
{ int: L3 Cache Settings }
HW_L3SETTINGS = 21;
{ int: L3 Cache Size in Bytes }
HW_L3CACHESIZE = 22;
{ int: Bus Frequency }
HW_TB_FREQ = 23;
{ uint64_t: physical ram size }
HW_MEMSIZE = 24;
{ int: number of available CPUs }
HW_AVAILCPU = 25;
{ number of valid hw ids }
HW_MAXID = 26;
{
These are the support HW selectors for sysctlbyname. Parameters that are byte count or frequencies are 64 bit numbers.
All other parameters are 32 bit numbers.
hw.memsize - The number of bytes of physical memory in the system.
hw.ncpu - The number maximum number of processor that could be available this boot.
Use this value for sizing of static per processor arrays; i.e. processor load statistics.
hw.activecpu - The number of cpus currently available for executing threads.
Use this number to determine the number threads to create in SMP aware applications.
This number can change when power management modes are changed.
hw.tbfrequency - This gives the time base frequency used by the OS and is the basis of all timing services.
In general is is better to use mach's or higher level timing services, but this value
is needed to convert the PPC Time Base registers to real time.
hw.cpufrequency - These values provide the current, min and max cpu frequency. The min and max are for
hw.cpufrequency_max - all power management modes. The current frequency is the max frequency in the current mode.
hw.cpufrequency_min - All frequencies are in Hz.
hw.busfrequency - These values provide the current, min and max bus frequency. The min and max are for
hw.busfrequency_max - all power management modes. The current frequency is the max frequency in the current mode.
hw.busfrequency_min - All frequencies are in Hz.
hw.cputype - These values provide the mach-o cpu type and subtype. A complete list is in <mach/machine.h>
hw.cpusubtype - These values should be used to determine what processor family the running cpu is from so that
the best binary can be chosen, or the best dynamic code generated. They should not be used
to determine if a given processor feature is available.
hw.byteorder - Gives the byte order of the processor. 4321 for big endian, 1234 for little.
hw.pagesize - Gives the size in bytes of the pages used by the processor and VM system.
hw.cachelinesize - Gives the size in bytes of the processor's cache lines.
This value should be use to control the strides of loops that use cache control instructions
like dcbz, dcbt or dcbst.
hw.l1dcachesize - These values provide the size in bytes of the L1, L2 and L3 caches. If a cache is not present
hw.l1icachesize - then the selector will return and error.
hw.l2cachesize -
hw.l3cachesize -
These are the selectors for optional processor features. Selectors that return errors are not support on the system.
Supported features will return 1 if they are recommended or 0 if they are supported but are not expected to help performance.
Future versions of these selectors may return larger values as necessary so it is best to test for non zero.
hw.optional.floatingpoint - Floating Point Instructions
hw.optional.altivec - AltiVec Instructions
hw.optional.graphicsops - Graphics Operations
hw.optional.64bitops - 64-bit Instructions
hw.optional.fsqrt - HW Floating Point Square Root Instruction
hw.optional.stfiwx - Store Floating Point as Integer Word Indexed Instructions
hw.optional.dcba - Data Cache Block Allocate Instruction
hw.optional.datastreams - Data Streams Instructions
hw.optional.dcbtstreams - Data Cache Block Touch Steams Instruction Form
}
{
CTL_USER definitions
}
{ string: _CS_PATH }
{ int: BC_BASE_MAX }
USER_BC_BASE_MAX = 2;
{ int: BC_DIM_MAX }
USER_BC_DIM_MAX = 3;
{ int: BC_SCALE_MAX }
USER_BC_SCALE_MAX = 4;
{ int: BC_STRING_MAX }
USER_BC_STRING_MAX = 5;
{ int: COLL_WEIGHTS_MAX }
USER_COLL_WEIGHTS_MAX = 6;
{ int: EXPR_NEST_MAX }
USER_EXPR_NEST_MAX = 7;
{ int: LINE_MAX }
USER_LINE_MAX = 8;
{ int: RE_DUP_MAX }
USER_RE_DUP_MAX = 9;
{ int: POSIX2_VERSION }
USER_POSIX2_VERSION = 10;
{ int: POSIX2_C_BIND }
USER_POSIX2_C_BIND = 11;
{ int: POSIX2_C_DEV }
USER_POSIX2_C_DEV = 12;
{ int: POSIX2_CHAR_TERM }
USER_POSIX2_CHAR_TERM = 13;
{ int: POSIX2_FORT_DEV }
USER_POSIX2_FORT_DEV = 14;
{ int: POSIX2_FORT_RUN }
USER_POSIX2_FORT_RUN = 15;
{ int: POSIX2_LOCALEDEF }
USER_POSIX2_LOCALEDEF = 16;
{ int: POSIX2_SW_DEV }
USER_POSIX2_SW_DEV = 17;
{ int: POSIX2_UPE }
USER_POSIX2_UPE = 18;
{ int: POSIX2_STREAM_MAX }
USER_STREAM_MAX = 19;
{ int: POSIX2_TZNAME_MAX }
USER_TZNAME_MAX = 20;
{ number of valid user ids }
USER_MAXID = 21;
{
$Log$
Revision 1.1 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
}

54
rtl/darwin/termio.pp Normal file
View File

@ -0,0 +1,54 @@
{
$Id$
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
Uses BaseUnix; // 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.
{
$Log$
Revision 1.1 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
Revision 1.1 2003/11/19 17:15:31 marco
* termio new includefile
}

465
rtl/darwin/termios.inc Normal file
View File

@ -0,0 +1,465 @@
{
$Id$
}
{$PACKRECORDS C}
{
Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
@APPLE_LICENSE_HEADER_START@
The contents of this file constitute Original Code as defined in and
are subject to the Apple Public Source License Version 1.1 (the
"License"). You may not use this file except in compliance with the
License. Please obtain a copy of the License at
http://www.apple.com/publicsource and read it before using this file.
This Original Code and all software distributed under the License are
distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
License for the specific language governing rights and limitations
under the License.
@APPLE_LICENSE_HEADER_END@
}
{ Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved }
{
Copyright (c) 1988, 1989, 1993, 1994
The Regents of the University of California. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by the University of
California, Berkeley and its contributors.
4. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
@(#)termios.h 8.3 (Berkeley) 3/28/94
}
{$ifndef _SYS_TERMIOS_H_}
{$define _SYS_TERMIOS_H_}
{
Special Control Characters
Index into c_cc[] character array.
Name Subscript Enabled by
}
{ ICANON }
const
VEOF = 0;
{ ICANON }
VEOL = 1;
{$ifndef _POSIX_SOURCE}
{ ICANON together with IEXTEN }
const
VEOL2 = 2;
{$endif}
{ ICANON }
const
VERASE = 3;
{$ifndef _POSIX_SOURCE}
{ ICANON together with IEXTEN }
const
VWERASE = 4;
{$endif}
{ ICANON }
const
VKILL = 5;
{$ifndef _POSIX_SOURCE}
{ ICANON together with IEXTEN }
const
VREPRINT = 6;
{$endif}
{ 7 spare 1 }
{ ISIG }
const
VINTR = 8;
{ ISIG }
VQUIT = 9;
{ ISIG }
VSUSP = 10;
{$ifndef _POSIX_SOURCE}
{ ISIG together with IEXTEN }
const
VDSUSP = 11;
{$endif}
{ IXON, IXOFF }
const
VSTART = 12;
{ IXON, IXOFF }
VSTOP = 13;
{$ifndef _POSIX_SOURCE}
{ IEXTEN }
const
VLNEXT = 14;
{ IEXTEN }
VDISCARD = 15;
{$endif}
{ !ICANON }
const
VMIN = 16;
{ !ICANON }
VTIME = 17;
{$ifndef _POSIX_SOURCE}
{ ICANON together with IEXTEN }
const
VSTATUS = 18;
{ 19 spare 2 }
{$endif}
const
NCCS = 20;
{$ifndef _POSIX_VDISABLE}
const
_POSIX_VDISABLE = $ff;
{$endif}
{$ifndef _POSIX_SOURCE}
{ was #define dname(params) para_def_expr }
{ argument types are unknown }
{ return type might be wrong }
function CCEQ(val,c : longint) : longint;
{$endif}
{
Input flags - software input processing
}
{ ignore BREAK condition }
const
IGNBRK = $00000001;
{ map BREAK to SIGINTR }
BRKINT = $00000002;
{ ignore (discard) parity errors }
IGNPAR = $00000004;
{ mark parity and framing errors }
PARMRK = $00000008;
{ enable checking of parity errors }
INPCK = $00000010;
{ strip 8th bit off chars }
ISTRIP = $00000020;
{ map NL into CR }
INLCR = $00000040;
{ ignore CR }
IGNCR = $00000080;
{ map CR to NL (ala CRMOD) }
ICRNL = $00000100;
{ enable output flow control }
IXON = $00000200;
{ enable input flow control }
IXOFF = $00000400;
{$ifndef _POSIX_SOURCE}
{ any char will restart after stop }
const
IXANY = $00000800;
{ ring bell on input queue full }
IMAXBEL = $00002000;
{$endif}
{_POSIX_SOURCE }
{
Output flags - software output processing
}
{ enable following output processing }
const
OPOST = $00000001;
{$ifndef _POSIX_SOURCE}
{ map NL to CR-NL (ala CRMOD) }
const
ONLCR = $00000002;
{ expand tabs to spaces }
OXTABS = $00000004;
{ discard EOT's (^D) on output) }
ONOEOT = $00000008;
{$endif}
{_POSIX_SOURCE }
{
Control flags - hardware control of terminal
}
{$ifndef _POSIX_SOURCE}
{ ignore control flags }
const
CIGNORE = $00000001;
{$endif}
{ character size mask }
const
CSIZE = $00000300;
{ 5 bits (pseudo) }
CS5 = $00000000;
{ 6 bits }
CS6 = $00000100;
{ 7 bits }
CS7 = $00000200;
{ 8 bits }
CS8 = $00000300;
{ send 2 stop bits }
CSTOPB = $00000400;
{ enable receiver }
CREAD = $00000800;
{ parity enable }
PARENB = $00001000;
{ odd parity, else even }
PARODD = $00002000;
{ hang up on last close }
HUPCL = $00004000;
{ ignore modem status lines }
CLOCAL = $00008000;
{$ifndef _POSIX_SOURCE}
{ CTS flow control of output }
const
CCTS_OFLOW = $00010000;
{ RTS flow control of input }
CRTS_IFLOW = $00020000;
CRTSCTS = CCTS_OFLOW or CRTS_IFLOW;
{ DTR flow control of input }
CDTR_IFLOW = $00040000;
{ DSR flow control of output }
CDSR_OFLOW = $00080000;
{ DCD flow control of output }
CCAR_OFLOW = $00100000;
{ old name for CCAR_OFLOW }
MDMBUF = $00100000;
{$endif}
{
"Local" flags - dumping ground for other state
Warning: some flags in this structure begin with
the letter "I" and look like they belong in the
input flag.
}
{$ifndef _POSIX_SOURCE}
{ visual erase for line kill }
const
ECHOKE = $00000001;
{$endif}
{_POSIX_SOURCE }
{ visually erase chars }
const
ECHOE = $00000002;
{ echo NL after line kill }
ECHOK = $00000004;
{ enable echoing }
ECHO = $00000008;
{ echo NL even if ECHO is off }
ECHONL = $00000010;
{$ifndef _POSIX_SOURCE}
{ visual erase mode for hardcopy }
const
ECHOPRT = $00000020;
{ echo control chars as ^(Char) }
ECHOCTL = $00000040;
{$endif}
{_POSIX_SOURCE }
{ enable signals INTR, QUIT, [D]SUSP }
const
ISIG = $00000080;
{ canonicalize input lines }
ICANON = $00000100;
{$ifndef _POSIX_SOURCE}
{ use alternate WERASE algorithm }
const
ALTWERASE = $00000200;
{$endif}
{_POSIX_SOURCE }
{ enable DISCARD and LNEXT }
const
IEXTEN = $00000400;
{ external processing }
EXTPROC = $00000800;
{ stop background jobs from output }
TOSTOP = $00400000;
{$ifndef _POSIX_SOURCE}
{ output being flushed (state) }
const
FLUSHO = $00800000;
{ no kernel output from VSTATUS }
NOKERNINFO = $02000000;
{ XXX retype pending input (state) }
PENDIN = $20000000;
{$endif}
{_POSIX_SOURCE }
{ don't flush after interrupt }
const
NOFLSH = $80000000;
type
tcflag_t = dword;
cc_t = byte;
speed_t = longint;
{ XXX should be unsigned long }
{ input flags }
{ output flags }
{ control flags }
{ local flags }
{ control chars }
{ input speed }
{ output speed }
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;
c_ispeed : speed_t;
c_ospeed : speed_t;
end;
{
Commands passed to tcsetattr() for setting the termios structure.
}
{ make change immediate }
const
TCSANOW = 0;
{ drain output, then change }
TCSADRAIN = 1;
{ drain output, flush input }
TCSAFLUSH = 2;
{$ifndef _POSIX_SOURCE}
{ flag - don't alter h.w. state }
const
TCSASOFT = $10;
{$endif}
{
Standard speeds
}
const
B0 = 0;
B50 = 50;
B75 = 75;
B110 = 110;
B134 = 134;
B150 = 150;
B200 = 200;
B300 = 300;
B600 = 600;
B1200 = 1200;
B1800 = 1800;
B2400 = 2400;
B4800 = 4800;
B9600 = 9600;
B19200 = 19200;
B38400 = 38400;
{$ifndef _POSIX_SOURCE}
const
B7200 = 7200;
B14400 = 14400;
B28800 = 28800;
B57600 = 57600;
B76800 = 76800;
B115200 = 115200;
B230400 = 230400;
EXTA = 19200;
EXTB = 38400;
{$endif}
{ !_POSIX_SOURCE }
const
TCIFLUSH = 1;
TCOFLUSH = 2;
TCIOFLUSH = 3;
TCOOFF = 1;
TCOON = 2;
TCIOFF = 3;
TCION = 4;
{
* Control Character Defaults
}
CtrlMask = $1f; {\037}
CEOF =chr( ORD('d') and CtrlMask);
CEOL =chr( $ff and CtrlMask);{ XXX avoid _POSIX_VDISABLE }
CERASE =chr( $7F and CtrlMask);
CINTR =chr(ORD('c') and CtrlMask);
CSTATUS =chr(ORD('t') and CtrlMask);
CKILL =chr(ORD('u') and CtrlMask);
CMIN =chr(1);
CQUIT =chr(034 and CtrlMask); { FS, ^\ }
CSUSP =chr(ORD('z') and CtrlMask);
CTIME =chr(0);
CDSUSP =chr(ORD('y') and CtrlMask);
CSTART =chr(ORD('q') and CtrlMask);
CSTOP =chr(ORD('s') and CtrlMask);
CLNEXT =chr(ORD('v') and CtrlMask);
CDISCARD =chr(ORD('o') and CtrlMask);
CWERASE =chr(ORD('w') and CtrlMask);
CREPRINT =chr(ORD('r') and CtrlMask);
CEOT =CEOF;
{ compat }
CBRK =CEOL;
CRPRNT =CREPRINT;
CFLUSH =CDISCARD;
{
* TTYDEFCHARS to include an array of default control characters.
}
ttydefchars : array[0..NCCS-1] OF char =(
CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT,
chr(_POSIX_VDISABLE), CINTR, CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT,
CDISCARD, CMIN, CTIME, CSTATUS, chr(_POSIX_VDISABLE));
{
$Log$
Revision 1.1 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
}

View File

@ -0,0 +1,97 @@
{
$Id$
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 implementation of several termio(s) functions
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
******************************************************************************}
Function TCGetAttr(fd:cint;var tios:TermIOS):cint; cdecl; external 'c' name 'tcgetattr';
Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint; cdecl; external 'c' name 'tcsetattr';
Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal); cdecl; external 'c' name 'cfsetispeed';
Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal); cdecl; external 'c' name 'cfsetospeed';
Procedure CFMakeRaw(var tios:TermIOS); cdecl; external 'c' name 'cfmakeraw';
Function TCSendBreak(fd,duration:cint):cint;
begin
TCSendBreak:=fpIOCtl(fd,TIOCSBRK,nil);
end;
Function TCSetPGrp(fd,id:cint):cint;
begin
TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(id));
end;
Function TCGetPGrp(fd:cint;var id:cint):cint;
begin
TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
end;
Function TCDrain(fd:cint):cint;
begin
TCDrain:=fpIOCtl(fd,TIOCDRAIN,nil); {Should set timeout to 1 first?}
end;
Function TCFlow(fd,act:cint):cint;
begin
case act OF
TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,nil);
TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,nil);
TCIOFF : {N/I}
end;
end;
Function TCFlush(fd,qsel:cint):cint;
begin
TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(qsel));
end;
Function IsATTY (Handle:cint):cint;
{
Check if the filehandle described by 'handle' is a TTY (Terminal)
}
var
t : Termios;
begin
IsAtty:=TCGetAttr(Handle,t);
end;
Function IsATTY(var f: text):cint;
{
Idem as previous, only now for text variables.
}
begin
IsATTY:=IsaTTY(textrec(f).handle);
end;
{
$Log$
Revision 1.1 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
Revision 1.2 2003/12/16 19:43:53 marco
* nil <-> 0 changes
Revision 1.1 2003/11/19 17:15:31 marco
* termio new includefile
}

646
rtl/darwin/tthread.inc Normal file
View File

@ -0,0 +1,646 @@
{
$Id$
This file is part of the Free Component Library (FCL)
Copyright (c) 1999-2000 by Peter Vreman
Darwin TThread implementation
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.
**********************************************************************}
{$IFDEF VER1_0} // leaving the old implementation in for now...
type
PThreadRec=^TThreadRec;
TThreadRec=record
thread : TThread;
next : PThreadRec;
end;
var
ThreadRoot : PThreadRec;
ThreadsInited : boolean;
// MainThreadID: longint;
Const
ThreadCount: longint = 0;
function ThreadSelf:TThread;
var
hp : PThreadRec;
sp : Pointer;
begin
sp:=SPtr;
hp:=ThreadRoot;
while assigned(hp) do
begin
if (sp<=hp^.Thread.FStackPointer) and
(sp>(hp^.Thread.FStackPointer-hp^.Thread.FStackSize)) then
begin
Result:=hp^.Thread;
exit;
end;
hp:=hp^.next;
end;
Result:=nil;
end;
//function SIGCHLDHandler(Sig: longint): longint; cdecl;//this is std linux C declaration as function
procedure SIGCHLDHandler(Sig: longint); cdecl;
begin
fpwaitpid(-1, nil, WNOHANG);
end;
procedure InitThreads;
var
Act, OldAct: Baseunix.PSigActionRec;
begin
ThreadRoot:=nil;
ThreadsInited:=true;
// This will install SIGCHLD signal handler
// signal() installs "one-shot" handler,
// so it is better to install and set up handler with sigaction()
GetMem(Act, SizeOf(SigActionRec));
GetMem(OldAct, SizeOf(SigActionRec));
Act^.sa_handler := TSigAction(@SIGCHLDHandler);
Act^.sa_flags := SA_NOCLDSTOP {or SA_NOMASK or SA_RESTART};
Fillchar(Act^.sa_mask,sizeof(Act^.sa_mask),0); //Do not block all signals ??. Don't need if SA_NOMASK in flags
FpSigAction(SIGCHLD, Act, OldAct);
FreeMem(Act, SizeOf(SigActionRec));
FreeMem(OldAct, SizeOf(SigActionRec));
end;
procedure DoneThreads;
var
hp : PThreadRec;
begin
while assigned(ThreadRoot) do
begin
ThreadRoot^.Thread.Destroy;
hp:=ThreadRoot;
ThreadRoot:=ThreadRoot^.Next;
dispose(hp);
end;
ThreadsInited:=false;
end;
procedure AddThread(t:TThread);
var
hp : PThreadRec;
begin
{ Need to initialize threads ? }
if not ThreadsInited then
InitThreads;
{ Put thread in the linked list }
new(hp);
hp^.Thread:=t;
hp^.next:=ThreadRoot;
ThreadRoot:=hp;
inc(ThreadCount, 1);
end;
procedure RemoveThread(t:TThread);
var
lasthp,hp : PThreadRec;
begin
hp:=ThreadRoot;
lasthp:=nil;
while assigned(hp) do
begin
if hp^.Thread=t then
begin
if assigned(lasthp) then
lasthp^.next:=hp^.next
else
ThreadRoot:=hp^.next;
dispose(hp);
exit;
end;
lasthp:=hp;
hp:=hp^.next;
end;
Dec(ThreadCount, 1);
if ThreadCount = 0 then DoneThreads;
end;
{ TThread }
function ThreadProc(args:pointer): Integer;cdecl;
var
FreeThread: Boolean;
Thread : TThread absolute args;
begin
while Thread.FHandle = 0 do fpsleep(1);
if Thread.FSuspended then Thread.suspend();
try
Thread.Execute;
except
Thread.FFatalException := TObject(AcquireExceptionObject);
end;
FreeThread := Thread.FFreeOnTerminate;
Result := Thread.FReturnValue;
Thread.FFinished := True;
Thread.DoTerminate;
if FreeThread then
Thread.Free;
fpexit(Result);
end;
constructor TThread.Create(CreateSuspended: Boolean);
var
Flags: Integer;
begin
inherited Create;
AddThread(self);
FSuspended := CreateSuspended;
Flags := CLONE_VM + CLONE_FS + CLONE_FILES + CLONE_SIGHAND + SIGCHLD;
{ Setup 16k of stack }
FStackSize:=16384;
Getmem(FStackPointer,FStackSize);
inc(FStackPointer,FStackSize);
FCallExitProcess:=false;
{ Clone }
FHandle:= Clone(@ThreadProc,FStackPointer,Flags,self);
// if FSuspended then Suspend;
FThreadID := FHandle;
IsMultiThread := TRUE;
FFatalException := nil;
end;
destructor TThread.Destroy;
begin
if not FFinished and not Suspended then
begin
Terminate;
WaitFor;
end;
if FHandle <> -1 then
fpkill(FHandle, SIGKILL);
dec(FStackPointer,FStackSize);
Freemem(FStackPointer);
FFatalException.Free;
FFatalException := nil;
inherited Destroy;
RemoveThread(self);
end;
procedure TThread.CallOnTerminate;
begin
FOnTerminate(Self);
end;
procedure TThread.DoTerminate;
begin
if Assigned(FOnTerminate) then
Synchronize(@CallOnTerminate);
end;
const
{ I Don't know idle or timecritical, value is also 20, so the largest other
possibility is 19 (PFV) }
Priorities: array [TThreadPriority] of Integer =
(-20,-19,-10,9,10,19,20);
function TThread.GetPriority: TThreadPriority;
var
P: Integer;
I: TThreadPriority;
begin
P := fpGetPriority(Prio_Process,FHandle);
Result := tpNormal;
for I := Low(TThreadPriority) to High(TThreadPriority) do
if Priorities[I] = P then
Result := I;
end;
procedure TThread.SetPriority(Value: TThreadPriority);
begin
fpSetPriority(Prio_Process,FHandle,Priorities[Value]);
end;
procedure TThread.Synchronize(Method: TThreadMethod);
begin
FSynchronizeException := nil;
FMethod := Method;
{ SendMessage(ThreadWindow, CM_EXECPROC, 0, Longint(Self)); }
if Assigned(FSynchronizeException) then
raise FSynchronizeException;
end;
procedure TThread.SetSuspended(Value: Boolean);
begin
if Value <> FSuspended then
if Value then
Suspend
else
Resume;
end;
procedure TThread.Suspend;
begin
FSuspended := true;
fpKill(FHandle, SIGSTOP);
end;
procedure TThread.Resume;
begin
fpKill(FHandle, SIGCONT);
FSuspended := False;
end;
procedure TThread.Terminate;
begin
FTerminated := True;
end;
function TThread.WaitFor: Integer;
var
status : longint;
begin
if FThreadID = MainThreadID then
fpwaitpid(0,@status,0)
else
fpwaitpid(FHandle,@status,0);
Result:=status;
end;
{$ELSE}
{
What follows, is a short description on my implementation of TThread.
Most information can also be found by reading the source and accompanying
comments.
A thread is created using BeginThread, which in turn calls
pthread_create. So the threads here are always posix threads.
Posix doesn't define anything for suspending threads as this is
inherintly unsafe. Just don't suspend threads at points they cannot
control. Therefore, I didn't implement .Suspend() if its called from
outside the threads execution flow (except on Linux _without_ NPTL).
The implementation for .suspend uses a semaphore, which is initialized
at thread creation. If the thread tries to suspend itself, we simply
let it wait on the semaphore until it is unblocked by someone else
who calls .Resume.
If a thread is supposed to be suspended (from outside its own path of
execution) on a system where the symbol LINUX is defined, two things
are possible.
1) the system has the LinuxThreads pthread implementation
2) the system has NPTL as the pthread implementation.
In the first case, each thread is a process on its own, which as far as
know actually violates posix with respect to signal handling.
But we can detect this case, because getpid(2) will
return a different PID for each thread. In that case, sending SIGSTOP
to the PID associated with a thread will actually stop that thread
only.
In the second case, this is not possible. But getpid(2) returns the same
PID across all threads, which is detected, and TThread.Suspend() does
nothing in that case. This should probably be changed, but I know of
no way to suspend a thread when using NPTL.
If the symbol LINUX is not defined, then the unimplemented
function SuspendThread is called.
Johannes Berg <johannes@sipsolutions.de>, Sunday, November 16 2003
}
// ========== semaphore stuff ==========
{
I don't like this. It eats up 2 filedescriptors for each thread,
and those are a limited resource. If you have a server programm
handling client connections (one per thread) it will not be able
to handle many if we use 2 fds already for internal structures.
However, right now I don't see a better option unless some sem_*
functions are added to systhrds.
I encapsulated all used functions here to make it easier to
change them completely.
}
function SemaphoreInit: Pointer;
begin
SemaphoreInit := GetMem(SizeOf(TFilDes));
fppipe(PFilDes(SemaphoreInit)^);
end;
procedure SemaphoreWait(const FSem: Pointer);
var
b: byte;
begin
fpread(PFilDes(FSem)^[0], b, 1);
end;
procedure SemaphorePost(const FSem: Pointer);
begin
fpwrite(PFilDes(FSem)^[1], #0, 1);
end;
procedure SemaphoreDestroy(const FSem: Pointer);
begin
fpclose(PFilDes(FSem)^[0]);
fpclose(PFilDes(FSem)^[1]);
FreeMemory(FSem);
end;
// =========== semaphore end ===========
var
ThreadsInited: boolean = false;
{$IFDEF LINUX}
GMainPID: LongInt = 0;
{$ENDIF}
const
// stupid, considering its not even implemented...
Priorities: array [TThreadPriority] of Integer =
(-20,-19,-10,0,9,18,19);
procedure InitThreads;
begin
if not ThreadsInited then begin
ThreadsInited := true;
{$IFDEF LINUX}
GMainPid := fpgetpid();
{$ENDIF}
end;
end;
procedure DoneThreads;
begin
ThreadsInited := false;
end;
{ ok, so this is a hack, but it works nicely. Just never use
a multiline argument with WRITE_DEBUG! }
{$MACRO ON}
{$IFDEF DEBUG_MT}
{$define WRITE_DEBUG := writeln} // actually write something
{$ELSE}
{$define WRITE_DEBUG := //} // just comment out those lines
{$ENDIF}
function ThreadFunc(parameter: Pointer): LongInt; cdecl;
var
LThread: TThread;
c: char;
begin
WRITE_DEBUG('ThreadFunc is here...');
LThread := TThread(parameter);
{$IFDEF LINUX}
// save the PID of the "thread"
// this is different from the PID of the main thread if
// the LinuxThreads implementation is used
LThread.FPid := fpgetpid();
{$ENDIF}
WRITE_DEBUG('thread initing, parameter = ', LongInt(LThread));
try
if LThread.FInitialSuspended then begin
SemaphoreWait(LThread.FSem);
if not LThread.FInitialSuspended then begin
WRITE_DEBUG('going into LThread.Execute');
LThread.Execute;
end;
end else begin
WRITE_DEBUG('going into LThread.Execute');
LThread.Execute;
end;
except
on e: exception do begin
WRITE_DEBUG('got exception: ',e.message);
LThread.FFatalException := TObject(AcquireExceptionObject);
// not sure if we should really do this...
// but .Destroy was called, so why not try FreeOnTerminate?
if e is EThreadDestroyCalled then LThread.FFreeOnTerminate := true;
end;
end;
WRITE_DEBUG('thread done running');
Result := LThread.FReturnValue;
WRITE_DEBUG('Result is ',Result);
LThread.FFinished := True;
LThread.DoTerminate;
if LThread.FreeOnTerminate then begin
WRITE_DEBUG('Thread should be freed');
LThread.Free;
WRITE_DEBUG('Thread freed');
end;
WRITE_DEBUG('thread func exiting');
end;
{ TThread }
constructor TThread.Create(CreateSuspended: Boolean);
begin
// lets just hope that the user doesn't create a thread
// via BeginThread and creates the first TThread Object in there!
InitThreads;
inherited Create;
FSem := SemaphoreInit;
FSuspended := CreateSuspended;
FSuspendedExternal := false;
FInitialSuspended := CreateSuspended;
FFatalException := nil;
WRITE_DEBUG('creating thread, self = ',longint(self));
FHandle:= BeginThread(@ThreadFunc, Pointer(Self), FThreadID);
WRITE_DEBUG('TThread.Create done');
end;
destructor TThread.Destroy;
begin
if FThreadID = GetCurrentThreadID then begin
raise EThreadDestroyCalled.Create('A thread cannot destroy itself except by setting FreeOnTerminate and leaving!');
end;
// if someone calls .Free on a thread with
// FreeOnTerminate, then don't crash!
FFreeOnTerminate := false;
if not FFinished and not FSuspended then begin
Terminate;
WaitFor;
end;
if (FInitialSuspended) then begin
// thread was created suspended but never woken up.
SemaphorePost(FSem);
WaitFor;
end;
FFatalException.Free;
FFatalException := nil;
SemaphoreDestroy(FSem);
inherited Destroy;
end;
procedure TThread.SetSuspended(Value: Boolean);
begin
if Value <> FSuspended then
if Value then
Suspend
else
Resume;
end;
procedure TThread.Suspend;
begin
if not FSuspended then begin
if FThreadID = GetCurrentThreadID then begin
FSuspended := true;
SemaphoreWait(FSem);
end else begin
FSuspendedExternal := true;
{$IFDEF LINUX}
// naughty hack if the user doesn't have Linux with NPTL...
// in that case, the PID of threads will not be identical
// to the other threads, which means that our thread is a normal
// process that we can suspend via SIGSTOP...
// this violates POSIX, but is the way it works on the
// LinuxThreads pthread implementation. Not with NPTL, but in that case
// getpid(2) also behaves properly and returns the same PID for
// all threads. Thats actually (FINALLY!) native thread support :-)
if FPid <> GMainPID then begin
FSuspended := true;
fpkill(FPid, SIGSTOP);
end;
{$ELSE}
SuspendThread(FHandle);
{$ENDIF}
end;
end;
end;
procedure TThread.Resume;
begin
if (not FSuspendedExternal) then begin
if FSuspended then begin
SemaphorePost(FSem);
FInitialSuspended := false;
FSuspended := False;
end;
end else begin
{$IFDEF LINUX}
// see .Suspend
if FPid <> GMainPID then begin
fpkill(FPid, SIGCONT);
FSuspended := False;
end;
{$ELSE}
ResumeThread(FHandle);
{$ENDIF}
FSuspendedExternal := false;
end;
end;
procedure TThread.Terminate;
begin
FTerminated := True;
end;
function TThread.WaitFor: Integer;
begin
WRITE_DEBUG('waiting for thread ',FHandle);
WaitFor := WaitForThreadTerminate(FHandle, 0);
WRITE_DEBUG('thread terminated');
end;
procedure TThread.CallOnTerminate;
begin
// no need to check if FOnTerminate <> nil, because
// thats already done in DoTerminate
FOnTerminate(self);
end;
procedure TThread.DoTerminate;
begin
if Assigned(FOnTerminate) then
Synchronize(@CallOnTerminate);
end;
function TThread.GetPriority: TThreadPriority;
var
P: Integer;
I: TThreadPriority;
begin
P := ThreadGetPriority(FHandle);
Result := tpNormal;
for I := Low(TThreadPriority) to High(TThreadPriority) do
if Priorities[I] = P then
Result := I;
end;
procedure TThread.Synchronize(Method: TThreadMethod);
begin
{$TODO someone with more clue of the GUI stuff will have to do this}
end;
procedure TThread.SetPriority(Value: TThreadPriority);
begin
ThreadSetPriority(FHandle, Priorities[Value]);
end;
{$ENDIF}
{
$Log$
Revision 1.1 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
Revision 1.7 2003/11/22 11:04:08 marco
* Johill: suspend fix
Revision 1.6 2003/11/19 10:12:02 marco
* more cleanups
Revision 1.5 2003/11/17 10:05:51 marco
* threads for FreeBSD. Not working tho
Revision 1.4 2003/11/17 08:27:49 marco
* pthreads based ttread from Johannes Berg
Revision 1.3 2003/11/10 16:54:28 marco
* new oldlinux unit. 1_0 defines killed in some former FCL parts.
Revision 1.2 2003/11/03 09:42:28 marco
* Peter's Cardinal<->Longint fixes patch
Revision 1.1 2003/10/06 21:01:06 peter
* moved classes unit to rtl
Revision 1.9 2003/10/06 17:06:55 florian
* applied Johannes Berg's patch for exception handling in threads
Revision 1.8 2003/09/20 15:10:30 marco
* small fixes. fcl now compiles
Revision 1.7 2002/12/18 20:44:36 peter
* use fillchar to clear sigset
Revision 1.6 2002/09/07 15:15:27 peter
* old logs removed and tabs fixed
}

73
rtl/darwin/unixsysc.inc Normal file
View File

@ -0,0 +1,73 @@
{
$Id$
This file is part of the Free Component Library (FCL)
Copyright (c) 1999-2000 by Peter Vreman
Darwin temporary pclose/assignpipe implementation
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
fpclose(filerec(F).Handle);
{ closed our side, Now wait for the other - this appears to be needed ?? }
pl:=@(filerec(f).userdata[2]);
fpwaitpid(pl^,@res,0);
pclose:=res shr 8;
end;
Function PClose(Var F:text) :cint;
var
pl : ^longint;
res : longint;
begin
fpclose(Textrec(F).Handle);
{ closed our side, Now wait for the other - this appears to be needed ?? }
pl:=@(textrec(f).userdata[2]);
fpwaitpid(pl^,@res,0);
pclose:=res shr 8;
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;
errn : cint;
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;
{
$Log$
Revision 1.1 2004-01-04 20:05:38 jonas
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
Several non-essential units are still missing, but make cycle works
}