2.7. Working with the Target

GCC-ERC32 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 each 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. See Appendix D.

2.7.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 GCC-ERC32 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 on the CD-ROM in directory /mnt/cdrom/src/xgc/runtimes/erc/monitor/.

$ ls /mnt/cdrom/src/xgc/runtimes/erc/monitor/
CVS Makefile README remcom.c t1.c xgcmon.M xgcmon.c xgcmon.ld

The ready-to-load (S-Record) version is /opt/gcc-erc32-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 XGC 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-10. The 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-11. 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-12. 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.7.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. What we need is a program that will use the interrupt vectors and interrupt handlers already included in the monitor.

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. We use art1 in place of art0.

The following code shows how to compile the Ackermann benchmark program using a custom linker script and the file art1.o.

Building to Run with the XGC Monitor

$ erc-coff-gcc ackermann.c -o ackermann -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.

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-13. Remote Debugging

$ erc-coff-gdb ackermann
XGC gcc-erc32 Version 1.7e (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 .rodata, 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
$