Contents|Index|Previous|Next

Unix operating system

The following documentation discusses the procedures for using the main utilities for the UNIX operating systems.

1. Create source code

Create the following sample source code and save it as ‘hello.c’. Use this program to verify correct installation.

#include <stdio.h>

int a, c;

void foo(int b)
{
  c = a + b;
  printf("%d + %d = %d\n", a, b, c);
}

int main()
{
  int b;

  a = 3;
  b = 4;
  printf("Hello, world!\n");
  foo(b);
  return 0;
}

2. Compile and link from source code

Throughout these examples the bold percent sign (%) represents the operating system command prompt.

The stand-alone simulator can work with both ‘big-endian’ and ‘little-endian’ executables. The DDB evaluation board requires a ‘little-endian’ executable. For the following examples compile a ‘little-endian’ executable named ‘hello.xl’.

To compile and link this example enter:

% gcc -g -EL hello.c -Tddb.ld -o hello.xl
%

To compile a little-endian executable use the ‘-EL’ option to GCC. The option
‘
-g’ generates debugging information, and ‘-o’ specifies the name of the executable to be produced. Other useful options include ‘-O’ for standard optimization, and ‘-O2’ for extensive optimization. When no optimization option is used GCC will not optimize.

To link an executable, the correct linker script must be specified with the ‘-T’ option. To link for the DDB (PMON) board, use ‘-Tddb.ld’. To link for a different PMON board’ use ‘-Tpmon.ld’.

3. Run the executable on the stand-alone simulator

To run this program on the stand-alone simulator, enter:

% mips64vr4300-elf-run hello.xl
hello world!
3 + 4 = 7
%

The simulator executes the program, and returns when the program exits.

4. Run under the debugger

GDB can be used to debug executables either on hardware via serial or ethernet download or using the GNUpro MIPS simulator. Debugging on hardware does not support doing ethernet and serial downloads concurrently. It is recommended that ethernet downloads are done on a private network. Ethernet traffic on a typical LAN can cause problems downloading software to the card.

4a. Debug with serial download

To run this executable on the DDB board, under the GNU debugger GDB, enter:

% mips64vr4300-elf-gdb -nw hello.xl 
GDB is free software and you are welcome to 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. 
GDB 4.16-nec-960902 (sparc-sun-sunos4.1.4 --target mips64vr4300-elf), 
Copyright 1996 Free Software Foundation, Inc. 

(gdb) target ddb /dev/ttya 
Remote MIPS debugging using /dev/ttya 
Current language: auto; currently asm 

(gdb) load 
.text   : 0xa0100000 .. 0xa01069c0 
.rodata : 0xa01069c0 .. 0xa0106df0 
.reginfo: 0xa0106df0 .. 0xa0106e08 
.data   : 0xa0107380 .. 0xa01079d0 
.lit8   : 0xa01079d0 .. 0xa0107a60 
.sdata  : 0xa0107a60 .. 0xa0107b00 

(gdb) break main 
Breakpoint 1 at 0xa01001b0: file hello.c, line 15. 

(gdb) run 
Starting program: /tmp/hello.xl 
Breakpoint 1, main () at hello.c:15 
15 a = 3; 
Current language: auto; currently c 

(gdb) print a 
$1 = 0 

(gdb) step 
16        b = 4; 

(gdb) print a 
$2 = 3 

(gdb) list 
11      int main() 
12      { 
13        int b; 
14 
15        a = 3; 
16        b = 4; 
17        printf("Hello, world!\n"); 
18        foo(b); 
19        return 0; 
20      } 

(gdb) list foo 
1      #include <stdio.h> 
2 
3      int a, c; 
4 
5      void foo(int b) 
6      { 
7        c = a + b; 
8        printf("%d + %d = %d\n", a, b, c); 
9      } 
10 

(gdb) break 7 
Breakpoint 2 at 0xa0100144: file hello.c, line 7. 

(gdb) continue 
Continuing. 
Hello, world! 
Breakpoint 2, foo (b=4) at hello.c:7 
7         c = a + b; 

