Ada Runtime Library: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
Detailed use of -ffunction-sections and -fdata-sections directives for dead code removal
m Minor improvements
Line 1:
This guide intends to serve as an introduction to the Ada run-time library, and as a guide to creating a basic Ada run-time library suitable for bare-metal development targeting the x86 platform.<br/>
For other architectures, AdaCore provides pre-made run-time libraries and board support packages targeting a variety of ARM/RISC-V boards. These are freely available on [https://github.com/AdaCore/bb-runtimes Github], as well as being packaged with their ARM'arm-ELFelf' compilerand 'riscv32-elf' compilers.
 
''Note: This guide is specific to the GNAT Ada compiler, available from either the FSF as part of [[GCC]], or as a stand-alone product from [https://www.adacore.com/download AdaCore]. Additionally it assumes the use of the GPRBuild suite of utilities, which are freely available as part of AdaCore’s GNAT compiler or can be built [https://github.com/AdaCore/gprbuild from source].''
Line 24:
== Anatomy of a run-time library ==
 
An Ada run-time library is fundamentally a directory tree containing the run-time sources and compiled library files. The <tt>adainclude</tt> subdirectory contains the run-time sources, which will provide the Ada equivalent of C header files for our run-time. The <tt>adalib</tt> subdirectory contains the compiled library artifacts that programs will be statically linked against. The compiler will require the presence of these two directories within the run-time directory to detect it as valid. The location of these directories can be customised by creating two files named <tt>'ada_source_path'</tt> and <tt>'ada_object_path'</tt> which allow the specification of alternate locations for the source and object directories. For more information on this feature, refer to the [https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gnat_ugn/Search-Paths-and-the-Run-Time-Library-RTL.html GNAT documentation].<br/>
A run-time library may be placed within the GNAT compiler's default search directories which will make it globally visible for the compiler, or can be placed in another location and specified as a relative path within the project's configuration file.<br/>
''Note: GPRBuild requires the presence of a run-time within its search path before it will fully acknowledge the presence of GNAT for a particular target.''
Line 179:
 
 
We can begin creating the source code for a minimal run-time by copying a list of files from our compiler's native run-time directory into the source directory of our run-time GNAT project. If you're using FSF GNAT this is most likely in a similar location to: <tt>/usr/lib/gcc/x86_64-linux-gnu/<version>/adainclude/</tt>. If you're using AdaCore GNAT Pro the directory structure for run-time sources is broken down into different sections, but you should still be able to find the same required files. ''Note: If you intend to use source files obtained from AdaCore's GNAT Pro or associated material in the construction of a run-time library, be sure to read and understand their licensing to understand any restrictions imposed upon the use of their open -source material.'' <br/>
A list of files to copy from your compiler's default hosted run-time to your run-time library project's source directory are found below, together with an explanation of their purpose.
 
Line 258:
=== Platform-specific support code ===
 
For the purposes of bare-metal development, it may be advantageous to define platform-specific support packages within the run-time library to avoid cluttering the main kernel package with platform-specific code. AsThis wellalso assupports to allowa greater degree of abstraction, and better portability of the kernel itself.<br/>
Any packages contained within the runtime will be accessible to the linked program automatically. Be mindful not to declare any new packages as children of the top level <tt>Ada</tt> or <tt>System</tt> packages, as GNAT will consider any non-standard children to be ‘implementation-specific’: for internal use only and forbid their use outside of the run-time.
 
Line 368:
end x86.Port_IO;
</source>
 
Fundamentally, the role of the runtime library is to implement the features defined in the Ada language standard for the particular target platform. This requires the creation of target-specific packages to interface with platform features such as internal clocks, [[UART|UARTs]] and [[PIT|timers]], among other things. These packages can then be used by language-defined packages in the runtime library to expose this functionality to the linked application.
 
=== System initialization code ===
Line 422 ⟶ 424:
The Ada standard provides the following implementation advice: ''"If an implementation supports Export for a given language, then it should also allow the main subprogram to be written in that language. It should support some mechanism for invoking the elaboration of the Ada library units included in the system, and for invoking the finalization of the environment task. On typical systems, the recommended mechanism is to provide two subprograms whose link names are '<tt>adainit</tt>' and '<tt>adafinal</tt>'. Adainit should contain the elaboration code for library units. Adafinal should contain the finalization code. These subprograms should have no effect the second and subsequent time they are called."'' Additional documentation can be found [http://ada-auth.org/standards/12rm/html/RM-B-1.html here]
 
IfIn youthe arecase creatingof a pure Ada kernel, a good place to put this procedure call is within yourthe boot code assembly to ensure that the run-time is properly initialized prior to the jump to Ada code.
 
== Additional Resources ==