From 84a54b7d049b7c48e34e7f5f072d5ba803da0116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Date: Wed, 13 Nov 2024 11:14:40 +0100 Subject: [PATCH 1/2] s-macres: merge native and qnx implementation Both are importing `exit` symbol from libc. --- linux/__init__.py | 2 +- qnx/__init__.py | 2 +- src/{s-macres__qnx.adb => s-macres__libc.adb} | 0 src/s-macres__native.adb | 45 ------------------- windows/__init__.py | 2 +- 5 files changed, 3 insertions(+), 48 deletions(-) rename src/{s-macres__qnx.adb => s-macres__libc.adb} (100%) delete mode 100644 src/s-macres__native.adb diff --git a/linux/__init__.py b/linux/__init__.py index d91a0b7c..3f867a94 100644 --- a/linux/__init__.py +++ b/linux/__init__.py @@ -4,7 +4,7 @@ class Linux(DFBBTarget): def __init__(self): super().__init__() - self.add_gnat_sources("src/s-macres__native.adb") + self.add_gnat_sources("src/s-macres__libc.adb") self.add_gnarl_sources("linux/adaint.c") def has_libc(self, profile): diff --git a/qnx/__init__.py b/qnx/__init__.py index 1d870361..ce0b594d 100644 --- a/qnx/__init__.py +++ b/qnx/__init__.py @@ -4,7 +4,7 @@ class QNX(Target): def __init__(self): super(QNX, self).__init__() - self.add_gnat_sources("src/s-macres__qnx.adb") + self.add_gnat_sources("src/s-macres__libc.adb") @property def has_command_line_arguments(self): diff --git a/src/s-macres__qnx.adb b/src/s-macres__libc.adb similarity index 100% rename from src/s-macres__qnx.adb rename to src/s-macres__libc.adb diff --git a/src/s-macres__native.adb b/src/s-macres__native.adb deleted file mode 100644 index e746a340..00000000 --- a/src/s-macres__native.adb +++ /dev/null @@ -1,45 +0,0 @@ ------------------------------------------------------------------------------- --- -- --- GNAT RUN-TIME COMPONENTS -- --- -- --- S Y S T E M . M A C H I N E _ R E S E T -- --- -- --- B o d y -- --- -- --- Copyright (C) 2011-2021, Free Software Foundation, Inc. -- --- -- --- GNAT is free software; you can redistribute it and/or modify it under -- --- terms of the GNU General Public License as published by the Free Soft- -- --- ware Foundation; either version 3, or (at your option) any later ver- -- --- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- --- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- --- or FITNESS FOR A PARTICULAR PURPOSE. -- --- -- --- As a special exception under Section 7 of GPL version 3, you are granted -- --- additional permissions described in the GCC Runtime Library Exception, -- --- version 3.1, as published by the Free Software Foundation. -- --- -- --- You should have received a copy of the GNU General Public License and -- --- a copy of the GCC Runtime Library Exception along with this program; -- --- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- --- . -- --- -- --- GNAT was originally developed by the GNAT team at New York University. -- --- Extensive contributions were provided by Ada Core Technologies Inc. -- --- -- ------------------------------------------------------------------------------- - -package body System.Machine_Reset is - procedure Os_Exit (Status : Integer); - pragma Import (C, Os_Exit, "exit"); - pragma No_Return (Os_Exit); - - ---------- - -- Stop -- - ---------- - - procedure Stop is - begin - Os_Exit (0); - end Stop; -end System.Machine_Reset; diff --git a/windows/__init__.py b/windows/__init__.py index 4e7ce7a1..abaec5cf 100644 --- a/windows/__init__.py +++ b/windows/__init__.py @@ -4,7 +4,7 @@ class Windows(DFBBTarget): def __init__(self): super().__init__() - self.add_gnat_sources("src/s-macres__native.adb", "src/s-textio__stdio.adb") + self.add_gnat_sources("src/s-macres__libc.adb", "src/s-textio__stdio.adb") @property def name(self): From 6397a57b1b6ee8c12c486b5d898bff79d2a282b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Date: Tue, 12 Nov 2024 13:30:32 +0100 Subject: [PATCH 2/2] ppc-lynx: add light runtime support Atomic operations are unabled though unchecked. llvm-project#21 --- Makefile | 5 + build_rts.py | 5 + gen_rts_sources.py | 11 +- lynx/__init__.py | 50 ++++++++ lynx/stdio_symbols.c | 55 +++++++++ src/system/system-lynxos178-ppc.ads | 182 ++++++++++++++++++++++++++++ support/rts_sources/sources.py | 29 +++++ 7 files changed, 336 insertions(+), 1 deletion(-) create mode 100644 lynx/__init__.py create mode 100644 lynx/stdio_symbols.c create mode 100644 src/system/system-lynxos178-ppc.ads diff --git a/Makefile b/Makefile index 8e5f716a..0e79afee 100644 --- a/Makefile +++ b/Makefile @@ -128,6 +128,11 @@ ifeq ($(TARGET),$(filter $(TARGET),ppc-pikeos5)) TARGETS=ppc-pikeos5 endif +ifeq ($(TARGET),$(filter $(TARGET),ppc-lynx178)) + TGT=powerpc-xcoff-lynxos178 + TARGETS=ppc-lynx178 +endif + ifeq ($(TARGETS), none) ifeq ($(TARGET),) $(error Error: TARGET is not defined) diff --git a/build_rts.py b/build_rts.py index 05c37eb2..c6e8c8bd 100755 --- a/build_rts.py +++ b/build_rts.py @@ -109,6 +109,8 @@ from freertos import ArmV7AFP_FreeRTOS +from lynx import PPCLynx + import argparse import os import subprocess @@ -326,6 +328,9 @@ def build_configs(target): t = Aarch64QNX() elif target == "arm-qnx": t = ARMQNX() + # LynxOS + elif target == "ppc-lynx178": + t = PPCLynx() else: print("Error: undefined target %s" % target) sys.exit(2) diff --git a/gen_rts_sources.py b/gen_rts_sources.py index 7f0e5536..c0f1b119 100755 --- a/gen_rts_sources.py +++ b/gen_rts_sources.py @@ -48,7 +48,16 @@ def main(): ) parser.add_argument( "--source-profile", - choices=["bb", "deos", "freertos", "linux", "pikeos", "vx7r2cert", "qnx"], + choices=[ + "bb", + "deos", + "freertos", + "linux", + "lynx", + "pikeos", + "vx7r2cert", + "qnx", + ], default="bb", help="platform specific source selections", ) diff --git a/lynx/__init__.py b/lynx/__init__.py new file mode 100644 index 00000000..03134af7 --- /dev/null +++ b/lynx/__init__.py @@ -0,0 +1,50 @@ +from support.bsp_sources.target import Target +from support.bsp_sources.archsupport import ArchSupport + + +class Lynx(Target): + def __init__(self): + super().__init__() + self.add_gnat_sources("src/s-macres__libc.adb", "lynx/stdio_symbols.c") + + def has_libc(self, profile): + return True + + @property + def has_single_precision_fpu(self): + return True + + @property + def has_double_precision_fpu(self): + return True + + @property + def is_os_target(self): + return True + + @property + def has_command_line_arguments(self): + return True + + @property + def is_legacy_format(self): + return True + + +class PPCLynx(Lynx): + def __init__(self): + super().__init__() + + @property + def target(self): + return "ppc-lynx178" + + @property + def name(self): + return "lynx" + + @property + def system_ads(self): + return { + "light": "system-lynxos178-ppc.ads", + } diff --git a/lynx/stdio_symbols.c b/lynx/stdio_symbols.c new file mode 100644 index 00000000..8099aaf3 --- /dev/null +++ b/lynx/stdio_symbols.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * * + * GNAT RUN-TIME COMPONENTS * + * * + * S T D I O S Y M B O L S * + * * + * C Implementation File * + * * + * Copyright (C) 2024-2024, Free Software Foundation, Inc. * + * * + * GNAT is free software; you can redistribute it and/or modify it under * + * terms of the GNU General Public License as published by the Free Soft- * + * ware Foundation; either version 3, or (at your option) any later ver- * + * sion. GNAT is distributed in the hope that it will be useful, but WITH- * + * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * + * or FITNESS FOR A PARTICULAR PURPOSE. * + * * + * As a special exception under Section 7 of GPL version 3, you are granted * + * additional permissions described in the GCC Runtime Library Exception, * + * version 3.1, as published by the Free Software Foundation. * + * * + * You should have received a copy of the GNU General Public License and * + * a copy of the GCC Runtime Library Exception along with this program; * + * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see * + * . * + * * + * GNAT was originally developed by the GNAT team at New York University. * + * Extensive contributions were provided by Ada Core Technologies Inc. * + * * + ****************************************************************************/ + +#include + +/* + * stdin, stdout and stderr are C defines and must be exposed for + * a-textio__ppclynx178.adb. + */ + +FILE * +__gnat_constant_stdin (void) +{ + return stdin; +} + +FILE * +__gnat_constant_stdout (void) +{ + return stdout; +} + +FILE * +__gnat_constant_stderr (void) +{ + return stderr; +} diff --git a/src/system/system-lynxos178-ppc.ads b/src/system/system-lynxos178-ppc.ads new file mode 100644 index 00000000..e2a1f6a0 --- /dev/null +++ b/src/system/system-lynxos178-ppc.ads @@ -0,0 +1,182 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT RUN-TIME COMPONENTS -- +-- -- +-- S Y S T E M -- +-- -- +-- S p e c -- +-- (LynxOS-178 PPC Version) -- +-- -- +-- Copyright (C) 2024-2024, Free Software Foundation, Inc. -- +-- -- +-- This specification is derived from the Ada Reference Manual for use with -- +-- GNAT. The copyright notice above, and the license provisions that follow -- +-- apply solely to the contents of the part following the private keyword. -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- As a special exception under Section 7 of GPL version 3, you are granted -- +-- additional permissions described in the GCC Runtime Library Exception, -- +-- version 3.1, as published by the Free Software Foundation. -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT was originally developed by the GNAT team at New York University. -- +-- Extensive contributions were provided by Ada Core Technologies Inc. -- +-- -- +------------------------------------------------------------------------------ + +pragma Restrictions (No_Exception_Propagation); +-- Disable exceptions propagation since only the last chance handler is +-- supported. + +pragma Restrictions (No_Exception_Registration); +-- Disable exception name registration. This capability is not used because +-- it is only required by exception stream attributes which are not supported +-- in this run time. + +pragma Restrictions (No_Implicit_Dynamic_Code); +-- Pointers to nested subprograms are not allowed in this run time, in order +-- to prevent the compiler from building "trampolines". + +pragma Restrictions (No_Finalization); +-- Controlled types are not supported in this run time + +pragma Restrictions (No_Tasking); +-- Tasking is not supported in this run time + +package System is + pragma Pure; + -- Note that we take advantage of the implementation permission to make + -- this unit Pure instead of Preelaborable; see RM 13.7.1(15). In Ada + -- 2005, this is Pure in any case (AI-362). + + pragma No_Elaboration_Code_All; + -- Allow the use of that restriction in units that WITH this unit + + type Name is (SYSTEM_NAME_GNAT); + System_Name : constant Name := SYSTEM_NAME_GNAT; + + -- System-Dependent Named Numbers + + Min_Int : constant := -2 ** (Standard'Max_Integer_Size - 1); + Max_Int : constant := 2 ** (Standard'Max_Integer_Size - 1) - 1; + + Max_Binary_Modulus : constant := 2 ** Standard'Max_Integer_Size; + Max_Nonbinary_Modulus : constant := 2 ** Integer'Size - 1; + + Max_Base_Digits : constant := Long_Long_Float'Digits; + Max_Digits : constant := Long_Long_Float'Digits; + + Max_Mantissa : constant := Standard'Max_Integer_Size - 1; + Fine_Delta : constant := 2.0 ** (-Max_Mantissa); + + Tick : constant := 0.01; + + -- Storage-related Declarations + + type Address is private; + pragma Preelaborable_Initialization (Address); + Null_Address : constant Address; + + Storage_Unit : constant := 8; + Word_Size : constant := 32; + Memory_Size : constant := 2 ** 32; + + -- Address comparison + + function "<" (Left, Right : Address) return Boolean; + function "<=" (Left, Right : Address) return Boolean; + function ">" (Left, Right : Address) return Boolean; + function ">=" (Left, Right : Address) return Boolean; + function "=" (Left, Right : Address) return Boolean; + + pragma Import (Intrinsic, "<"); + pragma Import (Intrinsic, "<="); + pragma Import (Intrinsic, ">"); + pragma Import (Intrinsic, ">="); + pragma Import (Intrinsic, "="); + + -- Other System-Dependent Declarations + + type Bit_Order is (High_Order_First, Low_Order_First); + Default_Bit_Order : constant Bit_Order := High_Order_First; + pragma Warnings (Off, Default_Bit_Order); -- kill constant condition warning + + -- Priority-related Declarations (RM D.1) + + -- 17 is the system determined default priority for user applications + -- running on LynxOS. + + -- The standard (Rm 13.7) requires that Default_Priority has the value: + + -- (Priority'First + Priority'Last) / 2 + + -- However, the default priority given by the OS is not the same thing as + -- the Ada value Default_Priority (previous examples include VxWorks). + -- Therefore, we follow a model based on the full range of LynxOS-178 + -- priorities. + + Max_Priority : constant Positive := 252; + Max_Interrupt_Priority : constant Positive := 255; + + subtype Any_Priority is Integer range 0 .. 255; + subtype Priority is Any_Priority range 0 .. 252; + subtype Interrupt_Priority is Any_Priority range 253 .. 255; + + Default_Priority : constant Priority := 126; + + -- Note that the priority of the environment task is set externally by the + -- OS + +private + + type Address is mod Memory_Size; + for Address'Size use Standard'Address_Size; + + Null_Address : constant Address := 0; + + -------------------------------------- + -- System Implementation Parameters -- + -------------------------------------- + + -- These parameters provide information about the target that is used + -- by the compiler. They are in the private part of System, where they + -- can be accessed using the special circuitry in the Targparm unit + -- whose source should be consulted for more detailed descriptions + -- of the individual switch values. + + Backend_Divide_Checks : constant Boolean := False; + Backend_Overflow_Checks : constant Boolean := True; + Command_Line_Args : constant Boolean := True; + Configurable_Run_Time : constant Boolean := True; + Denorm : constant Boolean := True; + Duration_32_Bits : constant Boolean := False; + Exit_Status_Supported : constant Boolean := True; + Machine_Overflows : constant Boolean := False; + Machine_Rounds : constant Boolean := True; + Preallocated_Stacks : constant Boolean := False; + Signed_Zeros : constant Boolean := True; + Stack_Check_Default : constant Boolean := False; + Stack_Check_Probes : constant Boolean := False; + Stack_Check_Limits : constant Boolean := False; + Support_Aggregates : constant Boolean := True; + Support_Atomic_Primitives : constant Boolean := True; + Support_Composite_Assign : constant Boolean := True; + Support_Composite_Compare : constant Boolean := True; + Support_Long_Shifts : constant Boolean := True; + Always_Compatible_Rep : constant Boolean := False; + Suppress_Standard_Library : constant Boolean := True; + Use_Ada_Main_Program_Name : constant Boolean := False; + Frontend_Exceptions : constant Boolean := False; + ZCX_By_Default : constant Boolean := True; + +end System; diff --git a/support/rts_sources/sources.py b/support/rts_sources/sources.py index 2732ed9b..01095014 100644 --- a/support/rts_sources/sources.py +++ b/support/rts_sources/sources.py @@ -294,6 +294,17 @@ "hie/s-textio__libc.ads", "hie/s-textio__libc.adb", ], + "lynx_srcs": [ + "exit.c", + "hie/a-textio.ads", + "hie/a-textio__ppclynx178.adb", + "hie/g-io__zfp.ads", + "hie/g-io__zfp.adb", + "hie/g-io-put.adb", + "hie/s-macres.ads", + "hie/s-textio__libc.ads", + "hie/s-textio__libc.adb", + ], "pikeos_srcs": [ "hie/a-textio.ads", "exit.c", @@ -367,6 +378,7 @@ "bb_srcs": ["hie/a-elchha__zfp.adb"], "freertos_srcs": ["hie/a-elchha__zfp.adb"], "linux_srcs": ["hie/a-elchha__zfp.adb"], + "lynx_srcs": ["hie/a-elchha__zfp.adb"], "pikeos_srcs": ["hie/a-elchha__zfp.adb"], "qnx_srcs": [ "hie/a-elchha__traceback.adb", @@ -397,6 +409,7 @@ "deos_srcs": ["hie/s-thread__cert.ads", "hie/s-thread__cert.adb"], "freertos_srcs": ["hie/s-sssita.ads", "hie/s-sssita.adb"], "linux_srcs": ["hie/s-sssita.ads", "hie/s-sssita.adb"], + "lynx_srcs": ["hie/s-sssita.ads", "hie/s-sssita.adb"], "pikeos_srcs": [ "hie/a-textio__pikeos-light.adb", "hie/s-sssita.ads", @@ -1390,6 +1403,19 @@ "hie/a-nallfl__light.ads", "libgnat/a-naliop.ads", ], + "lynx_srcs": [ + "hie/a-ngelfu__cert.ads", + "hie/a-ngelfu__cert.adb", + "hie/a-nlelfu__cert.ads", + "hie/a-nuelfu__cert.ads", + "hie/s-gcmain__cert.ads", + "hie/s-gcmain__cert.adb", + "hie/a-nllefu__cert.ads", + "hie/a-nuaufl__light.ads", + "hie/a-nalofl__light.ads", + "hie/a-nallfl__light.ads", + "libgnat/a-naliop.ads", + ], "pikeos_srcs": [ "hie/a-ngelfu__ada.ads", "hie/a-ngelfu__ada.adb", @@ -2300,18 +2326,21 @@ "bb_srcs": ["hie/s-parame__zfp_small.ads"], "freertos_srcs": ["hie/s-parame__zfp_small.ads"], "linux_srcs": ["hie/s-parame__zfp_small.ads"], + "lynx_srcs": ["hie/s-parame__zfp_small.ads"], }, "gnat/parameters/light-large": { "conditions": ["RTS_Profile:light", "Memory_Profile:large"], "bb_srcs": ["hie/s-parame__zfp.ads"], "freertos_srcs": ["hie/s-parame__zfp.ads"], "linux_srcs": ["hie/s-parame__zfp.ads"], + "lynx_srcs": ["hie/s-parame__zfp.ads"], }, "gnat/parameters/light-huge": { "conditions": ["RTS_Profile:light", "Memory_Profile:huge"], "bb_srcs": ["hie/s-parame__zfp_huge.ads"], "freertos_srcs": ["hie/s-parame__zfp_huge.ads"], "linux_srcs": ["hie/s-parame__zfp_huge.ads"], + "lynx_srcs": ["hie/s-parame__zfp_huge.ads"], }, # Cert "cert": {