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