From: Lucretia on
Hi,

I've posted this to the gcc ml as well, but I honestly don't think
I'll get anywhere with that so I'm posting it here as well.

I got a simple hello world style multiboot kernel working again
recently
and it has got me thinking about how I should be using GNAT.

Basically, I built a cross compiler for binutils and gcc to target
i386-elf (I will be wanting to play with other targets in the future,
e.g. mips-elf, arm-elf, sparc-elf, etc.). This gives me the following
toolset:

i386-elf-addr2line i386-elf-gcc i386-elf-gprof i386-elf-ranlib
i386-elf-ar i386-elf-gcc-4.2.2 i386-elf-ld i386-elf-
readelf
i386-elf-as i386-elf-gccbug i386-elf-nm i386-elf-size
i386-elf-c++filt i386-elf-gcov i386-elf-objcopy i386-elf-
strings
i386-elf-cpp i386-elf-gnatbind i386-elf-objdump i386-elf-strip

Which is fine enough as I can compile Ada sources with gcc.

Now to get my kernel to compile I originally used pragma No_Run_Time
which is now obsolete. I heard about the Zero Foot Print configurable
runtime but couldn't get it to compile some of the source files and I
couldn't figure out why.

I then tried to use the new Ada 2005 pragma Restrictions and put the
following in my gnat.adc:

-- Basic stuff.
pragma Restrictions(No_Obsolescent_Features);
pragma Restrictions(No_Exceptions);
pragma Restrictions(No_Recursion);

-- Memory management.
pragma Restrictions(No_Allocators);
pragma Restrictions(No_Local_Allocators);
pragma Restrictions(No_Unchecked_Deallocation);
--pragma Restrictions(No_);

-- Make sure we don't have tasking or any of it's features enabled.
pragma Restrictions(Max_Tasks => 0);
pragma Restrictions(No_Protected_Types);
pragma Restrictions(No_Delay);
pragma Restrictions(No_Task_Hierarchy);
pragma Restrictions(No_Abort_Statements);
pragma Restrictions(No_Implicit_Heap_Allocations);
pragma Restrictions(No_Asynchronous_Control);

I'm sure there are more I can use, I'm not sure about that.

Now, AFAIK I'm fairly sure I don't need to use the binder as that will
create a "main" including argc, argv, etc which you don't have in a
kernel (obviously), but I'm sure there are some elaborations that
aren't
being done that I *should* have.

I basically want to develop a microkernel that doesn't use the Ada
runtime as an executive, I know this is the usual route, but I don't
want to do that. An Ada runtime on top of my kernel is fine though.

So, am I going the right way about this? Or is there something else I
should be doing? Am I missing pragma's or using them wrong? Should I
really be building a minimal runtime such that I can use Ada minus
exceptions, tasking, etc?

Thanks,
Luke.
From: anon on
Your going down the wrong path!

First, there is no "pragma" other than "pragma No_Run_Time;" that
will allow GNAT to build code without a runtime code. Even then,
the code is not ROM bootable.

Second, The Ada main procedure (Ada program) has no startup address
or routine that can be directly linked and make a kernel, that can be
executed by a ROM startup! You must use the BINDER process to build
that start code. But the "GNAT BIND" does not allow stand-alone aka
ROM bootable kernel.

The GNAT binder perform a number of steps, that have to be preform
to insure that the program will work properly. Such as:
1. Checks that a program is consistent [ RM 10 ].
2. Checks that an acceptable order of elaboration exists
for the program [ RM 10 ].
3. Generates a main program incorporating the given
elaboration order. This program is a small Ada package
(body and spec) that must be subsequently compiled
using the GNAT compiler.
4. Determines the set of object files required by the
given main program.

So, for Ada only code, you must write a new Ada binder to preform
those steps to build a stand-alone code. And create the main program
(describe in step 3) that allows ROM bootable programs..

Time allowed just to write and test as new binder 6 months at least!


Another way is to use existing Ada 95 code projects that are out there.
That you can download the source code and study how they got around
this. But this way mean no Ada only code, and does violates the Ada RM.


