OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_62/] [or1ksim/] [README.gdb] - Blame information for rev 154

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 147 chris
Originally by Chris Ziomkowski 
2
Brief introduction to using GDB based debugging with or1ksim
3
 
4
GDB uses the JTAG proxy server included in or1ksim to communicate
5
directly with the simulator. Only 1 connection is allowed to the
6
proxy server at a time. Attempting a second connection will terminate
7
the previous connection. This is very useful when the gdb or1k
8
process terminates abnormally (such as when you are debugging the
9
debugger.) In this case it is impossible to notify the JTAG server
10
that the socket has shut down, and therefore it will assume that a
11
new connection implies the termination of the previous process.
12
 
13
The or1ksim will start the JTAG proxy server on the port specified
14
for service "jtag". If such a service is not specified, the server
15
will choose a random port number. This behavior can be overridden by
16
specifying the port number to the simulator using the -srv option.
17
As an example, "sim -srv 9999" starts up the simulator with the
18
JTAG proxy server on port 9999. This behavior is useful for those
19
people who do not have root access and can not add services to
20
the config files (such as university students operating in a shared
21
environment.)
22
 
23
As the JTAG proxy server runs only if there is data available for
24
reading, there is very little resource usage consumed by this
25
capability. However, in certain instances where gdb is not being
26
utilized, it is possible to disable the JTAG proxy server
27
entirely.  This will recover the few cycles necessary for the
28
poll() system call. (Tests indicate this has a negligible to
29
non existant impact on speed, however your mileage may vary.)
30
This behavior can be achieved by starting the simulator with
31
the command "sim -nosrv."
32
 
33
At startup, the simulator will execute random commands, just as
34
a real chip would do performing in this environment if the memory
35
was not initialized. If it is desired to simulate a ROM or FLASH
36
environment, these can be approximated by using the -loadmem option
37
to the simulator. For example, to simulate a 32k flash at location
38
0x8000, the command "sim -loadmem@0x8000 " could be
39
used, where  represents the name of the initialization
40
file. If the optional '@0x8000' flag is left off of the loadmem
41
statement, then the load will occur at location 0. Several loadmem
42
flags can appear on the command line to simulate different
43
memory blocks.
44
 
45
It is also possible to initialize all RAM to a predefined value,
46
which is usually 0x00000000 or 0xFFFFFFFF. This would be equivalent
47
to what is normally observed in a real world environment. However,
48
specific sequences are possible in case this is necessary. Alternatively,
49
random values can be assigned to memory, to check the behavior of a
50
process under different conditions. All of these options can be
51
handled by the "-initmem" option of the simulator. The following
52
command would startup the simulator with all memory initialized to
53
"1":
54
 
55
sim -initmem 0xFFFFFFFF
56
 
57
while this command would generate random values:
58
 
59
sim -initmem random
60
 
61
Once the simulator is started, it will print out something like
62
the following:
63
 
64
> bash-2.03$ sim
65
> JTAG Proxy server started on port 42240
66
> Machine initialization...
67
> Data cache tag: physical
68
> Insn cache tag: physical
69
> BPB simulation on.
70
> BTIC simulation on.
71
> Clock cycle: 4 ns
72
> RAM: 0x0 to 0x7aa80 (490 KB)
73
>
74
> simdebug off, interactive prompt off
75
> Building automata... done, num uncovered: 0/216.
76
> Parsing operands data... done.
77
> Resetting 4 UART(s).
78
> UART0 has problems with RX file stream.
79
> Resetting Tick Timer.
80
> Resetting Power Management.
81
> Resetting PIC.
82
> Exception 0x100 (Reset): Iqueue[0].insn_addr: 0x0  Eff ADDR: 0x0
83
>  pc: 0x0  pcnext: 0x4
84
>
85
 
86
Note that because we did not specify a server port, a random
87
port (42240) was selected for us (The "jtag" service does not
88
exist on this machine). We will need this value to create the
89
connection URL for the target command. It is now possible to
90
debug a program with gdb as follows:
91
 
