-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME-sh4-7750dc
292 lines (200 loc) · 8.43 KB
/
README-sh4-7750dc
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
$Id: README-sh4-7750dc,v 1.1.1.1 2002/03/19 02:53:13 bgat Exp $
Procedure for compiling, linking and
installing gdbstubs on the Sega Dreamcast.
Copyright (c) 1999 by William A. Gatliff
All rights reserved. bgat@open-widgets.com
See the file COPYING for details.
This file is provided "as-is", and without any express
or implied warranties, including, without limitation,
the implied warranties of merchantability and fitness
for a particular purpose.
The author welcomes feedback regarding this file.
SH-4 support added by Benoit Miller (fulg@iname.com).
Support for Sega Dreamcast(tm) added by Benoit Miller.
Disclaimer
----------
This stub is in no way associated with nor endorsed by Sega.
All information herein is presented AS-IS, and is at your
own risk. "SEGA" and "DREAMCAST" are registered trademarks
of Sega Enterprises, Ltd.
Table of contents
-----------------
1. Quick instructions
2. Detailed instructions
3. Making a gdbstub DC boot disk
4. Things to know
5. Extra Credits
6. Final words
-----------------
1. Quickstart
=============
- Compile the stub. (hint: 'make sh4-7750dc.srec')
- Boot your Dreamcast with the serial slave CD
- Upload 'sh4-7750dc.srec' to the Dreamcast
- Connect with gdb at 57600bps 8N1.
- Enjoy =)
2. Detailed Instructions
========================
Compiling the stub for Dreamcast
--------------------------------
This step is fairly straightforward. First, open up the makefile
in your favorite editor and change TARGET to match your target
type. For Dreamcast, you want to uncomment the line that says:
TARGET=sh-elf
Now save the file, exit your editor, and type:
make clean sh4-7750dc.srec
to generate the S-record file needed by the next step.
Boot your Dreamcast with the serial slave CD
--------------------------------------------
Again, this should be easy enough. If you don't have the boot disk,
you can find instructions on how to make one yourself here:
http://mc.pp.se/dc/serslave.html
If you run Windows instead of Linux, you can find better-suited
instructions here:
http://www3.sympatico.ca/fulg
Explaining how the slave works (and how to make it) is not the
purpose of this file, the links given above should contain
enough information to get you up and running in no time.
Upload 'sh4-7750dc.srec' to the Dreamcast
-----------------------------------------
Should be self-explanatory. Use your favorite terminal program to
upload the file. Once the stub replies with 'OK', the sides of the
screen will turn green, indicating that the stub is running.
Connect with gdb at 57600bps 8N1
--------------------------------
I've had no luck with faster baudrates, if you feel lucky, you
can change the baudrate value in sh4-7750dc.c.
Make sure your .gdbinit file (or gdb.ini under Windows) contains
the following two lines:
set endian little
set remotebaud 57600
Also note that gdbstub will reside somewhere in the upper memory area
of the Dreamcast (namely, from 0x8ce0b800-0x8ce0ffff). If you want to
change this behavior, read on...
3. Making a gdbstub DC boot disk
================================
if you intend to put gdbstub on a bootable CD (I highly recommend it!),
I've included a special linker command file for that purpose.
The binary image of gdbstubs is small enough to be included entirely
in the bootstrap portion of the IP.BIN. This has the added advantage
that the memory layout used by gdbstub does not touch anything in the
normal program range (eg anything from 0x8c010000 and up).
You'll need to edit the Makefile, and find the line that starts with
"sh4-7750dc.out:". Directly under it, look for this option:
-Wl,-T$(basename $@)-ram.cmd
^^^
and change it to
-Wl,-T$(basename $@)-cdrom.cmd
^^^^^
We need a pure binary file for the CD, so build it now by typing:
make clean sh4-7750dc.bin
This will create the binary file, ready to put into an IP.BIN.
If the build fails, make sure that optimizations are turned on
(CCFLAGS=-O2...) in the Makefile, or else the binary image will
not fit in the tiny space reserved for bootstraps.
Create your own IP.BIN (I used the one from the serial slave
CD as a template), then insert gdbstub to replace the internal
bootstrapping code at offset 0x6000:
dd if=ip.bin bs=1024 count=24 >tmp.bin
cat tmp.bin sh4-7750dc.bin >ipstub.bin
Then use the instructions to make a serial slave boot CD (links
given above), but use this new IPSTUB.BIN instead of the usual
IP.BIN.
4. Things to know
=================
There are still issues with the stub if you try to step
past the end of your program (eg past the end of main()).
Since this behavior would normally reset the Dreamcast
(because there is no operating system), I haven't tried
really hard to fix it. The stub will try to reset itself
but will behave erratically from that point on...
Also, note that the current version will not try to switch
to its own stack while debugging. In reality this is no
big deal (since gdbstub will write "below" your current sp)
but it can possibly change the behavior of a broken debugged
program. More specifically, if you have uninitialized
local variables on the stack, the initial value of that
variable may be different while debugging.
In other words, gdbstub is not yet debuggee-stack-clean.
This is not supposed to be a big deal in almost any scenario
(relying on the state of the stack is bad practice!), but it's
something to be aware of.
5. Extra Credits
================
This SH-4 port would not be possible without the generous (though
indirect) contributions of other people's open source work:
The cache clearing routine (gdb_flush_cache), the escaped-binary
decoding routine (ebin_to_mem), and the SCIF init procedure
were either based on or directly taken from the existing sh-stub
done by the SH-Linux team (http://www.sh-linux.org/ and
http://www.m17n.org/linux-sh/).
The stub initialization code (set_debug_traps) was originally
from Dan Potter (bard@allusion.net).
The piece of assembly code that computes the proper SCBRR2
value from a baud rate was originally written by Marcus Comstedt
(marcus@idonex.se).
6. Final words
==============
If you need more details, you can always try to email me
(fulg@iname.com) and I'll be happy to help. I'd also be
interested to know if anyone manages to find a simpler way
to put this on a bootable CD... =)
Cheers,
--
Benoit Miller - fulg@iname.com
"There is no spoon."
#
# Copyright (c) 2001 by William A. Gatliff
# All rights reserved. bgat@billgatliff.com
#
# See the file COPYING for details.
#
# This file is provided "as-is", and without any express
# or implied warranties, including, without limitation,
# the implied warranties of merchantability and fitness
# for a particular purpose.
#
# The author welcomes feedback regarding this file.
#
# $Id: README-sh4-7750dc,v 1.1.1.1 2002/03/19 02:53:13 bgat Exp $
Wow, this needs work.
To build for sh2-7045edk:
sh-elf-gcc -g -DCRT0 -DSH2_7045EDK -nostartfiles -Wl,--script=sh2-edk.ld \
gdb.c sh2.c sh2-edk.c
What I would like:
CROSS_COMPILE=sh-elf- TARGET=SH2_7045EDK make gdbstub.lib
CROSS_COMPILE=sh-elf- TARGET=SH2_7045EDK make gdbstub
[bgat@mars gdbstubs]$ rm -f a.out a.s19; m68k-elf-gcc -mcpu32 -Wall -g -DCRT0 -DSMC1UART -nostartfiles -Wl,--script=cpu32-mc68360.ld gdb.c cpu32.c cpu32-mc68360.c && m68k-elf-objcopy -O srec a.out a.s19
maybe:
if TARGET=SH2_7045EDK
objs = gdb.o sh2.o sh2-edk.o
cflags = -O2 -Wall -I. -DSH2_7045EDK
For the "gdbstub" target, (sh-elf-gdbstub?) add -DCRT0; omit for gdbstub.lib
***
CC=$(CROSS_COMPILE)gcc $(COMMON_CFLAGS)
LD=$(CROSS_COMPILE)ld
AS=$(CROSS_COMPILE)as
AR=$(CROSS_COMPILE)ar
OBJCOPY=$(CROSS_COMPILE)objcopy
COMMON_CFLAGS = -O2 -Wall -I.
# Hitachi SH2 architecture, various platforms
# -DSH2_7045EDK -- sh2 7045edk platform
SH2_7045EDK=gdb.c sh2.c sh2edk.c
sh2-7045edk.out: $(SH2_7045EDK)
$(CC) -m2 -Wl,-T$(basename $@).cmd -nostartfiles \
-Wl,-M -Wl,-Map=$(basename $@).map -Wl,--cref \
-Wl,--output=$@ $(SH2_7045EDK)
# Hitachi SH4 architecture, Sega Dreamcast platform
SH4_7750DC=sh4-7750dc.c sh4-775x.c gdb.c
sh4-7750dc.srec: sh4-7750dc.out
$(OBJCOPY) -S -j .text -j .except \
-O srec sh4-7750dc.out $@
sh4-7750dc.bin: sh4-7750dc.out
$(OBJCOPY) -S -j .text -j .except \
-O binary sh4-7750dc.out $@
sh4-7750dc.out: $(SH4_7550DC)
$(CC) -m4 -ml -Wl,-T$(basename $@)-ram.cmd -nostartfiles \
-Wl,-M -Wl,-Map=$(basename $@).map -Wl,--cref \
-Wl,--output=$@ $(SH4_7750DC)
clean:
-rm -rf *.out *.bin *.srec *.o