972
edits
[unchecked revision] | [unchecked revision] |
m (moved Ada Bare bones to Ada Bare Bones: Follow the same naming scheme as the another Bare Bones pages) |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
Line 32:
The following code demonstrates setting up a directory structure for the RTS:
<
mkdir -p bare_bones/src/pc
cd bare_bones
Line 39:
mkdir -p rts/src
mkdir -p obj
</syntaxhighlight>
The best way to begin creating a new run-time library is to base it upon the existing source files obtained from the system GNAT installation, modifying them where necessary.
Line 45:
The following code demonstrates copying the required files from the host system's GNAT installation's run-time library into <tt>rts/src</tt> and then creating symbolic links to <tt>rts/boards/${arch}/adainclude</tt>. Where <tt>${arch}</tt> is <tt>i386</tt>, <tt>armv6</tt>, etc. The source location will need to be modified to reflect the location of the system compiler.
<
system_compiler_dir="/usr/lib/gcc/x86_64-linux-gnu/8"
rts_dir="${PWD}/rts"
Line 56:
ln -s "${rts_dir}/src/$f" "${rts_dir}/rts/boards/i386/adainclude/$f"
done
</syntaxhighlight>
==Files==
Line 68:
Additionally, it is possible to apply additional global configuration files by appending the following line to the <tt>Builder</tt> package in a GNAT project file:
<
package Builder is
-- ...
for Global_Configuration_Pragmas use "kernel.adc";
end Builder;
</syntaxhighlight>
It is also possible to instruct the compiler to apply additional files containing configuration pragmas to the current compilation using the switch <tt>-gnatec=path</tt> on the command line. These configuration pragmas are applied in addition to those found in <tt>gnat.adc</tt>, if it is present.
Line 81:
See below for a list of restriction pragmas useful for a bare bones kernel and runtime:
<
pragma Discard_Names;
pragma Restrictions (No_Enumeration_Maps);
Line 95:
pragma Restrictions (No_Implicit_Dynamic_Code);
pragma Restrictions (No_Secondary_Stack);
</syntaxhighlight>
'''Note:''' ''Do not use <tt>pragma No_Run_Time</tt>. It is obsolete.''
Line 107:
| Discard_Names || The Ada compiler automatically generates strings containing the names of enumerated data types, among others. These strings can be used in I/O.
<
type Fruit is (Orange, Banana, Apple);
-- Ada defines the following strings, "Orange", "Banana" and "Apple" in an array.
Line 114:
Put (Fruit'Image (Orange));
-- Prints "Orange" to the console.
</syntaxhighlight>
This directive instructs the compiler not to generate these strings.
Line 161:
Passing the <tt>-r</tt> flag to the binder instructs it to emit a list of further restrictions that are possible to apply to the project.
<
package Binder is
for Default_Switches ("Ada") use ("-r");
end Binder;
</syntaxhighlight>
===system.ads===
Line 187:
Also, add the following line in the private part of the package:
<
private
Run_Time_Name : constant String := "Bare Bones Run Time";
</syntaxhighlight>
According to targparm.ads, it must be the first thing after the private keyword. It should also show up in error messages in parentheses, but I've not managed to get it to show up thus far. This is useful as it should show you which RTS you are currently using, just in case you configure your build incorrectly.
Line 205:
====last_chance_handler.ads====
<
with System;
Line 211:
(Source_Location : System.Address; Line : Integer);
pragma Export (C, Last_Chance_Handler, "__gnat_last_chance_handler");
</syntaxhighlight>
====last_chance_handler.adb====
<
procedure Last_Chance_Handler
(Source_Location : System.Address; Line : Integer) is
Line 225:
end loop;
end Last_Chance_Handler;
</syntaxhighlight>
The contents of the <tt>Last_Chance_Handler</tt> procedure will need to be tailored to the specific platform of the kernel. Typically this procedure will dump information regarding the exception to output media such as a [[Serial_Ports|serial port]].
Line 233:
Create a file called <tt>gnat.gpr</tt> in the root directory with the following contents:
<
library project gnat is
type Arch_Name is ("i386", "arm");
Line 274:
for Library_Dir use "rts/boards/" & Arch & "/adalib";
end gnat;
</syntaxhighlight>
Now compile with the following command:
<
gprbuild -XBoard=pc -Pgnat.gpr
</syntaxhighlight>
Inside <tt>rts/boards/i386/adainclude/</tt> the RTS sources should be symbolically linked along with the custom <tt>last_chance_hander</tt> and system files. Inside <tt>rts/boards/i386/adalib/</tt> there should be the <tt>libgnat-4.6.a</tt> file as well as <tt>*.ali</tt> matching the source files, which are required by GNAT.
Line 357:
====console.ads====
<
with System;
Line 476:
procedure Clear (Background : in Background_Colour := Black);
end Console;
</syntaxhighlight>
====console.adb====
<
package body Console is
procedure Put
Line 519:
end Clear;
end Console;
</syntaxhighlight>
===bare_bones.adb===
Line 525:
This is platform independent and therefore goes into the src directory.
<
with Console; use Console;
Line 537:
end Bare_Bones;
pragma No_Return (Bare_Bones);
</syntaxhighlight>
===linker.ld===
Line 585:
Place this file in the root directory.
<
ARCH = i386
RTS_DIR = `pwd`/rts/boards/$(ARCH)
Line 613:
clean:
-rm obj/* *~ bare_bones
</syntaxhighlight>
===bare_bones.gpr===
Line 619:
Place this file in the root directory.
<
project Bare_Bones is
type Arch_Name is ("i386", "arm");
Line 674:
end Linker;
end Bare_Bones;
</syntaxhighlight>
==Raspberry Pi==
Line 698:
<
git clone git://github.com/gonzoua/u-boot-pi.git
cd u-boot-pi
make rpi_b_config
</syntaxhighlight>
==Testing==
Line 709:
Make sure you have built the RTS above before this next stage otherwise you won't be able to compile the kernel.
<
make qemu
</syntaxhighlight>
On the QEMU window, it should clear the screen, the the cursor won't move so it will be in the middle of the screen, in the top-left corner will be the message "Hello, bare bones in Ada."
|