From 7efcefa510d143c7bd7e4fceb6f9fb428720decc Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 20 Apr 1999 13:05:42 +0000 Subject: base GNAT/RTEMS examples --- hello_world_ada/Makefile.erc32 | 40 ++++++++++++++++ hello_world_ada/Makefile.pc386 | 54 ++++++++++++++++++++++ hello_world_ada/Makefile.psim | 42 +++++++++++++++++ hello_world_ada/Makefile.score603e | 37 +++++++++++++++ hello_world_ada/README.ERC32 | 88 ++++++++++++++++++++++++++++++++++++ hello_world_ada/README.PSIM | 71 +++++++++++++++++++++++++++++ hello_world_ada/gdb.psim | 2 + hello_world_ada/hello.adb | 20 ++++++++ hello_world_ada/init.c | 93 ++++++++++++++++++++++++++++++++++++++ irq_test/interrupt_pkg.adb | 87 +++++++++++++++++++++++++++++++++++ irq_test/interrupt_pkg.ads | 3 ++ irq_test/irqforce.c | 7 +++ irq_test/irqtest.adb | 7 +++ 13 files changed, 551 insertions(+) create mode 100644 hello_world_ada/Makefile.erc32 create mode 100644 hello_world_ada/Makefile.pc386 create mode 100644 hello_world_ada/Makefile.psim create mode 100644 hello_world_ada/Makefile.score603e create mode 100644 hello_world_ada/README.ERC32 create mode 100644 hello_world_ada/README.PSIM create mode 100644 hello_world_ada/gdb.psim create mode 100644 hello_world_ada/hello.adb create mode 100644 hello_world_ada/init.c create mode 100644 irq_test/interrupt_pkg.adb create mode 100644 irq_test/interrupt_pkg.ads create mode 100644 irq_test/irqforce.c create mode 100644 irq_test/irqtest.adb diff --git a/hello_world_ada/Makefile.erc32 b/hello_world_ada/Makefile.erc32 new file mode 100644 index 0000000..fe2db50 --- /dev/null +++ b/hello_world_ada/Makefile.erc32 @@ -0,0 +1,40 @@ +# +# Makefile for hello world example +# + +MAIN=hello + +# Tool paths +target=sparc-rtems +tooldir=/home/joel/gnat-3.10b/${target}/ +rtemsdir=${tooldir}/rtems/erc32 + +# Tool names +GCC=${tooldir}/bin/${target}-gcc +GNATMAKE=${tooldir}/bin/${target}-gnatmake +SIZE=${tooldir}/bin/${target}-size +SIS=${tooldir}/bin/sis +GDB=${tooldir}/bin/sis-gdb + +CARGS=-B${rtemsdir}/lib/ -specs bsp_specs -qrtems -mcypress + +all: init.o + $(GNATMAKE) -v -O -gnata -gnatE -gnato $(MAIN) -g \ + -bargs -r \ + -cargs $(CARGS) \ + -largs $(CARGS) init.o + $(SIZE) $(MAIN) + + + +init.o: init.c + $(GCC) -O4 -g -Wall -ansi -fasm $(CARGS) -c init.c + +run: + $(SIS) $(MAIN) + +gdb: + $(GDB) $(MAIN) + +clean: + rm -f b_$(MAIN).c b_$(MAIN).o *.o *.ali $(MAIN) diff --git a/hello_world_ada/Makefile.pc386 b/hello_world_ada/Makefile.pc386 new file mode 100644 index 0000000..1aac9df --- /dev/null +++ b/hello_world_ada/Makefile.pc386 @@ -0,0 +1,54 @@ +# +# Makefile for hello world example +# + +MAIN=hello + +# Tool paths +target=i386-rtems +tooldir=/home/joel/gnat-3.10p/${target}/ +rtemsdir=${tooldir}/rtems/pc386 + +# Tool names +GCC=${tooldir}/bin/${target}-gcc +GNATMAKE=${tooldir}/bin/${target}-gnatmake +SIZE=${tooldir}/bin/${target}-size +OBJCOPY=${tooldir}/bin/${target}-objcopy +NM=${tooldir}/bin/${target}-nm + +HEADERADDR=0x00097E00 +START16FILE=$(rtemsdir)/lib/start16.bin +START16ADDR=0x00097C00 +RELOCADDR=0x00100000 + +CARGS=-B${rtemsdir}/lib/ -specs bsp_specs -qrtems \ + -Wl,-Ttext,$(RELOCADDR) -Wl,--oformat,elf32-i386 + +all: init.o $(MAIN) + +$(MAIN): $(MAIN).exe + ln $(MAIN).exe $(MAIN) + +$(MAIN).exe: init.o + $(GNATMAKE) -v -O -gnata -gnatE -gnato $(MAIN) -g -o $(MAIN).obj \ + -bargs -r \ + -cargs $(CARGS) \ + -largs $(CARGS) init.o + $(SIZE) $(MAIN).obj + $(NM) -g -n $(MAIN).obj >$(MAIN).num + $(OBJCOPY) -O a.out-i386 \ + --remove-section=.rodata \ + --remove-section=.comment \ + --remove-section=.note \ + --strip-unneeded $(MAIN).obj $@ + $(OBJCOPY) -O binary $(MAIN).obj $(MAIN).bin + $(rtemsdir)/build-tools/bin2boot -v $(MAIN).bt $(HEADERADDR) \ + $(START16FILE) $(START16ADDR) 0 $(MAIN).bin $(RELOCADDR) 0 + + +init.o: init.c + $(GCC) -O4 -g -Wall -ansi -fasm $(CARGS) \ + -DGNAT_MAIN_STACKSPACE=16 -c init.c + +clean: + rm -f b_$(MAIN).c b_$(MAIN).o *.o *.ali $(MAIN) diff --git a/hello_world_ada/Makefile.psim b/hello_world_ada/Makefile.psim new file mode 100644 index 0000000..3e8f09b --- /dev/null +++ b/hello_world_ada/Makefile.psim @@ -0,0 +1,42 @@ +# +# Makefile for hello world example +# + +MAIN=hello + +# Tool paths +target=powerpc-rtems +tooldir=/home/joel/gnat-3.11b/${target}/ +rtemsdir=${tooldir}/rtems/psim + +# Tool names +GCC=${tooldir}/bin/${target}-gcc +GNATMAKE=${tooldir}/bin/${target}-gnatmake +SIZE=${tooldir}/bin/${target}-size +PSIM=${tooldir}/bin/powerpc-rtems-run +GDB=${tooldir}/bin/powerpc-rtems-gdb + +CARGS=-B${rtemsdir}/lib/ -specs bsp_specs -qrtems -mcpu=603 + +all: init.o + $(GNATMAKE) -v -O -gnata -gnatE -gnato $(MAIN) -g \ + -bargs -r \ + -cargs $(CARGS) \ + -largs $(CARGS) init.o + $(SIZE) $(MAIN) + + + +init.o: init.c + $(GCC) -O4 -g -Wall -ansi -fasm $(CARGS) -c init.c + +run: + -$(PSIM) -o "/#address-cells 2" \ + -o "/openprom/options/oea-memory-size 4194304" $(MAIN) + @echo Ignore the return code. It is meaningless. + +gdb: + $(GDB) -x gdb.psim $(MAIN) + +clean: + rm -f b_$(MAIN).c b_$(MAIN).o *.o *.ali $(MAIN) diff --git a/hello_world_ada/Makefile.score603e b/hello_world_ada/Makefile.score603e new file mode 100644 index 0000000..e87873f --- /dev/null +++ b/hello_world_ada/Makefile.score603e @@ -0,0 +1,37 @@ +# +# Makefile for hello world example +# + +MAIN=hello + +# Tool paths +tooldir=/avenger/afcc_ada/tools/powerpc-rtems-gnat-3.10p/ +rtemsdir=${tooldir}/rtems/score603e + +# Tool names +GCC=${tooldir}/bin/powerpc-rtems-gcc +GNATMAKE=${tooldir}/bin/powerpc-rtems-gnatmake +SIZE=${tooldir}/bin/powerpc-rtems-size + +CARGS=-B${rtemsdir}/lib/ -specs bsp_specs -qrtems -mcpu=603 + +all: init.o + $(GNATMAKE) -v -O -gnata -gnatE -gnato $(MAIN) -g \ + -bargs -r \ + -cargs $(CARGS) \ + -largs $(CARGS) init.o + $(SIZE) $(MAIN) + + + +init.o: init.c + $(GCC) -O4 -g -Wall -ansi -fasm $(CARGS) -c init.c + +run: + @ echo Must run on the real target + +gdb: + @ echo No real target + +clean: + rm -f b_$(MAIN).c b_$(MAIN).o *.o *.ali $(MAIN) diff --git a/hello_world_ada/README.ERC32 b/hello_world_ada/README.ERC32 new file mode 100644 index 0000000..d058c31 --- /dev/null +++ b/hello_world_ada/README.ERC32 @@ -0,0 +1,88 @@ + +In this directory, there are the following files: + + Makefile - Example Makefile file + README - the file you are reading. + hello.adb - simple hello world file + init.c - RTEMS initialization thread which invokes the Ada main + +The following make stanza are included: + + all - This stanza builds the executable hello. + + run - This invokes the SPARC Instruction Simulator (SIS) on hello. + + gdb - This invokes gdb with the integrated SPARC Instruction + Simulator (SIS) on hello. + + clean - This stanza removes all generated files. + +The tool directory must be in your path for this to work. + +SAMPLE SESSION WITH SIS +======================= + +The following is a sample session with sis: + + $ gmake run + /home/joel/gnat-3.10b/sparc-rtems//bin/sis hello + + SIS - SPARC intruction simulator 2.7.4, copyright Jiri Gaisler 1995 + Bug-reports to jgais@wd.estec.esa.nl + + loading hello: + section .text at 0x02000000 (159152 bytes) + section .data at 0x02026db0 (4384 bytes) + section .bss at 0x02027ed0 (30948 bytes)(not loaded) + serial port A on stdin/stdout + sis> go + resuming at 0x02000000 + Hello World + IU in error mode (257) + 712144 02000800 91d02000 ta 0 + sis> quit + +Note that the user typed "go" to start the executable and "quit" to +exit the simulator. The normal exit message is "IU in error mode (257)" +because the program exits by generating an unhandled trap. + + +SAMPLE SESSION WITH GDB +======================= + +The following is a sample session with sis: + + $ gmake gdb + /home/joel/gnat-3.10b/sparc-rtems//bin/sis-gdb hello + GNU gdb 4.16.1a + Copyright 1996 Free Software Foundation, Inc. + GDB is free software, covered by the GNU General Public License, and you are + welcome to change it and/or distribute copies of it under certain conditions. + Type "show copying" to see the conditions. + There is absolutely no warranty for GDB. Type "show warranty" for details. + This GDB was configured as "--host=i486-linux --target=sparc-erc32-aout"... + + SIS - SPARC instruction simulator 2.7.4 + Bug-reports to Jiri Gaisler ESA/ESTEC (jgais@wd.estec.esa.nl) + serial port A on stdin/stdout + Connected to the simulator. + loading /usr1/rtems/work/tools_ada/example/hello: + section .text at 0x02000000 (159152 bytes) + section .data at 0x02026db0 (4384 bytes) + section .bss at 0x02027ed0 (30948 bytes)(not loaded) + (gdb) run + Starting program: /usr1/rtems/work/tools_ada/example/hello + Hello World + + Program exited normally. + (gdb) quit + +Note that the user typed "run" to start the executable and "quit" to +exit the debugger. Other gdb commands function the same as when gdb +is used natively. + +The program "sis-gdb" is a script which always invokes a command file +to initialize the simulator and load the executable into the simulator's +memory. + + diff --git a/hello_world_ada/README.PSIM b/hello_world_ada/README.PSIM new file mode 100644 index 0000000..4e4eade --- /dev/null +++ b/hello_world_ada/README.PSIM @@ -0,0 +1,71 @@ + +In this directory, there are the following files: + + Makefile - Example Makefile file + README - the file you are reading. + hello.adb - simple hello world file + init.c - RTEMS initialization thread which invokes the Ada main + +The following make stanza are included: + + all - This stanza builds the executable hello. + + run - This invokes the PowerPC Simulator (PSIM) on hello. + + gdb - This invokes gdb with the integrated PowerPC Simulator + (PSIM) on hello. + + clean - This stanza removes all generated files. + +The tool directory must be in your path for this to work. + +SAMPLE SESSION WITH PSIM +======================== + +The following is a sample session with psim: + + $ gmake run + + /home/joel/gnat-3.10p/powerpc-rtems//bin/psim hello + Hello World + Hello World + gmake: *** [run] Error 132 + +At this point, programs run under the powerpc-rtems-run command +restart a second time. This is an known problem with the RTEMS PSIM +Board Support Package. + +Note that the powerpc-rtems-run command has no interactive mode. + + +SAMPLE SESSION WITH GDB +======================= + +The following is a sample session with sis: + + $ gmake gdb + /home/joel/gnat-3.10p/powerpc-rtems//bin/psim-gdb hello + GNU gdb 4.16.1a + Copyright 1996 Free Software Foundation, Inc. + GDB is free software, covered by the GNU General Public License, and you are + welcome to change it and/or distribute copies of it under certain conditions. + Type "show copying" to see the conditions. + There is absolutely no warranty for GDB. Type "show warranty" for details. + This GDB was configured as "--host=i486-linux --target=powerpc-unknown-eabi"... + Connected to the simulator. + (gdb) run + Starting program: /usr1/rtems/work/tools_ada/example/hello + Hello World + (gdb) quit + The program is running. Quit anyway (and kill it)? (y or n) y + + +Note that the user typed "run" to start the executable and "quit" to +exit the debugger. Other gdb commands function the same as when gdb +is used natively. + +The program "psim-gdb" is a script which always invokes a command file +to initialize the simulator and load the executable into the simulator's +memory. + + diff --git a/hello_world_ada/gdb.psim b/hello_world_ada/gdb.psim new file mode 100644 index 0000000..496f1ac --- /dev/null +++ b/hello_world_ada/gdb.psim @@ -0,0 +1,2 @@ +tar sim -o "/#address-cells 2" -o "/openprom/options/oea-memory-size 4194304" +load diff --git a/hello_world_ada/hello.adb b/hello_world_ada/hello.adb new file mode 100644 index 0000000..63f8ac0 --- /dev/null +++ b/hello_world_ada/hello.adb @@ -0,0 +1,20 @@ +-- +-- Hello World with Flair +-- + +with Text_IO; use Text_IO; + +procedure Hello is +begin + Put_Line ("GNAT/RTEMS Hello World Test"); + New_Line; + Put_Line ("Welcome to the World of Lady Ada"); + + New_Line; + Put_Line ("Initiating 2.5 second delay"); + delay 2.5; + Put_Line ("Delay Complete"); + + Put_Line ("Test Complete"); +end Hello; + diff --git a/hello_world_ada/init.c b/hello_world_ada/init.c new file mode 100644 index 0000000..3a5b761 --- /dev/null +++ b/hello_world_ada/init.c @@ -0,0 +1,93 @@ +/* + * COPYRIGHT (c) 1989-1997. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be found in + * the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include + +#include +#include + +extern rtems_configuration_table BSP_Configuration; + +#ifdef GNAT_PID +#include +pid_t getpid() +{ + return GNAT_PID; +} +#endif + +/* + * By having the POSIX_Init thread create a second thread just + * to invoke gnat_main, we can override all default attributes + * of the "Ada environment task". Otherwise, we would be + * stuck with the defaults set by RTEMS. + */ + +void *start_gnat_main( void * argument ) +{ + extern int gnat_main ( int argc, char **argv, char **envp ); + + (void) gnat_main ( 0, 0, 0 ); + + exit( 0 ); + + return 0; +} + +void *POSIX_Init( void *argument ) +{ + pthread_t thread_id; + pthread_attr_t attr; + size_t stacksize = _ada_pthread_minimum_stack_size(); + int status; + + status = pthread_attr_init( &attr ); + assert( !status ); + +#ifdef GNAT_MAIN_STACKSPACE + stacksize = GNAT_MAIN_STACKSPACE * 1024; +#else +#define GNAT_MAIN_STACKSPACE 0 +#endif + + status = pthread_attr_setstacksize( &attr, stacksize ); + assert( !status ); + + status = pthread_create( &thread_id, &attr, start_gnat_main, NULL ); + assert( !status ); + + pthread_exit( 0 ); + + return 0; +} + +/* configuration information */ + +#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MICROSECONDS_PER_TICK RTEMS_MILLISECONDS_TO_MICROSECONDS(1) + +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_GNAT_RTEMS +/* +#define CONFIGURE_MAXIMUM_ADA_TASKS 20 +#define CONFIGURE_MAXIMUM_FAKE_ADA_TASKS 0 + +#define CONFIGURE_MEMORY_OVERHEAD (256 + GNAT_MAIN_STACKSPACE) +*/ + +#define CONFIGURE_INIT + +#include + diff --git a/irq_test/interrupt_pkg.adb b/irq_test/interrupt_pkg.adb new file mode 100644 index 0000000..2097ba8 --- /dev/null +++ b/irq_test/interrupt_pkg.adb @@ -0,0 +1,87 @@ + +-- This is an example of how to attach and handle interrupts in Ada 95. +-- Interrupt handling is done as follows: +-- +-- 1. A protected procedure is attached to the interrupt +-- 2. When activated, the procedure enables a conditional entry +-- 3. A task waiting on the entry will carry out the work. +-- +-- In this way, we spend minimum amount of time in the protected +-- procedure. Many other schemes are of course possible... +-- +-- Written by Tullio Vardanega and Jiri Gaisler +-- European Space Agency, 1999. +-- + + +with Ada.Interrupts; +with System; +with Ada.Text_IO; + +package body Interrupt_pkg is + + type T_SEM is (HIGH, LOW); + + Protected_Priority : constant System.Interrupt_Priority := + System.Interrupt_Priority'First; + +-- Protected object, including interrupt handler (Signal) and conditional entry. + + protected Handler is + procedure Signal; + entry Wait; + pragma Attach_Handler (Signal, 17); -- Signal 17 equals irq 1 on ERC32 + pragma Priority (Protected_Priority); + private + BARRIER : T_SEM := HIGH; + end Handler; + + protected body Handler is + procedure Signal is + begin + BARRIER := LOW; + end Signal; + entry Wait when (BARRIER = LOW) is + begin + BARRIER := HIGH; + end Wait; + end Handler; + +-- Sporadic task, waiting on entry (Wait) for the interrupt. + + task sporadic is + pragma Priority (8); + end sporadic; + + task body sporadic is + Message : constant STRING := + "sporadic activated"; + begin + loop + Handler.Wait; + Ada.Text_IO.Put_line (Message); + end loop; + end sporadic; + +-- Test program, generating interrupt 1 on ERC32 + + procedure itest is + procedure irqforce(irq : integer); + pragma Import (C, irqforce, "irqforce"); + begin + for i in 1..10 loop + irqforce(1); + delay(0.05); + end loop; + + -- Have to kill sporadic to exit since it is has an infinite loop + abort sporadic; + end; + +begin + + itest; + +end Interrupt_pkg; + + diff --git a/irq_test/interrupt_pkg.ads b/irq_test/interrupt_pkg.ads new file mode 100644 index 0000000..6bc597e --- /dev/null +++ b/irq_test/interrupt_pkg.ads @@ -0,0 +1,3 @@ +package Interrupt_pkg is + procedure itest; +end Interrupt_pkg; diff --git a/irq_test/irqforce.c b/irq_test/irqforce.c new file mode 100644 index 0000000..78ae91a --- /dev/null +++ b/irq_test/irqforce.c @@ -0,0 +1,7 @@ +#include + +irqforce(int irq) +{ + ERC32_Unmask_interrupt(irq); + ERC32_Force_interrupt(irq); +} diff --git a/irq_test/irqtest.adb b/irq_test/irqtest.adb new file mode 100644 index 0000000..1a9dfad --- /dev/null +++ b/irq_test/irqtest.adb @@ -0,0 +1,7 @@ +with Interrupt_pkg; + +procedure irqtest is +begin + null; +end irqtest; + -- cgit v1.2.3