(gdb) step 
8         printf("%d + %d = %d\n", a, b, c); 

(gdb) print c 
$3 = 7 

(gdb) next 
3 + 4 = 7 
9       } 

(gdb) backtrace 
#0 foo (b=4) at hello.c:9 
#1 0xa01001e0 in main () at hello.c:18 
#2 0xa01058f8 in __do_main () at ../../../../../libgloss/mips/../do_main.c:12 

(gdb) quit 

% 

The ‘-nw’ option in the original call to ‘gdb’ selected the command line interface to the GDB (GNU debugger), which is useful for making transcripts such as the one above. The ‘-nw’ option is also useful when you wish to report a bug in GDB, because a sequence of commands is simpler to reproduce. If you are running an X11 based server and your ‘DISPLAY’ environment variable is set, GDB will start the GNUPro ‘gdbtk’ interface by default.

4b. Debug with ethernet download

To run this executable on the DDB board, under the GNU debugger GDB, using ethernet download enter:

% mips64vr4300-elf-gdb -nw hello.xl 
GDB is free software and you are welcome to 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. 
GDB 4.16-nec-960902 (sparc-sun-sunos4.1.4 --target mips64vr4300-elf), 
Copyright 1996 Free Software Foundation, Inc. 

(gdb) target ddb /dev/ttya 192.168.1.1:/tmp/hello.tmp 
Remote MIPS debugging using /dev/ttya 
Current language: auto; currently asm 

(gdb) load 
.text   : 0xa0100000 .. 0xa01069c0 
.rodata : 0xa01069c0 .. 0xa0106df0 
.reginfo: 0xa0106df0 .. 0xa0106e08 
.data   : 0xa0107380 .. 0xa01079d0 
.lit8   : 0xa01079d0 .. 0xa0107a60 
.sdata  : 0xa0107a60 .. 0xa0107b00 

(gdb) break main 
Breakpoint 1 at 0xa01001b0: file hello.c, line 15. 

(gdb) run 
Starting program: /tmp/hello.xl 
Breakpoint 1, main () at hello.c:15 
15        a = 3; 
Current language: auto; currently c 

(gdb) print a 
$1 = 0 

(gdb) step 
16        b = 4; 

(gdb) print a 
$2 = 3 

(gdb) list 
11      int main() 
12      { 
13        int b; 
14 
15        a = 3; 
16        b = 4; 
17        printf("Hello, world!\n"); 
18        foo(b); 
19        return 0; 
20      } 

(gdb) list foo 
1      #include <stdio.h> 
2 
3      int a, c; 
4 
5      void foo(int b) 
6      { 
7        c = a + b; 
8        printf("%d + %d = %d\n", a, b, c); 
9      } 
10 

(gdb) break 7 
Breakpoint 2 at 0xa0100144: file hello.c, line 7. 

(gdb) continue 
Continuing. 
Hello, world! 
Breakpoint 2, foo (b=4) at hello.c:7 
7         c = a + b; 

(gdb) step 
8         printf("%d + %d = %d\n", a, b, c); 

(gdb) print c 
$3 = 7 

(gdb) next 
3 + 4 = 7 
9       } 

(gdb) backtrace 
#0 foo (b=4) at hello.c:9 
#1 0xa01001e0 in main () at hello.c:18 
#2 0xa01058f8 in __do_main () at ../../../../../libgloss/mips/../do_main.c:12 

(gdb) quit 

% 

The ‘-nw’ option selects the command line interface to the GDB (GNU debugger), which is useful for making transcripts such as the one above. The
‘
-nw’ option is also useful when you wish to report a bug in GDB, because a sequence of commands is simpler to reproduce. If you are running an X11 based server and your ‘DISPLAY’ environment variable is set, GDB will start the GNUPro ‘gdbtk’ interface by default.

4c. Debug with the built-in simulator

To run this executable under the GNU debugger GDB, on the built-in simulator enter:

