From 202fb34aeca8e3be17d90d6bd1b621ded8920560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20DUBOIN?= Date: Tue, 4 Mar 2025 22:03:47 +0100 Subject: [PATCH 1/6] feat(toolchain: newlib): add newlib libc Newlib is a multitarget libc implementation. This commit only adds the posibility to build it easily, and setup it so that it can be used with our custom toolchain in order to compile our future userland executables. It is still missing the required syscall implementations, since most (if not all technically) have yet to be implemented inside the kernel. We should now quickly implement the first few ones (exit, fds, etc ...) in order to REALLY compile our own program. --- README.md | 11 + flake.nix | 5 +- toolchain/build.mk | 1 + toolchain/newlib/.gitignore | 1 + toolchain/newlib/build.mk | 42 + toolchain/newlib/port/config.sub | 2359 +++++++++++++++++ toolchain/newlib/port/newlib/configure.host | 973 +++++++ .../newlib/port/newlib/libc/acinclude.m4 | 70 + .../newlib/port/newlib/libc/sys/Makefile.inc | 72 + .../newlib/libc/sys/dailyrun/Makefile.inc | 1 + .../port/newlib/libc/sys/dailyrun/crt0.c | 20 + .../port/newlib/libc/sys/dailyrun/syscalls.c | 30 + 12 files changed, 3583 insertions(+), 2 deletions(-) create mode 100644 toolchain/newlib/.gitignore create mode 100644 toolchain/newlib/build.mk create mode 100755 toolchain/newlib/port/config.sub create mode 100644 toolchain/newlib/port/newlib/configure.host create mode 100644 toolchain/newlib/port/newlib/libc/acinclude.m4 create mode 100644 toolchain/newlib/port/newlib/libc/sys/Makefile.inc create mode 100644 toolchain/newlib/port/newlib/libc/sys/dailyrun/Makefile.inc create mode 100644 toolchain/newlib/port/newlib/libc/sys/dailyrun/crt0.c create mode 100644 toolchain/newlib/port/newlib/libc/sys/dailyrun/syscalls.c diff --git a/README.md b/README.md index f9e4a678..b8033f02 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,17 @@ $ make iso # builds the kernel.iso file $ make qemu # boots up qemu using the iso file ``` +### Toolchain + +If you do not already have an available `i686-elf` toolchain, a custom GCC target for this kernel (i686-dailyrun) +is available for you to build inside the `toolchain` directory. Note that using this toolchain is required when +building userland executables destined to be used with this kernel. + +```bash +$ make gcc TARGET=i686-dailyrun ARCH= CROSS_COMPILE= +$ make libc ARCH=i686 CROSS_COMPILE= +``` + ## Testing I don't know how I can test kernel code, so all tests are performed manually for the time being ... diff --git a/flake.nix b/flake.nix index 2d1217a9..616d3cd5 100644 --- a/flake.nix +++ b/flake.nix @@ -73,8 +73,9 @@ gnumake pkg-config autoconf-archive - autoconf - automake + autoconf269 # newlib requires using v2.69 exactly + automake115x + autogen # Required libraries gmp.dev libmpc diff --git a/toolchain/build.mk b/toolchain/build.mk index 309b8e45..905a5db9 100644 --- a/toolchain/build.mk +++ b/toolchain/build.mk @@ -10,3 +10,4 @@ export PATH := $(PREFIX)/bin:$(PREFIX)/usr/bin:$(PATH) include $(TOOLCHAIN_DIR)/binutils/build.mk include $(TOOLCHAIN_DIR)/gcc/build.mk +include $(TOOLCHAIN_DIR)/newlib/build.mk diff --git a/toolchain/newlib/.gitignore b/toolchain/newlib/.gitignore new file mode 100644 index 00000000..3a7f5789 --- /dev/null +++ b/toolchain/newlib/.gitignore @@ -0,0 +1 @@ +newlib-*/ diff --git a/toolchain/newlib/build.mk b/toolchain/newlib/build.mk new file mode 100644 index 00000000..6e7828b1 --- /dev/null +++ b/toolchain/newlib/build.mk @@ -0,0 +1,42 @@ +TOOLCHAIN_NEWLIB_DIR := $(TOOLCHAIN_DIR)/newlib + +NEWLIB_VERSION := 4.5.0.20241231 +NEWLIB_TAR_URL := ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz +NEWLIB_DIR := $(TOOLCHAIN_NEWLIB_DIR)/newlib-$(NEWLIB_VERSION) +NEWLIB_TAR := $(NEWLIB_DIR).tar.gz +NEWLIB_BUILD_DIR := $(BUILD_DIR)/newlib-$(NEWLIB_VERSION) + +newlib/tar: $(NEWLIB_TAR) +$(NEWLIB_TAR): + $(call COMPILE,WGET,$@) + $(SILENT)$(WGET) $(NEWLIB_TAR_URL) -O $@ + +newlib/prepare: $(NEWLIB_DIR) +$(NEWLIB_DIR): $(NEWLIB_TAR) + $(call COMPILE,EXTRACT,$@) + $(SILENT)tar xf $(NEWLIB_TAR) -C $(dir $@) + $(call LOG,PATCH,$@) + $(SILENT)cp -rf $(TOOLCHAIN_NEWLIB_DIR)/port/* $@ + $(call LOG,RECONF,$@) + $(SILENT)cd $@/newlib && autoreconf -vfi $(SILENT_OUTPUT) + $(SILENT)cp -rf $(TOOLCHAIN_NEWLIB_DIR)/port/* $@ + +newlib/configure: $(NEWLIB_BUILD_DIR)/config.status +$(NEWLIB_BUILD_DIR)/config.status: $(NEWLIB_DIR) + $(call COMPILE,CONFIGURE,$@) + $(SILENT)\ + cd $(dir $@) && \ + $(PWD)/$(NEWLIB_DIR)/configure \ + --target="$(TARGET)" \ + --prefix="$(PREFIX)" \ + $(NEWLIB_CONFIGURE_FLAGS) \ + > configure.log \ + 2> configure.err + +libc: newlib +newlib: newlib/configure + $(call LOG,MAKE,newlib) + $(call MAKE_RECURSIVE,$(NEWLIB_BUILD_DIR),all CFLAGS='$(ASFLAGS)',newlib/) + $(call MAKE_RECURSIVE,$(NEWLIB_BUILD_DIR),install,newlib/) + +.PHONY: libc newlib newlib/configure newlib/prepare newlib/tar diff --git a/toolchain/newlib/port/config.sub b/toolchain/newlib/port/config.sub new file mode 100755 index 00000000..a8b19e4a --- /dev/null +++ b/toolchain/newlib/port/config.sub @@ -0,0 +1,2359 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright 1992-2024 Free Software Foundation, Inc. + +# shellcheck disable=SC2006,SC2268,SC2162 # see below for rationale + +timestamp='2024-05-27' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that +# program. This Exception is an additional permission under section 7 +# of the GNU General Public License, version 3 ("GPLv3"). + + +# Please send patches to . +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# You can get the latest version of this script from: +# https://git.savannah.gnu.org/cgit/config.git/plain/config.sub + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +# The "shellcheck disable" line above the timestamp inhibits complaints +# about features and limitations of the classic Bourne shell that were +# superseded or lifted in POSIX. However, this script identifies a wide +# variety of pre-POSIX systems that do not have POSIX shells at all, and +# even some reasonably current systems (Solaris 10 as case-in-point) still +# have a pre-POSIX /bin/sh. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS + +Canonicalize a configuration name. + +Options: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright 1992-2024 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try '$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo "$1" + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Split fields of configuration type +saved_IFS=$IFS +IFS="-" read field1 field2 field3 field4 <&2 + exit 1 + ;; + *-*-*-*) + basic_machine=$field1-$field2 + basic_os=$field3-$field4 + ;; + *-*-*) + # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two + # parts + maybe_os=$field2-$field3 + case $maybe_os in + cloudabi*-eabi* \ + | kfreebsd*-gnu* \ + | knetbsd*-gnu* \ + | kopensolaris*-gnu* \ + | linux-* \ + | managarm-* \ + | netbsd*-eabi* \ + | netbsd*-gnu* \ + | nto-qnx* \ + | os2-emx* \ + | rtmk-nova* \ + | storm-chaos* \ + | uclinux-gnu* \ + | uclinux-uclibc* \ + | windows-* ) + basic_machine=$field1 + basic_os=$maybe_os + ;; + android-linux) + basic_machine=$field1-unknown + basic_os=linux-android + ;; + *) + basic_machine=$field1-$field2 + basic_os=$field3 + ;; + esac + ;; + *-*) + case $field1-$field2 in + # Shorthands that happen to contain a single dash + convex-c[12] | convex-c3[248]) + basic_machine=$field2-convex + basic_os= + ;; + decstation-3100) + basic_machine=mips-dec + basic_os= + ;; + *-*) + # Second component is usually, but not always the OS + case $field2 in + # Do not treat sunos as a manufacturer + sun*os*) + basic_machine=$field1 + basic_os=$field2 + ;; + # Manufacturers + 3100* \ + | 32* \ + | 3300* \ + | 3600* \ + | 7300* \ + | acorn \ + | altos* \ + | apollo \ + | apple \ + | atari \ + | att* \ + | axis \ + | be \ + | bull \ + | cbm \ + | ccur \ + | cisco \ + | commodore \ + | convergent* \ + | convex* \ + | cray \ + | crds \ + | dec* \ + | delta* \ + | dg \ + | digital \ + | dolphin \ + | encore* \ + | gould \ + | harris \ + | highlevel \ + | hitachi* \ + | hp \ + | ibm* \ + | intergraph \ + | isi* \ + | knuth \ + | masscomp \ + | microblaze* \ + | mips* \ + | motorola* \ + | ncr* \ + | news \ + | next \ + | ns \ + | oki \ + | omron* \ + | pc533* \ + | rebel \ + | rom68k \ + | rombug \ + | semi \ + | sequent* \ + | siemens \ + | sgi* \ + | siemens \ + | sim \ + | sni \ + | sony* \ + | stratus \ + | sun \ + | sun[234]* \ + | tektronix \ + | tti* \ + | ultra \ + | unicom* \ + | wec \ + | winbond \ + | wrs) + basic_machine=$field1-$field2 + basic_os= + ;; + zephyr*) + basic_machine=$field1-unknown + basic_os=$field2 + ;; + *) + basic_machine=$field1 + basic_os=$field2 + ;; + esac + ;; + esac + ;; + *) + # Convert single-component short-hands not valid as part of + # multi-component configurations. + case $field1 in + 386bsd) + basic_machine=i386-pc + basic_os=bsd + ;; + a29khif) + basic_machine=a29k-amd + basic_os=udi + ;; + adobe68k) + basic_machine=m68010-adobe + basic_os=scout + ;; + alliant) + basic_machine=fx80-alliant + basic_os= + ;; + altos | altos3068) + basic_machine=m68k-altos + basic_os= + ;; + am29k) + basic_machine=a29k-none + basic_os=bsd + ;; + amdahl) + basic_machine=580-amdahl + basic_os=sysv + ;; + amiga) + basic_machine=m68k-unknown + basic_os= + ;; + amigaos | amigados) + basic_machine=m68k-unknown + basic_os=amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + basic_os=sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + basic_os=sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + basic_os=bsd + ;; + aros) + basic_machine=i386-pc + basic_os=aros + ;; + aux) + basic_machine=m68k-apple + basic_os=aux + ;; + balance) + basic_machine=ns32k-sequent + basic_os=dynix + ;; + blackfin) + basic_machine=bfin-unknown + basic_os=linux + ;; + cegcc) + basic_machine=arm-unknown + basic_os=cegcc + ;; + cray) + basic_machine=j90-cray + basic_os=unicos + ;; + crds | unos) + basic_machine=m68k-crds + basic_os= + ;; + da30) + basic_machine=m68k-da30 + basic_os= + ;; + dailyrun) + basic_machine=i686-pc + basic_os=dailyrun + ;; + decstation | pmax | pmin | dec3100 | decstatn) + basic_machine=mips-dec + basic_os= + ;; + delta88) + basic_machine=m88k-motorola + basic_os=sysv3 + ;; + dicos) + basic_machine=i686-pc + basic_os=dicos + ;; + djgpp) + basic_machine=i586-pc + basic_os=msdosdjgpp + ;; + ebmon29k) + basic_machine=a29k-amd + basic_os=ebmon + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + basic_os=ose + ;; + gmicro) + basic_machine=tron-gmicro + basic_os=sysv + ;; + go32) + basic_machine=i386-pc + basic_os=go32 + ;; + h8300hms) + basic_machine=h8300-hitachi + basic_os=hms + ;; + h8300xray) + basic_machine=h8300-hitachi + basic_os=xray + ;; + h8500hms) + basic_machine=h8500-hitachi + basic_os=hms + ;; + harris) + basic_machine=m88k-harris + basic_os=sysv3 + ;; + hp300 | hp300hpux) + basic_machine=m68k-hp + basic_os=hpux + ;; + hp300bsd) + basic_machine=m68k-hp + basic_os=bsd + ;; + hppaosf) + basic_machine=hppa1.1-hp + basic_os=osf + ;; + hppro) + basic_machine=hppa1.1-hp + basic_os=proelf + ;; + i386mach) + basic_machine=i386-mach + basic_os=mach + ;; + isi68 | isi) + basic_machine=m68k-isi + basic_os=sysv + ;; + m68knommu) + basic_machine=m68k-unknown + basic_os=linux + ;; + magnum | m3230) + basic_machine=mips-mips + basic_os=sysv + ;; + merlin) + basic_machine=ns32k-utek + basic_os=sysv + ;; + mingw64) + basic_machine=x86_64-pc + basic_os=mingw64 + ;; + mingw32) + basic_machine=i686-pc + basic_os=mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + basic_os=mingw32ce + ;; + monitor) + basic_machine=m68k-rom68k + basic_os=coff + ;; + morphos) + basic_machine=powerpc-unknown + basic_os=morphos + ;; + moxiebox) + basic_machine=moxie-unknown + basic_os=moxiebox + ;; + msdos) + basic_machine=i386-pc + basic_os=msdos + ;; + msys) + basic_machine=i686-pc + basic_os=msys + ;; + mvs) + basic_machine=i370-ibm + basic_os=mvs + ;; + nacl) + basic_machine=le32-unknown + basic_os=nacl + ;; + ncr3000) + basic_machine=i486-ncr + basic_os=sysv4 + ;; + netbsd386) + basic_machine=i386-pc + basic_os=netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + basic_os=linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + basic_os=newsos + ;; + news1000) + basic_machine=m68030-sony + basic_os=newsos + ;; + necv70) + basic_machine=v70-nec + basic_os=sysv + ;; + nh3000) + basic_machine=m68k-harris + basic_os=cxux + ;; + nh[45]000) + basic_machine=m88k-harris + basic_os=cxux + ;; + nindy960) + basic_machine=i960-intel + basic_os=nindy + ;; + mon960) + basic_machine=i960-intel + basic_os=mon960 + ;; + nonstopux) + basic_machine=mips-compaq + basic_os=nonstopux + ;; + os400) + basic_machine=powerpc-ibm + basic_os=os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + basic_os=ose + ;; + os68k) + basic_machine=m68k-none + basic_os=os68k + ;; + paragon) + basic_machine=i860-intel + basic_os=osf + ;; + parisc) + basic_machine=hppa-unknown + basic_os=linux + ;; + psp) + basic_machine=mipsallegrexel-sony + basic_os=psp + ;; + pw32) + basic_machine=i586-unknown + basic_os=pw32 + ;; + rdos | rdos64) + basic_machine=x86_64-pc + basic_os=rdos + ;; + rdos32) + basic_machine=i386-pc + basic_os=rdos + ;; + rom68k) + basic_machine=m68k-rom68k + basic_os=coff + ;; + sa29200) + basic_machine=a29k-amd + basic_os=udi + ;; + sei) + basic_machine=mips-sei + basic_os=seiux + ;; + sequent) + basic_machine=i386-sequent + basic_os= + ;; + sps7) + basic_machine=m68k-bull + basic_os=sysv2 + ;; + st2000) + basic_machine=m68k-tandem + basic_os= + ;; + stratus) + basic_machine=i860-stratus + basic_os=sysv4 + ;; + sun2) + basic_machine=m68000-sun + basic_os= + ;; + sun2os3) + basic_machine=m68000-sun + basic_os=sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + basic_os=sunos4 + ;; + sun3) + basic_machine=m68k-sun + basic_os= + ;; + sun3os3) + basic_machine=m68k-sun + basic_os=sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + basic_os=sunos4 + ;; + sun4) + basic_machine=sparc-sun + basic_os= + ;; + sun4os3) + basic_machine=sparc-sun + basic_os=sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + basic_os=sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + basic_os=solaris2 + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + basic_os= + ;; + sv1) + basic_machine=sv1-cray + basic_os=unicos + ;; + symmetry) + basic_machine=i386-sequent + basic_os=dynix + ;; + t3e) + basic_machine=alphaev5-cray + basic_os=unicos + ;; + t90) + basic_machine=t90-cray + basic_os=unicos + ;; + toad1) + basic_machine=pdp10-xkl + basic_os=tops20 + ;; + tpf) + basic_machine=s390x-ibm + basic_os=tpf + ;; + udi29k) + basic_machine=a29k-amd + basic_os=udi + ;; + ultra3) + basic_machine=a29k-nyu + basic_os=sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + basic_os=none + ;; + vaxv) + basic_machine=vax-dec + basic_os=sysv + ;; + vms) + basic_machine=vax-dec + basic_os=vms + ;; + vsta) + basic_machine=i386-pc + basic_os=vsta + ;; + vxworks960) + basic_machine=i960-wrs + basic_os=vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + basic_os=vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + basic_os=vxworks + ;; + xbox) + basic_machine=i686-pc + basic_os=mingw32 + ;; + ymp) + basic_machine=ymp-cray + basic_os=unicos + ;; + *) + basic_machine=$1 + basic_os= + ;; + esac + ;; +esac + +# Decode 1-component or ad-hoc basic machines +case $basic_machine in + # Here we handle the default manufacturer of certain CPU types. It is in + # some cases the only manufacturer, in others, it is the most popular. + w89k) + cpu=hppa1.1 + vendor=winbond + ;; + op50n) + cpu=hppa1.1 + vendor=oki + ;; + op60c) + cpu=hppa1.1 + vendor=oki + ;; + ibm*) + cpu=i370 + vendor=ibm + ;; + orion105) + cpu=clipper + vendor=highlevel + ;; + mac | mpw | mac-mpw) + cpu=m68k + vendor=apple + ;; + pmac | pmac-mpw) + cpu=powerpc + vendor=apple + ;; + + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + cpu=m68000 + vendor=att + ;; + 3b*) + cpu=we32k + vendor=att + ;; + bluegene*) + cpu=powerpc + vendor=ibm + basic_os=cnk + ;; + decsystem10* | dec10*) + cpu=pdp10 + vendor=dec + basic_os=tops10 + ;; + decsystem20* | dec20*) + cpu=pdp10 + vendor=dec + basic_os=tops20 + ;; + delta | 3300 | delta-motorola | 3300-motorola | motorola-delta | motorola-3300) + cpu=m68k + vendor=motorola + ;; + # This used to be dpx2*, but that gets the RS6000-based + # DPX/20 and the x86-based DPX/2-100 wrong. See + # https://oldskool.silicium.org/stations/bull_dpx20.htm + # https://www.feb-patrimoine.com/english/bull_dpx2.htm + # https://www.feb-patrimoine.com/english/unix_and_bull.htm + dpx2 | dpx2[23]00 | dpx2[23]xx) + cpu=m68k + vendor=bull + ;; + dpx2100 | dpx21xx) + cpu=i386 + vendor=bull + ;; + dpx20) + cpu=rs6000 + vendor=bull + ;; + encore | umax | mmax) + cpu=ns32k + vendor=encore + ;; + elxsi) + cpu=elxsi + vendor=elxsi + basic_os=${basic_os:-bsd} + ;; + fx2800) + cpu=i860 + vendor=alliant + ;; + genix) + cpu=ns32k + vendor=ns + ;; + h3050r* | hiux*) + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + cpu=m68000 + vendor=hp + ;; + hp9k3[2-9][0-9]) + cpu=m68k + vendor=hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + cpu=hppa1.1 + vendor=hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + i*86v32) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv32 + ;; + i*86v4*) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv4 + ;; + i*86v) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv + ;; + i*86sol2) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=solaris2 + ;; + j90 | j90-cray) + cpu=j90 + vendor=cray + basic_os=${basic_os:-unicos} + ;; + iris | iris4d) + cpu=mips + vendor=sgi + case $basic_os in + irix*) + ;; + *) + basic_os=irix4 + ;; + esac + ;; + miniframe) + cpu=m68000 + vendor=convergent + ;; + *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) + cpu=m68k + vendor=atari + basic_os=mint + ;; + news-3600 | risc-news) + cpu=mips + vendor=sony + basic_os=newsos + ;; + next | m*-next) + cpu=m68k + vendor=next + ;; + np1) + cpu=np1 + vendor=gould + ;; + op50n-* | op60c-*) + cpu=hppa1.1 + vendor=oki + basic_os=proelf + ;; + pa-hitachi) + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 + ;; + pbd) + cpu=sparc + vendor=tti + ;; + pbb) + cpu=m68k + vendor=tti + ;; + pc532) + cpu=ns32k + vendor=pc532 + ;; + pn) + cpu=pn + vendor=gould + ;; + power) + cpu=power + vendor=ibm + ;; + ps2) + cpu=i386 + vendor=ibm + ;; + rm[46]00) + cpu=mips + vendor=siemens + ;; + rtpc | rtpc-*) + cpu=romp + vendor=ibm + ;; + sde) + cpu=mipsisa32 + vendor=sde + basic_os=${basic_os:-elf} + ;; + simso-wrs) + cpu=sparclite + vendor=wrs + basic_os=vxworks + ;; + tower | tower-32) + cpu=m68k + vendor=ncr + ;; + vpp*|vx|vx-*) + cpu=f301 + vendor=fujitsu + ;; + w65) + cpu=w65 + vendor=wdc + ;; + w89k-*) + cpu=hppa1.1 + vendor=winbond + basic_os=proelf + ;; + none) + cpu=none + vendor=none + ;; + leon|leon[3-9]) + cpu=sparc + vendor=$basic_machine + ;; + leon-*|leon[3-9]-*) + cpu=sparc + vendor=`echo "$basic_machine" | sed 's/-.*//'` + ;; + + *-*) + saved_IFS=$IFS + IFS="-" read cpu vendor <&2 + exit 1 + ;; + esac + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $vendor in + digital*) + vendor=dec + ;; + commodore*) + vendor=cbm + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if test x"$basic_os" != x +then + +# First recognize some ad-hoc cases, or perhaps split kernel-os, or else just +# set os. +obj= +case $basic_os in + gnu/linux*) + kernel=linux + os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'` + ;; + os2-emx) + kernel=os2 + os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'` + ;; + nto-qnx*) + kernel=nto + os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'` + ;; + *-*) + saved_IFS=$IFS + IFS="-" read kernel os <&2 + fi + ;; + *) + echo "Invalid configuration '$1': OS '$os' not recognized" 1>&2 + exit 1 + ;; +esac + +case $obj in + aout* | coff* | elf* | pe*) + ;; + '') + # empty is fine + ;; + *) + echo "Invalid configuration '$1': Machine code format '$obj' not recognized" 1>&2 + exit 1 + ;; +esac + +# Here we handle the constraint that a (synthetic) cpu and os are +# valid only in combination with each other and nowhere else. +case $cpu-$os in + # The "javascript-unknown-ghcjs" triple is used by GHC; we + # accept it here in order to tolerate that, but reject any + # variations. + javascript-ghcjs) + ;; + javascript-* | *-ghcjs) + echo "Invalid configuration '$1': cpu '$cpu' is not valid with os '$os$obj'" 1>&2 + exit 1 + ;; +esac + +# As a final step for OS-related things, validate the OS-kernel combination +# (given a valid OS), if there is a kernel. +case $kernel-$os-$obj in + linux-gnu*- | linux-android*- | linux-dietlibc*- | linux-llvm*- \ + | linux-mlibc*- | linux-musl*- | linux-newlib*- \ + | linux-relibc*- | linux-uclibc*- | linux-ohos*- ) + ;; + uclinux-uclibc*- | uclinux-gnu*- ) + ;; + managarm-mlibc*- | managarm-kernel*- ) + ;; + windows*-msvc*-) + ;; + -dietlibc*- | -llvm*- | -mlibc*- | -musl*- | -newlib*- | -relibc*- \ + | -uclibc*- ) + # These are just libc implementations, not actual OSes, and thus + # require a kernel. + echo "Invalid configuration '$1': libc '$os' needs explicit kernel." 1>&2 + exit 1 + ;; + -kernel*- ) + echo "Invalid configuration '$1': '$os' needs explicit kernel." 1>&2 + exit 1 + ;; + *-kernel*- ) + echo "Invalid configuration '$1': '$kernel' does not support '$os'." 1>&2 + exit 1 + ;; + *-msvc*- ) + echo "Invalid configuration '$1': '$os' needs 'windows'." 1>&2 + exit 1 + ;; + kfreebsd*-gnu*- | knetbsd*-gnu*- | netbsd*-gnu*- | kopensolaris*-gnu*-) + ;; + vxworks-simlinux- | vxworks-simwindows- | vxworks-spe-) + ;; + nto-qnx*-) + ;; + os2-emx-) + ;; + rtmk-nova-) + ;; + *-eabi*- | *-gnueabi*-) + ;; + none--*) + # None (no kernel, i.e. freestanding / bare metal), + # can be paired with an machine code file format + ;; + -*-) + # Blank kernel with real OS is always fine. + ;; + --*) + # Blank kernel and OS with real machine code file format is always fine. + ;; + *-*-*) + echo "Invalid configuration '$1': Kernel '$kernel' not known to work with OS '$os'." 1>&2 + exit 1 + ;; +esac + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +case $vendor in + unknown) + case $cpu-$os in + *-riscix*) + vendor=acorn + ;; + *-sunos* | *-solaris*) + vendor=sun + ;; + *-cnk* | *-aix*) + vendor=ibm + ;; + *-beos*) + vendor=be + ;; + *-hpux*) + vendor=hp + ;; + *-mpeix*) + vendor=hp + ;; + *-hiux*) + vendor=hitachi + ;; + *-unos*) + vendor=crds + ;; + *-dgux*) + vendor=dg + ;; + *-luna*) + vendor=omron + ;; + *-genix*) + vendor=ns + ;; + *-clix*) + vendor=intergraph + ;; + *-mvs* | *-opened*) + vendor=ibm + ;; + *-os400*) + vendor=ibm + ;; + s390-* | s390x-*) + vendor=ibm + ;; + *-ptx*) + vendor=sequent + ;; + *-tpf*) + vendor=ibm + ;; + *-vxsim* | *-vxworks* | *-windiss*) + vendor=wrs + ;; + *-aux*) + vendor=apple + ;; + *-hms*) + vendor=hitachi + ;; + *-mpw* | *-macos*) + vendor=apple + ;; + *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) + vendor=atari + ;; + *-vos*) + vendor=stratus + ;; + esac + ;; +esac + +echo "$cpu-$vendor${kernel:+-$kernel}${os:+-$os}${obj:+-$obj}" +exit + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/toolchain/newlib/port/newlib/configure.host b/toolchain/newlib/port/newlib/configure.host new file mode 100644 index 00000000..dceb3d6f --- /dev/null +++ b/toolchain/newlib/port/newlib/configure.host @@ -0,0 +1,973 @@ +# configure.host + +# This shell script handles all host based configuration for newlib. +# It sets various shell variables based on the the host and the +# configuration options. You can modify this shell script without +# needing to rerun autoconf. + +# This shell script should be invoked as +# . configure.host +# If it encounters an error, it will exit with a message. + +# FIXME: This script is too complicated. It does things in too many +# different ways. This was taken from the old Cygnus configure script +# with only minor changes. It should be cleaned up. + +# FIXME: The general approach of picking and choosing which +# directories to configure, other than machine_dir and sys_dir, is +# potentially confusing. + +# It uses the following shell variables: +# host The configuration host +# host_cpu The configuration host CPU +# newlib_mb --enable-newlib-mb ("yes", "no") +# target_optspace --enable-target-optspace ("yes", "no", "") +# newlib_multithread --enable-newlib-multithread ("yes", "no", "yes") +# newlib_elix_level --enable-newlib-elix-level ("1","2","3","4") ("4") +# newlib_io_c99_formats --enable-newlib-io-c99-formats ("yes", "no", "") +# newlib_io_long_long --enable-newlib-io-long-long ("yes", "no", "") +# newlib_io_long_double --enable-newlib-io-long-double ("yes", "no", "") +# newlib_global_stdio_streams --enable-global-stdio-streams ("yes", "no, "") +# newlib_fno_builtin --disable-newlib-fno-builtin ("yes", "no, "") +# newlib_reent_check_verify --enable-newlib-reent-check-verify ("yes", "no, "") + +# It sets the following shell variables: +# newlib_cflags Special CFLAGS to use when building +# machine_dir Subdirectory of libc/machine to configure +# shared_machine_dir Subdirectory of libc/machine for files shared +# between specific architectures, optional +# sys_dir Subdirectory of libc/sys to configure +# have_sys_mach_dir Is there a machine subdirectory in sys subdirectory +# posix_dir "posix" to build libc/posix, "" otherwise +# signal_dir "signal" to build libc/signal, "" otherwise +# stdio64_dir "stdio64" to build libc/stdio64, "" otherwise +# syscall_dir "syscalls" to build libc/syscalls, "" otherwise +# unix_dir "unix" to build libc/unix, "" otherwise +# lpfx library object prefix - generated when no libtool +# crt1 name of crt1 object if one is provided +# crt1_dir directory where crt1 object is found +# have_crt0 "yes"/"no" if crt0 is/isn't provided. +# "" if crt0 is provided when sys_dir is set +# have_init_fini have init/fini ("yes" or "no", set to "yes" by default) +# noinclude list of include files to not install + +newlib_cflags="-D_LIBC" +libm_machine_dir= +machine_dir= +shared_machine_dir= +sys_dir= +posix_dir= +signal_dir=signal +stdio_dir=stdio +stdio64_dir= +xdr_dir= +syscall_dir= +unix_dir= +noinclude= +mach_add_setjmp= +crt1= +crt1_dir= +have_crt0= +have_init_fini=yes +default_newlib_io_c99_formats=no +default_newlib_io_long_long=no +default_newlib_io_long_double=no +default_newlib_io_pos_args=no +default_newlib_atexit_dynamic_alloc=yes +default_newlib_nano_malloc=no +default_newlib_reent_check_verify=yes +lpfx="lib_a-" +newlib_msg_warn= + +case "${target_optspace}:${host}" in + yes:*) + newlib_cflags="${newlib_cflags} -Os" + ;; + :m32r-* | :d10v-* | :d30v-* | :avr-* | :m32c-* | :msp430*-* | :nds32* | :pru-* | :rl78-* ) + newlib_cflags="${newlib_cflags} -Os" + ;; + no:* | :*) + ;; +esac + +case "${newlib_fno_builtin}:${host}" in + yes:*) + newlib_cflags="${newlib_cflags} -fno-builtin" + ;; + no:*) + newlib_cflags="${newlib_cflags}" + ;; + *:*) + # For now, all targets default to using -fno-builtin until tested without + newlib_cflags="${newlib_cflags} -fno-builtin" + ;; +esac + +# Get the source directories to use for the CPU type. +# machine_dir should supply CPU dependent routines, such as setjmp. +# newlib_cflags is passed to gcc when compiling. +# THIS TABLE IS ALPHA SORTED. KEEP IT THAT WAY. + +case "${host_cpu}" in + a29k) + machine_dir=a29k + ;; + aarch64*) + machine_dir=aarch64 + libm_machine_dir=aarch64 + ;; + amdgcn*) + newlib_cflags="${newlib_cflags} -D__DYNAMIC_REENT__" + machine_dir=amdgcn + libm_machine_dir=amdgcn + newlib_cv_initfinit_array=yes + ;; + arc | arceb) + machine_dir=arc + ;; + arc64 | arc32) + machine_dir=arc64 + ;; + arm*) + machine_dir=arm + libm_machine_dir=arm + ;; + avr*) + newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -mcall-prologues" + ;; + bfin) + machine_dir=bfin + ;; + cr16*) + machine_dir=cr16 + ;; + cris | crisv32) + # The size of the (kernel_)time_t passed from or to a + # simulator or a Linux kernel is mandated by the + # gettimeofday and time system calls and fixed to 32 bits, the + # size of a long. Instead of churning as 64 bits what is anyway + # 32 bits, it makes more sense to default to long. + test -z "${enable_newlib_long_time_t}" && newlib_long_time_t=yes + machine_dir=cris + ;; + crx*) + machine_dir=crx + ;; + csky*) + machine_dir=csky + default_newlib_atexit_dynamic_alloc="no" + ;; + d10v*) + machine_dir=d10v + ;; + d30v*) + machine_dir=d30v + ;; + epiphany) + machine_dir=epiphany + ;; + fido) + machine_dir=m68k + newlib_cflags="${newlib_cflags} -DCOMPACT_CTYPE" + ;; + fr30) + machine_dir=fr30 + ;; + frv) + machine_dir=frv + ;; + ft32*) + machine_dir=ft32 + newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED" + ;; + h8300) + machine_dir=h8300 + ;; + h8500) + machine_dir=h8500 + ;; + hppa*) + machine_dir=hppa + ;; + i960) + machine_dir=i960 + ;; + i[34567]86) + libm_machine_dir=i386 + machine_dir=i386 + shared_machine_dir=shared_x86 + # Don't use for these since they provide their own setjmp. + case ${host} in + *-*-sco* | *-*-cygwin*) + ;; + *) + mach_add_setjmp=true + ;; + esac + ;; + ia64*) + ;; + iq2000) + machine_dir=iq2000 + ;; + lm32) + machine_dir=lm32 + ;; + m32c) + machine_dir=m32c + newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY" + ;; + + m32r*) + machine_dir=m32r + ;; + + m68hc11|m6811|m68hc12|m6812) + machine_dir=m68hc11 + newlib_cflags="-DPREFER_SIZE_OVER_SPEED -Os -mrelax" + CFLAGS="-g -Os" + ;; + + m68*) + machine_dir=m68k + newlib_cflags="${newlib_cflags} -DCOMPACT_CTYPE" + ;; + m88k) + machine_dir=m88k + newlib_cflags="${newlib_cflags} -m88000" + ;; + m88110) + machine_dir=m88k + newlib_cflags="${newlib_cflags} -m88110" + ;; + mcore) + ;; + microblaze*) + machine_dir=microblaze + ;; + mep) + machine_dir=mep + ;; + mips*) + machine_dir=mips + libm_machine_dir=mips + ;; + mmix) + ;; + mn10200) + machine_dir=mn10200 + ;; + mn10300) + default_newlib_io_long_long="yes" + machine_dir=mn10300 + ;; + moxie) + machine_dir=moxie + ;; + msp430*) + newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY" + newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections " + newlib_cflags="${newlib_cflags} -mOs " + newlib_cflags="${newlib_cflags} -mhwmult=none " + machine_dir=msp430 + default_newlib_nano_malloc="yes" + ;; + mt*) + machine_dir=mt + ;; + nds32*) + machine_dir=nds32 + libm_machine_dir=nds32 + newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections" + newlib_cflags="${newlib_cflags} -DHAVE_RENAME" + ;; + nios2*) + machine_dir=nios2 + ;; + nvptx*) + machine_dir=nvptx + newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DMALLOC_PROVIDED" + ;; + or1k*|or1knd*) + machine_dir=or1k + have_init_fini=no + ;; + powerpc*) + machine_dir=powerpc + libm_machine_dir=powerpc + ;; + pru*) + newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED" + newlib_cflags="${newlib_cflags} -DNO_EXEC" + newlib_cflags="${newlib_cflags} -DSMALL_MEMORY" + newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections " + default_newlib_nano_malloc="yes" + default_newlib_atexit_dynamic_alloc="no" + machine_dir=pru + libm_machine_dir=pru + ;; + riscv*) + libm_machine_dir=riscv + machine_dir=riscv + newlib_cflags="${newlib_cflags} -DHAVE_NANOSLEEP" + default_newlib_atexit_dynamic_alloc="no" + have_init_fini=no + ;; + rl78) + machine_dir=rl78 + newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY" + newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections " + ;; + rx) + machine_dir=rx + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections " + ;; + sh | sh64) + machine_dir=sh + ;; + sparc*) + libm_machine_dir=sparc + machine_dir=sparc + # FIXME: Might wish to make MALLOC_ALIGNMENT more generic. + newlib_cflags="${newlib_cflags} -DMALLOC_ALIGNMENT=8" + ;; + tic4x|c4x) + machine_dir=tic4x + ;; + tic6x) + machine_dir=tic6x + ;; + tic80*) + machine_dir=tic80 + ;; + v70) + ;; + v810) + ;; + v850*) + machine_dir=v850 + newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED " + ;; + visium) + machine_dir=visium + ;; + w65*) + machine_dir=w65 + ;; + x86_64) + machine_dir=x86_64 + libm_machine_dir=x86_64 + shared_machine_dir=shared_x86 + ;; + xc16x*) + machine_dir=xc16x + ;; + xstormy16) + machine_dir=xstormy16 + newlib_cflags="${newlib_cflags} -DMALLOC_PROVIDED" + newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED" + ;; + xtensa) + libm_machine_dir=xtensa + machine_dir=xtensa + newlib_cflags="${newlib_cflags} -mlongcalls" + default_newlib_atexit_dynamic_alloc="no" + have_init_fini=no + ;; + z8k) + machine_dir=z8k + ;; + spu) + stdio_dir= + libm_machine_dir=spu + machine_dir=spu + newlib_cflags="${newlib_cflags} -D_POSIX_MODE" + newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED" + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections " + ;; + *) + echo '***' "Newlib does not support CPU ${host_cpu}" 1>&2 + exit 1 + ;; +esac + +# Disable thread support if requested. + +if [ "${newlib_multithread}" = "no" ] ; then + newlib_cflags="${newlib_cflags} -D__SINGLE_THREAD__" +fi + +# Disable syscall support if requested. + +if [ "${newlib_may_supply_syscalls}" = "no" ] ; then + newlib_cflags="${newlib_cflags} -D__NO_SYSCALLS__" +fi + +# Enable multibyte support if requested or it is defaulted +# for target. + +if [ "x${newlib_mb}" = "x" ]; then + case "${host}" in + *-*-cygwin*) + newlib_mb=yes + ;; + esac +fi + +# Disable printf/scanf floating-point support if requested. + +if [ "${newlib_io_float}" = "no" ] ; then + newlib_cflags="${newlib_cflags} -DNO_FLOATING_POINT" +fi + +# Get the source directories to use for the host. unix_dir is set +# to unix to get some standard Unix routines. posix_dir is set to get some +# standard Posix routines. sys_dir should supply system dependent routines +# including crt0. +# THIS TABLE IS ALPHA SORTED. KEEP IT THAT WAY. + +case "${host}" in + *-*-cygwin*) + posix_dir=posix + xdr_dir=xdr + ;; + *-*-dailyrun*) + sys_dir=dailyrun + ;; + *-*-netware*) + signal_dir= + sys_dir=netware + ;; + *-*-rtems*) # generic RTEMS support + sys_dir=rtems + posix_dir=posix + unix_dir=unix + ;; + *-*-tirtos*) + sys_dir=tirtos + have_crt0="no" + ;; + *-esp-*) + sys_dir=esp + have_crt0="no" + posix_dir=posix + newlib_cflags="${newlib_cflags} -D_NO_GLOB -D_NO_EXECVE -D_NO_GETLOGIN -D_NO_GETPWENT -D_NO_GETUT" + newlib_cflags="${newlib_cflags} -D_NO_GETPASS -D_NO_SIGSET -D_NO_WORDEXP -D_NO_POPEN -D_NO_POSIX_SPAWN" + newlib_cflags="${newlib_cflags} -DHAVE_FCNTL -DHAVE_BLKSIZE -DHAVE_OPENDIR -DHAVE_RENAME" + newlib_cflags="${newlib_cflags} -DGETREENT_PROVIDED -DSIGNAL_PROVIDED" + ;; + a29k-*-*) + sys_dir=a29khif + signal_dir= + ;; + amdgcn*) + sys_dir=amdgcn + have_crt0="no" + ;; + arm*-*-*) + sys_dir=arm + if [ "x${newlib_may_supply_syscalls}" = "xno" ] ; then + have_crt0="no" + fi + ;; + bfin-*-*) + sys_dir= + ;; + cr16-*-*) + sys_dir= + ;; + crx*) + sys_dir= + ;; + d10v*) + sys_dir=d10v + ;; + d30v*) + sys_dir= + ;; + epiphany-*-*) + sys_dir=epiphany + # crt0 is provided by libgloss. + have_crt0="no" + ;; + frv*) + sys_dir= + ;; + ft32*) + sys_dir= + ;; + h8300-*-hms*) + sys_dir=h8300hms + ;; + h8300-*-elf*) + sys_dir=h8300hms + ;; + h8300-*-coff*) + sys_dir=h8300hms + ;; + h8300-*-xray*) + sys_dir=h8300xray + ;; + h8500-*-hms*) + sys_dir=h8500hms + ;; + h8500-*-elf*) + sys_dir=h8500hms + ;; + i[34567]86-*-rdos*) + sys_dir=rdos + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + newlib_cflags="${newlib_cflags} -D_I386MACH_DISABLE_HW_INTERRUPTS" + ;; + i[34567]86-*-sco*) + sys_dir=sysvi386 + unix_dir=unix + ;; + + m68hc11-*-*|m6811-*-*|m6812-*-*|m68hc12-*-*) + ;; + + m68k-sun-sunos*) + unix_dir=unix + ;; + m8*-bug-*) + sys_dir=m88kbug + ;; + mep-*-*) + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + ;; + microblaze*-*-*) + machine_dir=microblaze + ;; + mmix-knuth-mmixware) + sys_dir=mmixware + ;; + moxie*) + sys_dir= + ;; + nios2*) + sys_dir= + ;; + or1k-*-elf | or1knd-*-elf) + sys_dir=or1k + newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED " + have_crt0="no" + ;; + powerpcle-*-pe) + posix_dir=posix + ;; + sh*-*) + sys_dir=sh + ;; + spu-*-*) + default_newlib_io_long_long="yes" + default_newlib_atexit_dynamic_alloc="no" + ;; + tic6x*) + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + have_crt0="no" + ;; + tic80*) + sys_dir=tic80 + ;; + v70-nec-*) + sys_dir=sysvnecv70 + ;; + v810-*-*) + sys_dir=sysnec810 + ;; + v850*-*-*) + sys_dir=sysnecv850 + if [ "x${newlib_may_supply_syscalls}" = "xno" ] ; then + have_crt0="no" + fi + ;; + visium-*-*) + sys_dir= + ;; + w65-*-*) + sys_dir=w65 + ;; + z8k-*-coff) + sys_dir=z8ksim + ;; +esac + +# Host specific flag settings -- usually for features that are not +# general enough or broad enough to be handled above. +# THIS TABLE IS ALPHA SORTED. KEEP IT THAT WAY. + +case "${host}" in + *-*-cygwin*) + test -z "$cygwin_srcdir" && cygwin_srcdir="${abs_newlib_basedir}/../winsup/cygwin" + export cygwin_srcdir + default_newlib_io_c99_formats="yes" + default_newlib_io_long_long="yes" + default_newlib_io_long_double="yes" + default_newlib_io_pos_args="yes" + CC="${CC} -I${cygwin_srcdir}/include" + newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DGETREENT_PROVIDED -DSIGNAL_PROVIDED -DHAVE_BLKSIZE -DHAVE_FCNTL -DMALLOC_PROVIDED -DHAVE_CHDIR -DHAVE_FCHDIR" + syscall_dir=syscalls + ;; + *-*-dailyrun*) + syscall_dir=syscalls + ;; +# RTEMS supplies its own versions of some routines: +# malloc() (reentrant version) +# exit() RTEMS has a "global" reent to flush +# signal()/raise() RTEMS has its own including pthread signals +# _XYZ_r() RTEMS has its own reentrant routines +# +# NOTE: When newlib malloc uses a semaphore, RTEMS will switch to that. + *-*-rtems*) + default_newlib_io_long_long="yes" + default_newlib_io_c99_formats="yes" + newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections " +newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DMALLOC_PROVIDED -DEXIT_PROVIDED -DSIGNAL_PROVIDED -DGETREENT_PROVIDED -DREENTRANT_SYSCALLS_PROVIDED -DHAVE_NANOSLEEP -DHAVE_BLKSIZE -DHAVE_FCNTL -DHAVE_ASSERT_FUNC" + # turn off unsupported items in posix directory + newlib_cflags="${newlib_cflags} -D_NO_GETLOGIN -D_NO_GETPWENT -D_NO_GETUT -D_NO_GETPASS -D_NO_SIGSET -D_NO_WORDEXP -D_NO_POPEN -D_NO_POSIX_SPAWN" + ;; +# VxWorks supplies its own version of malloc, and the newlib one +# doesn't work because VxWorks does not have sbrk. + *-wrs-vxworks*) + newlib_cflags="${newlib_cflags} -DMALLOC_PROVIDED -DMISSING_SYSCALL_NAMES -DHAVE_FCNTL" + ;; +# TIRTOS supplies its own version of malloc + *-*-tirtos*) + newlib_cflags="${newlib_cflags} -D__DYNAMIC_REENT__ -DMALLOC_PROVIDED" + ;; +# UDI doesn't have exec, so system() should fail the right way + a29k-amd-udi) + newlib_cflags="${newlib_cflags} -DNO_EXEC" + syscall_dir=syscalls + ;; + aarch64*-*-*) + default_newlib_io_long_long="yes" + syscall_dir=syscalls + ;; + arc*-*-*) + syscall_dir=syscalls + default_newlib_io_long_long="yes" + ;; + arm*-*-pe) + syscall_dir=syscalls + newlib_cflags="${newlib_cflags} -DHAVE_SYSCONF_PAGESIZE" + ;; + arm*-*-*) + syscall_dir=syscalls +# If newlib is supplying syscalls, select which debug protocol is being used. +# ARM_RDP_MONITOR selects the Demon monitor. +# ARM_RDI_MONITOR selects the Angel monitor. +# If neither are defined, then hard coded defaults will be used +# to create the program's environment. +# If --disable-newlib-supplied-syscalls is specified, then the end-user +# may specify the protocol via gcc spec files supplied by libgloss. + if [ "x${newlib_may_supply_syscalls}" = "xyes" ] ; then +# newlib_cflags="${newlib_cflags} -DARM_RDP_MONITOR" + newlib_cflags="${newlib_cflags} -DARM_RDI_MONITOR" + fi + newlib_cflags="${newlib_cflags} -DHAVE_SYSCONF_PAGESIZE" + ;; + avr*) + newlib_cflags="${newlib_cflags} -DNO_EXEC -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES" + ;; + bfin*) + syscall_dir=syscalls + ;; + cris-*-* | crisv32-*-*) + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -DHAVE_RENAME -D_USE_WRITE -DCOMPACT_CTYPE" + syscall_dir=syscalls + ;; + cr16-*-*) + syscall_dir=syscalls + ;; + crx-*-*) + newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DMISSING_SYSCALL_NAMES" + syscall_dir= + ;; + csky*) + newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES" + syscall_dir= + ;; + d10v*) + newlib_cflags="${newlib_cflags} -DSMALL_MEMORY" + syscall_dir=syscalls + ;; + d30v*) + newlib_cflags="${newlib_cflags} -DABORT_MESSAGE -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES" + syscall_dir= + ;; + epiphany*) + syscall_dir=syscalls + newlib_cflags="${newlib_cflags} -DSIGNAL_PROVIDED" + ;; + fido-*-elf) + newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES" + syscall_dir= + ;; + fr30-*-*) + syscall_dir=syscalls + ;; + frv-*-*) + syscall_dir=syscalls + default_newlib_io_long_long="yes" + ;; + ft32*-*-*) + syscall_dir=syscalls + ;; + h8300*-*-*) + syscall_dir=syscalls + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -DSMALL_DTOA -DSMALL_MEMORY" + # Simulator only extensions for H8300. + # Uncomment the next line to enable them. + # newlib_cflags="${newlib_cflags} -D__SIMULATOR__" + ;; + h8500-*-*) + syscall_dir=syscalls + newlib_cflags="${newlib_cflags} -DSMALL_DTOA -DSMALL_MEMORY" + ;; + i[34567]86-*-sco*) + newlib_cflags="${newlib_cflags} -DSIGNAL_PROVIDED -DHAVE_FCNTL" + ;; + i[34567]86-*-netware*) + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DNO_EXEC -DABORT_PROVIDED -DCLOCK_PROVIDED -DMALLOC_PROVIDED -DHAVE_FCNTL" + ;; + i[3-7]86-*-elfiamcu) + newlib_cflags="${newlib_cflags} -Os -DPREFER_SIZE_OVER_SPEED -ffunction-sections -fomit-frame-pointer -DREENTRANT_SYSCALL_PROVIDED" + if [ "${newlib_multithread}" = "no" ] ; then + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + else + syscall_dir=syscalls + newlib_cflags="${newlib_cflags} -D__DYNAMIC_REENT__" + fi + ;; + iq2000*) + syscall_dir=syscalls + default_newlib_io_long_long="yes" + ;; + lm32-*-*) + syscall_dir=syscalls + ;; + m32c-*-*) + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DABORT_PROVIDED" + syscall_dir= + ;; + m32r-*-*) + # Pass -msdata=sdata so _impure_ptr goes in .sdata. + # We don't generate sda relocs however for upward compatibility. + # FIXME: This is necessary because the default multilib doesn't + # use --print-multi-lib. + newlib_cflags="${newlib_cflags} -msdata=sdata" + syscall_dir=syscalls + ;; + m68hc11-*-*|m6811-*-*|m68hc12-*-*|m6812-*-*) + newlib_cflags="${newlib_cflags} -DNO_EXEC -DABORT_PROVIDED -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES" + ;; + m68k-unknown-elf) + newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES" + syscall_dir= + ;; + mcore-*-*) + syscall_dir=syscalls + ;; + microblaze*-*-*) + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DSMALL_MEMORY -D_REENT_SMALL" + ;; + mips64vr*-*-*) + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + ;; + mips*-*-elf*) + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + ;; + mmix-*) + syscall_dir=syscalls + # We need every symbol 32-bit aligned, so the invalid + # construct with attribute ((alias ("_ctype_b+127"))) breaks. + newlib_cflags="${newlib_cflags} -DCOMPACT_CTYPE" + ;; + mn10?00-*-*) + syscall_dir=syscalls + ;; + moxie-*-elf* | moxie-*-rtems*) + syscall_dir=syscalls + default_newlib_io_long_long="yes" + ;; + moxie-*-moxiebox) + syscall_dir=syscalls + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -Os -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY" + ;; + nios2*) + syscall_dir= + newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES" + ;; + nds32*) + syscall_dir=syscalls + ;; + or1k*|or1knd*) + syscall_dir=syscalls + ;; + powerpc*-*-eabialtivec*) + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + ;; + powerpc*-*-eabispe*) + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + ;; + powerpc*-*-eabi* | \ + powerpc*-*-elf* | \ + powerpc*-*-linux* | \ + powerpc*-*-rtem* | \ + powerpc*-*-sysv* | \ + powerpc*-*-solaris*) + default_newlib_io_long_long="yes" + newlib_cflags="${newlib_cflags} -mrelocatable-lib -mno-eabi -mstrict-align -DMISSING_SYSCALL_NAMES" + ;; + powerpcle-*-pe) + newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DHAVE_FCNTL -D_NO_POSIX_SPAWN" + syscall_dir=syscalls + ;; + pru*) + syscall_dir=syscalls + newlib_cflags="${newlib_cflags} -DSMALL_MEMORY -D_REENT_SMALL" + ;; + riscv*-*-*) + syscall_dir=syscalls + ;; + sh*-*-*) + default_newlib_io_long_long="yes" + syscall_dir=syscalls + ;; + sparc-sun-sunos*) + newlib_cflags="${newlib_cflags} -DSIGNAL_PROVIDED" + ;; + sparc64-*-*) + newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED -DHAVE_BLKSIZE -DHAVE_FCNTL" + # This either belongs elsewhere or nowhere. But I need *something*, + # so for now it's here ... + case "${host_os}" in + aoutv8 | *32p) + newlib_cflags="${newlib_cflags} -DTARGET_PTR_SIZE=32" ;; + *) + newlib_cflags="${newlib_cflags} -DTARGET_PTR_SIZE=64" ;; + esac + ;; + tic6x*) + syscall_dir= + newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED" + ;; + tic80*) + syscall_dir=syscalls + ;; + v850*-*-*) + syscall_dir=syscalls + ;; + visium-*-*) + newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES" + syscall_dir= + ;; + w65-*-*) + syscall_dir=syscalls + newlib_cflags="${newlib_cflags} -DSMALL_DTOA -DSMALL_MEMORY" + ;; + xc16x-*) + syscall_dir=syscalls + ;; + xstormy16-*-*) + syscall_dir=syscalls + ;; + xtensa*-*-* | xtensa*-*) + syscall_dir=syscalls + ;; + z8k-*-*) + syscall_dir=syscalls + ;; + *) + newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES" + syscall_dir= + ;; +esac + +# Use defaults for certain settings if not specified by user + +# Enable C99 format support in I/O routines if requested. +if [ "x${newlib_io_c99_formats}" = "x" ]; then + if [ ${default_newlib_io_c99_formats} = "yes" ]; then + newlib_io_c99_formats="yes"; + fi +fi + +# Enable long long support in I/O routines if requested. +if [ "x${newlib_io_long_long}" = "x" ]; then + if [ ${default_newlib_io_long_long} = "yes" ]; then + newlib_io_long_long="yes"; + fi +fi + +# Enable long double support in I/O routines if requested. +if [ "x${newlib_io_long_double}" = "x" ]; then + if [ ${default_newlib_io_long_double} = "yes" ]; then + newlib_io_long_double="yes"; + fi +fi + +# Enable printf positional argument support if requested. +if [ "x${newlib_io_pos_args}" = "x" ]; then + if [ ${default_newlib_io_pos_args} = "yes" ]; then + newlib_io_pos_args="yes"; + fi +fi + +# Disable atexit dynamic allocation if requested. +if [ "x${newlib_atexit_dynamic_alloc}" = "x" ]; then + if [ ${default_newlib_atexit_dynamic_alloc} = "yes" ]; then + newlib_atexit_dynamic_alloc="yes"; + fi +fi + +# Enable nano-malloc if requested. +if [ "x${newlib_nano_malloc}" = "x" ]; then + if [ ${default_newlib_nano_malloc} = "yes" ]; then + newlib_nano_malloc="yes"; + fi +fi + +# Enable _REENT_CHECK macro memory allocation verification. +if [ "x${newlib_reent_check_verify}" = "x" ]; then + if [ ${default_newlib_reent_check_verify} = "yes" ]; then + newlib_reent_check_verify="yes"; + fi +fi + +# Remove rpc headers if xdr_dir not specified +if [ "x${xdr_dir}" = "x" ]; then + noinclude="${noinclude} rpc/types.h rpc/xdr.h" +fi + +# Have init/finit if not explicitly specified otherwise +if [ "x${have_init_fini}" != "xno" ]; then + newlib_cflags="${newlib_cflags} -D_HAVE_INIT_FINI" +fi + +if test -z "${have_crt0}" && test -n "${sys_dir}"; then + have_crt0="yes" +fi + +# Target-specific defaults +case "${host_cpu}" in + nvptx*) + if [[ -z ${newlib_global_stdio_streams} ]]; then + newlib_global_stdio_streams="yes"; + fi + ;; +esac diff --git a/toolchain/newlib/port/newlib/libc/acinclude.m4 b/toolchain/newlib/port/newlib/libc/acinclude.m4 new file mode 100644 index 00000000..c4215160 --- /dev/null +++ b/toolchain/newlib/port/newlib/libc/acinclude.m4 @@ -0,0 +1,70 @@ +dnl For each directory which we may or may not want, we define a name +dnl for the library and an automake conditional for whether we should +dnl build the library. + +AM_CONDITIONAL(HAVE_SIGNAL_DIR, test x${signal_dir} != x) +AM_CONDITIONAL(HAVE_STDIO_DIR, test x${stdio_dir} != x) +AM_CONDITIONAL(HAVE_STDIO64_DIR, test x${stdio64_dir} != x) +AM_CONDITIONAL(HAVE_POSIX_DIR, test x${posix_dir} != x) +AM_CONDITIONAL(HAVE_XDR_DIR, test x${xdr_dir} != x) +AM_CONDITIONAL(HAVE_SYSCALL_DIR, test x${syscall_dir} != x) +AM_CONDITIONAL(HAVE_UNIX_DIR, test x${unix_dir} != x) + +dnl We always recur into sys and machine, and let them decide what to do. +m4_foreach_w([SYS_DIR], [ + a29khif amdgcn arm + d10v + dailyrun + epiphany + h8300hms h8500hms + m88kbug mmixware + netware + or1k + rdos rtems + sh sysmec sysnec810 sysnecv850 sysvi386 sysvnecv70 + tic80 tirtos + w65 + z8ksim +], [AM_CONDITIONAL([HAVE_LIBC_SYS_]m4_toupper(SYS_DIR)[_DIR], test "${sys_dir}" = SYS_DIR)]) + +AC_TYPE_LONG_DOUBLE +AM_CONDITIONAL(HAVE_LONG_DOUBLE, test x"$ac_cv_type_long_double" = x"yes") + +dnl iconv library will be compiled if --enable-newlib-iconv option is enabled +AM_CONDITIONAL(ENABLE_NEWLIB_ICONV, test x${newlib_iconv} != x) + +dnl We have to include these unconditionally since machines might want to use +dnl AM_CONDITIONAL in their subdirs. +m4_include([libc/machine/nds32/acinclude.m4]) +m4_include([libc/machine/powerpc/acinclude.m4]) +m4_include([libc/machine/sh/acinclude.m4]) +m4_include([libc/machine/spu/acinclude.m4]) +m4_include([libc/machine/xtensa/acinclude.m4]) + +m4_foreach_w([MACHINE], [ + aarch64 amdgcn arc arc64 arm + bfin + cr16 cris crx csky + d10v d30v + epiphany + fr30 frv ft32 + h8300 h8500 hppa + i386 i960 iq2000 + lm32 + m32c m32r m68hc11 m68k m88k mep microblaze mips mn10200 mn10300 moxie msp430 mt + nds32 necv70 nios2 nvptx + or1k + powerpc pru + riscv rl78 rx + sh sparc spu + tic4x tic6x tic80 + v850 visium + w65 + x86_64 xc16x xstormy16 xtensa + z8k +], [AM_CONDITIONAL([HAVE_LIBC_MACHINE_]m4_toupper(MACHINE), test "${machine_dir}" = MACHINE)]) + +AM_CONDITIONAL(HAVE_FPMATH_H, test -r "${srcdir}/libc/machine/${machine_dir}/machine/_fpmath.h") + + +AM_CONDITIONAL(MACH_ADD_SETJMP, test "x$mach_add_setjmp" = "xtrue") diff --git a/toolchain/newlib/port/newlib/libc/sys/Makefile.inc b/toolchain/newlib/port/newlib/libc/sys/Makefile.inc new file mode 100644 index 00000000..8e785724 --- /dev/null +++ b/toolchain/newlib/port/newlib/libc/sys/Makefile.inc @@ -0,0 +1,72 @@ +if HAVE_LIBC_SYS_A29KHIF_DIR +include %D%/a29khif/Makefile.inc +endif +if HAVE_LIBC_SYS_AMDGCN_DIR +include %D%/amdgcn/Makefile.inc +endif +if HAVE_LIBC_SYS_ARM_DIR +include %D%/arm/Makefile.inc +endif +if HAVE_LIBC_SYS_D10V_DIR +include %D%/d10v/Makefile.inc +endif +if HAVE_LIBC_SYS_DAILYRUN_DIR +include %D%/dailyrun/Makefile.inc +endif +if HAVE_LIBC_SYS_EPIPHANY_DIR +include %D%/epiphany/Makefile.inc +endif +if HAVE_LIBC_SYS_H8300HMS_DIR +include %D%/h8300hms/Makefile.inc +endif +if HAVE_LIBC_SYS_H8500HMS_DIR +include %D%/h8500hms/Makefile.inc +endif +if HAVE_LIBC_SYS_M88KBUG_DIR +include %D%/m88kbug/Makefile.inc +endif +if HAVE_LIBC_SYS_MMIXWARE_DIR +include %D%/mmixware/Makefile.inc +endif +if HAVE_LIBC_SYS_NETWARE_DIR +include %D%/netware/Makefile.inc +endif +if HAVE_LIBC_SYS_OR1K_DIR +include %D%/or1k/Makefile.inc +endif +if HAVE_LIBC_SYS_RDOS_DIR +include %D%/rdos/Makefile.inc +endif +if HAVE_LIBC_SYS_RTEMS_DIR +include %D%/rtems/Makefile.inc +endif +if HAVE_LIBC_SYS_SH_DIR +include %D%/sh/Makefile.inc +endif +if HAVE_LIBC_SYS_SYSMEC_DIR +include %D%/sysmec/Makefile.inc +endif +if HAVE_LIBC_SYS_SYSNEC810_DIR +include %D%/sysnec810/Makefile.inc +endif +if HAVE_LIBC_SYS_SYSNECV850_DIR +include %D%/sysnecv850/Makefile.inc +endif +if HAVE_LIBC_SYS_SYSVI386_DIR +include %D%/sysvi386/Makefile.inc +endif +if HAVE_LIBC_SYS_SYSVNECV70_DIR +include %D%/sysvnecv70/Makefile.inc +endif +if HAVE_LIBC_SYS_TIC80_DIR +include %D%/tic80/Makefile.inc +endif +if HAVE_LIBC_SYS_TIRTOS_DIR +include %D%/tirtos/Makefile.inc +endif +if HAVE_LIBC_SYS_W65_DIR +include %D%/w65/Makefile.inc +endif +if HAVE_LIBC_SYS_Z8KSIM_DIR +include %D%/z8ksim/Makefile.inc +endif diff --git a/toolchain/newlib/port/newlib/libc/sys/dailyrun/Makefile.inc b/toolchain/newlib/port/newlib/libc/sys/dailyrun/Makefile.inc new file mode 100644 index 00000000..ec439726 --- /dev/null +++ b/toolchain/newlib/port/newlib/libc/sys/dailyrun/Makefile.inc @@ -0,0 +1 @@ +libc_a_SOURCES += %D%/syscalls.c diff --git a/toolchain/newlib/port/newlib/libc/sys/dailyrun/crt0.c b/toolchain/newlib/port/newlib/libc/sys/dailyrun/crt0.c new file mode 100644 index 00000000..4cac83b5 --- /dev/null +++ b/toolchain/newlib/port/newlib/libc/sys/dailyrun/crt0.c @@ -0,0 +1,20 @@ +#include + +extern int main(int argc, char **argv); + +extern char _edata; +extern char _end; + +void _start(void) +{ + char *bss; + int ret; + + /* Fill bss with zeros */ + bss = &_edata + 1; + while (bss < &_end) + *bss++ = 0; + + ret = main(0, NULL); + _exit(ret); +} diff --git a/toolchain/newlib/port/newlib/libc/sys/dailyrun/syscalls.c b/toolchain/newlib/port/newlib/libc/sys/dailyrun/syscalls.c new file mode 100644 index 00000000..47c3220b --- /dev/null +++ b/toolchain/newlib/port/newlib/libc/sys/dailyrun/syscalls.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include +#include +#include + +char **environ; /* pointer to array of char * strings that define the current + environment variables */ + +void _exit(int val); +int close(int file); +int execve(char *name, char **argv, char **env); +int fork(void); +int fstat(int file, struct stat *st); +int getpid(); +int isatty(int file); +int kill(int pid, int sig); +int link(char *old, char *new); +int lseek(int file, int ptr, int dir); +int open(const char *name, int flags, ...); +int read(int file, char *ptr, int len); +caddr_t sbrk(int incr); +int stat(const char *file, struct stat *st); +clock_t times(struct tms *buf); +int unlink(char *name); +int wait(int *status); +int write(int file, char *ptr, int len); +int gettimeofday(struct timeval *p, void *z); From bdcf0d112451363cb0ca5343261758d621e490bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20DUBOIN?= Date: Wed, 5 Mar 2025 18:31:12 +0100 Subject: [PATCH 2/6] feat(nix): add devshell to build newlib --- flake.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/flake.nix b/flake.nix index 616d3cd5..fd883075 100644 --- a/flake.nix +++ b/flake.nix @@ -91,6 +91,21 @@ export CROSS_COMPILE= ''; }; + + newlib = pkgs.mkShell.override { stdenv = pkgs.stdenvNoCC; } { + hardeningDisable = [ "all" ]; + buildInputs = with pkgs; [ + gnumake + pkg-config + autoconf269 # newlib requires using v2.69 exactly + automake115x + ]; + + shellHook = '' + export ARCH=i686 + export CROSS_COMPILE= + ''; + }; }; } ); From 73397da485ba70f9068a11044acc78d07a5c37b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20DUBOIN?= Date: Wed, 5 Mar 2025 16:52:31 +0100 Subject: [PATCH 3/6] feat(ci: build): build newlib --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 690ffb54..d77c988c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,7 +54,11 @@ jobs: - name: Build Toolchain run: | - nix develop .#gcc --command make gcc TARGET=i686-dailyrun ARCH= CROSS_COMPILE= + nix develop .#gcc --command make gcc TARGET=i686-dailyrun ARCH= CROSS_COMPILE= GCC_CONFIGURE_FLAGS="--with-newlib" + + - name: Build Newlib (libc) + run: | + nix develop .#newlib --command make newlib ARCH=i686 CROSS_COMPILE= - name: Build Kernel run: | From 91bc636ca1af98f402f80b0d86724b4925ae3d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20DUBOIN?= Date: Fri, 7 Mar 2025 11:01:07 +0100 Subject: [PATCH 4/6] feat(lib): rename libc to libk Our previous libc implementation simply included the most basic mem* functions and such, commonly used inside the kernel. This worked well when working with a 'bare' gcc target (no real libc), but this is no longer the case. This library of useful and common libc function implementations has now been renamed to 'libk' instead. --- kernel/build.mk | 2 +- lib/build.mk | 2 +- lib/libc/build.mk | 5 ----- lib/libk/build.mk | 5 +++++ lib/{libc => libk}/include/string.h | 0 lib/{libc => libk}/src/memcpy.c | 0 lib/{libc => libk}/src/memset.c | 0 lib/{libc => libk}/src/string.c | 16 ++++++++++------ 8 files changed, 17 insertions(+), 13 deletions(-) delete mode 100644 lib/libc/build.mk create mode 100644 lib/libk/build.mk rename lib/{libc => libk}/include/string.h (100%) rename lib/{libc => libk}/src/memcpy.c (100%) rename lib/{libc => libk}/src/memset.c (100%) rename lib/{libc => libk}/src/string.c (86%) diff --git a/kernel/build.mk b/kernel/build.mk index a553e09d..e0fb4b28 100644 --- a/kernel/build.mk +++ b/kernel/build.mk @@ -50,7 +50,7 @@ DEPS += $(KERNEL_OBJS:.o=.d) KERNEL_LDSCRIPT := $(BUILD_DIR)/kernel/linker.ld -KERNEL_LIBS := c algo path uacpi +KERNEL_LIBS := k algo path uacpi $(KERNEL_BIN): CPPFLAGS += -DKERNEL -DUACPI_FORMATTED_LOGGING $(KERNEL_BIN): | $(KERNEL_LDSCRIPT) diff --git a/lib/build.mk b/lib/build.mk index 0bd1976f..35d3ea36 100644 --- a/lib/build.mk +++ b/lib/build.mk @@ -29,7 +29,7 @@ endef include $(LIB_DIR)/libtest/build.mk -include $(LIB_DIR)/libc/build.mk +include $(LIB_DIR)/libk/build.mk include $(LIB_DIR)/libalgo/build.mk include $(LIB_DIR)/libpath/build.mk include $(LIB_DIR)/uacpi/build.mk diff --git a/lib/libc/build.mk b/lib/libc/build.mk deleted file mode 100644 index 2dcf716a..00000000 --- a/lib/libc/build.mk +++ /dev/null @@ -1,5 +0,0 @@ -$(eval $(call DEFINE_STATIC_LIBRARY,libc, \ - string.c \ - memcpy.c \ - memset.c \ -)) diff --git a/lib/libk/build.mk b/lib/libk/build.mk new file mode 100644 index 00000000..664bdb28 --- /dev/null +++ b/lib/libk/build.mk @@ -0,0 +1,5 @@ +$(eval $(call DEFINE_STATIC_LIBRARY,libk, \ + string.c \ + memcpy.c \ + memset.c \ +)) diff --git a/lib/libc/include/string.h b/lib/libk/include/string.h similarity index 100% rename from lib/libc/include/string.h rename to lib/libk/include/string.h diff --git a/lib/libc/src/memcpy.c b/lib/libk/src/memcpy.c similarity index 100% rename from lib/libc/src/memcpy.c rename to lib/libk/src/memcpy.c diff --git a/lib/libc/src/memset.c b/lib/libk/src/memset.c similarity index 100% rename from lib/libc/src/memset.c rename to lib/libk/src/memset.c diff --git a/lib/libc/src/string.c b/lib/libk/src/string.c similarity index 86% rename from lib/libc/src/string.c rename to lib/libk/src/string.c index dc1a4dd6..0b354526 100644 --- a/lib/libc/src/string.c +++ b/lib/libk/src/string.c @@ -22,15 +22,19 @@ char *strncpy(char *dst, const char *src, size_t n) return dst; } -char *strlcpy(char *dst, const char *src, size_t n) +size_t strlcpy(char *dst, const char *src, size_t n) { - if (n == 0) - return dst; + size_t i; - strncpy(dst, src, n - 1); - dst[n - 1] = '\0'; + for (i = 0; i < n - 1; ++i) { + dst[i] = src[i]; + if (dst[i] == '\0') + break; + } - return dst; + dst[i] = '0'; + + return i; } int strcmp(const char *s1, const char *s2) From bcd3757c09dd62bcf1ffdda68ea0e91ab0f0fb56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20DUBOIN?= Date: Fri, 7 Mar 2025 11:14:35 +0100 Subject: [PATCH 5/6] feat(lib: k): remove libc headers These are now always present inside our gc target's include directory. If someone encounters a problem with header include paths, they should just use our target instead of the system they've installed. --- lib/libk/include/string.h | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 lib/libk/include/string.h diff --git a/lib/libk/include/string.h b/lib/libk/include/string.h deleted file mode 100644 index 73764f6c..00000000 --- a/lib/libk/include/string.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef STRING_H -#define STRING_H - -#include - -size_t strlen(const char *s); - -char *strncpy(char *dst, const char *src, size_t); -char *strlcpy(char *dst, const char *src, size_t); - -void *memset(void *s, int c, size_t n); -void *memcpy(void *restrict dest, const void *restrict src, size_t n); -int memcmp(const void *, const void *, size_t); - -int strcmp(const char *, const char *); -int strncmp(const char *, const char *, size_t); - -#endif /* STRING_H */ From 3b8ff8c99ef0014f7793476f813a71975bac6112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20DUBOIN?= Date: Fri, 7 Mar 2025 12:24:40 +0100 Subject: [PATCH 6/6] feat(build): dynamically define clean targets The files/directories to be cleaned are stored inside a variable. This lets the included build.mk define what should or should not be cleaned along with their target, instead of having a big chunk of arbitraty RM targets in the main Makefile. --- Makefile | 13 ++++++++++--- kernel/build.mk | 2 ++ lib/build.mk | 5 ++++- toolchain/binutils/build.mk | 2 ++ toolchain/build.mk | 2 ++ toolchain/gcc/build.mk | 2 ++ toolchain/newlib/build.mk | 3 +++ 7 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 0e703ac9..164702c8 100644 --- a/Makefile +++ b/Makefile @@ -91,6 +91,11 @@ define MAKE_RECURSIVE endef endif +define newline + + +endef + all: kernel include $(TOOLCHAIN_DIR)/build.mk @@ -119,12 +124,14 @@ compile_commands.json: $(call ASSERT_EXE_EXISTS,bear) $(SILENT)bear -- $(MAKE) -B all +clean/%: + $(RM) -rf $(shell echo "$@" | sed "s/clean/$(BUILD_DIR)/") + clean: - $(RM) -rf $(BUILD_DIR) + $(foreach to_clean,$(TO_CLEAN),$(RM) -rf $(to_clean) $(newline)) distclean: clean - $(RM) -rf $(TOOLCHAIN_LOCATION) - $(RM) -rf $(BINUTILS_DIR) $(GCC_DIR) + $(foreach to_clean,$(TO_DISTCLEAN),$(RM) -rf $(to_clean) $(newline)) .PHONY: clean distclean diff --git a/kernel/build.mk b/kernel/build.mk index e0fb4b28..6f856402 100644 --- a/kernel/build.mk +++ b/kernel/build.mk @@ -80,4 +80,6 @@ qemu-server: $(KERNEL_ISO) $(call ASSERT_EXE_EXISTS,$(QEMU)) $(SILENT)$(QEMU) -cdrom $(KERNEL_ISO) $(QEMU_ARGS) +TO_CLEAN += $(BUILD_DIR)/$(KERNEL_DIR) $(KERNEL_BIN) $(KERNEL_ISO) $(BUILD_DIR)/kernel.map $(BUILD_DIR)/kernel.sym + .PHONY: qemu qemu-server diff --git a/lib/build.mk b/lib/build.mk index 35d3ea36..5004d54c 100644 --- a/lib/build.mk +++ b/lib/build.mk @@ -21,14 +21,17 @@ $(BUILD_DIR)/$(1).a: $$($(1)_OBJS) DEPS += $$($(1)_OBJS:.o=.d) +TO_CLEAN += $$(BUILD_DIR)/$(1).a + endef define DEFINE_STATIC_LIBRARY $(call DEFINE_STATIC_LIBRARY_AT,$(1),$(1),include,src,$(2)) endef -include $(LIB_DIR)/libtest/build.mk +TO_CLEAN += $(BUILD_DIR)/$(LIB_DIR) +include $(LIB_DIR)/libtest/build.mk include $(LIB_DIR)/libk/build.mk include $(LIB_DIR)/libalgo/build.mk include $(LIB_DIR)/libpath/build.mk diff --git a/toolchain/binutils/build.mk b/toolchain/binutils/build.mk index cb076fa7..e21620b2 100644 --- a/toolchain/binutils/build.mk +++ b/toolchain/binutils/build.mk @@ -41,3 +41,5 @@ $(BINUTILS_LD): binutils/configure $(call MAKE_RECURSIVE,$(BINUTILS_BUILD_DIR),install,binutils/) .PHONY: binutils binutils/configure binutils/prepare + +TO_DISTCLEAN += $(BINUTILS_BUILD_DIR) $(BINUTILS_DIR) diff --git a/toolchain/build.mk b/toolchain/build.mk index 905a5db9..ca26118e 100644 --- a/toolchain/build.mk +++ b/toolchain/build.mk @@ -11,3 +11,5 @@ export PATH := $(PREFIX)/bin:$(PREFIX)/usr/bin:$(PATH) include $(TOOLCHAIN_DIR)/binutils/build.mk include $(TOOLCHAIN_DIR)/gcc/build.mk include $(TOOLCHAIN_DIR)/newlib/build.mk + +TO_DISTCLEAN += $(TOOLCHAIN_LOCATION) diff --git a/toolchain/gcc/build.mk b/toolchain/gcc/build.mk index f04cbe4f..8e65dad1 100644 --- a/toolchain/gcc/build.mk +++ b/toolchain/gcc/build.mk @@ -42,3 +42,5 @@ $(GCC_GCC): gcc/configure $(call MAKE_RECURSIVE,$(GCC_BUILD_DIR),install-target-libgcc,gcc/) .PHONY: gcc gcc/configure gcc/prepare + +TO_DISTCLEAN += $(GCC_BUILD_DIR) $(GCC_DIR) diff --git a/toolchain/newlib/build.mk b/toolchain/newlib/build.mk index 6e7828b1..5ece7783 100644 --- a/toolchain/newlib/build.mk +++ b/toolchain/newlib/build.mk @@ -40,3 +40,6 @@ newlib: newlib/configure $(call MAKE_RECURSIVE,$(NEWLIB_BUILD_DIR),install,newlib/) .PHONY: libc newlib newlib/configure newlib/prepare newlib/tar + +TO_CLEAN += $(NEWLIB_BUILD_DIR) +TO_DISTCLEAN += $(NEWLIB_DIR)