Ada Bare Bones: Difference between revisions
[unchecked revision] | [unchecked revision] |
Line 34: | Line 34: | ||
===gnat.adc=== |
===gnat.adc=== |
||
This file in the root directory of the build tells GNAT there are some configuration pragmas to apply to the build. These pragmas can also be placed at the start of your custom sytem.ads (see below), but we'll place them here for now. |
|||
<source lang="ada"> |
|||
pragma Discard_Names; |
|||
pragma Normalize_Scalars; |
|||
pragma Restrictions (No_Exception_Propagation); |
|||
pragma Restrictions (No_Finalization); |
|||
-- Use pragma Restrictions (No_Tasking) instead? |
|||
pragma Restrictions (Max_Tasks => 0); |
|||
pragma Restrictions (No_Protected_Types); |
|||
pragma Restrictions (No_Delay); |
|||
-- pragma Restrictions (No_Floating_Point); |
|||
pragma Restrictions (No_Recursion); |
|||
pragma Restrictions (No_Allocators); |
|||
pragma Restrictions (No_Dispatch); |
|||
pragma Restrictions (No_Implicit_Dynamic_Code); |
|||
pragma Restrictions (No_Secondary_Stack); |
|||
</source> |
|||
====Discard_Names==== |
|||
In Ada, the compiler generates strings for various data types, e.g. enumerations, these strings can then be used in I/O. |
|||
<source lang="ada"> |
|||
type Fruit is (Orange, Banana, Apple); |
|||
-- Ada defines the following strings, "Orange", "Banana" and "Apple" in an array. |
|||
-- These strings can be accessed using the 'Image attribute, as in |
|||
Put (Fruit'Image (Orange)); |
|||
-- Prints "Orange" to the console. |
|||
</source> |
|||
====Normalize_Scalars==== |
|||
Forces all scalars to be initialised, se the latest [http://gcc.gnu.org/onlinedocs/gcc-4.7.0/gnat_rm/Pragma-Normalize_005fScalars.html#Pragma-Normalize_005fScalars GNAT RM:Normalize_Scalars] for more information. |
|||
====No_Exception_Propagation==== |
|||
====No_Finalization==== |
|||
====Max_Tasks==== |
|||
====No_Protected_Types==== |
|||
====No_Delay==== |
|||
====No_Recursion==== |
|||
====No_Allocators==== |
|||
====No_Dispatch==== |
|||
====No_Implicit_Dynamic_Code==== |
|||
====No_Secondary_Stack==== |
|||
===system.ads=== |
===system.ads=== |
Revision as of 13:11, 13 June 2012
Difficulty level |
---|
![]() Medium |
Kernel Designs |
---|
Models |
Other Concepts |
In this tutorial we will compile a simple Ada kernel and boot it.
WAIT! Have you read Getting Started, Beginner Mistakes, and some of the related OS theory?
Preface
This tutorial is based on my multiboot kernel which I developed some time ago and placed on my site [1] and will also be the basis for my own kernel TAMP.
One of the first things people ask on the Ada IRC channel on Freenode is "Can Ada be used for OS development?" to which the answer is a resounding yes. But there are 2 problems:
- The people asking this question are new to Ada, and
- GNAT is not the easiest compiler to build.
Therefore these users don't understand what it takes to get the compiler into a useable state.
As you may have seen from other bare bones tutorials on this site, they state that you must have a compiler built which can handle ELF files, the usual way is by building GCC which targets i386-elf or some other similar architecture. The problem here is that GNAT will not build for these targets out of the box without messing with it's makefile. You have to do this as the makefile builds the RTS and then the gnat tools (gnatmake, gnatbind, et al).
So, for this tutorial, we will use the system GNAT compiler to build for i386 and later I will show how to build an arm-elf compiler and tools. I am on Debian testing 64-bit with GNAT 4.6.
GNAT and the Ada runtime system (RTS)
For this kernel we will be configuring a zero footprint RTS profile. This basically means, we have a compiler, tools and not much else.
Directory structure
We need a place to structure this kernel,
mkdir -p bare_bones/src
cd bare_bones
mkdir -p rts/boards/i386
gnat.adc
This file in the root directory of the build tells GNAT there are some configuration pragmas to apply to the build. These pragmas can also be placed at the start of your custom sytem.ads (see below), but we'll place them here for now.
pragma Discard_Names;
pragma Normalize_Scalars;
pragma Restrictions (No_Exception_Propagation);
pragma Restrictions (No_Finalization);
-- Use pragma Restrictions (No_Tasking) instead?
pragma Restrictions (Max_Tasks => 0);
pragma Restrictions (No_Protected_Types);
pragma Restrictions (No_Delay);
-- pragma Restrictions (No_Floating_Point);
pragma Restrictions (No_Recursion);
pragma Restrictions (No_Allocators);
pragma Restrictions (No_Dispatch);
pragma Restrictions (No_Implicit_Dynamic_Code);
pragma Restrictions (No_Secondary_Stack);
Discard_Names
In Ada, the compiler generates strings for various data types, e.g. enumerations, these strings can then be used in I/O.
type Fruit is (Orange, Banana, Apple);
-- Ada defines the following strings, "Orange", "Banana" and "Apple" in an array.
-- These strings can be accessed using the 'Image attribute, as in
Put (Fruit'Image (Orange));
-- Prints "Orange" to the console.
Normalize_Scalars
Forces all scalars to be initialised, se the latest GNAT RM:Normalize_Scalars for more information.
No_Exception_Propagation
No_Finalization
Max_Tasks
No_Protected_Types
No_Delay
No_Recursion
No_Allocators
No_Dispatch
No_Implicit_Dynamic_Code
No_Secondary_Stack
system.ads
Every Ada program must have access to the System package, this essentially tells the compiler what kind of hardware we are building for, therefore there will be 1 system.ads file per architecture your kernel supports.