mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 20:49:49 +02:00
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
This commit is contained in:
parent
a5dd1abd5f
commit
e5c42e6704
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Makefile generated by fpcmake v1.00 [2000/09/01]
|
||||
# Makefile generated by fpcmake v0.99.13 [2000/01/17]
|
||||
#
|
||||
|
||||
defaultrule: all
|
||||
@ -84,14 +84,12 @@ ifdef PP
|
||||
FPC=$(PP)
|
||||
else
|
||||
ifdef inOS2
|
||||
FPC=ppos2
|
||||
FPC=ppos2$(EXEEXT)
|
||||
else
|
||||
FPC=ppc386
|
||||
FPC=ppc386$(EXEEXT)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
override FPC:=$(subst $(EXEEXT),,$(FPC))
|
||||
override FPC:=$(subst \,/,$(FPC))$(EXEEXT)
|
||||
|
||||
# Target OS
|
||||
ifndef OS_TARGET
|
||||
@ -127,6 +125,7 @@ export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION
|
||||
RTL=..
|
||||
INC=$(RTL)/inc
|
||||
PROCINC=$(RTL)/$(CPU_TARGET)
|
||||
UNIXINC=$(RTL)/unix
|
||||
|
||||
UNITPREFIX=rtl
|
||||
|
||||
@ -153,10 +152,8 @@ endif
|
||||
ifdef FPCDIR
|
||||
override FPCDIR:=$(subst \,/,$(FPCDIR))
|
||||
ifeq ($(wildcard $(FPCDIR)/rtl),)
|
||||
ifeq ($(wildcard $(FPCDIR)/units),)
|
||||
override FPCDIR=wrong
|
||||
endif
|
||||
endif
|
||||
else
|
||||
override FPCDIR=wrong
|
||||
endif
|
||||
@ -165,32 +162,16 @@ endif
|
||||
ifeq ($(FPCDIR),wrong)
|
||||
override FPCDIR=.
|
||||
ifeq ($(wildcard $(FPCDIR)/rtl),)
|
||||
ifeq ($(wildcard $(FPCDIR)/units),)
|
||||
override FPCDIR=wrong
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
# Detect FPCDIR
|
||||
ifeq ($(FPCDIR),wrong)
|
||||
ifdef inlinux
|
||||
override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
|
||||
ifeq ($(wildcard $(FPCDIR)/units),)
|
||||
override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
|
||||
endif
|
||||
else
|
||||
override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
|
||||
override FPCDIR:=$(FPCDIR)/..
|
||||
ifeq ($(wildcard $(FPCDIR)/rtl),)
|
||||
ifeq ($(wildcard $(FPCDIR)/units),)
|
||||
override FPCDIR:=$(FPCDIR)/..
|
||||
ifeq ($(wildcard $(FPCDIR)/rtl),)
|
||||
ifeq ($(wildcard $(FPCDIR)/units),)
|
||||
override FPCDIR=c:/pp
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
override FPCDIR:=$(subst /$(FPC)$(EXEEXT),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC)$(EXEEXT),$(SEARCHPATH))))))
|
||||
endif
|
||||
endif
|
||||
|
||||
@ -218,7 +199,7 @@ ZIPTARGET=install
|
||||
|
||||
# Directories
|
||||
|
||||
override NEEDINCDIR=$(INC) $(PROCINC)
|
||||
override NEEDINCDIR=$(INC) $(PROCINC) $(UNIXINC)
|
||||
ifndef TARGETDIR
|
||||
TARGETDIR=.
|
||||
endif
|
||||
@ -229,8 +210,7 @@ endif
|
||||
# Libraries
|
||||
|
||||
LIBNAME=libfprtl.so
|
||||
LIBVERSION=1.0
|
||||
SHAREDLIBUNITOBJECTS=$(SYSTEMUNIT) objpas strings linux ports dos crt objects printer sysutils typinfo math cpu mmx getopts heaptrc errors sockets ipc dl dynlibs varutils
|
||||
SHAREDLIBOBJECTUNITS=$(SYSTEMUNIT) objpas strings linux ports dos crt objects printer sysutils typinfo math cpu mmx getopts heaptrc errors sockets ipc dl dynlibs varutils
|
||||
|
||||
# Info
|
||||
|
||||
@ -358,6 +338,13 @@ PPAS=ppas.bat
|
||||
endif
|
||||
endif
|
||||
|
||||
# also call ppas if with command option -s
|
||||
ifeq (,$(findstring -s ,$(COMPILER)))
|
||||
EXECPPAS=
|
||||
else
|
||||
EXECPPAS:=@$(PPAS)
|
||||
endif
|
||||
|
||||
# ldconfig to rebuild .so cache
|
||||
ifdef inlinux
|
||||
LDCONFIG=ldconfig
|
||||
@ -415,7 +402,7 @@ ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(EXEEXT),$(SEARCHPATH))))
|
||||
ifeq ($(ZIPPROG),)
|
||||
ZIPPROG=
|
||||
else
|
||||
ZIPPROG:=$(firstword $(ZIPPROG))
|
||||
ZIPPROG:=$(firstword $(ZIPPROG)) -D9 -r
|
||||
endif
|
||||
endif
|
||||
export ZIPPROG
|
||||
@ -606,19 +593,6 @@ DOCINSTALLDIR=$(BASEINSTALLDIR)/doc
|
||||
endif
|
||||
endif
|
||||
|
||||
# Where to install the examples, under linux we use the doc dir
|
||||
# because the copytree command will create a subdir itself
|
||||
ifndef EXAMPLEINSTALLDIR
|
||||
ifdef inlinux
|
||||
EXAMPLEINSTALLDIR=$(DOCINSTALLDIR)/examples
|
||||
else
|
||||
EXAMPLEINSTALLDIR=$(BASEINSTALLDIR)/examples
|
||||
endif
|
||||
ifdef EXAMPLESUBDIR
|
||||
EXAMPLEINSTALLDIR:=$(EXAMPLEINSTALLDIR)/$(EXAMPLESUBDIR)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Where the some extra (data)files will be stored
|
||||
ifndef DATAINSTALLDIR
|
||||
DATAINSTALLDIR=$(BASEINSTALLDIR)
|
||||
@ -628,6 +602,7 @@ endif
|
||||
# Redirection
|
||||
#####################################################################
|
||||
|
||||
# Release ? Then force OPT and don't use extra opts via commandline
|
||||
ifndef REDIRFILE
|
||||
REDIRFILE=log
|
||||
endif
|
||||
@ -654,7 +629,44 @@ ifneq ($(OS_TARGET),$(OS_SOURCE))
|
||||
override FPCOPT+=-T$(OS_TARGET)
|
||||
endif
|
||||
|
||||
# User dirs should be first, so they are looked at first
|
||||
ifdef UNITSDIR
|
||||
override FPCOPT+=-Fu$(UNITSDIR)
|
||||
endif
|
||||
|
||||
ifdef NEEDINCDIR
|
||||
override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
|
||||
endif
|
||||
|
||||
|
||||
# Target dirs
|
||||
ifdef TARGETDIR
|
||||
override FPCOPT+=-FE$(TARGETDIR)
|
||||
endif
|
||||
|
||||
# Smartlinking
|
||||
ifdef SMARTLINK
|
||||
override FPCOPT+=-CX
|
||||
endif
|
||||
|
||||
# Debug
|
||||
ifdef DEBUG
|
||||
override FPCOPT+=-g -dDEBUG
|
||||
endif
|
||||
|
||||
# Release mode (strip, optimize and don't load ppc386.cfg)
|
||||
ifdef RELEASE
|
||||
override FPCOPT+=-Xs -OG2p3 -n
|
||||
endif
|
||||
|
||||
# Verbose settings (warning,note,info)
|
||||
ifdef VERBOSE
|
||||
override FPCOPT+=-vwni
|
||||
endif
|
||||
|
||||
# Add commandline options
|
||||
ifdef OPT
|
||||
override FPCOPT+=$(OPT)
|
||||
endif
|
||||
ifdef UNITDIR
|
||||
override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
|
||||
endif
|
||||
@ -668,83 +680,6 @@ ifdef INCDIR
|
||||
override FPCOPT+=$(addprefix -Fi,$(INCDIR))
|
||||
endif
|
||||
|
||||
# Smartlinking
|
||||
ifdef LINKSMART
|
||||
override FPCOPT+=-XX
|
||||
endif
|
||||
|
||||
# Smartlinking creation
|
||||
ifdef CREATESMART
|
||||
override FPCOPT+=-CX
|
||||
endif
|
||||
|
||||
# Debug
|
||||
ifdef DEBUG
|
||||
override FPCOPT+=-g -dDEBUG
|
||||
endif
|
||||
|
||||
# Release mode (strip, optimize and don't load ppc386.cfg)
|
||||
# 0.99.12b has a bug in the optimizer so don't use it by default
|
||||
ifdef RELEASE
|
||||
ifeq ($(FPC_VERSION),0.99.12)
|
||||
override FPCOPT+=-Xs -OGp3 -n
|
||||
else
|
||||
override FPCOPT+=-Xs -OG2p3 -n
|
||||
endif
|
||||
endif
|
||||
|
||||
# Strip
|
||||
ifdef STRIP
|
||||
override FPCOPT+=-Xs
|
||||
endif
|
||||
|
||||
# Optimizer
|
||||
ifdef OPTIMIZE
|
||||
override FPCOPT+=-OG2p3
|
||||
endif
|
||||
|
||||
# Verbose settings (warning,note,info)
|
||||
ifdef VERBOSE
|
||||
override FPCOPT+=-vwni
|
||||
endif
|
||||
|
||||
ifdef UNITSDIR
|
||||
override FPCOPT+=-Fu$(UNITSDIR)
|
||||
endif
|
||||
|
||||
ifdef NEEDINCDIR
|
||||
override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
|
||||
endif
|
||||
|
||||
|
||||
# Target dirs and the prefix to use for clean/install
|
||||
ifdef TARGETDIR
|
||||
override FPCOPT+=-FE$(TARGETDIR)
|
||||
ifeq ($(TARGETDIR),.)
|
||||
override TARGETDIRPREFIX=
|
||||
else
|
||||
override TARGETDIRPREFIX=$(TARGETDIR)/
|
||||
endif
|
||||
endif
|
||||
ifdef UNITTARGETDIR
|
||||
override FPCOPT+=-FU$(UNITTARGETDIR)
|
||||
ifeq ($(UNITTARGETDIR),.)
|
||||
override UNITTARGETDIRPREFIX=
|
||||
else
|
||||
override UNITTARGETDIRPREFIX=$(TARGETDIR)/
|
||||
endif
|
||||
else
|
||||
ifdef TARGETDIR
|
||||
override UNITTARGETDIR=$(TARGETDIR)
|
||||
override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Add commandline options last so they can override
|
||||
ifdef OPT
|
||||
override FPCOPT+=$(OPT)
|
||||
endif
|
||||
|
||||
# Add defines from FPCOPTDEF to FPCOPT
|
||||
ifdef FPCOPTDEF
|
||||
override FPCOPT+=$(FPCOPTDEF)
|
||||
@ -764,22 +699,11 @@ endif
|
||||
ifeq ($(OS_SOURCE),win32)
|
||||
override FPCEXTCMD:=$(FPCOPT)
|
||||
override FPCOPT:=!FPCEXTCMD
|
||||
export FPCEXTCMD
|
||||
endif
|
||||
|
||||
# Compiler commandline
|
||||
override COMPILER:=$(FPC) $(FPCOPT)
|
||||
|
||||
# also call ppas if with command option -s
|
||||
# but only if the OS_SOURCE and OS_TARGE are equal
|
||||
ifeq (,$(findstring -s ,$(COMPILER)))
|
||||
EXECPPAS=
|
||||
else
|
||||
ifeq ($(OS_SOURCE),$(OS_TARGET))
|
||||
EXECPPAS:=@$(PPAS)
|
||||
endif
|
||||
endif
|
||||
|
||||
#####################################################################
|
||||
# Standard rules
|
||||
#####################################################################
|
||||
@ -798,23 +722,17 @@ install: fpc_install
|
||||
|
||||
sourceinstall: fpc_sourceinstall
|
||||
|
||||
exampleinstall: fpc_exampleinstall
|
||||
|
||||
zipinstall: fpc_zipinstall
|
||||
|
||||
zipsourceinstall: fpc_zipsourceinstall
|
||||
|
||||
zipexampleinstall: fpc_zipexampleinstall
|
||||
|
||||
clean: fpc_clean
|
||||
|
||||
distclean: fpc_distclean
|
||||
|
||||
cleanall: fpc_cleanall
|
||||
|
||||
info: fpc_info
|
||||
|
||||
.PHONY: all debug smart shared showinstall install sourceinstall exampleinstall zipinstall zipsourceinstall zipexampleinstall clean distclean cleanall info
|
||||
.PHONY: all debug smart shared showinstall install sourceinstall zipinstall zipsourceinstall clean cleanall info
|
||||
|
||||
#####################################################################
|
||||
# Loaders
|
||||
@ -862,11 +780,9 @@ fpc_units: $(UNITPPUFILES)
|
||||
# Resource strings
|
||||
#####################################################################
|
||||
|
||||
ifdef RSTOBJECTS
|
||||
override RSTFILES=$(addsuffix $(RSTEXT),$(RSTOBJECTS))
|
||||
|
||||
override CLEANRSTFILES+=$(RSTFILES)
|
||||
endif
|
||||
|
||||
#####################################################################
|
||||
# General compile rules
|
||||
@ -884,30 +800,25 @@ fpc_all: fpc_packages $(FPCMADE)
|
||||
fpc_debug:
|
||||
$(MAKE) all DEBUG=1
|
||||
|
||||
# Search paths for .ppu if targetdir is set
|
||||
ifdef UNITTARGETDIR
|
||||
vpath %$(PPUEXT) $(UNITTARGETDIR)
|
||||
endif
|
||||
|
||||
# General compile rules, available for both possible PASEXT
|
||||
|
||||
.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
|
||||
|
||||
%$(PPUEXT): %.pp
|
||||
$(COMPILER) $< $(REDIR)
|
||||
$(EXECPPAS)
|
||||
$(EXECPASS)
|
||||
|
||||
%$(PPUEXT): %.pas
|
||||
$(COMPILER) $< $(REDIR)
|
||||
$(EXECPPAS)
|
||||
$(EXECPASS)
|
||||
|
||||
%$(EXEEXT): %.pp
|
||||
$(COMPILER) $< $(REDIR)
|
||||
$(EXECPPAS)
|
||||
$(EXECPASS)
|
||||
|
||||
%$(EXEEXT): %.pas
|
||||
$(COMPILER) $< $(REDIR)
|
||||
$(EXECPPAS)
|
||||
$(EXECPASS)
|
||||
|
||||
#####################################################################
|
||||
# Library
|
||||
@ -915,26 +826,20 @@ endif
|
||||
|
||||
.PHONY: fpc_smart fpc_shared
|
||||
|
||||
ifdef LIBVERSION
|
||||
LIBFULLNAME=$(LIBNAME).$(LIBVERSION)
|
||||
else
|
||||
LIBFULLNAME=$(LIBNAME)
|
||||
endif
|
||||
|
||||
# Default sharedlib units are all unit objects
|
||||
ifndef SHAREDLIBUNITOBJECTS
|
||||
SHAREDLIBUNITOBJECTS:=$(UNITOBJECTS)
|
||||
endif
|
||||
|
||||
fpc_smart:
|
||||
$(MAKE) all LINKSMART=1 CREATESMART=1
|
||||
$(MAKE) all SMARTLINK=1
|
||||
|
||||
fpc_shared: all
|
||||
ifdef inlinux
|
||||
ifndef LIBNAME
|
||||
@$(ECHO) "LIBNAME not set"
|
||||
else
|
||||
$(PPUMOVE) $(SHAREDLIBUNITOBJECTS) -o$(LIBFULLNAME)
|
||||
$(PPUMOVE) $(SHAREDLIBUNITOBJECTS) -o$(LIBNAME)
|
||||
endif
|
||||
else
|
||||
@$(ECHO) "Shared Libraries not supported"
|
||||
@ -951,17 +856,16 @@ override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(EXTRAINSTALLUNITS))
|
||||
endif
|
||||
|
||||
ifdef INSTALLPPUFILES
|
||||
override INSTALLPPUFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLPPUFILES))
|
||||
ifdef PPUFILES
|
||||
ifdef inlinux
|
||||
INSTALLPPULINKFILES:=$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES))
|
||||
INSTALLPPULIBFILES:=$(shell $(PPUFILES) -L $(INSTALLPPUFILES))
|
||||
else
|
||||
INSTALLPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES))))
|
||||
INSTALLPPULINKFILES:=$(shell $(PPUFILES) $(INSTALLPPUFILES))
|
||||
endif
|
||||
override INSTALLPPULINKFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLPPULINKFILES))
|
||||
else
|
||||
INSTALLPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)))
|
||||
endif
|
||||
|
||||
ifdef INSTALLEXEFILES
|
||||
override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEFILES))
|
||||
endif
|
||||
|
||||
fpc_showinstall: $(SHOWINSTALLTARGET)
|
||||
@ -973,11 +877,8 @@ ifdef INSTALLPPUFILES
|
||||
ifneq ($(INSTALLPPULINKFILES),)
|
||||
@$(ECHO) -e $(addprefix "\n"$(UNITINSTALLDIR)/,$(INSTALLPPULINKFILES))
|
||||
endif
|
||||
ifneq ($(wildcard $(LIBFULLNAME)),)
|
||||
@$(ECHO) $(LIBINSTALLDIR)/$(LIBFULLNAME)
|
||||
ifdef inlinux
|
||||
@$(ECHO) $(LIBINSTALLDIR)/$(LIBNAME)
|
||||
endif
|
||||
ifneq ($(INSTALLPPULIBFILES),)
|
||||
@$(ECHO) -e $(addprefix "\n"$(LIBINSTALLDIR)/,$(INSTALLPPULIBFILES))
|
||||
endif
|
||||
endif
|
||||
ifdef EXTRAINSTALLFILES
|
||||
@ -1000,12 +901,9 @@ ifdef INSTALLPPUFILES
|
||||
ifneq ($(INSTALLPPULINKFILES),)
|
||||
$(INSTALL) $(INSTALLPPULINKFILES) $(UNITINSTALLDIR)
|
||||
endif
|
||||
ifneq ($(wildcard $(LIBFULLNAME)),)
|
||||
ifneq ($(INSTALLPPULIBFILES),)
|
||||
$(MKDIR) $(LIBINSTALLDIR)
|
||||
$(INSTALL) $(LIBFULLNAME) $(LIBINSTALLDIR)
|
||||
ifdef inlinux
|
||||
ln -sf $(LIBFULLNAME) $(LIBINSTALLDIR)/$(LIBNAME)
|
||||
endif
|
||||
$(INSTALL) $(INSTALLPPULIBFILES) $(LIBINSTALLDIR)
|
||||
endif
|
||||
endif
|
||||
ifdef EXTRAINSTALLFILES
|
||||
@ -1027,24 +925,6 @@ fpc_sourceinstall: clean
|
||||
$(MKDIR) $(SOURCEINSTALLDIR)
|
||||
$(COPYTREE) $(SOURCETOPDIR) $(SOURCEINSTALLDIR)
|
||||
|
||||
#####################################################################
|
||||
# exampleinstall rules
|
||||
#####################################################################
|
||||
|
||||
.PHONY: fpc_exampleinstall
|
||||
|
||||
fpc_exampleinstall: $(addsuffix _clean,$(EXAMPLEDIROBJECTS))
|
||||
ifdef EXAMPLESOURCEFILES
|
||||
$(MKDIR) $(EXAMPLEINSTALLDIR)
|
||||
$(COPY) $(EXAMPLESOURCEFILES) $(EXAMPLEINSTALLDIR)
|
||||
endif
|
||||
ifdef EXAMPLEDIROBJECTS
|
||||
ifndef EXAMPLESOURCEFILES
|
||||
$(MKDIR) $(EXAMPLEINSTALLDIR)
|
||||
endif
|
||||
$(COPYTREE) $(addsuffix /*,$(EXAMPLEDIROBJECTS)) $(EXAMPLEINSTALLDIR)
|
||||
endif
|
||||
|
||||
#####################################################################
|
||||
# Zip
|
||||
#####################################################################
|
||||
@ -1095,7 +975,7 @@ ifdef USETAR
|
||||
$(DEL) $(DESTZIPDIR)/$(ZIPNAME)$(TAREXT)
|
||||
cd $(PACKDIR) ; $(TARPROG) c$(TAROPT) --file $(DESTZIPDIR)/$(ZIPNAME)$(TAREXT) * ; cd $(BASEDIR)
|
||||
else
|
||||
$(DEL) $(DESTZIPDIR)/$(ZIPNAME)$(ZIPEXT)
|
||||
$(DEL) $(DESTZIPDIR)/$(ZIPNAME)/$(ZIPEXT)
|
||||
cd $(PACKDIR) ; $(ZIPPROG) -Dr $(ZIPOPT) $(DESTZIPDIR)/$(ZIPNAME)$(ZIPEXT) * ; cd $(BASEDIR)
|
||||
endif
|
||||
$(DELTREE) $(PACKDIR)
|
||||
@ -1106,35 +986,27 @@ endif
|
||||
fpc_zipsourceinstall:
|
||||
$(MAKE) fpc_zipinstall ZIPTARGET=sourceinstall PACKAGESUFFIX=src
|
||||
|
||||
.PHONY: fpc_zipexampleinstall
|
||||
|
||||
fpc_zipexampleinstall:
|
||||
$(MAKE) fpc_zipinstall ZIPTARGET=exampleinstall PACKAGESUFFIX=exm
|
||||
|
||||
#####################################################################
|
||||
# Clean rules
|
||||
#####################################################################
|
||||
|
||||
.PHONY: fpc_clean fpc_cleanall fpc_distclean
|
||||
.PHONY: fpc_clean fpc_cleanall
|
||||
|
||||
ifdef EXTRACLEANUNITS
|
||||
override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(EXTRACLEANUNITS))
|
||||
endif
|
||||
|
||||
ifdef CLEANPPUFILES
|
||||
override CLEANPPUFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANPPUFILES))
|
||||
# Get the .o and .a files created for the units
|
||||
ifdef PPUFILES
|
||||
CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))
|
||||
else
|
||||
CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))))
|
||||
CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)))
|
||||
endif
|
||||
override CLEANPPULINKFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANPPULINKFILES))
|
||||
endif
|
||||
|
||||
fpc_clean: $(CLEANTARGET)
|
||||
ifdef CLEANEXEFILES
|
||||
-$(DEL) $(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
|
||||
-$(DEL) $(CLEANEXEFILES)
|
||||
endif
|
||||
ifdef CLEANPPUFILES
|
||||
-$(DEL) $(CLEANPPUFILES)
|
||||
@ -1143,31 +1015,20 @@ ifneq ($(CLEANPPULINKFILES),)
|
||||
-$(DEL) $(CLEANPPULINKFILES)
|
||||
endif
|
||||
ifdef CLEANRSTFILES
|
||||
-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
|
||||
-$(DEL) $(CLEANRSTFILES)
|
||||
endif
|
||||
ifdef EXTRACLEANFILES
|
||||
-$(DEL) $(EXTRACLEANFILES)
|
||||
endif
|
||||
ifdef LIBNAME
|
||||
-$(DEL) $(LIBNAME) $(LIBFULLNAME)
|
||||
endif
|
||||
-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
|
||||
-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTCMD) $(REDIRFILE)
|
||||
|
||||
fpc_distclean: fpc_clean
|
||||
|
||||
# Also run clean first if targetdir is set. Unittargetdir is always
|
||||
# set if targetdir or unittargetdir is specified
|
||||
ifdef UNITTARGETDIR
|
||||
TARGETDIRCLEAN=clean
|
||||
endif
|
||||
|
||||
fpc_cleanall: $(CLEANTARGET) $(TARGETDIRCLEAN)
|
||||
fpc_cleanall: $(CLEANTARGET)
|
||||
ifdef CLEANEXEFILES
|
||||
-$(DEL) $(CLEANEXEFILES)
|
||||
endif
|
||||
-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
|
||||
-$(DELTREE) *$(SMARTEXT)
|
||||
-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
|
||||
-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTCMD) $(REDIRFILE)
|
||||
|
||||
#####################################################################
|
||||
# Info rules
|
||||
@ -1243,7 +1104,7 @@ endif
|
||||
# Users rules
|
||||
#####################################################################
|
||||
|
||||
vpath %$(PASEXT) $(INC) $(PROCINC)
|
||||
vpath %$(PASEXT) $(INC) $(PROCINC) $(UNIXINC)
|
||||
|
||||
#
|
||||
# Loaders
|
||||
@ -1285,14 +1146,14 @@ strings$(PPUEXT) : $(INC)/strings.pp $(INC)/stringsi.inc\
|
||||
#
|
||||
|
||||
linux$(PPUEXT) : linux.pp strings$(PPUEXT) $(INC)/textrec.inc $(INC)/filerec.inc \
|
||||
syscalls.inc systypes.inc sysconst.inc timezone.inc $(SYSTEMPPU) \
|
||||
linsysca.inc
|
||||
syscalls.inc systypes.inc sysconst.inc $(UNIXINC)/timezone.inc $(SYSTEMPPU) \
|
||||
$(UNIXINC)/linsysca.inc
|
||||
|
||||
ports$(PPUEXT) : ports.pp linux$(PPUEXT) objpas$(PPUEXT)
|
||||
|
||||
dl$(PPUEXT) : dl.pp
|
||||
|
||||
dynlibs$(PPUEXT) : $(INC)/dynlibs.pp dynlibs.inc dl$(PPUEXT) objpas$(PPUEXT)
|
||||
dynlibs$(PPUEXT) : $(INC)/dynlibs.pp $(UNIXINC)/dynlibs.inc dl$(PPUEXT) objpas$(PPUEXT)
|
||||
|
||||
|
||||
#
|
||||
@ -1304,7 +1165,7 @@ dos$(PPUEXT) : dos.pp $(INC)/filerec.inc $(INC)/textrec.inc strings$(PPUEXT) \
|
||||
|
||||
crt$(PPUEXT) : crt.pp $(INC)/textrec.inc linux$(PPUEXT) $(SYSTEMPPU)
|
||||
|
||||
objects$(PPUEXT) : $(INC)/objects.pp objinc.inc $(SYSTEMPPU)
|
||||
objects$(PPUEXT) : $(INC)/objects.pp $(UNIXINC)/objinc.inc $(SYSTEMPPU)
|
||||
|
||||
printer$(PPUEXT) : printer.pp $(INC)/textrec.inc linux$(PPUEXT) $(SYSTEMPPU)
|
||||
|
||||
@ -1315,12 +1176,12 @@ include $(GRAPHDIR)/makefile.inc
|
||||
GRAPHINCDEPS=$(addprefix $(GRAPHDIR)/,$(GRAPHINCNAMES))
|
||||
|
||||
graph$(PPUEXT) : graph.pp linux$(PPUEXT) $(SYSTEMPPU) \
|
||||
$(GRAPHINCDEPS) vgagraph16.inc
|
||||
$(COMPILER) -I$(GRAPHDIR) graph.pp $(REDIR)
|
||||
$(GRAPHINCDEPS) $(UNIXINC)/vgagraph16.inc
|
||||
$(COMPILER) -I$(GRAPHDIR) $(UNIXINC)/graph.pp $(REDIR)
|
||||
|
||||
ggigraph$(PPUEXT) : ggigraph.pp linux$(PPUEXT) $(SYSTEMPPU) \
|
||||
ggigraph$(PPUEXT) : $(UNIXINC)/ggigraph.pp linux$(PPUEXT) $(SYSTEMPPU) \
|
||||
$(GRAPHINCDEPS)
|
||||
$(COMPILER) -I$(GRAPHDIR) ggigraph.pp $(REDIR)
|
||||
$(COMPILER) -I$(GRAPHDIR) $(UNIXINC)/ggigraph.pp $(REDIR)
|
||||
|
||||
#
|
||||
# Delphi Compatible Units
|
||||
@ -1328,7 +1189,7 @@ ggigraph$(PPUEXT) : ggigraph.pp linux$(PPUEXT) $(SYSTEMPPU) \
|
||||
|
||||
sysutils$(PPUEXT) : sysutils.pp $(wildcard $(OBJPASDIR)/*.inc) \
|
||||
objpas$(PPUEXT) linux$(PPUEXT)
|
||||
$(COMPILER) -I$(OBJPASDIR) sysutils.pp $(REDIR)
|
||||
$(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/sysutils.pp $(REDIR)
|
||||
|
||||
typinfo$(PPUEXT): $(OBJPASDIR)/typinfo.pp objpas$(PPUEXT)
|
||||
$(COMPILER) -Sg $(OBJPASDIR)/typinfo.pp $(REDIR)
|
||||
@ -1341,7 +1202,7 @@ 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) varutils.pp $(REDIR)
|
||||
$(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/varutils.pp $(REDIR)
|
||||
|
||||
#
|
||||
# Other system-independent RTL Units
|
||||
|
@ -24,7 +24,7 @@ unitsubdir=rtl
|
||||
|
||||
[dirs]
|
||||
fpcdir=.
|
||||
incdir=$(INC) $(PROCINC)
|
||||
incdir=$(INC) $(PROCINC) $(UNIXINC)
|
||||
targetdir=.
|
||||
|
||||
[libs]
|
||||
@ -37,11 +37,11 @@ libunits=$(SYSTEMUNIT) objpas strings \
|
||||
cpu mmx getopts heaptrc \
|
||||
errors sockets ipc dl dynlibs varutils
|
||||
|
||||
|
||||
[presettings]
|
||||
RTL=..
|
||||
INC=$(RTL)/inc
|
||||
PROCINC=$(RTL)/$(CPU_TARGET)
|
||||
UNIXINC=$(RTL)/unix
|
||||
|
||||
UNITPREFIX=rtl
|
||||
|
||||
@ -61,7 +61,6 @@ ifndef USELIBGGI
|
||||
USELIBGGI=NO
|
||||
endif
|
||||
|
||||
|
||||
[postsettings]
|
||||
SYSTEMPPU=$(addsuffix $(PPUEXT),$(SYSTEMUNIT))
|
||||
|
||||
@ -82,7 +81,7 @@ SYSDEPS=$(SYSINCDEPS) $(SYSCPUDEPS)
|
||||
|
||||
|
||||
[rules]
|
||||
vpath %$(PASEXT) $(INC) $(PROCINC)
|
||||
vpath %$(PASEXT) $(INC) $(PROCINC) $(UNIXINC)
|
||||
|
||||
#
|
||||
# Loaders
|
||||
@ -124,14 +123,14 @@ strings$(PPUEXT) : $(INC)/strings.pp $(INC)/stringsi.inc\
|
||||
#
|
||||
|
||||
linux$(PPUEXT) : linux.pp strings$(PPUEXT) $(INC)/textrec.inc $(INC)/filerec.inc \
|
||||
syscalls.inc systypes.inc sysconst.inc timezone.inc $(SYSTEMPPU) \
|
||||
linsysca.inc
|
||||
syscalls.inc systypes.inc sysconst.inc $(UNIXINC)/timezone.inc $(SYSTEMPPU) \
|
||||
$(UNIXINC)/linsysca.inc
|
||||
|
||||
ports$(PPUEXT) : ports.pp linux$(PPUEXT) objpas$(PPUEXT)
|
||||
|
||||
dl$(PPUEXT) : dl.pp
|
||||
|
||||
dynlibs$(PPUEXT) : $(INC)/dynlibs.pp dynlibs.inc dl$(PPUEXT) objpas$(PPUEXT)
|
||||
dynlibs$(PPUEXT) : $(INC)/dynlibs.pp $(UNIXINC)/dynlibs.inc dl$(PPUEXT) objpas$(PPUEXT)
|
||||
|
||||
|
||||
#
|
||||
@ -143,7 +142,7 @@ dos$(PPUEXT) : dos.pp $(INC)/filerec.inc $(INC)/textrec.inc strings$(PPUEXT) \
|
||||
|
||||
crt$(PPUEXT) : crt.pp $(INC)/textrec.inc linux$(PPUEXT) $(SYSTEMPPU)
|
||||
|
||||
objects$(PPUEXT) : $(INC)/objects.pp objinc.inc $(SYSTEMPPU)
|
||||
objects$(PPUEXT) : $(INC)/objects.pp $(UNIXINC)/objinc.inc $(SYSTEMPPU)
|
||||
|
||||
printer$(PPUEXT) : printer.pp $(INC)/textrec.inc linux$(PPUEXT) $(SYSTEMPPU)
|
||||
|
||||
@ -154,12 +153,12 @@ include $(GRAPHDIR)/makefile.inc
|
||||
GRAPHINCDEPS=$(addprefix $(GRAPHDIR)/,$(GRAPHINCNAMES))
|
||||
|
||||
graph$(PPUEXT) : graph.pp linux$(PPUEXT) $(SYSTEMPPU) \
|
||||
$(GRAPHINCDEPS) vgagraph16.inc
|
||||
$(COMPILER) -I$(GRAPHDIR) graph.pp $(REDIR)
|
||||
$(GRAPHINCDEPS) $(UNIXINC)/vgagraph16.inc
|
||||
$(COMPILER) -I$(GRAPHDIR) $(UNIXINC)/graph.pp $(REDIR)
|
||||
|
||||
ggigraph$(PPUEXT) : ggigraph.pp linux$(PPUEXT) $(SYSTEMPPU) \
|
||||
ggigraph$(PPUEXT) : $(UNIXINC)/ggigraph.pp linux$(PPUEXT) $(SYSTEMPPU) \
|
||||
$(GRAPHINCDEPS)
|
||||
$(COMPILER) -I$(GRAPHDIR) ggigraph.pp $(REDIR)
|
||||
$(COMPILER) -I$(GRAPHDIR) $(UNIXINC)/ggigraph.pp $(REDIR)
|
||||
|
||||
#
|
||||
# Delphi Compatible Units
|
||||
@ -167,7 +166,7 @@ ggigraph$(PPUEXT) : ggigraph.pp linux$(PPUEXT) $(SYSTEMPPU) \
|
||||
|
||||
sysutils$(PPUEXT) : sysutils.pp $(wildcard $(OBJPASDIR)/*.inc) \
|
||||
objpas$(PPUEXT) linux$(PPUEXT)
|
||||
$(COMPILER) -I$(OBJPASDIR) sysutils.pp $(REDIR)
|
||||
$(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/sysutils.pp $(REDIR)
|
||||
|
||||
typinfo$(PPUEXT): $(OBJPASDIR)/typinfo.pp objpas$(PPUEXT)
|
||||
$(COMPILER) -Sg $(OBJPASDIR)/typinfo.pp $(REDIR)
|
||||
@ -180,7 +179,7 @@ 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) varutils.pp $(REDIR)
|
||||
$(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/varutils.pp $(REDIR)
|
||||
|
||||
#
|
||||
# Other system-independent RTL Units
|
||||
|
@ -22,750 +22,18 @@
|
||||
Unit SysLinux;
|
||||
Interface
|
||||
|
||||
{$ifdef m68k}
|
||||
{ used for single computations }
|
||||
const
|
||||
BIAS4 = $7f-1;
|
||||
{$endif}
|
||||
|
||||
{$define newsignal}
|
||||
|
||||
{$I systemh.inc}
|
||||
{$I heaph.inc}
|
||||
|
||||
const
|
||||
UnusedHandle = -1;
|
||||
StdInputHandle = 0;
|
||||
StdOutputHandle = 1;
|
||||
StdErrorHandle = 2;
|
||||
|
||||
var
|
||||
argc : longint;
|
||||
argv : ppchar;
|
||||
envp : ppchar;
|
||||
{$I sysunixh.inc}
|
||||
|
||||
Implementation
|
||||
|
||||
{$I system.inc}
|
||||
|
||||
{ used in syscall to report errors.}
|
||||
var
|
||||
Errno : longint;
|
||||
|
||||
{ Include constant and type definitions }
|
||||
{$i errno.inc } { Error numbers }
|
||||
{$i sysnr.inc } { System call numbers }
|
||||
{$i sysconst.inc } { Miscellaneous constants }
|
||||
{$i systypes.inc } { Types needed for system calls }
|
||||
|
||||
{ Read actual system call definitions. }
|
||||
{$i signal.inc}
|
||||
{$i syscalls.inc }
|
||||
|
||||
{*****************************************************************************
|
||||
Misc. System Dependent Functions
|
||||
*****************************************************************************}
|
||||
|
||||
procedure prthaltproc;external name '_haltproc';
|
||||
|
||||
procedure System_exit;
|
||||
begin
|
||||
{$ifdef i386}
|
||||
asm
|
||||
jmp prthaltproc
|
||||
end;
|
||||
{$else}
|
||||
asm
|
||||
jmp prthaltproc
|
||||
end;
|
||||
{$endif}
|
||||
End;
|
||||
|
||||
|
||||
Function ParamCount: Longint;
|
||||
Begin
|
||||
Paramcount:=argc-1
|
||||
End;
|
||||
|
||||
|
||||
Function ParamStr(l: Longint): String;
|
||||
var
|
||||
link,
|
||||
hs : string;
|
||||
i : longint;
|
||||
begin
|
||||
if l=0 then
|
||||
begin
|
||||
str(sys_getpid,hs);
|
||||
hs:='/proc/'+hs+'/exe'#0;
|
||||
i:=Sys_readlink(@hs[1],@link[1],high(link));
|
||||
{ it must also be an absolute filename, linux 2.0 points to a memory
|
||||
location so this will skip that }
|
||||
if (i>0) and (link[1]='/') then
|
||||
begin
|
||||
link[0]:=chr(i);
|
||||
paramstr:=link;
|
||||
end
|
||||
else
|
||||
paramstr:=strpas(argv[0]);
|
||||
end
|
||||
else
|
||||
if (l>0) and (l<argc) then
|
||||
paramstr:=strpas(argv[l])
|
||||
else
|
||||
paramstr:='';
|
||||
end;
|
||||
|
||||
|
||||
Procedure Randomize;
|
||||
Begin
|
||||
randseed:=sys_time;
|
||||
End;
|
||||
|
||||
|
||||
{*****************************************************************************
|
||||
Heap Management
|
||||
*****************************************************************************}
|
||||
|
||||
var
|
||||
_HEAP : longint;external name 'HEAP';
|
||||
_HEAPSIZE : longint;external name 'HEAPSIZE';
|
||||
|
||||
function getheapstart:pointer;assembler;
|
||||
{$ifdef i386}
|
||||
asm
|
||||
leal _HEAP,%eax
|
||||
end ['EAX'];
|
||||
{$else}
|
||||
asm
|
||||
lea.l _HEAP,a0
|
||||
move.l a0,d0
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
|
||||
function getheapsize:longint;assembler;
|
||||
{$ifdef i386}
|
||||
asm
|
||||
movl _HEAPSIZE,%eax
|
||||
end ['EAX'];
|
||||
{$else}
|
||||
asm
|
||||
move.l _HEAPSIZE,d0
|
||||
end ['D0'];
|
||||
{$endif}
|
||||
|
||||
|
||||
{$ifdef bsd}
|
||||
Function sbrk(size : longint) : Longint;
|
||||
|
||||
CONST MAP_PRIVATE =2;
|
||||
MAP_ANONYMOUS =$1000; {$20 under linux}
|
||||
|
||||
begin
|
||||
Sbrk:=do_syscall(syscall_nr_mmap,0,size,3,MAP_PRIVATE+MAP_ANONYMOUS,-1,0,0);
|
||||
if ErrNo<>0 then
|
||||
Sbrk:=0;
|
||||
end;
|
||||
|
||||
{$else}
|
||||
Function sbrk(size : longint) : Longint;
|
||||
type
|
||||
tmmapargs=packed record
|
||||
address : longint;
|
||||
size : longint;
|
||||
prot : longint;
|
||||
flags : longint;
|
||||
fd : longint;
|
||||
offset : longint;
|
||||
end;
|
||||
var
|
||||
t : syscallregs;
|
||||
mmapargs : tmmapargs;
|
||||
begin
|
||||
mmapargs.address:=0;
|
||||
mmapargs.size:=Size;
|
||||
mmapargs.prot:=3;
|
||||
mmapargs.flags:=$22;
|
||||
mmapargs.fd:=-1;
|
||||
mmapargs.offset:=0;
|
||||
t.reg2:=longint(@mmapargs);
|
||||
Sbrk:=syscall(syscall_nr_mmap,t);
|
||||
if ErrNo<>0 then
|
||||
Sbrk:=0;
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
{ include standard heap management }
|
||||
{$I heap.inc}
|
||||
|
||||
|
||||
{*****************************************************************************
|
||||
Low Level File Routines
|
||||
*****************************************************************************}
|
||||
|
||||
{
|
||||
The lowlevel file functions should take care of setting the InOutRes to the
|
||||
correct value if an error has occured, else leave it untouched
|
||||
}
|
||||
|
||||
Procedure Errno2Inoutres;
|
||||
{
|
||||
Convert ErrNo error to the correct Inoutres value
|
||||
}
|
||||
|
||||
begin
|
||||
if ErrNo=0 then { Else it will go through all the cases }
|
||||
exit;
|
||||
case ErrNo of
|
||||
Sys_ENFILE,
|
||||
Sys_EMFILE : Inoutres:=4;
|
||||
Sys_ENOENT : Inoutres:=2;
|
||||
Sys_EBADF : Inoutres:=6;
|
||||
Sys_ENOMEM,
|
||||
Sys_EFAULT : Inoutres:=217;
|
||||
Sys_EINVAL : Inoutres:=218;
|
||||
Sys_EPIPE,
|
||||
Sys_EINTR,
|
||||
Sys_EIO,
|
||||
Sys_EAGAIN,
|
||||
Sys_ENOSPC : Inoutres:=101;
|
||||
Sys_ENAMETOOLONG,
|
||||
Sys_ELOOP,
|
||||
Sys_ENOTDIR : Inoutres:=3;
|
||||
Sys_EROFS,
|
||||
Sys_EEXIST,
|
||||
Sys_EACCES : Inoutres:=5;
|
||||
Sys_ETXTBSY : Inoutres:=162;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Procedure Do_Close(Handle:Longint);
|
||||
Begin
|
||||
sys_close(Handle);
|
||||
End;
|
||||
|
||||
|
||||
Procedure Do_Erase(p:pchar);
|
||||
Begin
|
||||
sys_unlink(p);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Procedure Do_Rename(p1,p2:pchar);
|
||||
Begin
|
||||
sys_rename(p1,p2);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Function Do_Write(Handle,Addr,Len:Longint):longint;
|
||||
Begin
|
||||
repeat
|
||||
Do_Write:=sys_write(Handle,pchar(addr),len);
|
||||
until ErrNo<>Sys_EINTR;
|
||||
Errno2Inoutres;
|
||||
if Do_Write<0 then
|
||||
Do_Write:=0;
|
||||
End;
|
||||
|
||||
|
||||
Function Do_Read(Handle,Addr,Len:Longint):Longint;
|
||||
Begin
|
||||
repeat
|
||||
Do_Read:=sys_read(Handle,pchar(addr),len);
|
||||
until ErrNo<>Sys_EINTR;
|
||||
Errno2Inoutres;
|
||||
if Do_Read<0 then
|
||||
Do_Read:=0;
|
||||
End;
|
||||
|
||||
|
||||
Function Do_FilePos(Handle: Longint): Longint;
|
||||
Begin
|
||||
Do_FilePos:=sys_lseek(Handle, 0, Seek_Cur);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Procedure Do_Seek(Handle,Pos:Longint);
|
||||
Begin
|
||||
sys_lseek(Handle, pos, Seek_set);
|
||||
End;
|
||||
|
||||
|
||||
Function Do_SeekEnd(Handle:Longint): Longint;
|
||||
begin
|
||||
Do_SeekEnd:=sys_lseek(Handle,0,Seek_End);
|
||||
end;
|
||||
|
||||
{$ifdef BSD}
|
||||
Function Do_FileSize(Handle:Longint): Longint;
|
||||
var
|
||||
Info : Stat;
|
||||
Begin
|
||||
if do_SysCall(syscall_nr_fstat,handle,longint(@info))=0 then
|
||||
Do_FileSize:=Info.Size
|
||||
else
|
||||
Do_FileSize:=0;
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
{$ELSE}
|
||||
Function Do_FileSize(Handle:Longint): Longint;
|
||||
var
|
||||
regs : Syscallregs;
|
||||
Info : Stat;
|
||||
Begin
|
||||
regs.reg2:=Handle;
|
||||
regs.reg3:=longint(@Info);
|
||||
if SysCall(SysCall_nr_fstat,regs)=0 then
|
||||
Do_FileSize:=Info.Size
|
||||
else
|
||||
Do_FileSize:=0;
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
{$endif}
|
||||
|
||||
Procedure Do_Truncate(Handle,Pos:longint);
|
||||
{$ifndef bsd}
|
||||
var
|
||||
sr : syscallregs;
|
||||
{$endif}
|
||||
begin
|
||||
{$ifdef bsd}
|
||||
do_syscall(syscall_nr_ftruncate,handle,pos,0);
|
||||
{$else}
|
||||
sr.reg2:=Handle;
|
||||
sr.reg3:=Pos;
|
||||
syscall(syscall_nr_ftruncate,sr);
|
||||
{$endif}
|
||||
Errno2Inoutres;
|
||||
end;
|
||||
|
||||
|
||||
Procedure Do_Open(var f;p:pchar;flags:longint);
|
||||
{
|
||||
FileRec and textrec have both Handle and mode as the first items so
|
||||
they could use the same routine for opening/creating.
|
||||
when (flags and $100) the file will be append
|
||||
when (flags and $1000) the file will be truncate/rewritten
|
||||
when (flags and $10000) there is no check for close (needed for textfiles)
|
||||
}
|
||||
var
|
||||
oflags : longint;
|
||||
dirtest : stat;
|
||||
Begin
|
||||
{ close first if opened }
|
||||
if ((flags and $10000)=0) then
|
||||
begin
|
||||
case FileRec(f).mode of
|
||||
fminput,fmoutput,fminout : Do_Close(FileRec(f).Handle);
|
||||
fmclosed : ;
|
||||
else
|
||||
begin
|
||||
inoutres:=102; {not assigned}
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
{ reset file Handle }
|
||||
FileRec(f).Handle:=UnusedHandle;
|
||||
{ We do the conversion of filemodes here, concentrated on 1 place }
|
||||
case (flags and 3) of
|
||||
0 : begin
|
||||
oflags :=Open_RDONLY;
|
||||
FileRec(f).mode:=fminput;
|
||||
end;
|
||||
1 : begin
|
||||
oflags :=Open_WRONLY;
|
||||
FileRec(f).mode:=fmoutput;
|
||||
end;
|
||||
2 : begin
|
||||
oflags :=Open_RDWR;
|
||||
FileRec(f).mode:=fminout;
|
||||
end;
|
||||
end;
|
||||
if (flags and $1000)=$1000 then
|
||||
oflags:=oflags or (Open_CREAT or Open_TRUNC)
|
||||
else
|
||||
if (flags and $100)=$100 then
|
||||
oflags:=oflags or (Open_APPEND);
|
||||
{ empty name is special }
|
||||
if p[0]=#0 then
|
||||
begin
|
||||
case FileRec(f).mode of
|
||||
fminput :
|
||||
FileRec(f).Handle:=StdInputHandle;
|
||||
fminout, { this is set by rewrite }
|
||||
fmoutput :
|
||||
FileRec(f).Handle:=StdOutputHandle;
|
||||
fmappend :
|
||||
begin
|
||||
FileRec(f).Handle:=StdOutputHandle;
|
||||
FileRec(f).mode:=fmoutput; {fool fmappend}
|
||||
end;
|
||||
end;
|
||||
exit;
|
||||
end;
|
||||
{ real open call }
|
||||
FileRec(f).Handle:=sys_open(p,oflags,438);
|
||||
if (ErrNo=Sys_EROFS) and ((OFlags and Open_RDWR)<>0) then
|
||||
begin
|
||||
Oflags:=Oflags and not(Open_RDWR);
|
||||
FileRec(f).Handle:=sys_open(p,oflags,438);
|
||||
end;
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Function Do_IsDevice(Handle:Longint):boolean;
|
||||
{
|
||||
Interface to Unix ioctl call.
|
||||
Performs various operations on the filedescriptor Handle.
|
||||
Ndx describes the operation to perform.
|
||||
Data points to data needed for the Ndx function. The structure of this
|
||||
data is function-dependent.
|
||||
}
|
||||
var
|
||||
{$ifndef BSD}
|
||||
sr: SysCallRegs;
|
||||
{$endif}
|
||||
Data : array[0..255] of byte; {Large enough for termios info}
|
||||
begin
|
||||
{$ifdef BSD}
|
||||
Do_IsDevice:=(do_SysCall(syscall_nr_ioctl,handle,$5401,longint(@data))=0);
|
||||
{$else}
|
||||
sr.reg2:=Handle;
|
||||
sr.reg3:=$5401; {=TCGETS}
|
||||
sr.reg4:=Longint(@Data);
|
||||
Do_IsDevice:=(SysCall(Syscall_nr_ioctl,sr)=0);
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
|
||||
{*****************************************************************************
|
||||
UnTyped File Handling
|
||||
*****************************************************************************}
|
||||
|
||||
{$i file.inc}
|
||||
|
||||
{*****************************************************************************
|
||||
Typed File Handling
|
||||
*****************************************************************************}
|
||||
|
||||
{$i typefile.inc}
|
||||
|
||||
{*****************************************************************************
|
||||
Text File Handling
|
||||
*****************************************************************************}
|
||||
|
||||
{$DEFINE SHORT_LINEBREAK}
|
||||
{$DEFINE EXTENDED_EOF}
|
||||
|
||||
{$i text.inc}
|
||||
|
||||
{*****************************************************************************
|
||||
Directory Handling
|
||||
*****************************************************************************}
|
||||
|
||||
Procedure MkDir(Const s: String);[IOCheck];
|
||||
Var
|
||||
Buffer: Array[0..255] of Char;
|
||||
Begin
|
||||
If InOutRes <> 0 then exit;
|
||||
Move(s[1], Buffer, Length(s));
|
||||
Buffer[Length(s)] := #0;
|
||||
sys_mkdir(@buffer, 511);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Procedure RmDir(Const s: String);[IOCheck];
|
||||
Var
|
||||
Buffer: Array[0..255] of Char;
|
||||
Begin
|
||||
If InOutRes <> 0 then exit;
|
||||
Move(s[1], Buffer, Length(s));
|
||||
Buffer[Length(s)] := #0;
|
||||
sys_rmdir(@buffer);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Procedure ChDir(Const s: String);[IOCheck];
|
||||
Var
|
||||
Buffer: Array[0..255] of Char;
|
||||
Begin
|
||||
If InOutRes <> 0 then exit;
|
||||
Move(s[1], Buffer, Length(s));
|
||||
Buffer[Length(s)] := #0;
|
||||
sys_chdir(@buffer);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
procedure getdir(drivenr : byte;var dir : shortstring);
|
||||
var
|
||||
thisdir : stat;
|
||||
rootino,
|
||||
thisino,
|
||||
dotdotino : longint;
|
||||
rootdev,
|
||||
thisdev,
|
||||
dotdotdev : {$ifdef bsd}longint{$else}word{$endif};
|
||||
thedir,dummy : string[255];
|
||||
dirstream : pdir;
|
||||
d : pdirent;
|
||||
mountpoint,validdir : boolean;
|
||||
predot : string[255];
|
||||
begin
|
||||
drivenr:=0;
|
||||
dir:='';
|
||||
thedir:='/'#0;
|
||||
if sys_stat(@thedir[1],thisdir)<0 then
|
||||
exit;
|
||||
rootino:=thisdir.ino;
|
||||
rootdev:=thisdir.dev;
|
||||
thedir:='.'#0;
|
||||
if sys_stat(@thedir[1],thisdir)<0 then
|
||||
exit;
|
||||
thisino:=thisdir.ino;
|
||||
thisdev:=thisdir.dev;
|
||||
{ Now we can uniquely identify the current and root dir }
|
||||
thedir:='';
|
||||
predot:='';
|
||||
while not ((thisino=rootino) and (thisdev=rootdev)) do
|
||||
begin
|
||||
{ Are we on a mount point ? }
|
||||
dummy:=predot+'..'#0;
|
||||
if sys_stat(@dummy[1],thisdir)<0 then
|
||||
exit;
|
||||
dotdotino:=thisdir.ino;
|
||||
dotdotdev:=thisdir.dev;
|
||||
mountpoint:=(thisdev<>dotdotdev);
|
||||
{ Now, Try to find the name of this dir in the previous one }
|
||||
dirstream:=opendir (@dummy[1]);
|
||||
if dirstream=nil then
|
||||
exit;
|
||||
repeat
|
||||
d:=sys_readdir (dirstream);
|
||||
validdir:=false;
|
||||
if (d<>nil) and
|
||||
(not ((d^.name[0]='.') and ((d^.name[1]=#0) or ((d^.name[1]='.')
|
||||
and (d^.name[2]=#0))))) and
|
||||
(mountpoint or (d^.ino=thisino)) then
|
||||
begin
|
||||
dummy:=predot+'../'+strpas(@(d^.name[0]))+#0;
|
||||
validdir:=not (sys_stat (@(dummy[1]),thisdir)<0);
|
||||
end
|
||||
else
|
||||
validdir:=false;
|
||||
until (d=nil) or
|
||||
((validdir) and (thisdir.dev=thisdev) and (thisdir.ino=thisino) );
|
||||
if (closedir(dirstream)<0) or (d=nil) then
|
||||
exit;
|
||||
{ At this point, d.name contains the name of the current dir}
|
||||
thedir:='/'+strpas(@(d^.name[0]))+thedir;
|
||||
thisdev:=dotdotdev;
|
||||
thisino:=dotdotino;
|
||||
predot:=predot+'../';
|
||||
end;
|
||||
{ Now rootino=thisino and rootdev=thisdev so we've reached / }
|
||||
dir:=thedir
|
||||
end;
|
||||
|
||||
|
||||
{*****************************************************************************
|
||||
SystemUnit Initialization
|
||||
*****************************************************************************}
|
||||
|
||||
|
||||
{$ifdef I386}
|
||||
{ this should be defined in i386 directory !! PM }
|
||||
const
|
||||
fpucw : word = $1332;
|
||||
FPU_Invalid = 1;
|
||||
FPU_Denormal = 2;
|
||||
FPU_DivisionByZero = 4;
|
||||
FPU_Overflow = 8;
|
||||
FPU_Underflow = $10;
|
||||
FPU_StackUnderflow = $20;
|
||||
FPU_StackOverflow = $40;
|
||||
|
||||
{$endif I386}
|
||||
|
||||
Procedure ResetFPU;
|
||||
begin
|
||||
{$ifdef I386}
|
||||
asm
|
||||
fninit
|
||||
fldcw fpucw
|
||||
end;
|
||||
{$endif I386}
|
||||
end;
|
||||
|
||||
|
||||
{$ifdef BSD}
|
||||
procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec;someptr:pointer); cdecl;
|
||||
{$else}
|
||||
procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec); cdecl;
|
||||
{$ENDIF}
|
||||
var
|
||||
|
||||
res,fpustate : word;
|
||||
begin
|
||||
res:=0;
|
||||
case sig of
|
||||
8 : begin
|
||||
{ this is not allways necessary but I don't know yet
|
||||
how to tell if it is or not PM }
|
||||
{$ifdef I386}
|
||||
fpustate:=0;
|
||||
res:=200;
|
||||
{$ifndef BSD}
|
||||
if assigned(SigContext.fpstate) then
|
||||
fpuState:=SigContext.fpstate^.sw;
|
||||
{$else}
|
||||
fpustate:=SigContext.en_sw;
|
||||
writeln('xx:',sigcontext.en_tw,' ',sigcontext.en_cw);
|
||||
{$endif}
|
||||
if (FpuState and $7f) <> 0 then
|
||||
begin
|
||||
{ first check te more precise options }
|
||||
if (FpuState and FPU_DivisionByZero)<>0 then
|
||||
res:=200
|
||||
else if (FpuState and FPU_Overflow)<>0 then
|
||||
res:=205
|
||||
else if (FpuState and FPU_Underflow)<>0 then
|
||||
res:=206
|
||||
else if (FpuState and FPU_Denormal)<>0 then
|
||||
res:=216
|
||||
else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
|
||||
res:=207
|
||||
else if (FpuState and FPU_Invalid)<>0 then
|
||||
res:=216
|
||||
else
|
||||
res:=207; {'Coprocessor Error'}
|
||||
end;
|
||||
{$endif I386}
|
||||
ResetFPU;
|
||||
end;
|
||||
11 : res:=216;
|
||||
end;
|
||||
{ give runtime error at the position where the signal was raised }
|
||||
if res<>0 then
|
||||
begin
|
||||
{$ifdef I386}
|
||||
{$ifdef BSD}
|
||||
HandleErrorAddrFrame(res,SigContext.sc_eip,SigContext.sc_ebp);
|
||||
{$else}
|
||||
HandleErrorAddrFrame(res,SigContext.eip,SigContext.ebp);
|
||||
{$endif}
|
||||
{$else}
|
||||
HandleError(res);
|
||||
{$endif}
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Procedure InstallSignals;
|
||||
const
|
||||
{$Ifndef BSD}
|
||||
act: SigActionRec = (handler:(Sa:@SignalToRunError);sa_mask:0;sa_flags:0;
|
||||
Sa_restorer: NIL);
|
||||
{$ELSE}
|
||||
act: SigActionRec = (handler:(Sa:@SignalToRunError);sa_flags:SA_SIGINFO;
|
||||
sa_mask:0);
|
||||
{$endif}
|
||||
|
||||
oldact: PSigActionRec = Nil; {Probably not necessary anymore, now
|
||||
VAR is removed}
|
||||
begin
|
||||
ResetFPU;
|
||||
SigAction(8,@act,oldact);
|
||||
SigAction(11,@act,oldact);
|
||||
end;
|
||||
|
||||
|
||||
procedure SetupCmdLine;
|
||||
var
|
||||
bufsize,
|
||||
len,j,
|
||||
size,i : longint;
|
||||
found : boolean;
|
||||
buf : array[0..1026] of char;
|
||||
|
||||
procedure AddBuf;
|
||||
begin
|
||||
reallocmem(cmdline,size+bufsize);
|
||||
move(buf,cmdline[size],bufsize);
|
||||
inc(size,bufsize);
|
||||
bufsize:=0;
|
||||
end;
|
||||
|
||||
begin
|
||||
size:=0;
|
||||
bufsize:=0;
|
||||
i:=0;
|
||||
while (i<argc) do
|
||||
begin
|
||||
len:=strlen(argv[i]);
|
||||
if len>sizeof(buf)-2 then
|
||||
len:=sizeof(buf)-2;
|
||||
found:=false;
|
||||
for j:=1 to len do
|
||||
if argv[i][j]=' ' then
|
||||
begin
|
||||
found:=true;
|
||||
break;
|
||||
end;
|
||||
if bufsize+len>=sizeof(buf)-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;
|
||||
end;
|
||||
|
||||
|
||||
Begin
|
||||
{ Set up signals handlers }
|
||||
InstallSignals;
|
||||
{ Setup heap }
|
||||
InitHeap;
|
||||
InitExceptions;
|
||||
{ Arguments }
|
||||
SetupCmdLine;
|
||||
{ Setup stdin, stdout and stderr }
|
||||
OpenStdIO(Input,fmInput,StdInputHandle);
|
||||
OpenStdIO(Output,fmOutput,StdOutputHandle);
|
||||
OpenStdIO(StdOut,fmOutput,StdOutputHandle);
|
||||
OpenStdIO(StdErr,fmOutput,StdErrorHandle);
|
||||
{ Reset IO Error }
|
||||
InOutRes:=0;
|
||||
End.
|
||||
{$I sysunix.inc}
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.6 2000-09-11 13:48:08 marco
|
||||
Revision 1.7 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.6 2000/09/11 13:48:08 marco
|
||||
* FreeBSD support and removal of old sighandler
|
||||
|
||||
Revision 1.5 2000/08/13 08:43:45 peter
|
||||
|
@ -677,7 +677,10 @@ end;
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.3 2000-09-11 14:05:31 marco
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.3 2000/09/11 14:05:31 marco
|
||||
* FreeBSD support and removed old signalhandling
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:47 michael
|
@ -1652,7 +1652,10 @@ Finalization
|
||||
End.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2000-07-13 11:33:47 michael
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:47 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
@ -879,7 +879,10 @@ End.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.3 2000-07-14 10:33:10 michael
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.3 2000/07/14 10:33:10 michael
|
||||
+ Conditionals fixed
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:48 michael
|
@ -56,7 +56,10 @@ end;
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.1 2000-08-18 19:15:34 michael
|
||||
Revision 1.1 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.1 2000/08/18 19:15:34 michael
|
||||
+ Implemented loading of dynamical libraries
|
||||
|
||||
}
|
@ -144,7 +144,10 @@ Sys_EDQUOT = 122; { Quota exceeded }
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2000-07-13 11:33:48 michael
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:48 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
@ -175,7 +175,10 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.3 2000-09-04 19:39:28 peter
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.3 2000/09/04 19:39:28 peter
|
||||
* string to pchar (merged)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:48 michael
|
@ -534,7 +534,10 @@ finalization
|
||||
end.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2000-07-13 11:33:48 michael
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:48 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
@ -206,7 +206,10 @@ end;
|
||||
end.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2000-07-13 11:33:48 michael
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:48 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
@ -598,7 +598,10 @@ initialization
|
||||
end.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.4 2000-08-25 12:31:05 jonas
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.4 2000/08/25 12:31:05 jonas
|
||||
* fixed problem with messed-up terminal after exiting (merged from
|
||||
fixes branch)
|
||||
|
@ -19,7 +19,10 @@ implementation
|
||||
end.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2000-07-13 11:33:48 michael
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:48 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
@ -372,7 +372,10 @@ end;
|
||||
end.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.3 2000-09-12 08:51:43 marco
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.3 2000/09/12 08:51:43 marco
|
||||
* fixed some small problems left from merging. (waitpid has now last param longint)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:48 michael
|
@ -262,7 +262,10 @@ end;
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2000-09-11 14:05:31 marco
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/09/11 14:05:31 marco
|
||||
* FreeBSD support and removed old signalhandling
|
||||
|
||||
}
|
@ -1193,7 +1193,10 @@ end;
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.4 2000-09-12 08:51:43 marco
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.4 2000/09/12 08:51:43 marco
|
||||
* fixed some small problems left from merging. (waitpid has now last param longint)
|
||||
|
||||
Revision 1.3 2000/09/11 14:05:31 marco
|
@ -2799,7 +2799,10 @@ End.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.7 2000-09-12 08:51:43 marco
|
||||
Revision 1.2 2000-09-18 13:14:50 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.7 2000/09/12 08:51:43 marco
|
||||
* fixed some small problems left from merging. (waitpid has now last param longint)
|
||||
|
||||
Revision 1.6 2000/09/11 14:05:31 marco
|
@ -97,7 +97,10 @@ END;
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.3 2000-09-11 14:05:31 marco
|
||||
Revision 1.2 2000-09-18 13:14:51 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.3 2000/09/11 14:05:31 marco
|
||||
* FreeBSD support and removed old signalhandling
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:49 michael
|
@ -103,7 +103,10 @@ end;
|
||||
|
||||
end.
|
||||
$Log$
|
||||
Revision 1.2 2000-07-13 11:33:49 michael
|
||||
Revision 1.2 2000-09-18 13:14:51 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:49 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
@ -254,7 +254,10 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2000-07-13 11:33:49 michael
|
||||
Revision 1.2 2000-09-18 13:14:51 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:49 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
@ -205,7 +205,10 @@ end;
|
||||
|
||||
end.
|
||||
$Log$
|
||||
Revision 1.2 2000-07-13 11:33:49 michael
|
||||
Revision 1.2 2000-09-18 13:14:51 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:49 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
@ -155,7 +155,10 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.3 2000-09-11 14:05:31 marco
|
||||
Revision 1.2 2000-09-18 13:14:51 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.3 2000/09/11 14:05:31 marco
|
||||
* FreeBSD support and removed old signalhandling
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:49 michael
|
759
rtl/unix/sysunix.inc
Normal file
759
rtl/unix/sysunix.inc
Normal file
@ -0,0 +1,759 @@
|
||||
{
|
||||
$Id$
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
**********************************************************************}
|
||||
|
||||
{ These things are set in the makefile, }
|
||||
{ But you can override them here.}
|
||||
|
||||
{ If you use an aout system, set the conditional AOUT}
|
||||
{ $Define AOUT}
|
||||
|
||||
{$I system.inc}
|
||||
|
||||
{ used in syscall to report errors.}
|
||||
var
|
||||
Errno : longint;
|
||||
|
||||
{ Include constant and type definitions }
|
||||
{$i errno.inc } { Error numbers }
|
||||
{$i sysnr.inc } { System call numbers }
|
||||
{$i sysconst.inc } { Miscellaneous constants }
|
||||
{$i systypes.inc } { Types needed for system calls }
|
||||
|
||||
{ Read actual system call definitions. }
|
||||
{$i signal.inc}
|
||||
{$i syscalls.inc }
|
||||
|
||||
{*****************************************************************************
|
||||
Misc. System Dependent Functions
|
||||
*****************************************************************************}
|
||||
|
||||
procedure prthaltproc;external name '_haltproc';
|
||||
|
||||
procedure System_exit;
|
||||
begin
|
||||
{$ifdef i386}
|
||||
asm
|
||||
jmp prthaltproc
|
||||
end;
|
||||
{$else}
|
||||
asm
|
||||
jmp prthaltproc
|
||||
end;
|
||||
{$endif}
|
||||
End;
|
||||
|
||||
|
||||
Function ParamCount: Longint;
|
||||
Begin
|
||||
Paramcount:=argc-1
|
||||
End;
|
||||
|
||||
|
||||
Function ParamStr(l: Longint): String;
|
||||
var
|
||||
link,
|
||||
hs : string;
|
||||
i : longint;
|
||||
begin
|
||||
if l=0 then
|
||||
begin
|
||||
str(sys_getpid,hs);
|
||||
hs:='/proc/'+hs+'/exe'#0;
|
||||
i:=Sys_readlink(@hs[1],@link[1],high(link));
|
||||
{ it must also be an absolute filename, linux 2.0 points to a memory
|
||||
location so this will skip that }
|
||||
if (i>0) and (link[1]='/') then
|
||||
begin
|
||||
link[0]:=chr(i);
|
||||
paramstr:=link;
|
||||
end
|
||||
else
|
||||
paramstr:=strpas(argv[0]);
|
||||
end
|
||||
else
|
||||
if (l>0) and (l<argc) then
|
||||
paramstr:=strpas(argv[l])
|
||||
else
|
||||
paramstr:='';
|
||||
end;
|
||||
|
||||
|
||||
Procedure Randomize;
|
||||
Begin
|
||||
randseed:=sys_time;
|
||||
End;
|
||||
|
||||
|
||||
{*****************************************************************************
|
||||
Heap Management
|
||||
*****************************************************************************}
|
||||
|
||||
var
|
||||
_HEAP : longint;external name 'HEAP';
|
||||
_HEAPSIZE : longint;external name 'HEAPSIZE';
|
||||
|
||||
function getheapstart:pointer;assembler;
|
||||
{$ifdef i386}
|
||||
asm
|
||||
leal _HEAP,%eax
|
||||
end ['EAX'];
|
||||
{$else}
|
||||
asm
|
||||
lea.l _HEAP,a0
|
||||
move.l a0,d0
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
|
||||
function getheapsize:longint;assembler;
|
||||
{$ifdef i386}
|
||||
asm
|
||||
movl _HEAPSIZE,%eax
|
||||
end ['EAX'];
|
||||
{$else}
|
||||
asm
|
||||
move.l _HEAPSIZE,d0
|
||||
end ['D0'];
|
||||
{$endif}
|
||||
|
||||
|
||||
{$ifdef bsd}
|
||||
Function sbrk(size : longint) : Longint;
|
||||
|
||||
CONST MAP_PRIVATE =2;
|
||||
MAP_ANONYMOUS =$1000; {$20 under linux}
|
||||
|
||||
begin
|
||||
Sbrk:=do_syscall(syscall_nr_mmap,0,size,3,MAP_PRIVATE+MAP_ANONYMOUS,-1,0,0);
|
||||
if ErrNo<>0 then
|
||||
Sbrk:=0;
|
||||
end;
|
||||
|
||||
{$else}
|
||||
Function sbrk(size : longint) : Longint;
|
||||
type
|
||||
tmmapargs=packed record
|
||||
address : longint;
|
||||
size : longint;
|
||||
prot : longint;
|
||||
flags : longint;
|
||||
fd : longint;
|
||||
offset : longint;
|
||||
end;
|
||||
var
|
||||
t : syscallregs;
|
||||
mmapargs : tmmapargs;
|
||||
begin
|
||||
mmapargs.address:=0;
|
||||
mmapargs.size:=Size;
|
||||
mmapargs.prot:=3;
|
||||
mmapargs.flags:=$22;
|
||||
mmapargs.fd:=-1;
|
||||
mmapargs.offset:=0;
|
||||
t.reg2:=longint(@mmapargs);
|
||||
Sbrk:=syscall(syscall_nr_mmap,t);
|
||||
if ErrNo<>0 then
|
||||
Sbrk:=0;
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
{ include standard heap management }
|
||||
{$I heap.inc}
|
||||
|
||||
|
||||
{*****************************************************************************
|
||||
Low Level File Routines
|
||||
*****************************************************************************}
|
||||
|
||||
{
|
||||
The lowlevel file functions should take care of setting the InOutRes to the
|
||||
correct value if an error has occured, else leave it untouched
|
||||
}
|
||||
|
||||
Procedure Errno2Inoutres;
|
||||
{
|
||||
Convert ErrNo error to the correct Inoutres value
|
||||
}
|
||||
|
||||
begin
|
||||
if ErrNo=0 then { Else it will go through all the cases }
|
||||
exit;
|
||||
case ErrNo of
|
||||
Sys_ENFILE,
|
||||
Sys_EMFILE : Inoutres:=4;
|
||||
Sys_ENOENT : Inoutres:=2;
|
||||
Sys_EBADF : Inoutres:=6;
|
||||
Sys_ENOMEM,
|
||||
Sys_EFAULT : Inoutres:=217;
|
||||
Sys_EINVAL : Inoutres:=218;
|
||||
Sys_EPIPE,
|
||||
Sys_EINTR,
|
||||
Sys_EIO,
|
||||
Sys_EAGAIN,
|
||||
Sys_ENOSPC : Inoutres:=101;
|
||||
Sys_ENAMETOOLONG,
|
||||
Sys_ELOOP,
|
||||
Sys_ENOTDIR : Inoutres:=3;
|
||||
Sys_EROFS,
|
||||
Sys_EEXIST,
|
||||
Sys_EACCES : Inoutres:=5;
|
||||
Sys_ETXTBSY : Inoutres:=162;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Procedure Do_Close(Handle:Longint);
|
||||
Begin
|
||||
sys_close(Handle);
|
||||
End;
|
||||
|
||||
|
||||
Procedure Do_Erase(p:pchar);
|
||||
Begin
|
||||
sys_unlink(p);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Procedure Do_Rename(p1,p2:pchar);
|
||||
Begin
|
||||
sys_rename(p1,p2);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Function Do_Write(Handle,Addr,Len:Longint):longint;
|
||||
Begin
|
||||
repeat
|
||||
Do_Write:=sys_write(Handle,pchar(addr),len);
|
||||
until ErrNo<>Sys_EINTR;
|
||||
Errno2Inoutres;
|
||||
if Do_Write<0 then
|
||||
Do_Write:=0;
|
||||
End;
|
||||
|
||||
|
||||
Function Do_Read(Handle,Addr,Len:Longint):Longint;
|
||||
Begin
|
||||
repeat
|
||||
Do_Read:=sys_read(Handle,pchar(addr),len);
|
||||
until ErrNo<>Sys_EINTR;
|
||||
Errno2Inoutres;
|
||||
if Do_Read<0 then
|
||||
Do_Read:=0;
|
||||
End;
|
||||
|
||||
|
||||
Function Do_FilePos(Handle: Longint): Longint;
|
||||
Begin
|
||||
Do_FilePos:=sys_lseek(Handle, 0, Seek_Cur);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Procedure Do_Seek(Handle,Pos:Longint);
|
||||
Begin
|
||||
sys_lseek(Handle, pos, Seek_set);
|
||||
End;
|
||||
|
||||
|
||||
Function Do_SeekEnd(Handle:Longint): Longint;
|
||||
begin
|
||||
Do_SeekEnd:=sys_lseek(Handle,0,Seek_End);
|
||||
end;
|
||||
|
||||
{$ifdef BSD}
|
||||
Function Do_FileSize(Handle:Longint): Longint;
|
||||
var
|
||||
Info : Stat;
|
||||
Begin
|
||||
if do_SysCall(syscall_nr_fstat,handle,longint(@info))=0 then
|
||||
Do_FileSize:=Info.Size
|
||||
else
|
||||
Do_FileSize:=0;
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
{$ELSE}
|
||||
Function Do_FileSize(Handle:Longint): Longint;
|
||||
var
|
||||
regs : Syscallregs;
|
||||
Info : Stat;
|
||||
Begin
|
||||
regs.reg2:=Handle;
|
||||
regs.reg3:=longint(@Info);
|
||||
if SysCall(SysCall_nr_fstat,regs)=0 then
|
||||
Do_FileSize:=Info.Size
|
||||
else
|
||||
Do_FileSize:=0;
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
{$endif}
|
||||
|
||||
Procedure Do_Truncate(Handle,Pos:longint);
|
||||
{$ifndef bsd}
|
||||
var
|
||||
sr : syscallregs;
|
||||
{$endif}
|
||||
begin
|
||||
{$ifdef bsd}
|
||||
do_syscall(syscall_nr_ftruncate,handle,pos,0);
|
||||
{$else}
|
||||
sr.reg2:=Handle;
|
||||
sr.reg3:=Pos;
|
||||
syscall(syscall_nr_ftruncate,sr);
|
||||
{$endif}
|
||||
Errno2Inoutres;
|
||||
end;
|
||||
|
||||
|
||||
Procedure Do_Open(var f;p:pchar;flags:longint);
|
||||
{
|
||||
FileRec and textrec have both Handle and mode as the first items so
|
||||
they could use the same routine for opening/creating.
|
||||
when (flags and $100) the file will be append
|
||||
when (flags and $1000) the file will be truncate/rewritten
|
||||
when (flags and $10000) there is no check for close (needed for textfiles)
|
||||
}
|
||||
var
|
||||
oflags : longint;
|
||||
dirtest : stat;
|
||||
Begin
|
||||
{ close first if opened }
|
||||
if ((flags and $10000)=0) then
|
||||
begin
|
||||
case FileRec(f).mode of
|
||||
fminput,fmoutput,fminout : Do_Close(FileRec(f).Handle);
|
||||
fmclosed : ;
|
||||
else
|
||||
begin
|
||||
inoutres:=102; {not assigned}
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
{ reset file Handle }
|
||||
FileRec(f).Handle:=UnusedHandle;
|
||||
{ We do the conversion of filemodes here, concentrated on 1 place }
|
||||
case (flags and 3) of
|
||||
0 : begin
|
||||
oflags :=Open_RDONLY;
|
||||
FileRec(f).mode:=fminput;
|
||||
end;
|
||||
1 : begin
|
||||
oflags :=Open_WRONLY;
|
||||
FileRec(f).mode:=fmoutput;
|
||||
end;
|
||||
2 : begin
|
||||
oflags :=Open_RDWR;
|
||||
FileRec(f).mode:=fminout;
|
||||
end;
|
||||
end;
|
||||
if (flags and $1000)=$1000 then
|
||||
oflags:=oflags or (Open_CREAT or Open_TRUNC)
|
||||
else
|
||||
if (flags and $100)=$100 then
|
||||
oflags:=oflags or (Open_APPEND);
|
||||
{ empty name is special }
|
||||
if p[0]=#0 then
|
||||
begin
|
||||
case FileRec(f).mode of
|
||||
fminput :
|
||||
FileRec(f).Handle:=StdInputHandle;
|
||||
fminout, { this is set by rewrite }
|
||||
fmoutput :
|
||||
FileRec(f).Handle:=StdOutputHandle;
|
||||
fmappend :
|
||||
begin
|
||||
FileRec(f).Handle:=StdOutputHandle;
|
||||
FileRec(f).mode:=fmoutput; {fool fmappend}
|
||||
end;
|
||||
end;
|
||||
exit;
|
||||
end;
|
||||
{ real open call }
|
||||
FileRec(f).Handle:=sys_open(p,oflags,438);
|
||||
if (ErrNo=Sys_EROFS) and ((OFlags and Open_RDWR)<>0) then
|
||||
begin
|
||||
Oflags:=Oflags and not(Open_RDWR);
|
||||
FileRec(f).Handle:=sys_open(p,oflags,438);
|
||||
end;
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Function Do_IsDevice(Handle:Longint):boolean;
|
||||
{
|
||||
Interface to Unix ioctl call.
|
||||
Performs various operations on the filedescriptor Handle.
|
||||
Ndx describes the operation to perform.
|
||||
Data points to data needed for the Ndx function. The structure of this
|
||||
data is function-dependent.
|
||||
}
|
||||
var
|
||||
{$ifndef BSD}
|
||||
sr: SysCallRegs;
|
||||
{$endif}
|
||||
Data : array[0..255] of byte; {Large enough for termios info}
|
||||
begin
|
||||
{$ifdef BSD}
|
||||
Do_IsDevice:=(do_SysCall(syscall_nr_ioctl,handle,$5401,longint(@data))=0);
|
||||
{$else}
|
||||
sr.reg2:=Handle;
|
||||
sr.reg3:=$5401; {=TCGETS}
|
||||
sr.reg4:=Longint(@Data);
|
||||
Do_IsDevice:=(SysCall(Syscall_nr_ioctl,sr)=0);
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
|
||||
{*****************************************************************************
|
||||
UnTyped File Handling
|
||||
*****************************************************************************}
|
||||
|
||||
{$i file.inc}
|
||||
|
||||
{*****************************************************************************
|
||||
Typed File Handling
|
||||
*****************************************************************************}
|
||||
|
||||
{$i typefile.inc}
|
||||
|
||||
{*****************************************************************************
|
||||
Text File Handling
|
||||
*****************************************************************************}
|
||||
|
||||
{$DEFINE SHORT_LINEBREAK}
|
||||
{$DEFINE EXTENDED_EOF}
|
||||
|
||||
{$i text.inc}
|
||||
|
||||
{*****************************************************************************
|
||||
Directory Handling
|
||||
*****************************************************************************}
|
||||
|
||||
Procedure MkDir(Const s: String);[IOCheck];
|
||||
Var
|
||||
Buffer: Array[0..255] of Char;
|
||||
Begin
|
||||
If InOutRes <> 0 then exit;
|
||||
Move(s[1], Buffer, Length(s));
|
||||
Buffer[Length(s)] := #0;
|
||||
sys_mkdir(@buffer, 511);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Procedure RmDir(Const s: String);[IOCheck];
|
||||
Var
|
||||
Buffer: Array[0..255] of Char;
|
||||
Begin
|
||||
If InOutRes <> 0 then exit;
|
||||
Move(s[1], Buffer, Length(s));
|
||||
Buffer[Length(s)] := #0;
|
||||
sys_rmdir(@buffer);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
Procedure ChDir(Const s: String);[IOCheck];
|
||||
Var
|
||||
Buffer: Array[0..255] of Char;
|
||||
Begin
|
||||
If InOutRes <> 0 then exit;
|
||||
Move(s[1], Buffer, Length(s));
|
||||
Buffer[Length(s)] := #0;
|
||||
sys_chdir(@buffer);
|
||||
Errno2Inoutres;
|
||||
End;
|
||||
|
||||
|
||||
procedure getdir(drivenr : byte;var dir : shortstring);
|
||||
var
|
||||
thisdir : stat;
|
||||
rootino,
|
||||
thisino,
|
||||
dotdotino : longint;
|
||||
rootdev,
|
||||
thisdev,
|
||||
dotdotdev : {$ifdef bsd}longint{$else}word{$endif};
|
||||
thedir,dummy : string[255];
|
||||
dirstream : pdir;
|
||||
d : pdirent;
|
||||
mountpoint,validdir : boolean;
|
||||
predot : string[255];
|
||||
begin
|
||||
drivenr:=0;
|
||||
dir:='';
|
||||
thedir:='/'#0;
|
||||
if sys_stat(@thedir[1],thisdir)<0 then
|
||||
exit;
|
||||
rootino:=thisdir.ino;
|
||||
rootdev:=thisdir.dev;
|
||||
thedir:='.'#0;
|
||||
if sys_stat(@thedir[1],thisdir)<0 then
|
||||
exit;
|
||||
thisino:=thisdir.ino;
|
||||
thisdev:=thisdir.dev;
|
||||
{ Now we can uniquely identify the current and root dir }
|
||||
thedir:='';
|
||||
predot:='';
|
||||
while not ((thisino=rootino) and (thisdev=rootdev)) do
|
||||
begin
|
||||
{ Are we on a mount point ? }
|
||||
dummy:=predot+'..'#0;
|
||||
if sys_stat(@dummy[1],thisdir)<0 then
|
||||
exit;
|
||||
dotdotino:=thisdir.ino;
|
||||
dotdotdev:=thisdir.dev;
|
||||
mountpoint:=(thisdev<>dotdotdev);
|
||||
{ Now, Try to find the name of this dir in the previous one }
|
||||
dirstream:=opendir (@dummy[1]);
|
||||
if dirstream=nil then
|
||||
exit;
|
||||
repeat
|
||||
d:=sys_readdir (dirstream);
|
||||
validdir:=false;
|
||||
if (d<>nil) and
|
||||
(not ((d^.name[0]='.') and ((d^.name[1]=#0) or ((d^.name[1]='.')
|
||||
and (d^.name[2]=#0))))) and
|
||||
(mountpoint or (d^.ino=thisino)) then
|
||||
begin
|
||||
dummy:=predot+'../'+strpas(@(d^.name[0]))+#0;
|
||||
validdir:=not (sys_stat (@(dummy[1]),thisdir)<0);
|
||||
end
|
||||
else
|
||||
validdir:=false;
|
||||
until (d=nil) or
|
||||
((validdir) and (thisdir.dev=thisdev) and (thisdir.ino=thisino) );
|
||||
if (closedir(dirstream)<0) or (d=nil) then
|
||||
exit;
|
||||
{ At this point, d.name contains the name of the current dir}
|
||||
thedir:='/'+strpas(@(d^.name[0]))+thedir;
|
||||
thisdev:=dotdotdev;
|
||||
thisino:=dotdotino;
|
||||
predot:=predot+'../';
|
||||
end;
|
||||
{ Now rootino=thisino and rootdev=thisdev so we've reached / }
|
||||
dir:=thedir
|
||||
end;
|
||||
|
||||
|
||||
{*****************************************************************************
|
||||
SystemUnit Initialization
|
||||
*****************************************************************************}
|
||||
|
||||
|
||||
{$ifdef I386}
|
||||
{ this should be defined in i386 directory !! PM }
|
||||
const
|
||||
fpucw : word = $1332;
|
||||
FPU_Invalid = 1;
|
||||
FPU_Denormal = 2;
|
||||
FPU_DivisionByZero = 4;
|
||||
FPU_Overflow = 8;
|
||||
FPU_Underflow = $10;
|
||||
FPU_StackUnderflow = $20;
|
||||
FPU_StackOverflow = $40;
|
||||
|
||||
{$endif I386}
|
||||
|
||||
Procedure ResetFPU;
|
||||
begin
|
||||
{$ifdef I386}
|
||||
asm
|
||||
fninit
|
||||
fldcw fpucw
|
||||
end;
|
||||
{$endif I386}
|
||||
end;
|
||||
|
||||
|
||||
{$ifdef BSD}
|
||||
procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec;someptr:pointer); cdecl;
|
||||
{$else}
|
||||
procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec); cdecl;
|
||||
{$ENDIF}
|
||||
var
|
||||
|
||||
res,fpustate : word;
|
||||
begin
|
||||
res:=0;
|
||||
case sig of
|
||||
8 : begin
|
||||
{ this is not allways necessary but I don't know yet
|
||||
how to tell if it is or not PM }
|
||||
{$ifdef I386}
|
||||
fpustate:=0;
|
||||
res:=200;
|
||||
{$ifndef BSD}
|
||||
if assigned(SigContext.fpstate) then
|
||||
fpuState:=SigContext.fpstate^.sw;
|
||||
{$else}
|
||||
fpustate:=SigContext.en_sw;
|
||||
writeln('xx:',sigcontext.en_tw,' ',sigcontext.en_cw);
|
||||
{$endif}
|
||||
if (FpuState and $7f) <> 0 then
|
||||
begin
|
||||
{ first check te more precise options }
|
||||
if (FpuState and FPU_DivisionByZero)<>0 then
|
||||
res:=200
|
||||
else if (FpuState and FPU_Overflow)<>0 then
|
||||
res:=205
|
||||
else if (FpuState and FPU_Underflow)<>0 then
|
||||
res:=206
|
||||
else if (FpuState and FPU_Denormal)<>0 then
|
||||
res:=216
|
||||
else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
|
||||
res:=207
|
||||
else if (FpuState and FPU_Invalid)<>0 then
|
||||
res:=216
|
||||
else
|
||||
res:=207; {'Coprocessor Error'}
|
||||
end;
|
||||
{$endif I386}
|
||||
ResetFPU;
|
||||
end;
|
||||
11 : res:=216;
|
||||
end;
|
||||
{ give runtime error at the position where the signal was raised }
|
||||
if res<>0 then
|
||||
begin
|
||||
{$ifdef I386}
|
||||
{$ifdef BSD}
|
||||
HandleErrorAddrFrame(res,SigContext.sc_eip,SigContext.sc_ebp);
|
||||
{$else}
|
||||
HandleErrorAddrFrame(res,SigContext.eip,SigContext.ebp);
|
||||
{$endif}
|
||||
{$else}
|
||||
HandleError(res);
|
||||
{$endif}
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Procedure InstallSignals;
|
||||
const
|
||||
{$Ifndef BSD}
|
||||
act: SigActionRec = (handler:(Sa:@SignalToRunError);sa_mask:0;sa_flags:0;
|
||||
Sa_restorer: NIL);
|
||||
{$ELSE}
|
||||
act: SigActionRec = (handler:(Sa:@SignalToRunError);sa_flags:SA_SIGINFO;
|
||||
sa_mask:0);
|
||||
{$endif}
|
||||
|
||||
oldact: PSigActionRec = Nil; {Probably not necessary anymore, now
|
||||
VAR is removed}
|
||||
begin
|
||||
ResetFPU;
|
||||
SigAction(8,@act,oldact);
|
||||
SigAction(11,@act,oldact);
|
||||
end;
|
||||
|
||||
|
||||
procedure SetupCmdLine;
|
||||
var
|
||||
bufsize,
|
||||
len,j,
|
||||
size,i : longint;
|
||||
found : boolean;
|
||||
buf : array[0..1026] of char;
|
||||
|
||||
procedure AddBuf;
|
||||
begin
|
||||
reallocmem(cmdline,size+bufsize);
|
||||
move(buf,cmdline[size],bufsize);
|
||||
inc(size,bufsize);
|
||||
bufsize:=0;
|
||||
end;
|
||||
|
||||
begin
|
||||
size:=0;
|
||||
bufsize:=0;
|
||||
i:=0;
|
||||
while (i<argc) do
|
||||
begin
|
||||
len:=strlen(argv[i]);
|
||||
if len>sizeof(buf)-2 then
|
||||
len:=sizeof(buf)-2;
|
||||
found:=false;
|
||||
for j:=1 to len do
|
||||
if argv[i][j]=' ' then
|
||||
begin
|
||||
found:=true;
|
||||
break;
|
||||
end;
|
||||
if bufsize+len>=sizeof(buf)-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;
|
||||
end;
|
||||
|
||||
|
||||
Begin
|
||||
{ Set up signals handlers }
|
||||
InstallSignals;
|
||||
{ Setup heap }
|
||||
InitHeap;
|
||||
InitExceptions;
|
||||
{ Arguments }
|
||||
SetupCmdLine;
|
||||
{ Setup stdin, stdout and stderr }
|
||||
OpenStdIO(Input,fmInput,StdInputHandle);
|
||||
OpenStdIO(Output,fmOutput,StdOutputHandle);
|
||||
OpenStdIO(StdOut,fmOutput,StdOutputHandle);
|
||||
OpenStdIO(StdErr,fmOutput,StdErrorHandle);
|
||||
{ Reset IO Error }
|
||||
InOutRes:=0;
|
||||
End.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2000-09-18 13:14:51 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.6 2000/09/11 13:48:08 marco
|
||||
* FreeBSD support and removal of old sighandler
|
||||
|
||||
Revision 1.5 2000/08/13 08:43:45 peter
|
||||
* don't check for directory in do_open (merged)
|
||||
|
||||
Revision 1.4 2000/08/05 18:33:51 peter
|
||||
* paramstr(0) fix for linux 2.0 kernels (merged)
|
||||
|
||||
Revision 1.3 2000/07/14 10:33:10 michael
|
||||
+ Conditionals fixed
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:49 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
22
rtl/unix/sysunixh.inc
Normal file
22
rtl/unix/sysunixh.inc
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
{$ifdef m68k}
|
||||
{ used for single computations }
|
||||
const
|
||||
BIAS4 = $7f-1;
|
||||
{$endif}
|
||||
|
||||
{$define newsignal}
|
||||
|
||||
{$I systemh.inc}
|
||||
{$I heaph.inc}
|
||||
|
||||
const
|
||||
UnusedHandle = -1;
|
||||
StdInputHandle = 0;
|
||||
StdOutputHandle = 1;
|
||||
StdErrorHandle = 2;
|
||||
|
||||
var
|
||||
argc : longint;
|
||||
argv : ppchar;
|
||||
envp : ppchar;
|
@ -435,7 +435,10 @@ end.
|
||||
{
|
||||
|
||||
$Log$
|
||||
Revision 1.3 2000-08-29 17:58:13 michael
|
||||
Revision 1.2 2000-09-18 13:14:51 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.3 2000/08/29 17:58:13 michael
|
||||
Merged syserrormsg fix
|
||||
|
||||
Revision 1.2 2000/08/20 15:46:46 peter
|
@ -286,7 +286,10 @@ end;
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2000-07-13 11:33:49 michael
|
||||
Revision 1.2 2000-09-18 13:14:51 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:49 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
@ -40,7 +40,10 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.1 2000-08-29 18:20:13 michael
|
||||
Revision 1.1 2000-09-18 13:14:51 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.1 2000/08/29 18:20:13 michael
|
||||
+ new include files
|
||||
|
||||
}
|
@ -428,7 +428,10 @@ end;
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2000-07-13 11:33:49 michael
|
||||
Revision 1.2 2000-09-18 13:14:51 marco
|
||||
* Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
|
||||
|
||||
Revision 1.2 2000/07/13 11:33:49 michael
|
||||
+ removed logs
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user