1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 1988-2021 Free Software Foundation, Inc.
4
5Permission is granted to copy, distribute and/or modify this document
6under the terms of the GNU Free Documentation License, Version 1.3 or
7any later version published by the Free Software Foundation; with the
8Invariant Sections being "Free Software" and "Free Software Needs
9Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
10and with the Back-Cover Texts as in (a) below.
11
12(a) The FSF's Back-Cover Text is: "You are free to copy and modify
13this GNU Manual.  Buying copies from GNU Press supports the FSF in
14developing GNU and promoting software freedom." -->
15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
16<head>
17<title>Debugging with GDB: Bootstrapping</title>
18
19<meta name="description" content="Debugging with GDB: Bootstrapping">
20<meta name="keywords" content="Debugging with GDB: Bootstrapping">
21<meta name="resource-type" content="document">
22<meta name="distribution" content="global">
23<meta name="Generator" content="makeinfo">
24<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
25<link href="index.html#Top" rel="start" title="Top">
26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
28<link href="Remote-Stub.html#Remote-Stub" rel="up" title="Remote Stub">
29<link href="Debug-Session.html#Debug-Session" rel="next" title="Debug Session">
30<link href="Stub-Contents.html#Stub-Contents" rel="previous" title="Stub Contents">
31<style type="text/css">
32<!--
33a.summary-letter {text-decoration: none}
34blockquote.smallquotation {font-size: smaller}
35div.display {margin-left: 3.2em}
36div.example {margin-left: 3.2em}
37div.indentedblock {margin-left: 3.2em}
38div.lisp {margin-left: 3.2em}
39div.smalldisplay {margin-left: 3.2em}
40div.smallexample {margin-left: 3.2em}
41div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
42div.smalllisp {margin-left: 3.2em}
43kbd {font-style:oblique}
44pre.display {font-family: inherit}
45pre.format {font-family: inherit}
46pre.menu-comment {font-family: serif}
47pre.menu-preformatted {font-family: serif}
48pre.smalldisplay {font-family: inherit; font-size: smaller}
49pre.smallexample {font-size: smaller}
50pre.smallformat {font-family: inherit; font-size: smaller}
51pre.smalllisp {font-size: smaller}
52span.nocodebreak {white-space:nowrap}
53span.nolinebreak {white-space:nowrap}
54span.roman {font-family:serif; font-weight:normal}
55span.sansserif {font-family:sans-serif; font-weight:normal}
56ul.no-bullet {list-style: none}
57-->
58</style>
59
60
61</head>
62
63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
64<a name="Bootstrapping"></a>
65<div class="header">
66<p>
67Next: <a href="Debug-Session.html#Debug-Session" accesskey="n" rel="next">Debug Session</a>, Previous: <a href="Stub-Contents.html#Stub-Contents" accesskey="p" rel="previous">Stub Contents</a>, Up: <a href="Remote-Stub.html#Remote-Stub" accesskey="u" rel="up">Remote Stub</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
68</div>
69<hr>
70<a name="What-You-Must-Do-for-the-Stub"></a>
71<h4 class="subsection">20.5.2 What You Must Do for the Stub</h4>
72
73<a name="index-remote-stub_002c-support-routines"></a>
74<p>The debugging stubs that come with <small>GDB</small> are set up for a particular
75chip architecture, but they have no information about the rest of your
76debugging target machine.
77</p>
78<p>First of all you need to tell the stub how to communicate with the
79serial port.
80</p>
81<dl compact="compact">
82<dt><code>int getDebugChar()</code></dt>
83<dd><a name="index-getDebugChar"></a>
84<p>Write this subroutine to read a single character from the serial port.
85It may be identical to <code>getchar</code> for your target system; a
86different name is used to allow you to distinguish the two if you wish.
87</p>
88</dd>
89<dt><code>void putDebugChar(int)</code></dt>
90<dd><a name="index-putDebugChar"></a>
91<p>Write this subroutine to write a single character to the serial port.
92It may be identical to <code>putchar</code> for your target system; a
93different name is used to allow you to distinguish the two if you wish.
94</p></dd>
95</dl>
96
97<a name="index-control-C_002c-and-remote-debugging"></a>
98<a name="index-interrupting-remote-targets"></a>
99<p>If you want <small>GDB</small> to be able to stop your program while it is
100running, you need to use an interrupt-driven serial driver, and arrange
101for it to stop when it receives a <code>^C</code> (&lsquo;<samp>\003</samp>&rsquo;, the control-C
102character).  That is the character which <small>GDB</small> uses to tell the
103remote system to stop.
104</p>
105<p>Getting the debugging target to return the proper status to <small>GDB</small>
106probably requires changes to the standard stub; one quick and dirty way
107is to just execute a breakpoint instruction (the &ldquo;dirty&rdquo; part is that
108<small>GDB</small> reports a <code>SIGTRAP</code> instead of a <code>SIGINT</code>).
109</p>
110<p>Other routines you need to supply are:
111</p>
112<dl compact="compact">
113<dt><code>void exceptionHandler (int <var>exception_number</var>, void *<var>exception_address</var>)</code></dt>
114<dd><a name="index-exceptionHandler"></a>
115<p>Write this function to install <var>exception_address</var> in the exception
116handling tables.  You need to do this because the stub does not have any
117way of knowing what the exception handling tables on your target system
118are like (for example, the processor&rsquo;s table might be in <small>ROM</small>,
119containing entries which point to a table in <small>RAM</small>).
120The <var>exception_number</var> specifies the exception which should be changed;
121its meaning is architecture-dependent (for example, different numbers
122might represent divide by zero, misaligned access, etc).  When this
123exception occurs, control should be transferred directly to
124<var>exception_address</var>, and the processor state (stack, registers,
125and so on) should be just as it is when a processor exception occurs.  So if
126you want to use a jump instruction to reach <var>exception_address</var>, it
127should be a simple jump, not a jump to subroutine.
128</p>
129<p>For the 386, <var>exception_address</var> should be installed as an interrupt
130gate so that interrupts are masked while the handler runs.  The gate
131should be at privilege level 0 (the most privileged level).  The
132<small>SPARC</small> and 68k stubs are able to mask interrupts themselves without
133help from <code>exceptionHandler</code>.
134</p>
135</dd>
136<dt><code>void flush_i_cache()</code></dt>
137<dd><a name="index-flush_005fi_005fcache"></a>
138<p>On <small>SPARC</small> and <small>SPARCLITE</small> only, write this subroutine to flush the
139instruction cache, if any, on your target machine.  If there is no
140instruction cache, this subroutine may be a no-op.
141</p>
142<p>On target machines that have instruction caches, <small>GDB</small> requires this
143function to make certain that the state of your program is stable.
144</p></dd>
145</dl>
146
147<p>You must also make sure this library routine is available:
148</p>
149<dl compact="compact">
150<dt><code>void *memset(void *, int, int)</code></dt>
151<dd><a name="index-memset"></a>
152<p>This is the standard library function <code>memset</code> that sets an area of
153memory to a known value.  If you have one of the free versions of
154<code>libc.a</code>, <code>memset</code> can be found there; otherwise, you must
155either obtain it from your hardware manufacturer, or write your own.
156</p></dd>
157</dl>
158
159<p>If you do not use the GNU C compiler, you may need other standard
160library subroutines as well; this varies from one stub to another,
161but in general the stubs are likely to use any of the common library
162subroutines which <code><small>GCC</small></code> generates as inline code.
163</p>
164
165<hr>
166<div class="header">
167<p>
168Next: <a href="Debug-Session.html#Debug-Session" accesskey="n" rel="next">Debug Session</a>, Previous: <a href="Stub-Contents.html#Stub-Contents" accesskey="p" rel="previous">Stub Contents</a>, Up: <a href="Remote-Stub.html#Remote-Stub" accesskey="u" rel="up">Remote Stub</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
169</div>
170
171
172
173</body>
174</html>
175