In <dcc6d7b5-fb5b-4096-a066-85f6168a094d(a)l1g2000hsa.googlegroups.com>, Lucretia <lucretia9(a)lycos.co.uk> writes:
>Hi,
>
>I've posted this to the gcc ml as well, but I honestly don't think
>I'll get anywhere with that so I'm posting it here as well.
>
>I got a simple hello world style multiboot kernel working again
>recently
>and it has got me thinking about how I should be using GNAT.
>
>Basically, I built a cross compiler for binutils and gcc to target
>i386-elf (I will be wanting to play with other targets in the future,
>e.g. mips-elf, arm-elf, sparc-elf, etc.). This gives me the following
>toolset:
>
>i386-elf-addr2line i386-elf-gcc i386-elf-gprof i386-elf-ranlib
>i386-elf-ar i386-elf-gcc-4.2.2 i386-elf-ld i386-elf-
>readelf
>i386-elf-as i386-elf-gccbug i386-elf-nm i386-elf-size
>i386-elf-c++filt i386-elf-gcov i386-elf-objcopy i386-elf-
>strings
>i386-elf-cpp i386-elf-gnatbind i386-elf-objdump i386-elf-strip
>
>Which is fine enough as I can compile Ada sources with gcc.
>
>Now to get my kernel to compile I originally used pragma No_Run_Time
>which is now obsolete. I heard about the Zero Foot Print configurable
>runtime but couldn't get it to compile some of the source files and I
>couldn't figure out why.
>
>I then tried to use the new Ada 2005 pragma Restrictions and put the
>following in my gnat.adc:
>
>-- Basic stuff.
>pragma Restrictions(No_Obsolescent_Features);
>pragma Restrictions(No_Exceptions);
>pragma Restrictions(No_Recursion);
>
>-- Memory management.
>pragma Restrictions(No_Allocators);
>pragma Restrictions(No_Local_Allocators);
>pragma Restrictions(No_Unchecked_Deallocation);
>--pragma Restrictions(No_);
>
>-- Make sure we don't have tasking or any of it's features enabled.
>pragma Restrictions(Max_Tasks => 0);
>pragma Restrictions(No_Protected_Types);
>pragma Restrictions(No_Delay);
>pragma Restrictions(No_Task_Hierarchy);
>pragma Restrictions(No_Abort_Statements);
>pragma Restrictions(No_Implicit_Heap_Allocations);
>pragma Restrictions(No_Asynchronous_Control);
>
>I'm sure there are more I can use, I'm not sure about that.
>
>Now, AFAIK I'm fairly sure I don't need to use the binder as that will
>create a "main" including argc, argv, etc which you don't have in a
>kernel (obviously), but I'm sure there are some elaborations that
>aren't
>being done that I *should* have.
>
>I basically want to develop a microkernel that doesn't use the Ada
>runtime as an executive, I know this is the usual route, but I don't
>want to do that. An Ada runtime on top of my kernel is fine though.
>
>So, am I going the right way about this? Or is there something else I
>should be doing? Am I missing pragma's or using them wrong? Should I
>really be building a minimal runtime such that I can use Ada minus
>exceptions, tasking, etc?
>
>Thanks,
>Luke.

From: Lucretia on
On Jan 2, 8:49 pm, a...(a)anon.org (anon) wrote:
> Your going down the wrong path!
>
> First, there is no "pragma" other than "pragma No_Run_Time;" that
> will allow GNAT to build code without a runtime code. Even then,
> the code is not ROM bootable.

That pragma is deprecated for a start.

Why wouldn't it be ROM bootable?

> Second, The Ada main procedure (Ada program) has no startup address
> or routine that can be directly linked and make a kernel, that can be
> executed by a ROM startup! You must use the BINDER process to build
> that start code. But the "GNAT BIND" does not allow stand-alone aka
> ROM bootable kernel.

In my test I create a simple bit of asm that gets called by grub and
then it boots into my main Ada application. I also link with LD.

> The GNAT binder perform a number of steps, that have to be preform
> to insure that the program will work properly. Such as:
> 1. Checks that a program is consistent [ RM 10 ].

True enough.

> 2. Checks that an acceptable order of elaboration exists
> for the program [ RM 10 ].

This was something I was worried about.

> 3. Generates a main program incorporating the given
> elaboration order. This program is a small Ada package
> (body and spec) that must be subsequently compiled
> using the GNAT compiler.
> 4. Determines the set of object files required by the
> given main program.
>
> So, for Ada only code, you must write a new Ada binder to preform
> those steps to build a stand-alone code. And create the main program
> (describe in step 3) that allows ROM bootable programs..

Or use the gnatbind as a base.

> Time allowed just to write and test as new binder 6 months at least!
>
> Another way is to use existing Ada 95 code projects that are out there.
> That you can download the source code and study how they got around
> this. But this way mean no Ada only code, and does violates the Ada RM.

MarteOS actually uses gnat, they have ported the compiler to their os.
I don't know if it uses gnatbind. Not sure of pragmas either.

How do big companies use GNAT to create ROM bootable applications
then?

Luke.
From: Simon Wright on
anon(a)anon.org (anon) writes:

> 3. Generates a main program incorporating the given
> elaboration order. This program is a small Ada package
> (body and spec) that must be subsequently compiled
> using the GNAT compiler.
> 4. Determines the set of object files required by the
> given main program.

Not necessarily a main program: see http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gnat_ugn_unw/Binding-with-Non_002dAda-Main-Programs.html
From: Lucretia on
On Jan 2, 10:23 pm, Simon Wright <simon.j.wri...(a)mac.com> wrote:
> a...(a)anon.org (anon) writes:
> > 3. Generates a main program incorporating the given
> > elaboration order. This program is a small Ada package
> > (body and spec) that must be subsequently compiled
> > using the GNAT compiler.
> > 4. Determines the set of object files required by the
> > given main program.
>
> Not necessarily a main program: seehttp://gcc.gnu.org/onlinedocs/gcc-4.1.0/gnat_ugn_unw/Binding-with-Non...

Ah yeah, forgot about that, thanks. Thing is, it still requires the
standard lib and the use of -nostdlib doesn't make any difference.

$ i386-elf-gnatbind -n -nostdlib -nostdinc mb_start.ali
i386-elf-gnatbind: Cannot find: s-stalib.ali

So, I don't know where to go from here.

Thanks,
Luke.