2.8. Working with the Target

ERC32 Ada also supports debugging on the target computer. Before you can do this, you must connect the target board to the host computer using two serial cables that include a null modem. One cable connects the board's serial connector A to the host, and is used to down-load the monitor and for application program input and output. The other cable connects to the board's serial connector B, and is used by the debugger to load programs, and to perform debugging operations.

2.8.1. How to Down-load the Debug Monitor

Before we can use the debugger to down-load and debug programs running on the target, we must down-load the ERC32 Ada debug monitor. This is a small program that resides in the upper 32K bytes of RAM, and communicates with the ERC32 debugger over the serial interface B. You will find the source code in the directory /opt/erc32-ada-1.7/erc-coff/src/monitor/.

$ ls /opt/erc32-ada-1.7/erc-coff/src/monitor/
CVS  Makefile  README  art1.S  install.sh  remcom.c  t1.c  t2.adb  t2.c
t6  t6.c  xgcmon.M  xgcmon.c  xgcmon.ld

The ready-to-load (S-Record) version is /opt/erc32-ada-1.7/erc-coff/lib/xgcmon.

We assume the target board is fitted with the Saab Ericsson Space monitor. This monitor is based on Sun's SPARC Monitor, and is specially adapted for the Temic board. At the time of writing, the monitor is labeled "RDBmon V1.0". An alternative would be to fit the ERC32 Ada monitor, in which case the following load instructions may be skipped.

In this guide we use the program tip to work as a terminal. This program is generally available on Solaris platforms, but is seldom seen on Linux or Windows. If you don't have tip then there are other programs (such as Kermit) that will do as well.

We configured tip to use the serial interface connected to the target at 19200 bps in the file dem32. On Solaris, the configuration statement is in the file /etc/remote. The following example shows the configuration line used to generate the rest of this text. Note there is no entry for the output EOF string. This is not required.

The configuration line we use is as follows:

Example 2-16. Remote Configuration File

$ cat /etc/remote
...
dem32:\
        :dv=/dev/term/b:br#19200:el=^C^S^Q^U^D:ie=%$:
...

The debug monitor is called xgcmon. This file is formatted in Motorola S-Records ready for down-loading in response to the load command, as shown in the following example.

Example 2-17. Output from the SPARC Monitor

#RP


  ERC32 SEU test monitor 1.0


    0 - Start Sparcmon
    1 - Start IU regfile test
    2 - Start FPU regfile test
    3 - Start paranoia
    4 - Start RTEMS test case

#M

Select Sparcmon by pressing 0. The character is not echoed.

Example 2-18. Output from the Debug Monitor

0



 ERC32 SPARC Monitor V1.0.
monitor> load c s
load: s-record down-load
~>Local file name? xgcmon
1056 lines transferred in 15 seconds
!
monitor> run
$Id: xgcmon.c,v 1.1.1.1 1999/02/23 12:23:42 cvs Exp $

The monitor is now running and ready to communicate over the other serial interface. To leave tip type ~..

2.8.2. Preparing a Program to Run under the Monitor

Because the debug monitor is a complete supervisor-mode application program it is not appropriate to down-load the programs we built in the previous section. We must rebuild the program using the start file art1.

The module art1 consists of the code from art0 to do with initializing the high-level language environment. It omits the trap vector and trap handling code. You can get the source from /opt/erc32-ada-1.7/erc-coff/src/monitor/art1.S.

The following code shows how to compile the Ackermann benchmark program using a custom linker script, the module art1.

$ erc-coff-gcc -O ackermann.c -o ackermann -T xgcmon.ld art1.o

The file xgcmon.ld may be found on the CD-ROM in the run-time source directory.

The following example shows the Ackermann benchmark running under the control of the debugger. You should substitute your serial device name for ttyS0.

Example 2-19. Remote Debugging

$ erc-coff-gdb ackermann
XGC erc32-ada Version 1.7 (debugger)
Copyright (c) 1996, 2002, XGC Software.
Based on gdb version 5.1.1
Copyright (c) 1998 Free Software Foundation.
(gdb) set remote speed 19200
(gdb) tar rem /dev/ttyS0
Remote debugging using /dev/ttyS0
0x21f965c in ?? ()
(gdb) load
Loading section .text, size 0x1948 lma 0x2000000
Loading section .rdata, size 0x3d8 lma 0x2001948
Loading section .data, size 0x50 lma 0x2001d20
Start address 0x2000110
Transfer rate: 6698 bits/sec.
(gdb) run
Starting program: /hdb3/xgc/benchmarks/ackermann
,.,. ackermann GTS Version 0.1
---- ackermann Function call benchmark, A (3, 6).
   - ackermann time taken = 1.130e+00 Seconds.
**** ackermann  PASSED ============================.
Program exited normally.
(gdb) quit
$ 

A better way to build a program to run with the XGC Monitor is to use the linker emulation introduced with ERC32 Ada Version 1.7. The emulation knows the memory layout required and selects art1 in place of art0. Here's an example:

Example 2-20. Building to Run with the XGC Monitor

$ erc-coff-gnatmake -g ackermann -largs -Wl,-merc_xgcmon

The emulation, erc_xgcmon is given to the linker uising the -m option. If you try to run this program with the simulator, you will find that it fails almost immediately because the system registers have not been set up. When using the monitor, the system registers are set up in the monitor before the application program is loaded.