% mips64vr4300-elf-gdb -nw hello.xl 
GDB is free software and you are welcome to 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. 
GDB 4.16-nec-960902 (sparc-sun-sunos4.1.4 --target mips64vr4300-elf), 
Copyright 1996 Free Software Foundation, Inc. 

(gdb) target sim 
Remote MIPS debugging using /dev/ttya 
Current language: auto; currently asm 

(gdb) load 
.text   : 0xa0100000 .. 0xa01069c0 
.rodata : 0xa01069c0 .. 0xa0106df0 
.reginfo: 0xa0106df0 .. 0xa0106e08 
.data   : 0xa0107380 .. 0xa01079d0 
.lit8   : 0xa01079d0 .. 0xa0107a60 
.sdata  : 0xa0107a60 .. 0xa0107b00 

(gdb) break main 
Breakpoint 1 at 0xa01001b0: file hello.c, line 15. 

(gdb) run 
Starting program: /tmp/hello.xl 
Breakpoint 1, main () at hello.c:15 
15        a = 3; 
Current language: auto; currently c 

(gdb) print a 
$1 = 0 

(gdb) step 
16        b = 4; 

(gdb) print a 
$2 = 3 

(gdb) list 
11      int main() 
12      { 
13      int b; 
14 
15        a = 3; 
16        b = 4; 
17        printf("Hello, world!\n"); 
18        foo(b); 
19        return 0; 
20      } 

(gdb) list foo 
1      #include <stdio.h> 
2 
3      int a, c; 
4 
5      void foo(int b) 
6      { 
7        c = a + b; 
8        printf("%d + %d = %d\n", a, b, c); 
9      } 
10 

(gdb) break 7 
Breakpoint 2 at 0xa0100144: file hello.c, line 7. 

(gdb) continue 
Continuing. 
Hello, world! 
Breakpoint 2, foo (b=4) at hello.c:7 
7         c = a + b; 

(gdb) step 
8         printf("%d + %d = %d\n", a, b, c); 

(gdb) print c 
$3 = 7 

(gdb) next 
3 + 4 = 7 
9       } 

(gdb) backtrace 
#0 foo (b=4) at hello.c:9 
#1 0xa01001e0 in main () at hello.c:18 
#2 0xa01058f8 in __do_main () at ../../../../../libgloss/mips/../do_main.c:12 

(gdb) quit 

% 

The ‘-nw’ option selects the command line interface to the GDB (GNU debugger), which is useful for making transcripts such as the one above. The
‘
-nw’ option is also useful when you wish to report a bug in GDB, because a sequence of commands is simpler to reproduce. If you are running an X11 based server and your ‘DISPLAY’ environment variable is set, GDB will start the GNUPro ‘gdbtk’ interface by default.

5. Assembler listing from source code

The following command produces an assembler listing:

% mips64vr4300-elf-gcc -g -O2 -Wa,-alh,-L -c hello.c

The assembler option ‘-alh’ requests a listing with high-level language and assembler language interspersed, ‘-L’ preserves local labels, while the compiler debugging option ‘-g’ gives the assembler the necessary debugging information. The ‘-O2’ option produces better looking code output.

Here is a partial excerpt of the output. In the following listing, the source lines are shown by ‘****’ .The ‘.stabn’ lines are part of symbolic debugging information, and you may ignore them.

14:hello.c         **** 
15:hello.c         ****     a = 3; 
130                             .stabn 68,0,15,$LM8 
131 0044 24020003               li      $2,3     # 0x00000003 
132                       $LM9: 
16:hello.c         ****    b = 4; 
17:hello.c         ****    printf("Hello, world!\n"); 
133                            .stabn 68,0,17,$LM9 
134 0048 3C040000              lui      $4,%hi($LC1) # high 
135                       $LM10: 
136                            .stabn 68,0,15,$LM10 
137 004c AF820000              sw $2,a 
138                       $LM11: 
139                            .stabn 68,0,17,$LM11 
140                            .set noreorder 
141                            .set nomacro 
142 0050 0C000000              jal printf 
143 0054 24840010              addiu $4,$4,%lo($LC1) # low 
144                            .set macro 
145                            .set reorder 
146