92
> bash-2.03$ gdb
93
> GNU gdb 5.0
94
> Copyright 2000 Free Software Foundation, Inc.
95
> GDB is free software, covered by the GNU General Public License, and you are
96
> welcome to change it and/or distribute copies of it under certain conditions.
97
> Type "show copying" to see the conditions.
98
> There is absolutely no warranty for GDB.  Type "show warranty" for details.
99
> This GDB was configured as "--host=sparc-sun-solaris2.7 --target=or32-rtems".
100
> (or1k) file "dhry.or32"
101
> Reading symbols from dhry.or32...done.
102
> (or1k) target jtag jtag://localhost:42240
103
> Remote or1k debugging using jtag://localhost:42240
104
> 0x0 in ?? ()
105
> (or1k) load dhry.or32
106
> Loading section .text, size 0x14fc lma 0x100
107
> Loading section .data, size 0x2804 lma 0x15fc
108
> Start address 0x100 , load size 15616
109
> Transfer rate: 124928 bits/sec, 488 bytes/write.
110
> (or1k) b main
111
> Breakpoint 1 at 0x51c: file dhry.c, line 176.
112
> (or1k) run
113
> Starting program: /usr3/home/chris/opencores/or1k/gdb-build/gdb/dhry.or32
114
>
115
> Breakpoint 1, main () at dhry.c:176
116
> 176       Next_Ptr_Glob = (Rec_Pointer) &x;
117
> (or1k)
118
 
119
The simulator window will have printed out the following, showing that
120
a breakpoint exception was asserted.
121
 
122
> Exception 0xd00 (Break): Iqueue[0].insn_addr: 0x51c  Eff ADDR: 0x0
123
> pc: 0x51c  pcnext: 0x520
124
 
125
Note that when the "run" command is given, the simulator will start
126
by jumping to the reset vector at location 0x100. You must start off
127
by placing a small bootloader at this location. A simple environment
128
capable of running C programs can be established by placing the
129
following code in a file called "start.s" and linking it to your
130
executable. As an example, the following will work. The file start.s
131
was derived from the output of a file start.c compiled by gcc:
132
 
133
or32-rtems-gcc -g -c -o start.o start.s
134
or32-rtems-gcc -g -c -DOR1K -o dhry.o dhry.c
135 154 chris
or32-rtems-ld -Ttext 0x0 -o dhry.or32 start.o dhry.o
136 147 chris
 
137
---------------------- CUT HERE -------------------------
138
 
139
# file start.s
140
.file   "start.s"
141
 
142
# This is the general purpose start routine. It
143
# sets up the stack register, and jumps to the
144
# _main program location. It should be linked at
145
# the start of all programs.
146
 
147
.text
148 154 chris
        .align  4
149
        .org    0x100                   # The reset routine goes at 0x100
150 147 chris
.proc _rst
151
        .def    _rst
152
        .val    _rst
153
        .scl    2
154
        .type   041
155
        .endef
156
        .global _rst
157
_rst:
158
        .def    .bf
159
        .val    .
160
        .scl    101
161
        .endef
162 154 chris
        l.addi          r1,r0,0x7f00    # Set STACK to value 0x7f00
163
        l.addi          r2,r1,0x0       # FRAME and STACK are the same
164
        l.mfspr         r3,r0,17        # Get SR value
165
        l.ori           r3,r3,2         # Set exception enable bit
166
        l.jal           _main           # Jump to main routine
167
        l.mtspr         r0,r3,17        # Enable exceptions (DELAY SLOT)
168 147 chris
 
169
.endproc _rst
170
        .def    _rst
171
        .val    .
172
        .scl    -1
173
        .endef
174
 
175 154 chris
        .org    0xFFC
176
        l.nop                           # Guarantee the exception vector space
177
                                        # does not have general purpose code
178
 
179
# C code starts at 0x1000
180
 
181 147 chris
---------------------- CUT HERE -------------------------

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.