Whamcloud - gitweb
land clio.
[fs/lustre-release.git] / lustre / kernel_patches / patches / kgdb-2.6.18-vanilla.patch
1 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/Documentation/DocBook/Makefile linux-2.6.18.kgdb/Documentation/DocBook/Makefile
2 --- linux-2.6.18/Documentation/DocBook/Makefile 2006-09-20 07:42:06.000000000 +0400
3 +++ linux-2.6.18.kgdb/Documentation/DocBook/Makefile    2008-06-10 16:18:58.000000000 +0400
4 @@ -11,7 +11,7 @@ DOCBOOKS := wanbook.xml z8530book.xml mc
5             procfs-guide.xml writing_usb_driver.xml \
6             kernel-api.xml journal-api.xml lsm.xml usb.xml \
7             gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \
8 -           genericirq.xml
9 +           genericirq.xml kgdb.xml
10  
11  ###
12  # The build process is as follows (targets):
13 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/Documentation/DocBook/kgdb.tmpl linux-2.6.18.kgdb/Documentation/DocBook/kgdb.tmpl
14 --- linux-2.6.18/Documentation/DocBook/kgdb.tmpl        1970-01-01 03:00:00.000000000 +0300
15 +++ linux-2.6.18.kgdb/Documentation/DocBook/kgdb.tmpl   2008-06-10 16:19:47.000000000 +0400
16 @@ -0,0 +1,250 @@
17 +<?xml version="1.0" encoding="UTF-8"?>
18 +<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
19 +       "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
20 +
21 +<book id="kgdbInternals">
22 + <bookinfo>
23 +  <title>KGDB Internals</title>
24 +
25 +  <authorgroup>
26 +   <author>
27 +    <firstname>Tom</firstname>
28 +    <surname>Rini</surname>
29 +    <affiliation>
30 +     <address>
31 +      <email>trini@kernel.crashing.org</email>
32 +     </address>
33 +    </affiliation>
34 +   </author>
35 +  </authorgroup>
36 +
37 +  <authorgroup>
38 +   <author>
39 +    <firstname>Amit S.</firstname>
40 +    <surname>Kale</surname>
41 +    <affiliation>
42 +     <address>
43 +      <email>amitkale@linsyssoft.com</email>
44 +     </address>
45 +    </affiliation>
46 +   </author>
47 +  </authorgroup>
48 +
49 +  <copyright>
50 +   <year>2004-2005</year>
51 +   <holder>MontaVista Software, Inc.</holder>
52 +  </copyright>
53 +  <copyright>
54 +   <year>2004</year>
55 +   <holder>Amit S. Kale</holder>
56 +  </copyright>
57 +
58 +  <legalnotice>
59 +   <para>
60 +   This file is licensed under the terms of the GNU General Public License
61 +   version 2. This program is licensed "as is" without any warranty of any
62 +   kind, whether express or implied.
63 +   </para>
64 +
65 +  </legalnotice>
66 + </bookinfo>
67 +
68 +<toc></toc>
69 +  <chapter id="Introduction">
70 +    <title>Introduction</title>
71 +    <para>
72 +    kgdb is a source level debugger for linux kernel. It is used along
73 +    with gdb to debug a linux kernel. Kernel developers can debug a kernel
74 +    similar to application programs with the use of kgdb. It makes it
75 +    possible to place breakpoints in kernel code, step through the code
76 +    and observe variables.
77 +    </para>
78 +    <para>
79 +    Two machines are required for using kgdb. One of these machines is a
80 +    development machine and the other is a test machine. The machines are
81 +    typically connected through a serial line, a null-modem cable which
82 +    connects their serial ports.  It is also possible however, to use an
83 +    ethernet connection between the machines.  The kernel to be debugged
84 +    runs on the test machine. gdb runs on the development machine. The
85 +    serial line or ethernet connection is used by gdb to communicate to
86 +    the kernel being debugged.
87 +    </para>
88 +  </chapter>
89 +  <chapter id="CompilingAKernel">
90 +    <title>Compiling a kernel</title>
91 +    <para>
92 +    To enable <symbol>CONFIG_KGDB</symbol>, look under the "Kernel debugging"
93 +    and then select "KGDB: kernel debugging with remote gdb".
94 +    </para>
95 +    <para>
96 +    The first choice for I/O is <symbol>CONFIG_KGDB_ONLY_MODULES</symbol>.
97 +    This means that you will only be able to use KGDB after loading a
98 +    kernel module that defines how you want to be able to talk with
99 +    KGDB.  There are two other choices (more on some architectures) that
100 +    can be enabled as modules later, if not picked here.
101 +    </para>
102 +    <para>The first of these is <symbol>CONFIG_KGDB_8250_NOMODULE</symbol>.
103 +    This has sub-options such as <symbol>CONFIG_KGDB_SIMPLE_SERIAL</symbol>
104 +    which toggles choosing the serial port by ttyS number or by specifying
105 +    a port and IRQ number.
106 +    </para>
107 +    <para>
108 +    The second of these choices on most systems for I/O is
109 +    <symbol>CONFIG_KGDBOE</symbol>. This requires that the machine to be
110 +    debugged has an ethernet card which supports the netpoll API, such as
111 +    the cards supported by <symbol>CONFIG_E100</symbol>.  There are no
112 +    sub-options for this, but a kernel command line option is required.
113 +    </para>
114 +  </chapter>
115 +  <chapter id="BootingTheKernel">
116 +    <title>Booting the kernel</title>
117 +    <para>
118 +    The Kernel command line option <constant>kgdbwait</constant> makes kgdb
119 +    wait for gdb connection during booting of a kernel.  If the
120 +    <symbol>CONFIG_KGDB_8250</symbol> driver is used (or if applicable,
121 +    another serial driver) this breakpoint will happen very early on, before
122 +    console output.  If you wish to change serial port information and you
123 +    have enabled both <symbol>CONFIG_KGDB_8250</symbol> and
124 +    <symbol>CONFIG_KGDB_SIMPLE_SERIAL</symbol> then you must pass the option
125 +    <constant>kgdb8250=&lt;io or mmio&gt;,&lt;address&gt;,&lt;baud
126 +    rate&gt;,&lt;irq&gt;</constant> before <constant>kgdbwait</constant>.
127 +    The values <constant>io</constant> or <constant>mmio</constant> refer to
128 +    if the address being passed next needs to be memory mapped
129 +    (<constant>mmio</constant>) or not. The <constant>address</constant> must
130 +    be passed in hex and is the hardware address and will be remapped if
131 +    passed as <constant>mmio</constant>. The value
132 +    <constant>baud rate</constant> and <constant>irq</constant> are base-10.
133 +    The supported values for <constant>baud rate</constant> are
134 +    <constant>9600</constant>, <constant>19200</constant>,
135 +    <constant>38400</constant>, <constant>57600</constant>, and
136 +    <constant>115200</constant>.
137 +    </para>
138 +    <para>
139 +    To have KGDB stop the kernel and wait, with the compiled values for the
140 +    serial driver, pass in: <constant>kgdbwait</constant>.
141 +    </para>
142 +    <para>
143 +    To specify the values of the SH SCI(F) serial port at boot:
144 +    <constant>kgdbsci=0,115200</constant>.
145 +    </para>
146 +    <para>
147 +    To specify the values of the serial port at boot:
148 +    <constant>kgdb8250=io,3f8,115200,3</constant>.
149 +    On IA64 this could also be:
150 +    <constant>kgdb8250=mmio,0xff5e0000,115200,74</constant>
151 +    And to have KGDB also stop the kernel and wait for GDB to connect, pass in
152 +    <constant>kgdbwait</constant> after this arguement.
153 +    </para>
154 +    <para>
155 +    To configure the <symbol>CONFIG_KGDBOE</symbol> driver, pass in
156 +    <constant>kgdboe=[src-port]@&lt;src-ip&gt;/[dev],[tgt-port]@&lt;tgt-ip&gt;/[tgt-macaddr]</constant>
157 +    where:
158 +    <itemizedlist>
159 +      <listitem><para>src-port (optional): source for UDP packets (defaults to <constant>6443</constant>)</para></listitem>
160 +      <listitem><para>src-ip: source IP to use (interface address)</para></listitem>
161 +      <listitem><para>dev (optional): network interface (<constant>eth0</constant>)</para></listitem>
162 +      <listitem><para>tgt-port (optional): port GDB will use (defaults to <constant>6442</constant>)</para></listitem>
163 +      <listitem><para>tgt-ip: IP address GDB will be connecting from</para></listitem>
164 +      <listitem><para>tgt-macaddr (optional): ethernet MAC address for logging agent (default is broadcast)</para></listitem>
165 +    </itemizedlist>
166 +    </para>
167 +    <para>
168 +    The <symbol>CONFIG_KGDBOE</symbol> driver can be reconfigured at run
169 +    time, if <symbol>CONFIG_SYSFS</symbol> and
170 +    <symbol>CONFIG_MODULES</symbol> by echo'ing a new config string to
171 +    <constant>/sys/module/kgdboe/parameter/kgdboe</constant>.  The
172 +    driver can be unconfigured with the special string
173 +    <constant>not_configured</constant>.
174 +    </para>
175 +  </chapter>
176 +  <chapter id="ConnectingGDB">
177 +  <title>Connecting gdb</title>
178 +    <para>
179 +    If you have used any of the methods to have KGDB stop and create
180 +    an initial breakpoint described in the previous chapter, kgdb prints
181 +    the message "Waiting for connection from remote gdb..." on the console
182 +    and waits for connection from gdb. At this point you connect gdb to kgdb.
183 +    </para>
184 +    <para>
185 +    Example (serial):
186 +    </para>
187 +    <programlisting>
188 +    % gdb ./vmlinux
189 +    (gdb) set remotebaud 115200
190 +    (gdb) target remote /dev/ttyS0
191 +    </programlisting>
192 +    <para>
193 +    Example (ethernet):
194 +    </para>
195 +    <programlisting>
196 +    % gdb ./vmlinux
197 +    (gdb) target remote udp:192.168.2.2:6443
198 +    </programlisting>
199 +    <para>
200 +    Once connected, you can debug a kernel the way you would debug an
201 +    application program.
202 +    </para>
203 +  </chapter>
204 +  <chapter id="ArchitectureNotes">
205 +    <title>Architecture specific notes</title>
206 +      <para>
207 +      SuperH: The NMI switch found on some boards can be used to trigger an
208 +      initial breakpoint.  Subsequent triggers do nothing.  If console
209 +      is enabled on the SCI(F) serial port, and that is the port being used
210 +      for KGDB, then you must trigger a breakpoint via sysrq, NMI, or
211 +      some other method prior to connecting, or echo a control-c to the
212 +      serial port.  Also, to use the SCI(F) port for KGDB, the
213 +      <symbol>CONFIG_SERIAL_SH_SCI</symbol> driver must be enabled.
214 +      </para>
215 +  </chapter>
216 +  <chapter id="CommonBackEndReq">
217 +    <title>The common backend (required)</title>
218 +      <para>
219 +      There are a few flags which must be set on every architecture in
220 +      their &lt;asm/kgdb.h&gt; file.  These are:
221 +      <itemizedlist>
222 +        <listitem>
223 +         <para>
224 +         NUMREGBYTES: The size in bytes of all of the registers, so
225 +         that we can ensure they will all fit into a packet.
226 +         </para>
227 +         <para>
228 +         BUFMAX: The size in bytes of the buffer GDB will read into.
229 +         This must be larger than NUMREGBYTES.
230 +         </para>
231 +         <para>
232 +         CACHE_FLUSH_IS_SAFE: Set to one if it always safe to call
233 +         flush_cache_range or flush_icache_range.  On some architectures,
234 +         these functions may not be safe to call on SMP since we keep other
235 +         CPUs in a holding pattern.
236 +         </para>
237 +       </listitem>
238 +      </itemizedlist>
239 +      </para>
240 +      <para>
241 +      There are also the following functions for the common backend,
242 +      found in kernel/kgdb.c that must be supplied by the
243 +      architecture-specific backend.  No weak version of these is provided.
244 +      </para>
245 +!Iinclude/linux/kgdb.h
246 +  </chapter>
247 +  <chapter id="CommonBackEndOpt">
248 +    <title>The common backend (optional)</title>
249 +      <para>
250 +      These functions are part of the common backend, found in kernel/kgdb.c
251 +      and are optionally implemented.  Some functions (with _hw_ in the name)
252 +      end up being required on arches which use hardware breakpoints.
253 +      </para>
254 +!Ikernel/kgdb.c
255 +  </chapter>
256 +  <chapter id="DriverSpecificFunctions">
257 +    <title>Driver-Specific Functions</title>
258 +      <para>
259 +      Some of the I/O drivers have additional functions that can be
260 +      called, that are specific to the driver.  Calls from other places
261 +      to these functions must be wrapped in #ifdefs for the driver in
262 +      question.
263 +      </para>
264 +!Idrivers/serial/8250_kgdb.c
265 +   </chapter>
266 +</book>
267 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/MAINTAINERS linux-2.6.18.kgdb/MAINTAINERS
268 --- linux-2.6.18/MAINTAINERS    2006-09-20 07:42:06.000000000 +0400
269 +++ linux-2.6.18.kgdb/MAINTAINERS       2008-06-10 16:18:58.000000000 +0400
270 @@ -1685,6 +1685,15 @@ L:       linux-kernel@vger.kernel.org
271  L:     fastboot@osdl.org
272  S:     Maintained
273  
274 +KGDB
275 +P:     Tom Rini
276 +P:     Amit S. Kale
277 +M:     trini@kernel.crashing.org
278 +M:     amitkale@linsyssoft.com
279 +W:     http://sourceforge.net/projects/kgdb
280 +L:     kgdb-bugreport@lists.sourceforge.net
281 +S:     Maintained
282 +
283  KPROBES
284  P:     Prasanna S Panchamukhi
285  M:     prasanna@in.ibm.com
286 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/Makefile linux-2.6.18.kgdb/Makefile
287 --- linux-2.6.18/Makefile       2006-09-20 07:42:06.000000000 +0400
288 +++ linux-2.6.18.kgdb/Makefile  2008-06-10 16:19:57.000000000 +0400
289 @@ -990,6 +990,7 @@ MRPROPER_DIRS  += include/config include
290  MRPROPER_FILES += .config .config.old include/asm .version .old_version \
291                    include/linux/autoconf.h include/linux/version.h      \
292                    include/linux/utsrelease.h                            \
293 +                 include/linux/dwarf2-defs.h                           \
294                   Module.symvers tags TAGS cscope*
295  
296  # clean - Delete most, but leave enough to build external modules
297 @@ -1416,7 +1417,11 @@ clean := -f $(if $(KBUILD_SRC),$(srctree
298  endif  # skip-makefile
299  
300  PHONY += FORCE
301 -FORCE:
302 +include/linux/dwarf2-defs.h: $(srctree)/include/linux/dwarf2.h $(srctree)/scripts/dwarfh.awk
303 +       mkdir -p include/linux/
304 +       awk -f $(srctree)/scripts/dwarfh.awk $(srctree)/include/linux/dwarf2.h > include/linux/dwarf2-defs.h
305 +
306 +FORCE: include/linux/dwarf2-defs.h
307  
308  
309  # Declare the contents of the .PHONY variable as phony.  We keep that
310 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/kernel/Makefile linux-2.6.18.kgdb/arch/arm/kernel/Makefile
311 --- linux-2.6.18/arch/arm/kernel/Makefile       2006-09-20 07:42:06.000000000 +0400
312 +++ linux-2.6.18.kgdb/arch/arm/kernel/Makefile  2008-06-10 16:19:51.000000000 +0400
313 @@ -20,6 +20,7 @@ obj-$(CONFIG_ISA_DMA)         += dma-isa.o
314  obj-$(CONFIG_PCI)              += bios32.o isa.o
315  obj-$(CONFIG_SMP)              += smp.o
316  obj-$(CONFIG_OABI_COMPAT)      += sys_oabi-compat.o
317 +obj-$(CONFIG_KGDB)             += kgdb.o kgdb-jmp.o
318  
319  obj-$(CONFIG_CRUNCH)           += crunch.o crunch-bits.o
320  AFLAGS_crunch-bits.o           := -Wa,-mcpu=ep9312
321 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/kernel/entry-armv.S linux-2.6.18.kgdb/arch/arm/kernel/entry-armv.S
322 --- linux-2.6.18/arch/arm/kernel/entry-armv.S   2006-09-20 07:42:06.000000000 +0400
323 +++ linux-2.6.18.kgdb/arch/arm/kernel/entry-armv.S      2008-06-10 16:19:58.000000000 +0400
324 @@ -15,6 +15,7 @@
325   *  it to save wrong values...  Be aware!
326   */
327  
328 +#include <asm/kgdb.h>
329  #include <asm/memory.h>
330  #include <asm/glue.h>
331  #include <asm/vfpmacros.h>
332 @@ -232,6 +233,7 @@ svc_preempt:
333         beq     preempt_return                  @ go again
334         b       1b
335  #endif
336 +       CFI_END_FRAME(__irq_svc)
337  
338         .align  5
339  __und_svc:
340 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/kernel/kgdb-jmp.S linux-2.6.18.kgdb/arch/arm/kernel/kgdb-jmp.S
341 --- linux-2.6.18/arch/arm/kernel/kgdb-jmp.S     1970-01-01 03:00:00.000000000 +0300
342 +++ linux-2.6.18.kgdb/arch/arm/kernel/kgdb-jmp.S        2008-06-10 16:19:51.000000000 +0400
343 @@ -0,0 +1,32 @@
344 +/*
345 + * arch/arm/kernel/kgdb-jmp.S
346 + *
347 + * Trivial setjmp and longjmp procedures to support bus error recovery
348 + * which may occur during kgdb memory read/write operations.
349 + *
350 + * Author: MontaVista Software, Inc. <source@mvista.com>
351 + *         source@mvista.com
352 + *
353 + * 2002-2005 (c) MontaVista Software, Inc.  This file is licensed under the
354 + * terms of the GNU General Public License version 2. This program as licensed
355 + * "as is" without any warranty of any kind, whether express or implied.
356 + */
357 +#include <linux/linkage.h>
358 +
359 +ENTRY (kgdb_fault_setjmp)
360 +       /* Save registers */
361 +       stmia   r0, {r0-r14}
362 +       str     lr,[r0, #60]
363 +       mrs     r1,cpsr
364 +       str     r1,[r0,#64]
365 +       ldr     r1,[r0,#4]
366 +       mov     r0, #0
367 +       mov     pc,lr
368 +
369 +ENTRY (kgdb_fault_longjmp)
370 +       /* Restore registers */
371 +       mov     r1,#1
372 +       str     r1,[r0]
373 +       ldr     r1,[r0, #64]
374 +       msr     spsr,r1
375 +       ldmia   r0,{r0-pc}^
376 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/kernel/kgdb.c linux-2.6.18.kgdb/arch/arm/kernel/kgdb.c
377 --- linux-2.6.18/arch/arm/kernel/kgdb.c 1970-01-01 03:00:00.000000000 +0300
378 +++ linux-2.6.18.kgdb/arch/arm/kernel/kgdb.c    2008-06-10 16:19:51.000000000 +0400
379 @@ -0,0 +1,208 @@
380 +/*
381 + * arch/arm/kernel/kgdb.c
382 + *
383 + * ARM KGDB support
384 + *
385 + * Copyright (c) 2002-2004 MontaVista Software, Inc
386 + *
387 + * Authors:  George Davis <davis_g@mvista.com>
388 + *           Deepak Saxena <dsaxena@plexity.net>
389 + */
390 +#include <linux/config.h>
391 +#include <linux/types.h>
392 +#include <linux/kernel.h>
393 +#include <linux/signal.h>
394 +#include <linux/sched.h>
395 +#include <linux/mm.h>
396 +#include <linux/spinlock.h>
397 +#include <linux/personality.h>
398 +#include <linux/ptrace.h>
399 +#include <linux/elf.h>
400 +#include <linux/interrupt.h>
401 +#include <linux/init.h>
402 +#include <linux/kgdb.h>
403 +
404 +#include <asm/atomic.h>
405 +#include <asm/io.h>
406 +#include <asm/pgtable.h>
407 +#include <asm/system.h>
408 +#include <asm/uaccess.h>
409 +#include <asm/unistd.h>
410 +#include <asm/ptrace.h>
411 +#include <asm/traps.h>
412 +
413 +/* Make a local copy of the registers passed into the handler (bletch) */
414 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *kernel_regs)
415 +{
416 +       int regno;
417 +
418 +       /* Initialize all to zero (??) */
419 +       for (regno = 0; regno < GDB_MAX_REGS; regno++)
420 +               gdb_regs[regno] = 0;
421 +
422 +       gdb_regs[_R0] = kernel_regs->ARM_r0;
423 +       gdb_regs[_R1] = kernel_regs->ARM_r1;
424 +       gdb_regs[_R2] = kernel_regs->ARM_r2;
425 +       gdb_regs[_R3] = kernel_regs->ARM_r3;
426 +       gdb_regs[_R4] = kernel_regs->ARM_r4;
427 +       gdb_regs[_R5] = kernel_regs->ARM_r5;
428 +       gdb_regs[_R6] = kernel_regs->ARM_r6;
429 +       gdb_regs[_R7] = kernel_regs->ARM_r7;
430 +       gdb_regs[_R8] = kernel_regs->ARM_r8;
431 +       gdb_regs[_R9] = kernel_regs->ARM_r9;
432 +       gdb_regs[_R10] = kernel_regs->ARM_r10;
433 +       gdb_regs[_FP] = kernel_regs->ARM_fp;
434 +       gdb_regs[_IP] = kernel_regs->ARM_ip;
435 +       gdb_regs[_SP] = kernel_regs->ARM_sp;
436 +       gdb_regs[_LR] = kernel_regs->ARM_lr;
437 +       gdb_regs[_PC] = kernel_regs->ARM_pc;
438 +       gdb_regs[_CPSR] = kernel_regs->ARM_cpsr;
439 +}
440 +
441 +/* Copy local gdb registers back to kgdb regs, for later copy to kernel */
442 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *kernel_regs)
443 +{
444 +       kernel_regs->ARM_r0 = gdb_regs[_R0];
445 +       kernel_regs->ARM_r1 = gdb_regs[_R1];
446 +       kernel_regs->ARM_r2 = gdb_regs[_R2];
447 +       kernel_regs->ARM_r3 = gdb_regs[_R3];
448 +       kernel_regs->ARM_r4 = gdb_regs[_R4];
449 +       kernel_regs->ARM_r5 = gdb_regs[_R5];
450 +       kernel_regs->ARM_r6 = gdb_regs[_R6];
451 +       kernel_regs->ARM_r7 = gdb_regs[_R7];
452 +       kernel_regs->ARM_r8 = gdb_regs[_R8];
453 +       kernel_regs->ARM_r9 = gdb_regs[_R9];
454 +       kernel_regs->ARM_r10 = gdb_regs[_R10];
455 +       kernel_regs->ARM_fp = gdb_regs[_FP];
456 +       kernel_regs->ARM_ip = gdb_regs[_IP];
457 +       kernel_regs->ARM_sp = gdb_regs[_SP];
458 +       kernel_regs->ARM_lr = gdb_regs[_LR];
459 +       kernel_regs->ARM_pc = gdb_regs[_PC];
460 +       kernel_regs->ARM_cpsr = gdb_regs[GDB_MAX_REGS - 1];
461 +}
462 +
463 +static inline struct pt_regs *kgdb_get_user_regs(struct task_struct *task)
464 +{
465 +       return (struct pt_regs *)
466 +           ((unsigned long)task->thread_info + THREAD_SIZE -
467 +            8 - sizeof(struct pt_regs));
468 +}
469 +
470 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs,
471 +                                struct task_struct *task)
472 +{
473 +       int regno;
474 +       struct pt_regs *thread_regs;
475 +
476 +       /* Just making sure... */
477 +       if (task == NULL)
478 +               return;
479 +
480 +       /* Initialize to zero */
481 +       for (regno = 0; regno < GDB_MAX_REGS; regno++)
482 +               gdb_regs[regno] = 0;
483 +
484 +       /* Otherwise, we have only some registers from switch_to() */
485 +       thread_regs = kgdb_get_user_regs(task);
486 +       gdb_regs[_R0] = thread_regs->ARM_r0;    /* Not really valid? */
487 +       gdb_regs[_R1] = thread_regs->ARM_r1;    /* "               " */
488 +       gdb_regs[_R2] = thread_regs->ARM_r2;    /* "               " */
489 +       gdb_regs[_R3] = thread_regs->ARM_r3;    /* "               " */
490 +       gdb_regs[_R4] = thread_regs->ARM_r4;
491 +       gdb_regs[_R5] = thread_regs->ARM_r5;
492 +       gdb_regs[_R6] = thread_regs->ARM_r6;
493 +       gdb_regs[_R7] = thread_regs->ARM_r7;
494 +       gdb_regs[_R8] = thread_regs->ARM_r8;
495 +       gdb_regs[_R9] = thread_regs->ARM_r9;
496 +       gdb_regs[_R10] = thread_regs->ARM_r10;
497 +       gdb_regs[_FP] = thread_regs->ARM_fp;
498 +       gdb_regs[_IP] = thread_regs->ARM_ip;
499 +       gdb_regs[_SP] = thread_regs->ARM_sp;
500 +       gdb_regs[_LR] = thread_regs->ARM_lr;
501 +       gdb_regs[_PC] = thread_regs->ARM_pc;
502 +       gdb_regs[_CPSR] = thread_regs->ARM_cpsr;
503 +}
504 +
505 +static int compiled_break;
506 +
507 +int kgdb_arch_handle_exception(int exception_vector, int signo,
508 +                              int err_code, char *remcom_in_buffer,
509 +                              char *remcom_out_buffer,
510 +                              struct pt_regs *linux_regs)
511 +{
512 +       long addr;
513 +       char *ptr;
514 +
515 +       switch (remcom_in_buffer[0]) {
516 +       case 'c':
517 +               kgdb_contthread = NULL;
518 +
519 +               /*
520 +                * Try to read optional parameter, pc unchanged if no parm.
521 +                * If this was a compiled breakpoint, we need to move
522 +                * to the next instruction or we will just breakpoint
523 +                * over and over again.
524 +                */
525 +               ptr = &remcom_in_buffer[1];
526 +               if (kgdb_hex2long(&ptr, &addr)) {
527 +                       linux_regs->ARM_pc = addr;
528 +               } else if (compiled_break == 1) {
529 +                       linux_regs->ARM_pc += 4;
530 +               }
531 +
532 +               compiled_break = 0;
533 +
534 +               return 0;
535 +       }
536 +
537 +       return -1;
538 +}
539 +
540 +static int kgdb_brk_fn(struct pt_regs *regs, unsigned int instr)
541 +{
542 +       kgdb_handle_exception(1, SIGTRAP, 0, regs);
543 +
544 +       return 0;
545 +}
546 +
547 +static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int instr)
548 +{
549 +       compiled_break = 1;
550 +       kgdb_handle_exception(1, SIGTRAP, 0, regs);
551 +
552 +       return 0;
553 +}
554 +
555 +static struct undef_hook kgdb_brkpt_hook = {
556 +       .instr_mask = 0xffffffff,
557 +       .instr_val = KGDB_BREAKINST,
558 +       .fn = kgdb_brk_fn
559 +};
560 +
561 +static struct undef_hook kgdb_compiled_brkpt_hook = {
562 +       .instr_mask = 0xffffffff,
563 +       .instr_val = KGDB_COMPILED_BREAK,
564 +       .fn = kgdb_compiled_brk_fn
565 +};
566 +
567 +/*
568 + * Register our undef instruction hooks with ARM undef core.
569 + * We regsiter a hook specifically looking for the KGB break inst
570 + * and we handle the normal undef case within the do_undefinstr
571 + * handler.
572 + */
573 +int kgdb_arch_init(void)
574 +{
575 +       register_undef_hook(&kgdb_brkpt_hook);
576 +       register_undef_hook(&kgdb_compiled_brkpt_hook);
577 +
578 +       return 0;
579 +}
580 +
581 +struct kgdb_arch arch_kgdb_ops = {
582 +#ifndef __ARMEB__
583 +       .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
584 +#else
585 +       .gdb_bpt_instr = {0xe7, 0xff, 0xde, 0xfe}
586 +#endif
587 +};
588 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/kernel/setup.c linux-2.6.18.kgdb/arch/arm/kernel/setup.c
589 --- linux-2.6.18/arch/arm/kernel/setup.c        2006-09-20 07:42:06.000000000 +0400
590 +++ linux-2.6.18.kgdb/arch/arm/kernel/setup.c   2008-06-10 16:19:51.000000000 +0400
591 @@ -829,6 +829,11 @@ void __init setup_arch(char **cmdline_p)
592         conswitchp = &dummy_con;
593  #endif
594  #endif
595 +
596 +#if    defined(CONFIG_KGDB)
597 +       extern void __init early_trap_init(void);
598 +       early_trap_init();
599 +#endif
600  }
601  
602  
603 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/kernel/traps.c linux-2.6.18.kgdb/arch/arm/kernel/traps.c
604 --- linux-2.6.18/arch/arm/kernel/traps.c        2006-09-20 07:42:06.000000000 +0400
605 +++ linux-2.6.18.kgdb/arch/arm/kernel/traps.c   2008-06-10 16:19:51.000000000 +0400
606 @@ -278,6 +278,7 @@ asmlinkage void do_undefinstr(struct pt_
607         unsigned int instr;
608         struct undef_hook *hook;
609         siginfo_t info;
610 +       mm_segment_t fs;
611         void __user *pc;
612  
613         /*
614 @@ -287,12 +288,15 @@ asmlinkage void do_undefinstr(struct pt_
615          */
616         regs->ARM_pc -= correction;
617  
618 +       fs = get_fs();
619 +       set_fs(KERNEL_DS);
620         pc = (void __user *)instruction_pointer(regs);
621         if (thumb_mode(regs)) {
622                 get_user(instr, (u16 __user *)pc);
623         } else {
624                 get_user(instr, (u32 __user *)pc);
625         }
626 +       set_fs(fs);
627  
628         spin_lock_irq(&undef_lock);
629         list_for_each_entry(hook, &undef_hook, node) {
630 @@ -684,6 +688,13 @@ EXPORT_SYMBOL(abort);
631  
632  void __init trap_init(void)
633  {
634 +#if   defined(CONFIG_KGDB)
635 +       return;
636 +}
637 +
638 +void __init early_trap_init(void)
639 +{
640 +#endif
641         unsigned long vectors = CONFIG_VECTORS_BASE;
642         extern char __stubs_start[], __stubs_end[];
643         extern char __vectors_start[], __vectors_end[];
644 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/mach-ixp2000/core.c linux-2.6.18.kgdb/arch/arm/mach-ixp2000/core.c
645 --- linux-2.6.18/arch/arm/mach-ixp2000/core.c   2006-09-20 07:42:06.000000000 +0400
646 +++ linux-2.6.18.kgdb/arch/arm/mach-ixp2000/core.c      2008-06-10 16:19:51.000000000 +0400
647 @@ -34,6 +34,7 @@
648  #include <asm/system.h>
649  #include <asm/tlbflush.h>
650  #include <asm/pgtable.h>
651 +#include <asm/kgdb.h>
652  
653  #include <asm/mach/map.h>
654  #include <asm/mach/time.h>
655 @@ -184,6 +185,9 @@ static struct platform_device ixp2000_se
656  void __init ixp2000_uart_init(void)
657  {
658         platform_device_register(&ixp2000_serial_device);
659 +#ifdef CONFIG_KGDB_8250
660 +       kgdb8250_add_port(0, &ixp2000_serial_port);
661 +#endif
662  }
663  
664  
665 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/mach-ixp2000/ixdp2x01.c linux-2.6.18.kgdb/arch/arm/mach-ixp2000/ixdp2x01.c
666 --- linux-2.6.18/arch/arm/mach-ixp2000/ixdp2x01.c       2006-09-20 07:42:06.000000000 +0400
667 +++ linux-2.6.18.kgdb/arch/arm/mach-ixp2000/ixdp2x01.c  2008-06-10 16:19:51.000000000 +0400
668 @@ -38,6 +38,7 @@
669  #include <asm/system.h>
670  #include <asm/hardware.h>
671  #include <asm/mach-types.h>
672 +#include <asm/kgdb.h>
673  
674  #include <asm/mach/pci.h>
675  #include <asm/mach/map.h>
676 @@ -413,6 +414,11 @@ static void __init ixdp2x01_init_machine
677         platform_add_devices(ixdp2x01_devices, ARRAY_SIZE(ixdp2x01_devices));
678         ixp2000_uart_init();
679         ixdp2x01_uart_init();
680 +
681 +#ifdef CONFIG_KGDB_8250
682 +       kgdb8250_add_port(0, &ixdp425_serial_ports[0]);
683 +       kgdb8250_add_port(1, &ixdp425_serial_ports[1]);
684 +#endif
685  }
686  
687  
688 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/mach-ixp4xx/coyote-setup.c linux-2.6.18.kgdb/arch/arm/mach-ixp4xx/coyote-setup.c
689 --- linux-2.6.18/arch/arm/mach-ixp4xx/coyote-setup.c    2006-09-20 07:42:06.000000000 +0400
690 +++ linux-2.6.18.kgdb/arch/arm/mach-ixp4xx/coyote-setup.c       2008-06-10 16:19:51.000000000 +0400
691 @@ -96,6 +96,10 @@ static void __init coyote_init(void)
692         }
693  
694         platform_add_devices(coyote_devices, ARRAY_SIZE(coyote_devices));
695 +
696 +#ifdef CONFIG_KGDB_8250
697 +       kgdb8250_add_port(0, &coyote_serial_port);
698 +#endif
699  }
700  
701  #ifdef CONFIG_ARCH_ADI_COYOTE
702 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/mach-ixp4xx/ixdp425-setup.c linux-2.6.18.kgdb/arch/arm/mach-ixp4xx/ixdp425-setup.c
703 --- linux-2.6.18/arch/arm/mach-ixp4xx/ixdp425-setup.c   2006-09-20 07:42:06.000000000 +0400
704 +++ linux-2.6.18.kgdb/arch/arm/mach-ixp4xx/ixdp425-setup.c      2008-06-10 16:19:51.000000000 +0400
705 @@ -24,6 +24,7 @@
706  #include <asm/irq.h>
707  #include <asm/mach/arch.h>
708  #include <asm/mach/flash.h>
709 +#include <asm/kgdb.h>
710  
711  static struct flash_platform_data ixdp425_flash_data = {
712         .map_name       = "cfi_probe",
713 @@ -76,7 +77,8 @@ static struct plat_serial8250_port ixdp4
714                 .mapbase        = IXP4XX_UART1_BASE_PHYS,
715                 .membase        = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
716                 .irq            = IRQ_IXP4XX_UART1,
717 -               .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
718 +               .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST |
719 +                                       UPF_SHARE_IRQ,
720                 .iotype         = UPIO_MEM,
721                 .regshift       = 2,
722                 .uartclk        = IXP4XX_UART_XTAL,
723 @@ -85,7 +87,8 @@ static struct plat_serial8250_port ixdp4
724                 .mapbase        = IXP4XX_UART2_BASE_PHYS,
725                 .membase        = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
726                 .irq            = IRQ_IXP4XX_UART2,
727 -               .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
728 +               .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST |
729 +                                       UPF_SHARE_IRQ,
730                 .iotype         = UPIO_MEM,
731                 .regshift       = 2,
732                 .uartclk        = IXP4XX_UART_XTAL,
733 @@ -116,6 +119,11 @@ static void __init ixdp425_init(void)
734                 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
735  
736         platform_add_devices(ixdp425_devices, ARRAY_SIZE(ixdp425_devices));
737 +
738 +#ifdef CONFIG_KGDB_8250
739 +       kgdb8250_add_port(0, &ixdp425_serial_ports[0]);
740 +       kgdb8250_add_port(1, &ixdp425_serial_ports[1]);
741 +#endif
742  }
743  
744  #ifdef CONFIG_ARCH_IXDP425
745 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/mach-omap1/serial.c linux-2.6.18.kgdb/arch/arm/mach-omap1/serial.c
746 --- linux-2.6.18/arch/arm/mach-omap1/serial.c   2006-09-20 07:42:06.000000000 +0400
747 +++ linux-2.6.18.kgdb/arch/arm/mach-omap1/serial.c      2008-06-10 16:19:51.000000000 +0400
748 @@ -15,6 +15,7 @@
749  #include <linux/delay.h>
750  #include <linux/serial.h>
751  #include <linux/tty.h>
752 +#include <linux/kgdb.h>
753  #include <linux/serial_8250.h>
754  #include <linux/serial_reg.h>
755  #include <linux/clk.h>
756 @@ -199,6 +200,9 @@ void __init omap_serial_init(void)
757                         break;
758                 }
759                 omap_serial_reset(&serial_platform_data[i]);
760 +#ifdef CONFIG_KGDB_8250
761 +               kgdb8250_add_platform_port(i, &serial_platform_data[i]);
762 +#endif
763         }
764  }
765  
766 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/mach-pxa/Makefile linux-2.6.18.kgdb/arch/arm/mach-pxa/Makefile
767 --- linux-2.6.18/arch/arm/mach-pxa/Makefile     2006-09-20 07:42:06.000000000 +0400
768 +++ linux-2.6.18.kgdb/arch/arm/mach-pxa/Makefile        2008-06-10 16:19:51.000000000 +0400
769 @@ -31,6 +31,7 @@ obj-$(CONFIG_LEDS) += $(led-y)
770  # Misc features
771  obj-$(CONFIG_PM) += pm.o sleep.o
772  obj-$(CONFIG_PXA_SSP) += ssp.o
773 +obj-$(CONFIG_KGDB_PXA_SERIAL) += kgdb-serial.o
774  
775  ifeq ($(CONFIG_PXA27x),y)
776  obj-$(CONFIG_PM) += standby.o
777 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/mach-pxa/kgdb-serial.c linux-2.6.18.kgdb/arch/arm/mach-pxa/kgdb-serial.c
778 --- linux-2.6.18/arch/arm/mach-pxa/kgdb-serial.c        1970-01-01 03:00:00.000000000 +0300
779 +++ linux-2.6.18.kgdb/arch/arm/mach-pxa/kgdb-serial.c   2008-06-10 16:19:51.000000000 +0400
780 @@ -0,0 +1,98 @@
781 +/*
782 + * linux/arch/arm/mach-pxa/kgdb-serial.c
783 + *
784 + * Provides low level kgdb serial support hooks for PXA2xx boards
785 + *
786 + * Author:     Nicolas Pitre
787 + * Copyright:  (C) 2002-2005 MontaVista Software Inc.
788 + *
789 + * This program is free software; you can redistribute it and/or modify
790 + * it under the terms of the GNU General Public License version 2 as
791 + * published by the Free Software Foundation.
792 + */
793 +
794 +#include <linux/config.h>
795 +#include <linux/serial_reg.h>
796 +#include <linux/kgdb.h>
797 +#include <asm/processor.h>
798 +#include <asm/hardware.h>
799 +#include <asm/arch/pxa-regs.h>
800 +
801 +#if   defined(CONFIG_KGDB_PXA_FFUART)
802 +
803 +#define UART           FFUART
804 +#define CKEN_UART      CKEN6_FFUART
805 +#define GPIO_RX_MD     GPIO34_FFRXD_MD
806 +#define GPIO_TX_MD     GPIO39_FFTXD_MD
807 +
808 +#elif defined(CONFIG_KGDB_PXA_BTUART)
809 +
810 +#define UART           BTUART
811 +#define CKEN_UART      CKEN7_BTUART
812 +#define GPIO_RX_MD     GPIO42_BTRXD_MD
813 +#define GPIO_TX_MD     GPIO43_BTTXD_MD
814 +
815 +#elif defined(CONFIG_KGDB_PXA_STUART)
816 +
817 +#define UART           STUART
818 +#define CKEN_UART      CKEN5_STUART
819 +#define GPIO_RX_MD     GPIO46_STRXD_MD
820 +#define GPIO_TX_MD     GPIO47_STTXD_MD
821 +
822 +#endif
823 +
824 +#define UART_BAUDRATE  (CONFIG_KGDB_BAUDRATE)
825 +
826 +static volatile unsigned long *port = (unsigned long *)&UART;
827 +
828 +static int kgdb_serial_init(void)
829 +{
830 +       pxa_set_cken(CKEN_UART, 1);
831 +       pxa_gpio_mode(GPIO_RX_MD);
832 +       pxa_gpio_mode(GPIO_TX_MD);
833 +
834 +       port[UART_IER] = 0;
835 +       port[UART_LCR] = LCR_DLAB;
836 +       port[UART_DLL] = ((921600 / UART_BAUDRATE) & 0xff);
837 +       port[UART_DLM] = ((921600 / UART_BAUDRATE) >> 8);
838 +       port[UART_LCR] = LCR_WLS1 | LCR_WLS0;
839 +       port[UART_MCR] = 0;
840 +       port[UART_IER] = IER_UUE;
841 +       port[UART_FCR] = FCR_ITL_16;
842 +
843 +       return 0;
844 +}
845 +
846 +static void kgdb_serial_putchar(int c)
847 +{
848 +       if (!(CKEN & CKEN_UART) || port[UART_IER] != IER_UUE)
849 +               kgdb_serial_init();
850 +       while (!(port[UART_LSR] & LSR_TDRQ))
851 +               cpu_relax();
852 +       port[UART_TX] = c;
853 +}
854 +
855 +static void kgdb_serial_flush(void)
856 +{
857 +       if ((CKEN & CKEN_UART) && (port[UART_IER] & IER_UUE))
858 +               while (!(port[UART_LSR] & LSR_TEMT))
859 +                       cpu_relax();
860 +}
861 +
862 +static int kgdb_serial_getchar(void)
863 +{
864 +       unsigned char c;
865 +       if (!(CKEN & CKEN_UART) || port[UART_IER] != IER_UUE)
866 +               kgdb_serial_init();
867 +       while (!(port[UART_LSR] & UART_LSR_DR))
868 +               cpu_relax();
869 +       c = port[UART_RX];
870 +       return c;
871 +}
872 +
873 +struct kgdb_io kgdb_io_ops = {
874 +       .init = kgdb_serial_init,
875 +       .write_char = kgdb_serial_putchar,
876 +       .flush = kgdb_serial_flush,
877 +       .read_char = kgdb_serial_getchar,
878 +};
879 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/mach-versatile/kgdb_serial.c linux-2.6.18.kgdb/arch/arm/mach-versatile/kgdb_serial.c
880 --- linux-2.6.18/arch/arm/mach-versatile/kgdb_serial.c  1970-01-01 03:00:00.000000000 +0300
881 +++ linux-2.6.18.kgdb/arch/arm/mach-versatile/kgdb_serial.c     2008-06-10 16:19:51.000000000 +0400
882 @@ -0,0 +1,121 @@
883 +/*
884 + * arch/arm/mach-versatile/kgdb_serial.c
885 + *
886 + * Author: Manish Lachwani, mlachwani@mvista.com
887 + *
888 + * 2005 (c) MontaVista Software, Inc. This file is licensed under
889 + * the terms of the GNU General Public License version 2. This program
890 + * is licensed "as is" without any warranty of any kind, whether express
891 + * or implied.
892 + *
893 + * Support for KGDB on ARM Versatile.
894 + */
895 +#include <linux/config.h>
896 +#include <linux/serial_reg.h>
897 +#include <linux/kgdb.h>
898 +#include <asm/io.h>
899 +#include <asm/processor.h>
900 +#include <asm/hardware.h>
901 +#include <asm/hardware/amba_serial.h>
902 +#include <asm/arch-versatile/hardware.h>
903 +
904 +#define ARM_BAUD_38400         23
905 +/*
906 + * Functions that will be used later
907 + */
908 +#define UART_GET_INT_STATUS(p) readb((p) + UART010_IIR)
909 +#define UART_GET_MIS(p)                readw((p) + UART011_MIS)
910 +#define UART_PUT_ICR(p, c)     writel((c), (p) + UART010_ICR)
911 +#define UART_GET_FR(p)         readb((p) + UART01x_FR)
912 +#define UART_GET_CHAR(p)       readb((p) + UART01x_DR)
913 +#define UART_PUT_CHAR(p, c)     writel((c), (p) + UART01x_DR)
914 +#define UART_GET_RSR(p)                readb((p) + UART01x_RSR)
915 +#define UART_GET_CR(p)         readb((p) + UART010_CR)
916 +#define UART_PUT_CR(p,c)        writel((c), (p) + UART010_CR)
917 +#define UART_GET_LCRL(p)       readb((p) + UART010_LCRL)
918 +#define UART_PUT_LCRL(p,c)     writel((c), (p) + UART010_LCRL)
919 +#define UART_GET_LCRM(p)        readb((p) + UART010_LCRM)
920 +#define UART_PUT_LCRM(p,c)     writel((c), (p) + UART010_LCRM)
921 +#define UART_GET_LCRH(p)       readb((p) + UART010_LCRH)
922 +#define UART_PUT_LCRH(p,c)     writel((c), (p) + UART010_LCRH)
923 +#define UART_RX_DATA(s)                (((s) & UART01x_FR_RXFE) == 0)
924 +#define UART_TX_READY(s)       (((s) & UART01x_FR_TXFF) == 0)
925 +#define UART_TX_EMPTY(p)       ((UART_GET_FR(p) & UART01x_FR_TMSK) == 0)
926 +
927 +/*
928 + * KGDB IRQ
929 + */
930 +static int kgdb_irq = 12;
931 +static volatile unsigned char *port = NULL;
932 +
933 +static int kgdb_serial_init(void)
934 +{
935 +       int rate = ARM_BAUD_38400;
936 +
937 +       port = IO_ADDRESS(0x101F1000);
938 +       UART_PUT_CR(port, 0);
939 +
940 +       /* Set baud rate */
941 +       UART_PUT_LCRM(port, ((rate & 0xf00) >> 8));
942 +       UART_PUT_LCRL(port, (rate & 0xff));
943 +       UART_PUT_LCRH(port, UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN);
944 +       UART_PUT_CR(port, UART01x_CR_UARTEN);
945 +
946 +       return 0;
947 +}
948 +
949 +static void kgdb_serial_putchar(int ch)
950 +{
951 +       unsigned int status;
952 +
953 +       do {
954 +               status = UART_GET_FR(port);
955 +       } while (!UART_TX_READY(status));
956 +
957 +       UART_PUT_CHAR(port, ch);
958 +}
959 +
960 +static int kgdb_serial_getchar(void)
961 +{
962 +       unsigned int status;
963 +       int ch;
964 +
965 +       do {
966 +               status = UART_GET_FR(port);
967 +       } while (!UART_RX_DATA(status));
968 +       ch = UART_GET_CHAR(port);
969 +       return ch;
970 +}
971 +
972 +static struct uart_port kgdb_amba_port = {
973 +       .irq = 12,
974 +       .iobase = 0,
975 +       .iotype = UPIO_MEM,
976 +       .membase = (unsigned char *)IO_ADDRESS(0x101F1000),
977 +};
978 +
979 +static irqreturn_t kgdb_interrupt(int irq, void *dev_id, struct pt_regs *regs)
980 +{
981 +       int status = UART_GET_MIS(port);
982 +
983 +       if (irq != kgdb_irq)
984 +               return IRQ_NONE;
985 +
986 +       if (status & 0x40)
987 +               breakpoint();
988 +
989 +       return IRQ_HANDLED;
990 +}
991 +
992 +static void __init kgdb_hookup_irq(void)
993 +{
994 +       request_irq(kgdb_irq, kgdb_interrupt, SA_SHIRQ, "GDB-stub",
995 +                   &kgdb_amba_port);
996 +}
997 +
998 +struct kgdb_io kgdb_io_ops = {
999 +       .init = kgdb_serial_init,
1000 +       .write_char = kgdb_serial_putchar,
1001 +       .read_char = kgdb_serial_getchar,
1002 +       .late_init = kgdb_hookup_irq,
1003 +};
1004 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/arm/mm/extable.c linux-2.6.18.kgdb/arch/arm/mm/extable.c
1005 --- linux-2.6.18/arch/arm/mm/extable.c  2006-09-20 07:42:06.000000000 +0400
1006 +++ linux-2.6.18.kgdb/arch/arm/mm/extable.c     2008-06-10 16:19:51.000000000 +0400
1007 @@ -2,6 +2,7 @@
1008   *  linux/arch/arm/mm/extable.c
1009   */
1010  #include <linux/module.h>
1011 +#include <linux/kgdb.h>
1012  #include <asm/uaccess.h>
1013  
1014  int fixup_exception(struct pt_regs *regs)
1015 @@ -11,6 +12,12 @@ int fixup_exception(struct pt_regs *regs
1016         fixup = search_exception_tables(instruction_pointer(regs));
1017         if (fixup)
1018                 regs->ARM_pc = fixup->fixup;
1019 +#ifdef CONFIG_KGDB
1020 +       if (atomic_read(&debugger_active) && kgdb_may_fault)
1021 +               /* Restore our previous state. */
1022 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
1023 +               /* Not reached. */
1024 +#endif
1025  
1026         return fixup != NULL;
1027  }
1028 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/i386/kernel/Makefile linux-2.6.18.kgdb/arch/i386/kernel/Makefile
1029 --- linux-2.6.18/arch/i386/kernel/Makefile      2006-09-20 07:42:06.000000000 +0400
1030 +++ linux-2.6.18.kgdb/arch/i386/kernel/Makefile 2008-06-10 16:19:17.000000000 +0400
1031 @@ -39,6 +39,7 @@ obj-$(CONFIG_VM86)            += vm86.o
1032  obj-$(CONFIG_EARLY_PRINTK)     += early_printk.o
1033  obj-$(CONFIG_HPET_TIMER)       += hpet.o
1034  obj-$(CONFIG_K8_NB)            += k8.o
1035 +obj-$(CONFIG_KGDB)             += kgdb.o kgdb-jmp.o
1036  
1037  EXTRA_AFLAGS   := -traditional
1038  
1039 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/i386/kernel/entry.S linux-2.6.18.kgdb/arch/i386/kernel/entry.S
1040 --- linux-2.6.18/arch/i386/kernel/entry.S       2006-09-20 07:42:06.000000000 +0400
1041 +++ linux-2.6.18.kgdb/arch/i386/kernel/entry.S  2008-06-10 16:19:58.000000000 +0400
1042 @@ -201,7 +201,7 @@ VM_MASK             = 0x00020000
1043         CFI_OFFSET ecx, ECX-OLDESP;\
1044         CFI_OFFSET ebx, EBX-OLDESP
1045  
1046 -ENTRY(ret_from_fork)
1047 +KPROBE_ENTRY(ret_from_fork)
1048         CFI_STARTPROC
1049         pushl %eax
1050         CFI_ADJUST_CFA_OFFSET 4
1051 @@ -664,7 +664,7 @@ ENTRY(simd_coprocessor_error)
1052         jmp error_code
1053         CFI_ENDPROC
1054  
1055 -ENTRY(device_not_available)
1056 +KPROBE_ENTRY(device_not_available)
1057         RING0_INT_FRAME
1058         pushl $-1                       # mark this as an int
1059         CFI_ADJUST_CFA_OFFSET 4
1060 @@ -909,7 +909,7 @@ ENTRY(machine_check)
1061         CFI_ENDPROC
1062  #endif
1063  
1064 -ENTRY(spurious_interrupt_bug)
1065 +KPROBE_ENTRY(spurious_interrupt_bug)
1066         RING0_INT_FRAME
1067         pushl $0
1068         CFI_ADJUST_CFA_OFFSET 4
1069 @@ -953,3 +953,108 @@ ENDPROC(arch_unwind_init_running)
1070  #include "syscall_table.S"
1071  
1072  syscall_table_size=(.-sys_call_table)
1073 +
1074 +#      Here we do call frames.  We cheat a bit as we only really need
1075 +#      correct frames at locations we can actually look at from a
1076 +#      debugger.  Since the break instruction trap actually goes thru
1077 +#      some of this code, we don't really need info on those areas, but
1078 +#      only after the fact.  I.e. if we can not step or break in a
1079 +#      location or end up with a return address pointing at the
1080 +#      location, we don't need a correct call frame for it.
1081 +
1082 +#ifdef CONFIG_KGDB
1083 +
1084 +#include <linux/dwarf2-lang.h>
1085 +/*
1086 + * The register numbers as known by gdb
1087 + */
1088 +
1089 +#define _EAX 0
1090 +#define _ECX 1
1091 +#define _EDX 2
1092 +#define _EBX 3
1093 +#define _ESP 4
1094 +#define _EBP 5
1095 +#define _ESI 6
1096 +#define _EDI 7
1097 +#define _PC  8
1098 +#define _EIP 8
1099 +#define _PS  9
1100 +#define _EFLAGS  9
1101 +#define _CS 10
1102 +#define _SS 11
1103 +#define _DS 12
1104 +#define _ES 13
1105 +#define _FS 14
1106 +#define _GS 15
1107 +       /*
1108 +        * This code uses macros defined in linux/dwarf2-lang.h
1109 +        * They attempt to follow the dwarf2 naming conventions... sort of..
1110 +        */
1111 +ENTRY(end_of_stack_stop_unwind_function)
1112 +       .long   end_of_stack_stop_unwind_function+1
1113 +
1114 +       .text
1115 +
1116 +       CFI_preamble(c1,_PC,1,1)
1117 +       CFA_define_reference(_ESP,OLDESP)       /* Stack pointer */
1118 +       CFA_expression(_EIP)
1119 +          CFA_exp_OP_dup                       /* copy old esp */
1120 +          CFA_exp_OP_consts(CS-OLDESP)         /* offset to CS address */
1121 +          CFA_exp_OP_plus                      /* should be CS address */
1122 +          CFA_exp_OP_deref                     /* get the CS */
1123 +          CFA_exp_OP_const4s(VM_MASK|3)        /* prepare to mask it */
1124 +          CFA_exp_OP_and                       /* mask it, zero means kernel */
1125 +          CFA_exp_OP_bra(eip_user_rtn)         /* branch if user */
1126 +          CFA_exp_OP_const4s(EIP-OLDESP)       /* offset to return address */
1127 +          CFA_exp_OP_plus                      /* add that in */
1128 +          CFA_exp_OP_skip(eip_end)             /* done if kernel, skip out */
1129 +eip_user_rtn:
1130 +          CFA_exp_OP_addr(end_of_stack_stop_unwind_function)/*dummy function */
1131 +eip_end:
1132 +          CFA_expression_end
1133 +       CFA_define_offset(_EBX,EBX-OLDESP)
1134 +       CFA_define_offset(_ECX,ECX-OLDESP)
1135 +       CFA_define_offset(_EDX,EDX-OLDESP)
1136 +       CFA_define_offset(_ESI,ESI-OLDESP)
1137 +       CFA_define_offset(_EDI,EDI-OLDESP)
1138 +       CFA_define_offset(_EBP,EBP-OLDESP)
1139 +       CFA_define_offset(_EAX,EAX-OLDESP)
1140 +       CFA_define_offset(_EFLAGS,EFLAGS-OLDESP)
1141 +       CFI_postamble()
1142 +
1143 +/*
1144 + * This provides an uwind for our dummy end of unwind function.
1145 + * Current convention is to provied an undefined return address.
1146 + */
1147 +       CFI_preamble(c2,_PC,1,1)
1148 +       CFA_define_reference(_ESP,0)    /* Stack pointer */
1149 +       CFA_undefine_reg(_EIP)
1150 +       CFI_postamble()
1151 +
1152 +       FDE_preamble(c2,end_of_stack_stop_unwind_function,      \
1153 +                       end_of_stack_stop_unwind_function+5)
1154 +       FDE_postamble()
1155 +       /*
1156 +         * This is VERY sloppy.  At this point all we want to do is get
1157 +         * the frame right for back tracing.  It will not be good if
1158 +         * you try to single step.  We use already defined labels.
1159 +         * We want to cover all call outs.
1160 +         * We could also recode this as just one FDE, but this works and
1161 +         * I want to get it out.
1162 +        */
1163 +       FDE_preamble(c1,ret_from_fork,ret_from_exception)
1164 +       CFA_define_cfa_offset(4)                /* one extra word on stack */
1165 +       FDE_postamble()
1166 +
1167 +       FDE_preamble(c1,ret_from_exception,device_not_available_emulate)
1168 +       FDE_postamble()
1169 +
1170 +               FDE_preamble(c1,device_not_available_emulate,debug)
1171 +       CFA_define_cfa_offset(4)                /* one extra word on stack */
1172 +       FDE_postamble()
1173 +
1174 +       FDE_preamble(c1, debug,spurious_interrupt_bug)
1175 +       FDE_postamble()
1176 +
1177 +#endif
1178 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/i386/kernel/head.S linux-2.6.18.kgdb/arch/i386/kernel/head.S
1179 --- linux-2.6.18/arch/i386/kernel/head.S        2006-09-20 07:42:06.000000000 +0400
1180 +++ linux-2.6.18.kgdb/arch/i386/kernel/head.S   2008-06-10 16:19:58.000000000 +0400
1181 @@ -10,6 +10,7 @@
1182  .text
1183  #include <linux/threads.h>
1184  #include <linux/linkage.h>
1185 +#include <asm/kgdb.h>
1186  #include <asm/segment.h>
1187  #include <asm/page.h>
1188  #include <asm/pgtable.h>
1189 @@ -326,6 +327,10 @@ is386:     movl $2,%ecx            # set MP
1190  #endif /* CONFIG_SMP */
1191         jmp start_kernel
1192  
1193 +       /* This dwarf code tells gdb that this is the end of the unwind */
1194 +       /* This uses the CFA set up for pc=1 located in entry.S */
1195 +       CFI_END_FRAME(is386)
1196 +
1197  /*
1198   * We depend on ET to be correct. This checks for 287/387.
1199   */
1200 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/i386/kernel/kgdb-jmp.S linux-2.6.18.kgdb/arch/i386/kernel/kgdb-jmp.S
1201 --- linux-2.6.18/arch/i386/kernel/kgdb-jmp.S    1970-01-01 03:00:00.000000000 +0300
1202 +++ linux-2.6.18.kgdb/arch/i386/kernel/kgdb-jmp.S       2008-06-10 16:19:17.000000000 +0400
1203 @@ -0,0 +1,74 @@
1204 +/*
1205 + * arch/i386/kernel/kgdb-jmp.S
1206 + *
1207 + * Save and restore system registers so that within a limited frame we
1208 + * may have a fault and "jump back" to a known safe location.
1209 + *
1210 + * Author: George Anzinger <george@mvista.com>
1211 + *
1212 + * Cribbed from glibc, which carries the following:
1213 + * Copyright (C) 1996, 1996, 1997, 2000, 2001 Free Software Foundation, Inc.
1214 + * Copyright (C) 2005 by MontaVista Software.
1215 + *
1216 + * This file is licensed under the terms of the GNU General Public License
1217 + * version 2. This program as licensed "as is" without any warranty of
1218 + * any kind, whether express or implied.
1219 + */
1220 +
1221 +#include <linux/linkage.h>
1222 +
1223 +#define PCOFF          0
1224 +#define LINKAGE                4               /* just the return address */
1225 +#define PTR_SIZE       4
1226 +#define PARMS          LINKAGE         /* no space for saved regs */
1227 +#define JMPBUF         PARMS
1228 +#define VAL            JMPBUF+PTR_SIZE
1229 +
1230 +#define JB_BX          0
1231 +#define JB_SI          1
1232 +#define JB_DI          2
1233 +#define JB_BP          3
1234 +#define JB_SP          4
1235 +#define JB_PC          5
1236 +
1237 +/* This must be called prior to kgdb_fault_longjmp and
1238 + * kgdb_fault_longjmp must not be called outside of the context of the
1239 + * last call to kgdb_fault_setjmp.
1240 + * kgdb_fault_setjmp(int *jmp_buf[6])
1241 + */
1242 +ENTRY(kgdb_fault_setjmp)
1243 +       movl JMPBUF(%esp), %eax
1244 +
1245 +       /* Save registers.  */
1246 +       movl    %ebx, (JB_BX*4)(%eax)
1247 +       movl    %esi, (JB_SI*4)(%eax)
1248 +       movl    %edi, (JB_DI*4)(%eax)
1249 +       /* Save SP as it will be after we return.  */
1250 +       leal    JMPBUF(%esp), %ecx
1251 +       movl    %ecx, (JB_SP*4)(%eax)
1252 +       movl    PCOFF(%esp), %ecx       /* Save PC we are returning to now.  */
1253 +       movl    %ecx, (JB_PC*4)(%eax)
1254 +       movl    %ebp, (JB_BP*4)(%eax)   /* Save caller's frame pointer.  */
1255 +
1256 +       /* Restore state so we can now try the access. */
1257 +       movl    JMPBUF(%esp), %ecx      /* User's jmp_buf in %ecx.  */
1258 +       /* Save the return address now.  */
1259 +       movl    (JB_PC*4)(%ecx), %edx
1260 +       /* Restore registers.  */
1261 +       movl    $0, %eax
1262 +       movl    (JB_SP*4)(%ecx), %esp
1263 +       jmp     *%edx           /* Jump to saved PC. */
1264 +
1265 +/* kgdb_fault_longjmp(int *jmp_buf[6]) */
1266 +ENTRY(kgdb_fault_longjmp)
1267 +       movl    JMPBUF(%esp), %ecx      /* User's jmp_buf in %ecx.  */
1268 +       /* Save the return address now.  */
1269 +       movl    (JB_PC*4)(%ecx), %edx
1270 +       /* Restore registers.  */
1271 +       movl    (JB_BX*4)(%ecx), %ebx
1272 +       movl    (JB_SI*4)(%ecx), %esi
1273 +       movl    (JB_DI*4)(%ecx), %edi
1274 +       movl    (JB_BP*4)(%ecx), %ebp
1275 +       movl    $1, %eax
1276 +       movl    (JB_SP*4)(%ecx), %esp
1277 +       jmp     *%edx           /* Jump to saved PC. */
1278 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/i386/kernel/kgdb.c linux-2.6.18.kgdb/arch/i386/kernel/kgdb.c
1279 --- linux-2.6.18/arch/i386/kernel/kgdb.c        1970-01-01 03:00:00.000000000 +0300
1280 +++ linux-2.6.18.kgdb/arch/i386/kernel/kgdb.c   2008-06-10 16:20:15.000000000 +0400
1281 @@ -0,0 +1,363 @@
1282 +/*
1283 + *
1284 + * This program is free software; you can redistribute it and/or modify it
1285 + * under the terms of the GNU General Public License as published by the
1286 + * Free Software Foundation; either version 2, or (at your option) any
1287 + * later version.
1288 + *
1289 + * This program is distributed in the hope that it will be useful, but
1290 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1291 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1292 + * General Public License for more details.
1293 + *
1294 + */
1295 +
1296 +/*
1297 + * Copyright (C) 2000-2001 VERITAS Software Corporation.
1298 + */
1299 +/*
1300 + *  Contributor:     Lake Stevens Instrument Division$
1301 + *  Written by:      Glenn Engel $
1302 + *  Updated by:             Amit Kale<akale@veritas.com>
1303 + *  Updated by:             Tom Rini <trini@kernel.crashing.org>
1304 + *  Modified for 386 by Jim Kingdon, Cygnus Support.
1305 + *  Origianl kgdb, compatibility with 2.1.xx kernel by
1306 + *  David Grothe <dave@gcom.com>
1307 + *  Additional support from Tigran Aivazian <tigran@sco.com>
1308 + */
1309 +
1310 +#include <linux/string.h>
1311 +#include <linux/kernel.h>
1312 +#include <linux/sched.h>
1313 +#include <linux/smp.h>
1314 +#include <linux/spinlock.h>
1315 +#include <linux/delay.h>
1316 +#include <asm/vm86.h>
1317 +#include <asm/system.h>
1318 +#include <asm/ptrace.h>                /* for linux pt_regs struct */
1319 +#include <linux/kgdb.h>
1320 +#include <linux/init.h>
1321 +#include <asm/apicdef.h>
1322 +#include <asm/desc.h>
1323 +#include <asm/kdebug.h>
1324 +
1325 +#include "mach_ipi.h"
1326 +
1327 +/* Put the error code here just in case the user cares.  */
1328 +int gdb_i386errcode;
1329 +/* Likewise, the vector number here (since GDB only gets the signal
1330 +   number through the usual means, and that's not very specific).  */
1331 +int gdb_i386vector = -1;
1332 +
1333 +extern atomic_t cpu_doing_single_step;
1334 +
1335 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
1336 +{
1337 +       gdb_regs[_EAX] = regs->eax;
1338 +       gdb_regs[_EBX] = regs->ebx;
1339 +       gdb_regs[_ECX] = regs->ecx;
1340 +       gdb_regs[_EDX] = regs->edx;
1341 +       gdb_regs[_ESI] = regs->esi;
1342 +       gdb_regs[_EDI] = regs->edi;
1343 +       gdb_regs[_EBP] = regs->ebp;
1344 +       gdb_regs[_DS] = regs->xds;
1345 +       gdb_regs[_ES] = regs->xes;
1346 +       gdb_regs[_PS] = regs->eflags;
1347 +       gdb_regs[_CS] = regs->xcs;
1348 +       gdb_regs[_PC] = regs->eip;
1349 +       gdb_regs[_ESP] = (int)(&regs->esp);
1350 +       gdb_regs[_SS] = __KERNEL_DS;
1351 +       gdb_regs[_FS] = 0xFFFF;
1352 +       gdb_regs[_GS] = 0xFFFF;
1353 +}
1354 +
1355 +/*
1356 + * Extracts ebp, esp and eip values understandable by gdb from the values
1357 + * saved by switch_to.
1358 + * thread.esp points to ebp. flags and ebp are pushed in switch_to hence esp
1359 + * prior to entering switch_to is 8 greater then the value that is saved.
1360 + * If switch_to changes, change following code appropriately.
1361 + */
1362 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
1363 +{
1364 +       gdb_regs[_EAX] = 0;
1365 +       gdb_regs[_EBX] = 0;
1366 +       gdb_regs[_ECX] = 0;
1367 +       gdb_regs[_EDX] = 0;
1368 +       gdb_regs[_ESI] = 0;
1369 +       gdb_regs[_EDI] = 0;
1370 +       gdb_regs[_EBP] = *(unsigned long *)p->thread.esp;
1371 +       gdb_regs[_DS] = __KERNEL_DS;
1372 +       gdb_regs[_ES] = __KERNEL_DS;
1373 +       gdb_regs[_PS] = 0;
1374 +       gdb_regs[_CS] = __KERNEL_CS;
1375 +       gdb_regs[_PC] = p->thread.eip;
1376 +       gdb_regs[_ESP] = p->thread.esp;
1377 +       gdb_regs[_SS] = __KERNEL_DS;
1378 +       gdb_regs[_FS] = 0xFFFF;
1379 +       gdb_regs[_GS] = 0xFFFF;
1380 +}
1381 +
1382 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
1383 +{
1384 +       regs->eax = gdb_regs[_EAX];
1385 +       regs->ebx = gdb_regs[_EBX];
1386 +       regs->ecx = gdb_regs[_ECX];
1387 +       regs->edx = gdb_regs[_EDX];
1388 +       regs->esi = gdb_regs[_ESI];
1389 +       regs->edi = gdb_regs[_EDI];
1390 +       regs->ebp = gdb_regs[_EBP];
1391 +       regs->xds = gdb_regs[_DS];
1392 +       regs->xes = gdb_regs[_ES];
1393 +       regs->eflags = gdb_regs[_PS];
1394 +       regs->xcs = gdb_regs[_CS];
1395 +       regs->eip = gdb_regs[_PC];
1396 +}
1397 +
1398 +static struct hw_breakpoint {
1399 +       unsigned enabled;
1400 +       unsigned type;
1401 +       unsigned len;
1402 +       unsigned addr;
1403 +} breakinfo[4] = {
1404 +       { .enabled = 0 },
1405 +       { .enabled = 0 },
1406 +       { .enabled = 0 },
1407 +       { .enabled = 0 },
1408 +};
1409 +
1410 +void kgdb_correct_hw_break(void)
1411 +{
1412 +       int breakno;
1413 +       int correctit;
1414 +       int breakbit;
1415 +       unsigned dr7;
1416 +
1417 +       asm volatile ("movl %%db7, %0\n":"=r" (dr7)
1418 +                     :);
1419 +       do {
1420 +               unsigned addr0, addr1, addr2, addr3;
1421 +               asm volatile ("movl %%db0, %0\n"
1422 +                             "movl %%db1, %1\n"
1423 +                             "movl %%db2, %2\n"
1424 +                             "movl %%db3, %3\n":"=r" (addr0), "=r"(addr1),
1425 +                             "=r"(addr2), "=r"(addr3):);
1426 +       } while (0);
1427 +       correctit = 0;
1428 +       for (breakno = 0; breakno < 3; breakno++) {
1429 +               breakbit = 2 << (breakno << 1);
1430 +               if (!(dr7 & breakbit) && breakinfo[breakno].enabled) {
1431 +                       correctit = 1;
1432 +                       dr7 |= breakbit;
1433 +                       dr7 &= ~(0xf0000 << (breakno << 2));
1434 +                       dr7 |= (((breakinfo[breakno].len << 2) |
1435 +                                breakinfo[breakno].type) << 16) <<
1436 +                           (breakno << 2);
1437 +                       switch (breakno) {
1438 +                       case 0:
1439 +                               asm volatile ("movl %0, %%dr0\n"::"r"
1440 +                                             (breakinfo[breakno].addr));
1441 +                               break;
1442 +
1443 +                       case 1:
1444 +                               asm volatile ("movl %0, %%dr1\n"::"r"
1445 +                                             (breakinfo[breakno].addr));
1446 +                               break;
1447 +
1448 +                       case 2:
1449 +                               asm volatile ("movl %0, %%dr2\n"::"r"
1450 +                                             (breakinfo[breakno].addr));
1451 +                               break;
1452 +
1453 +                       case 3:
1454 +                               asm volatile ("movl %0, %%dr3\n"::"r"
1455 +                                             (breakinfo[breakno].addr));
1456 +                               break;
1457 +                       }
1458 +               } else if ((dr7 & breakbit) && !breakinfo[breakno].enabled) {
1459 +                       correctit = 1;
1460 +                       dr7 &= ~breakbit;
1461 +                       dr7 &= ~(0xf0000 << (breakno << 2));
1462 +               }
1463 +       }
1464 +       if (correctit)
1465 +               asm volatile ("movl %0, %%db7\n"::"r" (dr7));
1466 +}
1467 +
1468 +int kgdb_remove_hw_break(unsigned long addr)
1469 +{
1470 +       int i, idx = -1;
1471 +       for (i = 0; i < 4; i++) {
1472 +               if (breakinfo[i].addr == addr && breakinfo[i].enabled) {
1473 +                       idx = i;
1474 +                       break;
1475 +               }
1476 +       }
1477 +       if (idx == -1)
1478 +               return -1;
1479 +
1480 +       breakinfo[idx].enabled = 0;
1481 +       return 0;
1482 +}
1483 +
1484 +void kgdb_remove_all_hw_break(void)
1485 +{
1486 +       int i;
1487 +
1488 +       for (i = 0; i < 4; i++) {
1489 +               if (breakinfo[i].enabled) {
1490 +                       /* Do what? */
1491 +                       ;
1492 +               }
1493 +               memset(&breakinfo[i], 0, sizeof(struct hw_breakpoint));
1494 +       }
1495 +}
1496 +
1497 +int kgdb_set_hw_break(unsigned long addr)
1498 +{
1499 +       int i, idx = -1;
1500 +       for (i = 0; i < 4; i++) {
1501 +               if (!breakinfo[i].enabled) {
1502 +                       idx = i;
1503 +                       break;
1504 +               }
1505 +       }
1506 +       if (idx == -1)
1507 +               return -1;
1508 +
1509 +       breakinfo[idx].enabled = 1;
1510 +       breakinfo[idx].type = 1;
1511 +       breakinfo[idx].len = 1;
1512 +       breakinfo[idx].addr = addr;
1513 +       return 0;
1514 +}
1515 +
1516 +void kgdb_disable_hw_debug(struct pt_regs *regs)
1517 +{
1518 +       /* Disable hardware debugging while we are in kgdb */
1519 +       asm volatile ("movl %0,%%db7": /* no output */ :"r" (0));
1520 +}
1521 +
1522 +void kgdb_post_master_code(struct pt_regs *regs, int e_vector, int err_code)
1523 +{
1524 +       /* Master processor is completely in the debugger */
1525 +       gdb_i386vector = e_vector;
1526 +       gdb_i386errcode = err_code;
1527 +}
1528 +
1529 +void kgdb_roundup_cpus(unsigned long flags)
1530 +{
1531 +       send_IPI_allbutself(APIC_DM_NMI);
1532 +}
1533 +
1534 +int kgdb_arch_handle_exception(int e_vector, int signo,
1535 +                              int err_code, char *remcom_in_buffer,
1536 +                              char *remcom_out_buffer,
1537 +                              struct pt_regs *linux_regs)
1538 +{
1539 +       long addr;
1540 +       char *ptr;
1541 +       int newPC, dr6;
1542 +
1543 +       switch (remcom_in_buffer[0]) {
1544 +       case 'c':
1545 +       case 's':
1546 +               /* try to read optional parameter, pc unchanged if no parm */
1547 +               ptr = &remcom_in_buffer[1];
1548 +               if (kgdb_hex2long(&ptr, &addr))
1549 +                       linux_regs->eip = addr;
1550 +               newPC = linux_regs->eip;
1551 +
1552 +               /* clear the trace bit */
1553 +               linux_regs->eflags &= ~TF_MASK;
1554 +               atomic_set(&cpu_doing_single_step, -1);
1555 +
1556 +               /* set the trace bit if we're stepping */
1557 +               if (remcom_in_buffer[0] == 's') {
1558 +                       linux_regs->eflags |= TF_MASK;
1559 +                       debugger_step = 1;
1560 +                       atomic_set(&cpu_doing_single_step,smp_processor_id());
1561 +               }
1562 +
1563 +               asm volatile ("movl %%db6, %0\n":"=r" (dr6));
1564 +               if (!(dr6 & 0x4000)) {
1565 +                       long breakno;
1566 +                       for (breakno = 0; breakno < 4; ++breakno) {
1567 +                               if (dr6 & (1 << breakno) &&
1568 +                                   breakinfo[breakno].type == 0) {
1569 +                                       /* Set restore flag */
1570 +                                       linux_regs->eflags |= X86_EFLAGS_RF;
1571 +                                       break;
1572 +                               }
1573 +                       }
1574 +               }
1575 +               kgdb_correct_hw_break();
1576 +               asm volatile ("movl %0, %%db6\n"::"r" (0));
1577 +
1578 +               return (0);
1579 +       }                       /* switch */
1580 +       /* this means that we do not want to exit from the handler */
1581 +       return -1;
1582 +}
1583 +
1584 +/* Register KGDB with the i386die_chain so that we hook into all of the right
1585 + * spots. */
1586 +static int kgdb_notify(struct notifier_block *self, unsigned long cmd,
1587 +                      void *ptr)
1588 +{
1589 +       struct die_args *args = ptr;
1590 +       struct pt_regs *regs = args->regs;
1591 +
1592 +       /* Bad memory access? */
1593 +       if (cmd == DIE_PAGE_FAULT_NO_CONTEXT && atomic_read(&debugger_active)
1594 +                       && kgdb_may_fault) {
1595 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
1596 +               return NOTIFY_STOP;
1597 +       } else if (cmd == DIE_PAGE_FAULT)
1598 +               /* A normal page fault, ignore. */
1599 +               return NOTIFY_DONE;
1600 +       else if ((cmd == DIE_NMI || cmd == DIE_NMI_IPI ||
1601 +               cmd == DIE_NMIWATCHDOG) && atomic_read(&debugger_active)) {
1602 +               /* CPU roundup */
1603 +               kgdb_nmihook(smp_processor_id(), regs);
1604 +               return NOTIFY_STOP;
1605 +       } else if (cmd == DIE_NMI_IPI || cmd == DIE_NMI || user_mode(regs) ||
1606 +                       (cmd == DIE_DEBUG && atomic_read(&debugger_active)))
1607 +               /* Normal watchdog event or userspace debugging, or spurious
1608 +                * debug exception, ignore. */
1609 +               return NOTIFY_DONE;
1610 +
1611 +       kgdb_handle_exception(args->trapnr, args->signr, args->err, regs);
1612 +
1613 +       return NOTIFY_STOP;
1614 +}
1615 +
1616 +static struct notifier_block kgdb_notifier = {
1617 +       .notifier_call = kgdb_notify,
1618 +};
1619 +
1620 +int kgdb_arch_init(void)
1621 +{
1622 +       atomic_notifier_chain_register(&i386die_chain, &kgdb_notifier);
1623 +       return 0;
1624 +}
1625 +
1626 +/*
1627 + * Skip an int3 exception when it occurs after a breakpoint has been
1628 + * removed. Backtrack eip by 1 since the int3 would have caused it to
1629 + * increment by 1.
1630 + */
1631 +
1632 +int kgdb_skipexception(int exception, struct pt_regs *regs)
1633 +{
1634 +       if (exception == 3 && kgdb_isremovedbreak(regs->eip - 1)) {
1635 +               regs->eip -= 1;
1636 +               return 1;
1637 +       }
1638 +       return 0;
1639 +}
1640 +
1641 +struct kgdb_arch arch_kgdb_ops = {
1642 +       .gdb_bpt_instr = {0xcc},
1643 +       .flags = KGDB_HW_BREAKPOINT,
1644 +};
1645 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/i386/kernel/process.c linux-2.6.18.kgdb/arch/i386/kernel/process.c
1646 --- linux-2.6.18/arch/i386/kernel/process.c     2006-09-20 07:42:06.000000000 +0400
1647 +++ linux-2.6.18.kgdb/arch/i386/kernel/process.c        2008-06-10 16:19:58.000000000 +0400
1648 @@ -328,7 +328,27 @@ __asm__(".section .text\n"
1649         "call *%ebx\n\t"
1650         "pushl %eax\n\t"
1651         "call do_exit\n"
1652 +       "kernel_thread_helper_end:\n\t"
1653         ".previous");
1654 +#ifdef CONFIG_KGDB
1655 +#include <linux/dwarf2-lang.h>
1656 +
1657 +       /* This dwarf code tells gdb that this is the end of the unwind */
1658 +       /* This uses the CFA set up for pc=1 located in entry.S */
1659 +#define _ESP 4
1660 +#define _PC  8
1661 +#define _EIP 8
1662 +__asm__(
1663 +       QUOTE_THIS(
1664 +               CFI_preamble(dwarf_4,_PC,1,1)
1665 +               CFA_define_reference(_ESP,0)    /* Stack pointer */
1666 +               CFA_undefine_reg(_EIP)
1667 +               CFI_postamble()
1668 +
1669 +               FDE_preamble(dwarf_4,kernel_thread_helper,kernel_thread_helper_end)
1670 +               FDE_postamble()
1671 +               ));
1672 +#endif
1673  
1674  /*
1675   * Create a kernel thread
1676 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/i386/kernel/setup.c linux-2.6.18.kgdb/arch/i386/kernel/setup.c
1677 --- linux-2.6.18/arch/i386/kernel/setup.c       2006-09-20 07:42:06.000000000 +0400
1678 +++ linux-2.6.18.kgdb/arch/i386/kernel/setup.c  2008-06-10 16:19:17.000000000 +0400
1679 @@ -148,6 +148,7 @@ EXPORT_SYMBOL(ist_info);
1680  struct e820map e820;
1681  
1682  extern void early_cpu_init(void);
1683 +extern void early_trap_init(void);
1684  extern void generic_apic_probe(char *);
1685  extern int root_mountflags;
1686  
1687 @@ -1444,6 +1445,7 @@ void __init setup_arch(char **cmdline_p)
1688         memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
1689         pre_setup_arch_hook();
1690         early_cpu_init();
1691 +       early_trap_init();
1692  
1693         /*
1694          * FIXME: This isn't an official loader_type right
1695 @@ -1500,6 +1502,7 @@ void __init setup_arch(char **cmdline_p)
1696         data_resource.end = virt_to_phys(_edata)-1;
1697  
1698         parse_cmdline_early(cmdline_p);
1699 +       parse_early_param();
1700  
1701  #ifdef CONFIG_EARLY_PRINTK
1702         {
1703 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/i386/kernel/smpboot.c linux-2.6.18.kgdb/arch/i386/kernel/smpboot.c
1704 --- linux-2.6.18/arch/i386/kernel/smpboot.c     2006-09-20 07:42:06.000000000 +0400
1705 +++ linux-2.6.18.kgdb/arch/i386/kernel/smpboot.c        2008-06-10 16:19:58.000000000 +0400
1706 @@ -592,6 +592,9 @@ void __devinit initialize_secondary(void
1707  
1708         asm volatile(
1709                 "movl %0,%%esp\n\t"
1710 +#ifdef CONFIG_KGDB
1711 +               "pushl end_of_stack_stop_unwind_function\n\t"
1712 +#endif
1713                 "jmp *%1"
1714                 :
1715                 :"r" (current->thread.esp),"r" (current->thread.eip));
1716 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/i386/kernel/traps.c linux-2.6.18.kgdb/arch/i386/kernel/traps.c
1717 --- linux-2.6.18/arch/i386/kernel/traps.c       2006-09-20 07:42:06.000000000 +0400
1718 +++ linux-2.6.18.kgdb/arch/i386/kernel/traps.c  2008-06-10 16:19:17.000000000 +0400
1719 @@ -863,6 +863,7 @@ fastcall void __kprobes do_debug(struct 
1720          */
1721  clear_dr7:
1722         set_debugreg(0, 7);
1723 +       notify_die(DIE_DEBUG, "debug2", regs, condition, error_code, SIGTRAP);
1724         return;
1725  
1726  debug_vm86:
1727 @@ -1167,6 +1168,12 @@ static void __init set_task_gate(unsigne
1728         _set_gate(idt_table+n,5,0,0,(gdt_entry<<3));
1729  }
1730  
1731 +/* Some traps need to be set early. */
1732 +void __init early_trap_init(void) {
1733 +       set_intr_gate(1,&debug);
1734 +       set_system_intr_gate(3, &int3); /* int3 can be called from all */
1735 +       set_intr_gate(14,&page_fault);
1736 +}
1737  
1738  void __init trap_init(void)
1739  {
1740 @@ -1183,10 +1190,8 @@ void __init trap_init(void)
1741  #endif
1742  
1743         set_trap_gate(0,&divide_error);
1744 -       set_intr_gate(1,&debug);
1745         set_intr_gate(2,&nmi);
1746 -       set_system_intr_gate(3, &int3); /* int3/4 can be called from all */
1747 -       set_system_gate(4,&overflow);
1748 +       set_system_gate(4,&overflow); /* int4/5 can be called from all */
1749         set_trap_gate(5,&bounds);
1750         set_trap_gate(6,&invalid_op);
1751         set_trap_gate(7,&device_not_available);
1752 @@ -1196,7 +1201,6 @@ void __init trap_init(void)
1753         set_trap_gate(11,&segment_not_present);
1754         set_trap_gate(12,&stack_segment);
1755         set_trap_gate(13,&general_protection);
1756 -       set_intr_gate(14,&page_fault);
1757         set_trap_gate(15,&spurious_interrupt_bug);
1758         set_trap_gate(16,&coprocessor_error);
1759         set_trap_gate(17,&alignment_check);
1760 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/i386/mm/fault.c linux-2.6.18.kgdb/arch/i386/mm/fault.c
1761 --- linux-2.6.18/arch/i386/mm/fault.c   2006-09-20 07:42:06.000000000 +0400
1762 +++ linux-2.6.18.kgdb/arch/i386/mm/fault.c      2008-06-10 16:19:17.000000000 +0400
1763 @@ -539,6 +539,10 @@ no_context:
1764         if (is_prefetch(regs, address, error_code))
1765                 return;
1766  
1767 +       if (notify_die(DIE_PAGE_FAULT_NO_CONTEXT, "no context", regs,
1768 +                               error_code, 14, SIGSEGV) == NOTIFY_STOP)
1769 +               return;
1770 +
1771  /*
1772   * Oops. The kernel tried to access some bad page. We'll have to
1773   * terminate things with extreme prejudice.
1774 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/kernel/Makefile linux-2.6.18.kgdb/arch/ia64/kernel/Makefile
1775 --- linux-2.6.18/arch/ia64/kernel/Makefile      2006-09-20 07:42:06.000000000 +0400
1776 +++ linux-2.6.18.kgdb/arch/ia64/kernel/Makefile 2008-06-10 16:19:32.000000000 +0400
1777 @@ -31,6 +31,7 @@ obj-$(CONFIG_KPROBES)         += kprobes.o jpro
1778  obj-$(CONFIG_IA64_UNCACHED_ALLOCATOR)  += uncached.o
1779  obj-$(CONFIG_AUDIT)            += audit.o
1780  mca_recovery-y                 += mca_drv.o mca_drv_asm.o
1781 +obj-$(CONFIG_KGDB)             += kgdb.o kgdb-jmp.o
1782  
1783  # The gate DSO image is built using a special linker script.
1784  targets += gate.so gate-syms.o
1785 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/kernel/entry.S linux-2.6.18.kgdb/arch/ia64/kernel/entry.S
1786 --- linux-2.6.18/arch/ia64/kernel/entry.S       2006-09-20 07:42:06.000000000 +0400
1787 +++ linux-2.6.18.kgdb/arch/ia64/kernel/entry.S  2008-06-10 16:20:23.000000000 +0400
1788 @@ -953,9 +953,9 @@ GLOBAL_ENTRY(ia64_leave_kernel)
1789         shr.u r18=r19,16        // get byte size of existing "dirty" partition
1790         ;;
1791         mov r16=ar.bsp          // get existing backing store pointer
1792 -       addl r17=THIS_CPU(ia64_phys_stacked_size_p8),r0
1793 +(pUStk)        addl r17=THIS_CPU(ia64_phys_stacked_size_p8),r0
1794         ;;
1795 -       ld4 r17=[r17]           // r17 = cpu_data->phys_stacked_size_p8
1796 +(pUStk)        ld4 r17=[r17]           // r17 = cpu_data->phys_stacked_size_p8
1797  (pKStk)        br.cond.dpnt skip_rbs_switch
1798  
1799         /*
1800 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/kernel/ivt.S linux-2.6.18.kgdb/arch/ia64/kernel/ivt.S
1801 --- linux-2.6.18/arch/ia64/kernel/ivt.S 2006-09-20 07:42:06.000000000 +0400
1802 +++ linux-2.6.18.kgdb/arch/ia64/kernel/ivt.S    2008-06-10 16:20:23.000000000 +0400
1803 @@ -52,6 +52,14 @@
1804  #include <asm/unistd.h>
1805  #include <asm/errno.h>
1806  
1807 +#ifdef CONFIG_KGDB
1808 +#define KGDB_ENABLE_PSR_DB mov r31=psr;; movl r30=IA64_PSR_DB;;        \
1809 +       or r31=r31,r30;;                                        \
1810 +       mov psr.l=r31;; srlz.i;;
1811 +#else
1812 +#define KGDB_ENABLE_PSR_DB
1813 +#endif
1814 +
1815  #if 1
1816  # define PSR_DEFAULT_BITS      psr.ac
1817  #else
1818 @@ -519,6 +527,7 @@ ENTRY(page_fault)
1819         movl r14=ia64_leave_kernel
1820         ;;
1821         SAVE_REST
1822 +       KGDB_ENABLE_PSR_DB
1823         mov rp=r14
1824         ;;
1825         adds out2=16,r12                        // out2 = pointer to pt_regs
1826 @@ -863,6 +872,7 @@ ENTRY(interrupt)
1827         srlz.i                  // ensure everybody knows psr.ic is back on
1828         ;;
1829         SAVE_REST
1830 +       KGDB_ENABLE_PSR_DB
1831         ;;
1832         MCA_RECOVER_RANGE(interrupt)
1833         alloc r14=ar.pfs,0,0,2,0 // must be first in an insn group
1834 @@ -1110,6 +1120,7 @@ ENTRY(non_syscall)
1835         movl r15=ia64_leave_kernel
1836         ;;
1837         SAVE_REST
1838 +       KGDB_ENABLE_PSR_DB
1839         mov rp=r15
1840         ;;
1841         br.call.sptk.many b6=ia64_bad_break     // avoid WAW on CFM and ignore return addr
1842 @@ -1143,6 +1154,7 @@ ENTRY(dispatch_unaligned_handler)
1843         adds r3=8,r2                            // set up second base pointer
1844         ;;
1845         SAVE_REST
1846 +       KGDB_ENABLE_PSR_DB
1847         movl r14=ia64_leave_kernel
1848         ;;
1849         mov rp=r14
1850 @@ -1185,6 +1197,10 @@ ENTRY(dispatch_to_fault_handler)
1851         adds r3=8,r2                            // set up second base pointer for SAVE_REST
1852         ;;
1853         SAVE_REST
1854 +       cmp.eq p6,p0=29,out0
1855 +(p6)   br.cond.spnt 1f;;                       // debug_vector
1856 +       KGDB_ENABLE_PSR_DB
1857 +1:
1858         movl r14=ia64_leave_kernel
1859         ;;
1860         mov rp=r14
1861 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/kernel/kgdb-jmp.S linux-2.6.18.kgdb/arch/ia64/kernel/kgdb-jmp.S
1862 --- linux-2.6.18/arch/ia64/kernel/kgdb-jmp.S    1970-01-01 03:00:00.000000000 +0300
1863 +++ linux-2.6.18.kgdb/arch/ia64/kernel/kgdb-jmp.S       2008-06-10 16:19:32.000000000 +0400
1864 @@ -0,0 +1,238 @@
1865 +/* setjmp() and longjmp() assembler support for kdb on ia64.
1866 +
1867 +   This code was copied from glibc CVS as of 2001-06-27 and modified where
1868 +   necessary to fit the kernel.
1869 +   Keith Owens <kaos@melbourne.sgi.com> 2001-06-27
1870 + */
1871 +
1872 +/* Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
1873 +   Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
1874 +
1875 +   The GNU C Library is free software; you can redistribute it and/or
1876 +   modify it under the terms of the GNU Library General Public License as
1877 +   published by the Free Software Foundation; either version 2 of the
1878 +   License, or (at your option) any later version.
1879 +
1880 +   The GNU C Library is distributed in the hope that it will be useful,
1881 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
1882 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1883 +   Library General Public License for more details.
1884 +
1885 +   You should have received a copy of the GNU Library General Public
1886 +   License along with the GNU C Library; see the file COPYING.LIB.  If
1887 +   not, write to the Free Software Foundation, Inc.,
1888 +   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1889 +*/
1890 +
1891 +#include <asm/asmmacro.h>
1892 +GLOBAL_ENTRY(kgdb_fault_setjmp)
1893 +       .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(2)
1894 +       alloc loc1=ar.pfs,2,2,2,0
1895 +       mov r16=ar.unat
1896 +       ;;
1897 +       mov r17=ar.fpsr
1898 +       mov r2=in0
1899 +       add r3=8,in0
1900 +       ;;
1901 +.mem.offset 0,0;
1902 +       st8.spill.nta [r2]=sp,16        // r12 (sp)
1903 +.mem.offset 8,0;
1904 +       st8.spill.nta [r3]=gp,16        // r1 (gp)
1905 +       ;;
1906 +       st8.nta [r2]=r16,16             // save caller's unat
1907 +       st8.nta [r3]=r17,16             // save fpsr
1908 +       add r8=0xa0,in0
1909 +       ;;
1910 +.mem.offset 160,0;
1911 +       st8.spill.nta [r2]=r4,16        // r4
1912 +.mem.offset 168,0;
1913 +       st8.spill.nta [r3]=r5,16        // r5
1914 +       add r9=0xb0,in0
1915 +       ;;
1916 +       stf.spill.nta [r8]=f2,32
1917 +       stf.spill.nta [r9]=f3,32
1918 +       mov loc0=rp
1919 +       .body
1920 +       ;;
1921 +       stf.spill.nta [r8]=f4,32
1922 +       stf.spill.nta [r9]=f5,32
1923 +       mov r17=b1
1924 +       ;;
1925 +       stf.spill.nta [r8]=f16,32
1926 +       stf.spill.nta [r9]=f17,32
1927 +       mov r18=b2
1928 +       ;;
1929 +       stf.spill.nta [r8]=f18,32
1930 +       stf.spill.nta [r9]=f19,32
1931 +       mov r19=b3
1932 +       ;;
1933 +       stf.spill.nta [r8]=f20,32
1934 +       stf.spill.nta [r9]=f21,32
1935 +       mov r20=b4
1936 +       ;;
1937 +       stf.spill.nta [r8]=f22,32
1938 +       stf.spill.nta [r9]=f23,32
1939 +       mov r21=b5
1940 +       ;;
1941 +       stf.spill.nta [r8]=f24,32
1942 +       stf.spill.nta [r9]=f25,32
1943 +       mov r22=ar.lc
1944 +       ;;
1945 +       stf.spill.nta [r8]=f26,32
1946 +       stf.spill.nta [r9]=f27,32
1947 +       mov r24=pr
1948 +       ;;
1949 +       stf.spill.nta [r8]=f28,32
1950 +       stf.spill.nta [r9]=f29,32
1951 +       ;;
1952 +       stf.spill.nta [r8]=f30
1953 +       stf.spill.nta [r9]=f31
1954 +
1955 +.mem.offset 0,0;
1956 +       st8.spill.nta [r2]=r6,16        // r6
1957 +.mem.offset 8,0;
1958 +       st8.spill.nta [r3]=r7,16        // r7
1959 +       ;;
1960 +       mov r23=ar.bsp
1961 +       mov r25=ar.unat
1962 +       st8.nta [r2]=loc0,16            // b0
1963 +       st8.nta [r3]=r17,16             // b1
1964 +       ;;
1965 +       st8.nta [r2]=r18,16             // b2
1966 +       st8.nta [r3]=r19,16             // b3
1967 +       ;;
1968 +       st8.nta [r2]=r20,16             // b4
1969 +       st8.nta [r3]=r21,16             // b5
1970 +       ;;
1971 +       st8.nta [r2]=loc1,16            // ar.pfs
1972 +       st8.nta [r3]=r22,16             // ar.lc
1973 +       ;;
1974 +       st8.nta [r2]=r24,16             // pr
1975 +       st8.nta [r3]=r23,16             // ar.bsp
1976 +       ;;
1977 +       st8.nta [r2]=r25                // ar.unat
1978 +       st8.nta [r3]=in0                // &__jmp_buf
1979 +       mov r8=0
1980 +       mov rp=loc0
1981 +       mov ar.pfs=loc1
1982 +       br.ret.sptk.few rp
1983 +END(kdba_setjmp)
1984 +#define        pPos    p6      /* is rotate count positive? */
1985 +#define        pNeg    p7      /* is rotate count negative? */
1986 +GLOBAL_ENTRY(kgdb_fault_longjmp)
1987 +       alloc r8=ar.pfs,2,1,0,0
1988 +       mov r27=ar.rsc
1989 +       add r2=0x98,in0         // r2 <- &jmpbuf.orig_jmp_buf_addr
1990 +       ;;
1991 +       ld8 r8=[r2],-16         // r8 <- orig_jmp_buf_addr
1992 +       mov r10=ar.bsp
1993 +       and r11=~0x3,r27        // clear ar.rsc.mode
1994 +       ;;
1995 +       flushrs                 // flush dirty regs to backing store (must be first in insn grp)
1996 +       ld8 r23=[r2],8          // r23 <- jmpbuf.ar_bsp
1997 +       sub r8=r8,in0           // r8 <- &orig_jmpbuf - &jmpbuf
1998 +       ;;
1999 +       ld8 r25=[r2]            // r25 <- jmpbuf.ar_unat
2000 +       extr.u r8=r8,3,6        // r8 <- (&orig_jmpbuf - &jmpbuf)/8 & 0x3f
2001 +       ;;
2002 +       cmp.lt pNeg,pPos=r8,r0
2003 +       mov r2=in0
2004 +       ;;
2005 +(pPos) mov r16=r8
2006 +(pNeg) add r16=64,r8
2007 +(pPos) sub r17=64,r8
2008 +(pNeg) sub r17=r0,r8
2009 +       ;;
2010 +       mov ar.rsc=r11          // put RSE in enforced lazy mode
2011 +       shr.u r8=r25,r16
2012 +       add r3=8,in0            // r3 <- &jmpbuf.r1
2013 +       shl r9=r25,r17
2014 +       ;;
2015 +       or r25=r8,r9
2016 +       ;;
2017 +       mov r26=ar.rnat
2018 +       mov ar.unat=r25         // setup ar.unat (NaT bits for r1, r4-r7, and r12)
2019 +       ;;
2020 +       ld8.fill.nta sp=[r2],16 // r12 (sp)
2021 +       ld8.fill.nta gp=[r3],16         // r1 (gp)
2022 +       dep r11=-1,r23,3,6      // r11 <- ia64_rse_rnat_addr(jmpbuf.ar_bsp)
2023 +       ;;
2024 +       ld8.nta r16=[r2],16             // caller's unat
2025 +       ld8.nta r17=[r3],16             // fpsr
2026 +       ;;
2027 +       ld8.fill.nta r4=[r2],16 // r4
2028 +       ld8.fill.nta r5=[r3],16         // r5 (gp)
2029 +       cmp.geu p8,p0=r10,r11   // p8 <- (ar.bsp >= jmpbuf.ar_bsp)
2030 +       ;;
2031 +       ld8.fill.nta r6=[r2],16 // r6
2032 +       ld8.fill.nta r7=[r3],16         // r7
2033 +       ;;
2034 +       mov ar.unat=r16                 // restore caller's unat
2035 +       mov ar.fpsr=r17                 // restore fpsr
2036 +       ;;
2037 +       ld8.nta r16=[r2],16             // b0
2038 +       ld8.nta r17=[r3],16             // b1
2039 +       ;;
2040 +(p8)   ld8 r26=[r11]           // r26 <- *ia64_rse_rnat_addr(jmpbuf.ar_bsp)
2041 +       mov ar.bspstore=r23     // restore ar.bspstore
2042 +       ;;
2043 +       ld8.nta r18=[r2],16             // b2
2044 +       ld8.nta r19=[r3],16             // b3
2045 +       ;;
2046 +       ld8.nta r20=[r2],16             // b4
2047 +       ld8.nta r21=[r3],16             // b5
2048 +       ;;
2049 +       ld8.nta r11=[r2],16             // ar.pfs
2050 +       ld8.nta r22=[r3],56             // ar.lc
2051 +       ;;
2052 +       ld8.nta r24=[r2],32             // pr
2053 +       mov b0=r16
2054 +       ;;
2055 +       ldf.fill.nta f2=[r2],32
2056 +       ldf.fill.nta f3=[r3],32
2057 +       mov b1=r17
2058 +       ;;
2059 +       ldf.fill.nta f4=[r2],32
2060 +       ldf.fill.nta f5=[r3],32
2061 +       mov b2=r18
2062 +       ;;
2063 +       ldf.fill.nta f16=[r2],32
2064 +       ldf.fill.nta f17=[r3],32
2065 +       mov b3=r19
2066 +       ;;
2067 +       ldf.fill.nta f18=[r2],32
2068 +       ldf.fill.nta f19=[r3],32
2069 +       mov b4=r20
2070 +       ;;
2071 +       ldf.fill.nta f20=[r2],32
2072 +       ldf.fill.nta f21=[r3],32
2073 +       mov b5=r21
2074 +       ;;
2075 +       ldf.fill.nta f22=[r2],32
2076 +       ldf.fill.nta f23=[r3],32
2077 +       mov ar.lc=r22
2078 +       ;;
2079 +       ldf.fill.nta f24=[r2],32
2080 +       ldf.fill.nta f25=[r3],32
2081 +       cmp.eq p8,p9=0,in1
2082 +       ;;
2083 +       ldf.fill.nta f26=[r2],32
2084 +       ldf.fill.nta f27=[r3],32
2085 +       mov ar.pfs=r11
2086 +       ;;
2087 +       ldf.fill.nta f28=[r2],32
2088 +       ldf.fill.nta f29=[r3],32
2089 +       ;;
2090 +       ldf.fill.nta f30=[r2]
2091 +       ldf.fill.nta f31=[r3]
2092 +(p8)   mov r8=1
2093 +
2094 +       mov ar.rnat=r26         // restore ar.rnat
2095 +       ;;
2096 +       mov ar.rsc=r27          // restore ar.rsc
2097 +(p9)   mov r8=in1
2098 +
2099 +       invala                  // virt. -> phys. regnum mapping may change
2100 +       mov pr=r24,-1
2101 +       br.ret.sptk.few rp
2102 +END(kgdb_fault_longjmp)
2103 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/kernel/kgdb.c linux-2.6.18.kgdb/arch/ia64/kernel/kgdb.c
2104 --- linux-2.6.18/arch/ia64/kernel/kgdb.c        1970-01-01 03:00:00.000000000 +0300
2105 +++ linux-2.6.18.kgdb/arch/ia64/kernel/kgdb.c   2008-06-10 16:19:32.000000000 +0400
2106 @@ -0,0 +1,1131 @@
2107 +/*
2108 + *
2109 + * This program is free software; you can redistribute it and/or modify it
2110 + * under the terms of the GNU General Public License as published by the
2111 + * Free Software Foundation; either version 2, or (at your option) any
2112 + * later version.
2113 + *
2114 + * This program is distributed in the hope that it will be useful, but
2115 + * WITHOUT ANY WARRANTY; without even the implied warranty of
2116 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2117 + * General Public License for more details.
2118 + *
2119 + */
2120 +
2121 +/*
2122 + * Copyright (C) 2000-2001 VERITAS Software Corporation.
2123 + * (c) Copyright 2005 Hewlett-Packard Development Company, L.P.
2124 + *     Bob Picco <bob.picco@hp.com>
2125 + */
2126 +/*
2127 + *  Contributor:     Lake Stevens Instrument Division$
2128 + *  Written by:      Glenn Engel $
2129 + *  Updated by:             Amit Kale<akale@veritas.com>
2130 + *  Modified for 386 by Jim Kingdon, Cygnus Support.
2131 + *  Origianl kgdb, compatibility with 2.1.xx kernel by David Grothe <dave@gcom.com>
2132 + */
2133 +
2134 +#include <linux/string.h>
2135 +#include <linux/kernel.h>
2136 +#include <linux/sched.h>
2137 +#include <linux/smp.h>
2138 +#include <linux/spinlock.h>
2139 +#include <linux/delay.h>
2140 +#include <asm/system.h>
2141 +#include <asm/ptrace.h>                /* for linux pt_regs struct */
2142 +#include <asm/unwind.h>
2143 +#include <asm/rse.h>
2144 +#include <linux/kgdb.h>
2145 +#include <linux/init.h>
2146 +#include <asm/cacheflush.h>
2147 +#include <asm/kdebug.h>
2148 +
2149 +#define NUM_REGS 590
2150 +#define REGISTER_BYTES (NUM_REGS*8+128*8)
2151 +#define REGISTER_BYTE(N) (((N) * 8)                                    \
2152 +       + ((N) <= IA64_FR0_REGNUM ?                                     \
2153 +       0 : 8 * (((N) > IA64_FR127_REGNUM) ? 128 : (N) - IA64_FR0_REGNUM)))
2154 +#define REGISTER_SIZE(N)                                               \
2155 +       (((N) >= IA64_FR0_REGNUM && (N) <= IA64_FR127_REGNUM) ? 16 : 8)
2156 +#define IA64_GR0_REGNUM         0
2157 +#define IA64_FR0_REGNUM         128
2158 +#define IA64_FR127_REGNUM       (IA64_FR0_REGNUM+127)
2159 +#define IA64_PR0_REGNUM         256
2160 +#define IA64_BR0_REGNUM         320
2161 +#define IA64_VFP_REGNUM         328
2162 +#define IA64_PR_REGNUM          330
2163 +#define IA64_IP_REGNUM          331
2164 +#define IA64_PSR_REGNUM         332
2165 +#define IA64_CFM_REGNUM         333
2166 +#define IA64_AR0_REGNUM         334
2167 +#define IA64_NAT0_REGNUM        462
2168 +#define IA64_NAT31_REGNUM       (IA64_NAT0_REGNUM+31)
2169 +#define IA64_NAT32_REGNUM       (IA64_NAT0_REGNUM+32)
2170 +#define IA64_RSC_REGNUM                (IA64_AR0_REGNUM+16)
2171 +#define IA64_BSP_REGNUM                (IA64_AR0_REGNUM+17)
2172 +#define IA64_BSPSTORE_REGNUM   (IA64_AR0_REGNUM+18)
2173 +#define IA64_RNAT_REGNUM       (IA64_AR0_REGNUM+19)
2174 +#define IA64_FCR_REGNUM                (IA64_AR0_REGNUM+21)
2175 +#define IA64_EFLAG_REGNUM      (IA64_AR0_REGNUM+24)
2176 +#define IA64_CSD_REGNUM                (IA64_AR0_REGNUM+25)
2177 +#define IA64_SSD_REGNUM                (IA64_AR0_REGNUM+26)
2178 +#define IA64_CFLG_REGNUM       (IA64_AR0_REGNUM+27)
2179 +#define IA64_FSR_REGNUM                (IA64_AR0_REGNUM+28)
2180 +#define IA64_FIR_REGNUM                (IA64_AR0_REGNUM+29)
2181 +#define IA64_FDR_REGNUM                (IA64_AR0_REGNUM+30)
2182 +#define IA64_CCV_REGNUM                (IA64_AR0_REGNUM+32)
2183 +#define IA64_UNAT_REGNUM       (IA64_AR0_REGNUM+36)
2184 +#define IA64_FPSR_REGNUM       (IA64_AR0_REGNUM+40)
2185 +#define IA64_ITC_REGNUM                (IA64_AR0_REGNUM+44)
2186 +#define IA64_PFS_REGNUM                (IA64_AR0_REGNUM+64)
2187 +#define IA64_LC_REGNUM         (IA64_AR0_REGNUM+65)
2188 +#define IA64_EC_REGNUM         (IA64_AR0_REGNUM+66)
2189 +
2190 +#define        REGISTER_INDEX(N)       (REGISTER_BYTE(N) / sizeof (unsigned long))
2191 +#define BREAK_INSTR_ALIGN      (~0xfULL)
2192 +
2193 +#define        ptoff(V)        ((unsigned int) &((struct pt_regs *)0x0)->V)
2194 +struct reg_to_ptreg_index {
2195 +       unsigned int reg;
2196 +       unsigned int ptregoff;
2197 +};
2198 +
2199 +static struct reg_to_ptreg_index gr_reg_to_ptreg_index[] = {
2200 +       {IA64_GR0_REGNUM + 1, ptoff(r1)},
2201 +       {IA64_GR0_REGNUM + 2, ptoff(r2)},
2202 +       {IA64_GR0_REGNUM + 3, ptoff(r3)},
2203 +       {IA64_GR0_REGNUM + 8, ptoff(r8)},
2204 +       {IA64_GR0_REGNUM + 9, ptoff(r9)},
2205 +       {IA64_GR0_REGNUM + 10, ptoff(r10)},
2206 +       {IA64_GR0_REGNUM + 11, ptoff(r11)},
2207 +       {IA64_GR0_REGNUM + 12, ptoff(r12)},
2208 +       {IA64_GR0_REGNUM + 13, ptoff(r13)},
2209 +       {IA64_GR0_REGNUM + 14, ptoff(r14)},
2210 +       {IA64_GR0_REGNUM + 15, ptoff(r15)},
2211 +       {IA64_GR0_REGNUM + 16, ptoff(r16)},
2212 +       {IA64_GR0_REGNUM + 17, ptoff(r17)},
2213 +       {IA64_GR0_REGNUM + 18, ptoff(r18)},
2214 +       {IA64_GR0_REGNUM + 19, ptoff(r19)},
2215 +       {IA64_GR0_REGNUM + 20, ptoff(r20)},
2216 +       {IA64_GR0_REGNUM + 21, ptoff(r21)},
2217 +       {IA64_GR0_REGNUM + 22, ptoff(r22)},
2218 +       {IA64_GR0_REGNUM + 23, ptoff(r23)},
2219 +       {IA64_GR0_REGNUM + 24, ptoff(r24)},
2220 +       {IA64_GR0_REGNUM + 25, ptoff(r25)},
2221 +       {IA64_GR0_REGNUM + 26, ptoff(r26)},
2222 +       {IA64_GR0_REGNUM + 27, ptoff(r27)},
2223 +       {IA64_GR0_REGNUM + 28, ptoff(r28)},
2224 +       {IA64_GR0_REGNUM + 29, ptoff(r29)},
2225 +       {IA64_GR0_REGNUM + 30, ptoff(r30)},
2226 +       {IA64_GR0_REGNUM + 31, ptoff(r31)},
2227 +};
2228 +
2229 +static struct reg_to_ptreg_index br_reg_to_ptreg_index[] = {
2230 +       {IA64_BR0_REGNUM, ptoff(b0)},
2231 +       {IA64_BR0_REGNUM + 6, ptoff(b6)},
2232 +       {IA64_BR0_REGNUM + 7, ptoff(b7)},
2233 +};
2234 +
2235 +static struct reg_to_ptreg_index ar_reg_to_ptreg_index[] = {
2236 +       {IA64_PFS_REGNUM, ptoff(ar_pfs)},
2237 +       {IA64_UNAT_REGNUM, ptoff(ar_unat)},
2238 +       {IA64_RNAT_REGNUM, ptoff(ar_rnat)},
2239 +       {IA64_BSPSTORE_REGNUM, ptoff(ar_bspstore)},
2240 +       {IA64_RSC_REGNUM, ptoff(ar_rsc)},
2241 +       {IA64_CSD_REGNUM, ptoff(ar_csd)},
2242 +       {IA64_SSD_REGNUM, ptoff(ar_ssd)},
2243 +       {IA64_FPSR_REGNUM, ptoff(ar_fpsr)},
2244 +       {IA64_CCV_REGNUM, ptoff(ar_ccv)},
2245 +};
2246 +
2247 +extern atomic_t cpu_doing_single_step;
2248 +
2249 +static int kgdb_gr_reg(int regnum, struct unw_frame_info *info,
2250 +       unsigned long *reg, int rw)
2251 +{
2252 +       char nat;
2253 +
2254 +       if ((regnum >= IA64_GR0_REGNUM && regnum <= (IA64_GR0_REGNUM + 1)) ||
2255 +               (regnum >= (IA64_GR0_REGNUM + 4) &&
2256 +               regnum <= (IA64_GR0_REGNUM + 7)))
2257 +               return !unw_access_gr(info, regnum - IA64_GR0_REGNUM,
2258 +               reg, &nat, rw);
2259 +       else
2260 +               return 0;
2261 +}
2262 +static int kgdb_gr_ptreg(int regnum, struct pt_regs * ptregs,
2263 +       struct unw_frame_info *info, unsigned long *reg, int rw)
2264 +{
2265 +       int i, result = 1;
2266 +       char nat;
2267 +
2268 +       if (!((regnum >= (IA64_GR0_REGNUM + 2) &&
2269 +               regnum <= (IA64_GR0_REGNUM + 3)) ||
2270 +               (regnum >= (IA64_GR0_REGNUM + 8) &&
2271 +               regnum <= (IA64_GR0_REGNUM + 15)) ||
2272 +               (regnum >= (IA64_GR0_REGNUM + 16) &&
2273 +               regnum <= (IA64_GR0_REGNUM + 31))))
2274 +               return 0;
2275 +       else if (rw && ptregs) {
2276 +               for (i = 0; i < ARRAY_SIZE(gr_reg_to_ptreg_index); i++)
2277 +                       if (gr_reg_to_ptreg_index[i].reg == regnum) {
2278 +                               *((unsigned long *)(((void *)ptregs) +
2279 +                               gr_reg_to_ptreg_index[i].ptregoff)) = *reg;
2280 +                               break;
2281 +                       }
2282 +       } else if (!rw && ptregs) {
2283 +               for (i = 0; i < ARRAY_SIZE(gr_reg_to_ptreg_index); i++)
2284 +                       if (gr_reg_to_ptreg_index[i].reg == regnum) {
2285 +                               *reg = *((unsigned long *)
2286 +                               (((void *)ptregs) +
2287 +                                gr_reg_to_ptreg_index[i].ptregoff));
2288 +                               break;
2289 +                       }
2290 +       } else
2291 +               result = !unw_access_gr(info, regnum - IA64_GR0_REGNUM,
2292 +                                       reg, &nat, rw);
2293 +       return result;
2294 +}
2295 +
2296 +static int kgdb_br_reg(int regnum, struct pt_regs * ptregs,
2297 +       struct unw_frame_info *info, unsigned long *reg, int rw)
2298 +{
2299 +       int i, result = 1;
2300 +
2301 +       if (!(regnum >= IA64_BR0_REGNUM && regnum <= (IA64_BR0_REGNUM + 7)))
2302 +               return 0;
2303 +
2304 +       switch (regnum) {
2305 +       case IA64_BR0_REGNUM:
2306 +       case IA64_BR0_REGNUM + 6:
2307 +       case IA64_BR0_REGNUM + 7:
2308 +               if (rw) {
2309 +                       for (i = 0; i < ARRAY_SIZE(br_reg_to_ptreg_index); i++)
2310 +                               if (br_reg_to_ptreg_index[i].reg == regnum) {
2311 +                                       *((unsigned long *)
2312 +                                       (((void *)ptregs) +
2313 +                                       br_reg_to_ptreg_index[i].ptregoff)) =
2314 +                                       *reg;
2315 +                                       break;
2316 +                               }
2317 +               } else
2318 +                       for (i = 0; i < ARRAY_SIZE(br_reg_to_ptreg_index); i++)
2319 +                               if (br_reg_to_ptreg_index[i].reg == regnum) {
2320 +                                               *reg = *((unsigned long *)
2321 +                                               (((void *)ptregs) +
2322 +                                               br_reg_to_ptreg_index[i].
2323 +                                               ptregoff));
2324 +                                               break;
2325 +                               }
2326 +               break;
2327 +       case IA64_BR0_REGNUM + 1:
2328 +       case IA64_BR0_REGNUM + 2:
2329 +       case IA64_BR0_REGNUM + 3:
2330 +       case IA64_BR0_REGNUM + 4:
2331 +       case IA64_BR0_REGNUM + 5:
2332 +               result = !unw_access_br(info, regnum - IA64_BR0_REGNUM,
2333 +                               reg, rw);
2334 +               break;
2335 +       }
2336 +
2337 +       return result;
2338 +}
2339 +
2340 +static int kgdb_fr_reg(int regnum, char *inbuffer, struct pt_regs * ptregs,
2341 +       struct unw_frame_info *info, unsigned long *reg,
2342 +       struct ia64_fpreg *freg, int rw)
2343 +{
2344 +       int result = 1;
2345 +
2346 +       if (!(regnum >= IA64_FR0_REGNUM && regnum <= (IA64_FR0_REGNUM + 127)))
2347 +               return 0;
2348 +
2349 +       switch (regnum) {
2350 +       case IA64_FR0_REGNUM + 6:
2351 +       case IA64_FR0_REGNUM + 7:
2352 +       case IA64_FR0_REGNUM + 8:
2353 +       case IA64_FR0_REGNUM + 9:
2354 +       case IA64_FR0_REGNUM + 10:
2355 +       case IA64_FR0_REGNUM + 11:
2356 +       case IA64_FR0_REGNUM + 12:
2357 +               if (rw) {
2358 +                       char *ptr = inbuffer;
2359 +
2360 +                       freg->u.bits[0] = *reg;
2361 +                       kgdb_hex2long(&ptr, &freg->u.bits[1]);
2362 +                       *(&ptregs->f6 + (regnum - (IA64_FR0_REGNUM + 6))) =
2363 +                               *freg;
2364 +                       break;
2365 +               } else if (!ptregs)
2366 +                       result = !unw_access_fr(info, regnum - IA64_FR0_REGNUM,
2367 +                               freg, rw);
2368 +               else
2369 +                       *freg =
2370 +                       *(&ptregs->f6 + (regnum - (IA64_FR0_REGNUM + 6)));
2371 +               break;
2372 +       default:
2373 +               if (!rw)
2374 +                       result = !unw_access_fr(info, regnum - IA64_FR0_REGNUM,
2375 +                               freg, rw);
2376 +               else
2377 +                       result = 0;
2378 +               break;
2379 +       }
2380 +
2381 +       return result;
2382 +}
2383 +
2384 +static int kgdb_ar_reg(int regnum, struct pt_regs * ptregs,
2385 +       struct unw_frame_info *info, unsigned long *reg, int rw)
2386 +{
2387 +       int result = 0, i;
2388 +
2389 +       if (!(regnum >= IA64_AR0_REGNUM && regnum <= IA64_EC_REGNUM))
2390 +               return 0;
2391 +
2392 +       if (rw && ptregs) {
2393 +               for (i = 0; i < ARRAY_SIZE(ar_reg_to_ptreg_index); i++)
2394 +                       if (ar_reg_to_ptreg_index[i].reg == regnum) {
2395 +                               *((unsigned long *) (((void *)ptregs) +
2396 +                               ar_reg_to_ptreg_index[i].ptregoff)) =
2397 +                                       *reg;
2398 +                               result = 1;
2399 +                               break;
2400 +                       }
2401 +       } else if (ptregs) {
2402 +               for (i = 0; i < ARRAY_SIZE(ar_reg_to_ptreg_index); i++)
2403 +                       if (ar_reg_to_ptreg_index[i].reg == regnum) {
2404 +                               *reg = *((unsigned long *) (((void *)ptregs) +
2405 +                                       ar_reg_to_ptreg_index[i].ptregoff));
2406 +                                       result = 1;
2407 +                               break;
2408 +                       }
2409 +       }
2410 +
2411 +       if (result)
2412 +               return result;
2413 +
2414 +       result = 1;
2415 +
2416 +       switch (regnum) {
2417 +       case IA64_CSD_REGNUM:
2418 +               result = !unw_access_ar(info, UNW_AR_CSD, reg, rw);
2419 +               break;
2420 +       case IA64_SSD_REGNUM:
2421 +               result = !unw_access_ar(info, UNW_AR_SSD, reg, rw);
2422 +               break;
2423 +       case IA64_UNAT_REGNUM:
2424 +               result = !unw_access_ar(info, UNW_AR_RNAT, reg, rw);
2425 +               break;
2426 +               case IA64_RNAT_REGNUM:
2427 +               result = !unw_access_ar(info, UNW_AR_RNAT, reg, rw);
2428 +               break;
2429 +       case IA64_BSPSTORE_REGNUM:
2430 +               result = !unw_access_ar(info, UNW_AR_RNAT, reg, rw);
2431 +               break;
2432 +       case IA64_PFS_REGNUM:
2433 +               result = !unw_access_ar(info, UNW_AR_RNAT, reg, rw);
2434 +               break;
2435 +       case IA64_LC_REGNUM:
2436 +               result = !unw_access_ar(info, UNW_AR_LC, reg, rw);
2437 +               break;
2438 +       case IA64_EC_REGNUM:
2439 +               result = !unw_access_ar(info, UNW_AR_EC, reg, rw);
2440 +               break;
2441 +       case IA64_FPSR_REGNUM:
2442 +               result = !unw_access_ar(info, UNW_AR_FPSR, reg, rw);
2443 +               break;
2444 +       case IA64_RSC_REGNUM:
2445 +               result = !unw_access_ar(info, UNW_AR_RSC, reg, rw);
2446 +               break;
2447 +       case IA64_CCV_REGNUM:
2448 +               result = !unw_access_ar(info, UNW_AR_CCV, reg, rw);
2449 +               break;
2450 +       default:
2451 +               result = 0;
2452 +       }
2453 +
2454 +       return result;
2455 +}
2456 +
2457 +void kgdb_get_reg(char *outbuffer, int regnum, struct unw_frame_info *info,
2458 +       struct pt_regs *ptregs)
2459 +{
2460 +       unsigned long reg, size = 0, *mem = &reg;
2461 +       struct ia64_fpreg freg;
2462 +
2463 +       if (kgdb_gr_reg(regnum, info, &reg, 0) ||
2464 +               kgdb_gr_ptreg(regnum, ptregs, info, &reg, 0) ||
2465 +               kgdb_br_reg(regnum, ptregs, info, &reg, 0) ||
2466 +               kgdb_ar_reg(regnum, ptregs, info, &reg, 0))
2467 +                       size = sizeof(reg);
2468 +       else if (kgdb_fr_reg(regnum, NULL, ptregs, info, &reg, &freg, 0)) {
2469 +               size = sizeof(freg);
2470 +               mem = (unsigned long *)&freg;
2471 +       } else if (regnum == IA64_IP_REGNUM) {
2472 +               if (!ptregs) {
2473 +                       unw_get_ip(info, &reg);
2474 +                       size = sizeof(reg);
2475 +               } else {
2476 +                       reg = ptregs->cr_iip;
2477 +                       size = sizeof(reg);
2478 +               }
2479 +       } else if (regnum == IA64_CFM_REGNUM) {
2480 +               if (!ptregs)
2481 +                       unw_get_cfm(info, &reg);
2482 +               else
2483 +                       reg = ptregs->cr_ifs;
2484 +               size = sizeof(reg);
2485 +       } else if (regnum == IA64_PSR_REGNUM) {
2486 +               if (!ptregs && kgdb_usethread)
2487 +                       ptregs = (struct pt_regs *)
2488 +                       ((unsigned long)kgdb_usethread +
2489 +                       IA64_STK_OFFSET) - 1;
2490 +               if (ptregs)
2491 +                       reg = ptregs->cr_ipsr;
2492 +               size = sizeof(reg);
2493 +       } else if (regnum == IA64_PR_REGNUM) {
2494 +               if (ptregs)
2495 +                       reg = ptregs->pr;
2496 +               else
2497 +                       unw_access_pr(info, &reg, 0);
2498 +               size = sizeof(reg);
2499 +       } else if (regnum == IA64_BSP_REGNUM) {
2500 +               unw_get_bsp(info, &reg);
2501 +               size = sizeof(reg);
2502 +       }
2503 +
2504 +       if (size) {
2505 +               kgdb_mem2hex((char *) mem, outbuffer, size);
2506 +               outbuffer[size*2] = 0;
2507 +       }
2508 +       else
2509 +               strcpy(outbuffer, "E0");
2510 +
2511 +       return;
2512 +}
2513 +
2514 +void kgdb_put_reg(char *inbuffer, char *outbuffer, int regnum,
2515 +                 struct unw_frame_info *info, struct pt_regs *ptregs)
2516 +{
2517 +       unsigned long reg;
2518 +       struct ia64_fpreg freg;
2519 +       char *ptr = inbuffer;
2520 +
2521 +       kgdb_hex2long(&ptr, &reg);
2522 +       strcpy(outbuffer, "OK");
2523 +
2524 +       if (kgdb_gr_reg(regnum, info, &reg, 1) ||
2525 +               kgdb_gr_ptreg(regnum, ptregs, info, &reg, 1) ||
2526 +               kgdb_br_reg(regnum, ptregs, info, &reg, 1) ||
2527 +               kgdb_fr_reg(regnum, inbuffer, ptregs, info, &reg, &freg, 1) ||
2528 +               kgdb_ar_reg(regnum, ptregs, info, &reg, 1)) ;
2529 +       else if (regnum == IA64_IP_REGNUM)
2530 +               ptregs->cr_iip = reg;
2531 +       else if (regnum == IA64_CFM_REGNUM)
2532 +               ptregs->cr_ifs = reg;
2533 +       else if (regnum == IA64_PSR_REGNUM)
2534 +               ptregs->cr_ipsr = reg;
2535 +       else if (regnum == IA64_PR_REGNUM)
2536 +               ptregs->pr = reg;
2537 +       else
2538 +               strcpy(outbuffer, "E01");
2539 +       return;
2540 +}
2541 +
2542 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
2543 +{
2544 +}
2545 +
2546 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
2547 +{
2548 +}
2549 +
2550 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
2551 +{
2552 +
2553 +}
2554 +
2555 +#define        MAX_HW_BREAKPOINT       (20)
2556 +long hw_break_total_dbr, hw_break_total_ibr;
2557 +#define        HW_BREAKPOINT   (hw_break_total_dbr + hw_break_total_ibr)
2558 +#define        WATCH_INSTRUCTION       0x0
2559 +#define WATCH_WRITE            0x1
2560 +#define        WATCH_READ              0x2
2561 +#define        WATCH_ACCESS            0x3
2562 +
2563 +#define        HWCAP_DBR       ((1 << WATCH_WRITE) | (1 << WATCH_READ))
2564 +#define        HWCAP_IBR       (1 << WATCH_INSTRUCTION)
2565 +struct hw_breakpoint {
2566 +       unsigned enabled;
2567 +       unsigned long capable;
2568 +       unsigned long type;
2569 +       unsigned long mask;
2570 +       unsigned long addr;
2571 +} *breakinfo;
2572 +
2573 +static struct hw_breakpoint hwbreaks[MAX_HW_BREAKPOINT];
2574 +
2575 +enum instruction_type { A, I, M, F, B, L, X, u };
2576 +
2577 +static enum instruction_type bundle_encoding[32][3] = {
2578 +       {M, I, I},              /* 00 */
2579 +       {M, I, I},              /* 01 */
2580 +       {M, I, I},              /* 02 */
2581 +       {M, I, I},              /* 03 */
2582 +       {M, L, X},              /* 04 */
2583 +       {M, L, X},              /* 05 */
2584 +       {u, u, u},              /* 06 */
2585 +       {u, u, u},              /* 07 */
2586 +       {M, M, I},              /* 08 */
2587 +       {M, M, I},              /* 09 */
2588 +       {M, M, I},              /* 0A */
2589 +       {M, M, I},              /* 0B */
2590 +       {M, F, I},              /* 0C */
2591 +       {M, F, I},              /* 0D */
2592 +       {M, M, F},              /* 0E */
2593 +       {M, M, F},              /* 0F */
2594 +       {M, I, B},              /* 10 */
2595 +       {M, I, B},              /* 11 */
2596 +       {M, B, B},              /* 12 */
2597 +       {M, B, B},              /* 13 */
2598 +       {u, u, u},              /* 14 */
2599 +       {u, u, u},              /* 15 */
2600 +       {B, B, B},              /* 16 */
2601 +       {B, B, B},              /* 17 */
2602 +       {M, M, B},              /* 18 */
2603 +       {M, M, B},              /* 19 */
2604 +       {u, u, u},              /* 1A */
2605 +       {u, u, u},              /* 1B */
2606 +       {M, F, B},              /* 1C */
2607 +       {M, F, B},              /* 1D */
2608 +       {u, u, u},              /* 1E */
2609 +       {u, u, u},              /* 1F */
2610 +};
2611 +
2612 +int kgdb_validate_break_address(unsigned long addr)
2613 +{
2614 +       int error;
2615 +       char tmp_variable[BREAK_INSTR_SIZE];
2616 +       error = kgdb_get_mem((char *)(addr & BREAK_INSTR_ALIGN), tmp_variable,
2617 +               BREAK_INSTR_SIZE);
2618 +       return error;
2619 +}
2620 +
2621 +int kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr)
2622 +{
2623 +       extern unsigned long _start[];
2624 +       unsigned long slot = addr & BREAK_INSTR_ALIGN, bundle_addr;
2625 +       unsigned long template;
2626 +       struct bundle {
2627 +               struct {
2628 +                       unsigned long long template:5;
2629 +                       unsigned long long slot0:41;
2630 +                       unsigned long long slot1_p0:64 - 46;
2631 +               } quad0;
2632 +               struct {
2633 +                       unsigned long long slot1_p1:41 - (64 - 46);
2634 +                       unsigned long long slot2:41;
2635 +               } quad1;
2636 +       } bundle;
2637 +       int ret;
2638 +
2639 +       bundle_addr = addr & ~0xFULL;
2640 +
2641 +       if (bundle_addr == (unsigned long)_start)
2642 +               return 0;
2643 +
2644 +       ret = kgdb_get_mem((char *)bundle_addr, (char *)&bundle,
2645 +                          BREAK_INSTR_SIZE);
2646 +       if (ret < 0)
2647 +               return ret;
2648 +
2649 +       if (slot > 2)
2650 +               slot = 0;
2651 +
2652 +       memcpy(saved_instr, &bundle, BREAK_INSTR_SIZE);
2653 +       template = bundle.quad0.template;
2654 +
2655 +       if (slot == 1 && bundle_encoding[template][1] == L)
2656 +               slot = 2;
2657 +
2658 +       switch (slot) {
2659 +       case 0:
2660 +               bundle.quad0.slot0 = BREAKNUM;
2661 +               break;
2662 +       case 1:
2663 +               bundle.quad0.slot1_p0 = BREAKNUM;
2664 +               bundle.quad1.slot1_p1 = (BREAKNUM >> (64 - 46));
2665 +               break;
2666 +       case 2:
2667 +               bundle.quad1.slot2 = BREAKNUM;
2668 +               break;
2669 +       }
2670 +
2671 +       return kgdb_set_mem((char *)bundle_addr, (char *)&bundle,
2672 +                           BREAK_INSTR_SIZE);
2673 +}
2674 +
2675 +int kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle)
2676 +{
2677 +       extern unsigned long _start[];
2678 +
2679 +       addr = addr & BREAK_INSTR_ALIGN;
2680 +       if (addr == (unsigned long)_start)
2681 +               return 0;
2682 +       return kgdb_set_mem((char *)addr, (char *)bundle, BREAK_INSTR_SIZE);
2683 +}
2684 +
2685 +static int hw_breakpoint_init;
2686 +
2687 +void do_init_hw_break(void)
2688 +{
2689 +       s64 status;
2690 +       int i;
2691 +
2692 +       hw_breakpoint_init = 1;
2693 +
2694 +#ifdef CONFIG_IA64_HP_SIM
2695 +       hw_break_total_ibr = 8;
2696 +       hw_break_total_dbr = 8;
2697 +       status = 0;
2698 +#else
2699 +       status = ia64_pal_debug_info(&hw_break_total_ibr, &hw_break_total_dbr);
2700 +#endif
2701 +
2702 +       if (status) {
2703 +               printk(KERN_INFO "do_init_hw_break: pal call failed %d\n",
2704 +                      (int)status);
2705 +               return;
2706 +       }
2707 +
2708 +       if (HW_BREAKPOINT > MAX_HW_BREAKPOINT) {
2709 +               printk(KERN_INFO "do_init_hw_break: %d exceeds max %d\n",
2710 +                      (int)HW_BREAKPOINT, (int)MAX_HW_BREAKPOINT);
2711 +
2712 +               while ((HW_BREAKPOINT > MAX_HW_BREAKPOINT)
2713 +                      && hw_break_total_ibr != 1)
2714 +                       hw_break_total_ibr--;
2715 +               while (HW_BREAKPOINT > MAX_HW_BREAKPOINT)
2716 +                       hw_break_total_dbr--;
2717 +       }
2718 +
2719 +       breakinfo = hwbreaks;
2720 +
2721 +       memset(breakinfo, 0, HW_BREAKPOINT * sizeof(struct hw_breakpoint));
2722 +
2723 +       for (i = 0; i < hw_break_total_dbr; i++)
2724 +               breakinfo[i].capable = HWCAP_DBR;
2725 +
2726 +       for (; i < HW_BREAKPOINT; i++)
2727 +               breakinfo[i].capable = HWCAP_IBR;
2728 +
2729 +       return;
2730 +}
2731 +
2732 +void kgdb_correct_hw_break(void)
2733 +{
2734 +       int breakno;
2735 +
2736 +       if (!breakinfo)
2737 +               return;
2738 +
2739 +       for (breakno = 0; breakno < HW_BREAKPOINT; breakno++) {
2740 +               if (breakinfo[breakno].enabled) {
2741 +                       if (breakinfo[breakno].capable & HWCAP_IBR) {
2742 +                               int ibreakno = breakno - hw_break_total_dbr;
2743 +                               ia64_set_ibr(ibreakno << 1,
2744 +                                            breakinfo[breakno].addr);
2745 +                               ia64_set_ibr((ibreakno << 1) + 1,
2746 +                                            (~breakinfo[breakno].mask &
2747 +                                             ((1UL << 56UL) - 1)) |
2748 +                                             (1UL << 56UL) | (1UL << 63UL));
2749 +                       } else {
2750 +                               ia64_set_dbr(breakno << 1,
2751 +                                            breakinfo[breakno].addr);
2752 +                               ia64_set_dbr((breakno << 1) + 1,
2753 +                                            (~breakinfo[breakno].
2754 +                                             mask & ((1UL << 56UL) - 1)) |
2755 +                                            (1UL << 56UL) |
2756 +                                            (breakinfo[breakno].type << 62UL));
2757 +                       }
2758 +               } else {
2759 +                       if (breakinfo[breakno].capable & HWCAP_IBR)
2760 +                               ia64_set_ibr(((breakno -
2761 +                                              hw_break_total_dbr) << 1) + 1,
2762 +                                            0);
2763 +                       else
2764 +                               ia64_set_dbr((breakno << 1) + 1, 0);
2765 +               }
2766 +       }
2767 +
2768 +       return;
2769 +}
2770 +
2771 +int hardware_breakpoint(unsigned long addr, int length, int type, int action)
2772 +{
2773 +       int breakno, found, watch;
2774 +       unsigned long mask;
2775 +       extern unsigned long _start[];
2776 +
2777 +       if (!hw_breakpoint_init)
2778 +               do_init_hw_break();
2779 +
2780 +       if (!breakinfo)
2781 +               return 0;
2782 +       else if (addr == (unsigned long)_start)
2783 +               return 1;
2784 +
2785 +       if (type == WATCH_ACCESS)
2786 +               mask = HWCAP_DBR;
2787 +       else
2788 +               mask = 1UL << type;
2789 +
2790 +       for (watch = 0, found = 0, breakno = 0; breakno < HW_BREAKPOINT;
2791 +            breakno++) {
2792 +               if (action) {
2793 +                       if (breakinfo[breakno].enabled
2794 +                           || !(breakinfo[breakno].capable & mask))
2795 +                               continue;
2796 +                       breakinfo[breakno].enabled = 1;
2797 +                       breakinfo[breakno].type = type;
2798 +                       breakinfo[breakno].mask = length - 1;
2799 +                       breakinfo[breakno].addr = addr;
2800 +                       watch = breakno;
2801 +               } else if (breakinfo[breakno].enabled &&
2802 +                          ((length < 0 && breakinfo[breakno].addr == addr) ||
2803 +                           ((breakinfo[breakno].capable & mask) &&
2804 +                            (breakinfo[breakno].mask == (length - 1)) &&
2805 +                            (breakinfo[breakno].addr == addr)))) {
2806 +                       breakinfo[breakno].enabled = 0;
2807 +                       breakinfo[breakno].type = 0UL;
2808 +               } else
2809 +                       continue;
2810 +               found++;
2811 +               if (type != WATCH_ACCESS)
2812 +                       break;
2813 +               else if (found == 2)
2814 +                       break;
2815 +               else
2816 +                       mask = HWCAP_IBR;
2817 +       }
2818 +
2819 +       if (type == WATCH_ACCESS && found == 1) {
2820 +               breakinfo[watch].enabled = 0;
2821 +               found = 0;
2822 +       }
2823 +
2824 +       mb();
2825 +       return found;
2826 +}
2827 +
2828 +int kgdb_arch_set_hw_breakpoint(unsigned long addr, int len,
2829 +                               enum kgdb_bptype type)
2830 +{
2831 +       return hardware_breakpoint(addr, len, type - '1', 1);
2832 +}
2833 +
2834 +int kgdb_arch_remove_hw_breakpoint(unsigned long addr, int len,
2835 +                                  enum kgdb_bptype type)
2836 +{
2837 +       return hardware_breakpoint(addr, len, type - '1', 0);
2838 +}
2839 +
2840 +int kgdb_remove_hw_break(unsigned long addr)
2841 +{
2842 +       return hardware_breakpoint(addr, 8, WATCH_INSTRUCTION, 0);
2843 +
2844 +}
2845 +
2846 +void kgdb_remove_all_hw_break(void)
2847 +{
2848 +       int i;
2849 +
2850 +       for (i = 0; i < HW_BREAKPOINT; i++)
2851 +               memset(&breakinfo[i], 0, sizeof(struct hw_breakpoint));
2852 +}
2853 +
2854 +int kgdb_set_hw_break(unsigned long addr)
2855 +{
2856 +       return hardware_breakpoint(addr, 8, WATCH_INSTRUCTION, 1);
2857 +}
2858 +
2859 +void kgdb_disable_hw_debug(struct pt_regs *regs)
2860 +{
2861 +       unsigned long hw_breakpoint_status;
2862 +
2863 +       hw_breakpoint_status = ia64_getreg(_IA64_REG_PSR);
2864 +       if (hw_breakpoint_status & IA64_PSR_DB)
2865 +               ia64_setreg(_IA64_REG_PSR_L,
2866 +                           hw_breakpoint_status ^ IA64_PSR_DB);
2867 +}
2868 +
2869 +volatile static struct smp_unw {
2870 +       struct unw_frame_info *unw;
2871 +       struct task_struct *task;
2872 +} smp_unw[NR_CPUS];
2873 +
2874 +static int inline kgdb_get_blocked_state(struct task_struct *p,
2875 +                                        struct unw_frame_info *unw)
2876 +{
2877 +       unsigned long ip;
2878 +       int count = 0;
2879 +
2880 +       unw_init_from_blocked_task(unw, p);
2881 +       ip = 0UL;
2882 +       do {
2883 +               if (unw_unwind(unw) < 0)
2884 +                       return -1;
2885 +               unw_get_ip(unw, &ip);
2886 +               if (!in_sched_functions(ip))
2887 +                       break;
2888 +       } while (count++ < 16);
2889 +
2890 +       if (!ip)
2891 +               return -1;
2892 +       else
2893 +               return 0;
2894 +}
2895 +
2896 +static void inline kgdb_wait(struct pt_regs *regs)
2897 +{
2898 +       unsigned long hw_breakpoint_status = ia64_getreg(_IA64_REG_PSR);
2899 +       if (hw_breakpoint_status & IA64_PSR_DB)
2900 +               ia64_setreg(_IA64_REG_PSR_L,
2901 +                           hw_breakpoint_status ^ IA64_PSR_DB);
2902 +       kgdb_nmihook(smp_processor_id(), regs);
2903 +       if (hw_breakpoint_status & IA64_PSR_DB)
2904 +               ia64_setreg(_IA64_REG_PSR_L, hw_breakpoint_status);
2905 +
2906 +       return;
2907 +}
2908 +
2909 +static void inline normalize(struct unw_frame_info *running,
2910 +                            struct pt_regs *regs)
2911 +{
2912 +       unsigned long sp;
2913 +
2914 +       do {
2915 +               unw_get_sp(running, &sp);
2916 +               if ((sp + 0x10) >= (unsigned long)regs)
2917 +                       break;
2918 +       } while (unw_unwind(running) >= 0);
2919 +
2920 +       return;
2921 +}
2922 +
2923 +static void kgdb_init_running(struct unw_frame_info *unw, void *data)
2924 +{
2925 +       struct pt_regs *regs;
2926 +
2927 +       regs = data;
2928 +       normalize(unw, regs);
2929 +       smp_unw[smp_processor_id()].unw = unw;
2930 +       kgdb_wait(regs);
2931 +}
2932 +
2933 +void kgdb_wait_ipi(struct pt_regs *regs)
2934 +{
2935 +       struct unw_frame_info unw;
2936 +
2937 +       smp_unw[smp_processor_id()].task = current;
2938 +
2939 +       if (user_mode(regs)) {
2940 +               smp_unw[smp_processor_id()].unw = (struct unw_frame_info *)1;
2941 +               kgdb_wait(regs);
2942 +       } else {
2943 +               if (current->state == TASK_RUNNING)
2944 +                       unw_init_running(kgdb_init_running, regs);
2945 +               else {
2946 +                       if (kgdb_get_blocked_state(current, &unw))
2947 +                               smp_unw[smp_processor_id()].unw =
2948 +                                   (struct unw_frame_info *)1;
2949 +                       else
2950 +                               smp_unw[smp_processor_id()].unw = &unw;
2951 +                       kgdb_wait(regs);
2952 +               }
2953 +       }
2954 +
2955 +       smp_unw[smp_processor_id()].unw = NULL;
2956 +       return;
2957 +}
2958 +
2959 +void kgdb_roundup_cpus(unsigned long flags)
2960 +{
2961 +       if (num_online_cpus() > 1)
2962 +               smp_send_nmi_allbutself();
2963 +}
2964 +
2965 +static volatile int kgdb_hwbreak_sstep[NR_CPUS];
2966 +
2967 +static int kgdb_notify(struct notifier_block *self, unsigned long cmd,
2968 +       void *ptr)
2969 +{
2970 +       struct die_args *args = ptr;
2971 +       struct pt_regs *regs = args->regs;
2972 +       unsigned long err = args->err;
2973 +
2974 +       switch (cmd) {
2975 +       default:
2976 +               return NOTIFY_DONE;
2977 +       case DIE_PAGE_FAULT_NO_CONTEXT:
2978 +               if (atomic_read(&debugger_active) && kgdb_may_fault) {
2979 +                       kgdb_fault_longjmp(kgdb_fault_jmp_regs);
2980 +                       return NOTIFY_STOP;
2981 +               }
2982 +               break;
2983 +       case DIE_BREAK:
2984 +               if (user_mode(regs) || err == 0x80001)
2985 +                       return NOTIFY_DONE;
2986 +               break;
2987 +       case DIE_FAULT:
2988 +               if (user_mode(regs))
2989 +                       return NOTIFY_DONE;
2990 +               else if (err == 36 && kgdb_hwbreak_sstep[smp_processor_id()]) {
2991 +                       kgdb_hwbreak_sstep[smp_processor_id()] = 0;
2992 +                       regs->cr_ipsr &= ~IA64_PSR_SS;
2993 +                       return NOTIFY_STOP;
2994 +               }
2995 +       case DIE_MCA_MONARCH_PROCESS:
2996 +       case DIE_INIT_MONARCH_PROCESS:
2997 +               break;
2998 +       }
2999 +
3000 +       kgdb_handle_exception(args->trapnr, args->signr, args->err, regs);
3001 +       return NOTIFY_STOP;
3002 +}
3003 +
3004 +static struct notifier_block kgdb_notifier = {
3005 +       .notifier_call = kgdb_notify,
3006 +};
3007 +
3008 +int kgdb_arch_init(void)
3009 +{
3010 +       atomic_notifier_chain_register(&ia64die_chain, &kgdb_notifier);
3011 +       return 0;
3012 +}
3013 +
3014 +static void do_kgdb_handle_exception(struct unw_frame_info *, void *data);
3015 +
3016 +struct kgdb_state {
3017 +       int e_vector;
3018 +       int signo;
3019 +       unsigned long err_code;
3020 +       struct pt_regs *regs;
3021 +       struct unw_frame_info *unw;
3022 +       char *inbuf;
3023 +       char *outbuf;
3024 +       int unwind;
3025 +       int ret;
3026 +};
3027 +
3028 +static void inline kgdb_pc(struct pt_regs *regs, unsigned long pc)
3029 +{
3030 +       regs->cr_iip = pc & ~0xf;
3031 +       ia64_psr(regs)->ri = pc & 0x3;
3032 +       return;
3033 +}
3034 +
3035 +int kgdb_arch_handle_exception(int e_vector, int signo,
3036 +                              int err_code, char *remcom_in_buffer,
3037 +                              char *remcom_out_buffer,
3038 +                              struct pt_regs *linux_regs)
3039 +{
3040 +       struct kgdb_state info;
3041 +
3042 +       info.e_vector = e_vector;
3043 +       info.signo = signo;
3044 +       info.err_code = err_code;
3045 +       info.unw = (void *)0;
3046 +       info.inbuf = remcom_in_buffer;
3047 +       info.outbuf = remcom_out_buffer;
3048 +       info.unwind = 0;
3049 +       info.ret = -1;
3050 +
3051 +       if (remcom_in_buffer[0] == 'c' || remcom_in_buffer[0] == 's') {
3052 +               info.regs = linux_regs;
3053 +               do_kgdb_handle_exception(NULL, &info);
3054 +       } else if (kgdb_usethread == current) {
3055 +               info.regs = linux_regs;
3056 +               info.unwind = 1;
3057 +               unw_init_running(do_kgdb_handle_exception, &info);
3058 +       } else if (kgdb_usethread->state != TASK_RUNNING) {
3059 +               struct unw_frame_info unw_info;
3060 +
3061 +               if (kgdb_get_blocked_state(kgdb_usethread, &unw_info)) {
3062 +                       info.ret = 1;
3063 +                       goto bad;
3064 +               }
3065 +               info.regs = NULL;
3066 +               do_kgdb_handle_exception(&unw_info, &info);
3067 +       } else {
3068 +               int i;
3069 +
3070 +               for (i = 0; i < NR_CPUS; i++)
3071 +                       if (smp_unw[i].task == kgdb_usethread && smp_unw[i].unw
3072 +                           && smp_unw[i].unw != (struct unw_frame_info *)1) {
3073 +                               info.regs = NULL;
3074 +                               do_kgdb_handle_exception(smp_unw[i].unw, &info);
3075 +                               break;
3076 +                       } else {
3077 +                               info.ret = 1;
3078 +                               goto bad;
3079 +                       }
3080 +       }
3081 +
3082 +      bad:
3083 +       if (info.ret != -1 && remcom_in_buffer[0] == 'p') {
3084 +               unsigned long bad = 0xbad4badbadbadbadUL;
3085 +
3086 +               printk("kgdb_arch_handle_exception: p packet bad (%s)\n",
3087 +                      remcom_in_buffer);
3088 +               kgdb_mem2hex((char *)&bad, remcom_out_buffer, sizeof(bad));
3089 +               remcom_out_buffer[sizeof(bad) * 2] = 0;
3090 +               info.ret = -1;
3091 +       }
3092 +       return info.ret;
3093 +}
3094 +
3095 +/*
3096 + * This is done because I evidently made an incorrect 'p' encoding
3097 + * when my patch for gdb was committed. It was later corrected. This
3098 + * check supports both my wrong encoding of the register number and
3099 + * the correct encoding. Eventually this should be eliminated and
3100 + * kgdb_hex2long should be demarshalling the regnum.
3101 + */
3102 +static inline int check_packet(unsigned int regnum, char *packet)
3103 +{
3104 +       static int check_done, swap;
3105 +       unsigned long reglong;
3106 +
3107 +       if (likely(check_done)) {
3108 +               if (swap) {
3109 +                       kgdb_hex2long(&packet, &reglong);
3110 +                       regnum = (int) reglong;
3111 +               }
3112 +
3113 +       } else {
3114 +               if (regnum > NUM_REGS) {
3115 +                       kgdb_hex2long(&packet, &reglong);
3116 +                       regnum = (int) reglong;
3117 +                       swap = 1;
3118 +               }
3119 +               check_done = 1;
3120 +       }
3121 +       return regnum;
3122 +}
3123 +
3124 +static void do_kgdb_handle_exception(struct unw_frame_info *unw_info,
3125 +       void *data)
3126 +{
3127 +       long addr;
3128 +       char *ptr;
3129 +       unsigned long newPC;
3130 +       int e_vector, signo;
3131 +       unsigned long err_code;
3132 +       struct pt_regs *linux_regs;
3133 +       struct kgdb_state *info;
3134 +       char *remcom_in_buffer, *remcom_out_buffer;
3135 +
3136 +       info = data;
3137 +       info->unw = unw_info;
3138 +       e_vector = info->e_vector;
3139 +       signo = info->signo;
3140 +       err_code = info->err_code;
3141 +       remcom_in_buffer = info->inbuf;
3142 +       remcom_out_buffer = info->outbuf;
3143 +       linux_regs = info->regs;
3144 +
3145 +       if (info->unwind)
3146 +               normalize(unw_info, linux_regs);
3147 +
3148 +       switch (remcom_in_buffer[0]) {
3149 +       case 'p':
3150 +               {
3151 +                       unsigned int regnum;
3152 +
3153 +                       kgdb_hex2mem(&remcom_in_buffer[1], (char *)&regnum,
3154 +                                    sizeof(regnum));
3155 +                       regnum = check_packet(regnum, &remcom_in_buffer[1]);
3156 +                       if (regnum >= NUM_REGS) {
3157 +                               remcom_out_buffer[0] = 'E';
3158 +                               remcom_out_buffer[1] = 0;
3159 +                       } else
3160 +                               kgdb_get_reg(remcom_out_buffer, regnum,
3161 +                                            unw_info, linux_regs);
3162 +                       break;
3163 +               }
3164 +       case 'P':
3165 +               {
3166 +                       unsigned int regno;
3167 +                       long v;
3168 +                       char *ptr;
3169 +
3170 +                       ptr = &remcom_in_buffer[1];
3171 +                       if ((!kgdb_usethread || kgdb_usethread == current) &&
3172 +                           kgdb_hex2long(&ptr, &v) &&
3173 +                           *ptr++ == '=' && (v >= 0)) {
3174 +                               regno = (unsigned int)v;
3175 +                               regno = (regno >= NUM_REGS ? 0 : regno);
3176 +                               kgdb_put_reg(ptr, remcom_out_buffer, regno,
3177 +                                            unw_info, linux_regs);
3178 +                       } else
3179 +                               strcpy(remcom_out_buffer, "E01");
3180 +                       break;
3181 +               }
3182 +       case 'c':
3183 +       case 's':
3184 +               if (e_vector == TRAP_BRKPT && err_code == KGDBBREAKNUM) {
3185 +                       if (ia64_psr(linux_regs)->ri < 2)
3186 +                               kgdb_pc(linux_regs, linux_regs->cr_iip +
3187 +                                       ia64_psr(linux_regs)->ri + 1);
3188 +                       else
3189 +                               kgdb_pc(linux_regs, linux_regs->cr_iip + 16);
3190 +               }
3191 +
3192 +               /* try to read optional parameter, pc unchanged if no parm */
3193 +               ptr = &remcom_in_buffer[1];
3194 +               if (kgdb_hex2long(&ptr, &addr)) {
3195 +                       linux_regs->cr_iip = addr;
3196 +               }
3197 +               newPC = linux_regs->cr_iip;
3198 +
3199 +               /* clear the trace bit */
3200 +               linux_regs->cr_ipsr &= ~IA64_PSR_SS;
3201 +
3202 +               atomic_set(&cpu_doing_single_step, -1);
3203 +
3204 +               /* set the trace bit if we're stepping or took a hardware break */
3205 +               if (remcom_in_buffer[0] == 's' || e_vector == TRAP_HWBKPT) {
3206 +                       linux_regs->cr_ipsr |= IA64_PSR_SS;
3207 +                       debugger_step = 1;
3208 +                       if (kgdb_contthread)
3209 +                               atomic_set(&cpu_doing_single_step,
3210 +                                          smp_processor_id());
3211 +               }
3212 +
3213 +               kgdb_correct_hw_break();
3214 +
3215 +               /* if not hardware breakpoint, then reenable them */
3216 +               if (e_vector != TRAP_HWBKPT)
3217 +                       linux_regs->cr_ipsr |= IA64_PSR_DB;
3218 +               else {
3219 +                       kgdb_hwbreak_sstep[smp_processor_id()] = 1;
3220 +                       linux_regs->cr_ipsr &= ~IA64_PSR_DB;
3221 +               }
3222 +
3223 +               info->ret = 0;
3224 +               break;
3225 +       default:
3226 +               break;
3227 +       }
3228 +
3229 +       return;
3230 +}
3231 +
3232 +struct kgdb_arch arch_kgdb_ops = {
3233 +       .set_hw_breakpoint = kgdb_arch_set_hw_breakpoint,
3234 +       .remove_hw_breakpoint = kgdb_arch_remove_hw_breakpoint,
3235 +       .gdb_bpt_instr = {0xcc},
3236 +       .flags = KGDB_HW_BREAKPOINT,
3237 +};
3238 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/kernel/process.c linux-2.6.18.kgdb/arch/ia64/kernel/process.c
3239 --- linux-2.6.18/arch/ia64/kernel/process.c     2006-09-20 07:42:06.000000000 +0400
3240 +++ linux-2.6.18.kgdb/arch/ia64/kernel/process.c        2008-06-10 16:20:23.000000000 +0400
3241 @@ -458,6 +458,9 @@ copy_thread (int nr, unsigned long clone
3242          */
3243         child_ptregs->cr_ipsr = ((child_ptregs->cr_ipsr | IA64_PSR_BITS_TO_SET)
3244                                  & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_PP | IA64_PSR_UP));
3245 +#ifdef CONFIG_KGDB
3246 +       child_ptregs->cr_ipsr |= IA64_PSR_DB;
3247 +#endif
3248  
3249         /*
3250          * NOTE: The calling convention considers all floating point
3251 @@ -686,6 +689,9 @@ kernel_thread (int (*fn)(void *), void *
3252         regs.pt.r11 = (unsigned long) arg;      /* 2nd argument */
3253         /* Preserve PSR bits, except for bits 32-34 and 37-45, which we can't read.  */
3254         regs.pt.cr_ipsr = ia64_getreg(_IA64_REG_PSR) | IA64_PSR_BN;
3255 +#ifdef CONFIG_KGDB
3256 +       regs.pt.cr_ipsr |= IA64_PSR_DB;
3257 +#endif
3258         regs.pt.cr_ifs = 1UL << 63;             /* mark as valid, empty frame */
3259         regs.sw.ar_fpsr = regs.pt.ar_fpsr = ia64_getreg(_IA64_REG_AR_FPSR);
3260         regs.sw.ar_bspstore = (unsigned long) current + IA64_RBS_OFFSET;
3261 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/kernel/smp.c linux-2.6.18.kgdb/arch/ia64/kernel/smp.c
3262 --- linux-2.6.18/arch/ia64/kernel/smp.c 2006-09-20 07:42:06.000000000 +0400
3263 +++ linux-2.6.18.kgdb/arch/ia64/kernel/smp.c    2008-06-10 16:19:32.000000000 +0400
3264 @@ -47,6 +47,7 @@
3265  #include <asm/tlbflush.h>
3266  #include <asm/unistd.h>
3267  #include <asm/mca.h>
3268 +#include <linux/kgdb.h>
3269  
3270  /*
3271   * Structure and data for smp_call_function(). This is designed to minimise static memory
3272 @@ -66,6 +67,9 @@ static volatile struct call_data_struct 
3273  
3274  #define IPI_CALL_FUNC          0
3275  #define IPI_CPU_STOP           1
3276 +#ifdef CONFIG_KGDB
3277 +#define        IPI_KGDB_INTERRUPT      2
3278 +#endif
3279  
3280  /* This needs to be cacheline aligned because it is written to by *other* CPUs.  */
3281  static DEFINE_PER_CPU(u64, ipi_operation) ____cacheline_aligned;
3282 @@ -155,6 +159,11 @@ handle_IPI (int irq, void *dev_id, struc
3283                               case IPI_CPU_STOP:
3284                                 stop_this_cpu();
3285                                 break;
3286 +#ifdef CONFIG_KGDB
3287 +                             case IPI_KGDB_INTERRUPT:
3288 +                               kgdb_wait_ipi(regs);
3289 +                               break;
3290 +#endif
3291  
3292                               default:
3293                                 printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n", this_cpu, which);
3294 @@ -305,6 +314,14 @@ smp_call_function_single (int cpuid, voi
3295  }
3296  EXPORT_SYMBOL(smp_call_function_single);
3297  
3298 +#ifdef CONFIG_KGDB
3299 +void
3300 +smp_send_nmi_allbutself(void)
3301 +{
3302 +       send_IPI_allbutself(IPI_KGDB_INTERRUPT);
3303 +}
3304 +#endif
3305 +
3306  /*
3307   * this function sends a 'generic call function' IPI to all other CPUs
3308   * in the system.
3309 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/kernel/traps.c linux-2.6.18.kgdb/arch/ia64/kernel/traps.c
3310 --- linux-2.6.18/arch/ia64/kernel/traps.c       2006-09-20 07:42:06.000000000 +0400
3311 +++ linux-2.6.18.kgdb/arch/ia64/kernel/traps.c  2008-06-10 16:19:32.000000000 +0400
3312 @@ -200,8 +200,12 @@ __kprobes ia64_bad_break (unsigned long 
3313                 break;
3314  
3315               default:
3316 -               if (break_num < 0x40000 || break_num > 0x100000)
3317 +               if (break_num < 0x40000 || break_num > 0x100000) {
3318 +                       if (notify_die(DIE_BREAK, "bad break", regs,
3319 +                               break_num, TRAP_BRKPT, SIGTRAP) == NOTIFY_STOP)
3320 +                               return;
3321                         die_if_kernel("Bad break", regs, break_num);
3322 +               }
3323  
3324                 if (break_num < 0x80000) {
3325                         sig = SIGILL; code = __ILL_BREAK;
3326 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/kernel/unwind.c linux-2.6.18.kgdb/arch/ia64/kernel/unwind.c
3327 --- linux-2.6.18/arch/ia64/kernel/unwind.c      2006-09-20 07:42:06.000000000 +0400
3328 +++ linux-2.6.18.kgdb/arch/ia64/kernel/unwind.c 2008-06-10 16:20:23.000000000 +0400
3329 @@ -72,10 +72,68 @@
3330  # define STAT(x...)
3331  #endif
3332  
3333 +#ifdef CONFIG_KGDB
3334 +#define        KGDB_EARLY_SIZE 100
3335 +static struct unw_reg_state __initdata kgdb_reg_state[KGDB_EARLY_SIZE];
3336 +static struct unw_labeled_state __initdata kgdb_labeled_state[KGDB_EARLY_SIZE];
3337 +void __initdata *kgdb_reg_state_free, __initdata *kgdb_labeled_state_free;
3338 +
3339 +static void __init
3340 +kgdb_malloc_init(void)
3341 +{
3342 +       int i;
3343 +
3344 +       kgdb_reg_state_free = kgdb_reg_state;
3345 +       for (i = 1; i < KGDB_EARLY_SIZE; i++) {
3346 +               *((unsigned long *) &kgdb_reg_state[i]) = (unsigned long) kgdb_reg_state_free;
3347 +               kgdb_reg_state_free = &kgdb_reg_state[i];
3348 +       }
3349 +
3350 +       kgdb_labeled_state_free = kgdb_labeled_state;
3351 +       for (i = 1; i < KGDB_EARLY_SIZE; i++) {
3352 +               *((unsigned long *) &kgdb_labeled_state[i]) =
3353 +                       (unsigned long) kgdb_labeled_state_free;
3354 +               kgdb_labeled_state_free = &kgdb_labeled_state[i];
3355 +       }
3356 +
3357 +}
3358 +
3359 +static void * __init
3360 +kgdb_malloc(void **mem)
3361 +{
3362 +       void *p;
3363 +
3364 +       p = *mem;
3365 +       *mem = *((void **) p);
3366 +       return p;
3367 +}
3368 +
3369 +static void __init
3370 +kgdb_free(void **mem, void *p)
3371 +{
3372 +       *((void **)p) = *mem;
3373 +       *mem = p;
3374 +}
3375 +
3376 +#define alloc_reg_state()      (!malloc_sizes[0].cs_cachep ?           \
3377 +               kgdb_malloc(&kgdb_reg_state_free) :                     \
3378 +               kmalloc(sizeof(struct unw_reg_state), GFP_ATOMIC))
3379 +#define free_reg_state(usr)    (!malloc_sizes[0].cs_cachep ?           \
3380 +               kgdb_free(&kgdb_reg_state_free, usr) :                  \
3381 +               kfree(usr))
3382 +#define alloc_labeled_state()  (!malloc_sizes[0].cs_cachep ?           \
3383 +               kgdb_malloc(&kgdb_labeled_state_free) :                 \
3384 +               kmalloc(sizeof(struct unw_labeled_state), GFP_ATOMIC))
3385 +#define free_labeled_state(usr)        (!malloc_sizes[0].cs_cachep ?           \
3386 +               kgdb_free(&kgdb_labeled_state_free, usr) :              \
3387 +               kfree(usr))
3388 +
3389 +#else
3390  #define alloc_reg_state()      kmalloc(sizeof(struct unw_reg_state), GFP_ATOMIC)
3391  #define free_reg_state(usr)    kfree(usr)
3392  #define alloc_labeled_state()  kmalloc(sizeof(struct unw_labeled_state), GFP_ATOMIC)
3393  #define free_labeled_state(usr)        kfree(usr)
3394 +#endif
3395  
3396  typedef unsigned long unw_word;
3397  typedef unsigned char unw_hash_index_t;
3398 @@ -238,6 +296,24 @@ static struct {
3399  #endif
3400  };
3401  
3402 +#ifdef CONFIG_KGDB
3403 +/*
3404 + * This makes it safe to call breakpoint() very early
3405 + * in setup_arch providing:
3406 + *     1) breakpoint isn't called between lines in cpu_init
3407 + *        where init_mm.mm_count is incremented and ia64_mmu_init
3408 + *        is called.  Otherwise the test below is invalid.
3409 + *     2) the memory examined doesn't result in tlbmiss.
3410 + */
3411 +static unsigned long inline kgdb_unimpl_va_mask(void)
3412 +{
3413 +       if (atomic_read(&init_mm.mm_count) > 1)
3414 +               return local_cpu_data->unimpl_va_mask;
3415 +       else
3416 +               return 0UL;
3417 +}
3418 +#endif
3419 +
3420  static inline int
3421  read_only (void *addr)
3422  {
3423 @@ -1786,7 +1862,11 @@ run_script (struct unw_script *script, s
3424  
3425                       case UNW_INSN_LOAD:
3426  #ifdef UNW_DEBUG
3427 +#ifdef CONFIG_KGDB
3428 +                       if ((s[val] & (kgdb_unimpl_va_mask() | 0x7)) != 0
3429 +#else
3430                         if ((s[val] & (local_cpu_data->unimpl_va_mask | 0x7)) != 0
3431 +#endif
3432                             || s[val] < TASK_SIZE)
3433                         {
3434                                 UNW_DPRINT(0, "unwind.%s: rejecting bad psp=0x%lx\n",
3435 @@ -1821,7 +1901,11 @@ find_save_locs (struct unw_frame_info *i
3436         struct unw_script *scr;
3437         unsigned long flags = 0;
3438  
3439 +#ifdef CONFIG_KGDB
3440 +       if ((info->ip & (kgdb_unimpl_va_mask() | 0xf)) || info->ip < TASK_SIZE) {
3441 +#else
3442         if ((info->ip & (local_cpu_data->unimpl_va_mask | 0xf)) || info->ip < TASK_SIZE) {
3443 +#endif
3444                 /* don't let obviously bad addresses pollute the cache */
3445                 /* FIXME: should really be level 0 but it occurs too often. KAO */
3446                 UNW_DPRINT(1, "unwind.%s: rejecting bad ip=0x%lx\n", __FUNCTION__, info->ip);
3447 @@ -2249,6 +2333,9 @@ unw_init (void)
3448  
3449         init_unwind_table(&unw.kernel_table, "kernel", KERNEL_START, (unsigned long) __gp,
3450                           __start_unwind, __end_unwind);
3451 +#ifdef CONFIG_KGDB
3452 +       kgdb_malloc_init();
3453 +#endif
3454  }
3455  
3456  /*
3457 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/mm/extable.c linux-2.6.18.kgdb/arch/ia64/mm/extable.c
3458 --- linux-2.6.18/arch/ia64/mm/extable.c 2006-09-20 07:42:06.000000000 +0400
3459 +++ linux-2.6.18.kgdb/arch/ia64/mm/extable.c    2008-06-10 16:19:32.000000000 +0400
3460 @@ -6,6 +6,7 @@
3461   */
3462  
3463  #include <linux/sort.h>
3464 +#include <linux/kgdb.h>
3465  
3466  #include <asm/uaccess.h>
3467  #include <asm/module.h>
3468 @@ -73,6 +74,11 @@ search_extable (const struct exception_t
3469                  else
3470                          last = mid - 1;
3471          }
3472 +#ifdef CONFIG_KGDB
3473 +       if (atomic_read(&debugger_active) && kgdb_may_fault)
3474 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
3475 +               /* Not reached. */
3476 +#endif
3477          return NULL;
3478  }
3479  
3480 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ia64/mm/fault.c linux-2.6.18.kgdb/arch/ia64/mm/fault.c
3481 --- linux-2.6.18/arch/ia64/mm/fault.c   2006-09-20 07:42:06.000000000 +0400
3482 +++ linux-2.6.18.kgdb/arch/ia64/mm/fault.c      2008-06-10 16:19:32.000000000 +0400
3483 @@ -266,6 +266,10 @@ ia64_do_page_fault (unsigned long addres
3484          */
3485         bust_spinlocks(1);
3486  
3487 +       if (notify_die(DIE_PAGE_FAULT_NO_CONTEXT, "no context", regs,
3488 +                       isr, 14, SIGSEGV) == NOTIFY_STOP)
3489 +               return;
3490 +
3491         if (address < PAGE_SIZE)
3492                 printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference (address %016lx)\n", address);
3493         else
3494 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/Kconfig.debug linux-2.6.18.kgdb/arch/mips/Kconfig.debug
3495 --- linux-2.6.18/arch/mips/Kconfig.debug        2006-09-20 07:42:06.000000000 +0400
3496 +++ linux-2.6.18.kgdb/arch/mips/Kconfig.debug   2008-06-10 16:19:28.000000000 +0400
3497 @@ -37,25 +37,6 @@ config DEBUG_STACK_USAGE
3498  
3499           This option will slow down process creation somewhat.
3500  
3501 -config KGDB
3502 -       bool "Remote GDB kernel debugging"
3503 -       depends on DEBUG_KERNEL
3504 -       select DEBUG_INFO
3505 -       help
3506 -         If you say Y here, it will be possible to remotely debug the MIPS
3507 -         kernel using gdb. This enlarges your kernel image disk size by
3508 -         several megabytes and requires a machine with more than 16 MB,
3509 -         better 32 MB RAM to avoid excessive linking time. This is only
3510 -         useful for kernel hackers. If unsure, say N.
3511 -
3512 -config GDB_CONSOLE
3513 -       bool "Console output to GDB"
3514 -       depends on KGDB
3515 -       help
3516 -         If you are using GDB for remote debugging over a serial port and
3517 -         would like kernel messages to be formatted into GDB $O packets so
3518 -         that GDB prints them as program output, say 'Y'.
3519 -
3520  config SB1XXX_CORELIS
3521         bool "Corelis Debugger"
3522         depends on SIBYTE_SB1xxx_SOC
3523 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/kernel/Makefile linux-2.6.18.kgdb/arch/mips/kernel/Makefile
3524 --- linux-2.6.18/arch/mips/kernel/Makefile      2006-09-20 07:42:06.000000000 +0400
3525 +++ linux-2.6.18.kgdb/arch/mips/kernel/Makefile 2008-06-10 16:19:28.000000000 +0400
3526 @@ -59,7 +59,8 @@ obj-$(CONFIG_MIPS32_COMPAT)   += linux32.o
3527  obj-$(CONFIG_MIPS32_N32)       += binfmt_elfn32.o scall64-n32.o signal_n32.o
3528  obj-$(CONFIG_MIPS32_O32)       += binfmt_elfo32.o scall64-o32.o ptrace32.o
3529  
3530 -obj-$(CONFIG_KGDB)             += gdb-low.o gdb-stub.o
3531 +obj-$(CONFIG_KGDB)             += kgdb_handler.o kgdb.o kgdb-jmp.o     \
3532 +                                       kgdb-setjmp.o
3533  obj-$(CONFIG_PROC_FS)          += proc.o
3534  
3535  obj-$(CONFIG_64BIT)            += cpu-bugs64.o
3536 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/kernel/gdb-low.S linux-2.6.18.kgdb/arch/mips/kernel/gdb-low.S
3537 --- linux-2.6.18/arch/mips/kernel/gdb-low.S     2006-09-20 07:42:06.000000000 +0400
3538 +++ linux-2.6.18.kgdb/arch/mips/kernel/gdb-low.S        1970-01-01 03:00:00.000000000 +0300
3539 @@ -1,394 +0,0 @@
3540 -/*
3541 - * gdb-low.S contains the low-level trap handler for the GDB stub.
3542 - *
3543 - * Copyright (C) 1995 Andreas Busse
3544 - */
3545 -#include <linux/sys.h>
3546 -
3547 -#include <asm/asm.h>
3548 -#include <asm/errno.h>
3549 -#include <asm/irqflags.h>
3550 -#include <asm/mipsregs.h>
3551 -#include <asm/regdef.h>
3552 -#include <asm/stackframe.h>
3553 -#include <asm/gdb-stub.h>
3554 -
3555 -#ifdef CONFIG_32BIT
3556 -#define DMFC0  mfc0
3557 -#define DMTC0  mtc0
3558 -#define LDC1   lwc1
3559 -#define SDC1   lwc1
3560 -#endif
3561 -#ifdef CONFIG_64BIT
3562 -#define DMFC0  dmfc0
3563 -#define DMTC0  dmtc0
3564 -#define LDC1   ldc1
3565 -#define SDC1   ldc1
3566 -#endif
3567 -
3568 -/*
3569 - * [jsun] We reserves about 2x GDB_FR_SIZE in stack.  The lower (addressed)
3570 - * part is used to store registers and passed to exception handler.
3571 - * The upper part is reserved for "call func" feature where gdb client
3572 - * saves some of the regs, setups call frame and passes args.
3573 - *
3574 - * A trace shows about 200 bytes are used to store about half of all regs.
3575 - * The rest should be big enough for frame setup and passing args.
3576 - */
3577 -
3578 -/*
3579 - * The low level trap handler
3580 - */
3581 -               .align  5
3582 -               NESTED(trap_low, GDB_FR_SIZE, sp)
3583 -               .set    noat
3584 -               .set    noreorder
3585 -
3586 -               mfc0    k0, CP0_STATUS
3587 -               sll     k0, 3                   /* extract cu0 bit */
3588 -               bltz    k0, 1f
3589 -               move    k1, sp
3590 -
3591 -               /*
3592 -                * Called from user mode, go somewhere else.
3593 -                */
3594 -               mfc0    k0, CP0_CAUSE
3595 -               andi    k0, k0, 0x7c
3596 -#ifdef CONFIG_64BIT
3597 -               dsll    k0, k0, 1
3598 -#endif
3599 -               PTR_L   k1, saved_vectors(k0)
3600 -               jr      k1
3601 -               nop
3602 -1:
3603 -               move    k0, sp
3604 -               PTR_SUBU sp, k1, GDB_FR_SIZE*2  # see comment above
3605 -               LONG_S  k0, GDB_FR_REG29(sp)
3606 -               LONG_S  $2, GDB_FR_REG2(sp)
3607 -
3608 -/*
3609 - * First save the CP0 and special registers
3610 - */
3611 -
3612 -               mfc0    v0, CP0_STATUS
3613 -               LONG_S  v0, GDB_FR_STATUS(sp)
3614 -               mfc0    v0, CP0_CAUSE
3615 -               LONG_S  v0, GDB_FR_CAUSE(sp)
3616 -               DMFC0   v0, CP0_EPC
3617 -               LONG_S  v0, GDB_FR_EPC(sp)
3618 -               DMFC0   v0, CP0_BADVADDR
3619 -               LONG_S  v0, GDB_FR_BADVADDR(sp)
3620 -               mfhi    v0
3621 -               LONG_S  v0, GDB_FR_HI(sp)
3622 -               mflo    v0
3623 -               LONG_S  v0, GDB_FR_LO(sp)
3624 -
3625 -/*
3626 - * Now the integer registers
3627 - */
3628 -
3629 -               LONG_S  zero, GDB_FR_REG0(sp)           /* I know... */
3630 -               LONG_S  $1, GDB_FR_REG1(sp)
3631 -               /* v0 already saved */
3632 -               LONG_S  $3, GDB_FR_REG3(sp)
3633 -               LONG_S  $4, GDB_FR_REG4(sp)
3634 -               LONG_S  $5, GDB_FR_REG5(sp)
3635 -               LONG_S  $6, GDB_FR_REG6(sp)
3636 -               LONG_S  $7, GDB_FR_REG7(sp)
3637 -               LONG_S  $8, GDB_FR_REG8(sp)
3638 -               LONG_S  $9, GDB_FR_REG9(sp)
3639 -               LONG_S  $10, GDB_FR_REG10(sp)
3640 -               LONG_S  $11, GDB_FR_REG11(sp)
3641 -               LONG_S  $12, GDB_FR_REG12(sp)
3642 -               LONG_S  $13, GDB_FR_REG13(sp)
3643 -               LONG_S  $14, GDB_FR_REG14(sp)
3644 -               LONG_S  $15, GDB_FR_REG15(sp)
3645 -               LONG_S  $16, GDB_FR_REG16(sp)
3646 -               LONG_S  $17, GDB_FR_REG17(sp)
3647 -               LONG_S  $18, GDB_FR_REG18(sp)
3648 -               LONG_S  $19, GDB_FR_REG19(sp)
3649 -               LONG_S  $20, GDB_FR_REG20(sp)
3650 -               LONG_S  $21, GDB_FR_REG21(sp)
3651 -               LONG_S  $22, GDB_FR_REG22(sp)
3652 -               LONG_S  $23, GDB_FR_REG23(sp)
3653 -               LONG_S  $24, GDB_FR_REG24(sp)
3654 -               LONG_S  $25, GDB_FR_REG25(sp)
3655 -               LONG_S  $26, GDB_FR_REG26(sp)
3656 -               LONG_S  $27, GDB_FR_REG27(sp)
3657 -               LONG_S  $28, GDB_FR_REG28(sp)
3658 -               /* sp already saved */
3659 -               LONG_S  $30, GDB_FR_REG30(sp)
3660 -               LONG_S  $31, GDB_FR_REG31(sp)
3661 -
3662 -               CLI                             /* disable interrupts */
3663 -               TRACE_IRQS_OFF
3664 -
3665 -/*
3666 - * Followed by the floating point registers
3667 - */
3668 -               mfc0    v0, CP0_STATUS          /* FPU enabled? */
3669 -               srl     v0, v0, 16
3670 -               andi    v0, v0, (ST0_CU1 >> 16)
3671 -
3672 -               beqz    v0,2f                   /* disabled, skip */
3673 -                nop
3674 -
3675 -               SDC1    $0, GDB_FR_FPR0(sp)
3676 -               SDC1    $1, GDB_FR_FPR1(sp)
3677 -               SDC1    $2, GDB_FR_FPR2(sp)
3678 -               SDC1    $3, GDB_FR_FPR3(sp)
3679 -               SDC1    $4, GDB_FR_FPR4(sp)
3680 -               SDC1    $5, GDB_FR_FPR5(sp)
3681 -               SDC1    $6, GDB_FR_FPR6(sp)
3682 -               SDC1    $7, GDB_FR_FPR7(sp)
3683 -               SDC1    $8, GDB_FR_FPR8(sp)
3684 -               SDC1    $9, GDB_FR_FPR9(sp)
3685 -               SDC1    $10, GDB_FR_FPR10(sp)
3686 -               SDC1    $11, GDB_FR_FPR11(sp)
3687 -               SDC1    $12, GDB_FR_FPR12(sp)
3688 -               SDC1    $13, GDB_FR_FPR13(sp)
3689 -               SDC1    $14, GDB_FR_FPR14(sp)
3690 -               SDC1    $15, GDB_FR_FPR15(sp)
3691 -               SDC1    $16, GDB_FR_FPR16(sp)
3692 -               SDC1    $17, GDB_FR_FPR17(sp)
3693 -               SDC1    $18, GDB_FR_FPR18(sp)
3694 -               SDC1    $19, GDB_FR_FPR19(sp)
3695 -               SDC1    $20, GDB_FR_FPR20(sp)
3696 -               SDC1    $21, GDB_FR_FPR21(sp)
3697 -               SDC1    $22, GDB_FR_FPR22(sp)
3698 -               SDC1    $23, GDB_FR_FPR23(sp)
3699 -               SDC1    $24, GDB_FR_FPR24(sp)
3700 -               SDC1    $25, GDB_FR_FPR25(sp)
3701 -               SDC1    $26, GDB_FR_FPR26(sp)
3702 -               SDC1    $27, GDB_FR_FPR27(sp)
3703 -               SDC1    $28, GDB_FR_FPR28(sp)
3704 -               SDC1    $29, GDB_FR_FPR29(sp)
3705 -               SDC1    $30, GDB_FR_FPR30(sp)
3706 -               SDC1    $31, GDB_FR_FPR31(sp)
3707 -
3708 -/*
3709 - * FPU control registers
3710 - */
3711 -
3712 -               cfc1    v0, CP1_STATUS
3713 -               LONG_S  v0, GDB_FR_FSR(sp)
3714 -               cfc1    v0, CP1_REVISION
3715 -               LONG_S  v0, GDB_FR_FIR(sp)
3716 -
3717 -/*
3718 - * Current stack frame ptr
3719 - */
3720 -
3721 -2:
3722 -               LONG_S  sp, GDB_FR_FRP(sp)
3723 -
3724 -/*
3725 - * CP0 registers (R4000/R4400 unused registers skipped)
3726 - */
3727 -
3728 -               mfc0    v0, CP0_INDEX
3729 -               LONG_S  v0, GDB_FR_CP0_INDEX(sp)
3730 -               mfc0    v0, CP0_RANDOM
3731 -               LONG_S  v0, GDB_FR_CP0_RANDOM(sp)
3732 -               DMFC0   v0, CP0_ENTRYLO0
3733 -               LONG_S  v0, GDB_FR_CP0_ENTRYLO0(sp)
3734 -               DMFC0   v0, CP0_ENTRYLO1
3735 -               LONG_S  v0, GDB_FR_CP0_ENTRYLO1(sp)
3736 -               DMFC0   v0, CP0_CONTEXT
3737 -               LONG_S  v0, GDB_FR_CP0_CONTEXT(sp)
3738 -               mfc0    v0, CP0_PAGEMASK
3739 -               LONG_S  v0, GDB_FR_CP0_PAGEMASK(sp)
3740 -               mfc0    v0, CP0_WIRED
3741 -               LONG_S  v0, GDB_FR_CP0_WIRED(sp)
3742 -               DMFC0   v0, CP0_ENTRYHI
3743 -               LONG_S  v0, GDB_FR_CP0_ENTRYHI(sp)
3744 -               mfc0    v0, CP0_PRID
3745 -               LONG_S  v0, GDB_FR_CP0_PRID(sp)
3746 -
3747 -               .set    at
3748 -
3749 -/*
3750 - * Continue with the higher level handler
3751 - */
3752 -
3753 -               move    a0,sp
3754 -
3755 -               jal     handle_exception
3756 -                nop
3757 -
3758 -/*
3759 - * Restore all writable registers, in reverse order
3760 - */
3761 -
3762 -               .set    noat
3763 -
3764 -               LONG_L  v0, GDB_FR_CP0_ENTRYHI(sp)
3765 -               LONG_L  v1, GDB_FR_CP0_WIRED(sp)
3766 -               DMTC0   v0, CP0_ENTRYHI
3767 -               mtc0    v1, CP0_WIRED
3768 -               LONG_L  v0, GDB_FR_CP0_PAGEMASK(sp)
3769 -               LONG_L  v1, GDB_FR_CP0_ENTRYLO1(sp)
3770 -               mtc0    v0, CP0_PAGEMASK
3771 -               DMTC0   v1, CP0_ENTRYLO1
3772 -               LONG_L  v0, GDB_FR_CP0_ENTRYLO0(sp)
3773 -               LONG_L  v1, GDB_FR_CP0_INDEX(sp)
3774 -               DMTC0   v0, CP0_ENTRYLO0
3775 -               LONG_L  v0, GDB_FR_CP0_CONTEXT(sp)
3776 -               mtc0    v1, CP0_INDEX
3777 -               DMTC0   v0, CP0_CONTEXT
3778 -
3779 -
3780 -/*
3781 - * Next, the floating point registers
3782 - */
3783 -               mfc0    v0, CP0_STATUS          /* check if the FPU is enabled */
3784 -               srl     v0, v0, 16
3785 -               andi    v0, v0, (ST0_CU1 >> 16)
3786 -
3787 -               beqz    v0, 3f                  /* disabled, skip */
3788 -                nop
3789 -
3790 -               LDC1    $31, GDB_FR_FPR31(sp)
3791 -               LDC1    $30, GDB_FR_FPR30(sp)
3792 -               LDC1    $29, GDB_FR_FPR29(sp)
3793 -               LDC1    $28, GDB_FR_FPR28(sp)
3794 -               LDC1    $27, GDB_FR_FPR27(sp)
3795 -               LDC1    $26, GDB_FR_FPR26(sp)
3796 -               LDC1    $25, GDB_FR_FPR25(sp)
3797 -               LDC1    $24, GDB_FR_FPR24(sp)
3798 -               LDC1    $23, GDB_FR_FPR23(sp)
3799 -               LDC1    $22, GDB_FR_FPR22(sp)
3800 -               LDC1    $21, GDB_FR_FPR21(sp)
3801 -               LDC1    $20, GDB_FR_FPR20(sp)
3802 -               LDC1    $19, GDB_FR_FPR19(sp)
3803 -               LDC1    $18, GDB_FR_FPR18(sp)
3804 -               LDC1    $17, GDB_FR_FPR17(sp)
3805 -               LDC1    $16, GDB_FR_FPR16(sp)
3806 -               LDC1    $15, GDB_FR_FPR15(sp)
3807 -               LDC1    $14, GDB_FR_FPR14(sp)
3808 -               LDC1    $13, GDB_FR_FPR13(sp)
3809 -               LDC1    $12, GDB_FR_FPR12(sp)
3810 -               LDC1    $11, GDB_FR_FPR11(sp)
3811 -               LDC1    $10, GDB_FR_FPR10(sp)
3812 -               LDC1    $9, GDB_FR_FPR9(sp)
3813 -               LDC1    $8, GDB_FR_FPR8(sp)
3814 -               LDC1    $7, GDB_FR_FPR7(sp)
3815 -               LDC1    $6, GDB_FR_FPR6(sp)
3816 -               LDC1    $5, GDB_FR_FPR5(sp)
3817 -               LDC1    $4, GDB_FR_FPR4(sp)
3818 -               LDC1    $3, GDB_FR_FPR3(sp)
3819 -               LDC1    $2, GDB_FR_FPR2(sp)
3820 -               LDC1    $1, GDB_FR_FPR1(sp)
3821 -               LDC1    $0, GDB_FR_FPR0(sp)
3822 -
3823 -/*
3824 - * Now the CP0 and integer registers
3825 - */
3826 -
3827 -3:
3828 -#ifdef CONFIG_MIPS_MT_SMTC
3829 -               /* Read-modify write of Status must be atomic */
3830 -               mfc0    t2, CP0_TCSTATUS
3831 -               ori     t1, t2, TCSTATUS_IXMT
3832 -               mtc0    t1, CP0_TCSTATUS
3833 -               andi    t2, t2, TCSTATUS_IXMT
3834 -               _ehb
3835 -               DMT     9                               # dmt   t1
3836 -               jal     mips_ihb
3837 -               nop
3838 -#endif /* CONFIG_MIPS_MT_SMTC */
3839 -               mfc0    t0, CP0_STATUS
3840 -               ori     t0, 0x1f
3841 -               xori    t0, 0x1f
3842 -               mtc0    t0, CP0_STATUS
3843 -#ifdef CONFIG_MIPS_MT_SMTC
3844 -               andi    t1, t1, VPECONTROL_TE
3845 -               beqz    t1, 9f
3846 -               nop
3847 -               EMT                                     # emt
3848 -9:
3849 -               mfc0    t1, CP0_TCSTATUS
3850 -               xori    t1, t1, TCSTATUS_IXMT
3851 -               or      t1, t1, t2
3852 -               mtc0    t1, CP0_TCSTATUS
3853 -               _ehb
3854 -#endif /* CONFIG_MIPS_MT_SMTC */
3855 -               LONG_L  v0, GDB_FR_STATUS(sp)
3856 -               LONG_L  v1, GDB_FR_EPC(sp)
3857 -               mtc0    v0, CP0_STATUS
3858 -               DMTC0   v1, CP0_EPC
3859 -               LONG_L  v0, GDB_FR_HI(sp)
3860 -               LONG_L  v1, GDB_FR_LO(sp)
3861 -               mthi    v0
3862 -               mtlo    v1
3863 -               LONG_L  $31, GDB_FR_REG31(sp)
3864 -               LONG_L  $30, GDB_FR_REG30(sp)
3865 -               LONG_L  $28, GDB_FR_REG28(sp)
3866 -               LONG_L  $27, GDB_FR_REG27(sp)
3867 -               LONG_L  $26, GDB_FR_REG26(sp)
3868 -               LONG_L  $25, GDB_FR_REG25(sp)
3869 -               LONG_L  $24, GDB_FR_REG24(sp)
3870 -               LONG_L  $23, GDB_FR_REG23(sp)
3871 -               LONG_L  $22, GDB_FR_REG22(sp)
3872 -               LONG_L  $21, GDB_FR_REG21(sp)
3873 -               LONG_L  $20, GDB_FR_REG20(sp)
3874 -               LONG_L  $19, GDB_FR_REG19(sp)
3875 -               LONG_L  $18, GDB_FR_REG18(sp)
3876 -               LONG_L  $17, GDB_FR_REG17(sp)
3877 -               LONG_L  $16, GDB_FR_REG16(sp)
3878 -               LONG_L  $15, GDB_FR_REG15(sp)
3879 -               LONG_L  $14, GDB_FR_REG14(sp)
3880 -               LONG_L  $13, GDB_FR_REG13(sp)
3881 -               LONG_L  $12, GDB_FR_REG12(sp)
3882 -               LONG_L  $11, GDB_FR_REG11(sp)
3883 -               LONG_L  $10, GDB_FR_REG10(sp)
3884 -               LONG_L  $9, GDB_FR_REG9(sp)
3885 -               LONG_L  $8, GDB_FR_REG8(sp)
3886 -               LONG_L  $7, GDB_FR_REG7(sp)
3887 -               LONG_L  $6, GDB_FR_REG6(sp)
3888 -               LONG_L  $5, GDB_FR_REG5(sp)
3889 -               LONG_L  $4, GDB_FR_REG4(sp)
3890 -               LONG_L  $3, GDB_FR_REG3(sp)
3891 -               LONG_L  $2, GDB_FR_REG2(sp)
3892 -               LONG_L  $1, GDB_FR_REG1(sp)
3893 -#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
3894 -               LONG_L  k0, GDB_FR_EPC(sp)
3895 -               LONG_L  $29, GDB_FR_REG29(sp)           /* Deallocate stack */
3896 -               jr      k0
3897 -               rfe
3898 -#else
3899 -               LONG_L  sp, GDB_FR_REG29(sp)            /* Deallocate stack */
3900 -
3901 -               .set    mips3
3902 -               eret
3903 -               .set    mips0
3904 -#endif
3905 -               .set    at
3906 -               .set    reorder
3907 -               END(trap_low)
3908 -
3909 -LEAF(kgdb_read_byte)
3910 -4:             lb      t0, (a0)
3911 -               sb      t0, (a1)
3912 -               li      v0, 0
3913 -               jr      ra
3914 -               .section __ex_table,"a"
3915 -               PTR     4b, kgdbfault
3916 -               .previous
3917 -               END(kgdb_read_byte)
3918 -
3919 -LEAF(kgdb_write_byte)
3920 -5:             sb      a0, (a1)
3921 -               li      v0, 0
3922 -               jr      ra
3923 -               .section __ex_table,"a"
3924 -               PTR     5b, kgdbfault
3925 -               .previous
3926 -               END(kgdb_write_byte)
3927 -
3928 -               .type   kgdbfault@function
3929 -               .ent    kgdbfault
3930 -
3931 -kgdbfault:     li      v0, -EFAULT
3932 -               jr      ra
3933 -               .end    kgdbfault
3934 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/kernel/gdb-stub.c linux-2.6.18.kgdb/arch/mips/kernel/gdb-stub.c
3935 --- linux-2.6.18/arch/mips/kernel/gdb-stub.c    2006-09-20 07:42:06.000000000 +0400
3936 +++ linux-2.6.18.kgdb/arch/mips/kernel/gdb-stub.c       1970-01-01 03:00:00.000000000 +0300
3937 @@ -1,1154 +0,0 @@
3938 -/*
3939 - *  arch/mips/kernel/gdb-stub.c
3940 - *
3941 - *  Originally written by Glenn Engel, Lake Stevens Instrument Division
3942 - *
3943 - *  Contributed by HP Systems
3944 - *
3945 - *  Modified for SPARC by Stu Grossman, Cygnus Support.
3946 - *
3947 - *  Modified for Linux/MIPS (and MIPS in general) by Andreas Busse
3948 - *  Send complaints, suggestions etc. to <andy@waldorf-gmbh.de>
3949 - *
3950 - *  Copyright (C) 1995 Andreas Busse
3951 - *
3952 - *  Copyright (C) 2003 MontaVista Software Inc.
3953 - *  Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
3954 - */
3955 -
3956 -/*
3957 - *  To enable debugger support, two things need to happen.  One, a
3958 - *  call to set_debug_traps() is necessary in order to allow any breakpoints
3959 - *  or error conditions to be properly intercepted and reported to gdb.
3960 - *  Two, a breakpoint needs to be generated to begin communication.  This
3961 - *  is most easily accomplished by a call to breakpoint().  Breakpoint()
3962 - *  simulates a breakpoint by executing a BREAK instruction.
3963 - *
3964 - *
3965 - *    The following gdb commands are supported:
3966 - *
3967 - * command          function                               Return value
3968 - *
3969 - *    g             return the value of the CPU registers  hex data or ENN
3970 - *    G             set the value of the CPU registers     OK or ENN
3971 - *
3972 - *    mAA..AA,LLLL  Read LLLL bytes at address AA..AA      hex data or ENN
3973 - *    MAA..AA,LLLL: Write LLLL bytes at address AA.AA      OK or ENN
3974 - *
3975 - *    c             Resume at current address              SNN   ( signal NN)
3976 - *    cAA..AA       Continue at address AA..AA             SNN
3977 - *
3978 - *    s             Step one instruction                   SNN
3979 - *    sAA..AA       Step one instruction from AA..AA       SNN
3980 - *
3981 - *    k             kill
3982 - *
3983 - *    ?             What was the last sigval ?             SNN   (signal NN)
3984 - *
3985 - *    bBB..BB      Set baud rate to BB..BB                OK or BNN, then sets
3986 - *                                                        baud rate
3987 - *
3988 - * All commands and responses are sent with a packet which includes a
3989 - * checksum.  A packet consists of
3990 - *
3991 - * $<packet info>#<checksum>.
3992 - *
3993 - * where
3994 - * <packet info> :: <characters representing the command or response>
3995 - * <checksum>    :: < two hex digits computed as modulo 256 sum of <packetinfo>>
3996 - *
3997 - * When a packet is received, it is first acknowledged with either '+' or '-'.
3998 - * '+' indicates a successful transfer.  '-' indicates a failed transfer.
3999 - *
4000 - * Example:
4001 - *
4002 - * Host:                  Reply:
4003 - * $m0,10#2a               +$00010203040506070809101112131415#42
4004 - *
4005 - *
4006 - *  ==============
4007 - *  MORE EXAMPLES:
4008 - *  ==============
4009 - *
4010 - *  For reference -- the following are the steps that one
4011 - *  company took (RidgeRun Inc) to get remote gdb debugging
4012 - *  going. In this scenario the host machine was a PC and the
4013 - *  target platform was a Galileo EVB64120A MIPS evaluation
4014 - *  board.
4015 - *
4016 - *  Step 1:
4017 - *  First download gdb-5.0.tar.gz from the internet.
4018 - *  and then build/install the package.
4019 - *
4020 - *  Example:
4021 - *    $ tar zxf gdb-5.0.tar.gz
4022 - *    $ cd gdb-5.0
4023 - *    $ ./configure --target=mips-linux-elf
4024 - *    $ make
4025 - *    $ install
4026 - *    $ which mips-linux-elf-gdb
4027 - *    /usr/local/bin/mips-linux-elf-gdb
4028 - *
4029 - *  Step 2:
4030 - *  Configure linux for remote debugging and build it.
4031 - *
4032 - *  Example:
4033 - *    $ cd ~/linux
4034 - *    $ make menuconfig <go to "Kernel Hacking" and turn on remote debugging>
4035 - *    $ make
4036 - *
4037 - *  Step 3:
4038 - *  Download the kernel to the remote target and start
4039 - *  the kernel running. It will promptly halt and wait
4040 - *  for the host gdb session to connect. It does this
4041 - *  since the "Kernel Hacking" option has defined
4042 - *  CONFIG_KGDB which in turn enables your calls
4043 - *  to:
4044 - *     set_debug_traps();
4045 - *     breakpoint();
4046 - *
4047 - *  Step 4:
4048 - *  Start the gdb session on the host.
4049 - *
4050 - *  Example:
4051 - *    $ mips-linux-elf-gdb vmlinux
4052 - *    (gdb) set remotebaud 115200
4053 - *    (gdb) target remote /dev/ttyS1
4054 - *    ...at this point you are connected to
4055 - *       the remote target and can use gdb
4056 - *       in the normal fasion. Setting
4057 - *       breakpoints, single stepping,
4058 - *       printing variables, etc.
4059 - */
4060 -#include <linux/string.h>
4061 -#include <linux/kernel.h>
4062 -#include <linux/signal.h>
4063 -#include <linux/sched.h>
4064 -#include <linux/mm.h>
4065 -#include <linux/console.h>
4066 -#include <linux/init.h>
4067 -#include <linux/smp.h>
4068 -#include <linux/spinlock.h>
4069 -#include <linux/slab.h>
4070 -#include <linux/reboot.h>
4071 -
4072 -#include <asm/asm.h>
4073 -#include <asm/cacheflush.h>
4074 -#include <asm/mipsregs.h>
4075 -#include <asm/pgtable.h>
4076 -#include <asm/system.h>
4077 -#include <asm/gdb-stub.h>
4078 -#include <asm/inst.h>
4079 -#include <asm/smp.h>
4080 -
4081 -/*
4082 - * external low-level support routines
4083 - */
4084 -
4085 -extern int putDebugChar(char c);    /* write a single character      */
4086 -extern char getDebugChar(void);     /* read and return a single char */
4087 -extern void trap_low(void);
4088 -
4089 -/*
4090 - * breakpoint and test functions
4091 - */
4092 -extern void breakpoint(void);
4093 -extern void breakinst(void);
4094 -extern void async_breakpoint(void);
4095 -extern void async_breakinst(void);
4096 -extern void adel(void);
4097 -
4098 -/*
4099 - * local prototypes
4100 - */
4101 -
4102 -static void getpacket(char *buffer);
4103 -static void putpacket(char *buffer);
4104 -static int computeSignal(int tt);
4105 -static int hex(unsigned char ch);
4106 -static int hexToInt(char **ptr, int *intValue);
4107 -static int hexToLong(char **ptr, long *longValue);
4108 -static unsigned char *mem2hex(char *mem, char *buf, int count, int may_fault);
4109 -void handle_exception(struct gdb_regs *regs);
4110 -
4111 -int kgdb_enabled;
4112 -
4113 -/*
4114 - * spin locks for smp case
4115 - */
4116 -static DEFINE_SPINLOCK(kgdb_lock);
4117 -static raw_spinlock_t kgdb_cpulock[NR_CPUS] = {
4118 -       [0 ... NR_CPUS-1] = __RAW_SPIN_LOCK_UNLOCKED,
4119 -};
4120 -
4121 -/*
4122 - * BUFMAX defines the maximum number of characters in inbound/outbound buffers
4123 - * at least NUMREGBYTES*2 are needed for register packets
4124 - */
4125 -#define BUFMAX 2048
4126 -
4127 -static char input_buffer[BUFMAX];
4128 -static char output_buffer[BUFMAX];
4129 -static int initialized;        /* !0 means we've been initialized */
4130 -static int kgdb_started;
4131 -static const char hexchars[]="0123456789abcdef";
4132 -
4133 -/* Used to prevent crashes in memory access.  Note that they'll crash anyway if
4134 -   we haven't set up fault handlers yet... */
4135 -int kgdb_read_byte(unsigned char *address, unsigned char *dest);
4136 -int kgdb_write_byte(unsigned char val, unsigned char *dest);
4137 -
4138 -/*
4139 - * Convert ch from a hex digit to an int
4140 - */
4141 -static int hex(unsigned char ch)
4142 -{
4143 -       if (ch >= 'a' && ch <= 'f')
4144 -               return ch-'a'+10;
4145 -       if (ch >= '0' && ch <= '9')
4146 -               return ch-'0';
4147 -       if (ch >= 'A' && ch <= 'F')
4148 -               return ch-'A'+10;
4149 -       return -1;
4150 -}
4151 -
4152 -/*
4153 - * scan for the sequence $<data>#<checksum>
4154 - */
4155 -static void getpacket(char *buffer)
4156 -{
4157 -       unsigned char checksum;
4158 -       unsigned char xmitcsum;
4159 -       int i;
4160 -       int count;
4161 -       unsigned char ch;
4162 -
4163 -       do {
4164 -               /*
4165 -                * wait around for the start character,
4166 -                * ignore all other characters
4167 -                */
4168 -               while ((ch = (getDebugChar() & 0x7f)) != '$') ;
4169 -
4170 -               checksum = 0;
4171 -               xmitcsum = -1;
4172 -               count = 0;
4173 -
4174 -               /*
4175 -                * now, read until a # or end of buffer is found
4176 -                */
4177 -               while (count < BUFMAX) {
4178 -                       ch = getDebugChar();
4179 -                       if (ch == '#')
4180 -                               break;
4181 -                       checksum = checksum + ch;
4182 -                       buffer[count] = ch;
4183 -                       count = count + 1;
4184 -               }
4185 -
4186 -               if (count >= BUFMAX)
4187 -                       continue;
4188 -
4189 -               buffer[count] = 0;
4190 -
4191 -               if (ch == '#') {
4192 -                       xmitcsum = hex(getDebugChar() & 0x7f) << 4;
4193 -                       xmitcsum |= hex(getDebugChar() & 0x7f);
4194 -
4195 -                       if (checksum != xmitcsum)
4196 -                               putDebugChar('-');      /* failed checksum */
4197 -                       else {
4198 -                               putDebugChar('+'); /* successful transfer */
4199 -
4200 -                               /*
4201 -                                * if a sequence char is present,
4202 -                                * reply the sequence ID
4203 -                                */
4204 -                               if (buffer[2] == ':') {
4205 -                                       putDebugChar(buffer[0]);
4206 -                                       putDebugChar(buffer[1]);
4207 -
4208 -                                       /*
4209 -                                        * remove sequence chars from buffer
4210 -                                        */
4211 -                                       count = strlen(buffer);
4212 -                                       for (i=3; i <= count; i++)
4213 -                                               buffer[i-3] = buffer[i];
4214 -                               }
4215 -                       }
4216 -               }
4217 -       }
4218 -       while (checksum != xmitcsum);
4219 -}
4220 -
4221 -/*
4222 - * send the packet in buffer.
4223 - */
4224 -static void putpacket(char *buffer)
4225 -{
4226 -       unsigned char checksum;
4227 -       int count;
4228 -       unsigned char ch;
4229 -
4230 -       /*
4231 -        * $<packet info>#<checksum>.
4232 -        */
4233 -
4234 -       do {
4235 -               putDebugChar('$');
4236 -               checksum = 0;
4237 -               count = 0;
4238 -
4239 -               while ((ch = buffer[count]) != 0) {
4240 -                       if (!(putDebugChar(ch)))
4241 -                               return;
4242 -                       checksum += ch;
4243 -                       count += 1;
4244 -               }
4245 -
4246 -               putDebugChar('#');
4247 -               putDebugChar(hexchars[checksum >> 4]);
4248 -               putDebugChar(hexchars[checksum & 0xf]);
4249 -
4250 -       }
4251 -       while ((getDebugChar() & 0x7f) != '+');
4252 -}
4253 -
4254 -
4255 -/*
4256 - * Convert the memory pointed to by mem into hex, placing result in buf.
4257 - * Return a pointer to the last char put in buf (null), in case of mem fault,
4258 - * return 0.
4259 - * may_fault is non-zero if we are reading from arbitrary memory, but is currently
4260 - * not used.
4261 - */
4262 -static unsigned char *mem2hex(char *mem, char *buf, int count, int may_fault)
4263 -{
4264 -       unsigned char ch;
4265 -
4266 -       while (count-- > 0) {
4267 -               if (kgdb_read_byte(mem++, &ch) != 0)
4268 -                       return 0;
4269 -               *buf++ = hexchars[ch >> 4];
4270 -               *buf++ = hexchars[ch & 0xf];
4271 -       }
4272 -
4273 -       *buf = 0;
4274 -
4275 -       return buf;
4276 -}
4277 -
4278 -/*
4279 - * convert the hex array pointed to by buf into binary to be placed in mem
4280 - * return a pointer to the character AFTER the last byte written
4281 - * may_fault is non-zero if we are reading from arbitrary memory, but is currently
4282 - * not used.
4283 - */
4284 -static char *hex2mem(char *buf, char *mem, int count, int binary, int may_fault)
4285 -{
4286 -       int i;
4287 -       unsigned char ch;
4288 -
4289 -       for (i=0; i<count; i++)
4290 -       {
4291 -               if (binary) {
4292 -                       ch = *buf++;
4293 -                       if (ch == 0x7d)
4294 -                               ch = 0x20 ^ *buf++;
4295 -               }
4296 -               else {
4297 -                       ch = hex(*buf++) << 4;
4298 -                       ch |= hex(*buf++);
4299 -               }
4300 -               if (kgdb_write_byte(ch, mem++) != 0)
4301 -                       return 0;
4302 -       }
4303 -
4304 -       return mem;
4305 -}
4306 -
4307 -/*
4308 - * This table contains the mapping between SPARC hardware trap types, and
4309 - * signals, which are primarily what GDB understands.  It also indicates
4310 - * which hardware traps we need to commandeer when initializing the stub.
4311 - */
4312 -static struct hard_trap_info {
4313 -       unsigned char tt;               /* Trap type code for MIPS R3xxx and R4xxx */
4314 -       unsigned char signo;            /* Signal that we map this trap into */
4315 -} hard_trap_info[] = {
4316 -       { 6, SIGBUS },                  /* instruction bus error */
4317 -       { 7, SIGBUS },                  /* data bus error */
4318 -       { 9, SIGTRAP },                 /* break */
4319 -       { 10, SIGILL },                 /* reserved instruction */
4320 -/*     { 11, SIGILL },         */      /* CPU unusable */
4321 -       { 12, SIGFPE },                 /* overflow */
4322 -       { 13, SIGTRAP },                /* trap */
4323 -       { 14, SIGSEGV },                /* virtual instruction cache coherency */
4324 -       { 15, SIGFPE },                 /* floating point exception */
4325 -       { 23, SIGSEGV },                /* watch */
4326 -       { 31, SIGSEGV },                /* virtual data cache coherency */
4327 -       { 0, 0}                         /* Must be last */
4328 -};
4329 -
4330 -/* Save the normal trap handlers for user-mode traps. */
4331 -void *saved_vectors[32];
4332 -
4333 -/*
4334 - * Set up exception handlers for tracing and breakpoints
4335 - */
4336 -void set_debug_traps(void)
4337 -{
4338 -       struct hard_trap_info *ht;
4339 -       unsigned long flags;
4340 -       unsigned char c;
4341 -
4342 -       local_irq_save(flags);
4343 -       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
4344 -               saved_vectors[ht->tt] = set_except_vector(ht->tt, trap_low);
4345 -
4346 -       putDebugChar('+'); /* 'hello world' */
4347 -       /*
4348 -        * In case GDB is started before us, ack any packets
4349 -        * (presumably "$?#xx") sitting there.
4350 -        */
4351 -       while((c = getDebugChar()) != '$');
4352 -       while((c = getDebugChar()) != '#');
4353 -       c = getDebugChar(); /* eat first csum byte */
4354 -       c = getDebugChar(); /* eat second csum byte */
4355 -       putDebugChar('+'); /* ack it */
4356 -
4357 -       initialized = 1;
4358 -       local_irq_restore(flags);
4359 -}
4360 -
4361 -void restore_debug_traps(void)
4362 -{
4363 -       struct hard_trap_info *ht;
4364 -       unsigned long flags;
4365 -
4366 -       local_irq_save(flags);
4367 -       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
4368 -               set_except_vector(ht->tt, saved_vectors[ht->tt]);
4369 -       local_irq_restore(flags);
4370 -}
4371 -
4372 -/*
4373 - * Convert the MIPS hardware trap type code to a Unix signal number.
4374 - */
4375 -static int computeSignal(int tt)
4376 -{
4377 -       struct hard_trap_info *ht;
4378 -
4379 -       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
4380 -               if (ht->tt == tt)
4381 -                       return ht->signo;
4382 -
4383 -       return SIGHUP;          /* default for things we don't know about */
4384 -}
4385 -
4386 -/*
4387 - * While we find nice hex chars, build an int.
4388 - * Return number of chars processed.
4389 - */
4390 -static int hexToInt(char **ptr, int *intValue)
4391 -{
4392 -       int numChars = 0;
4393 -       int hexValue;
4394 -
4395 -       *intValue = 0;
4396 -
4397 -       while (**ptr) {
4398 -               hexValue = hex(**ptr);
4399 -               if (hexValue < 0)
4400 -                       break;
4401 -
4402 -               *intValue = (*intValue << 4) | hexValue;
4403 -               numChars ++;
4404 -
4405 -               (*ptr)++;
4406 -       }
4407 -
4408 -       return (numChars);
4409 -}
4410 -
4411 -static int hexToLong(char **ptr, long *longValue)
4412 -{
4413 -       int numChars = 0;
4414 -       int hexValue;
4415 -
4416 -       *longValue = 0;
4417 -
4418 -       while (**ptr) {
4419 -               hexValue = hex(**ptr);
4420 -               if (hexValue < 0)
4421 -                       break;
4422 -
4423 -               *longValue = (*longValue << 4) | hexValue;
4424 -               numChars ++;
4425 -
4426 -               (*ptr)++;
4427 -       }
4428 -
4429 -       return numChars;
4430 -}
4431 -
4432 -
4433 -#if 0
4434 -/*
4435 - * Print registers (on target console)
4436 - * Used only to debug the stub...
4437 - */
4438 -void show_gdbregs(struct gdb_regs * regs)
4439 -{
4440 -       /*
4441 -        * Saved main processor registers
4442 -        */
4443 -       printk("$0 : %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4444 -              regs->reg0, regs->reg1, regs->reg2, regs->reg3,
4445 -               regs->reg4, regs->reg5, regs->reg6, regs->reg7);
4446 -       printk("$8 : %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4447 -              regs->reg8, regs->reg9, regs->reg10, regs->reg11,
4448 -               regs->reg12, regs->reg13, regs->reg14, regs->reg15);
4449 -       printk("$16: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4450 -              regs->reg16, regs->reg17, regs->reg18, regs->reg19,
4451 -               regs->reg20, regs->reg21, regs->reg22, regs->reg23);
4452 -       printk("$24: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4453 -              regs->reg24, regs->reg25, regs->reg26, regs->reg27,
4454 -              regs->reg28, regs->reg29, regs->reg30, regs->reg31);
4455 -
4456 -       /*
4457 -        * Saved cp0 registers
4458 -        */
4459 -       printk("epc  : %08lx\nStatus: %08lx\nCause : %08lx\n",
4460 -              regs->cp0_epc, regs->cp0_status, regs->cp0_cause);
4461 -}
4462 -#endif /* dead code */
4463 -
4464 -/*
4465 - * We single-step by setting breakpoints. When an exception
4466 - * is handled, we need to restore the instructions hoisted
4467 - * when the breakpoints were set.
4468 - *
4469 - * This is where we save the original instructions.
4470 - */
4471 -static struct gdb_bp_save {
4472 -       unsigned long addr;
4473 -       unsigned int val;
4474 -} step_bp[2];
4475 -
4476 -#define BP 0x0000000d  /* break opcode */
4477 -
4478 -/*
4479 - * Set breakpoint instructions for single stepping.
4480 - */
4481 -static void single_step(struct gdb_regs *regs)
4482 -{
4483 -       union mips_instruction insn;
4484 -       unsigned long targ;
4485 -       int is_branch, is_cond, i;
4486 -
4487 -       targ = regs->cp0_epc;
4488 -       insn.word = *(unsigned int *)targ;
4489 -       is_branch = is_cond = 0;
4490 -
4491 -       switch (insn.i_format.opcode) {
4492 -       /*
4493 -        * jr and jalr are in r_format format.
4494 -        */
4495 -       case spec_op:
4496 -               switch (insn.r_format.func) {
4497 -               case jalr_op:
4498 -               case jr_op:
4499 -                       targ = *(&regs->reg0 + insn.r_format.rs);
4500 -                       is_branch = 1;
4501 -                       break;
4502 -               }
4503 -               break;
4504 -
4505 -       /*
4506 -        * This group contains:
4507 -        * bltz_op, bgez_op, bltzl_op, bgezl_op,
4508 -        * bltzal_op, bgezal_op, bltzall_op, bgezall_op.
4509 -        */
4510 -       case bcond_op:
4511 -               is_branch = is_cond = 1;
4512 -               targ += 4 + (insn.i_format.simmediate << 2);
4513 -               break;
4514 -
4515 -       /*
4516 -        * These are unconditional and in j_format.
4517 -        */
4518 -       case jal_op:
4519 -       case j_op:
4520 -               is_branch = 1;
4521 -               targ += 4;
4522 -               targ >>= 28;
4523 -               targ <<= 28;
4524 -               targ |= (insn.j_format.target << 2);
4525 -               break;
4526 -
4527 -       /*
4528 -        * These are conditional.
4529 -        */
4530 -       case beq_op:
4531 -       case beql_op:
4532 -       case bne_op:
4533 -       case bnel_op:
4534 -       case blez_op:
4535 -       case blezl_op:
4536 -       case bgtz_op:
4537 -       case bgtzl_op:
4538 -       case cop0_op:
4539 -       case cop1_op:
4540 -       case cop2_op:
4541 -       case cop1x_op:
4542 -               is_branch = is_cond = 1;
4543 -               targ += 4 + (insn.i_format.simmediate << 2);
4544 -               break;
4545 -       }
4546 -
4547 -       if (is_branch) {
4548 -               i = 0;
4549 -               if (is_cond && targ != (regs->cp0_epc + 8)) {
4550 -                       step_bp[i].addr = regs->cp0_epc + 8;
4551 -                       step_bp[i++].val = *(unsigned *)(regs->cp0_epc + 8);
4552 -                       *(unsigned *)(regs->cp0_epc + 8) = BP;
4553 -               }
4554 -               step_bp[i].addr = targ;
4555 -               step_bp[i].val  = *(unsigned *)targ;
4556 -               *(unsigned *)targ = BP;
4557 -       } else {
4558 -               step_bp[0].addr = regs->cp0_epc + 4;
4559 -               step_bp[0].val  = *(unsigned *)(regs->cp0_epc + 4);
4560 -               *(unsigned *)(regs->cp0_epc + 4) = BP;
4561 -       }
4562 -}
4563 -
4564 -/*
4565 - *  If asynchronously interrupted by gdb, then we need to set a breakpoint
4566 - *  at the interrupted instruction so that we wind up stopped with a
4567 - *  reasonable stack frame.
4568 - */
4569 -static struct gdb_bp_save async_bp;
4570 -
4571 -/*
4572 - * Swap the interrupted EPC with our asynchronous breakpoint routine.
4573 - * This is safer than stuffing the breakpoint in-place, since no cache
4574 - * flushes (or resulting smp_call_functions) are required.  The
4575 - * assumption is that only one CPU will be handling asynchronous bp's,
4576 - * and only one can be active at a time.
4577 - */
4578 -extern spinlock_t smp_call_lock;
4579 -
4580 -void set_async_breakpoint(unsigned long *epc)
4581 -{
4582 -       /* skip breaking into userland */
4583 -       if ((*epc & 0x80000000) == 0)
4584 -               return;
4585 -
4586 -#ifdef CONFIG_SMP
4587 -       /* avoid deadlock if someone is make IPC */
4588 -       if (spin_is_locked(&smp_call_lock))
4589 -               return;
4590 -#endif
4591 -
4592 -       async_bp.addr = *epc;
4593 -       *epc = (unsigned long)async_breakpoint;
4594 -}
4595 -
4596 -static void kgdb_wait(void *arg)
4597 -{
4598 -       unsigned flags;
4599 -       int cpu = smp_processor_id();
4600 -
4601 -       local_irq_save(flags);
4602 -
4603 -       __raw_spin_lock(&kgdb_cpulock[cpu]);
4604 -       __raw_spin_unlock(&kgdb_cpulock[cpu]);
4605 -
4606 -       local_irq_restore(flags);
4607 -}
4608 -
4609 -/*
4610 - * GDB stub needs to call kgdb_wait on all processor with interrupts
4611 - * disabled, so it uses it's own special variant.
4612 - */
4613 -static int kgdb_smp_call_kgdb_wait(void)
4614 -{
4615 -#ifdef CONFIG_SMP
4616 -       struct call_data_struct data;
4617 -       int i, cpus = num_online_cpus() - 1;
4618 -       int cpu = smp_processor_id();
4619 -
4620 -       /*
4621 -        * Can die spectacularly if this CPU isn't yet marked online
4622 -        */
4623 -       BUG_ON(!cpu_online(cpu));
4624 -
4625 -       if (!cpus)
4626 -               return 0;
4627 -
4628 -       if (spin_is_locked(&smp_call_lock)) {
4629 -               /*
4630 -                * Some other processor is trying to make us do something
4631 -                * but we're not going to respond... give up
4632 -                */
4633 -               return -1;
4634 -               }
4635 -
4636 -       /*
4637 -        * We will continue here, accepting the fact that
4638 -        * the kernel may deadlock if another CPU attempts
4639 -        * to call smp_call_function now...
4640 -        */
4641 -
4642 -       data.func = kgdb_wait;
4643 -       data.info = NULL;
4644 -       atomic_set(&data.started, 0);
4645 -       data.wait = 0;
4646 -
4647 -       spin_lock(&smp_call_lock);
4648 -       call_data = &data;
4649 -       mb();
4650 -
4651 -       /* Send a message to all other CPUs and wait for them to respond */
4652 -       for (i = 0; i < NR_CPUS; i++)
4653 -               if (cpu_online(i) && i != cpu)
4654 -                       core_send_ipi(i, SMP_CALL_FUNCTION);
4655 -
4656 -       /* Wait for response */
4657 -       /* FIXME: lock-up detection, backtrace on lock-up */
4658 -       while (atomic_read(&data.started) != cpus)
4659 -               barrier();
4660 -
4661 -       call_data = NULL;
4662 -       spin_unlock(&smp_call_lock);
4663 -#endif
4664 -
4665 -       return 0;
4666 -}
4667 -
4668 -/*
4669 - * This function does all command processing for interfacing to gdb.  It
4670 - * returns 1 if you should skip the instruction at the trap address, 0
4671 - * otherwise.
4672 - */
4673 -void handle_exception (struct gdb_regs *regs)
4674 -{
4675 -       int trap;                       /* Trap type */
4676 -       int sigval;
4677 -       long addr;
4678 -       int length;
4679 -       char *ptr;
4680 -       unsigned long *stack;
4681 -       int i;
4682 -       int bflag = 0;
4683 -
4684 -       kgdb_started = 1;
4685 -
4686 -       /*
4687 -        * acquire the big kgdb spinlock
4688 -        */
4689 -       if (!spin_trylock(&kgdb_lock)) {
4690 -               /*
4691 -                * some other CPU has the lock, we should go back to
4692 -                * receive the gdb_wait IPC
4693 -                */
4694 -               return;
4695 -       }
4696 -
4697 -       /*
4698 -        * If we're in async_breakpoint(), restore the real EPC from
4699 -        * the breakpoint.
4700 -        */
4701 -       if (regs->cp0_epc == (unsigned long)async_breakinst) {
4702 -               regs->cp0_epc = async_bp.addr;
4703 -               async_bp.addr = 0;
4704 -       }
4705 -
4706 -       /*
4707 -        * acquire the CPU spinlocks
4708 -        */
4709 -       for (i = num_online_cpus()-1; i >= 0; i--)
4710 -               if (__raw_spin_trylock(&kgdb_cpulock[i]) == 0)
4711 -                       panic("kgdb: couldn't get cpulock %d\n", i);
4712 -
4713 -       /*
4714 -        * force other cpus to enter kgdb
4715 -        */
4716 -       kgdb_smp_call_kgdb_wait();
4717 -
4718 -       /*
4719 -        * If we're in breakpoint() increment the PC
4720 -        */
4721 -       trap = (regs->cp0_cause & 0x7c) >> 2;
4722 -       if (trap == 9 && regs->cp0_epc == (unsigned long)breakinst)
4723 -               regs->cp0_epc += 4;
4724 -
4725 -       /*
4726 -        * If we were single_stepping, restore the opcodes hoisted
4727 -        * for the breakpoint[s].
4728 -        */
4729 -       if (step_bp[0].addr) {
4730 -               *(unsigned *)step_bp[0].addr = step_bp[0].val;
4731 -               step_bp[0].addr = 0;
4732 -
4733 -               if (step_bp[1].addr) {
4734 -                       *(unsigned *)step_bp[1].addr = step_bp[1].val;
4735 -                       step_bp[1].addr = 0;
4736 -               }
4737 -       }
4738 -
4739 -       stack = (long *)regs->reg29;                    /* stack ptr */
4740 -       sigval = computeSignal(trap);
4741 -
4742 -       /*
4743 -        * reply to host that an exception has occurred
4744 -        */
4745 -       ptr = output_buffer;
4746 -
4747 -       /*
4748 -        * Send trap type (converted to signal)
4749 -        */
4750 -       *ptr++ = 'T';
4751 -       *ptr++ = hexchars[sigval >> 4];
4752 -       *ptr++ = hexchars[sigval & 0xf];
4753 -
4754 -       /*
4755 -        * Send Error PC
4756 -        */
4757 -       *ptr++ = hexchars[REG_EPC >> 4];
4758 -       *ptr++ = hexchars[REG_EPC & 0xf];
4759 -       *ptr++ = ':';
4760 -       ptr = mem2hex((char *)&regs->cp0_epc, ptr, sizeof(long), 0);
4761 -       *ptr++ = ';';
4762 -
4763 -       /*
4764 -        * Send frame pointer
4765 -        */
4766 -       *ptr++ = hexchars[REG_FP >> 4];
4767 -       *ptr++ = hexchars[REG_FP & 0xf];
4768 -       *ptr++ = ':';
4769 -       ptr = mem2hex((char *)&regs->reg30, ptr, sizeof(long), 0);
4770 -       *ptr++ = ';';
4771 -
4772 -       /*
4773 -        * Send stack pointer
4774 -        */
4775 -       *ptr++ = hexchars[REG_SP >> 4];
4776 -       *ptr++ = hexchars[REG_SP & 0xf];
4777 -       *ptr++ = ':';
4778 -       ptr = mem2hex((char *)&regs->reg29, ptr, sizeof(long), 0);
4779 -       *ptr++ = ';';
4780 -
4781 -       *ptr++ = 0;
4782 -       putpacket(output_buffer);       /* send it off... */
4783 -
4784 -       /*
4785 -        * Wait for input from remote GDB
4786 -        */
4787 -       while (1) {
4788 -               output_buffer[0] = 0;
4789 -               getpacket(input_buffer);
4790 -
4791 -               switch (input_buffer[0])
4792 -               {
4793 -               case '?':
4794 -                       output_buffer[0] = 'S';
4795 -                       output_buffer[1] = hexchars[sigval >> 4];
4796 -                       output_buffer[2] = hexchars[sigval & 0xf];
4797 -                       output_buffer[3] = 0;
4798 -                       break;
4799 -
4800 -               /*
4801 -                * Detach debugger; let CPU run
4802 -                */
4803 -               case 'D':
4804 -                       putpacket(output_buffer);
4805 -                       goto finish_kgdb;
4806 -                       break;
4807 -
4808 -               case 'd':
4809 -                       /* toggle debug flag */
4810 -                       break;
4811 -
4812 -               /*
4813 -                * Return the value of the CPU registers
4814 -                */
4815 -               case 'g':
4816 -                       ptr = output_buffer;
4817 -                       ptr = mem2hex((char *)&regs->reg0, ptr, 32*sizeof(long), 0); /* r0...r31 */
4818 -                       ptr = mem2hex((char *)&regs->cp0_status, ptr, 6*sizeof(long), 0); /* cp0 */
4819 -                       ptr = mem2hex((char *)&regs->fpr0, ptr, 32*sizeof(long), 0); /* f0...31 */
4820 -                       ptr = mem2hex((char *)&regs->cp1_fsr, ptr, 2*sizeof(long), 0); /* cp1 */
4821 -                       ptr = mem2hex((char *)&regs->frame_ptr, ptr, 2*sizeof(long), 0); /* frp */
4822 -                       ptr = mem2hex((char *)&regs->cp0_index, ptr, 16*sizeof(long), 0); /* cp0 */
4823 -                       break;
4824 -
4825 -               /*
4826 -                * set the value of the CPU registers - return OK
4827 -                */
4828 -               case 'G':
4829 -               {
4830 -                       ptr = &input_buffer[1];
4831 -                       hex2mem(ptr, (char *)&regs->reg0, 32*sizeof(long), 0, 0);
4832 -                       ptr += 32*(2*sizeof(long));
4833 -                       hex2mem(ptr, (char *)&regs->cp0_status, 6*sizeof(long), 0, 0);
4834 -                       ptr += 6*(2*sizeof(long));
4835 -                       hex2mem(ptr, (char *)&regs->fpr0, 32*sizeof(long), 0, 0);
4836 -                       ptr += 32*(2*sizeof(long));
4837 -                       hex2mem(ptr, (char *)&regs->cp1_fsr, 2*sizeof(long), 0, 0);
4838 -                       ptr += 2*(2*sizeof(long));
4839 -                       hex2mem(ptr, (char *)&regs->frame_ptr, 2*sizeof(long), 0, 0);
4840 -                       ptr += 2*(2*sizeof(long));
4841 -                       hex2mem(ptr, (char *)&regs->cp0_index, 16*sizeof(long), 0, 0);
4842 -                       strcpy(output_buffer,"OK");
4843 -                }
4844 -               break;
4845 -
4846 -               /*
4847 -                * mAA..AA,LLLL  Read LLLL bytes at address AA..AA
4848 -                */
4849 -               case 'm':
4850 -                       ptr = &input_buffer[1];
4851 -
4852 -                       if (hexToLong(&ptr, &addr)
4853 -                               && *ptr++ == ','
4854 -                               && hexToInt(&ptr, &length)) {
4855 -                               if (mem2hex((char *)addr, output_buffer, length, 1))
4856 -                                       break;
4857 -                               strcpy (output_buffer, "E03");
4858 -                       } else
4859 -                               strcpy(output_buffer,"E01");
4860 -                       break;
4861 -
4862 -               /*
4863 -                * XAA..AA,LLLL: Write LLLL escaped binary bytes at address AA.AA
4864 -                */
4865 -               case 'X':
4866 -                       bflag = 1;
4867 -                       /* fall through */
4868 -
4869 -               /*
4870 -                * MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK
4871 -                */
4872 -               case 'M':
4873 -                       ptr = &input_buffer[1];
4874 -
4875 -                       if (hexToLong(&ptr, &addr)
4876 -                               && *ptr++ == ','
4877 -                               && hexToInt(&ptr, &length)
4878 -                               && *ptr++ == ':') {
4879 -                               if (hex2mem(ptr, (char *)addr, length, bflag, 1))
4880 -                                       strcpy(output_buffer, "OK");
4881 -                               else
4882 -                                       strcpy(output_buffer, "E03");
4883 -                       }
4884 -                       else
4885 -                               strcpy(output_buffer, "E02");
4886 -                       break;
4887 -
4888 -               /*
4889 -                * cAA..AA    Continue at address AA..AA(optional)
4890 -                */
4891 -               case 'c':
4892 -                       /* try to read optional parameter, pc unchanged if no parm */
4893 -
4894 -                       ptr = &input_buffer[1];
4895 -                       if (hexToLong(&ptr, &addr))
4896 -                               regs->cp0_epc = addr;
4897 -
4898 -                       goto exit_kgdb_exception;
4899 -                       break;
4900 -
4901 -               /*
4902 -                * kill the program; let us try to restart the machine
4903 -                * Reset the whole machine.
4904 -                */
4905 -               case 'k':
4906 -               case 'r':
4907 -                       machine_restart("kgdb restarts machine");
4908 -                       break;
4909 -
4910 -               /*
4911 -                * Step to next instruction
4912 -                */
4913 -               case 's':
4914 -                       /*
4915 -                        * There is no single step insn in the MIPS ISA, so we
4916 -                        * use breakpoints and continue, instead.
4917 -                        */
4918 -                       single_step(regs);
4919 -                       goto exit_kgdb_exception;
4920 -                       /* NOTREACHED */
4921 -                       break;
4922 -
4923 -               /*
4924 -                * Set baud rate (bBB)
4925 -                * FIXME: Needs to be written
4926 -                */
4927 -               case 'b':
4928 -               {
4929 -#if 0
4930 -                       int baudrate;
4931 -                       extern void set_timer_3();
4932 -
4933 -                       ptr = &input_buffer[1];
4934 -                       if (!hexToInt(&ptr, &baudrate))
4935 -                       {
4936 -                               strcpy(output_buffer,"B01");
4937 -                               break;
4938 -                       }
4939 -
4940 -                       /* Convert baud rate to uart clock divider */
4941 -
4942 -                       switch (baudrate)
4943 -                       {
4944 -                               case 38400:
4945 -                                       baudrate = 16;
4946 -                                       break;
4947 -                               case 19200:
4948 -                                       baudrate = 33;
4949 -                                       break;
4950 -                               case 9600:
4951 -                                       baudrate = 65;
4952 -                                       break;
4953 -                               default:
4954 -                                       baudrate = 0;
4955 -                                       strcpy(output_buffer,"B02");
4956 -                                       goto x1;
4957 -                       }
4958 -
4959 -                       if (baudrate) {
4960 -                               putpacket("OK");        /* Ack before changing speed */
4961 -                               set_timer_3(baudrate); /* Set it */
4962 -                       }
4963 -#endif
4964 -               }
4965 -               break;
4966 -
4967 -               }                       /* switch */
4968 -
4969 -               /*
4970 -                * reply to the request
4971 -                */
4972 -
4973 -               putpacket(output_buffer);
4974 -
4975 -       } /* while */
4976 -
4977 -       return;
4978 -
4979 -finish_kgdb:
4980 -       restore_debug_traps();
4981 -
4982 -exit_kgdb_exception:
4983 -       /* release locks so other CPUs can go */
4984 -       for (i = num_online_cpus()-1; i >= 0; i--)
4985 -               __raw_spin_unlock(&kgdb_cpulock[i]);
4986 -       spin_unlock(&kgdb_lock);
4987 -
4988 -       __flush_cache_all();
4989 -       return;
4990 -}
4991 -
4992 -/*
4993 - * This function will generate a breakpoint exception.  It is used at the
4994 - * beginning of a program to sync up with a debugger and can be used
4995 - * otherwise as a quick means to stop program execution and "break" into
4996 - * the debugger.
4997 - */
4998 -void breakpoint(void)
4999 -{
5000 -       if (!initialized)
5001 -               return;
5002 -
5003 -       __asm__ __volatile__(
5004 -                       ".globl breakinst\n\t"
5005 -                       ".set\tnoreorder\n\t"
5006 -                       "nop\n"
5007 -                       "breakinst:\tbreak\n\t"
5008 -                       "nop\n\t"
5009 -                       ".set\treorder"
5010 -                       );
5011 -}
5012 -
5013 -/* Nothing but the break; don't pollute any registers */
5014 -void async_breakpoint(void)
5015 -{
5016 -       __asm__ __volatile__(
5017 -                       ".globl async_breakinst\n\t"
5018 -                       ".set\tnoreorder\n\t"
5019 -                       "nop\n"
5020 -                       "async_breakinst:\tbreak\n\t"
5021 -                       "nop\n\t"
5022 -                       ".set\treorder"
5023 -                       );
5024 -}
5025 -
5026 -void adel(void)
5027 -{
5028 -       __asm__ __volatile__(
5029 -                       ".globl\tadel\n\t"
5030 -                       "lui\t$8,0x8000\n\t"
5031 -                       "lw\t$9,1($8)\n\t"
5032 -                       );
5033 -}
5034 -
5035 -/*
5036 - * malloc is needed by gdb client in "call func()", even a private one
5037 - * will make gdb happy
5038 - */
5039 -static void * __attribute_used__ malloc(size_t size)
5040 -{
5041 -       return kmalloc(size, GFP_ATOMIC);
5042 -}
5043 -
5044 -static void __attribute_used__ free (void *where)
5045 -{
5046 -       kfree(where);
5047 -}
5048 -
5049 -#ifdef CONFIG_GDB_CONSOLE
5050 -
5051 -void gdb_putsn(const char *str, int l)
5052 -{
5053 -       char outbuf[18];
5054 -
5055 -       if (!kgdb_started)
5056 -               return;
5057 -
5058 -       outbuf[0]='O';
5059 -
5060 -       while(l) {
5061 -               int i = (l>8)?8:l;
5062 -               mem2hex((char *)str, &outbuf[1], i, 0);
5063 -               outbuf[(i*2)+1]=0;
5064 -               putpacket(outbuf);
5065 -               str += i;
5066 -               l -= i;
5067 -       }
5068 -}
5069 -
5070 -static void gdb_console_write(struct console *con, const char *s, unsigned n)
5071 -{
5072 -       gdb_putsn(s, n);
5073 -}
5074 -
5075 -static struct console gdb_console = {
5076 -       .name   = "gdb",
5077 -       .write  = gdb_console_write,
5078 -       .flags  = CON_PRINTBUFFER,
5079 -       .index  = -1
5080 -};
5081 -
5082 -static int __init register_gdb_console(void)
5083 -{
5084 -       register_console(&gdb_console);
5085 -
5086 -       return 0;
5087 -}
5088 -
5089 -console_initcall(register_gdb_console);
5090 -
5091 -#endif
5092 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/kernel/irq.c linux-2.6.18.kgdb/arch/mips/kernel/irq.c
5093 --- linux-2.6.18/arch/mips/kernel/irq.c 2006-09-20 07:42:06.000000000 +0400
5094 +++ linux-2.6.18.kgdb/arch/mips/kernel/irq.c    2008-06-10 16:19:28.000000000 +0400
5095 @@ -25,6 +25,10 @@
5096  #include <asm/atomic.h>
5097  #include <asm/system.h>
5098  #include <asm/uaccess.h>
5099 +#include <asm/kgdb.h>
5100 +
5101 +/* Keep track of if we've done certain initialization already or not. */
5102 +int kgdb_early_setup;
5103  
5104  /*
5105   * 'what should we do if we get a hw irq event on an illegal vector'.
5106 @@ -115,23 +119,13 @@ asmlinkage void spurious_interrupt(struc
5107         atomic_inc(&irq_err_count);
5108  }
5109  
5110 -#ifdef CONFIG_KGDB
5111 -extern void breakpoint(void);
5112 -extern void set_debug_traps(void);
5113 -
5114 -static int kgdb_flag = 1;
5115 -static int __init nokgdb(char *str)
5116 -{
5117 -       kgdb_flag = 0;
5118 -       return 1;
5119 -}
5120 -__setup("nokgdb", nokgdb);
5121 -#endif
5122 -
5123  void __init init_IRQ(void)
5124  {
5125         int i;
5126  
5127 +       if (kgdb_early_setup)
5128 +               return;
5129 +
5130         for (i = 0; i < NR_IRQS; i++) {
5131                 irq_desc[i].status  = IRQ_DISABLED;
5132                 irq_desc[i].action  = NULL;
5133 @@ -144,12 +138,12 @@ void __init init_IRQ(void)
5134         }
5135  
5136         arch_init_irq();
5137 -
5138  #ifdef CONFIG_KGDB
5139 -       if (kgdb_flag) {
5140 -               printk("Wait for gdb client connection ...\n");
5141 -               set_debug_traps();
5142 -               breakpoint();
5143 -       }
5144 +       /*
5145 +        * We have been called before kgdb_arch_init(). Hence,
5146 +        * we dont want the traps to be reinitialized
5147 +        */
5148 +       if (kgdb_early_setup == 0)
5149 +               kgdb_early_setup = 1;
5150  #endif
5151  }
5152 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/kernel/kgdb-jmp.c linux-2.6.18.kgdb/arch/mips/kernel/kgdb-jmp.c
5153 --- linux-2.6.18/arch/mips/kernel/kgdb-jmp.c    1970-01-01 03:00:00.000000000 +0300
5154 +++ linux-2.6.18.kgdb/arch/mips/kernel/kgdb-jmp.c       2008-06-10 16:19:28.000000000 +0400
5155 @@ -0,0 +1,116 @@
5156 +/*
5157 + * arch/mips/kernel/kgdb-jmp.c
5158 + *
5159 + * Save and restore system registers so that within a limited frame we
5160 + * may have a fault and "jump back" to a known safe location.
5161 + *
5162 + * Author: Tom Rini <trini@kernel.crashing.org>
5163 + * Author: Manish Lachwani <mlachwani@mvista.com>
5164 + *
5165 + * Cribbed from glibc, which carries the following:
5166 + * Copyright (C) 1996, 1997, 2000, 2002, 2003 Free Software Foundation, Inc.
5167 + * Copyright (C) 2005 by MontaVista Software.
5168 + *
5169 + * This file is licensed under the terms of the GNU General Public License
5170 + * version 2. This program as licensed "as is" without any warranty of
5171 + * any kind, whether express or implied.
5172 + */
5173 +
5174 +#include <linux/kgdb.h>
5175 +#include <asm/interrupt.h>
5176 +
5177 +#ifdef CONFIG_MIPS64
5178 +/*
5179 + * MIPS 64-bit
5180 + */
5181 +
5182 +int kgdb_fault_setjmp_aux(unsigned long *curr_context, int sp, int fp)
5183 +{
5184 +       __asm__ __volatile__ ("sd $gp, %0" : : "m" (curr_context[0]));
5185 +       __asm__ __volatile__ ("sd $16, %0" : : "m" (curr_context[1]));
5186 +       __asm__ __volatile__ ("sd $17, %0" : : "m" (curr_context[2]));
5187 +       __asm__ __volatile__ ("sd $18, %0" : : "m" (curr_context[3]));
5188 +       __asm__ __volatile__ ("sd $19, %0" : : "m" (curr_context[4]));
5189 +       __asm__ __volatile__ ("sd $20, %0" : : "m" (curr_context[5]));
5190 +       __asm__ __volatile__ ("sd $21, %0" : : "m" (curr_context[6]));
5191 +       __asm__ __volatile__ ("sd $22, %0" : : "m" (curr_context[7]));
5192 +       __asm__ __volatile__ ("sd $23, %0" : : "m" (curr_context[8]));
5193 +       __asm__ __volatile__ ("sd $31, %0" : : "m" (curr_context[9]));
5194 +       curr_context[10] = (long *)sp;
5195 +       curr_context[11] = (long *)fp;
5196 +
5197 +       return 0;
5198 +}
5199 +
5200 +void kgdb_fault_longjmp(unsigned long *curr_context)
5201 +{
5202 +       unsigned long sp_val, fp_val;
5203 +
5204 +       __asm__ __volatile__ ("ld $gp, %0" : : "m" (curr_context[0]));
5205 +       __asm__ __volatile__ ("ld $16, %0" : : "m" (curr_context[1]));
5206 +       __asm__ __volatile__ ("ld $17, %0" : : "m" (curr_context[2]));
5207 +       __asm__ __volatile__ ("ld $18, %0" : : "m" (curr_context[3]));
5208 +       __asm__ __volatile__ ("ld $19, %0" : : "m" (curr_context[4]));
5209 +       __asm__ __volatile__ ("ld $20, %0" : : "m" (curr_context[5]));
5210 +       __asm__ __volatile__ ("ld $21, %0" : : "m" (curr_context[6]));
5211 +       __asm__ __volatile__ ("ld $22, %0" : : "m" (curr_context[7]));
5212 +       __asm__ __volatile__ ("ld $23, %0" : : "m" (curr_context[8]));
5213 +       __asm__ __volatile__ ("ld $25, %0" : : "m" (curr_context[9]));
5214 +       sp_val = curr_context[10];
5215 +       fp_val = curr_context[11];
5216 +       __asm__ __volatile__ ("ld $29, %0\n\t"
5217 +                             "ld $30, %1\n\t" : : "m" (sp_val), "m" (fp_val));
5218 +
5219 +       __asm__ __volatile__ ("dli $2, 1");
5220 +       __asm__ __volatile__ ("j $25");
5221 +
5222 +       for (;;);
5223 +}
5224 +#else
5225 +/*
5226 + * MIPS 32-bit
5227 + */
5228 +
5229 +int kgdb_fault_setjmp_aux(unsigned long *curr_context, int sp, int fp)
5230 +{
5231 +       __asm__ __volatile__("sw $gp, %0" : : "m" (curr_context[0]));
5232 +       __asm__ __volatile__("sw $16, %0" : : "m" (curr_context[1]));
5233 +       __asm__ __volatile__("sw $17, %0" : : "m" (curr_context[2]));
5234 +       __asm__ __volatile__("sw $18, %0" : : "m" (curr_context[3]));
5235 +       __asm__ __volatile__("sw $19, %0" : : "m" (curr_context[4]));
5236 +       __asm__ __volatile__("sw $20, %0" : : "m" (curr_context[5]));
5237 +       __asm__ __volatile__("sw $21, %0" : : "m" (curr_context[6]));
5238 +       __asm__ __volatile__("sw $22, %0" : : "m" (curr_context[7]));
5239 +       __asm__ __volatile__("sw $23, %0" : : "m" (curr_context[8]));
5240 +       __asm__ __volatile__("sw $31, %0" : : "m" (curr_context[9]));
5241 +       curr_context[10] = (long *)sp;
5242 +       curr_context[11] = (long *)fp;
5243 +
5244 +       return 0;
5245 +}
5246 +
5247 +void kgdb_fault_longjmp(unsigned long *curr_context)
5248 +{
5249 +       unsigned long sp_val, fp_val;
5250 +
5251 +       __asm__ __volatile__("lw $gp, %0" : : "m" (curr_context[0]));
5252 +       __asm__ __volatile__("lw $16, %0" : : "m" (curr_context[1]));
5253 +       __asm__ __volatile__("lw $17, %0" : : "m" (curr_context[2]));
5254 +       __asm__ __volatile__("lw $18, %0" : : "m" (curr_context[3]));
5255 +       __asm__ __volatile__("lw $19, %0" : : "m" (curr_context[4]));
5256 +       __asm__ __volatile__("lw $20, %0" : : "m" (curr_context[5]));
5257 +       __asm__ __volatile__("lw $21, %0" : : "m" (curr_context[6]));
5258 +       __asm__ __volatile__("lw $22, %0" : : "m" (curr_context[7]));
5259 +       __asm__ __volatile__("lw $23, %0" : : "m" (curr_context[8]));
5260 +       __asm__ __volatile__("lw $25, %0" : : "m" (curr_context[9]));
5261 +       sp_val = curr_context[10];
5262 +       fp_val = curr_context[11];
5263 +       __asm__ __volatile__("lw $29, %0\n\t"
5264 +                             "lw $30, %1\n\t" : : "m" (sp_val), "m" (fp_val));
5265 +
5266 +       __asm__ __volatile__("li $2, 1");
5267 +       __asm__ __volatile__("jr $25");
5268 +
5269 +       for (;;);
5270 +}
5271 +#endif
5272 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/kernel/kgdb-setjmp.S linux-2.6.18.kgdb/arch/mips/kernel/kgdb-setjmp.S
5273 --- linux-2.6.18/arch/mips/kernel/kgdb-setjmp.S 1970-01-01 03:00:00.000000000 +0300
5274 +++ linux-2.6.18.kgdb/arch/mips/kernel/kgdb-setjmp.S    2008-06-10 16:19:28.000000000 +0400
5275 @@ -0,0 +1,28 @@
5276 +/*
5277 + * arch/mips/kernel/kgdb-jmp.c
5278 + *
5279 + * Save and restore system registers so that within a limited frame we
5280 + * may have a fault and "jump back" to a known safe location.
5281 + *
5282 + * Copyright (C) 2005 by MontaVista Software.
5283 + * Author: Manish Lachwani (mlachwani@mvista.com)
5284 + *
5285 + * This file is licensed under the terms of the GNU General Public License
5286 + * version 2. This program as licensed "as is" without any warranty of
5287 + * any kind, whether express or implied.
5288 + */
5289 +
5290 +#include <asm/asm.h>
5291 +#include <asm/mipsregs.h>
5292 +#include <asm/regdef.h>
5293 +#include <asm/stackframe.h>
5294 +
5295 +       .ent    kgdb_fault_setjmp,0
5296 +ENTRY (kgdb_fault_setjmp)
5297 +       move    a1, sp
5298 +       move    a2, fp
5299 +#ifdef CONFIG_MIPS64
5300 +       nop
5301 +#endif
5302 +       j       kgdb_fault_setjmp_aux
5303 +       .end    kgdb_fault_setjmp
5304 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/kernel/kgdb.c linux-2.6.18.kgdb/arch/mips/kernel/kgdb.c
5305 --- linux-2.6.18/arch/mips/kernel/kgdb.c        1970-01-01 03:00:00.000000000 +0300
5306 +++ linux-2.6.18.kgdb/arch/mips/kernel/kgdb.c   2008-06-10 16:19:28.000000000 +0400
5307 @@ -0,0 +1,297 @@
5308 +/*
5309 + * arch/mips/kernel/kgdb.c
5310 + *
5311 + *  Originally written by Glenn Engel, Lake Stevens Instrument Division
5312 + *
5313 + *  Contributed by HP Systems
5314 + *
5315 + *  Modified for SPARC by Stu Grossman, Cygnus Support.
5316 + *
5317 + *  Modified for Linux/MIPS (and MIPS in general) by Andreas Busse
5318 + *  Send complaints, suggestions etc. to <andy@waldorf-gmbh.de>
5319 + *
5320 + *  Copyright (C) 1995 Andreas Busse
5321 + *
5322 + *  Copyright (C) 2003 MontaVista Software Inc.
5323 + *  Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
5324 + *
5325 + *  Copyright (C) 2004-2005 MontaVista Software Inc.
5326 + *  Author: Manish Lachwani, mlachwani@mvista.com or manish@koffee-break.com
5327 + *
5328 + *  This file is licensed under the terms of the GNU General Public License
5329 + *  version 2. This program is licensed "as is" without any warranty of any
5330 + *  kind, whether express or implied.
5331 + */
5332 +
5333 +#include <linux/string.h>
5334 +#include <linux/kernel.h>
5335 +#include <linux/sched.h>
5336 +#include <linux/smp.h>
5337 +#include <linux/spinlock.h>
5338 +#include <linux/delay.h>
5339 +#include <asm/system.h>
5340 +#include <asm/ptrace.h>                /* for linux pt_regs struct */
5341 +#include <linux/kgdb.h>
5342 +#include <linux/init.h>
5343 +#include <asm/inst.h>
5344 +#include <asm/gdb-stub.h>
5345 +#include <asm/cacheflush.h>
5346 +#include <asm/kdebug.h>
5347 +
5348 +static struct hard_trap_info {
5349 +       unsigned char tt;       /* Trap type code for MIPS R3xxx and R4xxx */
5350 +       unsigned char signo;    /* Signal that we map this trap into */
5351 +} hard_trap_info[] = {
5352 +       { 6, SIGBUS },          /* instruction bus error */
5353 +       { 7, SIGBUS },          /* data bus error */
5354 +       { 9, SIGTRAP },         /* break */
5355 +/*     { 11, SIGILL }, */      /* CPU unusable */
5356 +       { 12, SIGFPE },         /* overflow */
5357 +       { 13, SIGTRAP },        /* trap */
5358 +       { 14, SIGSEGV },        /* virtual instruction cache coherency */
5359 +       { 15, SIGFPE },         /* floating point exception */
5360 +       { 23, SIGSEGV },        /* watch */
5361 +       { 31, SIGSEGV },        /* virtual data cache coherency */
5362 +       { 0, 0}                 /* Must be last */
5363 +};
5364 +
5365 +/* Save the normal trap handlers for user-mode traps. */
5366 +void *saved_vectors[32];
5367 +
5368 +extern void trap_low(void);
5369 +extern void breakinst(void);
5370 +extern void init_IRQ(void);
5371 +
5372 +void kgdb_call_nmi_hook(void *ignored)
5373 +{
5374 +       kgdb_nmihook(smp_processor_id(), (void *)0);
5375 +}
5376 +
5377 +void kgdb_roundup_cpus(unsigned long flags)
5378 +{
5379 +       local_irq_restore(flags);
5380 +       smp_call_function(kgdb_call_nmi_hook, 0, 0, 0);
5381 +       local_irq_save(flags);
5382 +}
5383 +
5384 +static int compute_signal(int tt)
5385 +{
5386 +       struct hard_trap_info *ht;
5387 +
5388 +       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
5389 +               if (ht->tt == tt)
5390 +                       return ht->signo;
5391 +
5392 +       return SIGHUP;          /* default for things we don't know about */
5393 +}
5394 +
5395 +/*
5396 + * Set up exception handlers for tracing and breakpoints
5397 + */
5398 +void handle_exception(struct pt_regs *regs)
5399 +{
5400 +       int trap = (regs->cp0_cause & 0x7c) >> 2;
5401 +
5402 +       if (fixup_exception(regs)) {
5403 +               return;
5404 +       }
5405 +
5406 +       if (atomic_read(&debugger_active))
5407 +               kgdb_nmihook(smp_processor_id(), regs);
5408 +
5409 +       if (atomic_read(&kgdb_setting_breakpoint))
5410 +               if ((trap == 9) && (regs->cp0_epc == (unsigned long)breakinst))
5411 +                       regs->cp0_epc += 4;
5412 +
5413 +       kgdb_handle_exception(0, compute_signal(trap), 0, regs);
5414 +
5415 +       /* In SMP mode, __flush_cache_all does IPI */
5416 +       __flush_cache_all();
5417 +}
5418 +
5419 +void set_debug_traps(void)
5420 +{
5421 +       struct hard_trap_info *ht;
5422 +       unsigned long flags;
5423 +
5424 +       local_irq_save(flags);
5425 +
5426 +       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
5427 +               saved_vectors[ht->tt] = set_except_vector(ht->tt, trap_low);
5428 +
5429 +       local_irq_restore(flags);
5430 +}
5431 +
5432 +#if 0
5433 +/* This should be called before we exit kgdb_handle_exception() I believe.
5434 + * -- Tom
5435 + */
5436 +void restore_debug_traps(void)
5437 +{
5438 +       struct hard_trap_info *ht;
5439 +       unsigned long flags;
5440 +
5441 +       local_irq_save(flags);
5442 +       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
5443 +               set_except_vector(ht->tt, saved_vectors[ht->tt]);
5444 +       local_irq_restore(flags);
5445 +}
5446 +#endif
5447 +
5448 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
5449 +{
5450 +       int reg;
5451 +       gdb_reg_t *ptr = (gdb_reg_t*)gdb_regs;
5452 +
5453 +       for (reg = 0; reg < 32; reg++)
5454 +               *(ptr++) = regs->regs[reg];
5455 +
5456 +       *(ptr++) = regs->cp0_status;
5457 +       *(ptr++) = regs->lo;
5458 +       *(ptr++) = regs->hi;
5459 +       *(ptr++) = regs->cp0_badvaddr;
5460 +       *(ptr++) = regs->cp0_cause;
5461 +       *(ptr++) = regs->cp0_epc;
5462 +
5463 +       return;
5464 +}
5465 +
5466 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
5467 +{
5468 +
5469 +       int reg;
5470 +       const gdb_reg_t *ptr = (gdb_reg_t*)gdb_regs;
5471 +
5472 +       for (reg = 0; reg < 32; reg++)
5473 +               regs->regs[reg] = *(ptr++);
5474 +
5475 +       regs->cp0_status = *(ptr++);
5476 +       regs->lo = *(ptr++);
5477 +       regs->hi = *(ptr++);
5478 +       regs->cp0_badvaddr = *(ptr++);
5479 +       regs->cp0_cause = *(ptr++);
5480 +       regs->cp0_epc = *(ptr++);
5481 +
5482 +       return;
5483 +}
5484 +
5485 +/*
5486 + * Similar to regs_to_gdb_regs() except that process is sleeping and so
5487 + * we may not be able to get all the info.
5488 + */
5489 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
5490 +{
5491 +       int reg;
5492 +       struct thread_info *ti = p->thread_info;
5493 +       unsigned long ksp = (unsigned long)ti + THREAD_SIZE - 32;
5494 +       struct pt_regs *regs = (struct pt_regs *)ksp - 1;
5495 +       gdb_reg_t *ptr = (gdb_reg_t*)gdb_regs;
5496 +
5497 +       for (reg = 0; reg < 16; reg++)
5498 +               *(ptr++) = regs->regs[reg];
5499 +
5500 +       /* S0 - S7 */
5501 +       for (reg = 16; reg < 24; reg++)
5502 +               *(ptr++) = regs->regs[reg];
5503 +
5504 +       for (reg = 24; reg < 28; reg++)
5505 +               *(ptr++) = 0;
5506 +
5507 +       /* GP, SP, FP, RA */
5508 +       for (reg = 28; reg < 32; reg++)
5509 +               *(ptr++) = regs->regs[reg];
5510 +
5511 +       *(ptr++) = regs->cp0_status;
5512 +       *(ptr++) = regs->lo;
5513 +       *(ptr++) = regs->hi;
5514 +       *(ptr++) = regs->cp0_badvaddr;
5515 +       *(ptr++) = regs->cp0_cause;
5516 +       *(ptr++) = regs->cp0_epc;
5517 +
5518 +       return;
5519 +}
5520 +
5521 +/*
5522 + * Calls linux_debug_hook before the kernel dies. If KGDB is enabled,
5523 + * then try to fall into the debugger
5524 + */
5525 +static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd,
5526 +                           void *ptr)
5527 +{
5528 +       struct die_args *args = (struct die_args *)ptr;
5529 +       struct pt_regs *regs = args->regs;
5530 +       int trap = (regs->cp0_cause & 0x7c) >> 2;
5531 +
5532 +       /* See if KGDB is interested. */
5533 +       if (user_mode(regs))
5534 +               /* Userpace events, ignore. */
5535 +               return NOTIFY_DONE;
5536 +
5537 +       kgdb_handle_exception(trap, compute_signal(trap), 0, regs);
5538 +       return NOTIFY_OK;
5539 +}
5540 +
5541 +static struct notifier_block kgdb_notifier = {
5542 +       .notifier_call = kgdb_mips_notify,
5543 +};
5544 +
5545 +/*
5546 + * Handle the 's' and 'c' commands
5547 + */
5548 +int kgdb_arch_handle_exception(int vector, int signo, int err_code,
5549 +                              char *remcom_in_buffer, char *remcom_out_buffer,
5550 +                              struct pt_regs *regs)
5551 +{
5552 +       char *ptr;
5553 +       unsigned long address;
5554 +       int cpu = smp_processor_id();
5555 +
5556 +       switch (remcom_in_buffer[0]) {
5557 +       case 's':
5558 +       case 'c':
5559 +               /* handle the optional parameter */
5560 +               ptr = &remcom_in_buffer[1];
5561 +               if (kgdb_hex2long(&ptr, &address))
5562 +                       regs->cp0_epc = address;
5563 +
5564 +               atomic_set(&cpu_doing_single_step, -1);
5565 +               if (remcom_in_buffer[0] == 's')
5566 +                       if (kgdb_contthread)
5567 +                               atomic_set(&cpu_doing_single_step, cpu);
5568 +
5569 +               return 0;
5570 +       }
5571 +
5572 +       return -1;
5573 +}
5574 +
5575 +struct kgdb_arch arch_kgdb_ops = {
5576 +#ifdef CONFIG_CPU_LITTLE_ENDIAN
5577 +       .gdb_bpt_instr = {0xd},
5578 +#else
5579 +       .gdb_bpt_instr = {0x00, 0x00, 0x00, 0x0d},
5580 +#endif
5581 +};
5582 +
5583 +/*
5584 + * We use kgdb_early_setup so that functions we need to call now don't
5585 + * cause trouble when called again later.
5586 + */
5587 +int kgdb_arch_init(void)
5588 +{
5589 +       /* Board-specifics. */
5590 +       /* Force some calls to happen earlier. */
5591 +       if (kgdb_early_setup == 0) {
5592 +               trap_init();
5593 +               init_IRQ();
5594 +               kgdb_early_setup = 1;
5595 +       }
5596 +
5597 +       /* Set our traps. */
5598 +       /* This needs to be done more finely grained again, paired in
5599 +        * a before/after in kgdb_handle_exception(...) -- Tom */
5600 +       set_debug_traps();
5601 +       notifier_chain_register(&mips_die_chain, &kgdb_notifier);
5602 +
5603 +       return 0;
5604 +}
5605 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/kernel/kgdb_handler.S linux-2.6.18.kgdb/arch/mips/kernel/kgdb_handler.S
5606 --- linux-2.6.18/arch/mips/kernel/kgdb_handler.S        1970-01-01 03:00:00.000000000 +0300
5607 +++ linux-2.6.18.kgdb/arch/mips/kernel/kgdb_handler.S   2008-06-10 16:19:28.000000000 +0400
5608 @@ -0,0 +1,57 @@
5609 +/*
5610 + * arch/mips/kernel/kgdb_handler.S
5611 + *
5612 + * Copyright (C) 2004-2005 MontaVista Software Inc.
5613 + * Author: Manish Lachwani, mlachwani@mvista.com or manish@koffee-break.com
5614 + *
5615 + * This file is licensed under the terms of the GNU General Public
5616 + * version 2. This program is licensed "as is" without any warranty of any
5617 + * kind, whether express or implied.
5618 + */
5619 +
5620 +/*
5621 + * Trap Handler for the new KGDB framework. The main KGDB handler is
5622 + * handle_exception that will be called from here
5623 + *
5624 + */
5625 +
5626 +#include <linux/config.h>
5627 +#include <linux/sys.h>
5628 +
5629 +#include <asm/asm.h>
5630 +#include <asm/errno.h>
5631 +#include <asm/mipsregs.h>
5632 +#include <asm/regdef.h>
5633 +#include <asm/stackframe.h>
5634 +
5635 +       .align  5
5636 +       NESTED(trap_low, PT_SIZE, sp)
5637 +               .set    noat
5638 +               .set    noreorder
5639 +
5640 +               /*
5641 +                * Check for privileged instructions in user mode. For
5642 +                * this, check the cu0 bit in the CPU status register.
5643 +                */
5644 +               mfc0    k0, CP0_STATUS
5645 +               sll     k0, 3
5646 +               bltz    k0, 1f
5647 +               move    k1, sp
5648 +
5649 +               /*
5650 +                * GDB userland from within KGDB. If a user mode address
5651 +                * then jump to the saved exception handler
5652 +                */
5653 +               mfc0    k1, CP0_CAUSE
5654 +               andi    k1, k1, 0x7c
5655 +               PTR_L   k0, saved_vectors(k1)
5656 +               jr      k0
5657 +               nop
5658 +1:
5659 +               SAVE_ALL
5660 +               .set    at
5661 +               .set    reorder
5662 +               move    a0, sp
5663 +               jal     handle_exception
5664 +               j       ret_from_exception
5665 +       END(trap_low)
5666 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/kernel/traps.c linux-2.6.18.kgdb/arch/mips/kernel/traps.c
5667 --- linux-2.6.18/arch/mips/kernel/traps.c       2006-09-20 07:42:06.000000000 +0400
5668 +++ linux-2.6.18.kgdb/arch/mips/kernel/traps.c  2008-06-10 16:19:28.000000000 +0400
5669 @@ -10,6 +10,8 @@
5670   * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
5671   * Copyright (C) 2000, 01 MIPS Technologies, Inc.
5672   * Copyright (C) 2002, 2003, 2004, 2005  Maciej W. Rozycki
5673 + *
5674 + * KGDB specific changes - Manish Lachwani (mlachwani@mvista.com)
5675   */
5676  #include <linux/init.h>
5677  #include <linux/mm.h>
5678 @@ -20,6 +22,7 @@
5679  #include <linux/spinlock.h>
5680  #include <linux/kallsyms.h>
5681  #include <linux/bootmem.h>
5682 +#include <linux/kgdb.h>
5683  
5684  #include <asm/bootinfo.h>
5685  #include <asm/branch.h>
5686 @@ -40,6 +43,7 @@
5687  #include <asm/mmu_context.h>
5688  #include <asm/watch.h>
5689  #include <asm/types.h>
5690 +#include <asm/kdebug.h>
5691  
5692  extern asmlinkage void handle_int(void);
5693  extern asmlinkage void handle_tlbm(void);
5694 @@ -78,6 +82,21 @@ void (*board_bind_eic_interrupt)(int irq
5695   */
5696  #define MODULE_RANGE (8*1024*1024)
5697  
5698 +struct notifier_block *mips_die_chain;
5699 +static spinlock_t die_notifier_lock = SPIN_LOCK_UNLOCKED;
5700 +
5701 +int register_die_notifier(struct notifier_block *nb)
5702 +{
5703 +       int err = 0;
5704 +       unsigned long flags;
5705 +
5706 +       spin_lock_irqsave(&die_notifier_lock, flags);
5707 +       err = notifier_chain_register(&mips_die_chain, nb);
5708 +       spin_unlock_irqrestore(&die_notifier_lock, flags);
5709 +
5710 +       return err;
5711 +}
5712 +
5713  /*
5714   * This routine abuses get_user()/put_user() to reference pointers
5715   * with at least a bit of error checking ...
5716 @@ -1387,6 +1406,11 @@ void __init trap_init(void)
5717         extern char except_vec4;
5718         unsigned long i;
5719  
5720 +#if defined(CONFIG_KGDB)
5721 +       if (kgdb_early_setup)
5722 +               return; /* Already done */
5723 +#endif
5724 +
5725         if (cpu_has_veic || cpu_has_vint)
5726                 ebase = (unsigned long) alloc_bootmem_low_pages (0x200 + VECTORSPACING*64);
5727         else
5728 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/mips-boards/generic/Makefile linux-2.6.18.kgdb/arch/mips/mips-boards/generic/Makefile
5729 --- linux-2.6.18/arch/mips/mips-boards/generic/Makefile 2006-09-20 07:42:06.000000000 +0400
5730 +++ linux-2.6.18.kgdb/arch/mips/mips-boards/generic/Makefile    2008-06-10 16:19:28.000000000 +0400
5731 @@ -21,6 +21,5 @@
5732  obj-y                          := reset.o display.o init.o memory.o printf.o \
5733                                    cmdline.o time.o
5734  obj-$(CONFIG_PCI)              += pci.o
5735 -obj-$(CONFIG_KGDB)             += gdb_hook.o
5736  
5737  EXTRA_AFLAGS := $(CFLAGS)
5738 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/mips-boards/generic/init.c linux-2.6.18.kgdb/arch/mips/mips-boards/generic/init.c
5739 --- linux-2.6.18/arch/mips/mips-boards/generic/init.c   2006-09-20 07:42:06.000000000 +0400
5740 +++ linux-2.6.18.kgdb/arch/mips/mips-boards/generic/init.c      2008-06-10 16:19:28.000000000 +0400
5741 @@ -37,15 +37,6 @@
5742  
5743  #include <asm/mips-boards/malta.h>
5744  
5745 -#ifdef CONFIG_KGDB
5746 -extern int rs_kgdb_hook(int, int);
5747 -extern int rs_putDebugChar(char);
5748 -extern char rs_getDebugChar(void);
5749 -extern int saa9730_kgdb_hook(int);
5750 -extern int saa9730_putDebugChar(char);
5751 -extern char saa9730_getDebugChar(void);
5752 -#endif
5753 -
5754  int prom_argc;
5755  int *_prom_argv, *_prom_envp;
5756  
5757 @@ -172,58 +163,6 @@ static void __init console_config(void)
5758  }
5759  #endif
5760  
5761 -#ifdef CONFIG_KGDB
5762 -void __init kgdb_config (void)
5763 -{
5764 -       extern int (*generic_putDebugChar)(char);
5765 -       extern char (*generic_getDebugChar)(void);
5766 -       char *argptr;
5767 -       int line, speed;
5768 -
5769 -       argptr = prom_getcmdline();
5770 -       if ((argptr = strstr(argptr, "kgdb=ttyS")) != NULL) {
5771 -               argptr += strlen("kgdb=ttyS");
5772 -               if (*argptr != '0' && *argptr != '1')
5773 -                       printk("KGDB: Unknown serial line /dev/ttyS%c, "
5774 -                              "falling back to /dev/ttyS1\n", *argptr);
5775 -               line = *argptr == '0' ? 0 : 1;
5776 -               printk("KGDB: Using serial line /dev/ttyS%d for session\n", line);
5777 -
5778 -               speed = 0;
5779 -               if (*++argptr == ',')
5780 -               {
5781 -                       int c;
5782 -                       while ((c = *++argptr) && ('0' <= c && c <= '9'))
5783 -                               speed = speed * 10 + c - '0';
5784 -               }
5785 -#ifdef CONFIG_MIPS_ATLAS
5786 -               if (line == 1) {
5787 -                       speed = saa9730_kgdb_hook(speed);
5788 -                       generic_putDebugChar = saa9730_putDebugChar;
5789 -                       generic_getDebugChar = saa9730_getDebugChar;
5790 -               }
5791 -               else
5792 -#endif
5793 -               {
5794 -                       speed = rs_kgdb_hook(line, speed);
5795 -                       generic_putDebugChar = rs_putDebugChar;
5796 -                       generic_getDebugChar = rs_getDebugChar;
5797 -               }
5798 -
5799 -               prom_printf("KGDB: Using serial line /dev/ttyS%d at %d for session, "
5800 -                           "please connect your debugger\n", line ? 1 : 0, speed);
5801 -
5802 -               {
5803 -                       char *s;
5804 -                       for (s = "Please connect GDB to this port\r\n"; *s; )
5805 -                               generic_putDebugChar (*s++);
5806 -               }
5807 -
5808 -               /* Breakpoint is invoked after interrupts are initialised */
5809 -       }
5810 -}
5811 -#endif
5812 -
5813  void __init mips_nmi_setup (void)
5814  {
5815         void *base;
5816 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/mips-boards/malta/malta_setup.c linux-2.6.18.kgdb/arch/mips/mips-boards/malta/malta_setup.c
5817 --- linux-2.6.18/arch/mips/mips-boards/malta/malta_setup.c      2006-09-20 07:42:06.000000000 +0400
5818 +++ linux-2.6.18.kgdb/arch/mips/mips-boards/malta/malta_setup.c 2008-06-10 16:19:28.000000000 +0400
5819 @@ -46,10 +46,6 @@ extern void mips_reboot_setup(void);
5820  extern void mips_time_init(void);
5821  extern unsigned long mips_rtc_get_time(void);
5822  
5823 -#ifdef CONFIG_KGDB
5824 -extern void kgdb_config(void);
5825 -#endif
5826 -
5827  struct resource standard_io_resources[] = {
5828         { .name = "dma1", .start = 0x00, .end = 0x1f, .flags = IORESOURCE_BUSY },
5829         { .name = "timer", .start = 0x40, .end = 0x5f, .flags = IORESOURCE_BUSY },
5830 @@ -124,10 +120,6 @@ void __init plat_mem_setup(void)
5831          */
5832         enable_dma(4);
5833  
5834 -#ifdef CONFIG_KGDB
5835 -       kgdb_config ();
5836 -#endif
5837 -
5838         if ((mips_revision_corid == MIPS_REVISION_CORID_BONITO64) ||
5839             (mips_revision_corid == MIPS_REVISION_CORID_CORE_20K) ||
5840             (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL_BON)) {
5841 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/mm/extable.c linux-2.6.18.kgdb/arch/mips/mm/extable.c
5842 --- linux-2.6.18/arch/mips/mm/extable.c 2006-09-20 07:42:06.000000000 +0400
5843 +++ linux-2.6.18.kgdb/arch/mips/mm/extable.c    2008-06-10 16:19:28.000000000 +0400
5844 @@ -3,6 +3,7 @@
5845   */
5846  #include <linux/module.h>
5847  #include <linux/spinlock.h>
5848 +#include <linux/kgdb.h>
5849  #include <asm/branch.h>
5850  #include <asm/uaccess.h>
5851  
5852 @@ -16,6 +17,12 @@ int fixup_exception(struct pt_regs *regs
5853  
5854                 return 1;
5855         }
5856 +#ifdef CONFIG_KGDB
5857 +       if (atomic_read(&debugger_active) && kgdb_may_fault)
5858 +               /* Restore our previous state. */
5859 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
5860 +               /* Not reached. */
5861 +#endif
5862  
5863         return 0;
5864  }
5865 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/sibyte/cfe/setup.c linux-2.6.18.kgdb/arch/mips/sibyte/cfe/setup.c
5866 --- linux-2.6.18/arch/mips/sibyte/cfe/setup.c   2006-09-20 07:42:06.000000000 +0400
5867 +++ linux-2.6.18.kgdb/arch/mips/sibyte/cfe/setup.c      2008-06-10 16:19:28.000000000 +0400
5868 @@ -58,10 +58,6 @@ int cfe_cons_handle;
5869  extern unsigned long initrd_start, initrd_end;
5870  #endif
5871  
5872 -#ifdef CONFIG_KGDB
5873 -extern int kgdb_port;
5874 -#endif
5875 -
5876  static void ATTRIB_NORET cfe_linux_exit(void *arg)
5877  {
5878         int warm = *(int *)arg;
5879 @@ -242,9 +238,6 @@ void __init prom_init(void)
5880         int argc = fw_arg0;
5881         char **envp = (char **) fw_arg2;
5882         int *prom_vec = (int *) fw_arg3;
5883 -#ifdef CONFIG_KGDB
5884 -       char *arg;
5885 -#endif
5886  
5887         _machine_restart   = cfe_linux_restart;
5888         _machine_halt      = cfe_linux_halt;
5889 @@ -308,13 +301,6 @@ void __init prom_init(void)
5890                 }
5891         }
5892  
5893 -#ifdef CONFIG_KGDB
5894 -       if ((arg = strstr(arcs_cmdline,"kgdb=duart")) != NULL)
5895 -               kgdb_port = (arg[10] == '0') ? 0 : 1;
5896 -       else
5897 -               kgdb_port = 1;
5898 -#endif
5899 -
5900  #ifdef CONFIG_BLK_DEV_INITRD
5901         {
5902                 char *ptr;
5903 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/sibyte/sb1250/Makefile linux-2.6.18.kgdb/arch/mips/sibyte/sb1250/Makefile
5904 --- linux-2.6.18/arch/mips/sibyte/sb1250/Makefile       2006-09-20 07:42:06.000000000 +0400
5905 +++ linux-2.6.18.kgdb/arch/mips/sibyte/sb1250/Makefile  2008-06-10 16:19:28.000000000 +0400
5906 @@ -4,5 +4,6 @@ obj-$(CONFIG_SMP)                       += smp.o
5907  obj-$(CONFIG_SIBYTE_TBPROF)            += bcm1250_tbprof.o
5908  obj-$(CONFIG_SIBYTE_STANDALONE)                += prom.o
5909  obj-$(CONFIG_SIBYTE_BUS_WATCHER)       += bus_watcher.o
5910 +obj-$(CONFIG_KGDB_SIBYTE)              += kgdb_sibyte.o
5911  
5912  EXTRA_AFLAGS := $(CFLAGS)
5913 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/sibyte/sb1250/irq.c linux-2.6.18.kgdb/arch/mips/sibyte/sb1250/irq.c
5914 --- linux-2.6.18/arch/mips/sibyte/sb1250/irq.c  2006-09-20 07:42:06.000000000 +0400
5915 +++ linux-2.6.18.kgdb/arch/mips/sibyte/sb1250/irq.c     2008-06-10 16:19:28.000000000 +0400
5916 @@ -30,6 +30,7 @@
5917  #include <asm/system.h>
5918  #include <asm/ptrace.h>
5919  #include <asm/io.h>
5920 +#include <asm/kgdb.h>
5921  
5922  #include <asm/sibyte/sb1250_regs.h>
5923  #include <asm/sibyte/sb1250_int.h>
5924 @@ -59,16 +60,6 @@ static void sb1250_set_affinity(unsigned
5925  extern unsigned long ldt_eoi_space;
5926  #endif
5927  
5928 -#ifdef CONFIG_KGDB
5929 -static int kgdb_irq;
5930 -
5931 -/* Default to UART1 */
5932 -int kgdb_port = 1;
5933 -#ifdef CONFIG_SIBYTE_SB1250_DUART
5934 -extern char sb1250_duart_present[];
5935 -#endif
5936 -#endif
5937 -
5938  static struct irq_chip sb1250_irq_type = {
5939         .typename = "SB1250-IMR",
5940         .startup = startup_sb1250_irq,
5941 @@ -324,6 +315,11 @@ void __init arch_init_irq(void)
5942         unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
5943                 STATUSF_IP1 | STATUSF_IP0;
5944  
5945 +#ifdef CONFIG_KGDB
5946 +       if (kgdb_early_setup)
5947 +               return;
5948 +#endif
5949 +
5950         /* Default everything to IP2 */
5951         for (i = 0; i < SB1250_NR_IRQS; i++) {  /* was I0 */
5952                 __raw_writeq(IMR_IP2_VAL,
5953 @@ -375,50 +371,6 @@ void __init arch_init_irq(void)
5954         /* Enable necessary IPs, disable the rest */
5955         change_c0_status(ST0_IM, imask);
5956  
5957 -#ifdef CONFIG_KGDB
5958 -       if (kgdb_flag) {
5959 -               kgdb_irq = K_INT_UART_0 + kgdb_port;
5960 -
5961 -#ifdef CONFIG_SIBYTE_SB1250_DUART
5962 -               sb1250_duart_present[kgdb_port] = 0;
5963 -#endif
5964 -               /* Setup uart 1 settings, mapper */
5965 -               __raw_writeq(M_DUART_IMR_BRK,
5966 -                            IOADDR(A_DUART_IMRREG(kgdb_port)));
5967 -
5968 -               sb1250_steal_irq(kgdb_irq);
5969 -               __raw_writeq(IMR_IP6_VAL,
5970 -                            IOADDR(A_IMR_REGISTER(0,
5971 -                                                  R_IMR_INTERRUPT_MAP_BASE) +
5972 -                                   (kgdb_irq << 3)));
5973 -               sb1250_unmask_irq(0, kgdb_irq);
5974 -       }
5975 -#endif
5976 -}
5977 -
5978 -#ifdef CONFIG_KGDB
5979 -
5980 -#include <linux/delay.h>
5981 -
5982 -#define duart_out(reg, val)     csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
5983 -#define duart_in(reg)           csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
5984 -
5985 -static void sb1250_kgdb_interrupt(struct pt_regs *regs)
5986 -{
5987 -       /*
5988 -        * Clear break-change status (allow some time for the remote
5989 -        * host to stop the break, since we would see another
5990 -        * interrupt on the end-of-break too)
5991 -        */
5992 -       kstat_this_cpu.irqs[kgdb_irq]++;
5993 -       mdelay(500);
5994 -       duart_out(R_DUART_CMD, V_DUART_MISC_CMD_RESET_BREAK_INT |
5995 -                               M_DUART_RX_EN | M_DUART_TX_EN);
5996 -       set_async_breakpoint(&regs->cp0_epc);
5997 -}
5998 -
5999 -#endif         /* CONFIG_KGDB */
6000 -
6001  static inline int dclz(unsigned long long x)
6002  {
6003         int lz;
6004 @@ -473,7 +425,7 @@ asmlinkage void plat_irq_dispatch(struct
6005                 sb1250_mailbox_interrupt(regs);
6006  #endif
6007  
6008 -#ifdef CONFIG_KGDB
6009 +#ifdef CONFIG_KGDB_SIBYTE
6010         else if (pending & CAUSEF_IP6)                  /* KGDB (uart 1) */
6011                 sb1250_kgdb_interrupt(regs);
6012  #endif
6013 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/sibyte/sb1250/kgdb_sibyte.c linux-2.6.18.kgdb/arch/mips/sibyte/sb1250/kgdb_sibyte.c
6014 --- linux-2.6.18/arch/mips/sibyte/sb1250/kgdb_sibyte.c  1970-01-01 03:00:00.000000000 +0300
6015 +++ linux-2.6.18.kgdb/arch/mips/sibyte/sb1250/kgdb_sibyte.c     2008-06-10 16:19:28.000000000 +0400
6016 @@ -0,0 +1,164 @@
6017 +/*
6018 + * arch/mips/sibyte/sb1250/kgdb_sibyte.c
6019 + *
6020 + * Author: Manish Lachwani, mlachwani@mvista.com or manish@koffee-break.com
6021 + *
6022 + * 2004 (c) MontaVista Software, Inc. This file is licensed under
6023 + * the terms of the GNU General Public License version 2. This program
6024 + * is licensed "as is" without any warranty of any kind, whether express
6025 + * or implied.
6026 + */
6027 +
6028 +/*
6029 + * Support for KGDB on the Broadcom Sibyte. The SWARM board
6030 + * for example does not have a 8250/16550 compatible serial
6031 + * port. Hence, we need to have a driver for the serial
6032 + * ports to handle KGDB.  This board needs nothing in addition
6033 + * to what is normally provided by the gdb portion of the stub.
6034 + */
6035 +
6036 +#include <linux/delay.h>
6037 +#include <linux/kernel_stat.h>
6038 +#include <linux/init.h>
6039 +#include <linux/kgdb.h>
6040 +
6041 +#include <asm/io.h>
6042 +#include <asm/sibyte/sb1250.h>
6043 +#include <asm/sibyte/sb1250_regs.h>
6044 +#include <asm/sibyte/sb1250_uart.h>
6045 +#include <asm/sibyte/sb1250_int.h>
6046 +#include <asm/addrspace.h>
6047 +
6048 +int kgdb_port = 1;
6049 +static int kgdb_irq;
6050 +
6051 +extern char sb1250_duart_present[];
6052 +extern int sb1250_steal_irq(int irq);
6053 +
6054 +/* Forward declarations. */
6055 +static void kgdbsibyte_init_duart(void);
6056 +static int kgdb_init_io(void);
6057 +
6058 +#define IMR_IP6_VAL    K_INT_MAP_I4
6059 +#define        duart_out(reg, val)     csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
6060 +#define duart_in(reg)          csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
6061 +
6062 +static void kgdb_swarm_write_char(int c)
6063 +{
6064 +       while ((duart_in(R_DUART_STATUS) & M_DUART_TX_RDY) == 0) ;
6065 +       duart_out(R_DUART_TX_HOLD, c);
6066 +}
6067 +
6068 +static int kgdb_swarm_read_char(void)
6069 +{
6070 +       int ret_char;
6071 +       unsigned int status;
6072 +
6073 +       status = duart_in(R_DUART_STATUS);
6074 +       while ((status & M_DUART_RX_RDY) == 0) {
6075 +               status = duart_in(R_DUART_STATUS);
6076 +       }
6077 +
6078 +       /*
6079 +        * Check for framing error
6080 +        */
6081 +       if (status & M_DUART_FRM_ERR) {
6082 +               kgdbsibyte_init_duart();
6083 +               kgdb_swarm_write_char('-');
6084 +               return '-';
6085 +       }
6086 +
6087 +       ret_char = duart_in(R_DUART_RX_HOLD);
6088 +
6089 +       return ret_char;
6090 +}
6091 +
6092 +void sb1250_kgdb_interrupt(struct pt_regs *regs)
6093 +{
6094 +       int kgdb_irq = K_INT_UART_0 + kgdb_port;
6095 +       /*
6096 +        * Clear break-change status (allow some time for the remote
6097 +        * host to stop the break, since we would see another
6098 +        * interrupt on the end-of-break too)
6099 +        */
6100 +       kstat_this_cpu.irqs[kgdb_irq]++;
6101 +       mdelay(500);
6102 +       duart_out(R_DUART_CMD, V_DUART_MISC_CMD_RESET_BREAK_INT |
6103 +                 M_DUART_RX_EN | M_DUART_TX_EN);
6104 +       if (kgdb_io_ops.init != kgdb_init_io) {
6105 +               /* Throw away the data if another I/O routine is
6106 +                * active.
6107 +                */
6108 +               unsigned int status;
6109 +
6110 +               status = duart_in(R_DUART_STATUS);
6111 +               while ((status & M_DUART_RX_RDY) == 0) {
6112 +                       status = duart_in(R_DUART_STATUS);
6113 +               }
6114 +               /*
6115 +                * Check for framing error
6116 +                */
6117 +               if (status & M_DUART_FRM_ERR) {
6118 +                       kgdbsibyte_init_duart();
6119 +               }
6120 +               duart_in(R_DUART_RX_HOLD);
6121 +       } else
6122 +               breakpoint();
6123 +
6124 +}
6125 +
6126 +/*
6127 + * We use port #1 and we set it for 115200 BAUD, 8n1.
6128 + */
6129 +static void kgdbsibyte_init_duart(void)
6130 +{
6131 +       /* Set 8n1. */
6132 +       duart_out(R_DUART_MODE_REG_1,
6133 +                 V_DUART_BITS_PER_CHAR_8 | V_DUART_PARITY_MODE_NONE);
6134 +       duart_out(R_DUART_MODE_REG_2, M_DUART_STOP_BIT_LEN_1);
6135 +       /* Set baud rate of 115200. */
6136 +       duart_out(R_DUART_CLK_SEL, V_DUART_BAUD_RATE(115200));
6137 +       /* Enable rx and tx */
6138 +       duart_out(R_DUART_CMD, M_DUART_RX_EN | M_DUART_TX_EN);
6139 +}
6140 +
6141 +static int kgdb_init_io(void)
6142 +{
6143 +#ifdef CONFIG_SIBYTE_SB1250_DUART
6144 +       sb1250_duart_present[kgdb_port] = 0;
6145 +#endif
6146 +
6147 +       kgdbsibyte_init_duart();
6148 +
6149 +       return 0;
6150 +}
6151 +
6152 +/*
6153 + * Hookup our IRQ line.  We will already have been initialized a
6154 + * this point.
6155 + */
6156 +static void __init kgdbsibyte_hookup_irq(void)
6157 +{
6158 +       /* Steal the IRQ. */
6159 +       kgdb_irq = K_INT_UART_0 + kgdb_port;
6160 +
6161 +       /* Setup uart 1 settings, mapper */
6162 +       __raw_writeq(M_DUART_IMR_BRK, IOADDR(A_DUART_IMRREG(kgdb_port)));
6163 +
6164 +       sb1250_steal_irq(kgdb_irq);
6165 +
6166 +       __raw_writeq(IMR_IP6_VAL,
6167 +                    IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE) +
6168 +                           (kgdb_irq << 3)));
6169 +
6170 +       sb1250_unmask_irq(0, kgdb_irq);
6171 +}
6172 +
6173 +struct kgdb_io kgdb_io_ops = {
6174 +       .read_char = kgdb_swarm_read_char,
6175 +       .write_char = kgdb_swarm_write_char,
6176 +       .init = kgdb_init_io,
6177 +       .late_init = kgdbsibyte_hookup_irq,
6178 +       .pre_exception = NULL,
6179 +       .post_exception = NULL
6180 +};
6181 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/sibyte/swarm/Makefile linux-2.6.18.kgdb/arch/mips/sibyte/swarm/Makefile
6182 --- linux-2.6.18/arch/mips/sibyte/swarm/Makefile        2006-09-20 07:42:06.000000000 +0400
6183 +++ linux-2.6.18.kgdb/arch/mips/sibyte/swarm/Makefile   2008-06-10 16:19:28.000000000 +0400
6184 @@ -1,3 +1 @@
6185  lib-y                          = setup.o rtc_xicor1241.o rtc_m41t81.o
6186 -
6187 -lib-$(CONFIG_KGDB)             += dbg_io.o
6188 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/sibyte/swarm/dbg_io.c linux-2.6.18.kgdb/arch/mips/sibyte/swarm/dbg_io.c
6189 --- linux-2.6.18/arch/mips/sibyte/swarm/dbg_io.c        2006-09-20 07:42:06.000000000 +0400
6190 +++ linux-2.6.18.kgdb/arch/mips/sibyte/swarm/dbg_io.c   1970-01-01 03:00:00.000000000 +0300
6191 @@ -1,76 +0,0 @@
6192 -/*
6193 - * kgdb debug routines for SiByte boards.
6194 - *
6195 - * Copyright (C) 2001 MontaVista Software Inc.
6196 - * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
6197 - *
6198 - * This program is free software; you can redistribute  it and/or modify it
6199 - * under  the terms of  the GNU General  Public License as published by the
6200 - * Free Software Foundation;  either version 2 of the  License, or (at your
6201 - * option) any later version.
6202 - *
6203 - */
6204 -
6205 -/* -------------------- BEGINNING OF CONFIG --------------------- */
6206 -
6207 -#include <linux/delay.h>
6208 -#include <asm/io.h>
6209 -#include <asm/sibyte/sb1250.h>
6210 -#include <asm/sibyte/sb1250_regs.h>
6211 -#include <asm/sibyte/sb1250_uart.h>
6212 -#include <asm/sibyte/sb1250_int.h>
6213 -#include <asm/addrspace.h>
6214 -
6215 -/*
6216 - * We use the second serial port for kgdb traffic.
6217 - *     115200, 8, N, 1.
6218 - */
6219 -
6220 -#define        BAUD_RATE               115200
6221 -#define        CLK_DIVISOR             V_DUART_BAUD_RATE(BAUD_RATE)
6222 -#define        DATA_BITS               V_DUART_BITS_PER_CHAR_8         /* or 7    */
6223 -#define        PARITY                  V_DUART_PARITY_MODE_NONE        /* or even */
6224 -#define        STOP_BITS               M_DUART_STOP_BIT_LEN_1          /* or 2    */
6225 -
6226 -static int duart_initialized = 0;      /* 0: need to be init'ed by kgdb */
6227 -
6228 -/* -------------------- END OF CONFIG --------------------- */
6229 -extern int kgdb_port;
6230 -
6231 -#define        duart_out(reg, val)     csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
6232 -#define duart_in(reg)          csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
6233 -
6234 -void putDebugChar(unsigned char c);
6235 -unsigned char getDebugChar(void);
6236 -static void
6237 -duart_init(int clk_divisor, int data, int parity, int stop)
6238 -{
6239 -       duart_out(R_DUART_MODE_REG_1, data | parity);
6240 -       duart_out(R_DUART_MODE_REG_2, stop);
6241 -       duart_out(R_DUART_CLK_SEL, clk_divisor);
6242 -
6243 -       duart_out(R_DUART_CMD, M_DUART_RX_EN | M_DUART_TX_EN);  /* enable rx and tx */
6244 -}
6245 -
6246 -void
6247 -putDebugChar(unsigned char c)
6248 -{
6249 -       if (!duart_initialized) {
6250 -               duart_initialized = 1;
6251 -               duart_init(CLK_DIVISOR, DATA_BITS, PARITY, STOP_BITS);
6252 -       }
6253 -       while ((duart_in(R_DUART_STATUS) & M_DUART_TX_RDY) == 0);
6254 -       duart_out(R_DUART_TX_HOLD, c);
6255 -}
6256 -
6257 -unsigned char
6258 -getDebugChar(void)
6259 -{
6260 -       if (!duart_initialized) {
6261 -               duart_initialized = 1;
6262 -               duart_init(CLK_DIVISOR, DATA_BITS, PARITY, STOP_BITS);
6263 -       }
6264 -       while ((duart_in(R_DUART_STATUS) & M_DUART_RX_RDY) == 0) ;
6265 -       return duart_in(R_DUART_RX_HOLD);
6266 -}
6267 -
6268 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/mips/tx4938/common/Makefile linux-2.6.18.kgdb/arch/mips/tx4938/common/Makefile
6269 --- linux-2.6.18/arch/mips/tx4938/common/Makefile       2006-09-20 07:42:06.000000000 +0400
6270 +++ linux-2.6.18.kgdb/arch/mips/tx4938/common/Makefile  2008-06-10 16:19:28.000000000 +0400
6271 @@ -7,5 +7,5 @@
6272  #
6273  
6274  obj-y  += prom.o setup.o irq.o rtc_rx5c348.o
6275 -obj-$(CONFIG_KGDB) += dbgio.o
6276 +obj-$(CONFIG_KGDB_8250) += dbgio.o
6277  
6278 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/powerpc/Kconfig.debug linux-2.6.18.kgdb/arch/powerpc/Kconfig.debug
6279 --- linux-2.6.18/arch/powerpc/Kconfig.debug     2006-09-20 07:42:06.000000000 +0400
6280 +++ linux-2.6.18.kgdb/arch/powerpc/Kconfig.debug        2008-06-10 16:19:22.000000000 +0400
6281 @@ -18,52 +18,9 @@ config DEBUG_STACK_USAGE
6282  
6283           This option will slow down process creation somewhat.
6284  
6285 -config DEBUGGER
6286 -       bool "Enable debugger hooks"
6287 -       depends on DEBUG_KERNEL
6288 -       help
6289 -         Include in-kernel hooks for kernel debuggers. Unless you are
6290 -         intending to debug the kernel, say N here.
6291 -
6292 -config KGDB
6293 -       bool "Include kgdb kernel debugger"
6294 -       depends on DEBUGGER && (BROKEN || PPC_GEN550 || 4xx)
6295 -       select DEBUG_INFO
6296 -       help
6297 -         Include in-kernel hooks for kgdb, the Linux kernel source level
6298 -         debugger.  See <http://kgdb.sourceforge.net/> for more information.
6299 -         Unless you are intending to debug the kernel, say N here.
6300 -
6301 -choice
6302 -       prompt "Serial Port"
6303 -       depends on KGDB
6304 -       default KGDB_TTYS1
6305 -
6306 -config KGDB_TTYS0
6307 -       bool "ttyS0"
6308 -
6309 -config KGDB_TTYS1
6310 -       bool "ttyS1"
6311 -
6312 -config KGDB_TTYS2
6313 -       bool "ttyS2"
6314 -
6315 -config KGDB_TTYS3
6316 -       bool "ttyS3"
6317 -
6318 -endchoice
6319 -
6320 -config KGDB_CONSOLE
6321 -       bool "Enable serial console thru kgdb port"
6322 -       depends on KGDB && 8xx || CPM2
6323 -       help
6324 -         If you enable this, all serial console messages will be sent
6325 -         over the gdb stub.
6326 -         If unsure, say N.
6327 -
6328  config XMON
6329         bool "Include xmon kernel debugger"
6330 -       depends on DEBUGGER && !PPC_ISERIES
6331 +       depends on DEBUG_KERNEL && !PPC_ISERIES
6332         help
6333           Include in-kernel hooks for the xmon kernel monitor/debugger.
6334           Unless you are intending to debug the kernel, say N here.
6335 @@ -82,6 +39,11 @@ config XMON_DEFAULT
6336           xmon is normally disabled unless booted with 'xmon=on'.
6337           Use 'xmon=off' to disable xmon init during runtime.
6338  
6339 +config DEBUGGER
6340 +       bool
6341 +       depends on KGDB || XMON
6342 +       default y
6343 +
6344  config IRQSTACKS
6345         bool "Use separate kernel stacks when processing interrupts"
6346         depends on PPC64
6347 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/powerpc/kernel/Makefile linux-2.6.18.kgdb/arch/powerpc/kernel/Makefile
6348 --- linux-2.6.18/arch/powerpc/kernel/Makefile   2006-09-20 07:42:06.000000000 +0400
6349 +++ linux-2.6.18.kgdb/arch/powerpc/kernel/Makefile      2008-06-10 16:19:22.000000000 +0400
6350 @@ -60,6 +60,7 @@ obj-$(CONFIG_BOOTX_TEXT)      += btext.o
6351  obj-$(CONFIG_SMP)              += smp.o
6352  obj-$(CONFIG_KPROBES)          += kprobes.o
6353  obj-$(CONFIG_PPC_UDBG_16550)   += legacy_serial.o udbg_16550.o
6354 +obj-$(CONFIG_KGDB)             += kgdb.o
6355  module-$(CONFIG_PPC64)         += module_64.o
6356  obj-$(CONFIG_MODULES)          += $(module-y)
6357  
6358 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/powerpc/kernel/kgdb.c linux-2.6.18.kgdb/arch/powerpc/kernel/kgdb.c
6359 --- linux-2.6.18/arch/powerpc/kernel/kgdb.c     1970-01-01 03:00:00.000000000 +0300
6360 +++ linux-2.6.18.kgdb/arch/powerpc/kernel/kgdb.c        2008-06-10 16:19:22.000000000 +0400
6361 @@ -0,0 +1,568 @@
6362 +/*
6363 + * arch/powerpc/kernel/kgdb.c
6364 + *
6365 + * PowerPC backend to the KGDB stub.
6366 + *
6367 + * Maintainer: Tom Rini <trini@kernel.crashing.org>
6368 + *
6369 + * Copied from arch/ppc/kernel/kgdb.c, updated for ppc64
6370 + *
6371 + * Copyright (C) 1996 Paul Mackerras (setjmp/longjmp)
6372 + * 1998 (c) Michael AK Tesch (tesch@cs.wisc.edu)
6373 + * Copyright (C) 2003 Timesys Corporation.
6374 + * Copyright (C) 2004-2006 MontaVista Software, Inc.
6375 + * PPC64 Mods (C) 2005 Frank Rowand (frowand@mvista.com)
6376 + * PPC32 support restored by Vitaly Wool <vwool@ru.mvista.com> and
6377 + * Sergei Shtylyov <sshtylyov@ru.mvista.com>
6378 + *
6379 + * This file is licensed under the terms of the GNU General Public License
6380 + * version 2. This program as licensed "as is" without any warranty of any
6381 + * kind, whether express or implied.
6382 + */
6383 +
6384 +#include <linux/config.h>
6385 +#include <linux/kernel.h>
6386 +#include <linux/init.h>
6387 +#include <linux/kgdb.h>
6388 +#include <linux/smp.h>
6389 +#include <linux/signal.h>
6390 +#include <linux/ptrace.h>
6391 +#include <asm/current.h>
6392 +#include <asm/ptrace.h>
6393 +#include <asm/processor.h>
6394 +#include <asm/machdep.h>
6395 +
6396 +/*
6397 + * This table contains the mapping between PowerPC hardware trap types, and
6398 + * signals, which are primarily what GDB understands.  GDB and the kernel
6399 + * don't always agree on values, so we use constants taken from gdb-6.2.
6400 + */
6401 +static struct hard_trap_info
6402 +{
6403 +       unsigned int tt;                /* Trap type code for powerpc */
6404 +       unsigned char signo;            /* Signal that we map this trap into */
6405 +} hard_trap_info[] = {
6406 +       { 0x0100, 0x02 /* SIGINT */  },         /* system reset */
6407 +       { 0x0200, 0x0b /* SIGSEGV */ },         /* machine check */
6408 +       { 0x0300, 0x0b /* SIGSEGV */ },         /* data access */
6409 +       { 0x0400, 0x0b /* SIGSEGV */ },  /* instruction access */
6410 +       { 0x0500, 0x02 /* SIGINT */  },  /* external interrupt */
6411 +       { 0x0600, 0x0a /* SIGBUS */  },         /* alignment */
6412 +       { 0x0700, 0x05 /* SIGTRAP */ },  /* program check */
6413 +       { 0x0800, 0x08 /* SIGFPE */  },  /* fp unavailable */
6414 +       { 0x0900, 0x0e /* SIGALRM */ },  /* decrementer */
6415 +       { 0x0c00, 0x14 /* SIGCHLD */ },  /* system call */
6416 +#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
6417 +       { 0x2002, 0x05 /* SIGTRAP */ },  /* debug */
6418 +#if defined(CONFIG_FSL_BOOKE)
6419 +       { 0x2010, 0x08 /* SIGFPE */  },  /* spe unavailable */
6420 +       { 0x2020, 0x08 /* SIGFPE */  },  /* spe unavailable */
6421 +       { 0x2030, 0x08 /* SIGFPE */  },  /* spe fp data */
6422 +       { 0x2040, 0x08 /* SIGFPE */  },  /* spe fp data */
6423 +       { 0x2050, 0x08 /* SIGFPE */  },  /* spe fp round */
6424 +       { 0x2060, 0x0e /* SIGILL */  },  /* performace monitor */
6425 +       { 0x2900, 0x08 /* SIGFPE */  },  /* apu unavailable */
6426 +       { 0x3100, 0x0e /* SIGALRM */ },  /* fixed interval timer */
6427 +       { 0x3200, 0x02 /* SIGINT */  },  /* watchdog */
6428 +#else
6429 +       { 0x1000, 0x0e /* SIGALRM */ },  /* programmable interval timer */
6430 +       { 0x1010, 0x0e /* SIGALRM */ },  /* fixed interval timer */
6431 +       { 0x1020, 0x02 /* SIGINT */  },  /* watchdog */
6432 +       { 0x2010, 0x08 /* SIGFPE */  },  /* fp unavailable */
6433 +       { 0x2020, 0x08 /* SIGFPE */  },  /* ap unavailable */
6434 +#endif
6435 +#else
6436 +       { 0x0d00, 0x05 /* SIGTRAP */ },  /* single-step */
6437 +#if defined(CONFIG_8xx)
6438 +       { 0x1000, 0x04 /* SIGILL */  },  /* software emulation */
6439 +#else
6440 +       { 0x0f00, 0x04 /* SIGILL */  },         /* performance monitor */
6441 +       { 0x0f20, 0x08 /* SIGFPE */  },         /* altivec unavailable */
6442 +       { 0x1300, 0x05 /* SIGTRAP */ },         /* instruction address break */
6443 +#if defined(CONFIG_PPC64)
6444 +       { 0x1200, 0x05 /* SIGILL */  },         /* system error */
6445 +       { 0x1500, 0x04 /* SIGILL */  },         /* soft patch */
6446 +       { 0x1600, 0x04 /* SIGILL */  },         /* maintenance */
6447 +       { 0x1700, 0x08 /* SIGFPE */  },  /* altivec assist */
6448 +       { 0x1800, 0x04 /* SIGILL */  },         /* thermal */
6449 +#else
6450 +       { 0x1400, 0x02 /* SIGINT */  },  /* SMI */
6451 +       { 0x1600, 0x08 /* SIGFPE */  },  /* altivec assist */
6452 +       { 0x1700, 0x04 /* SIGILL */  },  /* TAU */
6453 +       { 0x2000, 0x05 /* SIGTRAP */ },  /* run mode */
6454 +#endif
6455 +#endif
6456 +#endif
6457 +       { 0x0000, 0x00 }                        /* Must be last */
6458 +};
6459 +
6460 +extern atomic_t cpu_doing_single_step;
6461 +
6462 +static int computeSignal(unsigned int tt)
6463 +{
6464 +       struct hard_trap_info *ht;
6465 +
6466 +       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
6467 +               if (ht->tt == tt)
6468 +                       return ht->signo;
6469 +
6470 +       return SIGHUP;          /* default for things we don't know about */
6471 +}
6472 +
6473 +static int kgdb_call_nmi_hook(struct pt_regs *regs)
6474 +{
6475 +       kgdb_nmihook(smp_processor_id(), regs);
6476 +       return 0;
6477 +}
6478 +
6479 +#ifdef CONFIG_SMP
6480 +void kgdb_roundup_cpus(unsigned long flags)
6481 +{
6482 +       smp_send_debugger_break(MSG_ALL_BUT_SELF);
6483 +}
6484 +#endif
6485 +
6486 +/* KGDB functions to use existing PowerPC64 hooks. */
6487 +static int kgdb_debugger(struct pt_regs *regs)
6488 +{
6489 +       return kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
6490 +}
6491 +
6492 +static int kgdb_breakpoint(struct pt_regs *regs)
6493 +{
6494 +       if (user_mode(regs))
6495 +               return 0;
6496 +
6497 +       kgdb_handle_exception(0, SIGTRAP, 0, regs);
6498 +
6499 +       if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
6500 +               regs->nip += 4;
6501 +
6502 +       return 1;
6503 +}
6504 +
6505 +static int kgdb_singlestep(struct pt_regs *regs)
6506 +{
6507 +       struct thread_info *thread_info, *exception_thread_info;
6508 +       if (user_mode(regs))
6509 +               return 0;
6510 +       /*
6511 +       * On Book E and perhaps other processsors, singlestep is handled on
6512 +       * the critical exception stack.  This causes current_thread_info()
6513 +       * to fail, since it it locates the thread_info by masking off
6514 +       * the low bits of the current stack pointer.  We work around
6515 +       * this issue by copying the thread_info from the kernel stack
6516 +       * before calling kgdb_handle_exception, and copying it back
6517 +       * afterwards.  On most processors the copy is avoided since
6518 +       * exception_thread_info == thread_info.
6519 +       */
6520 +       thread_info = (struct thread_info *)(regs->gpr[1] & ~(THREAD_SIZE-1));
6521 +       exception_thread_info = current_thread_info();
6522 +
6523 +       if (thread_info != exception_thread_info)
6524 +               memcpy(exception_thread_info, thread_info, sizeof *thread_info);
6525 +
6526 +       kgdb_handle_exception(0, SIGTRAP, 0, regs);
6527 +
6528 +       if (thread_info != exception_thread_info)
6529 +               memcpy(thread_info, exception_thread_info, sizeof *thread_info);
6530 +
6531 +       return 1;
6532 +}
6533 +
6534 +int kgdb_iabr_match(struct pt_regs *regs)
6535 +{
6536 +       if (user_mode(regs))
6537 +               return 0;
6538 +
6539 +       kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
6540 +       return 1;
6541 +}
6542 +
6543 +int kgdb_dabr_match(struct pt_regs *regs)
6544 +{
6545 +       if (user_mode(regs))
6546 +               return 0;
6547 +
6548 +       kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
6549 +       return 1;
6550 +}
6551 +
6552 +#define PACK64(ptr,src) do { *(ptr++) = (src); } while(0)
6553 +
6554 +#define PACK32(ptr,src) do {          \
6555 +       u32 *ptr32;                   \
6556 +       ptr32 = (u32 *)ptr;           \
6557 +       *(ptr32++) = (src);           \
6558 +       ptr = (unsigned long *)ptr32; \
6559 +       } while(0)
6560 +
6561 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
6562 +{
6563 +       unsigned long *ptr = gdb_regs;
6564 +       int reg;
6565 +
6566 +       memset(gdb_regs, 0, NUMREGBYTES);
6567 +
6568 +       for (reg = 0; reg < 32; reg++)
6569 +               PACK64(ptr, regs->gpr[reg]);
6570 +
6571 +#ifdef CONFIG_FSL_BOOKE
6572 +#ifdef CONFIG_SPE
6573 +       for (reg = 0; reg < 32; reg++)
6574 +               PACK64(ptr, current->thread.evr[reg]);
6575 +#else
6576 +       ptr += 32;
6577 +#endif
6578 +#else
6579 +       /* fp registers not used by kernel, leave zero */
6580 +       ptr += 32 * 8 / sizeof(long);
6581 +#endif
6582 +
6583 +       PACK64(ptr, regs->nip);
6584 +       PACK64(ptr, regs->msr);
6585 +       PACK32(ptr, regs->ccr);
6586 +       PACK64(ptr, regs->link);
6587 +       PACK64(ptr, regs->ctr);
6588 +       PACK32(ptr, regs->xer);
6589 +
6590 +#if 0
6591 +       Following are in struct thread_struct, not struct pt_regs,
6592 +       ignoring for now since kernel does not use them.  Would it
6593 +       make sense to get them from the thread that kgdb is set to?
6594 +
6595 +       If this code is enabled, update the definition of NUMREGBYTES to
6596 +       include the vector registers and vector state registers.
6597 +
6598 +       PACK32(ptr, current->thread->fpscr);
6599 +
6600 +       /* vr registers not used by kernel, leave zero */
6601 +       ptr += 32 * 16 / sizeof(long);
6602 +
6603 +#ifdef CONFIG_ALTIVEC
6604 +       PACK32(ptr, current->thread->vscr);
6605 +       PACK32(ptr, current->thread->vrsave);
6606 +#else
6607 +       ptr += 2 * 4 / sizeof(long);
6608 +#endif
6609 +#else
6610 +#ifdef CONFIG_FSL_BOOKE
6611 +#ifdef CONFIG_SPE
6612 +       /* u64 acc */
6613 +       PACK32(ptr, current->thread.acc >> 32);
6614 +       PACK32(ptr, current->thread.acc & 0xffffffff);
6615 +       PACK64(ptr, current->thread.spefscr);
6616 +#else
6617 +       ptr += 2 + 1;
6618 +#endif
6619 +#else
6620 +       /* fpscr not used by kernel, leave zero */
6621 +       PACK32(ptr, 0);
6622 +#endif
6623 +#endif
6624 +
6625 +       BUG_ON((unsigned long)ptr >
6626 +              (unsigned long)(((void *)gdb_regs) + NUMREGBYTES));
6627 +}
6628 +
6629 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
6630 +{
6631 +       struct pt_regs *regs = (struct pt_regs *)(p->thread.ksp +
6632 +                                                 STACK_FRAME_OVERHEAD);
6633 +       unsigned long *ptr = gdb_regs;
6634 +       int reg;
6635 +
6636 +       memset(gdb_regs, 0, NUMREGBYTES);
6637 +
6638 +       /* Regs GPR0-2 */
6639 +       for (reg = 0; reg < 3; reg++)
6640 +               PACK64(ptr, regs->gpr[reg]);
6641 +
6642 +       /* Regs GPR3-13 are caller saved, not in regs->gpr[] */
6643 +       ptr += 11;
6644 +
6645 +       /* Regs GPR14-31 */
6646 +       for (reg = 14; reg < 32; reg++)
6647 +               PACK64(ptr, regs->gpr[reg]);
6648 +
6649 +#ifdef CONFIG_FSL_BOOKE
6650 +#ifdef CONFIG_SPE
6651 +       for (reg = 0; reg < 32; reg++)
6652 +               PACK64(ptr, p->thread.evr[reg]);
6653 +#else
6654 +       ptr += 32;
6655 +#endif
6656 +#else
6657 +       /* fp registers not used by kernel, leave zero */
6658 +       ptr += 32 * 8 / sizeof(long);
6659 +#endif
6660 +       PACK64(ptr, regs->nip);
6661 +       PACK64(ptr, regs->msr);
6662 +       PACK32(ptr, regs->ccr);
6663 +       PACK64(ptr, regs->link);
6664 +       PACK64(ptr, regs->ctr);
6665 +       PACK32(ptr, regs->xer);
6666 +
6667 +#if 0
6668 +       Following are in struct thread_struct, not struct pt_regs,
6669 +       ignoring for now since kernel does not use them.  Would it
6670 +       make sense to get them from the thread that kgdb is set to?
6671 +
6672 +       If this code is enabled, update the definition of NUMREGBYTES to
6673 +       include the vector registers and vector state registers.
6674 +
6675 +       PACK32(ptr, p->thread->fpscr);
6676 +
6677 +       /* vr registers not used by kernel, leave zero */
6678 +       ptr += 32 * 16 / sizeof(long);
6679 +
6680 +#ifdef CONFIG_ALTIVEC
6681 +       PACK32(ptr, p->thread->vscr);
6682 +       PACK32(ptr, p->thread->vrsave);
6683 +#else
6684 +       ptr += 2 * 4 / sizeof(long);
6685 +#endif
6686 +#else
6687 +#ifdef CONFIG_FSL_BOOKE
6688 +#ifdef CONFIG_SPE
6689 +       /* u64 acc */
6690 +       PACK32(ptr, p->thread.acc >> 32);
6691 +       PACK32(ptr, p->thread.acc & 0xffffffff);
6692 +       PACK64(ptr, p->thread.spefscr);
6693 +#else
6694 +       ptr += 2 + 1;
6695 +#endif
6696 +#else
6697 +       /* fpscr not used by kernel, leave zero */
6698 +       PACK32(ptr, 0);
6699 +#endif
6700 +#endif
6701 +
6702 +       BUG_ON((unsigned long)ptr >
6703 +              (unsigned long)(((void *)gdb_regs) + NUMREGBYTES));
6704 +}
6705 +
6706 +#define UNPACK64(dest,ptr) do { dest = *(ptr++); } while(0)
6707 +
6708 +#define UNPACK32(dest,ptr) do {       \
6709 +       u32 *ptr32;                   \
6710 +       ptr32 = (u32 *)ptr;           \
6711 +       dest = *(ptr32++);            \
6712 +       ptr = (unsigned long *)ptr32; \
6713 +       } while(0)
6714 +
6715 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
6716 +{
6717 +       unsigned long *ptr = gdb_regs;
6718 +       int reg;
6719 +
6720 +#ifdef CONFIG_SPE
6721 +       union {
6722 +               u32 v32[2];
6723 +               u64 v64;
6724 +       } acc;
6725 +#endif
6726 +       for (reg = 0; reg < 32; reg++)
6727 +               UNPACK64(regs->gpr[reg], ptr);
6728 +
6729 +#ifdef CONFIG_FSL_BOOKE
6730 +#ifdef CONFIG_SPE
6731 +       for (reg = 0; reg < 32; reg++)
6732 +               UNPACK64(current->thread.evr[reg], ptr);
6733 +#else
6734 +       ptr += 32;
6735 +#endif
6736 +#else
6737 +       /* fp registers not used by kernel, leave zero */
6738 +       ptr += 32 * 8 / sizeof(int);
6739 +#endif
6740 +       UNPACK64(regs->nip, ptr);
6741 +       UNPACK64(regs->msr, ptr);
6742 +       UNPACK32(regs->ccr, ptr);
6743 +       UNPACK64(regs->link, ptr);
6744 +       UNPACK64(regs->ctr, ptr);
6745 +       UNPACK32(regs->xer, ptr);
6746 +
6747 +#if 0
6748 +       Following are in struct thread_struct, not struct pt_regs,
6749 +       ignoring for now since kernel does not use them.  Would it
6750 +       make sense to get them from the thread that kgdb is set to?
6751 +
6752 +       If this code is enabled, update the definition of NUMREGBYTES to
6753 +       include the vector registers and vector state registers.
6754 +
6755 +       /* fpscr, vscr, vrsave not used by kernel, leave unchanged */
6756 +
6757 +       UNPACK32(current->thread->fpscr, ptr);
6758 +
6759 +       /* vr registers not used by kernel, leave zero */
6760 +       ptr += 32 * 16 / sizeof(long);
6761 +
6762 +       #ifdef CONFIG_ALTIVEC
6763 +       UNPACK32(current->thread->vscr, ptr);
6764 +       UNPACK32(current->thread->vrsave, ptr);
6765 +#else
6766 +       ptr += 2 * 4 / sizeof(long);
6767 +#endif
6768 +#else
6769 +#ifdef CONFIG_FSL_BOOKE
6770 +#ifdef CONFIG_SPE
6771 +       /* u64 acc */
6772 +       UNPACK32(acc.v32[0], ptr);
6773 +       UNPACK32(acc.v32[1], ptr);
6774 +       current->thread.acc = acc.v64;
6775 +       UNPACK64(current->thread.spefscr, ptr);
6776 +#else
6777 +       ptr += 2 + 1;
6778 +#endif
6779 +#endif
6780 +#endif
6781 +
6782 +       BUG_ON((unsigned long)ptr >
6783 +              (unsigned long)(((void *)gdb_regs) + NUMREGBYTES));
6784 +}
6785 +
6786 +/*
6787 + * This function does PowerPC specific procesing for interfacing to gdb.
6788 + */
6789 +int kgdb_arch_handle_exception(int vector, int signo, int err_code,
6790 +                              char *remcom_in_buffer, char *remcom_out_buffer,
6791 +                              struct pt_regs *linux_regs)
6792 +{
6793 +       char *ptr = &remcom_in_buffer[1];
6794 +       unsigned long addr;
6795 +
6796 +       switch (remcom_in_buffer[0]) {
6797 +               /*
6798 +                * sAA..AA   Step one instruction from AA..AA
6799 +                * This will return an error to gdb ..
6800 +                */
6801 +       case 's':
6802 +       case 'c':
6803 +               /* handle the optional parameter */
6804 +               if (kgdb_hex2long(&ptr, &addr))
6805 +                       linux_regs->nip = addr;
6806 +
6807 +               atomic_set(&cpu_doing_single_step, -1);
6808 +               /* set the trace bit if we're stepping */
6809 +               if (remcom_in_buffer[0] == 's') {
6810 +#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
6811 +                       mtspr(SPRN_DBCR0,
6812 +                               mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM);
6813 +                       linux_regs->msr |= MSR_DE;
6814 +#else
6815 +                       linux_regs->msr |= MSR_SE;
6816 +#endif
6817 +                       debugger_step = 1;
6818 +                       if (kgdb_contthread)
6819 +                               atomic_set(&cpu_doing_single_step,
6820 +                                          smp_processor_id());
6821 +               }
6822 +               return 0;
6823 +       }
6824 +
6825 +       return -1;
6826 +}
6827 +
6828 +int kgdb_fault_setjmp(unsigned long *curr_context)
6829 +{
6830 +#ifdef CONFIG_PPC32
6831 +       __asm__ __volatile__("mflr 0; stw 0,0(%0);\n\
6832 +                               stw 1,4(%0); stw 2,8(%0);\n\
6833 +                               mfcr 0; stw 0,12(%0);\n\
6834 +                               stmw 13,16(%0)\n" : : "r" (curr_context));
6835 +#else
6836 +       __asm__ __volatile__("mflr 0; std 0,0(%0)\n\
6837 +                             std       1,8(%0)\n\
6838 +                             std       2,16(%0)\n\
6839 +                             mfcr 0; std 0,24(%0)\n\
6840 +                             std       13,32(%0)\n\
6841 +                             std       14,40(%0)\n\
6842 +                             std       15,48(%0)\n\
6843 +                             std       16,56(%0)\n\
6844 +                             std       17,64(%0)\n\
6845 +                             std       18,72(%0)\n\
6846 +                             std       19,80(%0)\n\
6847 +                             std       20,88(%0)\n\
6848 +                             std       21,96(%0)\n\
6849 +                             std       22,104(%0)\n\
6850 +                             std       23,112(%0)\n\
6851 +                             std       24,120(%0)\n\
6852 +                             std       25,128(%0)\n\
6853 +                             std       26,136(%0)\n\
6854 +                             std       27,144(%0)\n\
6855 +                             std       28,152(%0)\n\
6856 +                             std       29,160(%0)\n\
6857 +                             std       30,168(%0)\n\
6858 +                             std       31,176(%0)\n" : : "r" (curr_context));
6859 +#endif
6860 +       return 0;
6861 +}
6862 +
6863 +void kgdb_fault_longjmp(unsigned long *curr_context)
6864 +{
6865 +#ifdef CONFIG_PPC32
6866 +       __asm__ __volatile__("lmw 13,16(%0);\n\
6867 +                             lwz 0,12(%0); mtcrf 0x38,0;\n\
6868 +                             lwz 0,0(%0); lwz 1,4(%0); lwz 2,8(%0);\n\
6869 +                             mtlr 0; mr 3,1\n" : : "r" (curr_context));
6870 +#else
6871 +       __asm__ __volatile__("ld        13,32(%0)\n\
6872 +                             ld        14,40(%0)\n\
6873 +                             ld        15,48(%0)\n\
6874 +                             ld        16,56(%0)\n\
6875 +                             ld        17,64(%0)\n\
6876 +                             ld        18,72(%0)\n\
6877 +                             ld        19,80(%0)\n\
6878 +                             ld        20,88(%0)\n\
6879 +                             ld        21,96(%0)\n\
6880 +                             ld        22,104(%0)\n\
6881 +                             ld        23,112(%0)\n\
6882 +                             ld        24,120(%0)\n\
6883 +                             ld        25,128(%0)\n\
6884 +                             ld        26,136(%0)\n\
6885 +                             ld        27,144(%0)\n\
6886 +                             ld        28,152(%0)\n\
6887 +                             ld        29,160(%0)\n\
6888 +                             ld        30,168(%0)\n\
6889 +                             ld        31,176(%0)\n\
6890 +                             ld        0,24(%0)\n\
6891 +                             mtcrf     0x38,0\n\
6892 +                             ld        0,0(%0)\n\
6893 +                             ld        1,8(%0)\n\
6894 +                             ld        2,16(%0)\n\
6895 +                             mtlr      0\n\
6896 +                             mr        3,1\n" : : "r" (curr_context));
6897 +#endif
6898 +}
6899 +
6900 +/*
6901 + * Global data
6902 + */
6903 +struct kgdb_arch arch_kgdb_ops = {
6904 +       .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
6905 +};
6906 +
6907 +int kgdb_not_implemented(struct pt_regs *regs)
6908 +{
6909 +       return 0;
6910 +}
6911 +
6912 +int kgdb_arch_init(void)
6913 +{
6914 +#ifdef CONFIG_XMON
6915 +#error Both XMON and KGDB selected in .config.  Unselect one of them.
6916 +#endif
6917 +
6918 +       __debugger_ipi = kgdb_call_nmi_hook;
6919 +       __debugger = kgdb_debugger;
6920 +       __debugger_bpt = kgdb_breakpoint;
6921 +       __debugger_sstep = kgdb_singlestep;
6922 +       __debugger_iabr_match = kgdb_iabr_match;
6923 +       __debugger_dabr_match = kgdb_dabr_match;
6924 +       __debugger_fault_handler = kgdb_not_implemented;
6925 +
6926 +       return 0;
6927 +}
6928 +
6929 +arch_initcall(kgdb_arch_init);
6930 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/powerpc/kernel/legacy_serial.c linux-2.6.18.kgdb/arch/powerpc/kernel/legacy_serial.c
6931 --- linux-2.6.18/arch/powerpc/kernel/legacy_serial.c    2006-09-20 07:42:06.000000000 +0400
6932 +++ linux-2.6.18.kgdb/arch/powerpc/kernel/legacy_serial.c       2008-06-10 16:19:22.000000000 +0400
6933 @@ -11,6 +11,9 @@
6934  #include <asm/udbg.h>
6935  #include <asm/pci-bridge.h>
6936  #include <asm/ppc-pci.h>
6937 +#ifdef CONFIG_KGDB_8250
6938 +#include <linux/kgdb.h>
6939 +#endif
6940  
6941  #undef DEBUG
6942  
6943 @@ -470,6 +473,9 @@ static int __init serial_dev_init(void)
6944                         fixup_port_pio(i, np, port);
6945                 if ((port->iotype == UPIO_MEM) || (port->iotype == UPIO_TSI))
6946                         fixup_port_mmio(i, np, port);
6947 +#ifdef CONFIG_KGDB_8250
6948 +               kgdb8250_add_platform_port(i, port);
6949 +#endif
6950         }
6951  
6952         DBG("Registering platform serial ports\n");
6953 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/powerpc/kernel/setup_32.c linux-2.6.18.kgdb/arch/powerpc/kernel/setup_32.c
6954 --- linux-2.6.18/arch/powerpc/kernel/setup_32.c 2006-09-20 07:42:06.000000000 +0400
6955 +++ linux-2.6.18.kgdb/arch/powerpc/kernel/setup_32.c    2008-06-10 16:19:22.000000000 +0400
6956 @@ -45,10 +45,6 @@
6957  
6958  #define DBG(fmt...)
6959  
6960 -#if defined CONFIG_KGDB
6961 -#include <asm/kgdb.h>
6962 -#endif
6963 -
6964  extern void bootx_init(unsigned long r4, unsigned long phys);
6965  
6966  struct ide_machdep_calls ppc_ide_md;
6967 @@ -248,18 +244,6 @@ void __init setup_arch(char **cmdline_p)
6968         /* Register early console */
6969         register_early_udbg_console();
6970  
6971 -#if defined(CONFIG_KGDB)
6972 -       if (ppc_md.kgdb_map_scc)
6973 -               ppc_md.kgdb_map_scc();
6974 -       set_debug_traps();
6975 -       if (strstr(cmd_line, "gdb")) {
6976 -               if (ppc_md.progress)
6977 -                       ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
6978 -               printk("kgdb breakpoint activated\n");
6979 -               breakpoint();
6980 -       }
6981 -#endif
6982 -
6983         /*
6984          * Set cache line size based on type of cpu as a default.
6985          * Systems with OF can look in the properties on the cpu node(s)
6986 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/powerpc/mm/fault.c linux-2.6.18.kgdb/arch/powerpc/mm/fault.c
6987 --- linux-2.6.18/arch/powerpc/mm/fault.c        2006-09-20 07:42:06.000000000 +0400
6988 +++ linux-2.6.18.kgdb/arch/powerpc/mm/fault.c   2008-06-10 16:19:22.000000000 +0400
6989 @@ -28,6 +28,7 @@
6990  #include <linux/highmem.h>
6991  #include <linux/module.h>
6992  #include <linux/kprobes.h>
6993 +#include <linux/kgdb.h>
6994  
6995  #include <asm/page.h>
6996  #include <asm/pgtable.h>
6997 @@ -424,6 +425,13 @@ void bad_page_fault(struct pt_regs *regs
6998                 return;
6999         }
7000  
7001 +#ifdef CONFIG_KGDB
7002 +       if (atomic_read(&debugger_active) && kgdb_may_fault)
7003 +               /* Restore our previous state. */
7004 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
7005 +               /* Not reached. */
7006 +#endif
7007 +
7008         /* kernel has accessed a bad area */
7009  
7010         printk(KERN_ALERT "Unable to handle kernel paging request for ");
7011 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/powerpc/platforms/powermac/setup.c linux-2.6.18.kgdb/arch/powerpc/platforms/powermac/setup.c
7012 --- linux-2.6.18/arch/powerpc/platforms/powermac/setup.c        2006-09-20 07:42:06.000000000 +0400
7013 +++ linux-2.6.18.kgdb/arch/powerpc/platforms/powermac/setup.c   2008-06-10 16:19:22.000000000 +0400
7014 @@ -98,8 +98,6 @@ extern struct machdep_calls pmac_md;
7015  int sccdbg;
7016  #endif
7017  
7018 -extern void zs_kgdb_hook(int tty_num);
7019 -
7020  sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
7021  EXPORT_SYMBOL(sys_ctrler);
7022  
7023 @@ -319,10 +317,6 @@ static void __init pmac_setup_arch(void)
7024         l2cr_init();
7025  #endif /* CONFIG_PPC32 */
7026  
7027 -#ifdef CONFIG_KGDB
7028 -       zs_kgdb_hook(0);
7029 -#endif
7030 -
7031         find_via_cuda();
7032         find_via_pmu();
7033         smu_init();
7034 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/Kconfig.debug linux-2.6.18.kgdb/arch/ppc/Kconfig.debug
7035 --- linux-2.6.18/arch/ppc/Kconfig.debug 2006-09-20 07:42:06.000000000 +0400
7036 +++ linux-2.6.18.kgdb/arch/ppc/Kconfig.debug    2008-06-10 16:19:22.000000000 +0400
7037 @@ -2,42 +2,6 @@ menu "Kernel hacking"
7038  
7039  source "lib/Kconfig.debug"
7040  
7041 -config KGDB
7042 -       bool "Include kgdb kernel debugger"
7043 -       depends on DEBUG_KERNEL && (BROKEN || PPC_GEN550 || 4xx)
7044 -       select DEBUG_INFO
7045 -       help
7046 -         Include in-kernel hooks for kgdb, the Linux kernel source level
7047 -         debugger.  See <http://kgdb.sourceforge.net/> for more information.
7048 -         Unless you are intending to debug the kernel, say N here.
7049 -
7050 -choice
7051 -       prompt "Serial Port"
7052 -       depends on KGDB
7053 -       default KGDB_TTYS1
7054 -
7055 -config KGDB_TTYS0
7056 -       bool "ttyS0"
7057 -
7058 -config KGDB_TTYS1
7059 -       bool "ttyS1"
7060 -
7061 -config KGDB_TTYS2
7062 -       bool "ttyS2"
7063 -
7064 -config KGDB_TTYS3
7065 -       bool "ttyS3"
7066 -
7067 -endchoice
7068 -
7069 -config KGDB_CONSOLE
7070 -       bool "Enable serial console thru kgdb port"
7071 -       depends on KGDB && 8xx || CPM2
7072 -       help
7073 -         If you enable this, all serial console messages will be sent
7074 -         over the gdb stub.
7075 -         If unsure, say N.
7076 -
7077  config XMON
7078         bool "Include xmon kernel debugger"
7079         depends on DEBUG_KERNEL
7080 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/kernel/kgdb.c linux-2.6.18.kgdb/arch/ppc/kernel/kgdb.c
7081 --- linux-2.6.18/arch/ppc/kernel/kgdb.c 1970-01-01 03:00:00.000000000 +0300
7082 +++ linux-2.6.18.kgdb/arch/ppc/kernel/kgdb.c    2008-06-10 16:20:19.000000000 +0400
7083 @@ -0,0 +1,350 @@
7084 +/*
7085 + * arch/ppc/kernel/kgdb.c
7086 + *
7087 + * PowerPC backend to the KGDB stub.
7088 + *
7089 + * Maintainer: Tom Rini <trini@kernel.crashing.org>
7090 + *
7091 + * 1998 (c) Michael AK Tesch (tesch@cs.wisc.edu)
7092 + * Copyright (C) 2003 Timesys Corporation.
7093 + * 2004 (c) MontaVista Software, Inc.
7094 + *
7095 + * This file is licensed under the terms of the GNU General Public License
7096 + * version 2. This program as licensed "as is" without any warranty of any
7097 + * kind, whether express or implied.
7098 + */
7099 +
7100 +#include <linux/config.h>
7101 +#include <linux/kernel.h>
7102 +#include <linux/init.h>
7103 +#include <linux/kgdb.h>
7104 +#include <linux/smp.h>
7105 +#include <linux/signal.h>
7106 +#include <linux/ptrace.h>
7107 +#include <asm/current.h>
7108 +#include <asm/ptrace.h>
7109 +#include <asm/processor.h>
7110 +#include <asm/machdep.h>
7111 +
7112 +/*
7113 + * This table contains the mapping between PowerPC hardware trap types, and
7114 + * signals, which are primarily what GDB understands.  GDB and the kernel
7115 + * don't always agree on values, so we use constants taken from gdb-6.2.
7116 + */
7117 +static struct hard_trap_info
7118 +{
7119 +       unsigned int tt;                /* Trap type code for powerpc */
7120 +       unsigned char signo;            /* Signal that we map this trap into */
7121 +} hard_trap_info[] = {
7122 +#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
7123 +       { 0x0100, 0x02 /* SIGINT */  },         /* critical input interrupt */
7124 +       { 0x0200, 0x0b /* SIGSEGV */ },         /* machine check */
7125 +       { 0x0300, 0x0b /* SIGSEGV */ },         /* data storage */
7126 +       { 0x0400, 0x0a /* SIGBUS */  },         /* instruction storage */
7127 +       { 0x0500, 0x02 /* SIGINT */  },         /* interrupt */
7128 +       { 0x0600, 0x0a /* SIGBUS */  },         /* alignment */
7129 +       { 0x0700, 0x04 /* SIGILL */  },         /* program */
7130 +       { 0x0800, 0x04 /* SIGILL */  },         /* reserved */
7131 +       { 0x0900, 0x04 /* SIGILL */  },         /* reserved */
7132 +       { 0x0a00, 0x04 /* SIGILL */  },         /* reserved */
7133 +       { 0x0b00, 0x04 /* SIGILL */  },         /* reserved */
7134 +       { 0x0c00, 0x14 /* SIGCHLD */ },         /* syscall */
7135 +       { 0x0d00, 0x04 /* SIGILL */  },         /* reserved */
7136 +       { 0x0e00, 0x04 /* SIGILL */  },         /* reserved */
7137 +       { 0x0f00, 0x04 /* SIGILL */  },         /* reserved */
7138 +       { 0x2002, 0x05 /* SIGTRAP */},          /* debug */
7139 +#else
7140 +       { 0x0200, 0x0b /* SIGSEGV */ },         /* machine check */
7141 +       { 0x0300, 0x0b /* SIGSEGV */ },         /* address error (store) */
7142 +       { 0x0400, 0x0a /* SIGBUS */ },          /* instruction bus error */
7143 +       { 0x0500, 0x02 /* SIGINT */ },          /* interrupt */
7144 +       { 0x0600, 0x0a /* SIGBUS */ },          /* alingment */
7145 +       { 0x0700, 0x05 /* SIGTRAP */ },         /* breakpoint trap */
7146 +       { 0x0800, 0x08 /* SIGFPE */},           /* fpu unavail */
7147 +       { 0x0900, 0x0e /* SIGALRM */ },         /* decrementer */
7148 +       { 0x0a00, 0x04 /* SIGILL */ },          /* reserved */
7149 +       { 0x0b00, 0x04 /* SIGILL */ },          /* reserved */
7150 +       { 0x0c00, 0x14 /* SIGCHLD */ },         /* syscall */
7151 +       { 0x0d00, 0x05 /* SIGTRAP */ },         /* single-step/watch */
7152 +       { 0x0e00, 0x08 /* SIGFPE */ },          /* fp assist */
7153 +#endif
7154 +       { 0x0000, 0x000 }                       /* Must be last */
7155 +};
7156 +
7157 +extern atomic_t cpu_doing_single_step;
7158 +
7159 +static int computeSignal(unsigned int tt)
7160 +{
7161 +       struct hard_trap_info *ht;
7162 +
7163 +       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
7164 +               if (ht->tt == tt)
7165 +                       return ht->signo;
7166 +
7167 +       return SIGHUP;          /* default for things we don't know about */
7168 +}
7169 +
7170 +/* KGDB functions to use existing PowerPC hooks. */
7171 +static void kgdb_debugger(struct pt_regs *regs)
7172 +{
7173 +       kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
7174 +}
7175 +
7176 +static int kgdb_breakpoint(struct pt_regs *regs)
7177 +{
7178 +       if (user_mode(regs))
7179 +               return 0;
7180 +
7181 +       kgdb_handle_exception(0, SIGTRAP, 0, regs);
7182 +
7183 +       if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
7184 +               regs->nip += 4;
7185 +
7186 +       return 1;
7187 +}
7188 +
7189 +static int kgdb_singlestep(struct pt_regs *regs)
7190 +{
7191 +       struct thread_info *thread_info, *exception_thread_info;
7192 +
7193 +       if (user_mode(regs))
7194 +               return 0;
7195 +       /*
7196 +       * On Book E and perhaps other processsors, singlestep is handled on
7197 +       * the critical exception stack.  This causes current_thread_info()
7198 +       * to fail, since it it locates the thread_info by masking off
7199 +       * the low bits of the current stack pointer.  We work around
7200 +       * this issue by copying the thread_info from the kernel stack
7201 +       * before calling kgdb_handle_exception, and copying it back
7202 +       * afterwards.  On most processors the copy is avoided since
7203 +       * exception_thread_info == thread_info.
7204 +       */
7205 +       thread_info = (struct thread_info *)(regs->gpr[1] & ~(THREAD_SIZE-1));
7206 +       exception_thread_info = current_thread_info();
7207 +
7208 +       if (thread_info != exception_thread_info)
7209 +               memcpy(exception_thread_info, thread_info, sizeof *thread_info);
7210 +
7211 +       kgdb_handle_exception(0, SIGTRAP, 0, regs);
7212 +
7213 +       if (thread_info != exception_thread_info)
7214 +               memcpy(thread_info, exception_thread_info, sizeof *thread_info);
7215 +
7216 +       return 1;
7217 +}
7218 +
7219 +int kgdb_iabr_match(struct pt_regs *regs)
7220 +{
7221 +       if (user_mode(regs))
7222 +               return 0;
7223 +
7224 +       kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
7225 +       return 1;
7226 +}
7227 +
7228 +int kgdb_dabr_match(struct pt_regs *regs)
7229 +{
7230 +       if (user_mode(regs))
7231 +               return 0;
7232 +
7233 +       kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
7234 +       return 1;
7235 +}
7236 +
7237 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
7238 +{
7239 +       int reg;
7240 +       unsigned long *ptr = gdb_regs;
7241 +
7242 +       memset(gdb_regs, 0, MAXREG * 4);
7243 +
7244 +       for (reg = 0; reg < 32; reg++)
7245 +               *(ptr++) = regs->gpr[reg];
7246 +
7247 +#ifndef CONFIG_E500
7248 +       for (reg = 0; reg < 64; reg++)
7249 +               *(ptr++) = 0;
7250 +#else
7251 +       for (reg = 0; reg < 32; reg++)
7252 +               *(ptr++) = current->thread.evr[reg];
7253 +#endif
7254 +
7255 +       *(ptr++) = regs->nip;
7256 +       *(ptr++) = regs->msr;
7257 +       *(ptr++) = regs->ccr;
7258 +       *(ptr++) = regs->link;
7259 +       *(ptr++) = regs->ctr;
7260 +       *(ptr++) = regs->xer;
7261 +
7262 +#ifdef CONFIG_SPE
7263 +       /* u64 acc */
7264 +       *(ptr++) = (current->thread.acc >> 32);
7265 +       *(ptr++) = (current->thread.acc & 0xffffffff);
7266 +       *(ptr++) = current->thread.spefscr;
7267 +#endif
7268 +}
7269 +
7270 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
7271 +{
7272 +       struct pt_regs *regs = (struct pt_regs *)(p->thread.ksp +
7273 +                                                 STACK_FRAME_OVERHEAD);
7274 +       int reg;
7275 +       unsigned long *ptr = gdb_regs;
7276 +
7277 +       memset(gdb_regs, 0, MAXREG * 4);
7278 +
7279 +       /* Regs GPR0-2 */
7280 +       for (reg = 0; reg < 3; reg++)
7281 +               *(ptr++) = regs->gpr[reg];
7282 +
7283 +       /* Regs GPR3-13 are not saved */
7284 +       for (reg = 3; reg < 14; reg++)
7285 +               *(ptr++) = 0;
7286 +
7287 +       /* Regs GPR14-31 */
7288 +       for (reg = 14; reg < 32; reg++)
7289 +               *(ptr++) = regs->gpr[reg];
7290 +
7291 +#ifndef CONFIG_E500
7292 +       for (reg = 0; reg < 64; reg++)
7293 +               *(ptr++) = 0;
7294 +#else
7295 +       for (reg = 0; reg < 32; reg++)
7296 +               *(ptr++) = current->thread.evr[reg];
7297 +#endif
7298 +
7299 +       *(ptr++) = regs->nip;
7300 +       *(ptr++) = regs->msr;
7301 +       *(ptr++) = regs->ccr;
7302 +       *(ptr++) = regs->link;
7303 +       *(ptr++) = regs->ctr;
7304 +       *(ptr++) = regs->xer;
7305 +
7306 +#ifdef CONFIG_SPE
7307 +       /* u64 acc */
7308 +       *(ptr++) = (current->thread.acc >> 32);
7309 +       *(ptr++) = (current->thread.acc & 0xffffffff);
7310 +       *(ptr++) = current->thread.spefscr;
7311 +#endif
7312 +}
7313 +
7314 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
7315 +{
7316 +       int reg;
7317 +       unsigned long *ptr = gdb_regs;
7318 +#ifdef CONFIG_SPE
7319 +       union {
7320 +               u32 v32[2];
7321 +               u64 v64;
7322 +       } u;
7323 +#endif
7324 +
7325 +       for (reg = 0; reg < 32; reg++)
7326 +               regs->gpr[reg] = *(ptr++);
7327 +
7328 +#ifndef CONFIG_E500
7329 +       for (reg = 0; reg < 64; reg++)
7330 +               ptr++;
7331 +#else
7332 +       for (reg = 0; reg < 32; reg++)
7333 +               current->thread.evr[reg] = *(ptr++);
7334 +#endif
7335 +
7336 +       regs->nip = *(ptr++);
7337 +       regs->msr = *(ptr++);
7338 +       regs->ccr = *(ptr++);
7339 +       regs->link = *(ptr++);
7340 +       regs->ctr = *(ptr++);
7341 +       regs->xer = *(ptr++);
7342 +
7343 +#ifdef CONFIG_SPE
7344 +       /* u64 acc */
7345 +       u.v32[0] = *(ptr++);
7346 +       u.v32[1] = *(ptr++);
7347 +       current->thread.acc = u.v64;
7348 +       current->thread.spefscr = *(ptr++);
7349 +#endif
7350 +}
7351 +
7352 +/*
7353 + * Save/restore state in case a memory access causes a fault.
7354 + */
7355 +int kgdb_fault_setjmp(unsigned long *curr_context)
7356 +{
7357 +       __asm__ __volatile__("mflr 0; stw 0,0(%0);"
7358 +                            "stw 1,4(%0); stw 2,8(%0);"
7359 +                            "mfcr 0; stw 0,12(%0);"
7360 +                            "stmw 13,16(%0)"::"r"(curr_context));
7361 +       return 0;
7362 +}
7363 +
7364 +void kgdb_fault_longjmp(unsigned long *curr_context)
7365 +{
7366 +       __asm__ __volatile__("lmw 13,16(%0);"
7367 +                            "lwz 0,12(%0); mtcrf 0x38,0;"
7368 +                            "lwz 0,0(%0); lwz 1,4(%0); lwz 2,8(%0);"
7369 +                            "mtlr 0; mr 3,1"::"r"(curr_context));
7370 +}
7371 +
7372 +/*
7373 + * This function does PoerPC specific procesing for interfacing to gdb.
7374 + */
7375 +int kgdb_arch_handle_exception(int vector, int signo, int err_code,
7376 +                              char *remcom_in_buffer, char *remcom_out_buffer,
7377 +                              struct pt_regs *linux_regs)
7378 +{
7379 +       char *ptr = &remcom_in_buffer[1];
7380 +       unsigned long addr;
7381 +
7382 +       switch (remcom_in_buffer[0])
7383 +               {
7384 +               /*
7385 +                * sAA..AA   Step one instruction from AA..AA
7386 +                * This will return an error to gdb ..
7387 +                */
7388 +               case 's':
7389 +               case 'c':
7390 +                       /* handle the optional parameter */
7391 +                       if (kgdb_hex2long (&ptr, &addr))
7392 +                               linux_regs->nip = addr;
7393 +
7394 +                       atomic_set(&cpu_doing_single_step, -1);
7395 +                       /* set the trace bit if we're stepping */
7396 +                       if (remcom_in_buffer[0] == 's') {
7397 +#if defined (CONFIG_40x) || defined(CONFIG_BOOKE)
7398 +                               mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) |
7399 +                                               DBCR0_IC | DBCR0_IDM);
7400 +                               linux_regs->msr |= MSR_DE;
7401 +#else
7402 +                               linux_regs->msr |= MSR_SE;
7403 +#endif
7404 +                               debugger_step = 1;
7405 +                               if (kgdb_contthread)
7406 +                                       atomic_set(&cpu_doing_single_step,
7407 +                                                       smp_processor_id());
7408 +                       }
7409 +                       return 0;
7410 +       }
7411 +
7412 +       return -1;
7413 +}
7414 +
7415 +/*
7416 + * Global data
7417 + */
7418 +struct kgdb_arch arch_kgdb_ops = {
7419 +       .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
7420 +};
7421 +
7422 +int kgdb_arch_init(void)
7423 +{
7424 +       debugger = kgdb_debugger;
7425 +       debugger_bpt = kgdb_breakpoint;
7426 +       debugger_sstep = kgdb_singlestep;
7427 +       debugger_iabr_match = kgdb_iabr_match;
7428 +       debugger_dabr_match = kgdb_dabr_match;
7429 +
7430 +       return 0;
7431 +}
7432 +
7433 +arch_initcall(kgdb_arch_init);
7434 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/kernel/ppc-stub.c linux-2.6.18.kgdb/arch/ppc/kernel/ppc-stub.c
7435 --- linux-2.6.18/arch/ppc/kernel/ppc-stub.c     2006-09-20 07:42:06.000000000 +0400
7436 +++ linux-2.6.18.kgdb/arch/ppc/kernel/ppc-stub.c        1970-01-01 03:00:00.000000000 +0300
7437 @@ -1,866 +0,0 @@
7438 -/*
7439 - * ppc-stub.c:  KGDB support for the Linux kernel.
7440 - *
7441 - * adapted from arch/sparc/kernel/sparc-stub.c for the PowerPC
7442 - * some stuff borrowed from Paul Mackerras' xmon
7443 - * Copyright (C) 1998 Michael AK Tesch (tesch@cs.wisc.edu)
7444 - *
7445 - * Modifications to run under Linux
7446 - * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
7447 - *
7448 - * This file originally came from the gdb sources, and the
7449 - * copyright notices have been retained below.
7450 - */
7451 -
7452 -/****************************************************************************
7453 -
7454 -               THIS SOFTWARE IS NOT COPYRIGHTED
7455 -
7456 -   HP offers the following for use in the public domain.  HP makes no
7457 -   warranty with regard to the software or its performance and the
7458 -   user accepts the software "AS IS" with all faults.
7459 -
7460 -   HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
7461 -   TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
7462 -   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
7463 -
7464 -****************************************************************************/
7465 -
7466 -/****************************************************************************
7467 - *  Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $
7468 - *
7469 - *  Module name: remcom.c $
7470 - *  Revision: 1.34 $
7471 - *  Date: 91/03/09 12:29:49 $
7472 - *  Contributor:     Lake Stevens Instrument Division$
7473 - *
7474 - *  Description:     low level support for gdb debugger. $
7475 - *
7476 - *  Considerations:  only works on target hardware $
7477 - *
7478 - *  Written by:      Glenn Engel $
7479 - *  ModuleState:     Experimental $
7480 - *
7481 - *  NOTES:           See Below $
7482 - *
7483 - *  Modified for SPARC by Stu Grossman, Cygnus Support.
7484 - *
7485 - *  This code has been extensively tested on the Fujitsu SPARClite demo board.
7486 - *
7487 - *  To enable debugger support, two things need to happen.  One, a
7488 - *  call to set_debug_traps() is necessary in order to allow any breakpoints
7489 - *  or error conditions to be properly intercepted and reported to gdb.
7490 - *  Two, a breakpoint needs to be generated to begin communication.  This
7491 - *  is most easily accomplished by a call to breakpoint().  Breakpoint()
7492 - *  simulates a breakpoint by executing a trap #1.
7493 - *
7494 - *************
7495 - *
7496 - *    The following gdb commands are supported:
7497 - *
7498 - * command          function                     Return value
7499 - *
7500 - *    g             return the value of the CPU registers  hex data or ENN
7501 - *    G             set the value of the CPU registers     OK or ENN
7502 - *    qOffsets      Get section offsets.  Reply is Text=xxx;Data=yyy;Bss=zzz
7503 - *
7504 - *    mAA..AA,LLLL  Read LLLL bytes at address AA..AA      hex data or ENN
7505 - *    MAA..AA,LLLL: Write LLLL bytes at address AA.AA      OK or ENN
7506 - *
7507 - *    c             Resume at current address              SNN   ( signal NN)
7508 - *    cAA..AA       Continue at address AA..AA             SNN
7509 - *
7510 - *    s             Step one instruction                   SNN
7511 - *    sAA..AA       Step one instruction from AA..AA       SNN
7512 - *
7513 - *    k             kill
7514 - *
7515 - *    ?             What was the last sigval ?             SNN   (signal NN)
7516 - *
7517 - *    bBB..BB      Set baud rate to BB..BB                OK or BNN, then sets
7518 - *                                                        baud rate
7519 - *
7520 - * All commands and responses are sent with a packet which includes a
7521 - * checksum.  A packet consists of
7522 - *
7523 - * $<packet info>#<checksum>.
7524 - *
7525 - * where
7526 - * <packet info> :: <characters representing the command or response>
7527 - * <checksum>    :: <two hex digits computed as modulo 256 sum of <packetinfo>>
7528 - *
7529 - * When a packet is received, it is first acknowledged with either '+' or '-'.
7530 - * '+' indicates a successful transfer.  '-' indicates a failed transfer.
7531 - *
7532 - * Example:
7533 - *
7534 - * Host:                  Reply:
7535 - * $m0,10#2a               +$00010203040506070809101112131415#42
7536 - *
7537 - ****************************************************************************/
7538 -
7539 -#include <linux/kernel.h>
7540 -#include <linux/string.h>
7541 -#include <linux/mm.h>
7542 -#include <linux/smp.h>
7543 -#include <linux/smp_lock.h>
7544 -#include <linux/init.h>
7545 -#include <linux/sysrq.h>
7546 -
7547 -#include <asm/cacheflush.h>
7548 -#include <asm/system.h>
7549 -#include <asm/signal.h>
7550 -#include <asm/kgdb.h>
7551 -#include <asm/pgtable.h>
7552 -#include <asm/ptrace.h>
7553 -
7554 -void breakinst(void);
7555 -
7556 -/*
7557 - * BUFMAX defines the maximum number of characters in inbound/outbound buffers
7558 - * at least NUMREGBYTES*2 are needed for register packets
7559 - */
7560 -#define BUFMAX 2048
7561 -static char remcomInBuffer[BUFMAX];
7562 -static char remcomOutBuffer[BUFMAX];
7563 -
7564 -static int initialized;
7565 -static int kgdb_active;
7566 -static int kgdb_started;
7567 -static u_int fault_jmp_buf[100];
7568 -static int kdebug;
7569 -
7570 -
7571 -static const char hexchars[]="0123456789abcdef";
7572 -
7573 -/* Place where we save old trap entries for restoration - sparc*/
7574 -/* struct tt_entry kgdb_savettable[256]; */
7575 -/* typedef void (*trapfunc_t)(void); */
7576 -
7577 -static void kgdb_fault_handler(struct pt_regs *regs);
7578 -static int handle_exception (struct pt_regs *regs);
7579 -
7580 -#if 0
7581 -/* Install an exception handler for kgdb */
7582 -static void exceptionHandler(int tnum, unsigned int *tfunc)
7583 -{
7584 -       /* We are dorking with a live trap table, all irqs off */
7585 -}
7586 -#endif
7587 -
7588 -int
7589 -kgdb_setjmp(long *buf)
7590 -{
7591 -       asm ("mflr 0; stw 0,0(%0);"
7592 -            "stw 1,4(%0); stw 2,8(%0);"
7593 -            "mfcr 0; stw 0,12(%0);"
7594 -            "stmw 13,16(%0)"
7595 -            : : "r" (buf));
7596 -       /* XXX should save fp regs as well */
7597 -       return 0;
7598 -}
7599 -void
7600 -kgdb_longjmp(long *buf, int val)
7601 -{
7602 -       if (val == 0)
7603 -               val = 1;
7604 -       asm ("lmw 13,16(%0);"
7605 -            "lwz 0,12(%0); mtcrf 0x38,0;"
7606 -            "lwz 0,0(%0); lwz 1,4(%0); lwz 2,8(%0);"
7607 -            "mtlr 0; mr 3,%1"
7608 -            : : "r" (buf), "r" (val));
7609 -}
7610 -/* Convert ch from a hex digit to an int */
7611 -static int
7612 -hex(unsigned char ch)
7613 -{
7614 -       if (ch >= 'a' && ch <= 'f')
7615 -               return ch-'a'+10;
7616 -       if (ch >= '0' && ch <= '9')
7617 -               return ch-'0';
7618 -       if (ch >= 'A' && ch <= 'F')
7619 -               return ch-'A'+10;
7620 -       return -1;
7621 -}
7622 -
7623 -/* Convert the memory pointed to by mem into hex, placing result in buf.
7624 - * Return a pointer to the last char put in buf (null), in case of mem fault,
7625 - * return 0.
7626 - */
7627 -static unsigned char *
7628 -mem2hex(const char *mem, char *buf, int count)
7629 -{
7630 -       unsigned char ch;
7631 -       unsigned short tmp_s;
7632 -       unsigned long tmp_l;
7633 -
7634 -       if (kgdb_setjmp((long*)fault_jmp_buf) == 0) {
7635 -               debugger_fault_handler = kgdb_fault_handler;
7636 -
7637 -               /* Accessing 16 bit and 32 bit objects in a single
7638 -               ** load instruction is required to avoid bad side
7639 -               ** effects for some IO registers.
7640 -               */
7641 -
7642 -               if ((count == 2) && (((long)mem & 1) == 0)) {
7643 -                       tmp_s = *(unsigned short *)mem;
7644 -                       mem += 2;
7645 -                       *buf++ = hexchars[(tmp_s >> 12) & 0xf];
7646 -                       *buf++ = hexchars[(tmp_s >> 8) & 0xf];
7647 -                       *buf++ = hexchars[(tmp_s >> 4) & 0xf];
7648 -                       *buf++ = hexchars[tmp_s & 0xf];
7649 -
7650 -               } else if ((count == 4) && (((long)mem & 3) == 0)) {
7651 -                       tmp_l = *(unsigned int *)mem;
7652 -                       mem += 4;
7653 -                       *buf++ = hexchars[(tmp_l >> 28) & 0xf];
7654 -                       *buf++ = hexchars[(tmp_l >> 24) & 0xf];
7655 -                       *buf++ = hexchars[(tmp_l >> 20) & 0xf];
7656 -                       *buf++ = hexchars[(tmp_l >> 16) & 0xf];
7657 -                       *buf++ = hexchars[(tmp_l >> 12) & 0xf];
7658 -                       *buf++ = hexchars[(tmp_l >> 8) & 0xf];
7659 -                       *buf++ = hexchars[(tmp_l >> 4) & 0xf];
7660 -                       *buf++ = hexchars[tmp_l & 0xf];
7661 -
7662 -               } else {
7663 -                       while (count-- > 0) {
7664 -                               ch = *mem++;
7665 -                               *buf++ = hexchars[ch >> 4];
7666 -                               *buf++ = hexchars[ch & 0xf];
7667 -                       }
7668 -               }
7669 -
7670 -       } else {
7671 -               /* error condition */
7672 -       }
7673 -       debugger_fault_handler = NULL;
7674 -       *buf = 0;
7675 -       return buf;
7676 -}
7677 -
7678 -/* convert the hex array pointed to by buf into binary to be placed in mem
7679 - * return a pointer to the character AFTER the last byte written.
7680 -*/
7681 -static char *
7682 -hex2mem(char *buf, char *mem, int count)
7683 -{
7684 -       unsigned char ch;
7685 -       int i;
7686 -       char *orig_mem;
7687 -       unsigned short tmp_s;
7688 -       unsigned long tmp_l;
7689 -
7690 -       orig_mem = mem;
7691 -
7692 -       if (kgdb_setjmp((long*)fault_jmp_buf) == 0) {
7693 -               debugger_fault_handler = kgdb_fault_handler;
7694 -
7695 -               /* Accessing 16 bit and 32 bit objects in a single
7696 -               ** store instruction is required to avoid bad side
7697 -               ** effects for some IO registers.
7698 -               */
7699 -
7700 -               if ((count == 2) && (((long)mem & 1) == 0)) {
7701 -                       tmp_s = hex(*buf++) << 12;
7702 -                       tmp_s |= hex(*buf++) << 8;
7703 -                       tmp_s |= hex(*buf++) << 4;
7704 -                       tmp_s |= hex(*buf++);
7705 -
7706 -                       *(unsigned short *)mem = tmp_s;
7707 -                       mem += 2;
7708 -
7709 -               } else if ((count == 4) && (((long)mem & 3) == 0)) {
7710 -                       tmp_l = hex(*buf++) << 28;
7711 -                       tmp_l |= hex(*buf++) << 24;
7712 -                       tmp_l |= hex(*buf++) << 20;
7713 -                       tmp_l |= hex(*buf++) << 16;
7714 -                       tmp_l |= hex(*buf++) << 12;
7715 -                       tmp_l |= hex(*buf++) << 8;
7716 -                       tmp_l |= hex(*buf++) << 4;
7717 -                       tmp_l |= hex(*buf++);
7718 -
7719 -                       *(unsigned long *)mem = tmp_l;
7720 -                       mem += 4;
7721 -
7722 -               } else {
7723 -                       for (i=0; i<count; i++) {
7724 -                               ch = hex(*buf++) << 4;
7725 -                               ch |= hex(*buf++);
7726 -                               *mem++ = ch;
7727 -                       }
7728 -               }
7729 -
7730 -
7731 -               /*
7732 -               ** Flush the data cache, invalidate the instruction cache.
7733 -               */
7734 -               flush_icache_range((int)orig_mem, (int)orig_mem + count - 1);
7735 -
7736 -       } else {
7737 -               /* error condition */
7738 -       }
7739 -       debugger_fault_handler = NULL;
7740 -       return mem;
7741 -}
7742 -
7743 -/*
7744 - * While we find nice hex chars, build an int.
7745 - * Return number of chars processed.
7746 - */
7747 -static int
7748 -hexToInt(char **ptr, int *intValue)
7749 -{
7750 -       int numChars = 0;
7751 -       int hexValue;
7752 -
7753 -       *intValue = 0;
7754 -
7755 -       if (kgdb_setjmp((long*)fault_jmp_buf) == 0) {
7756 -               debugger_fault_handler = kgdb_fault_handler;
7757 -               while (**ptr) {
7758 -                       hexValue = hex(**ptr);
7759 -                       if (hexValue < 0)
7760 -                               break;
7761 -
7762 -                       *intValue = (*intValue << 4) | hexValue;
7763 -                       numChars ++;
7764 -
7765 -                       (*ptr)++;
7766 -               }
7767 -       } else {
7768 -               /* error condition */
7769 -       }
7770 -       debugger_fault_handler = NULL;
7771 -
7772 -       return (numChars);
7773 -}
7774 -
7775 -/* scan for the sequence $<data>#<checksum> */
7776 -static void
7777 -getpacket(char *buffer)
7778 -{
7779 -       unsigned char checksum;
7780 -       unsigned char xmitcsum;
7781 -       int i;
7782 -       int count;
7783 -       unsigned char ch;
7784 -
7785 -       do {
7786 -               /* wait around for the start character, ignore all other
7787 -                * characters */
7788 -               while ((ch = (getDebugChar() & 0x7f)) != '$') ;
7789 -
7790 -               checksum = 0;
7791 -               xmitcsum = -1;
7792 -
7793 -               count = 0;
7794 -
7795 -               /* now, read until a # or end of buffer is found */
7796 -               while (count < BUFMAX) {
7797 -                       ch = getDebugChar() & 0x7f;
7798 -                       if (ch == '#')
7799 -                               break;
7800 -                       checksum = checksum + ch;
7801 -                       buffer[count] = ch;
7802 -                       count = count + 1;
7803 -               }
7804 -
7805 -               if (count >= BUFMAX)
7806 -                       continue;
7807 -
7808 -               buffer[count] = 0;
7809 -
7810 -               if (ch == '#') {
7811 -                       xmitcsum = hex(getDebugChar() & 0x7f) << 4;
7812 -                       xmitcsum |= hex(getDebugChar() & 0x7f);
7813 -                       if (checksum != xmitcsum)
7814 -                               putDebugChar('-');      /* failed checksum */
7815 -                       else {
7816 -                               putDebugChar('+'); /* successful transfer */
7817 -                               /* if a sequence char is present, reply the ID */
7818 -                               if (buffer[2] == ':') {
7819 -                                       putDebugChar(buffer[0]);
7820 -                                       putDebugChar(buffer[1]);
7821 -                                       /* remove sequence chars from buffer */
7822 -                                       count = strlen(buffer);
7823 -                                       for (i=3; i <= count; i++)
7824 -                                               buffer[i-3] = buffer[i];
7825 -                               }
7826 -                       }
7827 -               }
7828 -       } while (checksum != xmitcsum);
7829 -}
7830 -
7831 -/* send the packet in buffer. */
7832 -static void putpacket(unsigned char *buffer)
7833 -{
7834 -       unsigned char checksum;
7835 -       int count;
7836 -       unsigned char ch, recv;
7837 -
7838 -       /* $<packet info>#<checksum>. */
7839 -       do {
7840 -               putDebugChar('$');
7841 -               checksum = 0;
7842 -               count = 0;
7843 -
7844 -               while ((ch = buffer[count])) {
7845 -                       putDebugChar(ch);
7846 -                       checksum += ch;
7847 -                       count += 1;
7848 -               }
7849 -
7850 -               putDebugChar('#');
7851 -               putDebugChar(hexchars[checksum >> 4]);
7852 -               putDebugChar(hexchars[checksum & 0xf]);
7853 -               recv = getDebugChar();
7854 -       } while ((recv & 0x7f) != '+');
7855 -}
7856 -
7857 -static void kgdb_flush_cache_all(void)
7858 -{
7859 -       flush_instruction_cache();
7860 -}
7861 -
7862 -/* Set up exception handlers for tracing and breakpoints
7863 - * [could be called kgdb_init()]
7864 - */
7865 -void set_debug_traps(void)
7866 -{
7867 -#if 0
7868 -       unsigned char c;
7869 -
7870 -       save_and_cli(flags);
7871 -
7872 -       /* In case GDB is started before us, ack any packets (presumably
7873 -        * "$?#xx") sitting there.
7874 -        *
7875 -        * I've found this code causes more problems than it solves,
7876 -        * so that's why it's commented out.  GDB seems to work fine
7877 -        * now starting either before or after the kernel   -bwb
7878 -        */
7879 -
7880 -       while((c = getDebugChar()) != '$');
7881 -       while((c = getDebugChar()) != '#');
7882 -       c = getDebugChar(); /* eat first csum byte */
7883 -       c = getDebugChar(); /* eat second csum byte */
7884 -       putDebugChar('+'); /* ack it */
7885 -#endif
7886 -       debugger = kgdb;
7887 -       debugger_bpt = kgdb_bpt;
7888 -       debugger_sstep = kgdb_sstep;
7889 -       debugger_iabr_match = kgdb_iabr_match;
7890 -       debugger_dabr_match = kgdb_dabr_match;
7891 -
7892 -       initialized = 1;
7893 -}
7894 -
7895 -static void kgdb_fault_handler(struct pt_regs *regs)
7896 -{
7897 -       kgdb_longjmp((long*)fault_jmp_buf, 1);
7898 -}
7899 -
7900 -int kgdb_bpt(struct pt_regs *regs)
7901 -{
7902 -       return handle_exception(regs);
7903 -}
7904 -
7905 -int kgdb_sstep(struct pt_regs *regs)
7906 -{
7907 -       return handle_exception(regs);
7908 -}
7909 -
7910 -void kgdb(struct pt_regs *regs)
7911 -{
7912 -       handle_exception(regs);
7913 -}
7914 -
7915 -int kgdb_iabr_match(struct pt_regs *regs)
7916 -{
7917 -       printk(KERN_ERR "kgdb doesn't support iabr, what?!?\n");
7918 -       return handle_exception(regs);
7919 -}
7920 -
7921 -int kgdb_dabr_match(struct pt_regs *regs)
7922 -{
7923 -       printk(KERN_ERR "kgdb doesn't support dabr, what?!?\n");
7924 -       return handle_exception(regs);
7925 -}
7926 -
7927 -/* Convert the hardware trap type code to a unix signal number. */
7928 -/*
7929 - * This table contains the mapping between PowerPC hardware trap types, and
7930 - * signals, which are primarily what GDB understands.
7931 - */
7932 -static struct hard_trap_info
7933 -{
7934 -       unsigned int tt;                /* Trap type code for powerpc */
7935 -       unsigned char signo;            /* Signal that we map this trap into */
7936 -} hard_trap_info[] = {
7937 -#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
7938 -       { 0x100, SIGINT  },             /* critical input interrupt */
7939 -       { 0x200, SIGSEGV },             /* machine check */
7940 -       { 0x300, SIGSEGV },             /* data storage */
7941 -       { 0x400, SIGBUS  },             /* instruction storage */
7942 -       { 0x500, SIGINT  },             /* interrupt */
7943 -       { 0x600, SIGBUS  },             /* alignment */
7944 -       { 0x700, SIGILL  },             /* program */
7945 -       { 0x800, SIGILL  },             /* reserved */
7946 -       { 0x900, SIGILL  },             /* reserved */
7947 -       { 0xa00, SIGILL  },             /* reserved */
7948 -       { 0xb00, SIGILL  },             /* reserved */
7949 -       { 0xc00, SIGCHLD },             /* syscall */
7950 -       { 0xd00, SIGILL  },             /* reserved */
7951 -       { 0xe00, SIGILL  },             /* reserved */
7952 -       { 0xf00, SIGILL  },             /* reserved */
7953 -       /*
7954 -       ** 0x1000  PIT
7955 -       ** 0x1010  FIT
7956 -       ** 0x1020  watchdog
7957 -       ** 0x1100  data TLB miss
7958 -       ** 0x1200  instruction TLB miss
7959 -       */
7960 -       { 0x2002, SIGTRAP},             /* debug */
7961 -#else
7962 -       { 0x200, SIGSEGV },             /* machine check */
7963 -       { 0x300, SIGSEGV },             /* address error (store) */
7964 -       { 0x400, SIGBUS },              /* instruction bus error */
7965 -       { 0x500, SIGINT },              /* interrupt */
7966 -       { 0x600, SIGBUS },              /* alingment */
7967 -       { 0x700, SIGTRAP },             /* breakpoint trap */
7968 -       { 0x800, SIGFPE },              /* fpu unavail */
7969 -       { 0x900, SIGALRM },             /* decrementer */
7970 -       { 0xa00, SIGILL },              /* reserved */
7971 -       { 0xb00, SIGILL },              /* reserved */
7972 -       { 0xc00, SIGCHLD },             /* syscall */
7973 -       { 0xd00, SIGTRAP },             /* single-step/watch */
7974 -       { 0xe00, SIGFPE },              /* fp assist */
7975 -#endif
7976 -       { 0, 0}                         /* Must be last */
7977 -
7978 -};
7979 -
7980 -static int computeSignal(unsigned int tt)
7981 -{
7982 -       struct hard_trap_info *ht;
7983 -
7984 -       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
7985 -               if (ht->tt == tt)
7986 -                       return ht->signo;
7987 -
7988 -       return SIGHUP; /* default for things we don't know about */
7989 -}
7990 -
7991 -#define PC_REGNUM 64
7992 -#define SP_REGNUM 1
7993 -
7994 -/*
7995 - * This function does all command processing for interfacing to gdb.
7996 - */
7997 -static int
7998 -handle_exception (struct pt_regs *regs)
7999 -{
8000 -       int sigval;
8001 -       int addr;
8002 -       int length;
8003 -       char *ptr;
8004 -       unsigned int msr;
8005 -
8006 -       /* We don't handle user-mode breakpoints. */
8007 -       if (user_mode(regs))
8008 -               return 0;
8009 -
8010 -       if (debugger_fault_handler) {
8011 -               debugger_fault_handler(regs);
8012 -               panic("kgdb longjump failed!\n");
8013 -       }
8014 -       if (kgdb_active) {
8015 -               printk(KERN_ERR "interrupt while in kgdb, returning\n");
8016 -               return 0;
8017 -       }
8018 -
8019 -       kgdb_active = 1;
8020 -       kgdb_started = 1;
8021 -
8022 -#ifdef KGDB_DEBUG
8023 -       printk("kgdb: entering handle_exception; trap [0x%x]\n",
8024 -                       (unsigned int)regs->trap);
8025 -#endif
8026 -
8027 -       kgdb_interruptible(0);
8028 -       lock_kernel();
8029 -       msr = mfmsr();
8030 -       mtmsr(msr & ~MSR_EE);   /* disable interrupts */
8031 -
8032 -       if (regs->nip == (unsigned long)breakinst) {
8033 -               /* Skip over breakpoint trap insn */
8034 -               regs->nip += 4;
8035 -       }
8036 -
8037 -       /* reply to host that an exception has occurred */
8038 -       sigval = computeSignal(regs->trap);
8039 -       ptr = remcomOutBuffer;
8040 -
8041 -       *ptr++ = 'T';
8042 -       *ptr++ = hexchars[sigval >> 4];
8043 -       *ptr++ = hexchars[sigval & 0xf];
8044 -       *ptr++ = hexchars[PC_REGNUM >> 4];
8045 -       *ptr++ = hexchars[PC_REGNUM & 0xf];
8046 -       *ptr++ = ':';
8047 -       ptr = mem2hex((char *)&regs->nip, ptr, 4);
8048 -       *ptr++ = ';';
8049 -       *ptr++ = hexchars[SP_REGNUM >> 4];
8050 -       *ptr++ = hexchars[SP_REGNUM & 0xf];
8051 -       *ptr++ = ':';
8052 -       ptr = mem2hex(((char *)regs) + SP_REGNUM*4, ptr, 4);
8053 -       *ptr++ = ';';
8054 -       *ptr++ = 0;
8055 -
8056 -       putpacket(remcomOutBuffer);
8057 -       if (kdebug)
8058 -               printk("remcomOutBuffer: %s\n", remcomOutBuffer);
8059 -
8060 -       /* XXX We may want to add some features dealing with poking the
8061 -        * XXX page tables, ... (look at sparc-stub.c for more info)
8062 -        * XXX also required hacking to the gdb sources directly...
8063 -        */
8064 -
8065 -       while (1) {
8066 -               remcomOutBuffer[0] = 0;
8067 -
8068 -               getpacket(remcomInBuffer);
8069 -               switch (remcomInBuffer[0]) {
8070 -               case '?': /* report most recent signal */
8071 -                       remcomOutBuffer[0] = 'S';
8072 -                       remcomOutBuffer[1] = hexchars[sigval >> 4];
8073 -                       remcomOutBuffer[2] = hexchars[sigval & 0xf];
8074 -                       remcomOutBuffer[3] = 0;
8075 -                       break;
8076 -#if 0
8077 -               case 'q': /* this screws up gdb for some reason...*/
8078 -               {
8079 -                       extern long _start, sdata, __bss_start;
8080 -
8081 -                       ptr = &remcomInBuffer[1];
8082 -                       if (strncmp(ptr, "Offsets", 7) != 0)
8083 -                               break;
8084 -
8085 -                       ptr = remcomOutBuffer;
8086 -                       sprintf(ptr, "Text=%8.8x;Data=%8.8x;Bss=%8.8x",
8087 -                               &_start, &sdata, &__bss_start);
8088 -                       break;
8089 -               }
8090 -#endif
8091 -               case 'd':
8092 -                       /* toggle debug flag */
8093 -                       kdebug ^= 1;
8094 -                       break;
8095 -
8096 -               case 'g':       /* return the value of the CPU registers.
8097 -                                * some of them are non-PowerPC names :(
8098 -                                * they are stored in gdb like:
8099 -                                * struct {
8100 -                                *     u32 gpr[32];
8101 -                                *     f64 fpr[32];
8102 -                                *     u32 pc, ps, cnd, lr; (ps=msr)
8103 -                                *     u32 cnt, xer, mq;
8104 -                                * }
8105 -                                */
8106 -               {
8107 -                       int i;
8108 -                       ptr = remcomOutBuffer;
8109 -                       /* General Purpose Regs */
8110 -                       ptr = mem2hex((char *)regs, ptr, 32 * 4);
8111 -                       /* Floating Point Regs - FIXME */
8112 -                       /*ptr = mem2hex((char *), ptr, 32 * 8);*/
8113 -                       for(i=0; i<(32*8*2); i++) { /* 2chars/byte */
8114 -                               ptr[i] = '0';
8115 -                       }
8116 -                       ptr += 32*8*2;
8117 -                       /* pc, msr, cr, lr, ctr, xer, (mq is unused) */
8118 -                       ptr = mem2hex((char *)&regs->nip, ptr, 4);
8119 -                       ptr = mem2hex((char *)&regs->msr, ptr, 4);
8120 -                       ptr = mem2hex((char *)&regs->ccr, ptr, 4);
8121 -                       ptr = mem2hex((char *)&regs->link, ptr, 4);
8122 -                       ptr = mem2hex((char *)&regs->ctr, ptr, 4);
8123 -                       ptr = mem2hex((char *)&regs->xer, ptr, 4);
8124 -               }
8125 -                       break;
8126 -
8127 -               case 'G': /* set the value of the CPU registers */
8128 -               {
8129 -                       ptr = &remcomInBuffer[1];
8130 -
8131 -                       /*
8132 -                        * If the stack pointer has moved, you should pray.
8133 -                        * (cause only god can help you).
8134 -                        */
8135 -
8136 -                       /* General Purpose Regs */
8137 -                       hex2mem(ptr, (char *)regs, 32 * 4);
8138 -
8139 -                       /* Floating Point Regs - FIXME?? */
8140 -                       /*ptr = hex2mem(ptr, ??, 32 * 8);*/
8141 -                       ptr += 32*8*2;
8142 -
8143 -                       /* pc, msr, cr, lr, ctr, xer, (mq is unused) */
8144 -                       ptr = hex2mem(ptr, (char *)&regs->nip, 4);
8145 -                       ptr = hex2mem(ptr, (char *)&regs->msr, 4);
8146 -                       ptr = hex2mem(ptr, (char *)&regs->ccr, 4);
8147 -                       ptr = hex2mem(ptr, (char *)&regs->link, 4);
8148 -                       ptr = hex2mem(ptr, (char *)&regs->ctr, 4);
8149 -                       ptr = hex2mem(ptr, (char *)&regs->xer, 4);
8150 -
8151 -                       strcpy(remcomOutBuffer,"OK");
8152 -               }
8153 -                       break;
8154 -               case 'H':
8155 -                       /* don't do anything, yet, just acknowledge */
8156 -                       hexToInt(&ptr, &addr);
8157 -                       strcpy(remcomOutBuffer,"OK");
8158 -                       break;
8159 -
8160 -               case 'm':       /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
8161 -                               /* Try to read %x,%x.  */
8162 -
8163 -                       ptr = &remcomInBuffer[1];
8164 -
8165 -                       if (hexToInt(&ptr, &addr) && *ptr++ == ','
8166 -                                       && hexToInt(&ptr, &length)) {
8167 -                               if (mem2hex((char *)addr, remcomOutBuffer,
8168 -                                                       length))
8169 -                                       break;
8170 -                               strcpy(remcomOutBuffer, "E03");
8171 -                       } else
8172 -                               strcpy(remcomOutBuffer, "E01");
8173 -                       break;
8174 -
8175 -               case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
8176 -                       /* Try to read '%x,%x:'.  */
8177 -
8178 -                       ptr = &remcomInBuffer[1];
8179 -
8180 -                       if (hexToInt(&ptr, &addr) && *ptr++ == ','
8181 -                                       && hexToInt(&ptr, &length)
8182 -                                       && *ptr++ == ':') {
8183 -                               if (hex2mem(ptr, (char *)addr, length))
8184 -                                       strcpy(remcomOutBuffer, "OK");
8185 -                               else
8186 -                                       strcpy(remcomOutBuffer, "E03");
8187 -                               flush_icache_range(addr, addr+length);
8188 -                       } else
8189 -                               strcpy(remcomOutBuffer, "E02");
8190 -                       break;
8191 -
8192 -
8193 -               case 'k': /* kill the program, actually just continue */
8194 -               case 'c': /* cAA..AA  Continue; address AA..AA optional */
8195 -                       /* try to read optional parameter, pc unchanged if no parm */
8196 -
8197 -                       ptr = &remcomInBuffer[1];
8198 -                       if (hexToInt(&ptr, &addr))
8199 -                               regs->nip = addr;
8200 -
8201 -/* Need to flush the instruction cache here, as we may have deposited a
8202 - * breakpoint, and the icache probably has no way of knowing that a data ref to
8203 - * some location may have changed something that is in the instruction cache.
8204 - */
8205 -                       kgdb_flush_cache_all();
8206 -                       mtmsr(msr);
8207 -
8208 -                       kgdb_interruptible(1);
8209 -                       unlock_kernel();
8210 -                       kgdb_active = 0;
8211 -                       if (kdebug) {
8212 -                               printk("remcomInBuffer: %s\n", remcomInBuffer);
8213 -                               printk("remcomOutBuffer: %s\n", remcomOutBuffer);
8214 -                       }
8215 -                       return 1;
8216 -
8217 -               case 's':
8218 -                       kgdb_flush_cache_all();
8219 -#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
8220 -                       mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | DBCR0_IC);
8221 -                       regs->msr |= MSR_DE;
8222 -#else
8223 -                       regs->msr |= MSR_SE;
8224 -#endif
8225 -                       unlock_kernel();
8226 -                       kgdb_active = 0;
8227 -                       if (kdebug) {
8228 -                               printk("remcomInBuffer: %s\n", remcomInBuffer);
8229 -                               printk("remcomOutBuffer: %s\n", remcomOutBuffer);
8230 -                       }
8231 -                       return 1;
8232 -
8233 -               case 'r':               /* Reset (if user process..exit ???)*/
8234 -                       panic("kgdb reset.");
8235 -                       break;
8236 -               }                       /* switch */
8237 -               if (remcomOutBuffer[0] && kdebug) {
8238 -                       printk("remcomInBuffer: %s\n", remcomInBuffer);
8239 -                       printk("remcomOutBuffer: %s\n", remcomOutBuffer);
8240 -               }
8241 -               /* reply to the request */
8242 -               putpacket(remcomOutBuffer);
8243 -       } /* while(1) */
8244 -}
8245 -
8246 -/* This function will generate a breakpoint exception.  It is used at the
8247 -   beginning of a program to sync up with a debugger and can be used
8248 -   otherwise as a quick means to stop program execution and "break" into
8249 -   the debugger. */
8250 -
8251 -void
8252 -breakpoint(void)
8253 -{
8254 -       if (!initialized) {
8255 -               printk("breakpoint() called b4 kgdb init\n");
8256 -               return;
8257 -       }
8258 -
8259 -       asm("   .globl breakinst        \n\
8260 -            breakinst: .long 0x7d821008");
8261 -}
8262 -
8263 -#ifdef CONFIG_KGDB_CONSOLE
8264 -/* Output string in GDB O-packet format if GDB has connected. If nothing
8265 -   output, returns 0 (caller must then handle output). */
8266 -int
8267 -kgdb_output_string (const char* s, unsigned int count)
8268 -{
8269 -       char buffer[512];
8270 -
8271 -       if (!kgdb_started)
8272 -               return 0;
8273 -
8274 -       count = (count <= (sizeof(buffer) / 2 - 2))
8275 -               ? count : (sizeof(buffer) / 2 - 2);
8276 -
8277 -       buffer[0] = 'O';
8278 -       mem2hex (s, &buffer[1], count);
8279 -       putpacket(buffer);
8280 -
8281 -       return 1;
8282 -}
8283 -#endif
8284 -
8285 -static void sysrq_handle_gdb(int key, struct pt_regs *pt_regs,
8286 -                            struct tty_struct *tty)
8287 -{
8288 -       printk("Entering GDB stub\n");
8289 -       breakpoint();
8290 -}
8291 -static struct sysrq_key_op sysrq_gdb_op = {
8292 -        .handler        = sysrq_handle_gdb,
8293 -        .help_msg       = "Gdb",
8294 -        .action_msg     = "GDB",
8295 -};
8296 -
8297 -static int gdb_register_sysrq(void)
8298 -{
8299 -       printk("Registering GDB sysrq handler\n");
8300 -       register_sysrq_key('g', &sysrq_gdb_op);
8301 -       return 0;
8302 -}
8303 -module_init(gdb_register_sysrq);
8304 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/kernel/setup.c linux-2.6.18.kgdb/arch/ppc/kernel/setup.c
8305 --- linux-2.6.18/arch/ppc/kernel/setup.c        2006-09-20 07:42:06.000000000 +0400
8306 +++ linux-2.6.18.kgdb/arch/ppc/kernel/setup.c   2008-06-10 16:19:22.000000000 +0400
8307 @@ -47,10 +47,6 @@
8308  #include <asm/ppc_sys.h>
8309  #endif
8310  
8311 -#if defined CONFIG_KGDB
8312 -#include <asm/kgdb.h>
8313 -#endif
8314 -
8315  extern void platform_init(unsigned long r3, unsigned long r4,
8316                 unsigned long r5, unsigned long r6, unsigned long r7);
8317  extern void identify_cpu(unsigned long offset, unsigned long cpu);
8318 @@ -504,18 +500,6 @@ void __init setup_arch(char **cmdline_p)
8319  #endif /* CONFIG_XMON */
8320         if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
8321  
8322 -#if defined(CONFIG_KGDB)
8323 -       if (ppc_md.kgdb_map_scc)
8324 -               ppc_md.kgdb_map_scc();
8325 -       set_debug_traps();
8326 -       if (strstr(cmd_line, "gdb")) {
8327 -               if (ppc_md.progress)
8328 -                       ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
8329 -               printk("kgdb breakpoint activated\n");
8330 -               breakpoint();
8331 -       }
8332 -#endif
8333 -
8334         /*
8335          * Set cache line size based on type of cpu as a default.
8336          * Systems with OF can look in the properties on the cpu node(s)
8337 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/mm/fault.c linux-2.6.18.kgdb/arch/ppc/mm/fault.c
8338 --- linux-2.6.18/arch/ppc/mm/fault.c    2006-09-20 07:42:06.000000000 +0400
8339 +++ linux-2.6.18.kgdb/arch/ppc/mm/fault.c       2008-06-10 16:19:22.000000000 +0400
8340 @@ -25,6 +25,7 @@
8341  #include <linux/interrupt.h>
8342  #include <linux/highmem.h>
8343  #include <linux/module.h>
8344 +#include <linux/kgdb.h>
8345  
8346  #include <asm/page.h>
8347  #include <asm/pgtable.h>
8348 @@ -329,6 +330,14 @@ bad_page_fault(struct pt_regs *regs, uns
8349                 return;
8350         }
8351  
8352 +#ifdef CONFIG_KGDB
8353 +       if (atomic_read(&debugger_active) && kgdb_may_fault) {
8354 +               /* Restore our previous state. */
8355 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
8356 +               /* Not reached. */
8357 +       }
8358 +#endif
8359 +
8360         /* kernel has accessed a bad area */
8361  #if defined(CONFIG_XMON) || defined(CONFIG_KGDB)
8362         if (debugger_kernel_faults)
8363 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/platforms/4xx/bubinga.c linux-2.6.18.kgdb/arch/ppc/platforms/4xx/bubinga.c
8364 --- linux-2.6.18/arch/ppc/platforms/4xx/bubinga.c       2006-09-20 07:42:06.000000000 +0400
8365 +++ linux-2.6.18.kgdb/arch/ppc/platforms/4xx/bubinga.c  2008-06-10 16:19:22.000000000 +0400
8366 @@ -4,7 +4,7 @@
8367   * Author: SAW (IBM), derived from walnut.c.
8368   *         Maintained by MontaVista Software <source@mvista.com>
8369   *
8370 - * 2003 (c) MontaVista Softare Inc.  This file is licensed under the
8371 + * 2003-2004 (c) MontaVista Softare Inc.  This file is licensed under the
8372   * terms of the GNU General Public License version 2. This program is
8373   * licensed "as is" without any warranty of any kind, whether express
8374   * or implied.
8375 @@ -100,17 +100,26 @@ bubinga_early_serial_map(void)
8376         port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
8377         port.line = 0;
8378  
8379 -       if (early_serial_setup(&port) != 0) {
8380 +#ifdef CONFIG_SERIAL_8250
8381 +       if (early_serial_setup(&port) != 0)
8382                 printk("Early serial init of port 0 failed\n");
8383 -       }
8384 +#endif
8385 +
8386 +#ifdef CONFIG_KGDB_8250
8387 +       kgdb8250_add_port(0, &port);
8388 +#endif
8389  
8390         port.membase = (void*)ACTING_UART1_IO_BASE;
8391         port.irq = ACTING_UART1_INT;
8392         port.line = 1;
8393  
8394 -       if (early_serial_setup(&port) != 0) {
8395 +#ifdef CONFIG_SERIAL_8250
8396 +       if (early_serial_setup(&port) != 0)
8397                 printk("Early serial init of port 1 failed\n");
8398 -       }
8399 +#endif
8400 +#ifdef CONFIG_KGDB_8250
8401 +       kgdb8250_add_port(1, &port);
8402 +#endif
8403  }
8404  
8405  void __init
8406 @@ -255,8 +264,4 @@ platform_init(unsigned long r3, unsigned
8407         ppc_md.nvram_read_val = todc_direct_read_val;
8408         ppc_md.nvram_write_val = todc_direct_write_val;
8409  #endif
8410 -#ifdef CONFIG_KGDB
8411 -       ppc_md.early_serial_map = bubinga_early_serial_map;
8412 -#endif
8413  }
8414 -
8415 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/platforms/4xx/ebony.c linux-2.6.18.kgdb/arch/ppc/platforms/4xx/ebony.c
8416 --- linux-2.6.18/arch/ppc/platforms/4xx/ebony.c 2006-09-20 07:42:06.000000000 +0400
8417 +++ linux-2.6.18.kgdb/arch/ppc/platforms/4xx/ebony.c    2008-06-10 16:19:22.000000000 +0400
8418 @@ -32,6 +32,7 @@
8419  #include <linux/tty.h>
8420  #include <linux/serial.h>
8421  #include <linux/serial_core.h>
8422 +#include <linux/kgdb.h>
8423  
8424  #include <asm/system.h>
8425  #include <asm/pgtable.h>
8426 @@ -226,14 +227,20 @@ ebony_early_serial_map(void)
8427         port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
8428         port.line = 0;
8429  
8430 -       if (early_serial_setup(&port) != 0) {
8431 +#ifdef CONFIG_SERIAL_8250
8432 +       if (early_serial_setup(&port) != 0)
8433                 printk("Early serial init of port 0 failed\n");
8434 -       }
8435 +#endif
8436  
8437 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8438 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8439         /* Configure debug serial access */
8440         gen550_init(0, &port);
8441 +#endif
8442 +#ifdef CONFIG_KGDB_8250
8443 +       kgdb8250_add_port(0, &port);
8444 +#endif
8445  
8446 +#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_8250)
8447         /* Purge TLB entry added in head_44x.S for early serial access */
8448         _tlbie(UART0_IO_BASE);
8449  #endif
8450 @@ -243,14 +250,18 @@ ebony_early_serial_map(void)
8451         port.uartclk = clocks.uart1;
8452         port.line = 1;
8453  
8454 -       if (early_serial_setup(&port) != 0) {
8455 +#ifdef CONFIG_SERIAL_8250
8456 +       if (early_serial_setup(&port) != 1)
8457                 printk("Early serial init of port 1 failed\n");
8458 -       }
8459 +#endif
8460  
8461 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8462 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8463         /* Configure debug serial access */
8464         gen550_init(1, &port);
8465  #endif
8466 +#ifdef CONFIG_KGDB_8250
8467 +       kgdb8250_add_port(1, &port);
8468 +#endif
8469  }
8470  
8471  static void __init
8472 @@ -327,8 +338,4 @@ void __init platform_init(unsigned long 
8473  
8474         ppc_md.nvram_read_val = todc_direct_read_val;
8475         ppc_md.nvram_write_val = todc_direct_write_val;
8476 -#ifdef CONFIG_KGDB
8477 -       ppc_md.early_serial_map = ebony_early_serial_map;
8478 -#endif
8479  }
8480 -
8481 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/platforms/4xx/ocotea.c linux-2.6.18.kgdb/arch/ppc/platforms/4xx/ocotea.c
8482 --- linux-2.6.18/arch/ppc/platforms/4xx/ocotea.c        2006-09-20 07:42:06.000000000 +0400
8483 +++ linux-2.6.18.kgdb/arch/ppc/platforms/4xx/ocotea.c   2008-06-10 16:19:22.000000000 +0400
8484 @@ -30,6 +30,7 @@
8485  #include <linux/tty.h>
8486  #include <linux/serial.h>
8487  #include <linux/serial_core.h>
8488 +#include <linux/kgdb.h>
8489  
8490  #include <asm/system.h>
8491  #include <asm/pgtable.h>
8492 @@ -249,14 +250,20 @@ ocotea_early_serial_map(void)
8493         port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
8494         port.line = 0;
8495  
8496 -       if (early_serial_setup(&port) != 0) {
8497 +#ifdef CONFIG_SERIAL_8250
8498 +       if (early_serial_setup(&port) != 0)
8499                 printk("Early serial init of port 0 failed\n");
8500 -       }
8501 +#endif
8502  
8503 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8504 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8505         /* Configure debug serial access */
8506         gen550_init(0, &port);
8507 +#endif
8508 +#ifdef CONFIG_KGDB_8250
8509 +       kgdb8250_add_port(0, &port);
8510 +#endif
8511  
8512 +#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_8250)
8513         /* Purge TLB entry added in head_44x.S for early serial access */
8514         _tlbie(UART0_IO_BASE);
8515  #endif
8516 @@ -266,14 +273,18 @@ ocotea_early_serial_map(void)
8517         port.uartclk = clocks.uart1;
8518         port.line = 1;
8519  
8520 -       if (early_serial_setup(&port) != 0) {
8521 +#ifdef CONFIG_SERIAL_8250
8522 +       if (early_serial_setup(&port) != 1)
8523                 printk("Early serial init of port 1 failed\n");
8524 -       }
8525 +#endif
8526  
8527 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8528 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8529         /* Configure debug serial access */
8530         gen550_init(1, &port);
8531  #endif
8532 +#ifdef CONFIG_KGDB_8250
8533 +       kgdb8250_add_port(1, &port);
8534 +#endif
8535  }
8536  
8537  static void __init
8538 @@ -343,8 +354,5 @@ void __init platform_init(unsigned long 
8539  
8540         ppc_md.nvram_read_val = todc_direct_read_val;
8541         ppc_md.nvram_write_val = todc_direct_write_val;
8542 -#ifdef CONFIG_KGDB
8543 -       ppc_md.early_serial_map = ocotea_early_serial_map;
8544 -#endif
8545         ppc_md.init = ocotea_init;
8546  }
8547 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/platforms/4xx/xilinx_ml300.c linux-2.6.18.kgdb/arch/ppc/platforms/4xx/xilinx_ml300.c
8548 --- linux-2.6.18/arch/ppc/platforms/4xx/xilinx_ml300.c  2006-09-20 07:42:06.000000000 +0400
8549 +++ linux-2.6.18.kgdb/arch/ppc/platforms/4xx/xilinx_ml300.c     2008-06-10 16:19:22.000000000 +0400
8550 @@ -41,9 +41,6 @@
8551   *      ppc4xx_map_io                          arch/ppc/syslib/ppc4xx_setup.c
8552   *  start_kernel                               init/main.c
8553   *    setup_arch                               arch/ppc/kernel/setup.c
8554 - * #if defined(CONFIG_KGDB)
8555 - *      *ppc_md.kgdb_map_scc() == gen550_kgdb_map_scc
8556 - * #endif
8557   *      *ppc_md.setup_arch == ml300_setup_arch this file
8558   *        ppc4xx_setup_arch                    arch/ppc/syslib/ppc4xx_setup.c
8559   *          ppc4xx_find_bridges                        arch/ppc/syslib/ppc405_pci.c
8560 @@ -117,7 +114,6 @@ ml300_early_serial_init(int num, struct 
8561  void __init
8562  ml300_early_serial_map(void)
8563  {
8564 -#ifdef CONFIG_SERIAL_8250
8565         struct plat_serial8250_port *pdata;
8566         int i = 0;
8567  
8568 @@ -129,7 +125,14 @@ ml300_early_serial_map(void)
8569                 pdata++;
8570                 i++;
8571         }
8572 -#endif /* CONFIG_SERIAL_8250 */
8573 +#ifdef CONFIG_SERIAL_8250
8574 +                if (early_serial_setup(&port) != 0)
8575 +                        printk("Early serial init of port %d failed\n", i);
8576 +#endif
8577 +
8578 +#ifdef CONFIG_KGDB_8250
8579 +       kgdb8250_add_port(i, &port)
8580 +#endif
8581  }
8582  
8583  void __init
8584 @@ -165,9 +168,4 @@ platform_init(unsigned long r3, unsigned
8585  #if defined(XPAR_POWER_0_POWERDOWN_BASEADDR)
8586         ppc_md.power_off = xilinx_power_off;
8587  #endif
8588 -
8589 -#ifdef CONFIG_KGDB
8590 -       ppc_md.early_serial_map = ml300_early_serial_map;
8591 -#endif
8592  }
8593 -
8594 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/platforms/85xx/sbc8560.c linux-2.6.18.kgdb/arch/ppc/platforms/85xx/sbc8560.c
8595 --- linux-2.6.18/arch/ppc/platforms/85xx/sbc8560.c      2006-09-20 07:42:06.000000000 +0400
8596 +++ linux-2.6.18.kgdb/arch/ppc/platforms/85xx/sbc8560.c 2008-06-10 16:19:22.000000000 +0400
8597 @@ -50,7 +50,6 @@
8598  #include <syslib/ppc85xx_common.h>
8599  #include <syslib/ppc85xx_setup.h>
8600  
8601 -#ifdef CONFIG_SERIAL_8250
8602  static void __init
8603  sbc8560_early_serial_map(void)
8604  {
8605 @@ -66,12 +65,16 @@ sbc8560_early_serial_map(void)
8606          uart_req.membase = ioremap(uart_req.mapbase, MPC85xx_UART0_SIZE);
8607         uart_req.type = PORT_16650;
8608  
8609 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8610 -        gen550_init(0, &uart_req);
8611 +#ifdef CONFIG_SERIAL_8250
8612 +       if (early_serial_setup(&uart_req) != 0)
8613 +               printk("Early serial init of port 0 failed\n");
8614 +#endif
8615 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8616 +       gen550_init(0, &uart_req);
8617 +#endif
8618 +#ifdef CONFIG_KGDB_8250
8619 +       kgdb8250_add_port(0, &uart_req);
8620  #endif
8621
8622 -        if (early_serial_setup(&uart_req) != 0)
8623 -                printk("Early serial init of port 0 failed\n");
8624   
8625          /* Assume early_serial_setup() doesn't modify uart_req */
8626         uart_req.line = 1;
8627 @@ -79,14 +82,17 @@ sbc8560_early_serial_map(void)
8628          uart_req.membase = ioremap(uart_req.mapbase, MPC85xx_UART1_SIZE);
8629         uart_req.irq = MPC85xx_IRQ_EXT10;
8630   
8631 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8632 -        gen550_init(1, &uart_req);
8633 +#ifdef CONFIG_SERIAL_8250
8634 +       if (early_serial_setup(&uart_req) != 0)
8635 +               printk("Early serial init of port 0 failed\n");
8636  #endif
8637
8638 -        if (early_serial_setup(&uart_req) != 0)
8639 -                printk("Early serial init of port 1 failed\n");
8640 -}
8641 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8642 +       gen550_init(0, &uart_req);
8643 +#endif
8644 +#ifdef CONFIG_KGDB_8250
8645 +       kgdb8250_add_port(0, &uart_req);
8646  #endif
8647 +}
8648  
8649  /* ************************************************************************
8650   *
8651 @@ -115,9 +121,7 @@ sbc8560_setup_arch(void)
8652         /* setup PCI host bridges */
8653         mpc85xx_setup_hose();
8654  #endif
8655 -#ifdef CONFIG_SERIAL_8250
8656         sbc8560_early_serial_map();
8657 -#endif
8658  #ifdef CONFIG_SERIAL_TEXT_DEBUG
8659         /* Invalidate the entry we stole earlier the serial ports
8660          * should be properly mapped */ 
8661 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/platforms/chestnut.c linux-2.6.18.kgdb/arch/ppc/platforms/chestnut.c
8662 --- linux-2.6.18/arch/ppc/platforms/chestnut.c  2006-09-20 07:42:06.000000000 +0400
8663 +++ linux-2.6.18.kgdb/arch/ppc/platforms/chestnut.c     2008-06-10 16:19:22.000000000 +0400
8664 @@ -492,7 +492,7 @@ chestnut_power_off(void)
8665  static void __init
8666  chestnut_map_io(void)
8667  {
8668 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8669 +#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_8250)
8670         io_block_mapping(CHESTNUT_UART_BASE, CHESTNUT_UART_BASE, 0x100000,
8671                 _PAGE_IO);
8672  #endif
8673 @@ -566,9 +566,6 @@ platform_init(unsigned long r3, unsigned
8674  #if defined(CONFIG_SERIAL_TEXT_DEBUG)
8675         ppc_md.progress = gen550_progress;
8676  #endif
8677 -#if defined(CONFIG_KGDB)
8678 -       ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
8679 -#endif
8680  
8681         if (ppc_md.progress)
8682                  ppc_md.progress("chestnut_init(): exit", 0);
8683 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/platforms/pplus.c linux-2.6.18.kgdb/arch/ppc/platforms/pplus.c
8684 --- linux-2.6.18/arch/ppc/platforms/pplus.c     2006-09-20 07:42:06.000000000 +0400
8685 +++ linux-2.6.18.kgdb/arch/ppc/platforms/pplus.c        2008-06-10 16:19:22.000000000 +0400
8686 @@ -893,9 +893,6 @@ platform_init(unsigned long r3, unsigned
8687  #ifdef CONFIG_SERIAL_TEXT_DEBUG
8688         ppc_md.progress = gen550_progress;
8689  #endif                         /* CONFIG_SERIAL_TEXT_DEBUG */
8690 -#ifdef CONFIG_KGDB
8691 -       ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
8692 -#endif
8693  #ifdef CONFIG_SMP
8694         smp_ops = &pplus_smp_ops;
8695  #endif                         /* CONFIG_SMP */
8696 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/platforms/sandpoint.c linux-2.6.18.kgdb/arch/ppc/platforms/sandpoint.c
8697 --- linux-2.6.18/arch/ppc/platforms/sandpoint.c 2006-09-20 07:42:06.000000000 +0400
8698 +++ linux-2.6.18.kgdb/arch/ppc/platforms/sandpoint.c    2008-06-10 16:19:22.000000000 +0400
8699 @@ -730,9 +730,6 @@ platform_init(unsigned long r3, unsigned
8700         ppc_md.nvram_read_val = todc_mc146818_read_val;
8701         ppc_md.nvram_write_val = todc_mc146818_write_val;
8702  
8703 -#ifdef CONFIG_KGDB
8704 -       ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
8705 -#endif
8706  #ifdef CONFIG_SERIAL_TEXT_DEBUG
8707         ppc_md.progress = gen550_progress;
8708  #endif
8709 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/platforms/spruce.c linux-2.6.18.kgdb/arch/ppc/platforms/spruce.c
8710 --- linux-2.6.18/arch/ppc/platforms/spruce.c    2006-09-20 07:42:06.000000000 +0400
8711 +++ linux-2.6.18.kgdb/arch/ppc/platforms/spruce.c       2008-06-10 16:19:22.000000000 +0400
8712 @@ -178,26 +178,32 @@ spruce_early_serial_map(void)
8713         serial_req.membase = (u_char *)UART0_IO_BASE;
8714         serial_req.regshift = 0;
8715  
8716 -#if defined(CONFIG_KGDB) || defined(CONFIG_SERIAL_TEXT_DEBUG)
8717 -       gen550_init(0, &serial_req);
8718 -#endif
8719  #ifdef CONFIG_SERIAL_8250
8720         if (early_serial_setup(&serial_req) != 0)
8721                 printk("Early serial init of port 0 failed\n");
8722  #endif
8723 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8724 +       gen550_init(0, &serial_req);
8725 +#endif
8726 +#ifdef CONFIG_KGDB_8250
8727 +       kgdb8250_add_port(0, &port);
8728 +#endif
8729  
8730         /* Assume early_serial_setup() doesn't modify serial_req */
8731         serial_req.line = 1;
8732         serial_req.irq = UART1_INT;
8733         serial_req.membase = (u_char *)UART1_IO_BASE;
8734  
8735 -#if defined(CONFIG_KGDB) || defined(CONFIG_SERIAL_TEXT_DEBUG)
8736 -       gen550_init(1, &serial_req);
8737 -#endif
8738  #ifdef CONFIG_SERIAL_8250
8739         if (early_serial_setup(&serial_req) != 0)
8740                 printk("Early serial init of port 1 failed\n");
8741  #endif
8742 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8743 +       gen550_init(1, &serial_req);
8744 +#endif
8745 +#ifdef CONFIG_KGDB_8250
8746 +       kgdb8250_add_port(1, &serial_req);
8747 +#endif
8748  }
8749  
8750  TODC_ALLOC();
8751 @@ -316,7 +322,4 @@ platform_init(unsigned long r3, unsigned
8752  #ifdef CONFIG_SERIAL_TEXT_DEBUG
8753         ppc_md.progress = gen550_progress;
8754  #endif /* CONFIG_SERIAL_TEXT_DEBUG */
8755 -#ifdef CONFIG_KGDB
8756 -       ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
8757 -#endif
8758  }
8759 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/syslib/Makefile linux-2.6.18.kgdb/arch/ppc/syslib/Makefile
8760 --- linux-2.6.18/arch/ppc/syslib/Makefile       2006-09-20 07:42:06.000000000 +0400
8761 +++ linux-2.6.18.kgdb/arch/ppc/syslib/Makefile  2008-06-10 16:19:22.000000000 +0400
8762 @@ -76,7 +76,6 @@ obj-$(CONFIG_PCI_8260)                += m82xx_pci.o p
8763  obj-$(CONFIG_8260_PCI9)                += m8260_pci_erratum9.o
8764  obj-$(CONFIG_CPM2)             += cpm2_common.o cpm2_pic.o
8765  ifeq ($(CONFIG_PPC_GEN550),y)
8766 -obj-$(CONFIG_KGDB)             += gen550_kgdb.o gen550_dbg.o
8767  obj-$(CONFIG_SERIAL_TEXT_DEBUG)        += gen550_dbg.o
8768  endif
8769  ifeq ($(CONFIG_SERIAL_MPSC_CONSOLE),y)
8770 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/syslib/gen550.h linux-2.6.18.kgdb/arch/ppc/syslib/gen550.h
8771 --- linux-2.6.18/arch/ppc/syslib/gen550.h       2006-09-20 07:42:06.000000000 +0400
8772 +++ linux-2.6.18.kgdb/arch/ppc/syslib/gen550.h  2008-06-10 16:19:22.000000000 +0400
8773 @@ -11,4 +11,3 @@
8774  
8775  extern void gen550_progress(char *, unsigned short);
8776  extern void gen550_init(int, struct uart_port *);
8777 -extern void gen550_kgdb_map_scc(void);
8778 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/syslib/ibm44x_common.c linux-2.6.18.kgdb/arch/ppc/syslib/ibm44x_common.c
8779 --- linux-2.6.18/arch/ppc/syslib/ibm44x_common.c        2006-09-20 07:42:06.000000000 +0400
8780 +++ linux-2.6.18.kgdb/arch/ppc/syslib/ibm44x_common.c   2008-06-10 16:19:22.000000000 +0400
8781 @@ -192,9 +192,6 @@ void __init ibm44x_platform_init(unsigne
8782  #ifdef CONFIG_SERIAL_TEXT_DEBUG
8783         ppc_md.progress = gen550_progress;
8784  #endif /* CONFIG_SERIAL_TEXT_DEBUG */
8785 -#ifdef CONFIG_KGDB
8786 -       ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
8787 -#endif
8788  
8789         /*
8790          * The Abatron BDI JTAG debugger does not tolerate others
8791 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/syslib/mv64x60.c linux-2.6.18.kgdb/arch/ppc/syslib/mv64x60.c
8792 --- linux-2.6.18/arch/ppc/syslib/mv64x60.c      2006-09-20 07:42:06.000000000 +0400
8793 +++ linux-2.6.18.kgdb/arch/ppc/syslib/mv64x60.c 2008-06-10 16:19:22.000000000 +0400
8794 @@ -241,6 +241,12 @@ static struct resource mv64x60_mpsc0_res
8795                 .end    = MV64x60_IRQ_SDMA_0,
8796                 .flags  = IORESOURCE_IRQ,
8797         },
8798 +       [4] = {
8799 +               .name   = "mpsc 0 irq",
8800 +               .start  = MV64x60_IRQ_MPSC_0,
8801 +               .end    = MV64x60_IRQ_MPSC_0,
8802 +               .flags  = IORESOURCE_IRQ,
8803 +       },
8804  };
8805  
8806  static struct platform_device mpsc0_device = {
8807 @@ -298,6 +304,12 @@ static struct resource mv64x60_mpsc1_res
8808                 .end    = MV64360_IRQ_SDMA_1,
8809                 .flags  = IORESOURCE_IRQ,
8810         },
8811 +       [4] = {
8812 +               .name   = "mpsc 1 irq",
8813 +               .start  = MV64360_IRQ_MPSC_1,
8814 +               .end    = MV64360_IRQ_MPSC_1,
8815 +               .flags  = IORESOURCE_IRQ,
8816 +       },
8817  };
8818  
8819  static struct platform_device mpsc1_device = {
8820 @@ -1426,12 +1438,46 @@ mv64x60_pd_fixup(struct mv64x60_handle *
8821  static int __init
8822  mv64x60_add_pds(void)
8823  {
8824 -       return platform_add_devices(mv64x60_pd_devs,
8825 -               ARRAY_SIZE(mv64x60_pd_devs));
8826 +       int i, ret = 0;
8827 +
8828 +       for (i = 0; i < ARRAY_SIZE(mv64x60_pd_devs); i++) {
8829 +               if (mv64x60_pd_devs[i]) {
8830 +                       ret = platform_device_register(mv64x60_pd_devs[i]);
8831 +               }
8832 +               if (ret) {
8833 +                       while (--i >= 0)
8834 +                               platform_device_unregister(mv64x60_pd_devs[i]);
8835 +                       break;
8836 +               }
8837 +       }
8838 +       return ret;
8839  }
8840  arch_initcall(mv64x60_add_pds);
8841  
8842  /*
8843 + * mv64x60_early_get_pdev_data()
8844 + *
8845 + * Get the data associated with a platform device by name and number.
8846 + */
8847 +struct platform_device * __init
8848 +mv64x60_early_get_pdev_data(const char *name, int id, int remove)
8849 +{
8850 +       int i;
8851 +       struct platform_device *pdev;
8852 +
8853 +       for (i = 0; i <ARRAY_SIZE(mv64x60_pd_devs); i++) {
8854 +               if ((pdev = mv64x60_pd_devs[i]) &&
8855 +                       pdev->id == id &&
8856 +                       !strcmp(pdev->name, name)) {
8857 +                       if (remove)
8858 +                               mv64x60_pd_devs[i] = NULL;
8859 +                       return pdev;
8860 +               }
8861 +       }
8862 +       return NULL;
8863 +}
8864 +
8865 +/*
8866   *****************************************************************************
8867   *
8868   *     GT64260-Specific Routines
8869 @@ -1764,6 +1810,11 @@ gt64260a_chip_specific_init(struct mv64x
8870                 r->start = MV64x60_IRQ_SDMA_0;
8871                 r->end = MV64x60_IRQ_SDMA_0;
8872         }
8873 +       if ((r = platform_get_resource(&mpsc1_device, IORESOURCE_IRQ, 1))
8874 +                       != NULL) {
8875 +               r->start = GT64260_IRQ_MPSC_1;
8876 +               r->end = GT64260_IRQ_MPSC_1;
8877 +       }
8878  #endif
8879  }
8880  
8881 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/syslib/mv64x60_dbg.c linux-2.6.18.kgdb/arch/ppc/syslib/mv64x60_dbg.c
8882 --- linux-2.6.18/arch/ppc/syslib/mv64x60_dbg.c  2006-09-20 07:42:06.000000000 +0400
8883 +++ linux-2.6.18.kgdb/arch/ppc/syslib/mv64x60_dbg.c     2008-06-10 16:19:22.000000000 +0400
8884 @@ -34,7 +34,7 @@ static struct mv64x60_handle  mv64x60_dbg
8885  void
8886  mv64x60_progress_init(u32 base)
8887  {
8888 -       mv64x60_dbg_bh.v_base = base;
8889 +       mv64x60_dbg_bh.v_base = (void*)base;
8890         return;
8891  }
8892  
8893 @@ -69,53 +69,3 @@ mv64x60_mpsc_progress(char *s, unsigned 
8894         return;
8895  }
8896  #endif /* CONFIG_SERIAL_TEXT_DEBUG */
8897 -
8898 -
8899 -#if defined(CONFIG_KGDB)
8900 -
8901 -#if defined(CONFIG_KGDB_TTYS0)
8902 -#define KGDB_PORT 0
8903 -#elif defined(CONFIG_KGDB_TTYS1)
8904 -#define KGDB_PORT 1
8905 -#else
8906 -#error "Invalid kgdb_tty port"
8907 -#endif
8908 -
8909 -void
8910 -putDebugChar(unsigned char c)
8911 -{
8912 -       mv64x60_polled_putc(KGDB_PORT, (char)c);
8913 -}
8914 -
8915 -int
8916 -getDebugChar(void)
8917 -{
8918 -       unsigned char   c;
8919 -
8920 -       while (!mv64x60_polled_getc(KGDB_PORT, &c));
8921 -       return (int)c;
8922 -}
8923 -
8924 -void
8925 -putDebugString(char* str)
8926 -{
8927 -       while (*str != '\0') {
8928 -               putDebugChar(*str);
8929 -               str++;
8930 -       }
8931 -       putDebugChar('\r');
8932 -       return;
8933 -}
8934 -
8935 -void
8936 -kgdb_interruptible(int enable)
8937 -{
8938 -}
8939 -
8940 -void
8941 -kgdb_map_scc(void)
8942 -{
8943 -       if (ppc_md.early_serial_map)
8944 -               ppc_md.early_serial_map();
8945 -}
8946 -#endif /* CONFIG_KGDB */
8947 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/ppc/syslib/ppc85xx_setup.c linux-2.6.18.kgdb/arch/ppc/syslib/ppc85xx_setup.c
8948 --- linux-2.6.18/arch/ppc/syslib/ppc85xx_setup.c        2006-09-20 07:42:06.000000000 +0400
8949 +++ linux-2.6.18.kgdb/arch/ppc/syslib/ppc85xx_setup.c   2008-06-10 16:19:22.000000000 +0400
8950 @@ -69,7 +69,6 @@ mpc85xx_calibrate_decr(void)
8951         mtspr(SPRN_TCR, TCR_DIE);
8952  }
8953  
8954 -#ifdef CONFIG_SERIAL_8250
8955  void __init
8956  mpc85xx_early_serial_map(void)
8957  {
8958 @@ -85,7 +84,7 @@ mpc85xx_early_serial_map(void)
8959         pdata[0].mapbase += binfo->bi_immr_base;
8960         pdata[0].membase = ioremap(pdata[0].mapbase, MPC85xx_UART0_SIZE);
8961  
8962 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8963 +#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_8250)
8964         memset(&serial_req, 0, sizeof (serial_req));
8965         serial_req.iotype = UPIO_MEM;
8966         serial_req.mapbase = pdata[0].mapbase;
8967 @@ -93,18 +92,24 @@ mpc85xx_early_serial_map(void)
8968         serial_req.regshift = 0;
8969  
8970         gen550_init(0, &serial_req);
8971 +#ifdef CONFIG_KGDB_8250
8972 +       kgdb8250_add_port(0, &serial_req);
8973 +#endif
8974  #endif
8975  
8976         pdata[1].uartclk = binfo->bi_busfreq;
8977         pdata[1].mapbase += binfo->bi_immr_base;
8978         pdata[1].membase = ioremap(pdata[1].mapbase, MPC85xx_UART0_SIZE);
8979  
8980 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8981 +#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_8250)
8982         /* Assume gen550_init() doesn't modify serial_req */
8983         serial_req.mapbase = pdata[1].mapbase;
8984         serial_req.membase = pdata[1].membase;
8985  
8986         gen550_init(1, &serial_req);
8987 +#ifdef CONFIG_KGDB_8250
8988 +       kgdb8250_add_port(1, &serial_req);
8989 +#endif
8990  #endif
8991  }
8992  #endif
8993 @@ -363,5 +368,3 @@ mpc85xx_setup_hose(void)
8994         return;
8995  }
8996  #endif /* CONFIG_PCI */
8997 -
8998 -
8999 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/Kconfig.debug linux-2.6.18.kgdb/arch/sh/Kconfig.debug
9000 --- linux-2.6.18/arch/sh/Kconfig.debug  2006-09-20 07:42:06.000000000 +0400
9001 +++ linux-2.6.18.kgdb/arch/sh/Kconfig.debug     2008-06-10 16:19:47.000000000 +0400
9002 @@ -29,96 +29,4 @@ config EARLY_PRINTK
9003           This option is only useful porting the kernel to a new machine,
9004           when the kernel may crash or hang before the serial console is
9005           initialised. If unsure, say N.
9006 -
9007 -config KGDB
9008 -       bool "Include KGDB kernel debugger"
9009 -       help
9010 -         Include in-kernel hooks for kgdb, the Linux kernel source level
9011 -         debugger.  See <http://kgdb.sourceforge.net/> for more information.
9012 -         Unless you are intending to debug the kernel, say N here.
9013 -
9014 -menu "KGDB configuration options"
9015 -       depends on KGDB
9016 -
9017 -config MORE_COMPILE_OPTIONS
9018 -       bool "Add any additional compile options"
9019 -       help
9020 -         If you want to add additional CFLAGS to the kernel build, enable this
9021 -         option and then enter what you would like to add in the next question.
9022 -         Note however that -g is already appended with the selection of KGDB.
9023 -
9024 -config COMPILE_OPTIONS
9025 -       string "Additional compile arguments"
9026 -       depends on MORE_COMPILE_OPTIONS
9027 -
9028 -config KGDB_NMI
9029 -       bool "Enter KGDB on NMI"
9030 -       default n
9031 -
9032 -config KGDB_THREAD
9033 -       bool "Include KGDB thread support"
9034 -       default y
9035 -
9036 -config SH_KGDB_CONSOLE
9037 -       bool "Console messages through GDB"
9038 -       default n
9039 -
9040 -config KGDB_SYSRQ
9041 -       bool "Allow SysRq 'G' to enter KGDB"
9042 -       default y
9043 -
9044 -config KGDB_KERNEL_ASSERTS
9045 -       bool "Include KGDB kernel assertions"
9046 -       default n
9047 -
9048 -comment "Serial port setup"
9049 -
9050 -config KGDB_DEFPORT
9051 -       int "Port number (ttySCn)"
9052 -       default "1"
9053 -
9054 -config KGDB_DEFBAUD
9055 -       int "Baud rate"
9056 -       default "115200"
9057 -
9058 -choice
9059 -       prompt "Parity"
9060 -       depends on KGDB
9061 -       default KGDB_DEFPARITY_N
9062 -
9063 -config KGDB_DEFPARITY_N
9064 -       bool "None"
9065 -
9066 -config KGDB_DEFPARITY_E
9067 -       bool "Even"
9068 -
9069 -config KGDB_DEFPARITY_O
9070 -       bool "Odd"
9071 -
9072 -endchoice
9073 -
9074 -choice
9075 -       prompt "Data bits"
9076 -       depends on KGDB
9077 -       default KGDB_DEFBITS_8
9078 -
9079 -config KGDB_DEFBITS_8
9080 -       bool "8"
9081 -
9082 -config KGDB_DEFBITS_7
9083 -       bool "7"
9084 -
9085 -endchoice
9086 -
9087 -endmenu
9088 -
9089 -config FRAME_POINTER
9090 -       bool "Compile the kernel with frame pointers"
9091 -       default y if KGDB
9092 -       help
9093 -         If you say Y here the resulting kernel image will be slightly larger
9094 -         and slower, but it will give very useful debugging information.
9095 -         If you don't debug the kernel, you can say N, but we may not be able
9096 -         to solve problems without frame pointers.
9097 -
9098  endmenu
9099 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/Makefile linux-2.6.18.kgdb/arch/sh/Makefile
9100 --- linux-2.6.18/arch/sh/Makefile       2006-09-20 07:42:06.000000000 +0400
9101 +++ linux-2.6.18.kgdb/arch/sh/Makefile  2008-06-10 16:19:47.000000000 +0400
9102 @@ -43,7 +43,6 @@ cflags-$(CONFIG_CPU_SH4)              += -m4 \
9103  cflags-$(CONFIG_CPU_SH4A)              += $(call cc-option,-m4a-nofpu,)
9104  
9105  cflags-$(CONFIG_SH_DSP)                        += -Wa,-dsp
9106 -cflags-$(CONFIG_SH_KGDB)               += -g
9107  
9108  cflags-$(CONFIG_MORE_COMPILE_OPTIONS)  += \
9109         $(shell echo $(CONFIG_COMPILE_OPTIONS) | sed -e 's/"//g')
9110 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/boards/se/7751/setup.c linux-2.6.18.kgdb/arch/sh/boards/se/7751/setup.c
9111 --- linux-2.6.18/arch/sh/boards/se/7751/setup.c 2006-09-20 07:42:06.000000000 +0400
9112 +++ linux-2.6.18.kgdb/arch/sh/boards/se/7751/setup.c    2008-06-10 16:19:47.000000000 +0400
9113 @@ -17,10 +17,6 @@
9114  #include <asm/io.h>
9115  #include <asm/se7751/se7751.h>
9116  
9117 -#ifdef CONFIG_SH_KGDB
9118 -#include <asm/kgdb.h>
9119 -#endif
9120 -
9121  /*
9122   * Configure the Super I/O chip
9123   */
9124 @@ -82,12 +78,6 @@ const char *get_system_type(void)
9125         return "7751 SolutionEngine";
9126  }
9127  
9128 -#ifdef CONFIG_SH_KGDB
9129 -static int kgdb_uart_setup(void);
9130 -static struct kgdb_sermap kgdb_uart_sermap = 
9131 -{ "ttyS", 0, kgdb_uart_setup, NULL };
9132 -#endif
9133
9134  /*
9135   * Initialize the board
9136   */
9137 @@ -95,133 +85,4 @@ void __init platform_setup(void)
9138  {
9139         /* Call init_smsc() replacement to set up SuperIO. */
9140         /* XXX: RTC setting comes here */
9141 -#ifdef CONFIG_SH_KGDB
9142 -       kgdb_register_sermap(&kgdb_uart_sermap);
9143 -#endif
9144 -}
9145 -
9146 -/*********************************************************************
9147 - * Currently a hack (e.g. does not interact well w/serial.c, lots of *
9148 - * hardcoded stuff) but may be useful if SCI/F needs debugging.      *
9149 - * Mostly copied from x86 code (see files asm-i386/kgdb_local.h and  *
9150 - * arch/i386/lib/kgdb_serial.c).                                     *
9151 - *********************************************************************/
9152 -
9153 -#ifdef CONFIG_SH_KGDB
9154 -#include <linux/types.h>
9155 -#include <linux/serial.h>
9156 -#include <linux/serialP.h>
9157 -#include <linux/serial_reg.h>
9158 -
9159 -#define COM1_PORT 0x3f8  /* Base I/O address */
9160 -#define COM1_IRQ  4      /* IRQ not used yet */
9161 -#define COM2_PORT 0x2f8  /* Base I/O address */
9162 -#define COM2_IRQ  3      /* IRQ not used yet */
9163 -
9164 -#define SB_CLOCK 1843200 /* Serial baud clock */
9165 -#define SB_BASE (SB_CLOCK/16)
9166 -#define SB_MCR UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS
9167 -
9168 -struct uart_port {
9169 -       int base;
9170 -};
9171 -#define UART_NPORTS 2
9172 -struct uart_port uart_ports[] = {
9173 -       { COM1_PORT },
9174 -       { COM2_PORT },
9175 -};
9176 -struct uart_port *kgdb_uart_port;
9177 -
9178 -#define UART_IN(reg)   inb_p(kgdb_uart_port->base + reg)
9179 -#define UART_OUT(reg,v)        outb_p((v), kgdb_uart_port->base + reg)
9180 -
9181 -/* Basic read/write functions for the UART */
9182 -#define UART_LSR_RXCERR    (UART_LSR_BI | UART_LSR_FE | UART_LSR_PE)
9183 -static int kgdb_uart_getchar(void)
9184 -{
9185 -       int lsr;
9186 -       int c = -1;
9187 -
9188 -       while (c == -1) {
9189 -               lsr = UART_IN(UART_LSR);
9190 -               if (lsr & UART_LSR_DR) 
9191 -                       c = UART_IN(UART_RX);
9192 -               if ((lsr & UART_LSR_RXCERR))
9193 -                       c = -1;
9194 -       }
9195 -       return c;
9196 -}
9197 -
9198 -static void kgdb_uart_putchar(int c)
9199 -{
9200 -       while ((UART_IN(UART_LSR) & UART_LSR_THRE) == 0)
9201 -               ;
9202 -       UART_OUT(UART_TX, c);
9203 -}
9204 -
9205 -/*
9206 - * Initialize UART to configured/requested values.
9207 - * (But we don't interrupts yet, or interact w/serial.c)
9208 - */
9209 -static int kgdb_uart_setup(void)
9210 -{
9211 -       int port;
9212 -       int lcr = 0;
9213 -       int bdiv = 0;
9214 -
9215 -       if (kgdb_portnum >= UART_NPORTS) {
9216 -               KGDB_PRINTK("uart port %d invalid.\n", kgdb_portnum);
9217 -               return -1;
9218 -       }
9219 -
9220 -       kgdb_uart_port = &uart_ports[kgdb_portnum];
9221 -
9222 -       /* Init sequence from gdb_hook_interrupt */
9223 -       UART_IN(UART_RX);
9224 -       UART_OUT(UART_IER, 0);
9225 -
9226 -       UART_IN(UART_RX);       /* Serial driver comments say */
9227 -       UART_IN(UART_IIR);      /* this clears interrupt regs */
9228 -       UART_IN(UART_MSR);
9229 -
9230 -       /* Figure basic LCR values */
9231 -       switch (kgdb_bits) {
9232 -       case '7':
9233 -               lcr |= UART_LCR_WLEN7;
9234 -               break;
9235 -       default: case '8': 
9236 -               lcr |= UART_LCR_WLEN8;
9237 -               break;
9238 -       }
9239 -       switch (kgdb_parity) {
9240 -       case 'O':
9241 -               lcr |= UART_LCR_PARITY;
9242 -               break;
9243 -       case 'E':
9244 -               lcr |= (UART_LCR_PARITY | UART_LCR_EPAR);
9245 -               break;
9246 -       default: break;
9247 -       }
9248 -
9249 -       /* Figure the baud rate divisor */
9250 -       bdiv = (SB_BASE/kgdb_baud);
9251 -       
9252 -       /* Set the baud rate and LCR values */
9253 -       UART_OUT(UART_LCR, (lcr | UART_LCR_DLAB));
9254 -       UART_OUT(UART_DLL, (bdiv & 0xff));
9255 -       UART_OUT(UART_DLM, ((bdiv >> 8) & 0xff));
9256 -       UART_OUT(UART_LCR, lcr);
9257 -
9258 -       /* Set the MCR */
9259 -       UART_OUT(UART_MCR, SB_MCR);
9260 -
9261 -       /* Turn off FIFOs for now */
9262 -       UART_OUT(UART_FCR, 0);
9263 -
9264 -       /* Setup complete: initialize function pointers */
9265 -       kgdb_getchar = kgdb_uart_getchar;
9266 -       kgdb_putchar = kgdb_uart_putchar;
9267 -
9268 -       return 0;
9269  }
9270 -#endif /* CONFIG_SH_KGDB */
9271 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/Makefile linux-2.6.18.kgdb/arch/sh/kernel/Makefile
9272 --- linux-2.6.18/arch/sh/kernel/Makefile        2006-09-20 07:42:06.000000000 +0400
9273 +++ linux-2.6.18.kgdb/arch/sh/kernel/Makefile   2008-06-10 16:19:47.000000000 +0400
9274 @@ -13,7 +13,7 @@ obj-y                         += cpu/ timers/
9275  obj-$(CONFIG_SMP)              += smp.o
9276  obj-$(CONFIG_CF_ENABLER)       += cf-enabler.o
9277  obj-$(CONFIG_SH_STANDARD_BIOS) += sh_bios.o
9278 -obj-$(CONFIG_SH_KGDB)          += kgdb_stub.o kgdb_jmp.o
9279 +obj-$(CONFIG_KGDB)             += kgdb.o kgdb-jmp.o
9280  obj-$(CONFIG_SH_CPU_FREQ)      += cpufreq.o
9281  obj-$(CONFIG_MODULES)          += module.o
9282  obj-$(CONFIG_EARLY_PRINTK)     += early_printk.o
9283 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/cpu/sh3/ex.S linux-2.6.18.kgdb/arch/sh/kernel/cpu/sh3/ex.S
9284 --- linux-2.6.18/arch/sh/kernel/cpu/sh3/ex.S    2006-09-20 07:42:06.000000000 +0400
9285 +++ linux-2.6.18.kgdb/arch/sh/kernel/cpu/sh3/ex.S       2008-06-10 16:19:47.000000000 +0400
9286 @@ -42,7 +42,7 @@ ENTRY(exception_handling_table)
9287         .long   exception_error ! reserved_instruction (filled by trap_init) /* 180 */
9288         .long   exception_error ! illegal_slot_instruction (filled by trap_init) /*1A0*/
9289  ENTRY(nmi_slot)
9290 -#if defined (CONFIG_KGDB_NMI)
9291 +#if defined (CONFIG_KGDB)
9292         .long   debug_enter     /* 1C0 */       ! Allow trap to debugger
9293  #else
9294         .long   exception_none  /* 1C0 */       ! Not implemented yet
9295 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/cpu/sh4/ex.S linux-2.6.18.kgdb/arch/sh/kernel/cpu/sh4/ex.S
9296 --- linux-2.6.18/arch/sh/kernel/cpu/sh4/ex.S    2006-09-20 07:42:06.000000000 +0400
9297 +++ linux-2.6.18.kgdb/arch/sh/kernel/cpu/sh4/ex.S       2008-06-10 16:19:47.000000000 +0400
9298 @@ -46,7 +46,7 @@ ENTRY(exception_handling_table)
9299         .long   exception_error ! reserved_instruction (filled by trap_init) /* 180 */
9300         .long   exception_error ! illegal_slot_instruction (filled by trap_init) /*1A0*/
9301  ENTRY(nmi_slot)
9302 -#if defined (CONFIG_KGDB_NMI)
9303 +#if defined (CONFIG_KGDB)
9304         .long   debug_enter     /* 1C0 */       ! Allow trap to debugger
9305  #else
9306         .long   exception_none  /* 1C0 */       ! Not implemented yet
9307 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/entry.S linux-2.6.18.kgdb/arch/sh/kernel/entry.S
9308 --- linux-2.6.18/arch/sh/kernel/entry.S 2006-09-20 07:42:06.000000000 +0400
9309 +++ linux-2.6.18.kgdb/arch/sh/kernel/entry.S    2008-06-10 16:19:47.000000000 +0400
9310 @@ -75,7 +75,7 @@
9311  ENOSYS = 38
9312  EINVAL = 22
9313  
9314 -#if defined(CONFIG_KGDB_NMI)
9315 +#if defined(CONFIG_KGDB)
9316  NMI_VEC = 0x1c0                        ! Must catch early for debounce
9317  #endif
9318  
9319 @@ -227,31 +227,33 @@ call_dae:
9320  2:     .long   do_address_error
9321  #endif /* CONFIG_MMU */
9322  
9323 -#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
9324 +#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_KGDB)
9325  ! Handle kernel debug if either kgdb (SW) or gdb-stub (FW) is present.
9326  ! If both are configured, handle the debug traps (breakpoints) in SW,
9327  ! but still allow BIOS traps to FW.
9328  
9329         .align  2
9330  debug_kernel:
9331 -#if defined(CONFIG_SH_STANDARD_BIOS) && defined(CONFIG_SH_KGDB)
9332 +#if defined(CONFIG_SH_STANDARD_BIOS) && defined(CONFIG_KGDB)
9333         /* Force BIOS call to FW (debug_trap put TRA in r8) */
9334         mov     r8,r0
9335         shlr2   r0
9336         cmp/eq  #0x3f,r0
9337         bt      debug_kernel_fw
9338 -#endif /* CONFIG_SH_STANDARD_BIOS && CONFIG_SH_KGDB */
9339 +#endif /* CONFIG_SH_STANDARD_BIOS && CONFIG_KGDB */
9340  
9341 -debug_enter:           
9342 -#if defined(CONFIG_SH_KGDB)
9343 +       .align 2
9344 +       .globl debug_enter
9345 +debug_enter:
9346 +#if defined(CONFIG_KGDB)
9347         /* Jump to kgdb, pass stacked regs as arg */
9348  debug_kernel_sw:
9349         mov.l   3f, r0
9350         jmp     @r0
9351          mov    r15, r4
9352         .align  2
9353 -3:     .long   kgdb_handle_exception
9354 -#endif /* CONFIG_SH_KGDB */
9355 +3:     .long   kgdb_exception_handler
9356 +#endif /* CONFIG_KGDB */
9357  
9358  #if defined(CONFIG_SH_STANDARD_BIOS)
9359         /* Unwind the stack and jmp to the debug entry */
9360 @@ -293,12 +295,12 @@ debug_kernel_fw:
9361  2:     .long   gdb_vbr_vector
9362  #endif /* CONFIG_SH_STANDARD_BIOS */
9363  
9364 -#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
9365 +#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_KGDB */
9366  
9367  
9368         .align  2
9369 -debug_trap:    
9370 -#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
9371 +debug_trap:
9372 +#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_KGDB)
9373         mov     #OFF_SR, r0
9374         mov.l   @(r0,r15), r0           ! get status register
9375         shll    r0
9376 @@ -642,7 +644,7 @@ skip_restore:
9377  6:     or      k0, k2                  ! Set the IMASK-bits
9378         ldc     k2, ssr
9379         !
9380 -#if defined(CONFIG_KGDB_NMI)
9381 +#if defined(CONFIG_KGDB)
9382         ! Clear in_nmi
9383         mov.l   4f, k0
9384         mov     #0, k1
9385 @@ -694,7 +696,7 @@ tlb_miss:
9386  interrupt:
9387         mov.l   2f, k2
9388         mov.l   3f, k3
9389 -#if defined(CONFIG_KGDB_NMI)
9390 +#if defined(CONFIG_KGDB)
9391         ! Debounce (filter nested NMI)
9392         mov.l   @k2, k0
9393         mov.l   5f, k1
9394 @@ -709,7 +711,7 @@ interrupt:
9395  5:     .long   NMI_VEC
9396  6:     .long   in_nmi
9397  0:
9398 -#endif /* defined(CONFIG_KGDB_NMI) */
9399 +#endif /* defined(CONFIG_KGDB) */
9400         bra     handle_exception
9401          mov.l  @k2, k2
9402  
9403 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/kgdb-jmp.S linux-2.6.18.kgdb/arch/sh/kernel/kgdb-jmp.S
9404 --- linux-2.6.18/arch/sh/kernel/kgdb-jmp.S      1970-01-01 03:00:00.000000000 +0300
9405 +++ linux-2.6.18.kgdb/arch/sh/kernel/kgdb-jmp.S 2008-06-10 16:19:47.000000000 +0400
9406 @@ -0,0 +1,32 @@
9407 +#include <linux/linkage.h>
9408 +
9409 +ENTRY(kgdb_fault_setjmp)
9410 +       add     #(9*4), r4
9411 +       sts.l   pr, @-r4
9412 +       mov.l   r15, @-r4
9413 +       mov.l   r14, @-r4
9414 +       mov.l   r13, @-r4
9415 +       mov.l   r12, @-r4
9416 +       mov.l   r11, @-r4
9417 +       mov.l   r10, @-r4
9418 +       mov.l   r9, @-r4
9419 +       mov.l   r8, @-r4
9420 +       rts
9421 +        mov    #0, r0
9422 +
9423 +ENTRY(kgdb_fault_longjmp)
9424 +       mov.l   @r4+, r8
9425 +       mov.l   @r4+, r9
9426 +       mov.l   @r4+, r10
9427 +       mov.l   @r4+, r11
9428 +       mov.l   @r4+, r12
9429 +       mov.l   @r4+, r13
9430 +       mov.l   @r4+, r14
9431 +       mov.l   @r4+, r15
9432 +       lds.l   @r4+, pr
9433 +       mov     r5, r0
9434 +       tst     r0, r0
9435 +       bf      1f
9436 +       mov     #1, r0
9437 +1:     rts
9438 +        nop
9439 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/kgdb.c linux-2.6.18.kgdb/arch/sh/kernel/kgdb.c
9440 --- linux-2.6.18/arch/sh/kernel/kgdb.c  1970-01-01 03:00:00.000000000 +0300
9441 +++ linux-2.6.18.kgdb/arch/sh/kernel/kgdb.c     2008-06-10 16:19:47.000000000 +0400
9442 @@ -0,0 +1,363 @@
9443 +/*
9444 + * arch/sh/kernel/kgdb.c
9445 + *
9446 + * Contains SH-specific low-level support for KGDB.
9447 + *
9448 + * Containes extracts from code by Glenn Engel, Jim Kingdon,
9449 + * David Grothe <dave@gcom.com>, Tigran Aivazian <tigran@sco.com>,
9450 + * Amit S. Kale <akale@veritas.com>,  William Gatliff <bgat@open-widgets.com>,
9451 + * Ben Lee, Steve Chamberlain and Benoit Miller <fulg@iname.com>,
9452 + * Henry Bell <henry.bell@st.com> and Jeremy Siegel <jsiegel@mvista.com>
9453 + *
9454 + * Maintainer: Tom Rini <trini@kernel.crashing.org>
9455 + *
9456 + * 2004 (c) MontaVista Software, Inc. This file is licensed under
9457 + * the terms of the GNU General Public License version 2. This program
9458 + * is licensed "as is" without any warranty of any kind, whether express
9459 + * or implied.
9460 + */
9461 +
9462 +#include <linux/string.h>
9463 +#include <linux/kernel.h>
9464 +#include <linux/sched.h>
9465 +#include <linux/smp.h>
9466 +#include <linux/spinlock.h>
9467 +#include <linux/delay.h>
9468 +#include <linux/linkage.h>
9469 +#include <linux/init.h>
9470 +#include <linux/kgdb.h>
9471 +
9472 +#include <asm/system.h>
9473 +#include <asm/current.h>
9474 +#include <asm/signal.h>
9475 +#include <asm/pgtable.h>
9476 +#include <asm/ptrace.h>
9477 +
9478 +extern void per_cpu_trap_init(void);
9479 +extern atomic_t cpu_doing_single_step;
9480 +
9481 +/* Function pointers for linkage */
9482 +static struct kgdb_regs trap_registers;
9483 +
9484 +/* Globals. */
9485 +char in_nmi;                   /* Set during NMI to prevent reentry */
9486 +
9487 +/* TRA differs sh3/4 */
9488 +#if defined(CONFIG_CPU_SH3)
9489 +#define TRA 0xffffffd0
9490 +#elif defined(CONFIG_CPU_SH4)
9491 +#define TRA 0xff000020
9492 +#endif
9493 +
9494 +/* Macros for single step instruction identification */
9495 +#define OPCODE_BT(op)         (((op) & 0xff00) == 0x8900)
9496 +#define OPCODE_BF(op)         (((op) & 0xff00) == 0x8b00)
9497 +#define OPCODE_BTF_DISP(op)   (((op) & 0x80) ? (((op) | 0xffffff80) << 1) : \
9498 +                             (((op) & 0x7f ) << 1))
9499 +#define OPCODE_BFS(op)        (((op) & 0xff00) == 0x8f00)
9500 +#define OPCODE_BTS(op)        (((op) & 0xff00) == 0x8d00)
9501 +#define OPCODE_BRA(op)        (((op) & 0xf000) == 0xa000)
9502 +#define OPCODE_BRA_DISP(op)   (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \
9503 +                             (((op) & 0x7ff) << 1))
9504 +#define OPCODE_BRAF(op)       (((op) & 0xf0ff) == 0x0023)
9505 +#define OPCODE_BRAF_REG(op)   (((op) & 0x0f00) >> 8)
9506 +#define OPCODE_BSR(op)        (((op) & 0xf000) == 0xb000)
9507 +#define OPCODE_BSR_DISP(op)   (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \
9508 +                             (((op) & 0x7ff) << 1))
9509 +#define OPCODE_BSRF(op)       (((op) & 0xf0ff) == 0x0003)
9510 +#define OPCODE_BSRF_REG(op)   (((op) >> 8) & 0xf)
9511 +#define OPCODE_JMP(op)        (((op) & 0xf0ff) == 0x402b)
9512 +#define OPCODE_JMP_REG(op)    (((op) >> 8) & 0xf)
9513 +#define OPCODE_JSR(op)        (((op) & 0xf0ff) == 0x400b)
9514 +#define OPCODE_JSR_REG(op)    (((op) >> 8) & 0xf)
9515 +#define OPCODE_RTS(op)        ((op) == 0xb)
9516 +#define OPCODE_RTE(op)        ((op) == 0x2b)
9517 +
9518 +#define SR_T_BIT_MASK           0x1
9519 +#define STEP_OPCODE             0xc320
9520 +#define BIOS_CALL_TRAP          0x3f
9521 +
9522 +/* Exception codes as per SH-4 core manual */
9523 +#define ADDRESS_ERROR_LOAD_VEC   7
9524 +#define ADDRESS_ERROR_STORE_VEC  8
9525 +#define TRAP_VEC                 11
9526 +#define INVALID_INSN_VEC         12
9527 +#define INVALID_SLOT_VEC         13
9528 +#define NMI_VEC                  14
9529 +#define SERIAL_BREAK_VEC         58
9530 +
9531 +/* Misc static */
9532 +static int stepped_address;
9533 +static short stepped_opcode;
9534 +
9535 +/* Translate SH-3/4 exception numbers to unix-like signal values */
9536 +static int compute_signal(const int excep_code)
9537 +{
9538 +       switch (excep_code) {
9539 +       case INVALID_INSN_VEC:
9540 +       case INVALID_SLOT_VEC:
9541 +               return SIGILL;
9542 +       case ADDRESS_ERROR_LOAD_VEC:
9543 +       case ADDRESS_ERROR_STORE_VEC:
9544 +               return SIGSEGV;
9545 +       case SERIAL_BREAK_VEC:
9546 +       case NMI_VEC:
9547 +               return SIGINT;
9548 +       default:
9549 +               /* Act like it was a break/trap. */
9550 +               return SIGTRAP;
9551 +       }
9552 +}
9553 +
9554 +/*
9555 + * Translate the registers of the system into the format that GDB wants.  Since
9556 + * we use a local structure to store things, instead of getting them out
9557 + * of pt_regs, we can just do a memcpy.
9558 + */
9559 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *ign)
9560 +{
9561 +       memcpy(gdb_regs, &trap_registers, sizeof(trap_registers));
9562 +}
9563 +
9564 +/*
9565 + * On SH we save: r1 (prev->thread.sp) r2 (prev->thread.pc) r4 (prev) r5 (next)
9566 + * r6 (next->thread.sp) r7 (next->thread.pc)
9567 + */
9568 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
9569 +{
9570 +       int count;
9571 +
9572 +       for (count = 0; count < 16; count++)
9573 +               *(gdb_regs++) = 0;
9574 +       *(gdb_regs++) = p->thread.pc;
9575 +       *(gdb_regs++) = 0;
9576 +       *(gdb_regs++) = 0;
9577 +       *(gdb_regs++) = 0;
9578 +       *(gdb_regs++) = 0;
9579 +       *(gdb_regs++) = 0;
9580 +       *(gdb_regs++) = 0;
9581 +}
9582 +
9583 +/*
9584 + * Translate the registers values that GDB has given us back into the
9585 + * format of the system.  See the comment above about memcpy.
9586 + */
9587 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *ign)
9588 +{
9589 +       memcpy(&trap_registers, gdb_regs, sizeof(trap_registers));
9590 +}
9591 +
9592 +/* Calculate the new address for after a step */
9593 +static short *get_step_address(void)
9594 +{
9595 +       short op = *(short *)trap_registers.pc;
9596 +       long addr;
9597 +
9598 +       /* BT */
9599 +       if (OPCODE_BT(op)) {
9600 +               if (trap_registers.sr & SR_T_BIT_MASK)
9601 +                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
9602 +               else
9603 +                       addr = trap_registers.pc + 2;
9604 +       }
9605 +
9606 +       /* BTS */
9607 +       else if (OPCODE_BTS(op)) {
9608 +               if (trap_registers.sr & SR_T_BIT_MASK)
9609 +                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
9610 +               else
9611 +                       addr = trap_registers.pc + 4;   /* Not in delay slot */
9612 +       }
9613 +
9614 +       /* BF */
9615 +       else if (OPCODE_BF(op)) {
9616 +               if (!(trap_registers.sr & SR_T_BIT_MASK))
9617 +                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
9618 +               else
9619 +                       addr = trap_registers.pc + 2;
9620 +       }
9621 +
9622 +       /* BFS */
9623 +       else if (OPCODE_BFS(op)) {
9624 +               if (!(trap_registers.sr & SR_T_BIT_MASK))
9625 +                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
9626 +               else
9627 +                       addr = trap_registers.pc + 4;   /* Not in delay slot */
9628 +       }
9629 +
9630 +       /* BRA */
9631 +       else if (OPCODE_BRA(op))
9632 +               addr = trap_registers.pc + 4 + OPCODE_BRA_DISP(op);
9633 +
9634 +       /* BRAF */
9635 +       else if (OPCODE_BRAF(op))
9636 +               addr = trap_registers.pc + 4
9637 +                   + trap_registers.regs[OPCODE_BRAF_REG(op)];
9638 +
9639 +       /* BSR */
9640 +       else if (OPCODE_BSR(op))
9641 +               addr = trap_registers.pc + 4 + OPCODE_BSR_DISP(op);
9642 +
9643 +       /* BSRF */
9644 +       else if (OPCODE_BSRF(op))
9645 +               addr = trap_registers.pc + 4
9646 +                   + trap_registers.regs[OPCODE_BSRF_REG(op)];
9647 +
9648 +       /* JMP */
9649 +       else if (OPCODE_JMP(op))
9650 +               addr = trap_registers.regs[OPCODE_JMP_REG(op)];
9651 +
9652 +       /* JSR */
9653 +       else if (OPCODE_JSR(op))
9654 +               addr = trap_registers.regs[OPCODE_JSR_REG(op)];
9655 +
9656 +       /* RTS */
9657 +       else if (OPCODE_RTS(op))
9658 +               addr = trap_registers.pr;
9659 +
9660 +       /* RTE */
9661 +       else if (OPCODE_RTE(op))
9662 +               addr = trap_registers.regs[15];
9663 +
9664 +       /* Other */
9665 +       else
9666 +               addr = trap_registers.pc + 2;
9667 +
9668 +       kgdb_flush_icache_range(addr, addr + 2);
9669 +       return (short *)addr;
9670 +}
9671 +
9672 +/* The command loop, read and act on requests */
9673 +int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
9674 +                              char *remcom_in_buffer, char *remcom_out_buffer,
9675 +                              struct pt_regs *ign)
9676 +{
9677 +       unsigned long addr;
9678 +       char *ptr = &remcom_in_buffer[1];
9679 +
9680 +       /* Examine first char of buffer to see what we need to do */
9681 +       switch (remcom_in_buffer[0]) {
9682 +       case 'c':               /* Continue at address AA..AA (optional) */
9683 +       case 's':               /* Step one instruction from AA..AA */
9684 +               /* Try to read optional parameter, PC unchanged if none */
9685 +               if (kgdb_hex2long(&ptr, &addr))
9686 +                       trap_registers.pc = addr;
9687 +
9688 +               atomic_set(&cpu_doing_single_step, -1);
9689 +               if (remcom_in_buffer[0] == 's') {
9690 +                       /* Replace the instruction immediately after the
9691 +                        * current instruction (i.e. next in the expected
9692 +                        * flow of control) with a trap instruction, so that
9693 +                        * returning will cause only a single instruction to
9694 +                        * be executed. Note that this model is slightly
9695 +                        * broken for instructions with delay slots
9696 +                        * (e.g. B[TF]S, BSR, BRA etc), where both the branch
9697 +                        * and the instruction in the delay slot will be
9698 +                        * executed.
9699 +                        */
9700 +                       /* Determine where the target instruction will send
9701 +                        * us to */
9702 +                       unsigned short *next_addr = get_step_address();
9703 +                       stepped_address = (int)next_addr;
9704 +
9705 +                       /* Replace it */
9706 +                       stepped_opcode = *(short *)next_addr;
9707 +                       *next_addr = STEP_OPCODE;
9708 +
9709 +                       /* Flush and return */
9710 +                       kgdb_flush_icache_range((long)next_addr,
9711 +                                               (long)next_addr + 2);
9712 +                       if (kgdb_contthread)
9713 +                               atomic_set(&cpu_doing_single_step,
9714 +                                          smp_processor_id());
9715 +               }
9716 +               return 0;
9717 +       }
9718 +       return -1;
9719 +}
9720 +
9721 +/*
9722 + * When an exception has occured, we are called.  We need to set things
9723 + * up so that we can call kgdb_handle_exception to handle requests from
9724 + * the remote GDB.
9725 + */
9726 +void kgdb_exception_handler(struct pt_regs *regs)
9727 +{
9728 +       int excep_code, vbr_val;
9729 +       int count;
9730 +
9731 +       /* Copy kernel regs (from stack) */
9732 +       for (count = 0; count < 16; count++)
9733 +               trap_registers.regs[count] = regs->regs[count];
9734 +       trap_registers.pc = regs->pc;
9735 +       trap_registers.pr = regs->pr;
9736 +       trap_registers.sr = regs->sr;
9737 +       trap_registers.gbr = regs->gbr;
9738 +       trap_registers.mach = regs->mach;
9739 +       trap_registers.macl = regs->macl;
9740 +
9741 +       __asm__ __volatile__("stc vbr, %0":"=r"(vbr_val));
9742 +       trap_registers.vbr = vbr_val;
9743 +
9744 +       /* Get the execption code. */
9745 +       __asm__ __volatile__("stc r2_bank, %0":"=r"(excep_code));
9746 +
9747 +       excep_code >>= 5;
9748 +
9749 +       /* If we got an NMI, and KGDB is not yet initialized, call
9750 +        * breakpoint() to try and initialize everything for us. */
9751 +       if (excep_code == NMI_VEC && !kgdb_initialized) {
9752 +               breakpoint();
9753 +               return;
9754 +       }
9755 +
9756 +       /* TRAP_VEC exception indicates a software trap inserted in place of
9757 +        * code by GDB so back up PC by one instruction, as this instruction
9758 +        * will later be replaced by its original one.  Do NOT do this for
9759 +        * trap 0xff, since that indicates a compiled-in breakpoint which
9760 +        * will not be replaced (and we would retake the trap forever) */
9761 +       if (excep_code == TRAP_VEC &&
9762 +           (*(volatile unsigned long *)TRA != (0xff << 2)))
9763 +               trap_registers.pc -= 2;
9764 +
9765 +       /* If we have been single-stepping, put back the old instruction.
9766 +        * We use stepped_address in case we have stopped more than one
9767 +        * instruction away. */
9768 +       if (stepped_opcode != 0) {
9769 +               *(short *)stepped_address = stepped_opcode;
9770 +               kgdb_flush_icache_range(stepped_address, stepped_address + 2);
9771 +       }
9772 +       stepped_opcode = 0;
9773 +
9774 +       /* Call the stub to do the processing.  Note that not everything we
9775 +        * need to send back and forth lives in pt_regs. */
9776 +       kgdb_handle_exception(excep_code, compute_signal(excep_code), 0, regs);
9777 +
9778 +       /* Copy back the (maybe modified) registers */
9779 +       for (count = 0; count < 16; count++)
9780 +               regs->regs[count] = trap_registers.regs[count];
9781 +       regs->pc = trap_registers.pc;
9782 +       regs->pr = trap_registers.pr;
9783 +       regs->sr = trap_registers.sr;
9784 +       regs->gbr = trap_registers.gbr;
9785 +       regs->mach = trap_registers.mach;
9786 +       regs->macl = trap_registers.macl;
9787 +
9788 +       vbr_val = trap_registers.vbr;
9789 +       __asm__ __volatile__("ldc %0, vbr": :"r"(vbr_val));
9790 +}
9791 +
9792 +int __init kgdb_arch_init(void)
9793 +{
9794 +       per_cpu_trap_init();
9795 +
9796 +       return 0;
9797 +}
9798 +
9799 +struct kgdb_arch arch_kgdb_ops = {
9800 +#ifdef CONFIG_CPU_LITTLE_ENDIAN
9801 +       .gdb_bpt_instr = {0xff, 0xc3},
9802 +#else
9803 +       .gdb_bpt_instr = {0xc3, 0xff},
9804 +#endif
9805 +};
9806 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/kgdb_jmp.S linux-2.6.18.kgdb/arch/sh/kernel/kgdb_jmp.S
9807 --- linux-2.6.18/arch/sh/kernel/kgdb_jmp.S      2006-09-20 07:42:06.000000000 +0400
9808 +++ linux-2.6.18.kgdb/arch/sh/kernel/kgdb_jmp.S 1970-01-01 03:00:00.000000000 +0300
9809 @@ -1,33 +0,0 @@
9810 -#include <linux/linkage.h>
9811 -
9812 -ENTRY(setjmp)
9813 -       add     #(9*4), r4
9814 -       sts.l   pr, @-r4
9815 -       mov.l   r15, @-r4
9816 -       mov.l   r14, @-r4
9817 -       mov.l   r13, @-r4
9818 -       mov.l   r12, @-r4
9819 -       mov.l   r11, @-r4
9820 -       mov.l   r10, @-r4
9821 -       mov.l   r9, @-r4
9822 -       mov.l   r8, @-r4
9823 -       rts
9824 -        mov    #0, r0
9825 -
9826 -ENTRY(longjmp)
9827 -       mov.l   @r4+, r8
9828 -       mov.l   @r4+, r9
9829 -       mov.l   @r4+, r10
9830 -       mov.l   @r4+, r11
9831 -       mov.l   @r4+, r12
9832 -       mov.l   @r4+, r13
9833 -       mov.l   @r4+, r14
9834 -       mov.l   @r4+, r15
9835 -       lds.l   @r4+, pr
9836 -       mov     r5, r0
9837 -       tst     r0, r0
9838 -       bf      1f
9839 -       mov     #1, r0  ! in case val==0
9840 -1:     rts
9841 -        nop
9842 -
9843 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/kgdb_stub.c linux-2.6.18.kgdb/arch/sh/kernel/kgdb_stub.c
9844 --- linux-2.6.18/arch/sh/kernel/kgdb_stub.c     2006-09-20 07:42:06.000000000 +0400
9845 +++ linux-2.6.18.kgdb/arch/sh/kernel/kgdb_stub.c        1970-01-01 03:00:00.000000000 +0300
9846 @@ -1,1491 +0,0 @@
9847 -/*
9848 - * May be copied or modified under the terms of the GNU General Public
9849 - * License.  See linux/COPYING for more information.
9850 - *
9851 - * Containes extracts from code by Glenn Engel, Jim Kingdon,
9852 - * David Grothe <dave@gcom.com>, Tigran Aivazian <tigran@sco.com>,
9853 - * Amit S. Kale <akale@veritas.com>,  William Gatliff <bgat@open-widgets.com>,
9854 - * Ben Lee, Steve Chamberlain and Benoit Miller <fulg@iname.com>.
9855 - * 
9856 - * This version by Henry Bell <henry.bell@st.com>
9857 - * Minor modifications by Jeremy Siegel <jsiegel@mvista.com>
9858 - * 
9859 - * Contains low-level support for remote debug using GDB. 
9860 - *
9861 - * To enable debugger support, two things need to happen. A call to
9862 - * set_debug_traps() is necessary in order to allow any breakpoints
9863 - * or error conditions to be properly intercepted and reported to gdb.
9864 - * A breakpoint also needs to be generated to begin communication.  This
9865 - * is most easily accomplished by a call to breakpoint() which does
9866 - * a trapa if the initialisation phase has been successfully completed.
9867 - *
9868 - * In this case, set_debug_traps() is not used to "take over" exceptions;
9869 - * other kernel code is modified instead to enter the kgdb functions here
9870 - * when appropriate (see entry.S for breakpoint traps and NMI interrupts,
9871 - * see traps.c for kernel error exceptions).
9872 - *
9873 - * The following gdb commands are supported:
9874 - *
9875 - *    Command       Function                               Return value
9876 - *
9877 - *    g             return the value of the CPU registers  hex data or ENN
9878 - *    G             set the value of the CPU registers     OK or ENN
9879 - *
9880 - *    mAA..AA,LLLL  Read LLLL bytes at address AA..AA      hex data or ENN
9881 - *    MAA..AA,LLLL: Write LLLL bytes at address AA.AA      OK or ENN
9882 - *    XAA..AA,LLLL: Same, but data is binary (not hex)     OK or ENN
9883 - *
9884 - *    c             Resume at current address              SNN   ( signal NN)
9885 - *    cAA..AA       Continue at address AA..AA             SNN
9886 - *    CNN;          Resume at current address with signal  SNN
9887 - *    CNN;AA..AA    Resume at address AA..AA with signal   SNN
9888 - *
9889 - *    s             Step one instruction                   SNN
9890 - *    sAA..AA       Step one instruction from AA..AA       SNN
9891 - *    SNN;          Step one instruction with signal       SNN
9892 - *    SNNAA..AA     Step one instruction from AA..AA w/NN  SNN
9893 - *
9894 - *    k             kill (Detach GDB)
9895 - *
9896 - *    d             Toggle debug flag
9897 - *    D             Detach GDB 
9898 - *
9899 - *    Hct           Set thread t for operations,           OK or ENN
9900 - *                  c = 'c' (step, cont), c = 'g' (other
9901 - *                  operations)
9902 - *
9903 - *    qC            Query current thread ID                QCpid
9904 - *    qfThreadInfo  Get list of current threads (first)    m<id>
9905 - *    qsThreadInfo   "    "  "     "      "   (subsequent)
9906 - *    qOffsets      Get section offsets                  Text=x;Data=y;Bss=z
9907 - * 
9908 - *    TXX           Find if thread XX is alive             OK or ENN
9909 - *    ?             What was the last sigval ?             SNN   (signal NN)
9910 - *    O             Output to GDB console
9911 - *
9912 - * Remote communication protocol.
9913 - *
9914 - *    A debug packet whose contents are <data> is encapsulated for
9915 - *    transmission in the form:
9916 - *
9917 - *       $ <data> # CSUM1 CSUM2
9918 - *
9919 - *       <data> must be ASCII alphanumeric and cannot include characters
9920 - *       '$' or '#'.  If <data> starts with two characters followed by
9921 - *       ':', then the existing stubs interpret this as a sequence number.
9922 - *
9923 - *       CSUM1 and CSUM2 are ascii hex representation of an 8-bit 
9924 - *       checksum of <data>, the most significant nibble is sent first.
9925 - *       the hex digits 0-9,a-f are used.
9926 - *
9927 - *    Receiver responds with:
9928 - *
9929 - *       +       - if CSUM is correct and ready for next packet
9930 - *       -       - if CSUM is incorrect
9931 - *
9932 - * Responses can be run-length encoded to save space.  A '*' means that
9933 - * the next character is an ASCII encoding giving a repeat count which
9934 - * stands for that many repititions of the character preceding the '*'.
9935 - * The encoding is n+29, yielding a printable character where n >=3 
9936 - * (which is where RLE starts to win).  Don't use an n > 126. 
9937 - *
9938 - * So "0* " means the same as "0000".
9939 - */
9940 -
9941 -#include <linux/string.h>
9942 -#include <linux/kernel.h>
9943 -#include <linux/sched.h>
9944 -#include <linux/smp.h>
9945 -#include <linux/spinlock.h>
9946 -#include <linux/delay.h>
9947 -#include <linux/linkage.h>
9948 -#include <linux/init.h>
9949 -
9950 -#include <asm/system.h>
9951 -#include <asm/current.h>
9952 -#include <asm/signal.h>
9953 -#include <asm/pgtable.h>
9954 -#include <asm/ptrace.h>
9955 -#include <asm/kgdb.h>
9956 -
9957 -#ifdef CONFIG_SH_KGDB_CONSOLE
9958 -#include <linux/console.h>
9959 -#endif
9960 -
9961 -/* Function pointers for linkage */
9962 -kgdb_debug_hook_t *kgdb_debug_hook;
9963 -kgdb_bus_error_hook_t *kgdb_bus_err_hook;
9964 -
9965 -int (*kgdb_getchar)(void);
9966 -void (*kgdb_putchar)(int);
9967 -
9968 -static void put_debug_char(int c)
9969 -{
9970 -       if (!kgdb_putchar)
9971 -               return;
9972 -       (*kgdb_putchar)(c);
9973 -}
9974 -static int get_debug_char(void)
9975 -{
9976 -       if (!kgdb_getchar)
9977 -               return -1;
9978 -       return (*kgdb_getchar)();
9979 -}
9980 -
9981 -/* Num chars in in/out bound buffers, register packets need NUMREGBYTES * 2 */
9982 -#define BUFMAX 1024
9983 -#define NUMREGBYTES (MAXREG*4)
9984 -#define OUTBUFMAX (NUMREGBYTES*2+512)
9985 -
9986 -enum regs {
9987 -       R0 = 0, R1,  R2,  R3,   R4,   R5,  R6, R7,
9988 -       R8, R9, R10, R11, R12,  R13,  R14, R15,
9989 -       PC, PR, GBR, VBR, MACH, MACL, SR,
9990 -       /*  */
9991 -       MAXREG
9992 -};
9993 -
9994 -static unsigned int registers[MAXREG];
9995 -struct kgdb_regs trap_registers;
9996 -
9997 -char kgdb_in_gdb_mode;
9998 -char in_nmi;                   /* Set during NMI to prevent reentry */
9999 -int kgdb_nofault;              /* Boolean to ignore bus errs (i.e. in GDB) */
10000 -int kgdb_enabled = 1;          /* Default to enabled, cmdline can disable */
10001 -int kgdb_halt;
10002 -
10003 -/* Exposed for user access */
10004 -struct task_struct *kgdb_current;
10005 -unsigned int kgdb_g_imask;
10006 -int kgdb_trapa_val;
10007 -int kgdb_excode;
10008 -
10009 -/* Default values for SCI (can override via kernel args in setup.c) */
10010 -#ifndef CONFIG_KGDB_DEFPORT
10011 -#define CONFIG_KGDB_DEFPORT 1
10012 -#endif
10013 -
10014 -#ifndef CONFIG_KGDB_DEFBAUD
10015 -#define CONFIG_KGDB_DEFBAUD 115200
10016 -#endif
10017 -
10018 -#if defined(CONFIG_KGDB_DEFPARITY_E)
10019 -#define CONFIG_KGDB_DEFPARITY 'E'
10020 -#elif defined(CONFIG_KGDB_DEFPARITY_O)
10021 -#define CONFIG_KGDB_DEFPARITY 'O'
10022 -#else /* CONFIG_KGDB_DEFPARITY_N */
10023 -#define CONFIG_KGDB_DEFPARITY 'N'
10024 -#endif
10025 -
10026 -#ifdef CONFIG_KGDB_DEFBITS_7
10027 -#define CONFIG_KGDB_DEFBITS '7'
10028 -#else /* CONFIG_KGDB_DEFBITS_8 */
10029 -#define CONFIG_KGDB_DEFBITS '8'
10030 -#endif
10031 -
10032 -/* SCI/UART settings, used in kgdb_console_setup() */
10033 -int  kgdb_portnum = CONFIG_KGDB_DEFPORT;
10034 -int  kgdb_baud = CONFIG_KGDB_DEFBAUD;
10035 -char kgdb_parity = CONFIG_KGDB_DEFPARITY;
10036 -char kgdb_bits = CONFIG_KGDB_DEFBITS;
10037 -
10038 -/* Jump buffer for setjmp/longjmp */
10039 -static jmp_buf rem_com_env;
10040 -
10041 -/* TRA differs sh3/4 */
10042 -#if defined(CONFIG_CPU_SH3)
10043 -#define TRA 0xffffffd0
10044 -#elif defined(CONFIG_CPU_SH4)
10045 -#define TRA 0xff000020
10046 -#endif
10047 -
10048 -/* Macros for single step instruction identification */
10049 -#define OPCODE_BT(op)         (((op) & 0xff00) == 0x8900)
10050 -#define OPCODE_BF(op)         (((op) & 0xff00) == 0x8b00)
10051 -#define OPCODE_BTF_DISP(op)   (((op) & 0x80) ? (((op) | 0xffffff80) << 1) : \
10052 -                             (((op) & 0x7f ) << 1))
10053 -#define OPCODE_BFS(op)        (((op) & 0xff00) == 0x8f00)
10054 -#define OPCODE_BTS(op)        (((op) & 0xff00) == 0x8d00)
10055 -#define OPCODE_BRA(op)        (((op) & 0xf000) == 0xa000)
10056 -#define OPCODE_BRA_DISP(op)   (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \
10057 -                             (((op) & 0x7ff) << 1))
10058 -#define OPCODE_BRAF(op)       (((op) & 0xf0ff) == 0x0023)
10059 -#define OPCODE_BRAF_REG(op)   (((op) & 0x0f00) >> 8)
10060 -#define OPCODE_BSR(op)        (((op) & 0xf000) == 0xb000)
10061 -#define OPCODE_BSR_DISP(op)   (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \
10062 -                             (((op) & 0x7ff) << 1))
10063 -#define OPCODE_BSRF(op)       (((op) & 0xf0ff) == 0x0003)
10064 -#define OPCODE_BSRF_REG(op)   (((op) >> 8) & 0xf)
10065 -#define OPCODE_JMP(op)        (((op) & 0xf0ff) == 0x402b)
10066 -#define OPCODE_JMP_REG(op)    (((op) >> 8) & 0xf)
10067 -#define OPCODE_JSR(op)        (((op) & 0xf0ff) == 0x400b)
10068 -#define OPCODE_JSR_REG(op)    (((op) >> 8) & 0xf)
10069 -#define OPCODE_RTS(op)        ((op) == 0xb)
10070 -#define OPCODE_RTE(op)        ((op) == 0x2b)
10071 -
10072 -#define SR_T_BIT_MASK           0x1
10073 -#define STEP_OPCODE             0xc320
10074 -#define BIOS_CALL_TRAP          0x3f
10075 -
10076 -/* Exception codes as per SH-4 core manual */
10077 -#define ADDRESS_ERROR_LOAD_VEC   7
10078 -#define ADDRESS_ERROR_STORE_VEC  8
10079 -#define TRAP_VEC                 11
10080 -#define INVALID_INSN_VEC         12
10081 -#define INVALID_SLOT_VEC         13
10082 -#define NMI_VEC                  14
10083 -#define USER_BREAK_VEC           15
10084 -#define SERIAL_BREAK_VEC         58
10085 -
10086 -/* Misc static */
10087 -static int stepped_address;
10088 -static short stepped_opcode;
10089 -static const char hexchars[] = "0123456789abcdef";
10090 -static char in_buffer[BUFMAX];
10091 -static char out_buffer[OUTBUFMAX];
10092 -
10093 -static void kgdb_to_gdb(const char *s);
10094 -
10095 -#ifdef CONFIG_KGDB_THREAD
10096 -static struct task_struct *trapped_thread;
10097 -static struct task_struct *current_thread;
10098 -typedef unsigned char threadref[8];
10099 -#define BUF_THREAD_ID_SIZE 16
10100 -#endif
10101 -
10102 -/* Return addr as a real volatile address */
10103 -static inline unsigned int ctrl_inl(const unsigned long addr)
10104 -{
10105 -       return *(volatile unsigned long *) addr;
10106 -}
10107 -
10108 -/* Correctly set *addr using volatile */
10109 -static inline void ctrl_outl(const unsigned int b, unsigned long addr)
10110 -{
10111 -       *(volatile unsigned long *) addr = b;
10112 -}
10113 -
10114 -/* Get high hex bits */
10115 -static char highhex(const int x)
10116 -{
10117 -       return hexchars[(x >> 4) & 0xf];
10118 -}
10119 -
10120 -/* Get low hex bits */
10121 -static char lowhex(const int x)
10122 -{
10123 -       return hexchars[x & 0xf];
10124 -}
10125 -
10126 -/* Convert ch to hex */
10127 -static int hex(const char ch)
10128 -{
10129 -       if ((ch >= 'a') && (ch <= 'f'))
10130 -               return (ch - 'a' + 10);
10131 -       if ((ch >= '0') && (ch <= '9'))
10132 -               return (ch - '0');
10133 -       if ((ch >= 'A') && (ch <= 'F'))
10134 -               return (ch - 'A' + 10);
10135 -       return (-1);
10136 -}
10137 -
10138 -/* Convert the memory pointed to by mem into hex, placing result in buf.
10139 -   Returns a pointer to the last char put in buf (null) */
10140 -static char *mem_to_hex(const char *mem, char *buf, const int count)
10141 -{
10142 -       int i;
10143 -       int ch;
10144 -       unsigned short s_val;
10145 -       unsigned long l_val;
10146 -
10147 -       /* Check for 16 or 32 */
10148 -       if (count == 2 && ((long) mem & 1) == 0) {
10149 -               s_val = *(unsigned short *) mem;
10150 -               mem = (char *) &s_val;
10151 -       } else if (count == 4 && ((long) mem & 3) == 0) {
10152 -               l_val = *(unsigned long *) mem;
10153 -               mem = (char *) &l_val;
10154 -       }
10155 -       for (i = 0; i < count; i++) {
10156 -               ch = *mem++;
10157 -               *buf++ = highhex(ch);
10158 -               *buf++ = lowhex(ch);
10159 -       }
10160 -       *buf = 0;
10161 -       return (buf);
10162 -}
10163 -
10164 -/* Convert the hex array pointed to by buf into binary, to be placed in mem.
10165 -   Return a pointer to the character after the last byte written */
10166 -static char *hex_to_mem(const char *buf, char *mem, const int count)
10167 -{
10168 -       int i;
10169 -       unsigned char ch;
10170 -
10171 -       for (i = 0; i < count; i++) {
10172 -               ch = hex(*buf++) << 4;
10173 -               ch = ch + hex(*buf++);
10174 -               *mem++ = ch;
10175 -       }
10176 -       return (mem);
10177 -}
10178 -
10179 -/* While finding valid hex chars, convert to an integer, then return it */
10180 -static int hex_to_int(char **ptr, int *int_value)
10181 -{
10182 -       int num_chars = 0;
10183 -       int hex_value;
10184 -
10185 -       *int_value = 0;
10186 -
10187 -       while (**ptr) {
10188 -               hex_value = hex(**ptr);
10189 -               if (hex_value >= 0) {
10190 -                       *int_value = (*int_value << 4) | hex_value;
10191 -                       num_chars++;
10192 -               } else
10193 -                       break;
10194 -               (*ptr)++;
10195 -       }
10196 -       return num_chars;
10197 -}
10198 -
10199 -/*  Copy the binary array pointed to by buf into mem.  Fix $, #,
10200 -    and 0x7d escaped with 0x7d.  Return a pointer to the character 
10201 -    after the last byte written. */
10202 -static char *ebin_to_mem(const char *buf, char *mem, int count)
10203 -{
10204 -       for (; count > 0; count--, buf++) {
10205 -               if (*buf == 0x7d)
10206 -                       *mem++ = *(++buf) ^ 0x20;
10207 -               else
10208 -                       *mem++ = *buf;
10209 -       }
10210 -       return mem;
10211 -}
10212 -
10213 -/* Pack a hex byte */
10214 -static char *pack_hex_byte(char *pkt, int byte)
10215 -{
10216 -       *pkt++ = hexchars[(byte >> 4) & 0xf];
10217 -       *pkt++ = hexchars[(byte & 0xf)];
10218 -       return pkt;
10219 -}
10220 -
10221 -#ifdef CONFIG_KGDB_THREAD
10222 -
10223 -/* Pack a thread ID */
10224 -static char *pack_threadid(char *pkt, threadref * id)
10225 -{
10226 -       char *limit;
10227 -       unsigned char *altid;
10228 -
10229 -       altid = (unsigned char *) id;
10230 -
10231 -       limit = pkt + BUF_THREAD_ID_SIZE;
10232 -       while (pkt < limit)
10233 -               pkt = pack_hex_byte(pkt, *altid++);
10234 -       return pkt;
10235 -}
10236 -
10237 -/* Convert an integer into our threadref */
10238 -static void int_to_threadref(threadref * id, const int value)
10239 -{
10240 -       unsigned char *scan = (unsigned char *) id;
10241 -       int i = 4;
10242 -
10243 -       while (i--)
10244 -               *scan++ = 0;
10245 -
10246 -       *scan++ = (value >> 24) & 0xff;
10247 -       *scan++ = (value >> 16) & 0xff;
10248 -       *scan++ = (value >> 8) & 0xff;
10249 -       *scan++ = (value & 0xff);
10250 -}
10251 -
10252 -/* Return a task structure ptr for a particular pid */
10253 -static struct task_struct *get_thread(int pid)
10254 -{
10255 -       struct task_struct *thread;
10256 -
10257 -       /* Use PID_MAX w/gdb for pid 0 */
10258 -       if (pid == PID_MAX) pid = 0;
10259 -
10260 -       /* First check via PID */
10261 -       thread = find_task_by_pid(pid);
10262 -
10263 -       if (thread)
10264 -               return thread;
10265 -
10266 -       /* Start at the start */
10267 -       thread = init_tasks[0];
10268 -
10269 -       /* Walk along the linked list of tasks */
10270 -       do {
10271 -               if (thread->pid == pid)
10272 -                       return thread;
10273 -               thread = thread->next_task;
10274 -       } while (thread != init_tasks[0]);
10275 -
10276 -       return NULL;
10277 -}
10278 -
10279 -#endif /* CONFIG_KGDB_THREAD */
10280 -
10281 -/* Scan for the start char '$', read the packet and check the checksum */
10282 -static void get_packet(char *buffer, int buflen)
10283 -{
10284 -       unsigned char checksum;
10285 -       unsigned char xmitcsum;
10286 -       int i;
10287 -       int count;
10288 -       char ch;
10289 -
10290 -       do {
10291 -               /* Ignore everything until the start character */
10292 -               while ((ch = get_debug_char()) != '$');
10293 -
10294 -               checksum = 0;
10295 -               xmitcsum = -1;
10296 -               count = 0;
10297 -
10298 -               /* Now, read until a # or end of buffer is found */
10299 -               while (count < (buflen - 1)) {
10300 -                       ch = get_debug_char();
10301 -
10302 -                       if (ch == '#')
10303 -                               break;
10304 -
10305 -                       checksum = checksum + ch;
10306 -                       buffer[count] = ch;
10307 -                       count = count + 1;
10308 -               }
10309 -
10310 -               buffer[count] = 0;
10311 -
10312 -               /* Continue to read checksum following # */
10313 -               if (ch == '#') {
10314 -                       xmitcsum = hex(get_debug_char()) << 4;
10315 -                       xmitcsum += hex(get_debug_char());
10316 -
10317 -                       /* Checksum */
10318 -                       if (checksum != xmitcsum)
10319 -                               put_debug_char('-');    /* Failed checksum */
10320 -                       else {
10321 -                               /* Ack successful transfer */
10322 -                               put_debug_char('+');
10323 -
10324 -                               /* If a sequence char is present, reply 
10325 -                                  the sequence ID */
10326 -                               if (buffer[2] == ':') {
10327 -                                       put_debug_char(buffer[0]);
10328 -                                       put_debug_char(buffer[1]);
10329 -
10330 -                                       /* Remove sequence chars from buffer */
10331 -                                       count = strlen(buffer);
10332 -                                       for (i = 3; i <= count; i++)
10333 -                                               buffer[i - 3] = buffer[i];
10334 -                               }
10335 -                       }
10336 -               }
10337 -       }
10338 -       while (checksum != xmitcsum);   /* Keep trying while we fail */
10339 -}
10340 -
10341 -/* Send the packet in the buffer with run-length encoding */
10342 -static void put_packet(char *buffer)
10343 -{
10344 -       int checksum;
10345 -       char *src;
10346 -       int runlen;
10347 -       int encode;
10348 -
10349 -       do {
10350 -               src = buffer;
10351 -               put_debug_char('$');
10352 -               checksum = 0;
10353 -
10354 -               /* Continue while we still have chars left */
10355 -               while (*src) {
10356 -                       /* Check for runs up to 99 chars long */
10357 -                       for (runlen = 1; runlen < 99; runlen++) {
10358 -                               if (src[0] != src[runlen])
10359 -                                       break;
10360 -                       }
10361 -
10362 -                       if (runlen > 3) {
10363 -                               /* Got a useful amount, send encoding */
10364 -                               encode = runlen + ' ' - 4;
10365 -                               put_debug_char(*src);   checksum += *src;
10366 -                               put_debug_char('*');    checksum += '*';
10367 -                               put_debug_char(encode); checksum += encode;
10368 -                               src += runlen;
10369 -                       } else {
10370 -                               /* Otherwise just send the current char */
10371 -                               put_debug_char(*src);   checksum += *src;
10372 -                               src += 1;
10373 -                       }
10374 -               }
10375 -
10376 -               /* '#' Separator, put high and low components of checksum */
10377 -               put_debug_char('#');
10378 -               put_debug_char(highhex(checksum));
10379 -               put_debug_char(lowhex(checksum));
10380 -       }
10381 -       while ((get_debug_char()) != '+');      /* While no ack */
10382 -}
10383 -
10384 -/* A bus error has occurred - perform a longjmp to return execution and
10385 -   allow handling of the error */
10386 -static void kgdb_handle_bus_error(void)
10387 -{
10388 -       longjmp(rem_com_env, 1);
10389 -}
10390 -
10391 -/* Translate SH-3/4 exception numbers to unix-like signal values */
10392 -static int compute_signal(const int excep_code)
10393 -{
10394 -       int sigval;
10395 -
10396 -       switch (excep_code) {
10397 -
10398 -       case INVALID_INSN_VEC:
10399 -       case INVALID_SLOT_VEC:
10400 -               sigval = SIGILL;
10401 -               break;
10402 -       case ADDRESS_ERROR_LOAD_VEC:
10403 -       case ADDRESS_ERROR_STORE_VEC:
10404 -               sigval = SIGSEGV;
10405 -               break;
10406 -
10407 -       case SERIAL_BREAK_VEC:
10408 -       case NMI_VEC:
10409 -               sigval = SIGINT;
10410 -               break;
10411 -
10412 -       case USER_BREAK_VEC:
10413 -       case TRAP_VEC:
10414 -               sigval = SIGTRAP;
10415 -               break;
10416 -
10417 -       default:
10418 -               sigval = SIGBUS;        /* "software generated" */
10419 -               break;
10420 -       }
10421 -
10422 -       return (sigval);
10423 -}
10424 -
10425 -/* Make a local copy of the registers passed into the handler (bletch) */
10426 -static void kgdb_regs_to_gdb_regs(const struct kgdb_regs *regs,
10427 -                                 int *gdb_regs)
10428 -{
10429 -       gdb_regs[R0] = regs->regs[R0];
10430 -       gdb_regs[R1] = regs->regs[R1];
10431 -       gdb_regs[R2] = regs->regs[R2];
10432 -       gdb_regs[R3] = regs->regs[R3];
10433 -       gdb_regs[R4] = regs->regs[R4];
10434 -       gdb_regs[R5] = regs->regs[R5];
10435 -       gdb_regs[R6] = regs->regs[R6];
10436 -       gdb_regs[R7] = regs->regs[R7];
10437 -       gdb_regs[R8] = regs->regs[R8];
10438 -       gdb_regs[R9] = regs->regs[R9];
10439 -       gdb_regs[R10] = regs->regs[R10];
10440 -       gdb_regs[R11] = regs->regs[R11];
10441 -       gdb_regs[R12] = regs->regs[R12];
10442 -       gdb_regs[R13] = regs->regs[R13];
10443 -       gdb_regs[R14] = regs->regs[R14];
10444 -       gdb_regs[R15] = regs->regs[R15];
10445 -       gdb_regs[PC] = regs->pc;
10446 -       gdb_regs[PR] = regs->pr;
10447 -       gdb_regs[GBR] = regs->gbr;
10448 -       gdb_regs[MACH] = regs->mach;
10449 -       gdb_regs[MACL] = regs->macl;
10450 -       gdb_regs[SR] = regs->sr;
10451 -       gdb_regs[VBR] = regs->vbr;
10452 -}
10453 -
10454 -/* Copy local gdb registers back to kgdb regs, for later copy to kernel */
10455 -static void gdb_regs_to_kgdb_regs(const int *gdb_regs,
10456 -                                 struct kgdb_regs *regs)
10457 -{
10458 -       regs->regs[R0] = gdb_regs[R0];
10459 -       regs->regs[R1] = gdb_regs[R1];
10460 -       regs->regs[R2] = gdb_regs[R2];
10461 -       regs->regs[R3] = gdb_regs[R3];
10462 -       regs->regs[R4] = gdb_regs[R4];
10463 -       regs->regs[R5] = gdb_regs[R5];
10464 -       regs->regs[R6] = gdb_regs[R6];
10465 -       regs->regs[R7] = gdb_regs[R7];
10466 -       regs->regs[R8] = gdb_regs[R8];
10467 -       regs->regs[R9] = gdb_regs[R9];
10468 -       regs->regs[R10] = gdb_regs[R10];
10469 -       regs->regs[R11] = gdb_regs[R11];
10470 -       regs->regs[R12] = gdb_regs[R12];
10471 -       regs->regs[R13] = gdb_regs[R13];
10472 -       regs->regs[R14] = gdb_regs[R14];
10473 -       regs->regs[R15] = gdb_regs[R15];
10474 -       regs->pc = gdb_regs[PC];
10475 -       regs->pr = gdb_regs[PR];
10476 -       regs->gbr = gdb_regs[GBR];
10477 -       regs->mach = gdb_regs[MACH];
10478 -       regs->macl = gdb_regs[MACL];
10479 -       regs->sr = gdb_regs[SR];
10480 -       regs->vbr = gdb_regs[VBR];
10481 -}
10482 -
10483 -#ifdef CONFIG_KGDB_THREAD
10484 -/* Make a local copy of registers from the specified thread */
10485 -asmlinkage void ret_from_fork(void);
10486 -static void thread_regs_to_gdb_regs(const struct task_struct *thread,
10487 -                                   int *gdb_regs)
10488 -{
10489 -       int regno;
10490 -       int *tregs;
10491 -
10492 -       /* Initialize to zero */
10493 -       for (regno = 0; regno < MAXREG; regno++)
10494 -               gdb_regs[regno] = 0;
10495 -
10496 -       /* Just making sure... */
10497 -       if (thread == NULL)
10498 -               return;
10499 -
10500 -       /* A new fork has pt_regs on the stack from a fork() call */
10501 -       if (thread->thread.pc == (unsigned long)ret_from_fork) {
10502 -
10503 -               int vbr_val;
10504 -               struct pt_regs *kregs;
10505 -               kregs = (struct pt_regs*)thread->thread.sp;
10506 -
10507 -               gdb_regs[R0] = kregs->regs[R0];
10508 -               gdb_regs[R1] = kregs->regs[R1];
10509 -               gdb_regs[R2] = kregs->regs[R2];
10510 -               gdb_regs[R3] = kregs->regs[R3];
10511 -               gdb_regs[R4] = kregs->regs[R4];
10512 -               gdb_regs[R5] = kregs->regs[R5];
10513 -               gdb_regs[R6] = kregs->regs[R6];
10514 -               gdb_regs[R7] = kregs->regs[R7];
10515 -               gdb_regs[R8] = kregs->regs[R8];
10516 -               gdb_regs[R9] = kregs->regs[R9];
10517 -               gdb_regs[R10] = kregs->regs[R10];
10518 -               gdb_regs[R11] = kregs->regs[R11];
10519 -               gdb_regs[R12] = kregs->regs[R12];
10520 -               gdb_regs[R13] = kregs->regs[R13];
10521 -               gdb_regs[R14] = kregs->regs[R14];
10522 -               gdb_regs[R15] = kregs->regs[R15];
10523 -               gdb_regs[PC] = kregs->pc;
10524 -               gdb_regs[PR] = kregs->pr;
10525 -               gdb_regs[GBR] = kregs->gbr;
10526 -               gdb_regs[MACH] = kregs->mach;
10527 -               gdb_regs[MACL] = kregs->macl;
10528 -               gdb_regs[SR] = kregs->sr;
10529 -
10530 -               asm("stc vbr, %0":"=r"(vbr_val));
10531 -               gdb_regs[VBR] = vbr_val;
10532 -               return;
10533 -       }
10534 -
10535 -       /* Otherwise, we have only some registers from switch_to() */
10536 -       tregs = (int *)thread->thread.sp;
10537 -       gdb_regs[R15] = (int)tregs;
10538 -       gdb_regs[R14] = *tregs++;
10539 -       gdb_regs[R13] = *tregs++;
10540 -       gdb_regs[R12] = *tregs++;
10541 -       gdb_regs[R11] = *tregs++;
10542 -       gdb_regs[R10] = *tregs++;
10543 -       gdb_regs[R9] = *tregs++;
10544 -       gdb_regs[R8] = *tregs++;
10545 -       gdb_regs[PR] = *tregs++;
10546 -       gdb_regs[GBR] = *tregs++;
10547 -       gdb_regs[PC] = thread->thread.pc;
10548 -}
10549 -#endif /* CONFIG_KGDB_THREAD */
10550 -
10551 -/* Calculate the new address for after a step */
10552 -static short *get_step_address(void)
10553 -{
10554 -       short op = *(short *) trap_registers.pc;
10555 -       long addr;
10556 -
10557 -       /* BT */
10558 -       if (OPCODE_BT(op)) {
10559 -               if (trap_registers.sr & SR_T_BIT_MASK)
10560 -                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
10561 -               else
10562 -                       addr = trap_registers.pc + 2;
10563 -       }
10564 -
10565 -       /* BTS */
10566 -       else if (OPCODE_BTS(op)) {
10567 -               if (trap_registers.sr & SR_T_BIT_MASK)
10568 -                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
10569 -               else
10570 -                       addr = trap_registers.pc + 4;   /* Not in delay slot */
10571 -       }
10572 -
10573 -       /* BF */
10574 -       else if (OPCODE_BF(op)) {
10575 -               if (!(trap_registers.sr & SR_T_BIT_MASK))
10576 -                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
10577 -               else
10578 -                       addr = trap_registers.pc + 2;
10579 -       }
10580 -
10581 -       /* BFS */
10582 -       else if (OPCODE_BFS(op)) {
10583 -               if (!(trap_registers.sr & SR_T_BIT_MASK))
10584 -                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
10585 -               else
10586 -                       addr = trap_registers.pc + 4;   /* Not in delay slot */
10587 -       }
10588 -
10589 -       /* BRA */
10590 -       else if (OPCODE_BRA(op))
10591 -               addr = trap_registers.pc + 4 + OPCODE_BRA_DISP(op);
10592 -
10593 -       /* BRAF */
10594 -       else if (OPCODE_BRAF(op))
10595 -               addr = trap_registers.pc + 4
10596 -                   + trap_registers.regs[OPCODE_BRAF_REG(op)];
10597 -
10598 -       /* BSR */
10599 -       else if (OPCODE_BSR(op))
10600 -               addr = trap_registers.pc + 4 + OPCODE_BSR_DISP(op);
10601 -
10602 -       /* BSRF */
10603 -       else if (OPCODE_BSRF(op))
10604 -               addr = trap_registers.pc + 4
10605 -                   + trap_registers.regs[OPCODE_BSRF_REG(op)];
10606 -
10607 -       /* JMP */
10608 -       else if (OPCODE_JMP(op))
10609 -               addr = trap_registers.regs[OPCODE_JMP_REG(op)];
10610 -
10611 -       /* JSR */
10612 -       else if (OPCODE_JSR(op))
10613 -               addr = trap_registers.regs[OPCODE_JSR_REG(op)];
10614 -
10615 -       /* RTS */
10616 -       else if (OPCODE_RTS(op))
10617 -               addr = trap_registers.pr;
10618 -
10619 -       /* RTE */
10620 -       else if (OPCODE_RTE(op))
10621 -               addr = trap_registers.regs[15];
10622 -
10623 -       /* Other */
10624 -       else
10625 -               addr = trap_registers.pc + 2;
10626 -
10627 -       kgdb_flush_icache_range(addr, addr + 2);
10628 -       return (short *) addr;
10629 -}
10630 -
10631 -/* Set up a single-step.  Replace the instruction immediately after the 
10632 -   current instruction (i.e. next in the expected flow of control) with a
10633 -   trap instruction, so that returning will cause only a single instruction
10634 -   to be executed. Note that this model is slightly broken for instructions
10635 -   with delay slots (e.g. B[TF]S, BSR, BRA etc), where both the branch
10636 -   and the instruction in the delay slot will be executed. */
10637 -static void do_single_step(void)
10638 -{
10639 -       unsigned short *addr = 0;
10640 -
10641 -       /* Determine where the target instruction will send us to */
10642 -       addr = get_step_address();
10643 -       stepped_address = (int)addr;
10644 -
10645 -       /* Replace it */
10646 -       stepped_opcode = *(short *)addr;
10647 -       *addr = STEP_OPCODE;
10648 -
10649 -       /* Flush and return */
10650 -       kgdb_flush_icache_range((long) addr, (long) addr + 2);
10651 -       return;
10652 -}
10653 -
10654 -/* Undo a single step */
10655 -static void undo_single_step(void)
10656 -{
10657 -       /* If we have stepped, put back the old instruction */
10658 -       /* Use stepped_address in case we stopped elsewhere */
10659 -       if (stepped_opcode != 0) {
10660 -               *(short*)stepped_address = stepped_opcode;
10661 -               kgdb_flush_icache_range(stepped_address, stepped_address + 2);
10662 -       }
10663 -       stepped_opcode = 0;
10664 -}
10665 -
10666 -/* Send a signal message */
10667 -static void send_signal_msg(const int signum)
10668 -{
10669 -#ifndef CONFIG_KGDB_THREAD
10670 -       out_buffer[0] = 'S';
10671 -       out_buffer[1] = highhex(signum);
10672 -       out_buffer[2] = lowhex(signum);
10673 -       out_buffer[3] = 0;
10674 -       put_packet(out_buffer);
10675 -#else /* CONFIG_KGDB_THREAD */
10676 -       int threadid;
10677 -       threadref thref;
10678 -       char *out = out_buffer;
10679 -       const char *tstring = "thread";
10680 -
10681 -       *out++ = 'T';
10682 -       *out++ = highhex(signum);
10683 -       *out++ = lowhex(signum);
10684 -
10685 -       while (*tstring) {
10686 -               *out++ = *tstring++;
10687 -       }
10688 -       *out++ = ':';
10689 -
10690 -       threadid = trapped_thread->pid;
10691 -       if (threadid == 0) threadid = PID_MAX;
10692 -       int_to_threadref(&thref, threadid);
10693 -       pack_threadid(out, &thref);
10694 -       out += BUF_THREAD_ID_SIZE;
10695 -       *out++ = ';';
10696 -
10697 -       *out = 0;
10698 -       put_packet(out_buffer);
10699 -#endif /* CONFIG_KGDB_THREAD */
10700 -}
10701 -
10702 -/* Reply that all was well */
10703 -static void send_ok_msg(void)
10704 -{
10705 -       strcpy(out_buffer, "OK");
10706 -       put_packet(out_buffer);
10707 -}
10708 -
10709 -/* Reply that an error occurred */
10710 -static void send_err_msg(void)
10711 -{
10712 -       strcpy(out_buffer, "E01");
10713 -       put_packet(out_buffer);
10714 -}
10715 -
10716 -/* Empty message indicates unrecognised command */
10717 -static void send_empty_msg(void)
10718 -{
10719 -       put_packet("");
10720 -}
10721 -
10722 -/* Read memory due to 'm' message */
10723 -static void read_mem_msg(void)
10724 -{
10725 -       char *ptr;
10726 -       int addr;
10727 -       int length;
10728 -
10729 -       /* Jmp, disable bus error handler */
10730 -       if (setjmp(rem_com_env) == 0) {
10731 -
10732 -               kgdb_nofault = 1;
10733 -
10734 -               /* Walk through, have m<addr>,<length> */
10735 -               ptr = &in_buffer[1];
10736 -               if (hex_to_int(&ptr, &addr) && (*ptr++ == ','))
10737 -                       if (hex_to_int(&ptr, &length)) {
10738 -                               ptr = 0;
10739 -                               if (length * 2 > OUTBUFMAX)
10740 -                                       length = OUTBUFMAX / 2;
10741 -                               mem_to_hex((char *) addr, out_buffer, length);
10742 -                       }
10743 -               if (ptr)
10744 -                       send_err_msg();
10745 -               else
10746 -                       put_packet(out_buffer);
10747 -       } else
10748 -               send_err_msg();
10749 -
10750 -       /* Restore bus error handler */
10751 -       kgdb_nofault = 0;
10752 -}
10753 -
10754 -/* Write memory due to 'M' or 'X' message */
10755 -static void write_mem_msg(int binary)
10756 -{
10757 -       char *ptr;
10758 -       int addr;
10759 -       int length;
10760 -
10761 -       if (setjmp(rem_com_env) == 0) {
10762 -
10763 -               kgdb_nofault = 1;
10764 -
10765 -               /* Walk through, have M<addr>,<length>:<data> */
10766 -               ptr = &in_buffer[1];
10767 -               if (hex_to_int(&ptr, &addr) && (*ptr++ == ','))
10768 -                       if (hex_to_int(&ptr, &length) && (*ptr++ == ':')) {
10769 -                               if (binary)
10770 -                                       ebin_to_mem(ptr, (char*)addr, length);
10771 -                               else
10772 -                                       hex_to_mem(ptr, (char*)addr, length);
10773 -                               kgdb_flush_icache_range(addr, addr + length);
10774 -                               ptr = 0;
10775 -                               send_ok_msg();
10776 -                       }
10777 -               if (ptr)
10778 -                       send_err_msg();
10779 -       } else
10780 -               send_err_msg();
10781 -
10782 -       /* Restore bus error handler */
10783 -       kgdb_nofault = 0;
10784 -}
10785 -
10786 -/* Continue message  */
10787 -static void continue_msg(void)
10788 -{
10789 -       /* Try to read optional parameter, PC unchanged if none */
10790 -       char *ptr = &in_buffer[1];
10791 -       int addr;
10792 -
10793 -       if (hex_to_int(&ptr, &addr))
10794 -               trap_registers.pc = addr;
10795 -}
10796 -
10797 -/* Continue message with signal */
10798 -static void continue_with_sig_msg(void)
10799 -{
10800 -       int signal;
10801 -       char *ptr = &in_buffer[1];
10802 -       int addr;
10803 -
10804 -       /* Report limitation */
10805 -       kgdb_to_gdb("Cannot force signal in kgdb, continuing anyway.\n");
10806 -
10807 -       /* Signal */
10808 -       hex_to_int(&ptr, &signal);
10809 -       if (*ptr == ';')
10810 -               ptr++;
10811 -
10812 -       /* Optional address */
10813 -       if (hex_to_int(&ptr, &addr))
10814 -               trap_registers.pc = addr;
10815 -}
10816 -
10817 -/* Step message */
10818 -static void step_msg(void)
10819 -{
10820 -       continue_msg();
10821 -       do_single_step();
10822 -}
10823 -
10824 -/* Step message with signal */
10825 -static void step_with_sig_msg(void)
10826 -{
10827 -       continue_with_sig_msg();
10828 -       do_single_step();
10829 -}
10830 -
10831 -/* Send register contents */
10832 -static void send_regs_msg(void)
10833 -{
10834 -#ifdef CONFIG_KGDB_THREAD
10835 -       if (!current_thread)
10836 -               kgdb_regs_to_gdb_regs(&trap_registers, registers);
10837 -       else
10838 -               thread_regs_to_gdb_regs(current_thread, registers);
10839 -#else
10840 -       kgdb_regs_to_gdb_regs(&trap_registers, registers);
10841 -#endif
10842 -
10843 -       mem_to_hex((char *) registers, out_buffer, NUMREGBYTES);
10844 -       put_packet(out_buffer);
10845 -}
10846 -
10847 -/* Set register contents - currently can't set other thread's registers */
10848 -static void set_regs_msg(void)
10849 -{
10850 -#ifdef CONFIG_KGDB_THREAD
10851 -       if (!current_thread) {
10852 -#endif
10853 -               kgdb_regs_to_gdb_regs(&trap_registers, registers);
10854 -               hex_to_mem(&in_buffer[1], (char *) registers, NUMREGBYTES);
10855 -               gdb_regs_to_kgdb_regs(registers, &trap_registers);
10856 -               send_ok_msg();
10857 -#ifdef CONFIG_KGDB_THREAD
10858 -       } else
10859 -               send_err_msg();
10860 -#endif
10861 -}
10862 -
10863 -
10864 -#ifdef CONFIG_KGDB_THREAD
10865 -
10866 -/* Set the status for a thread */
10867 -void set_thread_msg(void)
10868 -{
10869 -       int threadid;
10870 -       struct task_struct *thread = NULL;
10871 -       char *ptr;
10872 -
10873 -       switch (in_buffer[1]) {
10874 -
10875 -               /* To select which thread for gG etc messages, i.e. supported */
10876 -       case 'g':
10877 -
10878 -               ptr = &in_buffer[2];
10879 -               hex_to_int(&ptr, &threadid);
10880 -               thread = get_thread(threadid);
10881 -
10882 -               /* If we haven't found it */
10883 -               if (!thread) {
10884 -                       send_err_msg();
10885 -                       break;
10886 -               }
10887 -
10888 -               /* Set current_thread (or not) */
10889 -               if (thread == trapped_thread)
10890 -                       current_thread = NULL;
10891 -               else
10892 -                       current_thread = thread;
10893 -               send_ok_msg();
10894 -               break;
10895 -
10896 -       /* To select which thread for cCsS messages, i.e. unsupported */
10897 -       case 'c':
10898 -               send_ok_msg();
10899 -               break;
10900 -
10901 -       default:
10902 -               send_empty_msg();
10903 -               break;
10904 -       }
10905 -}
10906 -
10907 -/* Is a thread alive? */
10908 -static void thread_status_msg(void)
10909 -{
10910 -       char *ptr;
10911 -       int threadid;
10912 -       struct task_struct *thread = NULL;
10913 -
10914 -       ptr = &in_buffer[1];
10915 -       hex_to_int(&ptr, &threadid);
10916 -       thread = get_thread(threadid);
10917 -       if (thread)
10918 -               send_ok_msg();
10919 -       else
10920 -               send_err_msg();
10921 -}
10922 -/* Send the current thread ID */
10923 -static void thread_id_msg(void)
10924 -{
10925 -       int threadid;
10926 -       threadref thref;
10927 -
10928 -       out_buffer[0] = 'Q';
10929 -       out_buffer[1] = 'C';
10930 -
10931 -       if (current_thread)
10932 -               threadid = current_thread->pid;
10933 -       else if (trapped_thread)
10934 -               threadid = trapped_thread->pid;
10935 -       else /* Impossible, but just in case! */
10936 -       {
10937 -               send_err_msg();
10938 -               return;
10939 -       }
10940 -
10941 -       /* Translate pid 0 to PID_MAX for gdb */
10942 -       if (threadid == 0) threadid = PID_MAX;
10943 -
10944 -       int_to_threadref(&thref, threadid);
10945 -       pack_threadid(out_buffer + 2, &thref);
10946 -       out_buffer[2 + BUF_THREAD_ID_SIZE] = '\0';
10947 -       put_packet(out_buffer);
10948 -}
10949 -
10950 -/* Send thread info */
10951 -static void thread_info_msg(void)
10952 -{
10953 -       struct task_struct *thread = NULL;
10954 -       int threadid;
10955 -       char *pos;
10956 -       threadref thref;
10957 -
10958 -       /* Start with 'm' */
10959 -       out_buffer[0] = 'm';
10960 -       pos = &out_buffer[1];
10961 -
10962 -       /* For all possible thread IDs - this will overrun if > 44 threads! */
10963 -       /* Start at 1 and include PID_MAX (since GDB won't use pid 0...) */
10964 -       for (threadid = 1; threadid <= PID_MAX; threadid++) {
10965 -
10966 -               read_lock(&tasklist_lock);
10967 -               thread = get_thread(threadid);
10968 -               read_unlock(&tasklist_lock);
10969 -
10970 -               /* If it's a valid thread */
10971 -               if (thread) {
10972 -                       int_to_threadref(&thref, threadid);
10973 -                       pack_threadid(pos, &thref);
10974 -                       pos += BUF_THREAD_ID_SIZE;
10975 -                       *pos++ = ',';
10976 -               }
10977 -       }
10978 -       *--pos = 0;             /* Lose final comma */
10979 -       put_packet(out_buffer);
10980 -
10981 -}
10982 -
10983 -/* Return printable info for gdb's 'info threads' command */
10984 -static void thread_extra_info_msg(void)
10985 -{
10986 -       int threadid;
10987 -       struct task_struct *thread = NULL;
10988 -       char buffer[20], *ptr;
10989 -       int i;
10990 -
10991 -       /* Extract thread ID */
10992 -       ptr = &in_buffer[17];
10993 -       hex_to_int(&ptr, &threadid);
10994 -       thread = get_thread(threadid);
10995 -
10996 -       /* If we don't recognise it, say so */
10997 -       if (thread == NULL)
10998 -               strcpy(buffer, "(unknown)");
10999 -       else
11000 -               strcpy(buffer, thread->comm);
11001 -
11002 -       /* Construct packet */
11003 -       for (i = 0, ptr = out_buffer; buffer[i]; i++)
11004 -               ptr = pack_hex_byte(ptr, buffer[i]);
11005 -
11006 -       if (thread->thread.pc == (unsigned long)ret_from_fork) {
11007 -               strcpy(buffer, "<new fork>");
11008 -               for (i = 0; buffer[i]; i++)
11009 -                       ptr = pack_hex_byte(ptr, buffer[i]);
11010 -       }
11011 -
11012 -       *ptr = '\0';
11013 -       put_packet(out_buffer);
11014 -}
11015 -
11016 -/* Handle all qFooBarBaz messages - have to use an if statement as
11017 -   opposed to a switch because q messages can have > 1 char id. */
11018 -static void query_msg(void)
11019 -{
11020 -       const char *q_start = &in_buffer[1];
11021 -
11022 -       /* qC = return current thread ID */
11023 -       if (strncmp(q_start, "C", 1) == 0)
11024 -               thread_id_msg();
11025 -
11026 -       /* qfThreadInfo = query all threads (first) */
11027 -       else if (strncmp(q_start, "fThreadInfo", 11) == 0)
11028 -               thread_info_msg();
11029 -
11030 -       /* qsThreadInfo = query all threads (subsequent). We know we have sent
11031 -          them all after the qfThreadInfo message, so there are no to send */
11032 -       else if (strncmp(q_start, "sThreadInfo", 11) == 0)
11033 -               put_packet("l");        /* el = last */
11034 -
11035 -       /* qThreadExtraInfo = supply printable information per thread */
11036 -       else if (strncmp(q_start, "ThreadExtraInfo", 15) == 0)
11037 -               thread_extra_info_msg();
11038 -
11039 -       /* Unsupported - empty message as per spec */
11040 -       else
11041 -               send_empty_msg();
11042 -}
11043 -#endif /* CONFIG_KGDB_THREAD */
11044 -
11045 -/*
11046 - * Bring up the ports..
11047 - */
11048 -static int kgdb_serial_setup(void)
11049 -{
11050 -       extern int kgdb_console_setup(struct console *co, char *options);
11051 -       struct console dummy;
11052 -
11053 -       kgdb_console_setup(&dummy, 0);
11054 -
11055 -       return 0;
11056 -}
11057 -
11058 -/* The command loop, read and act on requests */
11059 -static void kgdb_command_loop(const int excep_code, const int trapa_value)
11060 -{
11061 -       int sigval;
11062 -
11063 -       if (excep_code == NMI_VEC) {
11064 -#ifndef CONFIG_KGDB_NMI
11065 -               KGDB_PRINTK("Ignoring unexpected NMI?\n");
11066 -               return;
11067 -#else /* CONFIG_KGDB_NMI */
11068 -               if (!kgdb_enabled) {
11069 -                       kgdb_enabled = 1;
11070 -                       kgdb_init();
11071 -               }
11072 -#endif /* CONFIG_KGDB_NMI */
11073 -       }
11074 -
11075 -       /* Ignore if we're disabled */
11076 -       if (!kgdb_enabled)
11077 -               return;
11078 -
11079 -#ifdef CONFIG_KGDB_THREAD
11080 -       /* Until GDB specifies a thread */
11081 -       current_thread = NULL;
11082 -       trapped_thread = current;
11083 -#endif
11084 -
11085 -       /* Enter GDB mode (e.g. after detach) */
11086 -       if (!kgdb_in_gdb_mode) {
11087 -               /* Do serial setup, notify user, issue preemptive ack */
11088 -               kgdb_serial_setup();
11089 -               KGDB_PRINTK("Waiting for GDB (on %s%d at %d baud)\n",
11090 -                           (kgdb_porttype ? kgdb_porttype->name : ""),
11091 -                           kgdb_portnum, kgdb_baud);
11092 -               kgdb_in_gdb_mode = 1;
11093 -               put_debug_char('+');
11094 -       }
11095 -
11096 -       /* Reply to host that an exception has occurred */
11097 -       sigval = compute_signal(excep_code);
11098 -       send_signal_msg(sigval);
11099 -
11100 -       /* TRAP_VEC exception indicates a software trap inserted in place of
11101 -          code by GDB so back up PC by one instruction, as this instruction
11102 -          will later be replaced by its original one.  Do NOT do this for
11103 -          trap 0xff, since that indicates a compiled-in breakpoint which
11104 -          will not be replaced (and we would retake the trap forever) */
11105 -       if ((excep_code == TRAP_VEC) && (trapa_value != (0xff << 2))) {
11106 -               trap_registers.pc -= 2;
11107 -       }
11108 -
11109 -       /* Undo any stepping we may have done */
11110 -       undo_single_step();
11111 -
11112 -       while (1) {
11113 -
11114 -               out_buffer[0] = 0;
11115 -               get_packet(in_buffer, BUFMAX);
11116 -
11117 -               /* Examine first char of buffer to see what we need to do */
11118 -               switch (in_buffer[0]) {
11119 -
11120 -               case '?':       /* Send which signal we've received */
11121 -                       send_signal_msg(sigval);
11122 -                       break;
11123 -
11124 -               case 'g':       /* Return the values of the CPU registers */
11125 -                       send_regs_msg();
11126 -                       break;
11127 -
11128 -               case 'G':       /* Set the value of the CPU registers */
11129 -                       set_regs_msg();
11130 -                       break;
11131 -
11132 -               case 'm':       /* Read LLLL bytes address AA..AA */
11133 -                       read_mem_msg();
11134 -                       break;
11135 -
11136 -               case 'M':       /* Write LLLL bytes address AA..AA, ret OK */
11137 -                       write_mem_msg(0);       /* 0 = data in hex */
11138 -                       break;
11139 -
11140 -               case 'X':       /* Write LLLL bytes esc bin address AA..AA */
11141 -                       if (kgdb_bits == '8')
11142 -                               write_mem_msg(1); /* 1 = data in binary */
11143 -                       else
11144 -                               send_empty_msg();
11145 -                       break;
11146 -
11147 -               case 'C':       /* Continue, signum included, we ignore it */
11148 -                       continue_with_sig_msg();
11149 -                       return;
11150 -
11151 -               case 'c':       /* Continue at address AA..AA (optional) */
11152 -                       continue_msg();
11153 -                       return;
11154 -
11155 -               case 'S':       /* Step, signum included, we ignore it */
11156 -                       step_with_sig_msg();
11157 -                       return;
11158 -
11159 -               case 's':       /* Step one instruction from AA..AA */
11160 -                       step_msg();
11161 -                       return;
11162 -
11163 -#ifdef CONFIG_KGDB_THREAD
11164 -
11165 -               case 'H':       /* Task related */
11166 -                       set_thread_msg();
11167 -                       break;
11168 -
11169 -               case 'T':       /* Query thread status */
11170 -                       thread_status_msg();
11171 -                       break;
11172 -
11173 -               case 'q':       /* Handle query - currently thread-related */
11174 -                       query_msg();
11175 -                       break;
11176 -#endif
11177 -
11178 -               case 'k':       /* 'Kill the program' with a kernel ? */
11179 -                       break;
11180 -
11181 -               case 'D':       /* Detach from program, send reply OK */
11182 -                       kgdb_in_gdb_mode = 0;
11183 -                       send_ok_msg();
11184 -                       get_debug_char();
11185 -                       return;
11186 -
11187 -               default:
11188 -                       send_empty_msg();
11189 -                       break;
11190 -               }
11191 -       }
11192 -}
11193 -
11194 -/* There has been an exception, most likely a breakpoint. */
11195 -void kgdb_handle_exception(struct pt_regs *regs)
11196 -{
11197 -       int excep_code, vbr_val;
11198 -       int count;
11199 -       int trapa_value = ctrl_inl(TRA);
11200 -
11201 -       /* Copy kernel regs (from stack) */
11202 -       for (count = 0; count < 16; count++)
11203 -               trap_registers.regs[count] = regs->regs[count];
11204 -       trap_registers.pc = regs->pc;
11205 -       trap_registers.pr = regs->pr;
11206 -       trap_registers.sr = regs->sr;
11207 -       trap_registers.gbr = regs->gbr;
11208 -       trap_registers.mach = regs->mach;
11209 -       trap_registers.macl = regs->macl;
11210 -
11211 -       asm("stc vbr, %0":"=r"(vbr_val));
11212 -       trap_registers.vbr = vbr_val;
11213 -
11214 -       /* Get excode for command loop call, user access */
11215 -       asm("stc r2_bank, %0":"=r"(excep_code));
11216 -       kgdb_excode = excep_code;
11217 -
11218 -       /* Other interesting environment items for reference */
11219 -       asm("stc r6_bank, %0":"=r"(kgdb_g_imask));
11220 -       kgdb_current = current;
11221 -       kgdb_trapa_val = trapa_value;
11222 -
11223 -       /* Act on the exception */
11224 -       kgdb_command_loop(excep_code >> 5, trapa_value);
11225 -
11226 -       kgdb_current = NULL;
11227 -
11228 -       /* Copy back the (maybe modified) registers */
11229 -       for (count = 0; count < 16; count++)
11230 -               regs->regs[count] = trap_registers.regs[count];
11231 -       regs->pc = trap_registers.pc;
11232 -       regs->pr = trap_registers.pr;
11233 -       regs->sr = trap_registers.sr;
11234 -       regs->gbr = trap_registers.gbr;
11235 -       regs->mach = trap_registers.mach;
11236 -       regs->macl = trap_registers.macl;
11237 -
11238 -       vbr_val = trap_registers.vbr;
11239 -       asm("ldc %0, vbr": :"r"(vbr_val));
11240 -
11241 -       return;
11242 -}
11243 -
11244 -/* Trigger a breakpoint by function */
11245 -void breakpoint(void)
11246 -{
11247 -       if (!kgdb_enabled) {
11248 -               kgdb_enabled = 1;
11249 -               kgdb_init();
11250 -       }
11251 -       BREAKPOINT();
11252 -}
11253 -
11254 -/* Initialise the KGDB data structures and serial configuration */
11255 -int kgdb_init(void)
11256 -{
11257 -       if (!kgdb_enabled)
11258 -               return 1;
11259 -
11260 -       in_nmi = 0;
11261 -       kgdb_nofault = 0;
11262 -       stepped_opcode = 0;
11263 -       kgdb_in_gdb_mode = 0;
11264 -
11265 -       if (kgdb_serial_setup() != 0) {
11266 -               KGDB_PRINTK("serial setup error\n");
11267 -               return -1;
11268 -       }
11269 -
11270 -       /* Init ptr to exception handler */
11271 -       kgdb_debug_hook = kgdb_handle_exception;
11272 -       kgdb_bus_err_hook = kgdb_handle_bus_error;
11273 -
11274 -       /* Enter kgdb now if requested, or just report init done */
11275 -       if (kgdb_halt) {
11276 -               kgdb_in_gdb_mode = 1;
11277 -               put_debug_char('+');
11278 -               breakpoint();
11279 -       }
11280 -       else
11281 -       {
11282 -               KGDB_PRINTK("stub is initialized.\n");
11283 -       }
11284 -
11285 -       return 0;
11286 -}
11287 -
11288 -/* Make function available for "user messages"; console will use it too. */
11289 -
11290 -char gdbmsgbuf[BUFMAX];
11291 -#define MAXOUT ((BUFMAX-2)/2)
11292 -
11293 -static void kgdb_msg_write(const char *s, unsigned count)
11294 -{
11295 -       int i;
11296 -       int wcount;
11297 -       char *bufptr;
11298 -
11299 -       /* 'O'utput */
11300 -       gdbmsgbuf[0] = 'O';
11301 -
11302 -       /* Fill and send buffers... */
11303 -       while (count > 0) {
11304 -               bufptr = gdbmsgbuf + 1;
11305 -
11306 -               /* Calculate how many this time */
11307 -               wcount = (count > MAXOUT) ? MAXOUT : count;
11308 -               
11309 -               /* Pack in hex chars */
11310 -               for (i = 0; i < wcount; i++)
11311 -                       bufptr = pack_hex_byte(bufptr, s[i]);
11312 -               *bufptr = '\0';
11313 -
11314 -               /* Move up */
11315 -               s += wcount;
11316 -               count -= wcount;
11317 -
11318 -               /* Write packet */
11319 -               put_packet(gdbmsgbuf);
11320 -       }
11321 -}
11322 -
11323 -static void kgdb_to_gdb(const char *s)
11324 -{
11325 -       kgdb_msg_write(s, strlen(s));
11326 -}
11327 -
11328 -#ifdef CONFIG_SH_KGDB_CONSOLE
11329 -void kgdb_console_write(struct console *co, const char *s, unsigned count)
11330 -{
11331 -       /* Bail if we're not talking to GDB */
11332 -       if (!kgdb_in_gdb_mode)
11333 -               return;
11334 -
11335 -       kgdb_msg_write(s, count);
11336 -}
11337 -#endif
11338 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/setup.c linux-2.6.18.kgdb/arch/sh/kernel/setup.c
11339 --- linux-2.6.18/arch/sh/kernel/setup.c 2006-09-20 07:42:06.000000000 +0400
11340 +++ linux-2.6.18.kgdb/arch/sh/kernel/setup.c    2008-06-10 16:19:47.000000000 +0400
11341 @@ -28,10 +28,6 @@
11342  #include <asm/setup.h>
11343  #include <asm/clock.h>
11344  
11345 -#ifdef CONFIG_SH_KGDB
11346 -#include <asm/kgdb.h>
11347 -static int kgdb_parse_options(char *options);
11348 -#endif
11349  extern void * __rd_start, * __rd_end;
11350  /*
11351   * Machine setup..
11352 @@ -528,93 +524,3 @@ struct seq_operations cpuinfo_op = {
11353         .show   = show_cpuinfo,
11354  };
11355  #endif /* CONFIG_PROC_FS */
11356 -
11357 -#ifdef CONFIG_SH_KGDB
11358 -/*
11359 - * Parse command-line kgdb options.  By default KGDB is enabled,
11360 - * entered on error (or other action) using default serial info.
11361 - * The command-line option can include a serial port specification
11362 - * and an action to override default or configured behavior.
11363 - */
11364 -struct kgdb_sermap kgdb_sci_sermap =
11365 -{ "ttySC", 5, kgdb_sci_setup, NULL };
11366 -
11367 -struct kgdb_sermap *kgdb_serlist = &kgdb_sci_sermap;
11368 -struct kgdb_sermap *kgdb_porttype = &kgdb_sci_sermap;
11369 -
11370 -void kgdb_register_sermap(struct kgdb_sermap *map)
11371 -{
11372 -       struct kgdb_sermap *last;
11373 -
11374 -       for (last = kgdb_serlist; last->next; last = last->next)
11375 -               ;
11376 -       last->next = map;
11377 -       if (!map->namelen) {
11378 -               map->namelen = strlen(map->name);
11379 -       }
11380 -}
11381 -
11382 -static int __init kgdb_parse_options(char *options)
11383 -{
11384 -       char c;
11385 -       int baud;
11386 -
11387 -       /* Check for port spec (or use default) */
11388 -
11389 -       /* Determine port type and instance */
11390 -       if (!memcmp(options, "tty", 3)) {
11391 -               struct kgdb_sermap *map = kgdb_serlist;
11392 -
11393 -               while (map && memcmp(options, map->name, map->namelen))
11394 -                       map = map->next;
11395 -
11396 -               if (!map) {
11397 -                       KGDB_PRINTK("unknown port spec in %s\n", options);
11398 -                       return -1;
11399 -               }
11400 -
11401 -               kgdb_porttype = map;
11402 -               kgdb_serial_setup = map->setup_fn;
11403 -               kgdb_portnum = options[map->namelen] - '0';
11404 -               options += map->namelen + 1;
11405 -
11406 -               options = (*options == ',') ? options+1 : options;
11407 -
11408 -               /* Read optional parameters (baud/parity/bits) */
11409 -               baud = simple_strtoul(options, &options, 10);
11410 -               if (baud != 0) {
11411 -                       kgdb_baud = baud;
11412 -
11413 -                       c = toupper(*options);
11414 -                       if (c == 'E' || c == 'O' || c == 'N') {
11415 -                               kgdb_parity = c;
11416 -                               options++;
11417 -                       }
11418 -
11419 -                       c = *options;
11420 -                       if (c == '7' || c == '8') {
11421 -                               kgdb_bits = c;
11422 -                               options++;
11423 -                       }
11424 -                       options = (*options == ',') ? options+1 : options;
11425 -               }
11426 -       }
11427 -
11428 -       /* Check for action specification */
11429 -       if (!memcmp(options, "halt", 4)) {
11430 -               kgdb_halt = 1;
11431 -               options += 4;
11432 -       } else if (!memcmp(options, "disabled", 8)) {
11433 -               kgdb_enabled = 0;
11434 -               options += 8;
11435 -       }
11436 -
11437 -       if (*options) {
11438 -                KGDB_PRINTK("ignored unknown options: %s\n", options);
11439 -               return 0;
11440 -       }
11441 -       return 1;
11442 -}
11443 -__setup("kgdb=", kgdb_parse_options);
11444 -#endif /* CONFIG_SH_KGDB */
11445 -
11446 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/time.c linux-2.6.18.kgdb/arch/sh/kernel/time.c
11447 --- linux-2.6.18/arch/sh/kernel/time.c  2006-09-20 07:42:06.000000000 +0400
11448 +++ linux-2.6.18.kgdb/arch/sh/kernel/time.c     2008-06-10 16:19:47.000000000 +0400
11449 @@ -184,12 +184,4 @@ void __init time_init(void)
11450          */
11451         sys_timer = get_sys_timer();
11452         printk(KERN_INFO "Using %s for system timer\n", sys_timer->name);
11453 -
11454 -#if defined(CONFIG_SH_KGDB)
11455 -       /*
11456 -        * Set up kgdb as requested. We do it here because the serial
11457 -        * init uses the timer vars we just set up for figuring baud.
11458 -        */
11459 -       kgdb_init();
11460 -#endif
11461  }
11462 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/kernel/traps.c linux-2.6.18.kgdb/arch/sh/kernel/traps.c
11463 --- linux-2.6.18/arch/sh/kernel/traps.c 2006-09-20 07:42:06.000000000 +0400
11464 +++ linux-2.6.18.kgdb/arch/sh/kernel/traps.c    2008-06-10 16:19:47.000000000 +0400
11465 @@ -26,6 +26,7 @@
11466  #include <linux/spinlock.h>
11467  #include <linux/module.h>
11468  #include <linux/kallsyms.h>
11469 +#include <linux/kgdb.h>
11470  
11471  #include <asm/system.h>
11472  #include <asm/uaccess.h>
11473 @@ -34,17 +35,8 @@
11474  #include <asm/processor.h>
11475  #include <asm/sections.h>
11476  
11477 -#ifdef CONFIG_SH_KGDB
11478 -#include <asm/kgdb.h>
11479 -#define CHK_REMOTE_DEBUG(regs)                                               \
11480 -{                                                                            \
11481 -  if ((kgdb_debug_hook != (kgdb_debug_hook_t *) NULL) && (!user_mode(regs))) \
11482 -  {                                                                          \
11483 -    (*kgdb_debug_hook)(regs);                                                \
11484 -  }                                                                          \
11485 -}
11486 -#else
11487 -#define CHK_REMOTE_DEBUG(regs)
11488 +#ifndef CONFIG_KGDB
11489 +#define kgdb_handle_exception(t, s, e, r)
11490  #endif
11491  
11492  #define DO_ERROR(trapnr, signr, str, name, tsk)                                \
11493 @@ -65,7 +57,7 @@ asmlinkage void do_##name(unsigned long 
11494         local_irq_enable();                                             \
11495         tsk->thread.error_code = error_code;                            \
11496         tsk->thread.trap_no = trapnr;                                   \
11497 -        CHK_REMOTE_DEBUG(&regs);                                       \
11498 +       kgdb_handle_exception(trapnr, signr, error_code, &regs);        \
11499         force_sig(signr, tsk);                                          \
11500         die_if_no_fixup(str,&regs,error_code);                          \
11501  }
11502 @@ -92,10 +84,12 @@ void die(const char * str, struct pt_reg
11503  {
11504         static int die_counter;
11505  
11506 +#ifdef CONFIG_KGDB
11507 +       kgdb_handle_exception(1, SIGTRAP, err, regs);
11508 +#endif
11509         console_verbose();
11510         spin_lock_irq(&die_lock);
11511         printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
11512 -       CHK_REMOTE_DEBUG(regs);
11513         show_regs(regs);
11514         spin_unlock_irq(&die_lock);
11515         do_exit(SIGSEGV);
11516 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/mm/extable.c linux-2.6.18.kgdb/arch/sh/mm/extable.c
11517 --- linux-2.6.18/arch/sh/mm/extable.c   2006-09-20 07:42:06.000000000 +0400
11518 +++ linux-2.6.18.kgdb/arch/sh/mm/extable.c      2008-06-10 16:19:47.000000000 +0400
11519 @@ -5,6 +5,7 @@
11520   */
11521  
11522  #include <linux/module.h>
11523 +#include <linux/kgdb.h>
11524  #include <asm/uaccess.h>
11525  
11526  int fixup_exception(struct pt_regs *regs)
11527 @@ -16,6 +17,12 @@ int fixup_exception(struct pt_regs *regs
11528                 regs->pc = fixup->fixup;
11529                 return 1;
11530         }
11531 +#ifdef CONFIG_KGDB
11532 +       if (atomic_read(&debugger_active) && kgdb_may_fault)
11533 +               /* Restore our previous state. */
11534 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
11535 +               /* Never reached. */
11536 +#endif
11537  
11538         return 0;
11539  }
11540 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/mm/fault-nommu.c linux-2.6.18.kgdb/arch/sh/mm/fault-nommu.c
11541 --- linux-2.6.18/arch/sh/mm/fault-nommu.c       2006-09-20 07:42:06.000000000 +0400
11542 +++ linux-2.6.18.kgdb/arch/sh/mm/fault-nommu.c  2008-06-10 16:19:47.000000000 +0400
11543 @@ -29,10 +29,6 @@
11544  #include <asm/mmu_context.h>
11545  #include <asm/cacheflush.h>
11546  
11547 -#if defined(CONFIG_SH_KGDB)
11548 -#include <asm/kgdb.h>
11549 -#endif
11550 -
11551  extern void die(const char *,struct pt_regs *,long);
11552  
11553  /*
11554 @@ -43,11 +39,6 @@ extern void die(const char *,struct pt_r
11555  asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long writeaccess,
11556                               unsigned long address)
11557  {
11558 -#if defined(CONFIG_SH_KGDB)
11559 -       if (kgdb_nofault && kgdb_bus_err_hook)
11560 -               kgdb_bus_err_hook();
11561 -#endif
11562 -
11563         /*
11564          * Oops. The kernel tried to access some bad page. We'll have to
11565          * terminate things with extreme prejudice.
11566 @@ -69,11 +60,6 @@ asmlinkage void do_page_fault(struct pt_
11567  asmlinkage int __do_page_fault(struct pt_regs *regs, unsigned long writeaccess,
11568                                unsigned long address)
11569  {
11570 -#if defined(CONFIG_SH_KGDB)
11571 -       if (kgdb_nofault && kgdb_bus_err_hook)
11572 -               kgdb_bus_err_hook();
11573 -#endif
11574 -
11575         if (address >= TASK_SIZE)
11576                 return 1;
11577  
11578 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/sh/mm/fault.c linux-2.6.18.kgdb/arch/sh/mm/fault.c
11579 --- linux-2.6.18/arch/sh/mm/fault.c     2006-09-20 07:42:06.000000000 +0400
11580 +++ linux-2.6.18.kgdb/arch/sh/mm/fault.c        2008-06-10 16:19:47.000000000 +0400
11581 @@ -28,7 +28,6 @@
11582  #include <asm/pgalloc.h>
11583  #include <asm/mmu_context.h>
11584  #include <asm/cacheflush.h>
11585 -#include <asm/kgdb.h>
11586  
11587  extern void die(const char *,struct pt_regs *,long);
11588  
11589 @@ -45,11 +44,6 @@ asmlinkage void do_page_fault(struct pt_
11590         struct vm_area_struct * vma;
11591         unsigned long page;
11592  
11593 -#ifdef CONFIG_SH_KGDB
11594 -       if (kgdb_nofault && kgdb_bus_err_hook)
11595 -               kgdb_bus_err_hook();
11596 -#endif
11597 -
11598         tsk = current;
11599         mm = tsk->mm;
11600  
11601 @@ -153,6 +147,7 @@ no_context:
11602         }
11603         die("Oops", regs, writeaccess);
11604         do_exit(SIGKILL);
11605 +       dump_stack();
11606  
11607  /*
11608   * We ran out of memory, or some other thing happened to us that made
11609 @@ -202,11 +197,6 @@ asmlinkage int __do_page_fault(struct pt
11610         spinlock_t *ptl;
11611         int ret = 1;
11612  
11613 -#ifdef CONFIG_SH_KGDB
11614 -       if (kgdb_nofault && kgdb_bus_err_hook)
11615 -               kgdb_bus_err_hook();
11616 -#endif
11617 -
11618  #ifdef CONFIG_SH_STORE_QUEUES
11619         addrmax = P4SEG_STORE_QUE + 0x04000000;
11620  #endif
11621 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/x86_64/Kconfig.debug linux-2.6.18.kgdb/arch/x86_64/Kconfig.debug
11622 --- linux-2.6.18/arch/x86_64/Kconfig.debug      2006-09-20 07:42:06.000000000 +0400
11623 +++ linux-2.6.18.kgdb/arch/x86_64/Kconfig.debug 2008-06-10 16:19:41.000000000 +0400
11624 @@ -55,7 +55,4 @@ config DEBUG_STACK_USAGE
11625  
11626           This option will slow down process creation somewhat.
11627  
11628 -#config X86_REMOTE_DEBUG
11629 -#       bool "kgdb debugging stub"
11630 -
11631  endmenu
11632 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/x86_64/kernel/Makefile linux-2.6.18.kgdb/arch/x86_64/kernel/Makefile
11633 --- linux-2.6.18/arch/x86_64/kernel/Makefile    2006-09-20 07:42:06.000000000 +0400
11634 +++ linux-2.6.18.kgdb/arch/x86_64/kernel/Makefile       2008-06-10 16:19:41.000000000 +0400
11635 @@ -33,6 +33,7 @@ obj-$(CONFIG_IOMMU)           += pci-gart.o apert
11636  obj-$(CONFIG_CALGARY_IOMMU)    += pci-calgary.o tce.o
11637  obj-$(CONFIG_SWIOTLB)          += pci-swiotlb.o
11638  obj-$(CONFIG_KPROBES)          += kprobes.o
11639 +obj-$(CONFIG_KGDB)             += kgdb.o kgdb-jmp.o
11640  obj-$(CONFIG_X86_PM_TIMER)     += pmtimer.o
11641  obj-$(CONFIG_X86_VSMP)         += vsmp.o
11642  obj-$(CONFIG_K8_NB)            += k8.o
11643 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/x86_64/kernel/entry.S linux-2.6.18.kgdb/arch/x86_64/kernel/entry.S
11644 --- linux-2.6.18/arch/x86_64/kernel/entry.S     2006-09-20 07:42:06.000000000 +0400
11645 +++ linux-2.6.18.kgdb/arch/x86_64/kernel/entry.S        2008-06-10 16:19:58.000000000 +0400
11646 @@ -42,6 +42,7 @@
11647  #include <asm/hw_irq.h>
11648  #include <asm/page.h>
11649  #include <asm/irqflags.h>
11650 +#include <asm/kgdb.h>
11651  
11652         .code64
11653  
11654 @@ -881,6 +882,7 @@ error_exit:         
11655         RESTORE_ARGS 0,8,0                                              
11656         jmp iret_label
11657         CFI_ENDPROC
11658 +       CFI_END_FRAME(kernel_thread)
11659  
11660  error_kernelspace:
11661         incl %ebx
11662 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/x86_64/kernel/kgdb-jmp.S linux-2.6.18.kgdb/arch/x86_64/kernel/kgdb-jmp.S
11663 --- linux-2.6.18/arch/x86_64/kernel/kgdb-jmp.S  1970-01-01 03:00:00.000000000 +0300
11664 +++ linux-2.6.18.kgdb/arch/x86_64/kernel/kgdb-jmp.S     2008-06-10 16:19:41.000000000 +0400
11665 @@ -0,0 +1,65 @@
11666 +/*
11667 + * arch/x86_64/kernel/kgdb-jmp.S
11668 + *
11669 + * Save and restore system registers so that within a limited frame we
11670 + * may have a fault and "jump back" to a known safe location.
11671 + *
11672 + * Author: Tom Rini <trini@kernel.crashing.org>
11673 + *
11674 + * Cribbed from glibc, which carries the following:
11675 + * Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
11676 + * Copyright (C) 2005 by MontaVista Software.
11677 + *
11678 + * This file is licensed under the terms of the GNU General Public License
11679 + * version 2. This program as licensed "as is" without any warranty of
11680 + * any kind, whether express or implied.
11681 + */
11682 +
11683 +#include <linux/linkage.h>
11684 +
11685 +#define JB_RBX         0
11686 +#define JB_RBP         1
11687 +#define JB_R12         2
11688 +#define JB_R13         3
11689 +#define JB_R14         4
11690 +#define JB_R15         5
11691 +#define JB_RSP         6
11692 +#define JB_PC          7
11693 +
11694 +       .code64
11695 +
11696 +/* This must be called prior to kgdb_fault_longjmp and
11697 + * kgdb_fault_longjmp must not be called outside of the context of the
11698 + * last call to kgdb_fault_setjmp.
11699 + */
11700 +ENTRY(kgdb_fault_setjmp)
11701 +       /* Save registers. */
11702 +       movq %rbx, (JB_RBX*8)(%rdi)
11703 +       movq %rbp, (JB_RBP*8)(%rdi)
11704 +       movq %r12, (JB_R12*8)(%rdi)
11705 +       movq %r13, (JB_R13*8)(%rdi)
11706 +       movq %r14, (JB_R14*8)(%rdi)
11707 +       movq %r15, (JB_R15*8)(%rdi)
11708 +       leaq 8(%rsp), %rdx      /* Save SP as it will be after we return. */
11709 +       movq %rdx, (JB_RSP*8)(%rdi)
11710 +       movq (%rsp), %rax       /* Save PC we are returning to now. */
11711 +       movq %rax, (JB_PC*8)(%rdi)
11712 +       /* Set return value for setjmp. */
11713 +       mov $0,%eax
11714 +       movq (JB_PC*8)(%rdi),%rdx
11715 +       movq (JB_RSP*8)(%rdi),%rsp
11716 +       jmpq *%rdx
11717 +
11718 +ENTRY(kgdb_fault_longjmp)
11719 +       /* Restore registers. */
11720 +       movq (JB_RBX*8)(%rdi),%rbx
11721 +       movq (JB_RBP*8)(%rdi),%rbp
11722 +       movq (JB_R12*8)(%rdi),%r12
11723 +       movq (JB_R13*8)(%rdi),%r13
11724 +       movq (JB_R14*8)(%rdi),%r14
11725 +       movq (JB_R15*8)(%rdi),%r15
11726 +       /* Set return value for setjmp. */
11727 +       movq (JB_PC*8)(%rdi),%rdx
11728 +       movq (JB_RSP*8)(%rdi),%rsp
11729 +       mov $1,%eax
11730 +       jmpq *%rdx
11731 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/x86_64/kernel/kgdb.c linux-2.6.18.kgdb/arch/x86_64/kernel/kgdb.c
11732 --- linux-2.6.18/arch/x86_64/kernel/kgdb.c      1970-01-01 03:00:00.000000000 +0300
11733 +++ linux-2.6.18.kgdb/arch/x86_64/kernel/kgdb.c 2008-06-10 16:19:41.000000000 +0400
11734 @@ -0,0 +1,474 @@
11735 +/*
11736 + *
11737 + * This program is free software; you can redistribute it and/or modify it
11738 + * under the terms of the GNU General Public License as published by the
11739 + * Free Software Foundation; either version 2, or (at your option) any
11740 + * later version.
11741 + *
11742 + * This program is distributed in the hope that it will be useful, but
11743 + * WITHOUT ANY WARRANTY; without even the implied warranty of
11744 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11745 + * General Public License for more details.
11746 + *
11747 + */
11748 +
11749 +/*
11750 + * Copyright (C) 2004 Amit S. Kale <amitkale@linsyssoft.com>
11751 + * Copyright (C) 2000-2001 VERITAS Software Corporation.
11752 + * Copyright (C) 2002 Andi Kleen, SuSE Labs
11753 + * Copyright (C) 2004 LinSysSoft Technologies Pvt. Ltd.
11754 + */
11755 +/****************************************************************************
11756 + *  Contributor:     Lake Stevens Instrument Division$
11757 + *  Written by:      Glenn Engel $
11758 + *  Updated by:             Amit Kale<akale@veritas.com>
11759 + *  Modified for 386 by Jim Kingdon, Cygnus Support.
11760 + *  Origianl kgdb, compatibility with 2.1.xx kernel by
11761 + *  David Grothe <dave@gcom.com>
11762 + *  Integrated into 2.2.5 kernel by Tigran Aivazian <tigran@sco.com>
11763 + *  X86_64 changes from Andi Kleen's patch merged by Jim Houston
11764 + */
11765 +
11766 +#include <linux/string.h>
11767 +#include <linux/kernel.h>
11768 +#include <linux/sched.h>
11769 +#include <linux/smp.h>
11770 +#include <linux/spinlock.h>
11771 +#include <linux/delay.h>
11772 +#include <asm/system.h>
11773 +#include <asm/ptrace.h>                /* for linux pt_regs struct */
11774 +#include <linux/kgdb.h>
11775 +#include <linux/init.h>
11776 +#include <asm/apicdef.h>
11777 +#include <asm/mach_apic.h>
11778 +#include <asm/kdebug.h>
11779 +#include <asm/debugreg.h>
11780 +
11781 +/* Put the error code here just in case the user cares.  */
11782 +int gdb_x86_64errcode;
11783 +/* Likewise, the vector number here (since GDB only gets the signal
11784 +   number through the usual means, and that's not very specific).  */
11785 +int gdb_x86_64vector = -1;
11786 +
11787 +extern atomic_t cpu_doing_single_step;
11788 +
11789 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
11790 +{
11791 +       gdb_regs[_RAX] = regs->rax;
11792 +       gdb_regs[_RBX] = regs->rbx;
11793 +       gdb_regs[_RCX] = regs->rcx;
11794 +       gdb_regs[_RDX] = regs->rdx;
11795 +       gdb_regs[_RSI] = regs->rsi;
11796 +       gdb_regs[_RDI] = regs->rdi;
11797 +       gdb_regs[_RBP] = regs->rbp;
11798 +       gdb_regs[_PS] = regs->eflags;
11799 +       gdb_regs[_PC] = regs->rip;
11800 +       gdb_regs[_R8] = regs->r8;
11801 +       gdb_regs[_R9] = regs->r9;
11802 +       gdb_regs[_R10] = regs->r10;
11803 +       gdb_regs[_R11] = regs->r11;
11804 +       gdb_regs[_R12] = regs->r12;
11805 +       gdb_regs[_R13] = regs->r13;
11806 +       gdb_regs[_R14] = regs->r14;
11807 +       gdb_regs[_R15] = regs->r15;
11808 +       gdb_regs[_RSP] = regs->rsp;
11809 +}
11810 +
11811 +extern void thread_return(void);
11812 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
11813 +{
11814 +       gdb_regs[_RAX] = 0;
11815 +       gdb_regs[_RBX] = 0;
11816 +       gdb_regs[_RCX] = 0;
11817 +       gdb_regs[_RDX] = 0;
11818 +       gdb_regs[_RSI] = 0;
11819 +       gdb_regs[_RDI] = 0;
11820 +       gdb_regs[_RBP] = *(unsigned long *)p->thread.rsp;
11821 +       gdb_regs[_PS] = *(unsigned long *)(p->thread.rsp + 8);
11822 +       gdb_regs[_PC] = (unsigned long)&thread_return;
11823 +       gdb_regs[_R8] = 0;
11824 +       gdb_regs[_R9] = 0;
11825 +       gdb_regs[_R10] = 0;
11826 +       gdb_regs[_R11] = 0;
11827 +       gdb_regs[_R12] = 0;
11828 +       gdb_regs[_R13] = 0;
11829 +       gdb_regs[_R14] = 0;
11830 +       gdb_regs[_R15] = 0;
11831 +       gdb_regs[_RSP] = p->thread.rsp;
11832 +}
11833 +
11834 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
11835 +{
11836 +       regs->rax = gdb_regs[_RAX];
11837 +       regs->rbx = gdb_regs[_RBX];
11838 +       regs->rcx = gdb_regs[_RCX];
11839 +       regs->rdx = gdb_regs[_RDX];
11840 +       regs->rsi = gdb_regs[_RSI];
11841 +       regs->rdi = gdb_regs[_RDI];
11842 +       regs->rbp = gdb_regs[_RBP];
11843 +       regs->eflags = gdb_regs[_PS];
11844 +       regs->rip = gdb_regs[_PC];
11845 +       regs->r8 = gdb_regs[_R8];
11846 +       regs->r9 = gdb_regs[_R9];
11847 +       regs->r10 = gdb_regs[_R10];
11848 +       regs->r11 = gdb_regs[_R11];
11849 +       regs->r12 = gdb_regs[_R12];
11850 +       regs->r13 = gdb_regs[_R13];
11851 +       regs->r14 = gdb_regs[_R14];
11852 +       regs->r15 = gdb_regs[_R15];
11853 +#if 0                          /* can't change these */
11854 +       regs->rsp = gdb_regs[_RSP];
11855 +       regs->ss = gdb_regs[_SS];
11856 +       regs->fs = gdb_regs[_FS];
11857 +       regs->gs = gdb_regs[_GS];
11858 +#endif
11859 +
11860 +}                              /* gdb_regs_to_regs */
11861 +
11862 +struct hw_breakpoint {
11863 +       unsigned enabled;
11864 +       unsigned type;
11865 +       unsigned len;
11866 +       unsigned long addr;
11867 +} breakinfo[4] = { {
11868 +enabled:0}, {
11869 +enabled:0}, {
11870 +enabled:0}, {
11871 +enabled:0}};
11872 +
11873 +void kgdb_correct_hw_break(void)
11874 +{
11875 +       int breakno;
11876 +       int correctit;
11877 +       int breakbit;
11878 +       unsigned long dr7;
11879 +
11880 +       asm volatile ("movq %%db7, %0\n":"=r" (dr7):);
11881 +       do {
11882 +               unsigned long addr0, addr1, addr2, addr3;
11883 +               asm volatile ("movq %%db0, %0\n"
11884 +                             "movq %%db1, %1\n"
11885 +                             "movq %%db2, %2\n"
11886 +                             "movq %%db3, %3\n":"=r" (addr0), "=r"(addr1),
11887 +                             "=r"(addr2), "=r"(addr3):);
11888 +       } while (0);
11889 +       correctit = 0;
11890 +       for (breakno = 0; breakno < 3; breakno++) {
11891 +               breakbit = 2 << (breakno << 1);
11892 +               if (!(dr7 & breakbit) && breakinfo[breakno].enabled) {
11893 +                       correctit = 1;
11894 +                       dr7 |= breakbit;
11895 +                       dr7 &= ~(0xf0000 << (breakno << 2));
11896 +                       dr7 |= (((breakinfo[breakno].len << 2) |
11897 +                                breakinfo[breakno].type) << 16) <<
11898 +                           (breakno << 2);
11899 +                       switch (breakno) {
11900 +                       case 0:
11901 +                               asm volatile ("movq %0, %%dr0\n"::"r"
11902 +                                             (breakinfo[breakno].addr));
11903 +                               break;
11904 +
11905 +                       case 1:
11906 +                               asm volatile ("movq %0, %%dr1\n"::"r"
11907 +                                             (breakinfo[breakno].addr));
11908 +                               break;
11909 +
11910 +                       case 2:
11911 +                               asm volatile ("movq %0, %%dr2\n"::"r"
11912 +                                             (breakinfo[breakno].addr));
11913 +                               break;
11914 +
11915 +                       case 3:
11916 +                               asm volatile ("movq %0, %%dr3\n"::"r"
11917 +                                             (breakinfo[breakno].addr));
11918 +                               break;
11919 +                       }
11920 +               } else if ((dr7 & breakbit) && !breakinfo[breakno].enabled) {
11921 +                       correctit = 1;
11922 +                       dr7 &= ~breakbit;
11923 +                       dr7 &= ~(0xf0000 << (breakno << 2));
11924 +               }
11925 +       }
11926 +       if (correctit) {
11927 +               asm volatile ("movq %0, %%db7\n"::"r" (dr7));
11928 +       }
11929 +}
11930 +
11931 +int kgdb_remove_hw_break(unsigned long addr)
11932 +{
11933 +       int i, idx = -1;
11934 +       for (i = 0; i < 4; i++) {
11935 +               if (breakinfo[i].addr == addr && breakinfo[i].enabled) {
11936 +                       idx = i;
11937 +                       break;
11938 +               }
11939 +       }
11940 +       if (idx == -1)
11941 +               return -1;
11942 +
11943 +       breakinfo[idx].enabled = 0;
11944 +       return 0;
11945 +}
11946 +
11947 +int kgdb_set_hw_break(unsigned long addr)
11948 +{
11949 +       int i, idx = -1;
11950 +       for (i = 0; i < 4; i++) {
11951 +               if (!breakinfo[i].enabled) {
11952 +                       idx = i;
11953 +                       break;
11954 +               }
11955 +       }
11956 +       if (idx == -1)
11957 +               return -1;
11958 +
11959 +       breakinfo[idx].enabled = 1;
11960 +       breakinfo[idx].type = 1;
11961 +       breakinfo[idx].len = 1;
11962 +       breakinfo[idx].addr = addr;
11963 +       return 0;
11964 +}
11965 +
11966 +int remove_hw_break(unsigned breakno)
11967 +{
11968 +       if (!breakinfo[breakno].enabled) {
11969 +               return -1;
11970 +       }
11971 +       breakinfo[breakno].enabled = 0;
11972 +       return 0;
11973 +}
11974 +
11975 +int set_hw_break(unsigned breakno, unsigned type, unsigned len, unsigned addr)
11976 +{
11977 +       if (breakinfo[breakno].enabled) {
11978 +               return -1;
11979 +       }
11980 +       breakinfo[breakno].enabled = 1;
11981 +       breakinfo[breakno].type = type;
11982 +       breakinfo[breakno].len = len;
11983 +       breakinfo[breakno].addr = addr;
11984 +       return 0;
11985 +}
11986 +
11987 +void kgdb_disable_hw_debug(struct pt_regs *regs)
11988 +{
11989 +       /* Disable hardware debugging while we are in kgdb */
11990 +       asm volatile ("movq %0,%%db7": /* no output */ :"r" (0UL));
11991 +}
11992 +
11993 +void kgdb_post_master_code(struct pt_regs *regs, int e_vector, int err_code)
11994 +{
11995 +       /* Master processor is completely in the debugger */
11996 +       gdb_x86_64vector = e_vector;
11997 +       gdb_x86_64errcode = err_code;
11998 +}
11999 +
12000 +void kgdb_roundup_cpus(unsigned long flags)
12001 +{
12002 +       send_IPI_allbutself(APIC_DM_NMI);
12003 +}
12004 +
12005 +int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
12006 +                              char *remcomInBuffer, char *remcomOutBuffer,
12007 +                              struct pt_regs *linux_regs)
12008 +{
12009 +       unsigned long addr, length;
12010 +       unsigned long breakno, breaktype;
12011 +       char *ptr;
12012 +       int newPC;
12013 +       unsigned long dr6;
12014 +
12015 +       switch (remcomInBuffer[0]) {
12016 +       case 'c':
12017 +       case 's':
12018 +               /* try to read optional parameter, pc unchanged if no parm */
12019 +               ptr = &remcomInBuffer[1];
12020 +               if (kgdb_hex2long(&ptr, &addr))
12021 +                       linux_regs->rip = addr;
12022 +               newPC = linux_regs->rip;
12023 +
12024 +               /* clear the trace bit */
12025 +               linux_regs->eflags &= ~TF_MASK;
12026 +
12027 +               atomic_set(&cpu_doing_single_step, -1);
12028 +               /* set the trace bit if we're stepping */
12029 +               if (remcomInBuffer[0] == 's') {
12030 +                       linux_regs->eflags |= TF_MASK;
12031 +                       debugger_step = 1;
12032 +                       if (kgdb_contthread)
12033 +                               atomic_set(&cpu_doing_single_step,
12034 +                                          smp_processor_id());
12035 +
12036 +               }
12037 +
12038 +               asm volatile ("movq %%db6, %0\n":"=r" (dr6));
12039 +               if (!(dr6 & 0x4000)) {
12040 +                       for (breakno = 0; breakno < 4; ++breakno) {
12041 +                               if (dr6 & (1 << breakno)) {
12042 +                                       if (breakinfo[breakno].type == 0) {
12043 +                                               /* Set restore flag */
12044 +                                               linux_regs->eflags |=
12045 +                                                   X86_EFLAGS_RF;
12046 +                                               break;
12047 +                                       }
12048 +                               }
12049 +                       }
12050 +               }
12051 +               kgdb_correct_hw_break();
12052 +               asm volatile ("movq %0, %%db6\n"::"r" (0UL));
12053 +
12054 +               return (0);
12055 +
12056 +       case 'Y':
12057 +               ptr = &remcomInBuffer[1];
12058 +               kgdb_hex2long(&ptr, &breakno);
12059 +               ptr++;
12060 +               kgdb_hex2long(&ptr, &breaktype);
12061 +               ptr++;
12062 +               kgdb_hex2long(&ptr, &length);
12063 +               ptr++;
12064 +               kgdb_hex2long(&ptr, &addr);
12065 +               if (set_hw_break(breakno & 0x3, breaktype & 0x3,
12066 +                                length & 0x3, addr) == 0)
12067 +                       strcpy(remcomOutBuffer, "OK");
12068 +               else
12069 +                       strcpy(remcomOutBuffer, "ERROR");
12070 +               break;
12071 +
12072 +               /* Remove hardware breakpoint */
12073 +       case 'y':
12074 +               ptr = &remcomInBuffer[1];
12075 +               kgdb_hex2long(&ptr, &breakno);
12076 +               if (remove_hw_break(breakno & 0x3) == 0)
12077 +                       strcpy(remcomOutBuffer, "OK");
12078 +               else
12079 +                       strcpy(remcomOutBuffer, "ERROR");
12080 +               break;
12081 +
12082 +       }                       /* switch */
12083 +       return -1;
12084 +}
12085 +
12086 +static struct pt_regs *in_interrupt_stack(unsigned long rsp, int cpu)
12087 +{
12088 +       struct pt_regs *regs;
12089 +       unsigned long end = (unsigned long)cpu_pda(cpu)->irqstackptr;
12090 +       if (rsp <= end && rsp >= end - IRQSTACKSIZE + 8) {
12091 +               regs = *(((struct pt_regs **)end) - 1);
12092 +               return regs;
12093 +       }
12094 +       return NULL;
12095 +}
12096 +
12097 +static struct pt_regs *in_exception_stack(unsigned long rsp, int cpu)
12098 +{
12099 +       int i;
12100 +       struct tss_struct *init_tss = &__get_cpu_var(init_tss);
12101 +       for (i = 0; i < N_EXCEPTION_STACKS; i++)
12102 +               if (rsp >= init_tss[cpu].ist[i] &&
12103 +                   rsp <= init_tss[cpu].ist[i] + EXCEPTION_STKSZ) {
12104 +                       struct pt_regs *r =
12105 +                           (void *)init_tss[cpu].ist[i] + EXCEPTION_STKSZ;
12106 +                       return r - 1;
12107 +               }
12108 +       return NULL;
12109 +}
12110 +
12111 +void kgdb_shadowinfo(struct pt_regs *regs, char *buffer, unsigned threadid)
12112 +{
12113 +       static char intr_desc[] = "Stack at interrupt entrypoint";
12114 +       static char exc_desc[] = "Stack at exception entrypoint";
12115 +       struct pt_regs *stregs;
12116 +       int cpu = hard_smp_processor_id();
12117 +
12118 +       if ((stregs = in_interrupt_stack(regs->rsp, cpu)))
12119 +               kgdb_mem2hex(intr_desc, buffer, strlen(intr_desc));
12120 +       else if ((stregs = in_exception_stack(regs->rsp, cpu)))
12121 +               kgdb_mem2hex(exc_desc, buffer, strlen(exc_desc));
12122 +}
12123 +
12124 +struct task_struct *kgdb_get_shadow_thread(struct pt_regs *regs, int threadid)
12125 +{
12126 +       struct pt_regs *stregs;
12127 +       int cpu = hard_smp_processor_id();
12128 +
12129 +       if ((stregs = in_interrupt_stack(regs->rsp, cpu)))
12130 +               return current;
12131 +       else if ((stregs = in_exception_stack(regs->rsp, cpu)))
12132 +               return current;
12133 +
12134 +       return NULL;
12135 +}
12136 +
12137 +struct pt_regs *kgdb_shadow_regs(struct pt_regs *regs, int threadid)
12138 +{
12139 +       struct pt_regs *stregs;
12140 +       int cpu = hard_smp_processor_id();
12141 +
12142 +       if ((stregs = in_interrupt_stack(regs->rsp, cpu)))
12143 +               return stregs;
12144 +       else if ((stregs = in_exception_stack(regs->rsp, cpu)))
12145 +               return stregs;
12146 +
12147 +       return NULL;
12148 +}
12149 +
12150 +/* Register KGDB with the die_chain so that we hook into all of the right
12151 + * spots. */
12152 +static int kgdb_notify(struct notifier_block *self, unsigned long cmd,
12153 +                      void *ptr)
12154 +{
12155 +       struct die_args *args = ptr;
12156 +       struct pt_regs *regs = args->regs;
12157 +
12158 +       if (cmd == DIE_PAGE_FAULT_NO_CONTEXT && atomic_read(&debugger_active)
12159 +                       && kgdb_may_fault) {
12160 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
12161 +               return NOTIFY_STOP;
12162 +       /* CPU roundup? */
12163 +       } else if (atomic_read(&debugger_active) && cmd == DIE_NMI_IPI) {
12164 +               kgdb_nmihook(smp_processor_id(), regs);
12165 +               return NOTIFY_STOP;
12166 +               /* See if KGDB is interested. */
12167 +       } else if (cmd == DIE_PAGE_FAULT || user_mode(regs) ||
12168 +                  cmd == DIE_NMI_IPI || (cmd == DIE_DEBUG &&
12169 +                                         atomic_read(&debugger_active)))
12170 +               /* Userpace events, normal watchdog event, or spurious
12171 +                * debug exception.  Ignore. */
12172 +               return NOTIFY_DONE;
12173 +
12174 +       kgdb_handle_exception(args->trapnr, args->signr, args->err, regs);
12175 +
12176 +       return NOTIFY_STOP;
12177 +}
12178 +
12179 +static struct notifier_block kgdb_notifier = {
12180 +       .notifier_call = kgdb_notify,
12181 +       .priority = 0x7fffffff, /* we need to notified first */
12182 +};
12183 +
12184 +int kgdb_arch_init(void)
12185 +{
12186 +       atomic_notifier_chain_register(&die_chain, &kgdb_notifier);
12187 +       return 0;
12188 +}
12189 +/*
12190 + * Skip an int3 exception when it occurs after a breakpoint has been
12191 + * removed. Backtrack eip by 1 since the int3 would have caused it to
12192 + * increment by 1.
12193 + */
12194 +
12195 +int kgdb_skipexception(int exception, struct pt_regs *regs)
12196 +{
12197 +       if (exception == 3 && kgdb_isremovedbreak(regs->rip - 1)) {
12198 +               regs->rip -= 1;
12199 +               return 1;
12200 +       }
12201 +       return 0;
12202 +}
12203 +
12204 +struct kgdb_arch arch_kgdb_ops = {
12205 +       .gdb_bpt_instr = {0xcc},
12206 +       .flags = KGDB_HW_BREAKPOINT,
12207 +       .shadowth = 1,
12208 +};
12209 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/arch/x86_64/mm/fault.c linux-2.6.18.kgdb/arch/x86_64/mm/fault.c
12210 --- linux-2.6.18/arch/x86_64/mm/fault.c 2006-09-20 07:42:06.000000000 +0400
12211 +++ linux-2.6.18.kgdb/arch/x86_64/mm/fault.c    2008-06-10 16:19:36.000000000 +0400
12212 @@ -557,6 +557,10 @@ no_context:
12213         if (is_errata93(regs, address))
12214                 return; 
12215  
12216 +       if (notify_die(DIE_PAGE_FAULT_NO_CONTEXT, "no context", regs,
12217 +                               error_code, 14, SIGSEGV) == NOTIFY_STOP)
12218 +               return;
12219 +
12220  /*
12221   * Oops. The kernel tried to access some bad page. We'll have to
12222   * terminate things with extreme prejudice.
12223 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/char/keyboard.c linux-2.6.18.kgdb/drivers/char/keyboard.c
12224 --- linux-2.6.18/drivers/char/keyboard.c        2006-09-20 07:42:06.000000000 +0400
12225 +++ linux-2.6.18.kgdb/drivers/char/keyboard.c   2008-06-10 16:20:02.000000000 +0400
12226 @@ -1174,6 +1174,7 @@ static void kbd_keycode(unsigned int key
12227                 sysrq_down = 0;
12228         if (sysrq_down && down && !rep) {
12229                 handle_sysrq(kbd_sysrq_xlate[keycode], regs, tty);
12230 +               sysrq_down = 0;         /* In case we miss the 'up' event. */
12231                 return;
12232         }
12233  #endif
12234 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/net/Makefile linux-2.6.18.kgdb/drivers/net/Makefile
12235 --- linux-2.6.18/drivers/net/Makefile   2006-09-20 07:42:06.000000000 +0400
12236 +++ linux-2.6.18.kgdb/drivers/net/Makefile      2008-06-10 16:19:13.000000000 +0400
12237 @@ -216,6 +216,7 @@ obj-$(CONFIG_ETRAX_ETHERNET) += cris/
12238  obj-$(CONFIG_ENP2611_MSF_NET) += ixp2000/
12239  
12240  obj-$(CONFIG_NETCONSOLE) += netconsole.o
12241 +obj-$(CONFIG_KGDBOE) += kgdboe.o
12242  
12243  obj-$(CONFIG_FS_ENET) += fs_enet/
12244  
12245 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/net/kgdboe.c linux-2.6.18.kgdb/drivers/net/kgdboe.c
12246 --- linux-2.6.18/drivers/net/kgdboe.c   1970-01-01 03:00:00.000000000 +0300
12247 +++ linux-2.6.18.kgdb/drivers/net/kgdboe.c      2008-06-10 16:19:13.000000000 +0400
12248 @@ -0,0 +1,294 @@
12249 +/*
12250 + * drivers/net/kgdboe.c
12251 + *
12252 + * A network interface for GDB.
12253 + * Based upon 'gdbserial' by David Grothe <dave@gcom.com>
12254 + * and Scott Foehner <sfoehner@engr.sgi.com>
12255 + *
12256 + * Maintainers: Amit S. Kale <amitkale@linsyssoft.com> and
12257 + *             Tom Rini <trini@kernel.crashing.org>
12258 + *
12259 + * 2004 (c) Amit S. Kale <amitkale@linsyssoft.com>
12260 + * 2004-2005 (c) MontaVista Software, Inc.
12261 + * 2005 (c) Wind River Systems, Inc.
12262 + *
12263 + * Contributors at various stages not listed above:
12264 + * San Mehat <nettwerk@biodome.org>, Robert Walsh <rjwalsh@durables.org>,
12265 + * wangdi <wangdi@clusterfs.com>, Matt Mackall <mpm@selenic.com>,
12266 + * Pavel Machek <pavel@suse.cz>, Jason Wessel <jason.wessel@windriver.com>
12267 + *
12268 + * This file is licensed under the terms of the GNU General Public License
12269 + * version 2. This program is licensed "as is" without any warranty of any
12270 + * kind, whether express or implied.
12271 + */
12272 +
12273 +#include <linux/kernel.h>
12274 +#include <linux/interrupt.h>
12275 +#include <linux/string.h>
12276 +#include <linux/kgdb.h>
12277 +#include <linux/netpoll.h>
12278 +#include <linux/init.h>
12279 +
12280 +#include <asm/atomic.h>
12281 +
12282 +#define IN_BUF_SIZE 512                /* power of 2, please */
12283 +#define NOT_CONFIGURED_STRING "not_configured"
12284 +#define OUT_BUF_SIZE 30                /* We don't want to send too big of a packet. */
12285 +#define MAX_KGDBOE_CONFIG_STR 256
12286 +
12287 +static char in_buf[IN_BUF_SIZE], out_buf[OUT_BUF_SIZE];
12288 +static int in_head, in_tail, out_count;
12289 +static atomic_t in_count;
12290 +/* 0 = unconfigured, 1 = netpoll options parsed, 2 = fully configured. */
12291 +static int configured;
12292 +static struct kgdb_io local_kgdb_io_ops;
12293 +static int use_dynamic_mac;
12294 +
12295 +MODULE_DESCRIPTION("KGDB driver for network interfaces");
12296 +MODULE_LICENSE("GPL");
12297 +static char config[MAX_KGDBOE_CONFIG_STR] = NOT_CONFIGURED_STRING;
12298 +static struct kparam_string kps = {
12299 +       .string = config,
12300 +       .maxlen = MAX_KGDBOE_CONFIG_STR,
12301 +};
12302 +
12303 +static void rx_hook(struct netpoll *np, int port, char *msg, int len,
12304 +                   struct sk_buff *skb)
12305 +{
12306 +       int i;
12307 +
12308 +       np->remote_port = port;
12309 +
12310 +       /* Copy the MAC address if we need to. */
12311 +       if (use_dynamic_mac) {
12312 +               memcpy(np->remote_mac, eth_hdr(skb)->h_source,
12313 +                               sizeof(np->remote_mac));
12314 +               use_dynamic_mac = 0;
12315 +       }
12316 +
12317 +       /*
12318 +        * This could be GDB trying to attach.  But it could also be GDB
12319 +        * finishing up a session, with kgdb_connected=0 but GDB sending
12320 +        * an ACK for the final packet.  To make sure we don't try and
12321 +        * make a breakpoint when GDB is leaving, make sure that if
12322 +        * !kgdb_connected the only len == 1 packet we allow is ^C.
12323 +        */
12324 +       if (!kgdb_connected && (len != 1 || msg[0] == 3) &&
12325 +           !atomic_read(&kgdb_setting_breakpoint)) {
12326 +               tasklet_schedule(&kgdb_tasklet_breakpoint);
12327 +       }
12328 +
12329 +       for (i = 0; i < len; i++) {
12330 +               if (msg[i] == 3)
12331 +                       tasklet_schedule(&kgdb_tasklet_breakpoint);
12332 +
12333 +               if (atomic_read(&in_count) >= IN_BUF_SIZE) {
12334 +                       /* buffer overflow, clear it */
12335 +                       in_head = in_tail = 0;
12336 +                       atomic_set(&in_count, 0);
12337 +                       break;
12338 +               }
12339 +               in_buf[in_head++] = msg[i];
12340 +               in_head &= (IN_BUF_SIZE - 1);
12341 +               atomic_inc(&in_count);
12342 +       }
12343 +}
12344 +
12345 +static struct netpoll np = {
12346 +       .dev_name = "eth0",
12347 +       .name = "kgdboe",
12348 +       .rx_hook = rx_hook,
12349 +       .local_port = 6443,
12350 +       .remote_port = 6442,
12351 +       .remote_mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
12352 +};
12353 +
12354 +static void eth_pre_exception_handler(void)
12355 +{
12356 +       /* Increment the module count when the debugger is active */
12357 +       if (!kgdb_connected)
12358 +               try_module_get(THIS_MODULE);
12359 +       netpoll_set_trap(1);
12360 +}
12361 +
12362 +static void eth_post_exception_handler(void)
12363 +{
12364 +       /* decrement the module count when the debugger detaches */
12365 +       if (!kgdb_connected)
12366 +               module_put(THIS_MODULE);
12367 +       netpoll_set_trap(0);
12368 +}
12369 +
12370 +static int eth_get_char(void)
12371 +{
12372 +       int chr;
12373 +
12374 +       while (atomic_read(&in_count) == 0)
12375 +               netpoll_poll(&np);
12376 +
12377 +       chr = in_buf[in_tail++];
12378 +       in_tail &= (IN_BUF_SIZE - 1);
12379 +       atomic_dec(&in_count);
12380 +       return chr;
12381 +}
12382 +
12383 +static void eth_flush_buf(void)
12384 +{
12385 +       if (out_count && np.dev) {
12386 +               netpoll_send_udp(&np, out_buf, out_count);
12387 +               memset(out_buf, 0, sizeof(out_buf));
12388 +               out_count = 0;
12389 +       }
12390 +}
12391 +
12392 +static void eth_put_char(u8 chr)
12393 +{
12394 +       out_buf[out_count++] = chr;
12395 +       if (out_count == OUT_BUF_SIZE)
12396 +               eth_flush_buf();
12397 +}
12398 +
12399 +static int option_setup(char *opt)
12400 +{
12401 +       char opt_scratch[MAX_KGDBOE_CONFIG_STR];
12402 +
12403 +       /* If we're being given a new configuration, copy it in. */
12404 +       if (opt != config)
12405 +               strcpy(config, opt);
12406 +       /* But work on a copy as netpoll_parse_options will eat it. */
12407 +       strcpy(opt_scratch, opt);
12408 +       configured = !netpoll_parse_options(&np, opt_scratch);
12409 +
12410 +       use_dynamic_mac = 1;
12411 +
12412 +       return 0;
12413 +}
12414 +__setup("kgdboe=", option_setup);
12415 +
12416 +/* With our config string set by some means, configure kgdboe. */
12417 +static int configure_kgdboe(void)
12418 +{
12419 +       /* Try out the string. */
12420 +       option_setup(config);
12421 +
12422 +       if (!configured) {
12423 +               printk(KERN_ERR "kgdboe: configuration incorrect - kgdboe not "
12424 +                      "loaded.\n");
12425 +               printk(KERN_ERR "  Usage: kgdboe=[src-port]@[src-ip]/[dev],"
12426 +                               "[tgt-port]@<tgt-ip>/<tgt-macaddr>\n");
12427 +               return -EINVAL;
12428 +       }
12429 +
12430 +       /* Bring it up. */
12431 +       if (netpoll_setup(&np)) {
12432 +               printk(KERN_ERR "kgdboe: netpoll_setup failed kgdboe failed\n");
12433 +               return -EINVAL;
12434 +       }
12435 +
12436 +       if (kgdb_register_io_module(&local_kgdb_io_ops)) {
12437 +               netpoll_cleanup(&np);
12438 +               return -EINVAL;
12439 +       }
12440 +
12441 +       configured = 2;
12442 +
12443 +       return 0;
12444 +}
12445 +
12446 +static int init_kgdboe(void)
12447 +{
12448 +       int ret;
12449 +
12450 +       /* Already done? */
12451 +       if (configured == 2)
12452 +               return 0;
12453 +
12454 +       /* OK, go ahead and do it. */
12455 +       ret = configure_kgdboe();
12456 +
12457 +       if (configured == 2)
12458 +               printk(KERN_INFO "kgdboe: debugging over ethernet enabled\n");
12459 +
12460 +       return ret;
12461 +}
12462 +
12463 +static void cleanup_kgdboe(void)
12464 +{
12465 +       netpoll_cleanup(&np);
12466 +       configured = 0;
12467 +       kgdb_unregister_io_module(&local_kgdb_io_ops);
12468 +}
12469 +
12470 +static int param_set_kgdboe_var(const char *kmessage, struct kernel_param *kp)
12471 +{
12472 +       char kmessage_save[MAX_KGDBOE_CONFIG_STR];
12473 +       int msg_len = strlen(kmessage);
12474 +
12475 +       if (msg_len + 1 > MAX_KGDBOE_CONFIG_STR) {
12476 +               printk(KERN_ERR "%s: string doesn't fit in %u chars.\n",
12477 +                      kp->name, MAX_KGDBOE_CONFIG_STR - 1);
12478 +               return -ENOSPC;
12479 +       }
12480 +
12481 +       if (kgdb_connected) {
12482 +               printk(KERN_ERR "kgdboe: Cannot reconfigure while KGDB is "
12483 +                               "connected.\n");
12484 +               return 0;
12485 +       }
12486 +
12487 +       /* Start the reconfiguration process by saving the old string */
12488 +       strncpy(kmessage_save, config, sizeof(kmessage_save));
12489 +
12490 +
12491 +       /* Copy in the new param and strip out invalid characters so we
12492 +        * can optionally specify the MAC.
12493 +        */
12494 +       strncpy(config, kmessage, sizeof(config));
12495 +       msg_len--;
12496 +       while (msg_len > 0 &&
12497 +                       (config[msg_len] < ',' || config[msg_len] > 'f')) {
12498 +               config[msg_len] = '\0';
12499 +               msg_len--;
12500 +       }
12501 +
12502 +       /* Check to see if we are unconfiguring the io module and that it
12503 +        * was in a fully configured state, as this is the only time that
12504 +        * netpoll_cleanup should get called
12505 +        */
12506 +       if (configured == 2 && strcmp(config, NOT_CONFIGURED_STRING) == 0) {
12507 +               printk(KERN_INFO "kgdboe: reverting to unconfigured state\n");
12508 +               cleanup_kgdboe();
12509 +               return 0;
12510 +       } else
12511 +               /* Go and configure with the new params. */
12512 +               configure_kgdboe();
12513 +
12514 +       if (configured == 2)
12515 +               return 0;
12516 +
12517 +       /* If the new string was invalid, revert to the previous state, which
12518 +        * is at a minimum not_configured. */
12519 +       strncpy(config, kmessage_save, sizeof(config));
12520 +       if (strcmp(kmessage_save, NOT_CONFIGURED_STRING) != 0) {
12521 +               printk(KERN_INFO "kgdboe: reverting to prior configuration\n");
12522 +               /* revert back to the original config */
12523 +               strncpy(config, kmessage_save, sizeof(config));
12524 +               configure_kgdboe();
12525 +       }
12526 +       return 0;
12527 +}
12528 +
12529 +static struct kgdb_io local_kgdb_io_ops = {
12530 +       .read_char = eth_get_char,
12531 +       .write_char = eth_put_char,
12532 +       .init = init_kgdboe,
12533 +       .flush = eth_flush_buf,
12534 +       .pre_exception = eth_pre_exception_handler,
12535 +       .post_exception = eth_post_exception_handler
12536 +};
12537 +
12538 +module_init(init_kgdboe);
12539 +module_exit(cleanup_kgdboe);
12540 +module_param_call(kgdboe, param_set_kgdboe_var, param_get_string, &kps, 0644);
12541 +MODULE_PARM_DESC(kgdboe, " kgdboe=[src-port]@[src-ip]/[dev],"
12542 +                "[tgt-port]@<tgt-ip>/<tgt-macaddr>\n");
12543 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/8250.c linux-2.6.18.kgdb/drivers/serial/8250.c
12544 --- linux-2.6.18/drivers/serial/8250.c  2006-09-20 07:42:06.000000000 +0400
12545 +++ linux-2.6.18.kgdb/drivers/serial/8250.c     2008-06-10 16:19:03.000000000 +0400
12546 @@ -2628,6 +2628,25 @@ void serial8250_unregister_port(int line
12547  }
12548  EXPORT_SYMBOL(serial8250_unregister_port);
12549  
12550 +/**
12551 + *     serial8250_unregister_by_port - remove a 16x50 serial port
12552 + *     at runtime.
12553 + *     @port: A &struct uart_port that describes the port to remove.
12554 + *
12555 + *     Remove one serial port.  This may not be called from interrupt
12556 + *     context.  We hand the port back to the our control.
12557 + */
12558 +void serial8250_unregister_by_port(struct uart_port *port)
12559 +{
12560 +       struct uart_8250_port *uart;
12561 +
12562 +       uart = serial8250_find_match_or_unused(port);
12563 +
12564 +       if (uart)
12565 +               serial8250_unregister_port(uart->port.line);
12566 +}
12567 +EXPORT_SYMBOL(serial8250_unregister_by_port);
12568 +
12569  static int __init serial8250_init(void)
12570  {
12571         int ret, i;
12572 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/8250_kgdb.c linux-2.6.18.kgdb/drivers/serial/8250_kgdb.c
12573 --- linux-2.6.18/drivers/serial/8250_kgdb.c     1970-01-01 03:00:00.000000000 +0300
12574 +++ linux-2.6.18.kgdb/drivers/serial/8250_kgdb.c        2008-06-10 16:19:03.000000000 +0400
12575 @@ -0,0 +1,516 @@
12576 +/*
12577 + * 8250 interface for kgdb.
12578 + *
12579 + * This is a merging of many different drivers, and all of the people have
12580 + * had an impact in some form or another:
12581 + *
12582 + * 2004-2005 (c) MontaVista Software, Inc.
12583 + * 2005-2006 (c) Wind River Systems, Inc.
12584 + *
12585 + * Amit Kale <amitkale@emsyssoft.com>, David Grothe <dave@gcom.com>,
12586 + * Scott Foehner <sfoehner@engr.sgi.com>, George Anzinger <george@mvista.com>,
12587 + * Robert Walsh <rjwalsh@durables.org>, wangdi <wangdi@clusterfs.com>,
12588 + * San Mehat, Tom Rini <trini@mvista.com>,
12589 + * Jason Wessel <jason.wessel@windriver.com>
12590 + */
12591 +
12592 +#include <linux/config.h>
12593 +#include <linux/kernel.h>
12594 +#include <linux/init.h>
12595 +#include <linux/kgdb.h>
12596 +#include <linux/interrupt.h>
12597 +#include <linux/tty.h>
12598 +#include <linux/serial.h>
12599 +#include <linux/serial_reg.h>
12600 +#include <linux/serialP.h>
12601 +#include <linux/ioport.h>
12602 +
12603 +#include <asm/io.h>
12604 +#include <asm/serial.h>                /* For BASE_BAUD and SERIAL_PORT_DFNS */
12605 +
12606 +#include "8250.h"
12607 +
12608 +#define GDB_BUF_SIZE   512     /* power of 2, please */
12609 +
12610 +MODULE_DESCRIPTION("KGDB driver for the 8250");
12611 +MODULE_LICENSE("GPL");
12612 +/* These will conflict with early_param otherwise. */
12613 +#ifdef CONFIG_KGDB_8250_MODULE
12614 +static char config[256];
12615 +module_param_string(kgdb8250, config, 256, 0);
12616 +MODULE_PARM_DESC(kgdb8250,
12617 +                " kgdb8250=<io or mmio>,<address>,<baud rate>,<irq>\n");
12618 +static struct kgdb_io local_kgdb_io_ops;
12619 +#endif                         /* CONFIG_KGDB_8250_MODULE */
12620 +
12621 +/* Speed of the UART. */
12622 +static int kgdb8250_baud;
12623 +
12624 +/* Flag for if we need to call request_mem_region */
12625 +static int kgdb8250_needs_request_mem_region;
12626 +
12627 +static char kgdb8250_buf[GDB_BUF_SIZE];
12628 +static atomic_t kgdb8250_buf_in_cnt;
12629 +static int kgdb8250_buf_out_inx;
12630 +
12631 +/* Old-style serial definitions, if existant, and a counter. */
12632 +#ifdef CONFIG_KGDB_SIMPLE_SERIAL
12633 +static int __initdata should_copy_rs_table = 1;
12634 +static struct serial_state old_rs_table[] __initdata = {
12635 +#ifdef SERIAL_PORT_DFNS
12636 +       SERIAL_PORT_DFNS
12637 +#endif
12638 +};
12639 +#endif
12640 +
12641 +/* Our internal table of UARTS. */
12642 +#define UART_NR        CONFIG_SERIAL_8250_NR_UARTS
12643 +static struct uart_port kgdb8250_ports[UART_NR];
12644 +
12645 +static struct uart_port *current_port;
12646 +
12647 +/* Base of the UART. */
12648 +static void *kgdb8250_addr;
12649 +
12650 +/* Forward declarations. */
12651 +static int kgdb8250_uart_init(void);
12652 +static int __init kgdb_init_io(void);
12653 +static int __init kgdb8250_opt(char *str);
12654 +
12655 +/* These are much shorter calls to ioread8/iowrite8 that take into
12656 + * account our shifts, etc. */
12657 +static inline unsigned int kgdb_ioread(u8 mask)
12658 +{
12659 +       return ioread8(kgdb8250_addr + (mask << current_port->regshift));
12660 +}
12661 +
12662 +static inline void kgdb_iowrite(u8 val, u8 mask)
12663 +{
12664 +       iowrite8(val, kgdb8250_addr + (mask << current_port->regshift));
12665 +}
12666 +
12667 +/*
12668 + * Wait until the interface can accept a char, then write it.
12669 + */
12670 +static void kgdb_put_debug_char(u8 chr)
12671 +{
12672 +       while (!(kgdb_ioread(UART_LSR) & UART_LSR_THRE)) ;
12673 +
12674 +       kgdb_iowrite(chr, UART_TX);
12675 +}
12676 +
12677 +/*
12678 + * Get a byte from the hardware data buffer and return it
12679 + */
12680 +static int read_data_bfr(void)
12681 +{
12682 +       char it = kgdb_ioread(UART_LSR);
12683 +
12684 +       if (it & UART_LSR_DR)
12685 +               return kgdb_ioread(UART_RX);
12686 +
12687 +       /*
12688 +        * If we have a framing error assume somebody messed with
12689 +        * our uart.  Reprogram it and send '-' both ways...
12690 +        */
12691 +       if (it & 0xc) {
12692 +               kgdb8250_uart_init();
12693 +               kgdb_put_debug_char('-');
12694 +               return '-';
12695 +       }
12696 +
12697 +       return -1;
12698 +}
12699 +
12700 +/*
12701 + * Get a char if available, return -1 if nothing available.
12702 + * Empty the receive buffer first, then look at the interface hardware.
12703 + */
12704 +static int kgdb_get_debug_char(void)
12705 +{
12706 +       int retchr;
12707 +
12708 +       /* intr routine has q'd chars */
12709 +       if (atomic_read(&kgdb8250_buf_in_cnt) != 0) {
12710 +               retchr = kgdb8250_buf[kgdb8250_buf_out_inx++];
12711 +               kgdb8250_buf_out_inx &= (GDB_BUF_SIZE - 1);
12712 +               atomic_dec(&kgdb8250_buf_in_cnt);
12713 +               return retchr;
12714 +       }
12715 +
12716 +       do {
12717 +               retchr = read_data_bfr();
12718 +       } while (retchr < 0);
12719 +
12720 +       return retchr;
12721 +}
12722 +
12723 +/*
12724 + * This is the receiver interrupt routine for the GDB stub.
12725 + * All that we need to do is verify that the interrupt happened on the
12726 + * line we're in charge of.  If this is true, schedule a breakpoint and
12727 + * return.
12728 + */
12729 +static irqreturn_t
12730 +kgdb8250_interrupt(int irq, void *dev_id, struct pt_regs *regs)
12731 +{
12732 +       if (kgdb_ioread(UART_IIR) & UART_IIR_RDI) {
12733 +               /* Throw away the data if another I/O routine is active. */
12734 +               if (kgdb_io_ops.read_char != kgdb_get_debug_char &&
12735 +                               (kgdb_ioread(UART_LSR) & UART_LSR_DR))
12736 +                       kgdb_ioread(UART_RX);
12737 +               else
12738 +                       breakpoint();
12739 +       }
12740 +
12741 +       return IRQ_HANDLED;
12742 +}
12743 +
12744 +/*
12745 + *  Initializes the UART.
12746 + *  Returns:
12747 + *     0 on success, 1 on failure.
12748 + */
12749 +static int
12750 +kgdb8250_uart_init (void)
12751 +{
12752 +       unsigned int ier, base_baud = current_port->uartclk ?
12753 +               current_port->uartclk / 16 : BASE_BAUD;
12754 +
12755 +       /* test uart existance */
12756 +       if(kgdb_ioread(UART_LSR) == 0xff)
12757 +               return -1;
12758 +
12759 +       /* disable interrupts */
12760 +       kgdb_iowrite(0, UART_IER);
12761 +
12762 +#if defined(CONFIG_ARCH_OMAP1510)
12763 +       /* Workaround to enable 115200 baud on OMAP1510 internal ports */
12764 +       if (cpu_is_omap1510() && is_omap_port((void *)kgdb8250_addr)) {
12765 +               if (kgdb8250_baud == 115200) {
12766 +                       base_baud = 1;
12767 +                       kgdb8250_baud = 1;
12768 +                       kgdb_iowrite(1, UART_OMAP_OSC_12M_SEL);
12769 +               } else
12770 +                       kgdb_iowrite(0, UART_OMAP_OSC_12M_SEL);
12771 +       }
12772 +#endif
12773 +       /* set DLAB */
12774 +       kgdb_iowrite(UART_LCR_DLAB, UART_LCR);
12775 +
12776 +       /* set baud */
12777 +       kgdb_iowrite((base_baud / kgdb8250_baud) & 0xff, UART_DLL);
12778 +       kgdb_iowrite((base_baud / kgdb8250_baud) >> 8, UART_DLM);
12779 +
12780 +       /* reset DLAB, set LCR */
12781 +       kgdb_iowrite(UART_LCR_WLEN8, UART_LCR);
12782 +
12783 +       /* set DTR and RTS */
12784 +       kgdb_iowrite(UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS, UART_MCR);
12785 +
12786 +       /* setup fifo */
12787 +       kgdb_iowrite(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR
12788 +               | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_8,
12789 +               UART_FCR);
12790 +
12791 +       /* clear pending interrupts */
12792 +       kgdb_ioread(UART_IIR);
12793 +       kgdb_ioread(UART_RX);
12794 +       kgdb_ioread(UART_LSR);
12795 +       kgdb_ioread(UART_MSR);
12796 +
12797 +       /* turn on RX interrupt only */
12798 +       kgdb_iowrite(UART_IER_RDI, UART_IER);
12799 +
12800 +       /*
12801 +        * Borrowed from the main 8250 driver.
12802 +        * Try writing and reading the UART_IER_UUE bit (b6).
12803 +        * If it works, this is probably one of the Xscale platform's
12804 +        * internal UARTs.
12805 +        * We're going to explicitly set the UUE bit to 0 before
12806 +        * trying to write and read a 1 just to make sure it's not
12807 +        * already a 1 and maybe locked there before we even start start.
12808 +        */
12809 +       ier = kgdb_ioread(UART_IER);
12810 +       kgdb_iowrite(ier & ~UART_IER_UUE, UART_IER);
12811 +       if (!(kgdb_ioread(UART_IER) & UART_IER_UUE)) {
12812 +               /*
12813 +                * OK it's in a known zero state, try writing and reading
12814 +                * without disturbing the current state of the other bits.
12815 +                */
12816 +               kgdb_iowrite(ier | UART_IER_UUE, UART_IER);
12817 +               if (kgdb_ioread(UART_IER) & UART_IER_UUE)
12818 +                       /*
12819 +                        * It's an Xscale.
12820 +                        */
12821 +                       ier |= UART_IER_UUE | UART_IER_RTOIE;
12822 +       }
12823 +       kgdb_iowrite(ier, UART_IER);
12824 +       return 0;
12825 +}
12826 +
12827 +/*
12828 + * Copy the old serial_state table to our uart_port table if we haven't
12829 + * had values specifically configured in.  We need to make sure this only
12830 + * happens once.
12831 + */
12832 +static void __init kgdb8250_copy_rs_table(void)
12833 +{
12834 +#ifdef CONFIG_KGDB_SIMPLE_SERIAL
12835 +       int i;
12836 +
12837 +       if (!should_copy_rs_table)
12838 +               return;
12839 +
12840 +       for (i = 0; i < ARRAY_SIZE(old_rs_table); i++) {
12841 +               kgdb8250_ports[i].iobase = old_rs_table[i].port;
12842 +               kgdb8250_ports[i].irq = irq_canonicalize(old_rs_table[i].irq);
12843 +               kgdb8250_ports[i].uartclk = old_rs_table[i].baud_base * 16;
12844 +               kgdb8250_ports[i].membase = old_rs_table[i].iomem_base;
12845 +               kgdb8250_ports[i].iotype = old_rs_table[i].io_type;
12846 +               kgdb8250_ports[i].regshift = old_rs_table[i].iomem_reg_shift;
12847 +               kgdb8250_ports[i].line = i;
12848 +       }
12849 +
12850 +       should_copy_rs_table = 0;
12851 +#endif
12852 +}
12853 +
12854 +/*
12855 + * Hookup our IRQ line now that it is safe to do so, after we grab any
12856 + * memory regions we might need to.  If we haven't been initialized yet,
12857 + * go ahead and copy the old_rs_table in.
12858 + */
12859 +static void __init kgdb8250_late_init(void)
12860 +{
12861 +       /* Try and copy the old_rs_table. */
12862 +       kgdb8250_copy_rs_table();
12863 +
12864 +#if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
12865 +       /* Take the port away from the main driver. */
12866 +       serial8250_unregister_by_port(current_port);
12867 +
12868 +       /* Now reinit the port as the above has disabled things. */
12869 +       kgdb8250_uart_init();
12870 +#endif
12871 +       /* We may need to call request_mem_region() first. */
12872 +       if (kgdb8250_needs_request_mem_region)
12873 +               request_mem_region(current_port->mapbase,
12874 +                                  8 << current_port->regshift, "kgdb");
12875 +       if (request_irq(current_port->irq, kgdb8250_interrupt, SA_SHIRQ,
12876 +                       "GDB-stub", current_port) < 0)
12877 +               printk(KERN_ERR "KGDB failed to request the serial IRQ (%d)\n",
12878 +                      current_port->irq);
12879 +}
12880 +
12881 +static __init int kgdb_init_io(void)
12882 +{
12883 +       /* Give us the basic table of uarts. */
12884 +       kgdb8250_copy_rs_table();
12885 +
12886 +       /* We're either a module and parse a config string, or we have a
12887 +        * semi-static config. */
12888 +#ifdef CONFIG_KGDB_8250_MODULE
12889 +       if (strlen(config)) {
12890 +               if (kgdb8250_opt(config))
12891 +                       return -EINVAL;
12892 +       } else {
12893 +               printk(KERN_ERR "kgdb8250: argument error, usage: "
12894 +                      "kgdb8250=<io or mmio>,<address>,<baud rate>,<irq>\n");
12895 +               return -EINVAL;
12896 +       }
12897 +#elif defined(CONFIG_KGDB_SIMPLE_SERIAL)
12898 +       kgdb8250_baud = CONFIG_KGDB_BAUDRATE;
12899 +
12900 +       /* Setup our pointer to the serial port now. */
12901 +       current_port = &kgdb8250_ports[CONFIG_KGDB_PORT_NUM];
12902 +#else
12903 +       if (kgdb8250_opt(CONFIG_KGDB_8250_CONF_STRING))
12904 +               return -EINVAL;
12905 +#endif
12906 +
12907 +
12908 +       /* Internal driver setup. */
12909 +       switch (current_port->iotype) {
12910 +       case UPIO_MEM:
12911 +               if (current_port->mapbase)
12912 +                       kgdb8250_needs_request_mem_region = 1;
12913 +               if (current_port->flags & UPF_IOREMAP) {
12914 +                       current_port->membase = ioremap(current_port->mapbase,
12915 +                                               8 << current_port->regshift);
12916 +                       if (!current_port->membase)
12917 +                               return -EIO;    /* Failed. */
12918 +               }
12919 +               kgdb8250_addr = current_port->membase;
12920 +               break;
12921 +       case UPIO_PORT:
12922 +       default:
12923 +               kgdb8250_addr = ioport_map(current_port->iobase,
12924 +                                          8 << current_port->regshift);
12925 +               if (!kgdb8250_addr)
12926 +                       return -EIO;    /* Failed. */
12927 +       }
12928 +
12929 +       if (kgdb8250_uart_init() == -1) {
12930 +               printk(KERN_ERR "kgdb8250: init failed\n");
12931 +               return -EIO;
12932 +       }
12933 +#ifdef CONFIG_KGDB_8250_MODULE
12934 +       /* Attach the kgdb irq. When this is built into the kernel, it
12935 +        * is called as a part of late_init sequence.
12936 +        */
12937 +       kgdb8250_late_init();
12938 +       if (kgdb_register_io_module(&local_kgdb_io_ops))
12939 +               return -EINVAL;
12940 +
12941 +       printk(KERN_INFO "kgdb8250: debugging enabled\n");
12942 +#endif                         /* CONFIG_KGD_8250_MODULE */
12943 +
12944 +       return 0;
12945 +}
12946 +
12947 +#ifdef CONFIG_KGDB_8250_MODULE
12948 +/* If it is a module the kgdb_io_ops should be a static which
12949 + * is passed to the KGDB I/O initialization
12950 + */
12951 +static struct kgdb_io local_kgdb_io_ops = {
12952 +#else                          /* ! CONFIG_KGDB_8250_MODULE */
12953 +struct kgdb_io kgdb_io_ops = {
12954 +#endif                         /* ! CONFIG_KGD_8250_MODULE */
12955 +       .read_char = kgdb_get_debug_char,
12956 +       .write_char = kgdb_put_debug_char,
12957 +       .init = kgdb_init_io,
12958 +       .late_init = kgdb8250_late_init,
12959 +};
12960 +
12961 +/**
12962 + *     kgdb8250_add_port - Define a serial port for use with KGDB
12963 + *     @i: The index of the port being added
12964 + *     @serial_req: The &struct uart_port describing the port
12965 + *
12966 + *     On platforms where we must register the serial device
12967 + *     dynamically, this is the best option if a platform also normally
12968 + *     calls early_serial_setup().
12969 + */
12970 +void __init kgdb8250_add_port(int i, struct uart_port *serial_req)
12971 +{
12972 +       /* Make sure we've got the built-in data before we override. */
12973 +       kgdb8250_copy_rs_table();
12974 +
12975 +       /* Copy the whole thing over. */
12976 +       if (current_port != &kgdb8250_ports[i])
12977 +                memcpy(&kgdb8250_ports[i], serial_req, sizeof(struct uart_port));
12978 +}
12979 +
12980 +/**
12981 + *     kgdb8250_add_platform_port - Define a serial port for use with KGDB
12982 + *     @i: The index of the port being added
12983 + *     @p: The &struct plat_serial8250_port describing the port
12984 + *
12985 + *     On platforms where we must register the serial device
12986 + *     dynamically, this is the best option if a platform normally
12987 + *     handles uart setup with an array of &struct plat_serial8250_port.
12988 + */
12989 +void __init kgdb8250_add_platform_port(int i, struct plat_serial8250_port *p)
12990 +{
12991 +       /* Make sure we've got the built-in data before we override. */
12992 +       kgdb8250_copy_rs_table();
12993 +
12994 +       kgdb8250_ports[i].iobase = p->iobase;
12995 +       kgdb8250_ports[i].membase = p->membase;
12996 +       kgdb8250_ports[i].irq = p->irq;
12997 +       kgdb8250_ports[i].uartclk = p->uartclk;
12998 +       kgdb8250_ports[i].regshift = p->regshift;
12999 +       kgdb8250_ports[i].iotype = p->iotype;
13000 +       kgdb8250_ports[i].flags = p->flags;
13001 +       kgdb8250_ports[i].mapbase = p->mapbase;
13002 +}
13003 +
13004 +/*
13005 + * Syntax for this cmdline option is:
13006 + * kgdb8250=<io or mmio>,<address>,<baud rate>,<irq>"
13007 + */
13008 +static int __init kgdb8250_opt(char *str)
13009 +{
13010 +       /* We'll fill out and use the first slot. */
13011 +       current_port = &kgdb8250_ports[0];
13012 +
13013 +       if (!strncmp(str, "io", 2)) {
13014 +               current_port->iotype = UPIO_PORT;
13015 +               str += 2;
13016 +       } else if (!strncmp(str, "mmap", 4)) {
13017 +               current_port->iotype = UPIO_MEM;
13018 +               current_port->flags |= UPF_IOREMAP;
13019 +               str += 4;
13020 +       } else if (!strncmp(str, "mmio", 4)) {
13021 +               current_port->iotype = UPIO_MEM;
13022 +               current_port->flags &= ~UPF_IOREMAP;
13023 +               str += 4;
13024 +       } else
13025 +               goto errout;
13026 +
13027 +       if (*str != ',')
13028 +               goto errout;
13029 +       str++;
13030 +
13031 +       if (current_port->iotype == UPIO_PORT)
13032 +               current_port->iobase = simple_strtoul(str, &str, 16);
13033 +       else {
13034 +               if (current_port->flags & UPF_IOREMAP)
13035 +                       current_port->mapbase =
13036 +                               (unsigned long) simple_strtoul(str, &str, 16);
13037 +               else
13038 +                       current_port->membase =
13039 +                               (void *) simple_strtoul(str, &str, 16);
13040 +       }
13041 +
13042 +       if (*str != ',')
13043 +               goto errout;
13044 +       str++;
13045 +
13046 +       kgdb8250_baud = simple_strtoul(str, &str, 10);
13047 +       if (!kgdb8250_baud)
13048 +               goto errout;
13049 +
13050 +       if (*str != ',')
13051 +               goto errout;
13052 +       str++;
13053 +
13054 +       current_port->irq = simple_strtoul(str, &str, 10);
13055 +
13056 +#ifdef CONFIG_KGDB_SIMPLE_SERIAL
13057 +       should_copy_rs_table = 0;
13058 +#endif
13059 +
13060 +       return 0;
13061 +
13062 +      errout:
13063 +       printk(KERN_ERR "Invalid syntax for option kgdb8250=\n");
13064 +       return 1;
13065 +}
13066 +
13067 +#ifdef CONFIG_KGDB_8250_MODULE
13068 +static void cleanup_kgdb8250(void)
13069 +{
13070 +       kgdb_unregister_io_module(&local_kgdb_io_ops);
13071 +
13072 +       /* Clean up the irq and memory */
13073 +       free_irq(current_port->irq, current_port);
13074 +
13075 +       if (kgdb8250_needs_request_mem_region)
13076 +               release_mem_region(current_port->mapbase,
13077 +                                  8 << current_port->regshift);
13078 +       /* Hook up the serial port back to what it was previously
13079 +        * hooked up to.
13080 +        */
13081 +#if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
13082 +       /* Give the port back to the 8250 driver. */
13083 +       serial8250_register_port(current_port);
13084 +#endif
13085 +}
13086 +
13087 +module_init(kgdb_init_io);
13088 +module_exit(cleanup_kgdb8250);
13089 +#else                          /* ! CONFIG_KGDB_8250_MODULE */
13090 +early_param("kgdb8250", kgdb8250_opt);
13091 +#endif                         /* ! CONFIG_KGDB_8250_MODULE */
13092 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/Kconfig linux-2.6.18.kgdb/drivers/serial/Kconfig
13093 --- linux-2.6.18/drivers/serial/Kconfig 2006-09-20 07:42:06.000000000 +0400
13094 +++ linux-2.6.18.kgdb/drivers/serial/Kconfig    2008-06-10 16:19:03.000000000 +0400
13095 @@ -106,7 +106,7 @@ config SERIAL_8250_CS
13096  
13097  config SERIAL_8250_NR_UARTS
13098         int "Maximum number of 8250/16550 serial ports"
13099 -       depends on SERIAL_8250
13100 +       depends on SERIAL_8250 || KGDB_8250
13101         default "4"
13102         help
13103           Set this to the number of serial ports you want the driver
13104 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/Makefile linux-2.6.18.kgdb/drivers/serial/Makefile
13105 --- linux-2.6.18/drivers/serial/Makefile        2006-09-20 07:42:06.000000000 +0400
13106 +++ linux-2.6.18.kgdb/drivers/serial/Makefile   2008-06-10 16:19:22.000000000 +0400
13107 @@ -47,6 +47,7 @@ obj-$(CONFIG_SERIAL_IMX) += imx.o
13108  obj-$(CONFIG_SERIAL_MPC52xx) += mpc52xx_uart.o
13109  obj-$(CONFIG_SERIAL_ICOM) += icom.o
13110  obj-$(CONFIG_SERIAL_M32R_SIO) += m32r_sio.o
13111 +obj-$(CONFIG_KGDB_MPSC) += mpsc_kgdb.o
13112  obj-$(CONFIG_SERIAL_MPSC) += mpsc.o
13113  obj-$(CONFIG_ETRAX_SERIAL) += crisv10.o
13114  obj-$(CONFIG_SERIAL_JSM) += jsm/
13115 @@ -56,3 +57,4 @@ obj-$(CONFIG_SERIAL_SGI_IOC4) += ioc4_se
13116  obj-$(CONFIG_SERIAL_SGI_IOC3) += ioc3_serial.o
13117  obj-$(CONFIG_SERIAL_AT91) += at91_serial.o
13118  obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
13119 +obj-$(CONFIG_KGDB_8250) += 8250_kgdb.o
13120 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/amba-pl011.c linux-2.6.18.kgdb/drivers/serial/amba-pl011.c
13121 --- linux-2.6.18/drivers/serial/amba-pl011.c    2006-09-20 07:42:06.000000000 +0400
13122 +++ linux-2.6.18.kgdb/drivers/serial/amba-pl011.c       2008-06-10 16:19:51.000000000 +0400
13123 @@ -340,7 +340,7 @@ static int pl011_startup(struct uart_por
13124         /*
13125          * Allocate the IRQ
13126          */
13127 -       retval = request_irq(uap->port.irq, pl011_int, 0, "uart-pl011", uap);
13128 +       retval = request_irq(uap->port.irq, pl011_int, SA_SHIRQ, "uart-pl011", uap);
13129         if (retval)
13130                 goto clk_dis;
13131  
13132 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/cpm_uart/Makefile linux-2.6.18.kgdb/drivers/serial/cpm_uart/Makefile
13133 --- linux-2.6.18/drivers/serial/cpm_uart/Makefile       2006-09-20 07:42:06.000000000 +0400
13134 +++ linux-2.6.18.kgdb/drivers/serial/cpm_uart/Makefile  2008-06-10 16:19:22.000000000 +0400
13135 @@ -7,5 +7,6 @@ obj-$(CONFIG_SERIAL_CPM) += cpm_uart.o
13136  # Select the correct platform objects.
13137  cpm_uart-objs-$(CONFIG_CPM2)   += cpm_uart_cpm2.o
13138  cpm_uart-objs-$(CONFIG_8xx)    += cpm_uart_cpm1.o
13139 +cpm_uart-objs-$(CONFIG_KGDB_CPM_UART)  += cpm_uart_kgdb.o
13140  
13141  cpm_uart-objs  := cpm_uart_core.o $(cpm_uart-objs-y)
13142 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/cpm_uart/cpm_uart.h linux-2.6.18.kgdb/drivers/serial/cpm_uart/cpm_uart.h
13143 --- linux-2.6.18/drivers/serial/cpm_uart/cpm_uart.h     2006-09-20 07:42:06.000000000 +0400
13144 +++ linux-2.6.18.kgdb/drivers/serial/cpm_uart/cpm_uart.h        2008-06-10 16:19:22.000000000 +0400
13145 @@ -51,6 +51,39 @@
13146  
13147  #define SCC_WAIT_CLOSING 100
13148  
13149 +#ifdef CONFIG_KGDB_CPM_UART
13150 +
13151 +/* Speed of the debug UART. */
13152 +#if defined(CONFIG_KGDB_9600BAUD)
13153 +#define KGDB_BAUD B9600
13154 +#elif defined(CONFIG_KGDB_19200BAUD)
13155 +#define KGDB_BAUD B19200
13156 +#elif defined(CONFIG_KGDB_38400BAUD)
13157 +#define KGDB_BAUD B38400
13158 +#elif defined(CONFIG_KGDB_57600BAUD)
13159 +#define KGDB_BAUD B57600
13160 +#else
13161 +#define KGDB_BAUD B115200      /* Start with this if not given */
13162 +#endif
13163 +
13164 +#ifdef CONFIG_KGDB_CPM_UART_SCC1
13165 +#define KGDB_PINFO_INDEX       UART_SCC1
13166 +#elif CONFIG_KGDB_CPM_UART_SCC2
13167 +#define KGDB_PINFO_INDEX       UART_SCC2
13168 +#elif CONFIG_KGDB_CPM_UART_SCC3
13169 +#define KGDB_PINFO_INDEX       UART_SCC3
13170 +#elif CONFIG_KGDB_CPM_UART_SCC4
13171 +#define KGDB_PINFO_INDEX       UART_SCC4
13172 +#elif CONFIG_KGDB_CPM_UART_SMC1
13173 +#define KGDB_PINFO_INDEX       UART_SMC1
13174 +#elif CONFIG_KGDB_CPM_UART_SMC2
13175 +#define KGDB_PINFO_INDEX       UART_SMC2
13176 +#else
13177 +#error The S(M)CC for kgdb console is undefined
13178 +#endif
13179 +
13180 +#endif /* CONFIG_KGDB_CPM_UART */
13181 +
13182  struct uart_cpm_port {
13183         struct uart_port        port;
13184         u16                     rx_nrfifos;
13185 @@ -87,6 +120,9 @@ extern int cpm_uart_port_map[UART_NR];
13186  extern int cpm_uart_nr;
13187  extern struct uart_cpm_port cpm_uart_ports[UART_NR];
13188  
13189 +void cpm_uart_early_write(int index, const char *s, u_int count);
13190 +int cpm_uart_early_setup(int index,int early);
13191 +
13192  /* these are located in their respective files */
13193  void cpm_line_cr_cmd(int line, int cmd);
13194  int cpm_uart_init_portdesc(void);
13195 @@ -133,5 +169,4 @@ static inline void *cpm2cpu_addr(unsigne
13196         return 0;
13197  }
13198  
13199 -
13200  #endif /* CPM_UART_H */
13201 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/cpm_uart/cpm_uart_core.c linux-2.6.18.kgdb/drivers/serial/cpm_uart/cpm_uart_core.c
13202 --- linux-2.6.18/drivers/serial/cpm_uart/cpm_uart_core.c        2006-09-20 07:42:06.000000000 +0400
13203 +++ linux-2.6.18.kgdb/drivers/serial/cpm_uart/cpm_uart_core.c   2008-06-10 16:19:22.000000000 +0400
13204 @@ -1070,22 +1070,17 @@ int cpm_uart_drv_get_platform_data(struc
13205         return 0;
13206  }
13207  
13208 -#ifdef CONFIG_SERIAL_CPM_CONSOLE
13209 -/*
13210 - *     Print a string to the serial port trying not to disturb
13211 - *     any possible real use of the port...
13212 - *
13213 - *     Note that this is called with interrupts already disabled
13214 - */
13215 -static void cpm_uart_console_write(struct console *co, const char *s,
13216 +void cpm_uart_early_write(int index, const char *s,
13217                                    u_int count)
13218  {
13219 -       struct uart_cpm_port *pinfo =
13220 -           &cpm_uart_ports[cpm_uart_port_map[co->index]];
13221 +       struct uart_cpm_port *pinfo;
13222         unsigned int i;
13223         volatile cbd_t *bdp, *bdbase;
13224         volatile unsigned char *cp;
13225  
13226 +       BUG_ON(index>UART_NR);
13227 +       pinfo = &cpm_uart_ports[index];
13228 +
13229         /* Get the address of the host memory buffer.
13230          */
13231         bdp = pinfo->tx_cur;
13232 @@ -1149,16 +1144,11 @@ static void cpm_uart_console_write(struc
13233         pinfo->tx_cur = (volatile cbd_t *) bdp;
13234  }
13235  
13236 -
13237 -static int __init cpm_uart_console_setup(struct console *co, char *options)
13238 +int cpm_uart_early_setup(int index, int early)
13239  {
13240 +       int ret;
13241         struct uart_port *port;
13242         struct uart_cpm_port *pinfo;
13243 -       int baud = 38400;
13244 -       int bits = 8;
13245 -       int parity = 'n';
13246 -       int flow = 'n';
13247 -       int ret;
13248  
13249         struct fs_uart_platform_info *pdata;
13250         struct platform_device* pdev = early_uart_get_pdev(co->index);
13251 @@ -1169,8 +1159,9 @@ static int __init cpm_uart_console_setup
13252                 cpm_uart_init_portdesc();
13253         }
13254  
13255 +       BUG_ON(index>UART_NR);
13256         port =
13257 -           (struct uart_port *)&cpm_uart_ports[cpm_uart_port_map[co->index]];
13258 +               (struct uart_port *)&cpm_uart_ports[index];
13259         pinfo = (struct uart_cpm_port *)port;
13260         if (!pdev) {
13261                 if (pinfo->set_lineif)
13262 @@ -1184,19 +1175,6 @@ static int __init cpm_uart_console_setup
13263                 cpm_uart_drv_get_platform_data(pdev, 1);
13264         }
13265  
13266 -       pinfo->flags |= FLAG_CONSOLE;
13267 -
13268 -       if (options) {
13269 -               uart_parse_options(options, &baud, &parity, &bits, &flow);
13270 -       } else {
13271 -               bd_t *bd = (bd_t *) __res;
13272 -
13273 -               if (bd->bi_baudrate)
13274 -                       baud = bd->bi_baudrate;
13275 -               else
13276 -                       baud = 9600;
13277 -       }
13278 -
13279         if (IS_SMC(pinfo)) {
13280                 pinfo->smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
13281                 pinfo->smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
13282 @@ -1204,8 +1182,7 @@ static int __init cpm_uart_console_setup
13283                 pinfo->sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
13284                 pinfo->sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
13285         }
13286 -
13287 -       ret = cpm_uart_allocbuf(pinfo, 1);
13288 +       ret = cpm_uart_allocbuf(pinfo, early);
13289  
13290         if (ret)
13291                 return ret;
13292 @@ -1217,6 +1194,56 @@ static int __init cpm_uart_console_setup
13293         else
13294                 cpm_uart_init_scc(pinfo);
13295  
13296 +       return 0;
13297 +}
13298 +
13299 +#ifdef CONFIG_SERIAL_CPM_CONSOLE
13300 +/*
13301 + *     Print a string to the serial port trying not to disturb
13302 + *     any possible real use of the port...
13303 + *
13304 + *     Note that this is called with interrupts already disabled
13305 + */
13306 +
13307 +static void cpm_uart_console_write(struct console *co, const char *s,
13308 +                                  u_int count)
13309 +{
13310 +       cpm_uart_early_write(cpm_uart_port_map[co->index],s,count);
13311 +}
13312 +
13313 +/*
13314 + * Setup console. Be careful is called early !
13315 + */
13316 +static int __init cpm_uart_console_setup(struct console *co, char *options)
13317 +{
13318 +       struct uart_port *port;
13319 +       struct uart_cpm_port *pinfo;
13320 +       int baud = 115200;
13321 +       int bits = 8;
13322 +       int parity = 'n';
13323 +       int flow = 'n';
13324 +       int ret;
13325 +
13326 +       port =
13327 +           (struct uart_port *)&cpm_uart_ports[cpm_uart_port_map[co->index]];
13328 +       pinfo = (struct uart_cpm_port *)port;
13329 +
13330 +       pinfo->flags |= FLAG_CONSOLE;
13331 +
13332 +       if (options) {
13333 +               uart_parse_options(options, &baud, &parity, &bits, &flow);
13334 +       } else {
13335 +               bd_t *bd = (bd_t *) __res;
13336 +
13337 +               if (bd->bi_baudrate)
13338 +                       baud = bd->bi_baudrate;
13339 +               else
13340 +                       baud = 9600;
13341 +       }
13342 +
13343 +       ret = cpm_uart_early_setup(cpm_uart_port_map[co->index], 1);
13344 +       if(ret)
13345 +               return ret;
13346         uart_set_options(port, co, baud, parity, bits, flow);
13347  
13348         return 0;
13349 @@ -1364,6 +1391,12 @@ static int cpm_uart_init(void) {
13350  
13351                 for (i = 0; i < cpm_uart_nr; i++) {
13352                         int con = cpm_uart_port_map[i];
13353 +
13354 +#ifdef CONFIG_KGDB_CPM_UART
13355 +               /* We are not interested in ports yet utilized by kgdb */
13356 +               if(con == KGDB_PINFO_INDEX)
13357 +                       continue;
13358 +#endif
13359                         cpm_uart_ports[con].port.line = i;
13360                         cpm_uart_ports[con].port.flags = UPF_BOOT_AUTOCONF;
13361                         uart_add_one_port(&cpm_reg, &cpm_uart_ports[con].port);
13362 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/cpm_uart/cpm_uart_cpm1.c linux-2.6.18.kgdb/drivers/serial/cpm_uart/cpm_uart_cpm1.c
13363 --- linux-2.6.18/drivers/serial/cpm_uart/cpm_uart_cpm1.c        2006-09-20 07:42:06.000000000 +0400
13364 +++ linux-2.6.18.kgdb/drivers/serial/cpm_uart/cpm_uart_cpm1.c   2008-06-10 16:19:22.000000000 +0400
13365 @@ -52,6 +52,7 @@ void cpm_line_cr_cmd(int line, int cmd)
13366  {
13367         ushort val;
13368         volatile cpm8xx_t *cp = cpmp;
13369 +       unsigned *bcsr_io;
13370  
13371         switch (line) {
13372         case UART_SMC1:
13373 @@ -94,12 +95,35 @@ void scc1_lineif(struct uart_cpm_port *p
13374  {
13375         /* XXX SCC1: insert port configuration here */
13376         pinfo->brg = 1;
13377 +
13378 +#if defined (CONFIG_MPC885ADS) || defined (CONFIG_MPC86XADS)
13379 +       bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
13380 +
13381 +       if (bcsr_io == NULL) {
13382 +               printk(KERN_CRIT "Could not remap BCSR\n");
13383 +               return;
13384 +       }
13385 +       out_be32(bcsr_io, in_be32(bcsr_io) & ~BCSR1_RS232EN_1);
13386 +       iounmap(bcsr_io);
13387 +#endif
13388  }
13389  
13390  void scc2_lineif(struct uart_cpm_port *pinfo)
13391  {
13392         /* XXX SCC2: insert port configuration here */
13393         pinfo->brg = 2;
13394 +       unsigned *bcsr_io;
13395 +
13396 +#if defined (CONFIG_MPC885ADS) || defined (CONFIG_MPC86XADS)
13397 +       bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
13398 +
13399 +       if (bcsr_io == NULL) {
13400 +               printk(KERN_CRIT "Could not remap BCSR\n");
13401 +               return;
13402 +       }
13403 +        out_be32(bcsr_io, in_be32(bcsr_io) & ~BCSR1_RS232EN_2);
13404 +       iounmap(bcsr_io);
13405 +#endif
13406  }
13407  
13408  void scc3_lineif(struct uart_cpm_port *pinfo)
13409 @@ -188,6 +212,10 @@ int cpm_uart_init_portdesc(void)
13410  {
13411         pr_debug("CPM uart[-]:init portdesc\n");
13412  
13413 +       /* Check if we have called this yet. This may happen if early kgdb
13414 +       breakpoint is on */
13415 +       if(cpm_uart_nr)
13416 +               return 0;
13417         cpm_uart_nr = 0;
13418  #ifdef CONFIG_SERIAL_CPM_SMC1
13419         cpm_uart_ports[UART_SMC1].smcp = &cpmp->cp_smc[0];
13420 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/cpm_uart/cpm_uart_cpm2.c linux-2.6.18.kgdb/drivers/serial/cpm_uart/cpm_uart_cpm2.c
13421 --- linux-2.6.18/drivers/serial/cpm_uart/cpm_uart_cpm2.c        2006-09-20 07:42:06.000000000 +0400
13422 +++ linux-2.6.18.kgdb/drivers/serial/cpm_uart/cpm_uart_cpm2.c   2008-06-10 16:19:22.000000000 +0400
13423 @@ -256,6 +256,10 @@ int cpm_uart_init_portdesc(void)
13424  {
13425         pr_debug("CPM uart[-]:init portdesc\n");
13426  
13427 +       /* Check if we have called this yet. This may happen if early kgdb
13428 +       breakpoint is on */
13429 +       if(cpm_uart_nr)
13430 +               return 0;
13431         cpm_uart_nr = 0;
13432  #ifdef CONFIG_SERIAL_CPM_SMC1
13433         cpm_uart_ports[UART_SMC1].smcp = (smc_t *) & cpm2_immr->im_smc[0];
13434 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/cpm_uart/cpm_uart_kgdb.c linux-2.6.18.kgdb/drivers/serial/cpm_uart/cpm_uart_kgdb.c
13435 --- linux-2.6.18/drivers/serial/cpm_uart/cpm_uart_kgdb.c        1970-01-01 03:00:00.000000000 +0300
13436 +++ linux-2.6.18.kgdb/drivers/serial/cpm_uart/cpm_uart_kgdb.c   2008-06-10 16:19:22.000000000 +0400
13437 @@ -0,0 +1,195 @@
13438 +/*
13439 + * drivers/serial/cpm_uart/cpm_uart_kgdb.c
13440 + *
13441 + * CPM UART interface for kgdb.
13442 + *
13443 + * Author: Vitaly Bordug <vbordug@ru.mvista.com>
13444 + *
13445 + * Used some bits from drivers/serial/kgdb_8250.c as a template
13446 + *
13447 + * 2005 (c) MontaVista Software, Inc. This file is licensed under
13448 + * the terms of the GNU General Public License version 2. This program
13449 + * is licensed "as is" without any warranty of any kind, whether express
13450 + * or implied.
13451 + */
13452 +
13453 +#include <linux/kgdb.h>
13454 +#include <linux/config.h>
13455 +#include <linux/kernel.h>
13456 +#include <linux/init.h>
13457 +#include <linux/interrupt.h>
13458 +#include <linux/tty.h>
13459 +#include <linux/serial.h>
13460 +#include <linux/serial_core.h>
13461 +#include <linux/serial_reg.h>
13462 +
13463 +#include <asm/io.h>
13464 +#include <asm/serial.h>                /* For BASE_BAUD and SERIAL_PORT_DFNS */
13465 +
13466 +#include "cpm_uart.h"
13467 +
13468 +#define GDB_BUF_SIZE   512     /* power of 2, please */
13469 +
13470 +
13471 +static char kgdb_buf[GDB_BUF_SIZE], *kgdbp;
13472 +static int kgdb_chars;
13473 +
13474 +/* Forward declarations. */
13475 +
13476 +/*
13477 + * Receive character from the serial port.  This only works well
13478 + * before the port is initialize for real use.
13479 + */
13480 +static int kgdb_wait_key(char *obuf)
13481 +{
13482 +       struct uart_cpm_port *pinfo;
13483 +
13484 +       u_char                          c, *cp;
13485 +       volatile        cbd_t           *bdp;
13486 +       int                             i;
13487 +
13488 +       pinfo = &cpm_uart_ports[KGDB_PINFO_INDEX];
13489 +
13490 +       /* Get the address of the host memory buffer.
13491 +        */
13492 +       bdp = pinfo->rx_cur;
13493 +       while (bdp->cbd_sc & BD_SC_EMPTY);
13494 +
13495 +       /* If the buffer address is in the CPM DPRAM, don't
13496 +        * convert it.
13497 +        */
13498 +       cp = cpm2cpu_addr(bdp->cbd_bufaddr);
13499 +
13500 +       if (obuf) {
13501 +               i = c = bdp->cbd_datlen;
13502 +               while (i-- > 0)
13503 +               {
13504 +                       *obuf++ = *cp++;
13505 +               }
13506 +       } else {
13507 +               c = *cp;
13508 +       }
13509 +       bdp->cbd_sc |= BD_SC_EMPTY;
13510 +
13511 +       if (bdp->cbd_sc & BD_SC_WRAP) {
13512 +               bdp = pinfo->rx_bd_base;
13513 +       } else {
13514 +               bdp++;
13515 +       }
13516 +       pinfo->rx_cur = (cbd_t *)bdp;
13517 +
13518 +       return((int)c);
13519 +}
13520 +
13521 +
13522 +/*
13523 + * Wait until the interface can accept a char, then write it.
13524 + */
13525 +static void
13526 +kgdb_put_debug_char(int chr)
13527 +{
13528 +       static char ch[2];
13529 +       ch[0]=(char)chr;
13530 +       cpm_uart_early_write(KGDB_PINFO_INDEX, ch, 1);
13531 +}
13532 +
13533 +
13534 +/*
13535 + * Get a char if available, return -1 if nothing available.
13536 + * Empty the receive buffer first, then look at the interface hardware.
13537 + */
13538 +static int
13539 +kgdb_get_debug_char(void)
13540 +{
13541 +       if (kgdb_chars<=0) {
13542 +               kgdb_chars = kgdb_wait_key(kgdb_buf);
13543 +               kgdbp = kgdb_buf;
13544 +       }
13545 +       kgdb_chars--;
13546 +
13547 +       return (*kgdbp++);
13548 +}
13549 +
13550 +static void termios_set_options(int index,
13551 +                int baud, int parity, int bits, int flow)
13552 +{
13553 +       struct termios termios;
13554 +       struct uart_port *port;
13555 +       struct uart_cpm_port *pinfo;
13556 +
13557 +       BUG_ON(index>UART_NR);
13558 +
13559 +       port =
13560 +           (struct uart_port *)&cpm_uart_ports[index];
13561 +       pinfo = (struct uart_cpm_port *)port;
13562 +
13563 +       /*
13564 +        * Ensure that the serial console lock is initialised
13565 +        * early.
13566 +        */
13567 +       spin_lock_init(&port->lock);
13568 +
13569 +       memset(&termios, 0, sizeof(struct termios));
13570 +
13571 +       termios.c_cflag = CREAD | HUPCL | CLOCAL;
13572 +
13573 +       termios.c_cflag |= baud;
13574 +
13575 +       if (bits == 7)
13576 +               termios.c_cflag |= CS7;
13577 +       else
13578 +               termios.c_cflag |= CS8;
13579 +
13580 +       switch (parity) {
13581 +       case 'o': case 'O':
13582 +               termios.c_cflag |= PARODD;
13583 +               /*fall through*/
13584 +       case 'e': case 'E':
13585 +               termios.c_cflag |= PARENB;
13586 +               break;
13587 +       }
13588 +
13589 +       if (flow == 'r')
13590 +               termios.c_cflag |= CRTSCTS;
13591 +
13592 +       port->ops->set_termios(port, &termios, NULL);
13593 +}
13594 +
13595 +/*
13596 + *  Returns:
13597 + *     0 on success, 1 on failure.
13598 + */
13599 +static int kgdb_init(void)
13600 +{
13601 +       struct uart_port *port;
13602 +       struct uart_cpm_port *pinfo;
13603 +
13604 +       int use_bootmem = 0; /* use dma by default */
13605 +
13606 +       if(!cpm_uart_nr)
13607 +       {
13608 +               use_bootmem = 1;
13609 +               cpm_uart_init_portdesc();
13610 +       }
13611 +       port = (struct uart_port *)&cpm_uart_ports[KGDB_PINFO_INDEX];
13612 +       pinfo = (struct uart_cpm_port *)port;
13613 +
13614 +       if (cpm_uart_early_setup(KGDB_PINFO_INDEX, use_bootmem))
13615 +               return 1;
13616 +
13617 +       termios_set_options(KGDB_PINFO_INDEX, KGDB_BAUD,'n',8,'n');
13618 +        if (IS_SMC(pinfo))
13619 +                pinfo->smcp->smc_smcm |= SMCM_TX;
13620 +        else
13621 +                pinfo->sccp->scc_sccm |= UART_SCCM_TX;
13622 +
13623 +       return 0;
13624 +}
13625 +
13626 +
13627 +struct kgdb_io kgdb_io_ops = {
13628 +       .read_char = kgdb_get_debug_char,
13629 +       .write_char = kgdb_put_debug_char,
13630 +       .init = kgdb_init,
13631 +};
13632 +
13633 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/mpsc.c linux-2.6.18.kgdb/drivers/serial/mpsc.c
13634 --- linux-2.6.18/drivers/serial/mpsc.c  2006-09-20 07:42:06.000000000 +0400
13635 +++ linux-2.6.18.kgdb/drivers/serial/mpsc.c     2008-06-10 16:19:22.000000000 +0400
13636 @@ -242,6 +242,11 @@ struct mpsc_port_info *mpsc_device_remov
13637  #define        MPSC_RCRR                       0x0004
13638  #define        MPSC_TCRR                       0x0008
13639  
13640 +/* MPSC Interrupt registers (offset from MV64x60_SDMA_INTR_OFFSET) */
13641 +#define MPSC_INTR_CAUSE                        0x0004
13642 +#define MPSC_INTR_MASK                 0x0084
13643 +#define MPSC_INTR_CAUSE_RCC            (1<<6)
13644 +
13645  /* Serial DMA Controller Interface Registers */
13646  #define        SDMA_SDC                        0x0000
13647  #define        SDMA_SDCM                       0x0008
13648 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/mpsc_kgdb.c linux-2.6.18.kgdb/drivers/serial/mpsc_kgdb.c
13649 --- linux-2.6.18/drivers/serial/mpsc_kgdb.c     1970-01-01 03:00:00.000000000 +0300
13650 +++ linux-2.6.18.kgdb/drivers/serial/mpsc_kgdb.c        2008-06-10 16:19:22.000000000 +0400
13651 @@ -0,0 +1,299 @@
13652 +/*
13653 + * drivers/serial/mpsc_kgdb.c
13654 + *
13655 + * KGDB driver for the Marvell MultiProtocol Serial Controller (MPCS)
13656 + *
13657 + * Based on the polled boot loader driver by Ajit Prem (ajit.prem@motorola.com)
13658 + *
13659 + * Author: Randy Vinson <rvinson@mvista.com>
13660 + *
13661 + * 2005 (c) MontaVista Software, Inc.
13662 + * This program is free software; you can redistribute  it and/or modify it
13663 + * under  the terms of  the GNU General  Public License as published by the
13664 + * Free Software Foundation;  either version 2 of the  License, or (at your
13665 + * option) any later version.
13666 + */
13667 +
13668 +#include <linux/config.h>
13669 +#include <linux/kgdb.h>
13670 +#include <linux/mv643xx.h>
13671 +#include <linux/device.h>
13672 +#include <asm/mv64x60.h>
13673 +#include <asm/serial.h>
13674 +#include <asm/io.h>
13675 +#include <asm/delay.h>
13676 +
13677 +#include "mpsc.h"
13678 +
13679 +/* Speed of the UART. */
13680 +static int kgdbmpsc_baud = CONFIG_KGDB_BAUDRATE;
13681 +
13682 +/* Index of the UART, matches ttyMX naming. */
13683 +static int kgdbmpsc_ttyMM = CONFIG_KGDB_PORT_NUM;
13684 +
13685 +#define MPSC_INTR_REG_SELECT(x)        ((x) + (8 * kgdbmpsc_ttyMM))
13686 +
13687 +static int kgdbmpsc_init(void);
13688 +
13689 +static struct platform_device mpsc_dev, shared_dev;
13690 +
13691 +static void __iomem *mpsc_base;
13692 +static void __iomem *brg_base;
13693 +static void __iomem *routing_base;
13694 +static void __iomem *sdma_base;
13695 +
13696 +static unsigned int mpsc_irq;
13697 +
13698 +static void kgdb_write_debug_char(int c)
13699 +{
13700 +       u32 data;
13701 +
13702 +       data = readl(mpsc_base + MPSC_MPCR);
13703 +       writeb(c, mpsc_base + MPSC_CHR_1);
13704 +       mb();
13705 +       data = readl(mpsc_base + MPSC_CHR_2);
13706 +       data |= MPSC_CHR_2_TTCS;
13707 +       writel(data, mpsc_base + MPSC_CHR_2);
13708 +       mb();
13709 +
13710 +       while (readl(mpsc_base + MPSC_CHR_2) & MPSC_CHR_2_TTCS) ;
13711 +}
13712 +
13713 +static int kgdb_get_debug_char(void)
13714 +{
13715 +       unsigned char c;
13716 +
13717 +       while (!(readl(sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_CAUSE)) &
13718 +                MPSC_INTR_CAUSE_RCC)) ;
13719 +
13720 +       c = readb(mpsc_base + MPSC_CHR_10 + (1 << 1));
13721 +       mb();
13722 +       writeb(c, mpsc_base + MPSC_CHR_10 + (1 << 1));
13723 +       mb();
13724 +       writel(~MPSC_INTR_CAUSE_RCC, sdma_base +
13725 +              MPSC_INTR_REG_SELECT(MPSC_INTR_CAUSE));
13726 +       return (c);
13727 +}
13728 +
13729 +/*
13730 + * This is the receiver interrupt routine for the GDB stub.
13731 + * All that we need to do is verify that the interrupt happened on the
13732 + * line we're in charge of.  If this is true, schedule a breakpoint and
13733 + * return.
13734 + */
13735 +static irqreturn_t
13736 +kgdbmpsc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
13737 +{
13738 +       if (irq != mpsc_irq)
13739 +               return IRQ_NONE;
13740 +       /*
13741 +        * If  there is some other CPU in KGDB then this is a
13742 +        * spurious interrupt. so return without even checking a byte
13743 +        */
13744 +       if (atomic_read(&debugger_active))
13745 +               return IRQ_NONE;
13746 +
13747 +       if (readl(sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_CAUSE)) &
13748 +           MPSC_INTR_CAUSE_RCC)
13749 +               breakpoint();
13750 +
13751 +       return IRQ_HANDLED;
13752 +}
13753 +
13754 +static int __init kgdbmpsc_init(void)
13755 +{
13756 +       struct mpsc_pdata *pdata;
13757 +       u32 cdv;
13758 +
13759 +       if (!brg_base || !mpsc_base || !routing_base || !sdma_base)
13760 +               return -1;
13761 +
13762 +       /* Set MPSC Routing to enable both ports */
13763 +       writel(0x0, routing_base + MPSC_MRR);
13764 +
13765 +       /* MPSC 0/1 Rx & Tx get clocks BRG0/1 */
13766 +       writel(0x00000100, routing_base + MPSC_RCRR);
13767 +       writel(0x00000100, routing_base + MPSC_TCRR);
13768 +
13769 +       /* Disable all MPSC interrupts and clear any pending interrupts */
13770 +       writel(0, sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_MASK));
13771 +       writel(0, sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_CAUSE));
13772 +
13773 +       pdata = (struct mpsc_pdata *)mpsc_dev.dev.platform_data;
13774 +
13775 +       /* cdv = (clock/(2*16*baud rate)) for 16X mode. */
13776 +       cdv = ((pdata->brg_clk_freq / (32 * kgdbmpsc_baud)) - 1);
13777 +       writel((pdata->brg_clk_src << 18) | (1 << 16) | cdv,
13778 +              brg_base + BRG_BCR);
13779 +
13780 +       /* Put MPSC into UART mode, no null modem, 16x clock mode */
13781 +       writel(0x000004c4, mpsc_base + MPSC_MMCRL);
13782 +       writel(0x04400400, mpsc_base + MPSC_MMCRH);
13783 +
13784 +       writel(0, mpsc_base + MPSC_CHR_1);
13785 +       writel(0, mpsc_base + MPSC_CHR_9);
13786 +       writel(0, mpsc_base + MPSC_CHR_10);
13787 +       writel(4, mpsc_base + MPSC_CHR_3);
13788 +       writel(0x20000000, mpsc_base + MPSC_CHR_4);
13789 +       writel(0x9000, mpsc_base + MPSC_CHR_5);
13790 +       writel(0, mpsc_base + MPSC_CHR_6);
13791 +       writel(0, mpsc_base + MPSC_CHR_7);
13792 +       writel(0, mpsc_base + MPSC_CHR_8);
13793 +
13794 +       /* 8 data bits, 1 stop bit */
13795 +       writel((3 << 12), mpsc_base + MPSC_MPCR);
13796 +
13797 +       /* Enter "hunt" mode */
13798 +       writel((1 << 31), mpsc_base + MPSC_CHR_2);
13799 +
13800 +       udelay(100);
13801 +       return 0;
13802 +}
13803 +
13804 +static void __iomem *__init
13805 +kgdbmpsc_map_resource(struct platform_device *pd, int type, int num)
13806 +{
13807 +       void __iomem *base = NULL;
13808 +       struct resource *r;
13809 +
13810 +       if ((r = platform_get_resource(pd, IORESOURCE_MEM, num)))
13811 +               base = ioremap(r->start, r->end - r->start + 1);
13812 +       return base;
13813 +}
13814 +
13815 +static void __iomem *__init
13816 +kgdbmpsc_unmap_resource(struct platform_device *pd, int type, int num,
13817 +                       void __iomem * base)
13818 +{
13819 +       if (base)
13820 +               iounmap(base);
13821 +       return NULL;
13822 +}
13823 +
13824 +static void __init
13825 +kgdbmpsc_reserve_resource(struct platform_device *pd, int type, int num)
13826 +{
13827 +       struct resource *r;
13828 +
13829 +       if ((r = platform_get_resource(pd, IORESOURCE_MEM, num)))
13830 +               request_mem_region(r->start, r->end - r->start + 1, "kgdb");
13831 +}
13832 +
13833 +static int __init kgdbmpsc_local_init(void)
13834 +{
13835 +       if (!mpsc_dev.num_resources || !shared_dev.num_resources)
13836 +               return 1;       /* failure */
13837 +
13838 +       mpsc_base = kgdbmpsc_map_resource(&mpsc_dev, IORESOURCE_MEM,
13839 +                                         MPSC_BASE_ORDER);
13840 +       brg_base = kgdbmpsc_map_resource(&mpsc_dev, IORESOURCE_MEM,
13841 +                                        MPSC_BRG_BASE_ORDER);
13842 +
13843 +       /* get the platform data for the shared registers and get them mapped */
13844 +       routing_base = kgdbmpsc_map_resource(&shared_dev,
13845 +                                            IORESOURCE_MEM,
13846 +                                            MPSC_ROUTING_BASE_ORDER);
13847 +       sdma_base =
13848 +           kgdbmpsc_map_resource(&shared_dev, IORESOURCE_MEM,
13849 +                                 MPSC_SDMA_INTR_BASE_ORDER);
13850 +
13851 +       mpsc_irq = platform_get_irq(&mpsc_dev, 1);
13852 +
13853 +       if (mpsc_base && brg_base && routing_base && sdma_base)
13854 +               return 0;       /* success */
13855 +
13856 +       return 1;               /* failure */
13857 +}
13858 +
13859 +static void __init kgdbmpsc_local_exit(void)
13860 +{
13861 +       if (sdma_base)
13862 +               sdma_base = kgdbmpsc_unmap_resource(&shared_dev, IORESOURCE_MEM,
13863 +                                                   MPSC_SDMA_INTR_BASE_ORDER,
13864 +                                                   sdma_base);
13865 +       if (routing_base)
13866 +               routing_base = kgdbmpsc_unmap_resource(&shared_dev,
13867 +                                                      IORESOURCE_MEM,
13868 +                                                      MPSC_ROUTING_BASE_ORDER,
13869 +                                                      routing_base);
13870 +       if (brg_base)
13871 +               brg_base = kgdbmpsc_unmap_resource(&mpsc_dev, IORESOURCE_MEM,
13872 +                                                  MPSC_BRG_BASE_ORDER,
13873 +                                                  brg_base);
13874 +       if (mpsc_base)
13875 +               mpsc_base = kgdbmpsc_unmap_resource(&mpsc_dev, IORESOURCE_MEM,
13876 +                                                   MPSC_BASE_ORDER, mpsc_base);
13877 +}
13878 +
13879 +static void __init kgdbmpsc_update_pdata(struct platform_device *pdev)
13880 +{
13881 +
13882 +       snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s%u", pdev->name, pdev->id);
13883 +}
13884 +
13885 +static int __init kgdbmpsc_pdev_init(void)
13886 +{
13887 +       struct platform_device *pdev;
13888 +
13889 +       /* get the platform data for the specified port. */
13890 +       pdev = mv64x60_early_get_pdev_data(MPSC_CTLR_NAME, kgdbmpsc_ttyMM, 1);
13891 +       if (pdev) {
13892 +               memcpy(&mpsc_dev, pdev, sizeof(struct platform_device));
13893 +               if (platform_notify) {
13894 +                       kgdbmpsc_update_pdata(&mpsc_dev);
13895 +                       platform_notify(&mpsc_dev.dev);
13896 +               }
13897 +
13898 +               /* get the platform data for the shared registers. */
13899 +               pdev = mv64x60_early_get_pdev_data(MPSC_SHARED_NAME, 0, 0);
13900 +               if (pdev) {
13901 +                       memcpy(&shared_dev, pdev,
13902 +                              sizeof(struct platform_device));
13903 +                       if (platform_notify) {
13904 +                               kgdbmpsc_update_pdata(&shared_dev);
13905 +                               platform_notify(&shared_dev.dev);
13906 +                       }
13907 +               }
13908 +       }
13909 +       return 0;
13910 +}
13911 +
13912 +postcore_initcall(kgdbmpsc_pdev_init);
13913 +
13914 +static int __init kgdbmpsc_init_io(void)
13915 +{
13916 +
13917 +       kgdbmpsc_pdev_init();
13918 +
13919 +       if (kgdbmpsc_local_init()) {
13920 +               kgdbmpsc_local_exit();
13921 +               return -1;
13922 +       }
13923 +
13924 +       if (kgdbmpsc_init() == -1)
13925 +               return -1;
13926 +       return 0;
13927 +}
13928 +
13929 +static void __init kgdbmpsc_hookup_irq(void)
13930 +{
13931 +       unsigned int msk;
13932 +       if (!request_irq(mpsc_irq, kgdbmpsc_interrupt, 0, "kgdb mpsc", NULL)) {
13933 +               /* Enable interrupt */
13934 +               msk = readl(sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_MASK));
13935 +               msk |= MPSC_INTR_CAUSE_RCC;
13936 +               writel(msk, sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_MASK));
13937 +
13938 +               kgdbmpsc_reserve_resource(&mpsc_dev, IORESOURCE_MEM,
13939 +                                         MPSC_BASE_ORDER);
13940 +               kgdbmpsc_reserve_resource(&mpsc_dev, IORESOURCE_MEM,
13941 +                                         MPSC_BRG_BASE_ORDER);
13942 +       }
13943 +}
13944 +
13945 +struct kgdb_io kgdb_io_ops = {
13946 +       .read_char = kgdb_get_debug_char,
13947 +       .write_char = kgdb_write_debug_char,
13948 +       .init = kgdbmpsc_init_io,
13949 +       .late_init = kgdbmpsc_hookup_irq,
13950 +};
13951 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/pxa.c linux-2.6.18.kgdb/drivers/serial/pxa.c
13952 --- linux-2.6.18/drivers/serial/pxa.c   2006-09-20 07:42:06.000000000 +0400
13953 +++ linux-2.6.18.kgdb/drivers/serial/pxa.c      2008-06-10 16:19:51.000000000 +0400
13954 @@ -42,6 +42,9 @@
13955  #include <linux/tty.h>
13956  #include <linux/tty_flip.h>
13957  #include <linux/serial_core.h>
13958 +#ifdef CONFIG_KGDB_CONSOLE
13959 +#include <linux/kgdb.h>
13960 +#endif
13961  
13962  #include <asm/io.h>
13963  #include <asm/hardware.h>
13964 @@ -692,6 +695,8 @@ serial_pxa_console_init(void)
13965  console_initcall(serial_pxa_console_init);
13966  
13967  #define PXA_CONSOLE    &serial_pxa_console
13968 +#elif defined(CONFIG_KGDB_CONSOLE)
13969 +#define PXA_CONSOLE    &kgdbcons
13970  #else
13971  #define PXA_CONSOLE    NULL
13972  #endif
13973 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/serial_core.c linux-2.6.18.kgdb/drivers/serial/serial_core.c
13974 --- linux-2.6.18/drivers/serial/serial_core.c   2006-09-20 07:42:06.000000000 +0400
13975 +++ linux-2.6.18.kgdb/drivers/serial/serial_core.c      2008-06-10 16:19:03.000000000 +0400
13976 @@ -33,6 +33,7 @@
13977  #include <linux/serial.h> /* for serial_state and serial_icounter_struct */
13978  #include <linux/delay.h>
13979  #include <linux/mutex.h>
13980 +#include <linux/kgdb.h>
13981  
13982  #include <asm/irq.h>
13983  #include <asm/uaccess.h>
13984 @@ -65,6 +66,12 @@ static struct lock_class_key port_lock_k
13985  #define uart_console(port)     (0)
13986  #endif
13987  
13988 +#ifdef CONFIG_KGDB_CONSOLE
13989 +#define uart_kgdb(port)                (port->cons && !strcmp(port->cons->name, "kgdb"))
13990 +#else
13991 +#define uart_kgdb(port)                (0)
13992 +#endif
13993 +
13994  static void uart_change_speed(struct uart_state *state, struct termios *old_termios);
13995  static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
13996  static void uart_change_pm(struct uart_state *state, int pm_state);
13997 @@ -1673,6 +1680,9 @@ static int uart_line_info(char *buf, str
13998                         port->iotype == UPIO_MEM ? port->mapbase :
13999                                                 (unsigned long) port->iobase,
14000                         port->irq);
14001 +       if (port->iotype == UPIO_MEM)
14002 +               ret += sprintf(buf+ret, " membase 0x%08lX",
14003 +                                          (unsigned long) port->membase);
14004  
14005         if (port->type == PORT_UNKNOWN) {
14006                 strcat(buf, "\n");
14007 @@ -2038,7 +2048,8 @@ uart_report_port(struct uart_driver *drv
14008         case UPIO_AU:
14009         case UPIO_TSI:
14010                 snprintf(address, sizeof(address),
14011 -                        "MMIO 0x%lx", port->mapbase);
14012 +                       "MMIO map 0x%lx mem 0x%lx", port->mapbase,
14013 +                       (unsigned long) port->membase);
14014                 break;
14015         default:
14016                 strlcpy(address, "*unknown*", sizeof(address));
14017 @@ -2090,9 +2101,9 @@ uart_configure_port(struct uart_driver *
14018  
14019                 /*
14020                  * Power down all ports by default, except the
14021 -                * console if we have one.
14022 +                * console (real or kgdb) if we have one.
14023                  */
14024 -               if (!uart_console(port))
14025 +               if (!uart_console(port) && !uart_kgdb(port))
14026                         uart_change_pm(state, 3);
14027         }
14028  }
14029 @@ -2284,6 +2295,12 @@ int uart_add_one_port(struct uart_driver
14030          */
14031         port->flags &= ~UPF_DEAD;
14032  
14033 +#if defined(CONFIG_KGDB_8250)
14034 +       /* Add any 8250-like ports we find later. */
14035 +       if (port->type <= PORT_MAX_8250)
14036 +               kgdb8250_add_port(port->line, port);
14037 +#endif
14038 +
14039   out:
14040         mutex_unlock(&state->mutex);
14041         mutex_unlock(&port_mutex);
14042 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/serial_txx9.c linux-2.6.18.kgdb/drivers/serial/serial_txx9.c
14043 --- linux-2.6.18/drivers/serial/serial_txx9.c   2006-09-20 07:42:06.000000000 +0400
14044 +++ linux-2.6.18.kgdb/drivers/serial/serial_txx9.c      2008-06-10 16:19:28.000000000 +0400
14045 @@ -1164,6 +1164,96 @@ static struct pci_driver serial_txx9_pci
14046  MODULE_DEVICE_TABLE(pci, serial_txx9_pci_tbl);
14047  #endif /* ENABLE_SERIAL_TXX9_PCI */
14048  
14049 +/******************************************************************************/
14050 +/* BEG: KDBG Routines                                                         */
14051 +/******************************************************************************/
14052 +
14053 +#ifdef CONFIG_KGDB
14054 +int kgdb_init_count = 0;
14055 +
14056 +void txx9_sio_kgdb_hook(unsigned int port, unsigned int baud_rate)
14057 +{
14058 +       static struct resource kgdb_resource;
14059 +       int ret;
14060 +       struct uart_txx9_port *up = &serial_txx9_ports[port];
14061 +
14062 +       /* prevent initialization by driver */
14063 +       kgdb_resource.name = "serial_txx9(debug)";
14064 +       kgdb_resource.start = (unsigned long)up->port.membase;
14065 +       kgdb_resource.end = (unsigned long)(up->port.membase + 36 - 1);
14066 +       kgdb_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
14067 +
14068 +       ret = request_resource(&iomem_resource, &kgdb_resource);
14069 +       if(ret == -EBUSY)
14070 +               printk(" serial_txx9(debug): request_resource failed\n");
14071 +
14072 +       return;
14073 +}
14074 +void
14075 +txx9_sio_kdbg_init( unsigned int port_number )
14076 +{
14077 +       if (port_number == 1) {
14078 +               txx9_sio_kgdb_hook(port_number, 38400);
14079 +       } else {
14080 +               printk("Bad Port Number [%u] != [1]\n",port_number);
14081 +       }
14082 +       return;
14083 +}
14084 +
14085 +u8
14086 +txx9_sio_kdbg_rd( void )
14087 +{
14088 +       unsigned int status,ch;
14089 +       struct uart_txx9_port *up = &serial_txx9_ports[1];
14090 +
14091 +       if (kgdb_init_count == 0) {
14092 +               txx9_sio_kdbg_init(1);
14093 +               kgdb_init_count = 1;
14094 +       }
14095 +
14096 +       while (1) {
14097 +               status = sio_in(up, TXX9_SIDISR);
14098 +               if ( status & 0x1f ) {
14099 +                       ch = sio_in(up, TXX9_SIRFIFO );
14100 +                       break;
14101 +               }
14102 +       }
14103 +
14104 +       return (ch);
14105 +}
14106 +
14107 +int
14108 +txx9_sio_kdbg_wr( u8 ch )
14109 +{
14110 +       unsigned int status;
14111 +       struct uart_txx9_port *up = &serial_txx9_ports[1];
14112 +
14113 +       if (kgdb_init_count == 0) {
14114 +               txx9_sio_kdbg_init(1);
14115 +               kgdb_init_count = 1;
14116 +       }
14117 +
14118 +       while (1) {
14119 +               status = sio_in(up, TXX9_SICISR);
14120 +               if (status & TXX9_SICISR_TRDY) {
14121 +                       if ( ch == '\n' ) {
14122 +                               txx9_sio_kdbg_wr( '\r' );
14123 +                       }
14124 +                       sio_out(up, TXX9_SITFIFO, (u32)ch );
14125 +
14126 +                       break;
14127 +               }
14128 +       }
14129 +
14130 +       return (1);
14131 +}
14132 +#endif /* CONFIG_KGDB */
14133 +
14134 +
14135 +/******************************************************************************/
14136 +/* END: KDBG Routines                                                         */
14137 +/******************************************************************************/
14138 +
14139  static int __init serial_txx9_init(void)
14140  {
14141         int ret;
14142 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/drivers/serial/sh-sci.c linux-2.6.18.kgdb/drivers/serial/sh-sci.c
14143 --- linux-2.6.18/drivers/serial/sh-sci.c        2006-09-20 07:42:06.000000000 +0400
14144 +++ linux-2.6.18.kgdb/drivers/serial/sh-sci.c   2008-06-10 16:19:47.000000000 +0400
14145 @@ -42,6 +42,7 @@
14146  #include <linux/console.h>
14147  #include <linux/bitops.h>
14148  #include <linux/generic_serial.h>
14149 +#include <linux/kgdb.h>
14150  
14151  #ifdef CONFIG_CPU_FREQ
14152  #include <linux/notifier.h>
14153 @@ -67,14 +68,16 @@
14154  
14155  #include "sh-sci.h"
14156  
14157 -#ifdef CONFIG_SH_KGDB
14158 -#include <asm/kgdb.h>
14159 -
14160 -static int kgdb_get_char(struct sci_port *port);
14161 -static void kgdb_put_char(struct sci_port *port, char c);
14162 -static void kgdb_handle_error(struct sci_port *port);
14163 -static struct sci_port *kgdb_sci_port;
14164 -#endif /* CONFIG_SH_KGDB */
14165 +#ifdef CONFIG_KGDB_SH_SCI
14166 +/* Speed of the UART. */
14167 +static int kgdbsci_baud = CONFIG_KGDB_BAUDRATE
14168 +
14169 +/* Index of the UART, matches ttySCX naming. */
14170 +static int kgdbsci_ttySC = CONFIG_KGDB_PORT_NUM;
14171 +
14172 +/* Make life easier on us. */
14173 +#define KGDBPORT       sci_ports[kgdbsci_ttySC]
14174 +#endif /* CONFIG_KGDB_SH_SCI */
14175  
14176  #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
14177  static struct sci_port *serial_console_port = 0;
14178 @@ -87,20 +90,17 @@ static void sci_start_rx(struct uart_por
14179  static void sci_stop_rx(struct uart_port *port);
14180  static int sci_request_irq(struct sci_port *port);
14181  static void sci_free_irq(struct sci_port *port);
14182 +static void sci_set_termios(struct uart_port *port, struct termios *termios,
14183 +                       struct termios *old);
14184 +static int kgdbsci_init(void);
14185  
14186  static struct sci_port sci_ports[];
14187  static struct uart_driver sci_uart_driver;
14188  
14189  #define SCI_NPORTS sci_uart_driver.nr
14190  
14191 -#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
14192 -
14193 -static void handle_error(struct uart_port *port)
14194 -{                              /* Clear error flags */
14195 -       sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
14196 -}
14197 -
14198 -static int get_char(struct uart_port *port)
14199 +#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_KGDB_SH_SCI)
14200 +static int get_char_for_gdb(struct uart_port *port)
14201  {
14202         unsigned long flags;
14203         unsigned short status;
14204 @@ -110,7 +110,8 @@ static int get_char(struct uart_port *po
14205          do {
14206                 status = sci_in(port, SCxSR);
14207                 if (status & SCxSR_ERRORS(port)) {
14208 -                       handle_error(port);
14209 +                       /* Clear error flags. */
14210 +                       sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
14211                         continue;
14212                 }
14213         } while (!(status & SCxSR_RDxF(port)));
14214 @@ -121,21 +122,7 @@ static int get_char(struct uart_port *po
14215  
14216         return c;
14217  }
14218 -
14219 -/* Taken from sh-stub.c of GDB 4.18 */
14220 -static const char hexchars[] = "0123456789abcdef";
14221 -
14222 -static __inline__ char highhex(int  x)
14223 -{
14224 -       return hexchars[(x >> 4) & 0xf];
14225 -}
14226 -
14227 -static __inline__ char lowhex(int  x)
14228 -{
14229 -       return hexchars[x & 0xf];
14230 -}
14231 -
14232 -#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
14233 +#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_KGDB_SH_SCI */
14234  
14235  /*
14236   * Send the packet in buffer.  The host gets one chance to read it.
14237 @@ -167,21 +154,14 @@ static void put_string(struct sci_port *
14238         const unsigned char *p = buffer;
14239         int i;
14240  
14241 -#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
14242 -       int checksum;
14243 -       int usegdb=0;
14244 -
14245  #ifdef CONFIG_SH_STANDARD_BIOS
14246 +       int checksum;
14247 +        const char hexchars[] = "0123456789abcdef";
14248 +       
14249         /* This call only does a trap the first time it is
14250          * called, and so is safe to do here unconditionally
14251          */
14252 -       usegdb |= sh_bios_in_gdb_mode();
14253 -#endif
14254 -#ifdef CONFIG_SH_KGDB
14255 -       usegdb |= (kgdb_in_gdb_mode && (port == kgdb_sci_port));
14256 -#endif
14257 -
14258 -       if (usegdb) {
14259 +       if (sh_bios_in_gdb_mode()) {
14260             /*  $<packet info>#<checksum>. */
14261             do {
14262                 unsigned char c;
14263 @@ -193,18 +173,18 @@ static void put_string(struct sci_port *
14264                         int h, l;
14265  
14266                         c = *p++;
14267 -                       h = highhex(c);
14268 -                       l = lowhex(c);
14269 +                       h = hexchars[c >> 4];
14270 +                       l = hexchars[c % 16];
14271                         put_char(port, h);
14272                         put_char(port, l);
14273                         checksum += h + l;
14274                 }
14275                 put_char(port, '#');
14276 -               put_char(port, highhex(checksum));
14277 -               put_char(port, lowhex(checksum));
14278 +               put_char(port, hexchars[checksum >> 4]);
14279 +               put_char(port, hexchars[checksum % 16]);
14280             } while  (get_char(port) != '+');
14281         } else
14282 -#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
14283 +#endif /* CONFIG_SH_STANDARD_BIOS */
14284         for (i=0; i<count; i++) {
14285                 if (*p == 10)
14286                         put_char(port, '\r');
14287 @@ -214,90 +194,163 @@ static void put_string(struct sci_port *
14288  #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
14289  
14290  
14291 -#ifdef CONFIG_SH_KGDB
14292 -
14293 -/* Is the SCI ready, ie is there a char waiting? */
14294 -static int kgdb_is_char_ready(struct sci_port *port)
14295 +#ifdef CONFIG_KGDB_SH_SCI
14296 +static int kgdbsci_read_char(void)
14297  {
14298 -        unsigned short status = sci_in(port, SCxSR);
14299 -
14300 -        if (status & (SCxSR_ERRORS(port) | SCxSR_BRK(port)))
14301 -                kgdb_handle_error(port);
14302 -
14303 -        return (status & SCxSR_RDxF(port));
14304 +       return get_char_for_gdb(&KGDBPORT.port);
14305  }
14306  
14307 -/* Write a char */
14308 -static void kgdb_put_char(struct sci_port *port, char c)
14309 +/* Called from kgdbstub.c to put a character, just a wrapper */
14310 +static void kgdbsci_write_char(int c)
14311  {
14312 -        unsigned short status;
14313 -
14314 -        do
14315 -                status = sci_in(port, SCxSR);
14316 -        while (!(status & SCxSR_TDxE(port)));
14317 +       unsigned short status;
14318  
14319 -        sci_out(port, SCxTDR, c);
14320 -        sci_in(port, SCxSR);    /* Dummy read */
14321 -        sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
14322 +       do
14323 +               status = sci_in(&KGDBPORT.port, SCxSR);
14324 +       while (!(status & SCxSR_TDxE(&KGDBPORT.port)));
14325 +
14326 +       sci_out(&KGDBPORT.port, SCxTDR, c);
14327 +       sci_in(&KGDBPORT.port, SCxSR);  /* Dummy read */
14328 +       sci_out(&KGDBPORT.port, SCxSR, SCxSR_TDxE_CLEAR(&KGDBPORT.port));
14329  }
14330  
14331 -/* Get a char if there is one, else ret -1 */
14332 -static int kgdb_get_char(struct sci_port *port)
14333 +#ifndef CONFIG_SERIAL_SH_SCI_CONSOLE
14334 +/* If we don't have console, we never hookup IRQs.  But we need to
14335 + * hookup one so that we can interrupt the system.
14336 + */
14337 +static irqreturn_t kgdbsci_rx_interrupt(int irq, void *ptr,
14338 +               struct pt_regs *regs)
14339  {
14340 -        int c;
14341 +       struct uart_port *port = ptr;
14342  
14343 -        if (kgdb_is_char_ready(port) == 0)
14344 -                c = -1;
14345 -        else {
14346 -                c = sci_in(port, SCxRDR);
14347 -                sci_in(port, SCxSR);    /* Dummy read */
14348 -                sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
14349 -        }
14350 +       if (!(sci_in(port, SCxSR) & SCxSR_RDxF(port)))
14351 +               return IRQ_NONE;
14352  
14353 -        return c;
14354 -}
14355 -
14356 -/* Called from kgdbstub.c to get a character, i.e. is blocking */
14357 -static int kgdb_sci_getchar(void)
14358 -{
14359 -        volatile int c;
14360 +       if (kgdb_io_ops.init != kgdbsci_init) {
14361 +               /* Throw away the data if another I/O routine is active */
14362 +               get_char_for_gdb(&KGDBPORT.port);
14363 +       } else
14364 +               /* We've got an interrupt, so go ahead and call breakpoint() */
14365 +               breakpoint();
14366  
14367 -        /* Keep trying to read a character, this could be neater */
14368 -        while ((c = kgdb_get_char(kgdb_sci_port)) < 0);
14369 +       sci_in(port, SCxSR); /* dummy read */
14370 +       sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
14371  
14372 -        return c;
14373 +       return IRQ_HANDLED;
14374  }
14375  
14376 -/* Called from kgdbstub.c to put a character, just a wrapper */
14377 -static void kgdb_sci_putchar(int c)
14378 +static irqreturn_t kgdbsci_mpxed_interrupt(int irq, void *ptr,
14379 +               struct pt_regs *regs)
14380  {
14381 +        unsigned short ssr_status, scr_status;
14382 +        struct uart_port *port = ptr;
14383 +
14384 +        ssr_status = sci_in(port,SCxSR);
14385 +        scr_status = sci_in(port,SCSCR);
14386 +
14387 +       /* Rx Interrupt */
14388 +        if ((ssr_status&0x0002) && (scr_status&0x0040))
14389 +               kgdbsci_rx_interrupt(irq, ptr, regs);
14390  
14391 -        kgdb_put_char(kgdb_sci_port, c);
14392 +       return IRQ_HANDLED;
14393  }
14394  
14395 -/* Clear any errors on the SCI */
14396 -static void kgdb_handle_error(struct sci_port *port)
14397 +static void __init kgdbsci_lateinit(void)
14398  {
14399 -        sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));  /* Clear error flags */
14400 +       if (KGDBPORT.irqs[0] == KGDBPORT.irqs[1]) {
14401 +               if (!KGDBPORT.irqs[0]) {
14402 +                       printk(KERN_ERR "kgdbsci: Cannot allocate irq.\n");
14403 +                       return;
14404 +               }
14405 +               if (request_irq(KGDBPORT.irqs[0], kgdbsci_mpxed_interrupt,
14406 +                                       SA_INTERRUPT, "kgdbsci",
14407 +                                       &KGDBPORT.port)) {
14408 +                       printk(KERN_ERR "kgdbsci: Cannot allocate irq.\n");
14409 +                       return;
14410 +               }
14411 +       } else {
14412 +               if (KGDBPORT.irqs[1])
14413 +                       request_irq(KGDBPORT.irqs[1],
14414 +                                       kgdbsci_rx_interrupt, SA_INTERRUPT,
14415 +                                       "kgdbsci", &KGDBPORT.port);
14416 +       }
14417  }
14418 +#endif
14419  
14420 -/* Breakpoint if there's a break sent on the serial port */
14421 -static void kgdb_break_interrupt(int irq, void *ptr, struct pt_regs *regs)
14422 +/*
14423 + * We use the normal init routine to setup the port, so we can't be
14424 + * in here too early.
14425 + */
14426 +static int kgdbsci_init(void)
14427  {
14428 -        struct sci_port *port = ptr;
14429 -        unsigned short status = sci_in(port, SCxSR);
14430 +       struct termios termios;
14431  
14432 -        if (status & SCxSR_BRK(port)) {
14433 +       memset(&termios, 0, sizeof(struct termios));
14434  
14435 -                /* Break into the debugger if a break is detected */
14436 -                BREAKPOINT();
14437 +       termios.c_cflag = CREAD | HUPCL | CLOCAL | CS8;
14438 +       switch (kgdbsci_baud) {
14439 +       case 9600:
14440 +               termios.c_cflag |= B9600;
14441 +               break;
14442 +       case 19200:
14443 +               termios.c_cflag |= B19200;
14444 +               break;
14445 +       case 38400:
14446 +               termios.c_cflag |= B38400;
14447 +               break;
14448 +       case 57600:
14449 +               termios.c_cflag |= B57600;
14450 +               break;
14451 +       case 115200:
14452 +               termios.c_cflag |= B115200;
14453 +               break;
14454 +       }
14455 +       sci_set_termios(&KGDBPORT.port, &termios, NULL);
14456  
14457 -                /* Clear */
14458 -                sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port));
14459 -        }
14460 +       return 0;
14461  }
14462  
14463 -#endif /* CONFIG_SH_KGDB */
14464 +struct kgdb_io kgdb_io_ops = {
14465 +       .read_char = kgdbsci_read_char,
14466 +       .write_char = kgdbsci_write_char,
14467 +       .init = kgdbsci_init,
14468 +#ifndef CONFIG_SERIAL_SH_SCI_CONSOLE
14469 +       .late_init = kgdbsci_lateinit,
14470 +#else /* ! CONFIG_SERIAL_SH_SCI_CONSOLE */
14471 +       .late_init = NULL,
14472 +#endif /* ! CONFIG_SERIAL_SH_SCI_CONSOLE */
14473 +       .pre_exception = NULL,
14474 +       .post_exception = NULL
14475 +};
14476 +
14477 +/*
14478 + * Syntax for this cmdline option is "kgdbsci=ttyno,baudrate".
14479 + */
14480 +static int __init
14481 +kgdbsci_opt(char *str)
14482 +{
14483 +       /* We might have anywhere from 1 to 3 ports. */
14484 +       if (*str < '0' || *str > SCI_NPORTS + '0')
14485 +                goto errout;
14486 +       kgdbsci_ttySC = *str - '0';
14487 +       str++;
14488 +       if (*str != ',')
14489 +                goto errout;
14490 +       str++;
14491 +       kgdbsci_baud = simple_strtoul(str, &str, 10);
14492 +       if (kgdbsci_baud != 9600 && kgdbsci_baud != 19200 &&
14493 +           kgdbsci_baud != 38400 && kgdbsci_baud != 57600 &&
14494 +           kgdbsci_baud != 115200)
14495 +                goto errout;
14496 +
14497 +       return 0;
14498 +
14499 +errout:
14500 +       printk(KERN_ERR "Invalid syntax for option kgdbsci=\n");
14501 +       return 1;
14502 +}
14503 +__setup("kgdbsci", kgdbsci_opt);
14504 +#endif /* CONFIG_KGDB_SH_SCI */
14505  
14506  #if defined(__H8300S__)
14507  enum { sci_disable, sci_enable };
14508 @@ -555,6 +608,16 @@ static inline void sci_receive_chars(str
14509                                         continue;
14510                                 }
14511  
14512 +#ifdef CONFIG_KGDB_SH_SCI
14513 +                               /* We assume that a ^C on the port KGDB
14514 +                                * is using means that KGDB wants to
14515 +                                * interrupt the running system.
14516 +                                */
14517 +                               if (port->line == KGDBPORT.port.line &&
14518 +                                               c == 3)
14519 +                                       breakpoint();
14520 +#endif
14521 +
14522                                 /* Store data and status */
14523                                 if (status&SCxSR_FER(port)) {
14524                                         flag = TTY_FRAME;
14525 @@ -1618,6 +1681,7 @@ static int __init sci_console_init(void)
14526  console_initcall(sci_console_init);
14527  #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
14528  
14529 +#if 0
14530  #ifdef CONFIG_SH_KGDB
14531  /*
14532   * FIXME: Most of this can go away.. at the moment, we rely on
14533 @@ -1663,30 +1727,9 @@ int __init kgdb_console_setup(struct con
14534         return uart_set_options(port, co, baud, parity, bits, flow);
14535  }
14536  #endif /* CONFIG_SH_KGDB */
14537 +#endif /* 0 */
14538  
14539 -#ifdef CONFIG_SH_KGDB_CONSOLE
14540 -static struct console kgdb_console = {
14541 -        .name          = "ttySC",
14542 -        .write         = kgdb_console_write,
14543 -        .setup         = kgdb_console_setup,
14544 -        .flags         = CON_PRINTBUFFER | CON_ENABLED,
14545 -        .index         = -1,
14546 -       .data           = &sci_uart_driver,
14547 -};
14548 -
14549 -/* Register the KGDB console so we get messages (d'oh!) */
14550 -static int __init kgdb_console_init(void)
14551 -{
14552 -       register_console(&kgdb_console);
14553 -       return 0;
14554 -}
14555 -
14556 -console_initcall(kgdb_console_init);
14557 -#endif /* CONFIG_SH_KGDB_CONSOLE */
14558 -
14559 -#if defined(CONFIG_SH_KGDB_CONSOLE)
14560 -#define SCI_CONSOLE    &kgdb_console
14561 -#elif defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
14562 +#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
14563  #define SCI_CONSOLE    &serial_console
14564  #else
14565  #define SCI_CONSOLE    0
14566 @@ -1757,4 +1800,3 @@ static void __exit sci_exit(void)
14567  
14568  module_init(sci_init);
14569  module_exit(sci_exit);
14570 -
14571 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-arm/kgdb.h linux-2.6.18.kgdb/include/asm-arm/kgdb.h
14572 --- linux-2.6.18/include/asm-arm/kgdb.h 1970-01-01 03:00:00.000000000 +0300
14573 +++ linux-2.6.18.kgdb/include/asm-arm/kgdb.h    2008-06-10 16:19:58.000000000 +0400
14574 @@ -0,0 +1,92 @@
14575 +/*
14576 + * include/asm-arm/kgdb.h
14577 + *
14578 + * ARM KGDB support
14579 + *
14580 + * Author: Deepak Saxena <dsaxena@mvista.com>
14581 + *
14582 + * Copyright (C) 2002 MontaVista Software Inc.
14583 + *
14584 + */
14585 +
14586 +#ifndef __ASM_KGDB_H__
14587 +#define __ASM_KGDB_H__
14588 +
14589 +#include <linux/config.h>
14590 +#include <asm/ptrace.h>
14591 +#include <asm-generic/kgdb.h>
14592 +
14593 +
14594 +/*
14595 + * GDB assumes that we're a user process being debugged, so
14596 + * it will send us an SWI command to write into memory as the
14597 + * debug trap. When an SWI occurs, the next instruction addr is
14598 + * placed into R14_svc before jumping to the vector trap.
14599 + * This doesn't work for kernel debugging as we are already in SVC
14600 + * we would loose the kernel's LR, which is a bad thing. This
14601 + * is  bad thing.
14602 + *
14603 + * By doing this as an undefined instruction trap, we force a mode
14604 + * switch from SVC to UND mode, allowing us to save full kernel state.
14605 + *
14606 + * We also define a KGDB_COMPILED_BREAK which can be used to compile
14607 + * in breakpoints. This is important for things like sysrq-G and for
14608 + * the initial breakpoint from trap_init().
14609 + *
14610 + * Note to ARM HW designers: Add real trap support like SH && PPC to
14611 + * make our lives much much simpler. :)
14612 + */
14613 +#define        BREAK_INSTR_SIZE                4
14614 +#define GDB_BREAKINST                   0xef9f0001
14615 +#define KGDB_BREAKINST                  0xe7ffdefe
14616 +#define KGDB_COMPILED_BREAK             0xe7ffdeff
14617 +#define CACHE_FLUSH_IS_SAFE            1
14618 +
14619 +#ifndef        __ASSEMBLY__
14620 +
14621 +#define        BREAKPOINT()                    asm(".word      0xe7ffdeff")
14622 +
14623 +
14624 +extern void kgdb_handle_bus_error(void);
14625 +extern int kgdb_fault_expected;
14626 +#endif /* !__ASSEMBLY__ */
14627 +
14628 +/*
14629 + * From Amit S. Kale:
14630 + *
14631 + * In the register packet, words 0-15 are R0 to R10, FP, IP, SP, LR, PC. But
14632 + * Register 16 isn't cpsr. GDB passes CPSR in word 25. There are 9 words in
14633 + * between which are unused. Passing only 26 words to gdb is sufficient.
14634 + * GDB can figure out that floating point registers are not passed.
14635 + * GDB_MAX_REGS should be 26.
14636 + */
14637 +#define        GDB_MAX_REGS            (26)
14638 +
14639 +#define        KGDB_MAX_NO_CPUS        1
14640 +#define        BUFMAX                  400
14641 +#define        NUMREGBYTES             (GDB_MAX_REGS << 2)
14642 +#define        NUMCRITREGBYTES         (32 << 2)
14643 +
14644 +#define        _R0             0
14645 +#define        _R1             1
14646 +#define        _R2             2
14647 +#define        _R3             3
14648 +#define        _R4             4
14649 +#define        _R5             5
14650 +#define        _R6             6
14651 +#define        _R7             7
14652 +#define        _R8             8
14653 +#define        _R9             9
14654 +#define        _R10            10
14655 +#define        _FP             11
14656 +#define        _IP             12
14657 +#define        _SP             13
14658 +#define        _LR             14
14659 +#define        _PC             15
14660 +#define        _CPSR           (GDB_MAX_REGS - 1)
14661 +
14662 +/* So that we can denote the end of a frame for tracing, in the simple
14663 + * case. */
14664 +#define CFI_END_FRAME(func)    __CFI_END_FRAME(_PC,_SP,func)
14665 +
14666 +#endif /* __ASM_KGDB_H__ */
14667 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-arm/system.h linux-2.6.18.kgdb/include/asm-arm/system.h
14668 --- linux-2.6.18/include/asm-arm/system.h       2006-09-20 07:42:06.000000000 +0400
14669 +++ linux-2.6.18.kgdb/include/asm-arm/system.h  2008-06-10 16:19:51.000000000 +0400
14670 @@ -444,6 +444,47 @@ static inline unsigned long __xchg(unsig
14671  extern void disable_hlt(void);
14672  extern void enable_hlt(void);
14673  
14674 +#define        __HAVE_ARCH_CMPXCHG     1
14675 +
14676 +#include <asm/types.h>
14677 +
14678 +static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
14679 +                                       unsigned long new)
14680 +{
14681 +       u32 retval;
14682 +       unsigned long flags;
14683 +
14684 +       local_irq_save(flags);
14685 +       retval = *m;
14686 +       if (retval == old)
14687 +               *m = new;
14688 +       local_irq_restore(flags);       /* implies memory barrier  */
14689 +
14690 +       return retval;
14691 +}
14692 +
14693 +/* This function doesn't exist, so you'll get a linker error
14694 +   if something tries to do an invalid cmpxchg().  */
14695 +extern void __cmpxchg_called_with_bad_pointer(void);
14696 +
14697 +static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
14698 +       unsigned long new, int size)
14699 +{
14700 +       switch (size) {
14701 +       case 4:
14702 +               return __cmpxchg_u32(ptr, old, new);
14703 +       }
14704 +       __cmpxchg_called_with_bad_pointer();
14705 +       return old;
14706 +}
14707 +
14708 +#define cmpxchg(ptr,o,n)                                                \
14709 +  ({                                                                    \
14710 +     __typeof__(*(ptr)) _o_ = (o);                                      \
14711 +     __typeof__(*(ptr)) _n_ = (n);                                      \
14712 +     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,          \
14713 +                                   (unsigned long)_n_, sizeof(*(ptr))); \
14714 +  })
14715  #endif /* __ASSEMBLY__ */
14716  
14717  #define arch_align_stack(x) (x)
14718 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-generic/kgdb.h linux-2.6.18.kgdb/include/asm-generic/kgdb.h
14719 --- linux-2.6.18/include/asm-generic/kgdb.h     1970-01-01 03:00:00.000000000 +0300
14720 +++ linux-2.6.18.kgdb/include/asm-generic/kgdb.h        2008-06-10 16:19:58.000000000 +0400
14721 @@ -0,0 +1,34 @@
14722 +/*
14723 + * include/asm-generic/kgdb.h
14724 + *
14725 + * This provides the assembly level information so that KGDB can provide
14726 + * a GDB that has been patched with enough information to know to stop
14727 + * trying to unwind the function.
14728 + *
14729 + * Author: Tom Rini <trini@kernel.crashing.org>
14730 + *
14731 + * 2005 (c) MontaVista Software, Inc. This file is licensed under the terms
14732 + * of the GNU General Public License version 2. This program is licensed
14733 + * "as is" without any warranty of any kind, whether express or implied.
14734 + */
14735 +
14736 +#ifndef __ASM_GENERIC_KGDB_H__
14737 +#define __ASM_GENERIC_KGDB_H__
14738 +
14739 +#include <linux/dwarf2-lang.h>
14740 +#ifdef __ASSEMBLY__
14741 +#ifdef CONFIG_KGDB
14742 +/* This MUST be put at the end of a given assembly function */
14743 +#define __CFI_END_FRAME(pc,sp,func)                    \
14744 +CAT3(.Lend_,func,:)                                    \
14745 +       CFI_preamble(func,pc,0x1,-DATA_ALIGN_FACTOR)    \
14746 +       CFA_define_reference(sp, 0)                     \
14747 +       CFA_undefine_reg(pc)                            \
14748 +       CFI_postamble()                                 \
14749 +       FDE_preamble(func,func,CAT3(.Lend,_,func))      \
14750 +       FDE_postamble()
14751 +#else
14752 +#define __CFI_END_FRAME(pc,sp,fn)
14753 +#endif                         /* CONFIG_KGDB */
14754 +#endif                         /* __ASSEMBLY__ */
14755 +#endif                         /* __ASM_GENERIC_KGDB_H__ */
14756 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-i386/kdebug.h linux-2.6.18.kgdb/include/asm-i386/kdebug.h
14757 --- linux-2.6.18/include/asm-i386/kdebug.h      2006-09-20 07:42:06.000000000 +0400
14758 +++ linux-2.6.18.kgdb/include/asm-i386/kdebug.h 2008-06-10 16:19:17.000000000 +0400
14759 @@ -39,6 +39,7 @@ enum die_val {
14760         DIE_CALL,
14761         DIE_NMI_IPI,
14762         DIE_PAGE_FAULT,
14763 +       DIE_PAGE_FAULT_NO_CONTEXT,
14764  };
14765  
14766  static inline int notify_die(enum die_val val, const char *str,
14767 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-i386/kgdb.h linux-2.6.18.kgdb/include/asm-i386/kgdb.h
14768 --- linux-2.6.18/include/asm-i386/kgdb.h        1970-01-01 03:00:00.000000000 +0300
14769 +++ linux-2.6.18.kgdb/include/asm-i386/kgdb.h   2008-06-10 16:19:58.000000000 +0400
14770 @@ -0,0 +1,58 @@
14771 +#ifdef __KERNEL__
14772 +#ifndef _ASM_KGDB_H_
14773 +#define _ASM_KGDB_H_
14774 +
14775 +/*
14776 + * Copyright (C) 2001-2004 Amit S. Kale
14777 + */
14778 +
14779 +#include <asm-generic/kgdb.h>
14780 +
14781 +/*
14782 + *  Note that this register image is in a different order than
14783 + *  the register image that Linux produces at interrupt time.
14784 + *
14785 + *  Linux's register image is defined by struct pt_regs in ptrace.h.
14786 + *  Just why GDB uses a different order is a historical mystery.
14787 + */
14788 +#define _EAX   0
14789 +#define _ECX   1
14790 +#define _EDX   2
14791 +#define _EBX   3
14792 +#define _ESP   4
14793 +#define _EBP   5
14794 +#define _ESI   6
14795 +#define _EDI   7
14796 +#define _PC    8
14797 +#define _EIP   8
14798 +#define _PS    9
14799 +#define _EFLAGS        9
14800 +#define _CS    10
14801 +#define _SS    11
14802 +#define _DS    12
14803 +#define _ES    13
14804 +#define _FS    14
14805 +#define _GS    15
14806 +
14807 +/* So that we can denote the end of a frame for tracing, in the simple
14808 + * case. */
14809 +#define CFI_END_FRAME(func)    __CFI_END_FRAME(_EIP,_ESP,func)
14810 +
14811 +#ifndef __ASSEMBLY__
14812 +/************************************************************************/
14813 +/* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/
14814 +/* at least NUMREGBYTES*2 are needed for register packets */
14815 +/* Longer buffer is needed to list all threads */
14816 +#define BUFMAX                 1024
14817 +
14818 +/* Number of bytes of registers.  */
14819 +#define NUMREGBYTES            64
14820 +/* Number of bytes of registers we need to save for a setjmp/longjmp. */
14821 +#define NUMCRITREGBYTES                24
14822 +
14823 +#define BREAKPOINT()           asm("   int $3");
14824 +#define BREAK_INSTR_SIZE       1
14825 +#define CACHE_FLUSH_IS_SAFE    1
14826 +#endif                         /* !__ASSEMBLY__ */
14827 +#endif                         /* _ASM_KGDB_H_ */
14828 +#endif                         /* __KERNEL__ */
14829 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-ia64/kdebug.h linux-2.6.18.kgdb/include/asm-ia64/kdebug.h
14830 --- linux-2.6.18/include/asm-ia64/kdebug.h      2006-09-20 07:42:06.000000000 +0400
14831 +++ linux-2.6.18.kgdb/include/asm-ia64/kdebug.h 2008-06-10 16:19:32.000000000 +0400
14832 @@ -72,6 +72,7 @@ enum die_val {
14833         DIE_KDEBUG_LEAVE,
14834         DIE_KDUMP_ENTER,
14835         DIE_KDUMP_LEAVE,
14836 +       DIE_PAGE_FAULT_NO_CONTEXT,
14837  };
14838  
14839  static inline int notify_die(enum die_val val, char *str, struct pt_regs *regs,
14840 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-ia64/kgdb.h linux-2.6.18.kgdb/include/asm-ia64/kgdb.h
14841 --- linux-2.6.18/include/asm-ia64/kgdb.h        1970-01-01 03:00:00.000000000 +0300
14842 +++ linux-2.6.18.kgdb/include/asm-ia64/kgdb.h   2008-06-10 16:19:32.000000000 +0400
14843 @@ -0,0 +1,36 @@
14844 +#ifdef __KERNEL__
14845 +#ifndef _ASM_KGDB_H_
14846 +#define _ASM_KGDB_H_
14847 +
14848 +/*
14849 + * Copyright (C) 2001-2004 Amit S. Kale
14850 + */
14851 +
14852 +#include <linux/threads.h>
14853 +
14854 +/************************************************************************/
14855 +/* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/
14856 +/* at least NUMREGBYTES*2 are needed for register packets */
14857 +/* Longer buffer is needed to list all threads */
14858 +#define BUFMAX                 1024
14859 +
14860 +/* Number of bytes of registers.  We set this to 0 so that certain GDB
14861 + * packets will fail, forcing the use of others, which are more friendly
14862 + * on ia64. */
14863 +#define NUMREGBYTES            0
14864 +
14865 +#define NUMCRITREGBYTES                (70*8)
14866 +#define JMP_REGS_ALIGNMENT     __attribute__ ((aligned (16)))
14867 +
14868 +#define BREAKNUM               0x00003333300LL
14869 +#define KGDBBREAKNUM           0x6665UL
14870 +#define BREAKPOINT()           asm volatile ("break.m 0x6665")
14871 +#define BREAK_INSTR_SIZE       16
14872 +#define CACHE_FLUSH_IS_SAFE    1
14873 +
14874 +struct pt_regs;
14875 +extern volatile int kgdb_hwbreak_sstep[NR_CPUS];
14876 +extern void smp_send_nmi_allbutself(void);
14877 +extern void kgdb_wait_ipi(struct pt_regs *);
14878 +#endif                         /* _ASM_KGDB_H_ */
14879 +#endif                         /* __KERNEL__ */
14880 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-mips/kdebug.h linux-2.6.18.kgdb/include/asm-mips/kdebug.h
14881 --- linux-2.6.18/include/asm-mips/kdebug.h      1970-01-01 03:00:00.000000000 +0300
14882 +++ linux-2.6.18.kgdb/include/asm-mips/kdebug.h 2008-06-10 16:19:28.000000000 +0400
14883 @@ -0,0 +1,47 @@
14884 +/*
14885 + *
14886 + * Copyright (C) 2004  MontaVista Software Inc.
14887 + * Author: Manish Lachwani, mlachwani@mvista.com or manish@koffee-break.com
14888 + *
14889 + * This program is free software; you can redistribute  it and/or modify it
14890 + * under  the terms of  the GNU General  Public License as published by the
14891 + * Free Software Foundation;  either version 2 of the  License, or (at your
14892 + * option) any later version.
14893 + *
14894 + */
14895 +#ifndef _MIPS_KDEBUG_H
14896 +#define _MIPS_KDEBUG_H
14897 +
14898 +#include <linux/notifier.h>
14899 +
14900 +struct pt_regs;
14901 +
14902 +struct die_args {
14903 +       struct pt_regs *regs;
14904 +       const char *str;
14905 +       long err;
14906 +};
14907 +
14908 +int register_die_notifier(struct notifier_block *nb);
14909 +extern struct notifier_block *mips_die_chain;
14910 +
14911 +enum die_val {
14912 +       DIE_OOPS = 1,
14913 +       DIE_PANIC,
14914 +       DIE_DIE,
14915 +       DIE_KERNELDEBUG,
14916 +       DIE_TRAP,
14917 +       DIE_PAGE_FAULT,
14918 +};
14919 +
14920 +/*
14921 + * trap number can be computed from regs and signr can be computed using
14922 + * compute_signal()
14923 + */
14924 +static inline int notify_die(enum die_val val,char *str,struct pt_regs *regs,long err)
14925 +{
14926 +       struct die_args args = { .regs=regs, .str=str, .err=err };
14927 +       return notifier_call_chain(&mips_die_chain, val, &args);
14928 +}
14929 +
14930 +#endif /* _MIPS_KDEBUG_H */
14931 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-mips/kgdb.h linux-2.6.18.kgdb/include/asm-mips/kgdb.h
14932 --- linux-2.6.18/include/asm-mips/kgdb.h        1970-01-01 03:00:00.000000000 +0300
14933 +++ linux-2.6.18.kgdb/include/asm-mips/kgdb.h   2008-06-10 16:19:58.000000000 +0400
14934 @@ -0,0 +1,34 @@
14935 +#ifdef __KERNEL__
14936 +#ifndef _ASM_KGDB_H_
14937 +#define _ASM_KGDB_H_
14938 +
14939 +#ifndef __ASSEMBLY__
14940 +#if (_MIPS_ISA == _MIPS_ISA_MIPS1) || (_MIPS_ISA == _MIPS_ISA_MIPS2)
14941 +typedef u32 gdb_reg_t;
14942 +#elif (_MIPS_ISA == _MIPS_ISA_MIPS3) || (_MIPS_ISA == _MIPS_ISA_MIPS4)
14943 +typedef u64 gdb_reg_t;
14944 +#else
14945 +#error need to do
14946 +#endif /* _MIPS_ISA */
14947 +
14948 +#include <asm-generic/kgdb.h>
14949 +
14950 +#ifndef __ASSEMBLY__
14951 +#define BUFMAX                 2048
14952 +#define NUMREGBYTES            (90*sizeof(gdb_reg_t))
14953 +#define NUMCRITREGBYTES                (12*sizeof(gdb_reg_t))
14954 +#define BREAK_INSTR_SIZE       4
14955 +#define BREAKPOINT()           __asm__ __volatile__(           \
14956 +                                       ".globl breakinst\n\t"  \
14957 +                                       ".set\tnoreorder\n\t"   \
14958 +                                       "nop\n"                 \
14959 +                                       "breakinst:\tbreak\n\t" \
14960 +                                       "nop\n\t"               \
14961 +                                       ".set\treorder")
14962 +#define CACHE_FLUSH_IS_SAFE    0
14963 +
14964 +extern int kgdb_early_setup;
14965 +
14966 +#endif                         /* !__ASSEMBLY__ */
14967 +#endif                         /* _ASM_KGDB_H_ */
14968 +#endif                         /* __KERNEL__ */
14969 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-powerpc/kgdb.h linux-2.6.18.kgdb/include/asm-powerpc/kgdb.h
14970 --- linux-2.6.18/include/asm-powerpc/kgdb.h     1970-01-01 03:00:00.000000000 +0300
14971 +++ linux-2.6.18.kgdb/include/asm-powerpc/kgdb.h        2008-06-10 16:19:58.000000000 +0400
14972 @@ -0,0 +1,74 @@
14973 +/*
14974 + * include/asm-powerpc/kgdb.h
14975 + *
14976 + * The PowerPC (32/64) specific defines / externs for KGDB.  Based on
14977 + * the previous 32bit and 64bit specific files, which had the following
14978 + * copyrights:
14979 + *
14980 + * PPC64 Mods (C) 2005 Frank Rowand (frowand@mvista.com)
14981 + * PPC Mods (C) 2004 Tom Rini (trini@mvista.com)
14982 + * PPC Mods (C) 2003 John Whitney (john.whitney@timesys.com)
14983 + * PPC Mods (C) 1998 Michael Tesch (tesch@cs.wisc.edu)
14984 + *
14985 + *
14986 + * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
14987 + * Author: Tom Rini <trini@kernel.crashing.org>
14988 + *
14989 + * 2006 (c) MontaVista Software, Inc. This file is licensed under
14990 + * the terms of the GNU General Public License version 2. This program
14991 + * is licensed "as is" without any warranty of any kind, whether express
14992 + * or implied.
14993 + */
14994 +#ifdef __KERNEL__
14995 +#ifndef __POWERPC_KGDB_H__
14996 +#define __POWERPC_KGDB_H__
14997 +
14998 +#include <asm-generic/kgdb.h>
14999 +#ifndef __ASSEMBLY__
15000 +
15001 +#define BREAK_INSTR_SIZE       4
15002 +#define BUFMAX                 ((NUMREGBYTES * 2) + 512)
15003 +#define OUTBUFMAX              ((NUMREGBYTES * 2) + 512)
15004 +#define BREAKPOINT()           asm(".long 0x7d821008"); /* twge r2, r2 */
15005 +#define CACHE_FLUSH_IS_SAFE    1
15006 +
15007 +/* The number bytes of registers we have to save depends on a few
15008 + * things.  For 64bit we default to not including vector registers and
15009 + * vector state registers. */
15010 +#ifdef CONFIG_PPC64
15011 +/*
15012 + * 64 bit (8 byte) registers:
15013 + *   32 gpr, 32 fpr, nip, msr, link, ctr
15014 + * 32 bit (4 byte) registers:
15015 + *   ccr, xer, fpscr
15016 + */
15017 +#define NUMREGBYTES            ((68 * 8) + (3 * 4))
15018 +#if 0
15019 +/* The following adds in vector registers and vector state registers. */
15020 +/* 128 bit (16 byte) registers:
15021 + *   32 vr
15022 + * 64 bit (8 byte) registers:
15023 + *   32 gpr, 32 fpr, nip, msr, link, ctr
15024 + * 32 bit (4 byte) registers:
15025 + *   ccr, xer, fpscr, vscr, vrsave
15026 + */
15027 +#define NUMREGBYTES            ((128 * 16) + (68 * 8) + (5 * 4))
15028 +#endif
15029 +#define NUMCRITREGBYTES                184
15030 +#else /* CONFIG_PPC32 */
15031 +/* On non-E500 family PPC32 we determine the size by picking the last
15032 + * register we need, but on E500 we skip sections so we list what we
15033 + * need to store, and add it up. */
15034 +#ifndef CONFIG_E500
15035 +#define MAXREG                 (PT_FPSCR+1)
15036 +#else
15037 +/* 32 GPRs (8 bytes), nip, msr, ccr, link, ctr, xer, acc (8 bytes), spefscr*/
15038 +#define MAXREG                 ((32*2)+6+2+1)
15039 +#endif
15040 +#define NUMREGBYTES            (MAXREG * sizeof(int))
15041 +/* CR/LR, R1, R2, R13-R31 inclusive. */
15042 +#define NUMCRITREGBYTES                (23 * sizeof(int))
15043 +#endif /* 32/64 */
15044 +#endif /* !(__ASSEMBLY__) */
15045 +#endif /* !__POWERPC_KGDB_H__ */
15046 +#endif /* __KERNEL__ */
15047 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-ppc/kgdb.h linux-2.6.18.kgdb/include/asm-ppc/kgdb.h
15048 --- linux-2.6.18/include/asm-ppc/kgdb.h 2006-09-20 07:42:06.000000000 +0400
15049 +++ linux-2.6.18.kgdb/include/asm-ppc/kgdb.h    2008-06-10 16:19:22.000000000 +0400
15050 @@ -1,57 +1,18 @@
15051 -/*
15052 - * kgdb.h: Defines and declarations for serial line source level
15053 - *         remote debugging of the Linux kernel using gdb.
15054 - *
15055 - * PPC Mods (C) 1998 Michael Tesch (tesch@cs.wisc.edu)
15056 - *
15057 - * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
15058 - */
15059  #ifdef __KERNEL__
15060 -#ifndef _PPC_KGDB_H
15061 -#define _PPC_KGDB_H
15062 -
15063 +#ifndef __PPC_KGDB_H__
15064 +#define __PPC_KGDB_H__
15065 +#include <asm-powerpc/kgdb.h>
15066  #ifndef __ASSEMBLY__
15067 -
15068 -/* Things specific to the gen550 backend. */
15069 -struct uart_port;
15070 -
15071 -extern void gen550_progress(char *, unsigned short);
15072 -extern void gen550_kgdb_map_scc(void);
15073 -extern void gen550_init(int, struct uart_port *);
15074 -
15075 -/* Things specific to the pmac backend. */
15076 -extern void zs_kgdb_hook(int tty_num);
15077 -
15078 -/* To init the kgdb engine. (called by serial hook)*/
15079 -extern void set_debug_traps(void);
15080 -
15081 -/* To enter the debugger explicitly. */
15082 -extern void breakpoint(void);
15083 -
15084 -/* For taking exceptions
15085 - * these are defined in traps.c
15086 - */
15087 -extern int (*debugger)(struct pt_regs *regs);
15088 + /* For taking exceptions
15089 +  * these are defined in traps.c
15090 +  */
15091 +struct pt_regs;
15092 +extern void (*debugger)(struct pt_regs *regs);
15093  extern int (*debugger_bpt)(struct pt_regs *regs);
15094  extern int (*debugger_sstep)(struct pt_regs *regs);
15095  extern int (*debugger_iabr_match)(struct pt_regs *regs);
15096  extern int (*debugger_dabr_match)(struct pt_regs *regs);
15097  extern void (*debugger_fault_handler)(struct pt_regs *regs);
15098 -
15099 -/* What we bring to the party */
15100 -int kgdb_bpt(struct pt_regs *regs);
15101 -int kgdb_sstep(struct pt_regs *regs);
15102 -void kgdb(struct pt_regs *regs);
15103 -int kgdb_iabr_match(struct pt_regs *regs);
15104 -int kgdb_dabr_match(struct pt_regs *regs);
15105 -
15106 -/*
15107 - * external low-level support routines (ie macserial.c)
15108 - */
15109 -extern void kgdb_interruptible(int); /* control interrupts from serial */
15110 -extern void putDebugChar(char);   /* write a single character      */
15111 -extern char getDebugChar(void);   /* read and return a single char */
15112 -
15113 -#endif /* !(__ASSEMBLY__) */
15114 -#endif /* !(_PPC_KGDB_H) */
15115 +#endif /* !__ASSEMBLY__ */
15116 +#endif /* __PPC_KGDB_H__ */
15117  #endif /* __KERNEL__ */
15118 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-ppc/machdep.h linux-2.6.18.kgdb/include/asm-ppc/machdep.h
15119 --- linux-2.6.18/include/asm-ppc/machdep.h      2006-09-20 07:42:06.000000000 +0400
15120 +++ linux-2.6.18.kgdb/include/asm-ppc/machdep.h 2008-06-10 16:19:22.000000000 +0400
15121 @@ -72,9 +72,7 @@ struct machdep_calls {
15122         unsigned long   (*find_end_of_memory)(void);
15123         void            (*setup_io_mappings)(void);
15124  
15125 -       void            (*early_serial_map)(void);
15126         void            (*progress)(char *, unsigned short);
15127 -       void            (*kgdb_map_scc)(void);
15128  
15129         unsigned char   (*nvram_read_val)(int addr);
15130         void            (*nvram_write_val)(int addr, unsigned char val);
15131 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-ppc/mv64x60.h linux-2.6.18.kgdb/include/asm-ppc/mv64x60.h
15132 --- linux-2.6.18/include/asm-ppc/mv64x60.h      2006-09-20 07:42:06.000000000 +0400
15133 +++ linux-2.6.18.kgdb/include/asm-ppc/mv64x60.h 2008-06-10 16:19:22.000000000 +0400
15134 @@ -348,6 +348,8 @@ u32 mv64x60_calc_mem_size(struct mv64x60
15135  
15136  void mv64x60_progress_init(u32 base);
15137  void mv64x60_mpsc_progress(char *s, unsigned short hex);
15138 +struct platform_device * mv64x60_early_get_pdev_data(const char *name,
15139 +               int id, int remove);
15140  
15141  extern struct mv64x60_32bit_window
15142         gt64260_32bit_windows[MV64x60_32BIT_WIN_COUNT];
15143 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-ppc/mv64x60_defs.h linux-2.6.18.kgdb/include/asm-ppc/mv64x60_defs.h
15144 --- linux-2.6.18/include/asm-ppc/mv64x60_defs.h 2006-09-20 07:42:06.000000000 +0400
15145 +++ linux-2.6.18.kgdb/include/asm-ppc/mv64x60_defs.h    2008-06-10 16:19:22.000000000 +0400
15146 @@ -57,7 +57,8 @@
15147  #define        MV64x60_IRQ_I2C                         37
15148  #define        MV64x60_IRQ_BRG                         39
15149  #define        MV64x60_IRQ_MPSC_0                      40
15150 -#define        MV64x60_IRQ_MPSC_1                      42
15151 +#define        MV64360_IRQ_MPSC_1                      41
15152 +#define        GT64260_IRQ_MPSC_1                      42
15153  #define        MV64x60_IRQ_COMM                        43
15154  #define        MV64x60_IRQ_P0_GPP_0_7                  56
15155  #define        MV64x60_IRQ_P0_GPP_8_15                 57
15156 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-sh/kgdb.h linux-2.6.18.kgdb/include/asm-sh/kgdb.h
15157 --- linux-2.6.18/include/asm-sh/kgdb.h  2006-09-20 07:42:06.000000000 +0400
15158 +++ linux-2.6.18.kgdb/include/asm-sh/kgdb.h     2008-06-10 16:19:58.000000000 +0400
15159 @@ -2,94 +2,40 @@
15160   * May be copied or modified under the terms of the GNU General Public
15161   * License.  See linux/COPYING for more information.
15162   *
15163 - * Based on original code by Glenn Engel, Jim Kingdon,
15164 - * David Grothe <dave@gcom.com>, Tigran Aivazian, <tigran@sco.com> and
15165 - * Amit S. Kale <akale@veritas.com>
15166 - * 
15167 - * Super-H port based on sh-stub.c (Ben Lee and Steve Chamberlain) by
15168 - * Henry Bell <henry.bell@st.com>
15169 - * 
15170 - * Header file for low-level support for remote debug using GDB. 
15171 + * Based on a file that was modified or based on files by: Glenn Engel,
15172 + * Jim Kingdon, David Grothe <dave@gcom.com>, Tigran Aivazian <tigran@sco.com>,
15173 + * Amit S. Kale <akale@veritas.com>, sh-stub.c from Ben Lee and
15174 + * Steve Chamberlain, Henry Bell <henry.bell@st.com>
15175 + *
15176 + * Maintainer: Tom Rini <trini@kernel.crashing.org>
15177   *
15178   */
15179  
15180  #ifndef __KGDB_H
15181  #define __KGDB_H
15182  
15183 -#include <asm/ptrace.h>
15184 -
15185 -struct console;
15186 +#include <asm-generic/kgdb.h>
15187 +/* Based on sh-gdb.c from gdb-6.1, Glenn
15188 +     Engel at HP  Ben Lee and Steve Chamberlain */
15189 +#define NUMREGBYTES    112     /* 92 */
15190 +#define NUMCRITREGBYTES        (9 << 2)
15191 +#define BUFMAX         400
15192  
15193 -/* Same as pt_regs but has vbr in place of syscall_nr */
15194 +#ifndef __ASSEMBLY__
15195  struct kgdb_regs {
15196          unsigned long regs[16];
15197          unsigned long pc;
15198          unsigned long pr;
15199 -        unsigned long sr;
15200          unsigned long gbr;
15201 +        unsigned long vbr;
15202          unsigned long mach;
15203          unsigned long macl;
15204 -        unsigned long vbr;
15205 -};
15206 -
15207 -/* State info */
15208 -extern char kgdb_in_gdb_mode;
15209 -extern int kgdb_done_init;
15210 -extern int kgdb_enabled;
15211 -extern int kgdb_nofault;       /* Ignore bus errors (in gdb mem access) */
15212 -extern int kgdb_halt;          /* Execute initial breakpoint at startup */
15213 -extern char in_nmi;            /* Debounce flag to prevent NMI reentry*/
15214 -
15215 -/* SCI */
15216 -extern int kgdb_portnum;
15217 -extern int kgdb_baud;
15218 -extern char kgdb_parity;
15219 -extern char kgdb_bits;
15220 -extern int kgdb_console_setup(struct console *, char *);
15221 -
15222 -/* Init and interface stuff */
15223 -extern int kgdb_init(void);
15224 -extern int (*kgdb_serial_setup)(void);
15225 -extern int (*kgdb_getchar)(void);
15226 -extern void (*kgdb_putchar)(int);
15227 -
15228 -struct kgdb_sermap {
15229 -       char *name;
15230 -       int namelen;
15231 -       int (*setup_fn)(struct console *, char *);
15232 -       struct kgdb_sermap *next;
15233 +        unsigned long sr;
15234  };
15235 -extern void kgdb_register_sermap(struct kgdb_sermap *map);
15236 -extern struct kgdb_sermap *kgdb_porttype;
15237  
15238 -/* Trap functions */
15239 -typedef void (kgdb_debug_hook_t)(struct pt_regs *regs); 
15240 -typedef void (kgdb_bus_error_hook_t)(void);
15241 -extern kgdb_debug_hook_t  *kgdb_debug_hook;
15242 -extern kgdb_bus_error_hook_t *kgdb_bus_err_hook;
15243 -
15244 -extern void breakpoint(void);
15245 -
15246 -/* Console */
15247 -struct console;
15248 -void kgdb_console_write(struct console *co, const char *s, unsigned count);
15249 -void kgdb_console_init(void);
15250 -
15251 -/* Prototypes for jmp fns */
15252 -#define _JBLEN 9
15253 -typedef        int jmp_buf[_JBLEN];
15254 -extern void    longjmp(jmp_buf __jmpb, int __retval);
15255 -extern int     setjmp(jmp_buf __jmpb);
15256 -
15257 -/* Variadic macro to print our own message to the console */
15258 -#define KGDB_PRINTK(...) printk("KGDB: " __VA_ARGS__)
15259 -
15260 -/* Forced breakpoint */
15261 -#define BREAKPOINT() do {                                     \
15262 -  if (kgdb_enabled) {                                         \
15263 -    asm volatile("trapa   #0xff");                            \
15264 -  }                                                           \
15265 -} while (0)
15266 +#define BREAKPOINT()           asm("trapa #0xff");
15267 +#define BREAK_INSTR_SIZE       2
15268 +#define CACHE_FLUSH_IS_SAFE    1
15269  
15270  /* KGDB should be able to flush all kernel text space */
15271  #if defined(CONFIG_CPU_SH4)
15272 @@ -102,30 +48,5 @@ extern int     setjmp(jmp_buf __jmpb);
15273  #else
15274  #define kgdb_flush_icache_range(start, end)    do { } while (0)
15275  #endif
15276 -
15277 -/* Kernel assert macros */
15278 -#ifdef CONFIG_KGDB_KERNEL_ASSERTS
15279 -
15280 -/* Predefined conditions */
15281 -#define KA_VALID_ERRNO(errno) ((errno) > 0 && (errno) <= EMEDIUMTYPE)
15282 -#define KA_VALID_PTR_ERR(ptr) KA_VALID_ERRNO(-PTR_ERR(ptr))
15283 -#define KA_VALID_KPTR(ptr)  (!(ptr) || \
15284 -              ((void *)(ptr) >= (void *)PAGE_OFFSET &&  \
15285 -               (void *)(ptr) < ERR_PTR(-EMEDIUMTYPE)))
15286 -#define KA_VALID_PTRORERR(errptr) \
15287 -               (KA_VALID_KPTR(errptr) || KA_VALID_PTR_ERR(errptr))
15288 -#define KA_HELD_GKL()  (current->lock_depth >= 0)
15289 -
15290 -/* The actual assert */
15291 -#define KGDB_ASSERT(condition, message) do {                   \
15292 -       if (!(condition) && (kgdb_enabled)) {                   \
15293 -               KGDB_PRINTK("Assertion failed at %s:%d: %s\n",  \
15294 -                                  __FILE__, __LINE__, message);\
15295 -               BREAKPOINT();                                   \
15296 -       }                                                       \
15297 -} while (0)
15298 -#else
15299 -#define KGDB_ASSERT(condition, message)
15300 -#endif
15301 -
15302 +#endif                         /* !__ASSEMBLY__ */
15303  #endif
15304 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-sh/system.h linux-2.6.18.kgdb/include/asm-sh/system.h
15305 --- linux-2.6.18/include/asm-sh/system.h        2006-09-20 07:42:06.000000000 +0400
15306 +++ linux-2.6.18.kgdb/include/asm-sh/system.h   2008-06-10 16:19:47.000000000 +0400
15307 @@ -6,6 +6,7 @@
15308   * Copyright (C) 2002 Paul Mundt
15309   */
15310  
15311 +#include <asm/types.h>
15312  
15313  /*
15314   *     switch_to() should switch tasks to task nr n, first
15315 @@ -260,6 +261,45 @@ static __inline__ unsigned long __xchg(u
15316         return x;
15317  }
15318  
15319 +static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
15320 +       unsigned long new)
15321 +{
15322 +       __u32 retval;
15323 +       unsigned long flags;
15324 +
15325 +       local_irq_save(flags);
15326 +       retval = *m;
15327 +       if (retval == old)
15328 +               *m = new;
15329 +       local_irq_restore(flags);       /* implies memory barrier  */
15330 +       return retval;
15331 +}
15332 +
15333 +/* This function doesn't exist, so you'll get a linker error
15334 + * if something tries to do an invalid cmpxchg(). */
15335 +extern void __cmpxchg_called_with_bad_pointer(void);
15336 +
15337 +#define __HAVE_ARCH_CMPXCHG    1
15338 +
15339 +static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
15340 +               unsigned long new, int size)
15341 +{
15342 +       switch (size) {
15343 +       case 4:
15344 +               return __cmpxchg_u32(ptr, old, new);
15345 +       }
15346 +       __cmpxchg_called_with_bad_pointer();
15347 +       return old;
15348 +}
15349 +
15350 +#define cmpxchg(ptr,o,n)                                                \
15351 +  ({                                                                    \
15352 +     __typeof__(*(ptr)) _o_ = (o);                                      \
15353 +     __typeof__(*(ptr)) _n_ = (n);                                      \
15354 +     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,          \
15355 +                                   (unsigned long)_n_, sizeof(*(ptr))); \
15356 +  })
15357 +
15358  /* XXX
15359   * disable hlt during certain critical i/o operations
15360   */
15361 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-x86_64/kdebug.h linux-2.6.18.kgdb/include/asm-x86_64/kdebug.h
15362 --- linux-2.6.18/include/asm-x86_64/kdebug.h    2006-09-20 07:42:06.000000000 +0400
15363 +++ linux-2.6.18.kgdb/include/asm-x86_64/kdebug.h       2008-06-10 16:19:36.000000000 +0400
15364 @@ -34,6 +34,7 @@ enum die_val {
15365         DIE_CALL,
15366         DIE_NMI_IPI,
15367         DIE_PAGE_FAULT,
15368 +       DIE_PAGE_FAULT_NO_CONTEXT,
15369  };
15370  
15371  static inline int notify_die(enum die_val val, const char *str,
15372 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-x86_64/kgdb.h linux-2.6.18.kgdb/include/asm-x86_64/kgdb.h
15373 --- linux-2.6.18/include/asm-x86_64/kgdb.h      1970-01-01 03:00:00.000000000 +0300
15374 +++ linux-2.6.18.kgdb/include/asm-x86_64/kgdb.h 2008-06-10 16:19:58.000000000 +0400
15375 @@ -0,0 +1,54 @@
15376 +#ifdef __KERNEL__
15377 +#ifndef _ASM_KGDB_H_
15378 +#define _ASM_KGDB_H_
15379 +
15380 +/*
15381 + * Copyright (C) 2001-2004 Amit S. Kale
15382 + */
15383 +
15384 +#include <asm-generic/kgdb.h>
15385 +
15386 +/*
15387 + *  Note that this register image is in a different order than
15388 + *  the register image that Linux produces at interrupt time.
15389 + *
15390 + *  Linux's register image is defined by struct pt_regs in ptrace.h.
15391 + *  Just why GDB uses a different order is a historical mystery.
15392 + */
15393 +#define _RAX   0
15394 +#define _RDX   1
15395 +#define _RCX   2
15396 +#define _RBX   3
15397 +#define _RSI   4
15398 +#define _RDI   5
15399 +#define _RBP   6
15400 +#define _RSP   7
15401 +#define _R8    8
15402 +#define _R9    9
15403 +#define _R10   10
15404 +#define _R11   11
15405 +#define _R12   12
15406 +#define _R13   13
15407 +#define _R14   14
15408 +#define _R15   15
15409 +#define _PC    16
15410 +#define _PS    17
15411 +
15412 +/* Number of bytes of registers.  */
15413 +#define NUMREGBYTES            ((_PS+1)*8)
15414 +#define NUMCRITREGBYTES                (8 * 8)         /* 8 registers. */
15415 +
15416 +/* Help GDB to know when to stop backtracing. */
15417 +#define CFI_END_FRAME(func)    __CFI_END_FRAME(_PC,_RSP,func)
15418 +#ifndef __ASSEMBLY__
15419 +/* BUFMAX defines the maximum number of characters in inbound/outbound
15420 + * buffers at least NUMREGBYTES*2 are needed for register packets, and
15421 + * a longer buffer is needed to list all threads. */
15422 +#define BUFMAX                 1024
15423 +#define BREAKPOINT()           asm("   int $3");
15424 +#define CHECK_EXCEPTION_STACK() ((&__get_cpu_var(init_tss))[0].ist[0])
15425 +#define BREAK_INSTR_SIZE       1
15426 +#define CACHE_FLUSH_IS_SAFE    1
15427 +#endif                         /* !__ASSEMBLY__ */
15428 +#endif                         /* _ASM_KGDB_H_ */
15429 +#endif                         /* __KERNEL__ */
15430 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/asm-x86_64/system.h linux-2.6.18.kgdb/include/asm-x86_64/system.h
15431 --- linux-2.6.18/include/asm-x86_64/system.h    2006-09-20 07:42:06.000000000 +0400
15432 +++ linux-2.6.18.kgdb/include/asm-x86_64/system.h       2008-06-10 16:19:42.000000000 +0400
15433 @@ -21,7 +21,9 @@
15434         ,"rcx","rbx","rdx","r8","r9","r10","r11","r12","r13","r14","r15"
15435  
15436  #define switch_to(prev,next,last) \
15437 -       asm volatile(SAVE_CONTEXT                                                   \
15438 +       asm volatile(".globl __switch_to_begin\n\t"                                 \
15439 +                    "__switch_to_begin:\n\t"                                     \
15440 +                    SAVE_CONTEXT                                                 \
15441                      "movq %%rsp,%P[threadrsp](%[prev])\n\t" /* save RSP */       \
15442                      "movq %P[threadrsp](%[next]),%%rsp\n\t" /* restore RSP */    \
15443                      "call __switch_to\n\t"                                       \
15444 @@ -33,6 +35,8 @@
15445                      "movq %%rax,%%rdi\n\t"                                       \
15446                      "jc   ret_from_fork\n\t"                                     \
15447                      RESTORE_CONTEXT                                                \
15448 +                    ".globl __switch_to_end\n\t"                                 \
15449 +                    "__switch_to_end:\n\t"                                       \
15450                      : "=a" (last)                                                \
15451                      : [next] "S" (next), [prev] "D" (prev),                      \
15452                        [threadrsp] "i" (offsetof(struct task_struct, thread.rsp)), \
15453 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/linux/dwarf2-defs.h linux-2.6.18.kgdb/include/linux/dwarf2-defs.h
15454 --- linux-2.6.18/include/linux/dwarf2-defs.h    1970-01-01 03:00:00.000000000 +0300
15455 +++ linux-2.6.18.kgdb/include/linux/dwarf2-defs.h       2008-06-10 16:22:59.000000000 +0400
15456 @@ -0,0 +1,515 @@
15457 +#ifndef  _ELF_DWARF_H
15458 +/* Machine generated from dwarf2.h by scripts/dwarfh.awk */
15459 +#define _ELF_DWARF2_H
15460 +#define DW_TAG_padding  0x00
15461 +#define DW_TAG_array_type       0x01
15462 +#define DW_TAG_class_type       0x02
15463 +#define DW_TAG_entry_point      0x03
15464 +#define DW_TAG_enumeration_type         0x04
15465 +#define DW_TAG_formal_parameter         0x05
15466 +#define DW_TAG_imported_declaration     0x08
15467 +#define DW_TAG_label    0x0a
15468 +#define DW_TAG_lexical_block    0x0b
15469 +#define DW_TAG_member   0x0d
15470 +#define DW_TAG_pointer_type     0x0f
15471 +#define DW_TAG_reference_type   0x10
15472 +#define DW_TAG_compile_unit     0x11
15473 +#define DW_TAG_string_type      0x12
15474 +#define DW_TAG_structure_type   0x13
15475 +#define DW_TAG_subroutine_type  0x15
15476 +#define DW_TAG_typedef  0x16
15477 +#define DW_TAG_union_type       0x17
15478 +#define DW_TAG_unspecified_parameters   0x18
15479 +#define DW_TAG_variant  0x19
15480 +#define DW_TAG_common_block     0x1a
15481 +#define DW_TAG_common_inclusion         0x1b
15482 +#define DW_TAG_inheritance      0x1c
15483 +#define DW_TAG_inlined_subroutine       0x1d
15484 +#define DW_TAG_module   0x1e
15485 +#define DW_TAG_ptr_to_member_type       0x1f
15486 +#define DW_TAG_set_type         0x20
15487 +#define DW_TAG_subrange_type    0x21
15488 +#define DW_TAG_with_stmt        0x22
15489 +#define DW_TAG_access_declaration       0x23
15490 +#define DW_TAG_base_type        0x24
15491 +#define DW_TAG_catch_block      0x25
15492 +#define DW_TAG_const_type       0x26
15493 +#define DW_TAG_constant         0x27
15494 +#define DW_TAG_enumerator       0x28
15495 +#define DW_TAG_file_type        0x29
15496 +#define DW_TAG_friend   0x2a
15497 +#define DW_TAG_namelist         0x2b
15498 +#define DW_TAG_namelist_item    0x2c
15499 +#define DW_TAG_packed_type      0x2d
15500 +#define DW_TAG_subprogram       0x2e
15501 +#define DW_TAG_template_type_param      0x2f
15502 +#define DW_TAG_template_value_param     0x30
15503 +#define DW_TAG_thrown_type      0x31
15504 +#define DW_TAG_try_block        0x32
15505 +#define DW_TAG_variant_part     0x33
15506 +#define DW_TAG_variable         0x34
15507 +#define DW_TAG_volatile_type    0x35
15508 +#define DW_TAG_dwarf_procedure  0x36
15509 +#define DW_TAG_restrict_type    0x37
15510 +#define DW_TAG_interface_type   0x38
15511 +#define DW_TAG_namespace        0x39
15512 +#define DW_TAG_imported_module  0x3a
15513 +#define DW_TAG_unspecified_type         0x3b
15514 +#define DW_TAG_partial_unit     0x3c
15515 +#define DW_TAG_imported_unit    0x3d
15516 +#define DW_TAG_MIPS_loop        0x4081
15517 +#define DW_TAG_HP_array_descriptor      0x4090
15518 +#define DW_TAG_format_label     0x4101
15519 +#define DW_TAG_function_template        0x4102
15520 +#define DW_TAG_class_template   0x4103
15521 +#define DW_TAG_GNU_BINCL        0x4104
15522 +#define DW_TAG_GNU_EINCL        0x4105
15523 +#define DW_TAG_upc_shared_type  0x8765
15524 +#define DW_TAG_upc_strict_type  0x8766
15525 +#define DW_TAG_upc_relaxed_type         0x8767
15526 +#define DW_TAG_PGI_kanji_type   0xA000
15527 +#define DW_TAG_PGI_interface_block      0xA020
15528 +#define DW_TAG_lo_user 0x4080
15529 +#define DW_TAG_hi_user 0xffff
15530 +#define DW_children_no   0
15531 +#define        DW_children_yes  1
15532 +#define DW_FORM_addr    0x01
15533 +#define DW_FORM_block2  0x03
15534 +#define DW_FORM_block4  0x04
15535 +#define DW_FORM_data2   0x05
15536 +#define DW_FORM_data4   0x06
15537 +#define DW_FORM_data8   0x07
15538 +#define DW_FORM_string  0x08
15539 +#define DW_FORM_block   0x09
15540 +#define DW_FORM_block1  0x0a
15541 +#define DW_FORM_data1   0x0b
15542 +#define DW_FORM_flag    0x0c
15543 +#define DW_FORM_sdata   0x0d
15544 +#define DW_FORM_strp    0x0e
15545 +#define DW_FORM_udata   0x0f
15546 +#define DW_FORM_ref_addr        0x10
15547 +#define DW_FORM_ref1    0x11
15548 +#define DW_FORM_ref2    0x12
15549 +#define DW_FORM_ref4    0x13
15550 +#define DW_FORM_ref8    0x14
15551 +#define DW_FORM_ref_udata       0x15
15552 +#define DW_FORM_indirect        0x16
15553 +#define DW_AT_sibling   0x01
15554 +#define DW_AT_location  0x02
15555 +#define DW_AT_name      0x03
15556 +#define DW_AT_ordering  0x09
15557 +#define DW_AT_subscr_data       0x0a
15558 +#define DW_AT_byte_size         0x0b
15559 +#define DW_AT_bit_offset        0x0c
15560 +#define DW_AT_bit_size  0x0d
15561 +#define DW_AT_element_list      0x0f
15562 +#define DW_AT_stmt_list         0x10
15563 +#define DW_AT_low_pc    0x11
15564 +#define DW_AT_high_pc   0x12
15565 +#define DW_AT_language  0x13
15566 +#define DW_AT_member    0x14
15567 +#define DW_AT_discr     0x15
15568 +#define DW_AT_discr_value       0x16
15569 +#define DW_AT_visibility        0x17
15570 +#define DW_AT_import    0x18
15571 +#define DW_AT_string_length     0x19
15572 +#define DW_AT_common_reference  0x1a
15573 +#define DW_AT_comp_dir  0x1b
15574 +#define DW_AT_const_value       0x1c
15575 +#define DW_AT_containing_type   0x1d
15576 +#define DW_AT_default_value     0x1e
15577 +#define DW_AT_inline    0x20
15578 +#define DW_AT_is_optional       0x21
15579 +#define DW_AT_lower_bound       0x22
15580 +#define DW_AT_producer  0x25
15581 +#define DW_AT_prototyped        0x27
15582 +#define DW_AT_return_addr       0x2a
15583 +#define DW_AT_start_scope       0x2c
15584 +#define DW_AT_stride_size       0x2e
15585 +#define DW_AT_upper_bound       0x2f
15586 +#define DW_AT_abstract_origin   0x31
15587 +#define DW_AT_accessibility     0x32
15588 +#define DW_AT_address_class     0x33
15589 +#define DW_AT_artificial        0x34
15590 +#define DW_AT_base_types        0x35
15591 +#define DW_AT_calling_convention        0x36
15592 +#define DW_AT_count     0x37
15593 +#define DW_AT_data_member_location      0x38
15594 +#define DW_AT_decl_column       0x39
15595 +#define DW_AT_decl_file         0x3a
15596 +#define DW_AT_decl_line         0x3b
15597 +#define DW_AT_declaration       0x3c
15598 +#define DW_AT_discr_list        0x3d
15599 +#define DW_AT_encoding  0x3e
15600 +#define DW_AT_external  0x3f
15601 +#define DW_AT_frame_base        0x40
15602 +#define DW_AT_friend    0x41
15603 +#define DW_AT_identifier_case   0x42
15604 +#define DW_AT_macro_info        0x43
15605 +#define DW_AT_namelist_items    0x44
15606 +#define DW_AT_priority  0x45
15607 +#define DW_AT_segment   0x46
15608 +#define DW_AT_specification     0x47
15609 +#define DW_AT_static_link       0x48
15610 +#define DW_AT_type      0x49
15611 +#define DW_AT_use_location      0x4a
15612 +#define DW_AT_variable_parameter        0x4b
15613 +#define DW_AT_virtuality        0x4c
15614 +#define DW_AT_vtable_elem_location      0x4d
15615 +#define DW_AT_allocated         0x4e
15616 +#define DW_AT_associated        0x4f
15617 +#define DW_AT_data_location     0x50
15618 +#define DW_AT_stride    0x51
15619 +#define DW_AT_entry_pc  0x52
15620 +#define DW_AT_use_UTF8  0x53
15621 +#define DW_AT_extension         0x54
15622 +#define DW_AT_ranges    0x55
15623 +#define DW_AT_trampoline        0x56
15624 +#define DW_AT_call_column       0x57
15625 +#define DW_AT_call_file         0x58
15626 +#define DW_AT_call_line         0x59
15627 +#define DW_AT_MIPS_fde  0x2001
15628 +#define DW_AT_MIPS_loop_begin   0x2002
15629 +#define DW_AT_MIPS_tail_loop_begin      0x2003
15630 +#define DW_AT_MIPS_epilog_begin         0x2004
15631 +#define DW_AT_MIPS_loop_unroll_factor   0x2005
15632 +#define DW_AT_MIPS_software_pipeline_depth      0x2006
15633 +#define DW_AT_MIPS_linkage_name         0x2007
15634 +#define DW_AT_MIPS_stride       0x2008
15635 +#define DW_AT_MIPS_abstract_name        0x2009
15636 +#define DW_AT_MIPS_clone_origin         0x200a
15637 +#define DW_AT_MIPS_has_inlines  0x200b
15638 +#define DW_AT_HP_block_index    0x2000
15639 +#define DW_AT_HP_unmodifiable   0x2001
15640 +#define DW_AT_HP_actuals_stmt_list      0x2010
15641 +#define DW_AT_HP_proc_per_section       0x2011
15642 +#define DW_AT_HP_raw_data_ptr   0x2012
15643 +#define DW_AT_HP_pass_by_reference      0x2013
15644 +#define DW_AT_HP_opt_level      0x2014
15645 +#define DW_AT_HP_prof_version_id        0x2015
15646 +#define DW_AT_HP_opt_flags      0x2016
15647 +#define DW_AT_HP_cold_region_low_pc     0x2017
15648 +#define DW_AT_HP_cold_region_high_pc    0x2018
15649 +#define DW_AT_HP_all_variables_modifiable       0x2019
15650 +#define DW_AT_HP_linkage_name   0x201a
15651 +#define DW_AT_HP_prof_flags     0x201b
15652 +#define DW_AT_sf_names  0x2101
15653 +#define DW_AT_src_info  0x2102
15654 +#define DW_AT_mac_info  0x2103
15655 +#define DW_AT_src_coords        0x2104
15656 +#define DW_AT_body_begin        0x2105
15657 +#define DW_AT_body_end  0x2106
15658 +#define DW_AT_GNU_vector        0x2107
15659 +#define DW_AT_VMS_rtnbeg_pd_address     0x2201
15660 +#define DW_AT_upc_threads_scaled        0x3210
15661 +#define DW_AT_PGI_lbase         0x3a00
15662 +#define DW_AT_PGI_soffset       0x3a01
15663 +#define DW_AT_PGI_lstride       0x3a02
15664 +#define DW_AT_lo_user  0x2000  /* Implementation-defined range start.  */
15665 +#define DW_AT_hi_user  0x3ff0  /* Implementation-defined range end.  */
15666 +#define DW_OP_addr      0x03
15667 +#define DW_OP_deref     0x06
15668 +#define DW_OP_const1u   0x08
15669 +#define DW_OP_const1s   0x09
15670 +#define DW_OP_const2u   0x0a
15671 +#define DW_OP_const2s   0x0b
15672 +#define DW_OP_const4u   0x0c
15673 +#define DW_OP_const4s   0x0d
15674 +#define DW_OP_const8u   0x0e
15675 +#define DW_OP_const8s   0x0f
15676 +#define DW_OP_constu    0x10
15677 +#define DW_OP_consts    0x11
15678 +#define DW_OP_dup       0x12
15679 +#define DW_OP_drop      0x13
15680 +#define DW_OP_over      0x14
15681 +#define DW_OP_pick      0x15
15682 +#define DW_OP_swap      0x16
15683 +#define DW_OP_rot       0x17
15684 +#define DW_OP_xderef    0x18
15685 +#define DW_OP_abs       0x19
15686 +#define DW_OP_and       0x1a
15687 +#define DW_OP_div       0x1b
15688 +#define DW_OP_minus     0x1c
15689 +#define DW_OP_mod       0x1d
15690 +#define DW_OP_mul       0x1e
15691 +#define DW_OP_neg       0x1f
15692 +#define DW_OP_not       0x20
15693 +#define DW_OP_or        0x21
15694 +#define DW_OP_plus      0x22
15695 +#define DW_OP_plus_uconst       0x23
15696 +#define DW_OP_shl       0x24
15697 +#define DW_OP_shr       0x25
15698 +#define DW_OP_shra      0x26
15699 +#define DW_OP_xor       0x27
15700 +#define DW_OP_bra       0x28
15701 +#define DW_OP_eq        0x29
15702 +#define DW_OP_ge        0x2a
15703 +#define DW_OP_gt        0x2b
15704 +#define DW_OP_le        0x2c
15705 +#define DW_OP_lt        0x2d
15706 +#define DW_OP_ne        0x2e
15707 +#define DW_OP_skip      0x2f
15708 +#define DW_OP_lit0      0x30
15709 +#define DW_OP_lit1      0x31
15710 +#define DW_OP_lit2      0x32
15711 +#define DW_OP_lit3      0x33
15712 +#define DW_OP_lit4      0x34
15713 +#define DW_OP_lit5      0x35
15714 +#define DW_OP_lit6      0x36
15715 +#define DW_OP_lit7      0x37
15716 +#define DW_OP_lit8      0x38
15717 +#define DW_OP_lit9      0x39
15718 +#define DW_OP_lit10     0x3a
15719 +#define DW_OP_lit11     0x3b
15720 +#define DW_OP_lit12     0x3c
15721 +#define DW_OP_lit13     0x3d
15722 +#define DW_OP_lit14     0x3e
15723 +#define DW_OP_lit15     0x3f
15724 +#define DW_OP_lit16     0x40
15725 +#define DW_OP_lit17     0x41
15726 +#define DW_OP_lit18     0x42
15727 +#define DW_OP_lit19     0x43
15728 +#define DW_OP_lit20     0x44
15729 +#define DW_OP_lit21     0x45
15730 +#define DW_OP_lit22     0x46
15731 +#define DW_OP_lit23     0x47
15732 +#define DW_OP_lit24     0x48
15733 +#define DW_OP_lit25     0x49
15734 +#define DW_OP_lit26     0x4a
15735 +#define DW_OP_lit27     0x4b
15736 +#define DW_OP_lit28     0x4c
15737 +#define DW_OP_lit29     0x4d
15738 +#define DW_OP_lit30     0x4e
15739 +#define DW_OP_lit31     0x4f
15740 +#define DW_OP_reg0      0x50
15741 +#define DW_OP_reg1      0x51
15742 +#define DW_OP_reg2      0x52
15743 +#define DW_OP_reg3      0x53
15744 +#define DW_OP_reg4      0x54
15745 +#define DW_OP_reg5      0x55
15746 +#define DW_OP_reg6      0x56
15747 +#define DW_OP_reg7      0x57
15748 +#define DW_OP_reg8      0x58
15749 +#define DW_OP_reg9      0x59
15750 +#define DW_OP_reg10     0x5a
15751 +#define DW_OP_reg11     0x5b
15752 +#define DW_OP_reg12     0x5c
15753 +#define DW_OP_reg13     0x5d
15754 +#define DW_OP_reg14     0x5e
15755 +#define DW_OP_reg15     0x5f
15756 +#define DW_OP_reg16     0x60
15757 +#define DW_OP_reg17     0x61
15758 +#define DW_OP_reg18     0x62
15759 +#define DW_OP_reg19     0x63
15760 +#define DW_OP_reg20     0x64
15761 +#define DW_OP_reg21     0x65
15762 +#define DW_OP_reg22     0x66
15763 +#define DW_OP_reg23     0x67
15764 +#define DW_OP_reg24     0x68
15765 +#define DW_OP_reg25     0x69
15766 +#define DW_OP_reg26     0x6a
15767 +#define DW_OP_reg27     0x6b
15768 +#define DW_OP_reg28     0x6c
15769 +#define DW_OP_reg29     0x6d
15770 +#define DW_OP_reg30     0x6e
15771 +#define DW_OP_reg31     0x6f
15772 +#define DW_OP_breg0     0x70
15773 +#define DW_OP_breg1     0x71
15774 +#define DW_OP_breg2     0x72
15775 +#define DW_OP_breg3     0x73
15776 +#define DW_OP_breg4     0x74
15777 +#define DW_OP_breg5     0x75
15778 +#define DW_OP_breg6     0x76
15779 +#define DW_OP_breg7     0x77
15780 +#define DW_OP_breg8     0x78
15781 +#define DW_OP_breg9     0x79
15782 +#define DW_OP_breg10    0x7a
15783 +#define DW_OP_breg11    0x7b
15784 +#define DW_OP_breg12    0x7c
15785 +#define DW_OP_breg13    0x7d
15786 +#define DW_OP_breg14    0x7e
15787 +#define DW_OP_breg15    0x7f
15788 +#define DW_OP_breg16    0x80
15789 +#define DW_OP_breg17    0x81
15790 +#define DW_OP_breg18    0x82
15791 +#define DW_OP_breg19    0x83
15792 +#define DW_OP_breg20    0x84
15793 +#define DW_OP_breg21    0x85
15794 +#define DW_OP_breg22    0x86
15795 +#define DW_OP_breg23    0x87
15796 +#define DW_OP_breg24    0x88
15797 +#define DW_OP_breg25    0x89
15798 +#define DW_OP_breg26    0x8a
15799 +#define DW_OP_breg27    0x8b
15800 +#define DW_OP_breg28    0x8c
15801 +#define DW_OP_breg29    0x8d
15802 +#define DW_OP_breg30    0x8e
15803 +#define DW_OP_breg31    0x8f
15804 +#define DW_OP_regx      0x90
15805 +#define DW_OP_fbreg     0x91
15806 +#define DW_OP_bregx     0x92
15807 +#define DW_OP_piece     0x93
15808 +#define DW_OP_deref_size        0x94
15809 +#define DW_OP_xderef_size       0x95
15810 +#define DW_OP_nop       0x96
15811 +#define DW_OP_push_object_address       0x97
15812 +#define DW_OP_call2     0x98
15813 +#define DW_OP_call4     0x99
15814 +#define DW_OP_call_ref  0x9a
15815 +#define DW_OP_GNU_push_tls_address      0xe0
15816 +#define DW_OP_HP_unknown        0xe0
15817 +#define DW_OP_HP_is_value       0xe1
15818 +#define DW_OP_HP_fltconst4      0xe2
15819 +#define DW_OP_HP_fltconst8      0xe3
15820 +#define DW_OP_HP_mod_range      0xe4
15821 +#define DW_OP_HP_unmod_range    0xe5
15822 +#define DW_OP_HP_tls    0xe6
15823 +#define DW_OP_lo_user  0xe0    /* Implementation-defined range start.  */
15824 +#define DW_OP_hi_user  0xff    /* Implementation-defined range end.  */
15825 +#define DW_ATE_void     0x0
15826 +#define DW_ATE_address  0x1
15827 +#define DW_ATE_boolean  0x2
15828 +#define DW_ATE_complex_float    0x3
15829 +#define DW_ATE_float    0x4
15830 +#define DW_ATE_signed   0x5
15831 +#define DW_ATE_signed_char      0x6
15832 +#define DW_ATE_unsigned         0x7
15833 +#define DW_ATE_unsigned_char    0x8
15834 +#define DW_ATE_imaginary_float  0x9
15835 +#define DW_ATE_HP_float80       0x80
15836 +#define DW_ATE_HP_complex_float80       0x81
15837 +#define DW_ATE_HP_float128      0x82
15838 +#define DW_ATE_HP_complex_float128      0x83
15839 +#define DW_ATE_HP_floathpintel  0x84
15840 +#define DW_ATE_HP_imaginary_float80     0x85
15841 +#define DW_ATE_HP_imaginary_float128    0x86
15842 +#define        DW_ATE_lo_user 0x80
15843 +#define        DW_ATE_hi_user 0xff
15844 +#define DW_ORD_row_major        0
15845 +#define DW_ORD_col_major        1
15846 +#define DW_ACCESS_public        1
15847 +#define DW_ACCESS_protected     2
15848 +#define DW_ACCESS_private       3
15849 +#define DW_VIS_local    1
15850 +#define DW_VIS_exported         2
15851 +#define DW_VIS_qualified        3
15852 +#define DW_VIRTUALITY_none      0
15853 +#define DW_VIRTUALITY_virtual   1
15854 +#define DW_VIRTUALITY_pure_virtual      2
15855 +#define DW_ID_case_sensitive    0
15856 +#define DW_ID_up_case   1
15857 +#define DW_ID_down_case         2
15858 +#define DW_ID_case_insensitive  3
15859 +#define DW_CC_normal    0x1
15860 +#define DW_CC_program   0x2
15861 +#define DW_CC_nocall    0x3
15862 +#define DW_CC_lo_user 0x40
15863 +#define DW_CC_hi_user 0xff
15864 +#define DW_INL_not_inlined      0
15865 +#define DW_INL_inlined  1
15866 +#define DW_INL_declared_not_inlined     2
15867 +#define DW_INL_declared_inlined         3
15868 +#define DW_DSC_label    0
15869 +#define DW_DSC_range    1
15870 +#define DW_LNS_extended_op      0
15871 +#define DW_LNS_copy     1
15872 +#define DW_LNS_advance_pc       2
15873 +#define DW_LNS_advance_line     3
15874 +#define DW_LNS_set_file         4
15875 +#define DW_LNS_set_column       5
15876 +#define DW_LNS_negate_stmt      6
15877 +#define DW_LNS_set_basic_block  7
15878 +#define DW_LNS_const_add_pc     8
15879 +#define DW_LNS_fixed_advance_pc         9
15880 +#define DW_LNS_set_prologue_end         10
15881 +#define DW_LNS_set_epilogue_begin       11
15882 +#define DW_LNS_set_isa  12
15883 +#define DW_LNE_end_sequence     1
15884 +#define DW_LNE_set_address      2
15885 +#define DW_LNE_define_file      3
15886 +#define DW_LNE_HP_negate_is_UV_update   0x11
15887 +#define DW_LNE_HP_push_context  0x12
15888 +#define DW_LNE_HP_pop_context   0x13
15889 +#define DW_LNE_HP_set_file_line_column  0x14
15890 +#define DW_LNE_HP_set_routine_name      0x15
15891 +#define DW_LNE_HP_set_sequence  0x16
15892 +#define DW_LNE_HP_negate_post_semantics         0x17
15893 +#define DW_LNE_HP_negate_function_exit  0x18
15894 +#define DW_LNE_HP_negate_front_end_logical      0x19
15895 +#define DW_LNE_HP_define_proc   0x20
15896 +#define DW_CFA_advance_loc      0x40
15897 +#define DW_CFA_offset   0x80
15898 +#define DW_CFA_restore  0xc0
15899 +#define DW_CFA_nop      0x00
15900 +#define DW_CFA_set_loc  0x01
15901 +#define DW_CFA_advance_loc1     0x02
15902 +#define DW_CFA_advance_loc2     0x03
15903 +#define DW_CFA_advance_loc4     0x04
15904 +#define DW_CFA_offset_extended  0x05
15905 +#define DW_CFA_restore_extended         0x06
15906 +#define DW_CFA_undefined        0x07
15907 +#define DW_CFA_same_value       0x08
15908 +#define DW_CFA_register         0x09
15909 +#define DW_CFA_remember_state   0x0a
15910 +#define DW_CFA_restore_state    0x0b
15911 +#define DW_CFA_def_cfa  0x0c
15912 +#define DW_CFA_def_cfa_register         0x0d
15913 +#define DW_CFA_def_cfa_offset   0x0e
15914 +#define DW_CFA_def_cfa_expression       0x0f
15915 +#define DW_CFA_expression       0x10
15916 +#define DW_CFA_offset_extended_sf       0x11
15917 +#define DW_CFA_def_cfa_sf       0x12
15918 +#define DW_CFA_def_cfa_offset_sf        0x13
15919 +#define DW_CFA_MIPS_advance_loc8        0x1d
15920 +#define DW_CFA_GNU_window_save  0x2d
15921 +#define DW_CFA_GNU_args_size    0x2e
15922 +#define DW_CFA_GNU_negative_offset_extended     0x2f
15923 +#define DW_CIE_ID        0xffffffff
15924 +#define DW_CIE_VERSION   1
15925 +#define DW_CFA_extended   0
15926 +#define DW_CFA_lo_user    0x1c
15927 +#define DW_CFA_hi_user    0x3f
15928 +#define DW_CHILDREN_no              0x00
15929 +#define DW_CHILDREN_yes                     0x01
15930 +#define DW_ADDR_none           0
15931 +#define DW_LANG_C89     0x0001
15932 +#define DW_LANG_C       0x0002
15933 +#define DW_LANG_Ada83   0x0003
15934 +#define DW_LANG_C_plus_plus     0x0004
15935 +#define DW_LANG_Cobol74         0x0005
15936 +#define DW_LANG_Cobol85         0x0006
15937 +#define DW_LANG_Fortran77       0x0007
15938 +#define DW_LANG_Fortran90       0x0008
15939 +#define DW_LANG_Pascal83        0x0009
15940 +#define DW_LANG_Modula2         0x000a
15941 +#define DW_LANG_Java    0x000b
15942 +#define DW_LANG_C99     0x000c
15943 +#define DW_LANG_Ada95   0x000d
15944 +#define DW_LANG_Fortran95       0x000e
15945 +#define DW_LANG_Mips_Assembler  0x8001
15946 +#define DW_LANG_Upc     0x8765
15947 +#define DW_LANG_lo_user 0x8000 /* Implementation-defined range start.  */
15948 +#define DW_LANG_hi_user 0xffff /* Implementation-defined range start.  */
15949 +#define DW_MACINFO_define       1
15950 +#define DW_MACINFO_undef        2
15951 +#define DW_MACINFO_start_file   3
15952 +#define DW_MACINFO_end_file     4
15953 +#define DW_MACINFO_vendor_ext   255
15954 +#define DW_EH_PE_absptr                0x00
15955 +#define DW_EH_PE_omit          0xff
15956 +#define DW_EH_PE_uleb128       0x01
15957 +#define DW_EH_PE_udata2                0x02
15958 +#define DW_EH_PE_udata4                0x03
15959 +#define DW_EH_PE_udata8                0x04
15960 +#define DW_EH_PE_sleb128       0x09
15961 +#define DW_EH_PE_sdata2                0x0A
15962 +#define DW_EH_PE_sdata4                0x0B
15963 +#define DW_EH_PE_sdata8                0x0C
15964 +#define DW_EH_PE_signed                0x08
15965 +#define DW_EH_PE_pcrel         0x10
15966 +#define DW_EH_PE_textrel       0x20
15967 +#define DW_EH_PE_datarel       0x30
15968 +#define DW_EH_PE_funcrel       0x40
15969 +#define DW_EH_PE_aligned       0x50
15970 +#define DW_EH_PE_indirect      0x80
15971 +#endif
15972 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/linux/dwarf2-lang.h linux-2.6.18.kgdb/include/linux/dwarf2-lang.h
15973 --- linux-2.6.18/include/linux/dwarf2-lang.h    1970-01-01 03:00:00.000000000 +0300
15974 +++ linux-2.6.18.kgdb/include/linux/dwarf2-lang.h       2008-06-10 16:19:58.000000000 +0400
15975 @@ -0,0 +1,300 @@
15976 +#ifndef DWARF2_LANG
15977 +#define DWARF2_LANG
15978 +
15979 +/*
15980 + * This is free software; you can redistribute it and/or modify it under
15981 + * the terms of the GNU General Public License as published by the Free
15982 + * Software Foundation; either version 2, or (at your option) any later
15983 + * version.
15984 + */
15985 +/*
15986 + * This file defines macros that allow generation of DWARF debug records
15987 + * for asm files.  This file is platform independent.  Register numbers
15988 + * (which are about the only thing that is platform dependent) are to be
15989 + * supplied by a platform defined file.
15990 + */
15991 +/*
15992 + * We need this to work for both asm and C.  In asm we are using the
15993 + * old comment trick to concatenate while C uses the new ANSI thing.
15994 + * Here we have concat macro...  The multi level thing is to allow and
15995 + * macros used in the names to be resolved prior to the cat (at which
15996 + * time they are no longer the same string).
15997 + */
15998 +#define CAT3(a,b,c) _CAT3(a,b,c)
15999 +#define _CAT3(a,b,c) __CAT3(a,b,c)
16000 +#ifndef __STDC__
16001 +#define __CAT3(a,b,c) a/**/b/**/c
16002 +#else
16003 +#define __CAT3(a,b,c) a##b##c
16004 +#endif
16005 +#ifdef __ASSEMBLY__
16006 +#define IFC(a)
16007 +#define IFN_C(a) a
16008 +#define NL ;
16009 +#define QUOTE_THIS(a) a
16010 +#define DWARF_preamble .section .debug_frame,"",%progbits;
16011 +#else
16012 +#define IFC(a) a
16013 +#define IFN_C(a)
16014 +#define NL \n\t
16015 +#define QUOTE_THIS(a) _QUOTE_THIS(a)
16016 +#define _QUOTE_THIS(a) #a
16017 +/* Don't let CPP see the " and , \042=" \054=, */
16018 +#define DWARF_preamble .section .debug_frame \054\042\042\054%progbits
16019 +#endif
16020 +
16021 +#ifdef CONFIG_64BIT
16022 +#define DATA_ALIGN_FACTOR      8
16023 +#define ADDR_LOC               .quad
16024 +#else
16025 +#define DATA_ALIGN_FACTOR      4
16026 +#define ADDR_LOC               .long
16027 +#endif
16028 +
16029 +#include <linux/dwarf2-defs.h>
16030 +/*
16031 + * This macro starts a debug frame section.  The debug_frame describes
16032 + * where to find the registers that the enclosing function saved on
16033 + * entry.
16034 + *
16035 + * ORD is use by the label generator and should be the same as what is
16036 + * passed to CFI_postamble.
16037 + *
16038 + * pc, pc register gdb ordinal.
16039 + *
16040 + * code_align this is the factor used to define locations or regions
16041 + * where the given definitions apply.  If you use labels to define these
16042 + * this should be 1.
16043 + *
16044 + * data_align this is the factor used to define register offsets.  If
16045 + * you use struct offset, this should be the size of the register in
16046 + * bytes or the negative of that.  This is how it is used: you will
16047 + * define a register as the reference register, say the stack pointer,
16048 + * then you will say where a register is located relative to this
16049 + * reference registers value, say 40 for register 3 (the gdb register
16050 + * number).  The <40> will be multiplied by <data_align> to define the
16051 + * byte offset of the given register (3, in this example).  So if your
16052 + * <40> is the byte offset and the reference register points at the
16053 + * begining, you would want 1 for the data_offset.  If <40> was the 40th
16054 + * 4-byte element in that structure you would want 4.  And if your
16055 + * reference register points at the end of the structure you would want
16056 + * a negative data_align value(and you would have to do other math as
16057 + * well).
16058 + */
16059 +
16060 +#define CFI_preamble(ORD, pc, code_align, data_align)  \
16061 +         DWARF_preamble        NL                              \
16062 +       .align DATA_ALIGN_FACTOR NL                     \
16063 +        .globl CAT3(frame,_,ORD) NL                    \
16064 +CAT3(frame,_,ORD): NL                                  \
16065 +       .long 7f-6f NL                                  \
16066 +6:                                                     \
16067 +       .long   DW_CIE_ID NL                            \
16068 +       .byte   DW_CIE_VERSION NL                       \
16069 +       .byte 0  NL                                     \
16070 +       .uleb128 code_align NL                          \
16071 +       .sleb128 data_align NL                          \
16072 +       .byte pc NL
16073 +
16074 +/*
16075 + * After the above macro and prior to the CFI_postamble, you need to
16076 + * define the initial state.  This starts with defining the reference
16077 + * register and, usually the pc.  Here are some helper macros:
16078 + */
16079 +
16080 +#define CFA_define_reference(reg, offset)      \
16081 +       .byte DW_CFA_def_cfa NL                 \
16082 +       .uleb128 reg NL                         \
16083 +       .uleb128 (offset) NL
16084 +
16085 +#define CFA_define_offset(reg, offset)         \
16086 +       .byte (DW_CFA_offset + reg) NL          \
16087 +       .uleb128 (offset) NL
16088 +
16089 +#define CFA_restore(reg)                       \
16090 +        .byte (DW_CFA_restore + reg) NL
16091 +
16092 +#define CFI_postamble()                                \
16093 +       .align DATA_ALIGN_FACTOR NL                             \
16094 +7: NL                                          \
16095 +.previous NL
16096 +
16097 +/*
16098 + * So now your code pushs stuff on the stack, you need a new location
16099 + * and the rules for what to do.  This starts a running description of
16100 + * the call frame.  You need to describe what changes with respect to
16101 + * the call registers as the location of the pc moves through the code.
16102 + * The following builds an FDE (fram descriptor entry?).  Like the
16103 + * above, it has a preamble and a postamble.  It also is tied to the CFI
16104 + * above.
16105 + * The preamble macro is tied to the CFI thru the first parameter.  The
16106 + * second is the code start address and then the code end address+1.
16107 + */
16108 +#define FDE_preamble(ORD, initial_address, end_address)        \
16109 +        DWARF_preamble NL                              \
16110 +       .align DATA_ALIGN_FACTOR NL                                     \
16111 +       .long 9f-8f NL                                  \
16112 +8:                                                     \
16113 +       .long CAT3(frame,_,ORD) NL                      \
16114 +       ADDR_LOC initial_address NL                     \
16115 +       ADDR_LOC (end_address - initial_address) NL
16116 +
16117 +#define FDE_postamble()                                \
16118 +       .align DATA_ALIGN_FACTOR NL                             \
16119 +9:      NL                                     \
16120 +.previous NL
16121 +
16122 +/*
16123 + * That done, you can now add registers, subtract registers, move the
16124 + * reference and even change the reference.  You can also define a new
16125 + * area of code the info applies to.  For discontinuous bits you should
16126 + * start a new FDE.  You may have as many as you like.
16127 + */
16128 +
16129 +/*
16130 + * To advance the stack address by <bytes> (0x3f max)
16131 + */
16132 +
16133 +#define CFA_advance_loc(bytes)                 \
16134 +       .byte DW_CFA_advance_loc+bytes NL
16135 +
16136 +/*
16137 + * This one is good for 0xff or 255
16138 + */
16139 +#define CFA_advance_loc1(bytes)                        \
16140 +       .byte DW_CFA_advance_loc1 NL            \
16141 +        .byte bytes NL
16142 +
16143 +#define CFA_undefine_reg(reg)                  \
16144 +        .byte DW_CFA_undefined NL              \
16145 +       .uleb128 reg NL
16146 +/*
16147 + * With the above you can define all the register locations.  But
16148 + * suppose the reference register moves... Takes the new offset NOT an
16149 + * increment.  This is how esp is tracked if it is not saved.
16150 + */
16151 +
16152 +#define CFA_define_cfa_offset(offset)          \
16153 +       .byte DW_CFA_def_cfa_offset NL          \
16154 +       .uleb128 (offset) NL
16155 +/*
16156 + * Or suppose you want to use a different reference register...
16157 + */
16158 +#define CFA_define_cfa_register(reg)           \
16159 +       .byte DW_CFA_def_cfa_register NL        \
16160 +       .uleb128 reg NL
16161 +
16162 +/*
16163 + * If you want to mess with the stack pointer, here is the expression.
16164 + * The stack starts empty.
16165 + */
16166 +#define CFA_def_cfa_expression                         \
16167 +        .byte DW_CFA_def_cfa_expression        NL      \
16168 +       .uleb128 20f-10f NL                     \
16169 +10:     NL
16170 +/*
16171 + * This expression is to be used for other regs.  The stack starts with the
16172 + * stack address.
16173 + */
16174 +
16175 +#define CFA_expression(reg)                    \
16176 +        .byte DW_CFA_expression         NL             \
16177 +        .uleb128 reg NL                                \
16178 +       .uleb128 20f-10f NL                     \
16179 +10:     NL
16180 +/*
16181 + * Here we do the expression stuff.  You should code the above followed
16182 + *  by expression OPs followed by CFA_expression_end.
16183 + */
16184 +
16185 +
16186 +#define CFA_expression_end                     \
16187 +20:     NL
16188 +
16189 +#define CFA_exp_OP_const4s(a)                  \
16190 +        .byte DW_OP_const4s NL                 \
16191 +        .long a NL
16192 +
16193 +#define  CFA_exp_OP_swap  .byte DW_OP_swap NL
16194 +#define  CFA_exp_OP_dup  .byte DW_OP_dup NL
16195 +#define  CFA_exp_OP_drop  .byte DW_OP_drop NL
16196 +/*
16197 + * All these work on the top two elements on the stack, replacing them
16198 + * with the result.  Top comes first where it matters.  True is 1, false 0.
16199 + */
16200 +#define  CFA_exp_OP_deref .byte DW_OP_deref NL
16201 +#define  CFA_exp_OP_and   .byte DW_OP_and NL
16202 +#define  CFA_exp_OP_div   .byte DW_OP_div NL
16203 +#define  CFA_exp_OP_minus .byte DW_OP_minus NL
16204 +#define  CFA_exp_OP_mod   .byte DW_OP_mod NL
16205 +#define  CFA_exp_OP_neg   .byte DW_OP_neg NL
16206 +#define  CFA_exp_OP_plus  .byte DW_OP_plus NL
16207 +#define  CFA_exp_OP_not   .byte DW_OP_not NL
16208 +#define  CFA_exp_OP_or    .byte DW_OP_or NL
16209 +#define  CFA_exp_OP_xor   .byte DW_OP_xor NL
16210 +#define  CFA_exp_OP_le    .byte DW_OP_le NL
16211 +#define  CFA_exp_OP_ge    .byte DW_OP_ge NL
16212 +#define  CFA_exp_OP_eq    .byte DW_OP_eq NL
16213 +#define  CFA_exp_OP_lt    .byte DW_OP_lt NL
16214 +#define  CFA_exp_OP_gt    .byte DW_OP_gt NL
16215 +#define  CFA_exp_OP_ne    .byte DW_OP_ne NL
16216 +/*
16217 + * These take a parameter as noted
16218 + */
16219 +/*
16220 + * Unconditional skip to loc. loc is a label (loc:)
16221 + */
16222 +#define CFA_exp_OP_skip(loc)                   \
16223 +         .byte DW_OP_skip  NL                  \
16224 +        .hword  loc-.-2 NL
16225 +/*
16226 + * Conditional skip to loc (TOS != 0, TOS--) (loc is a label)
16227 + */
16228 +#define CFA_exp_OP_bra(loc)                    \
16229 +         .byte DW_OP_bra NL                    \
16230 +        .hword loc-.-2 NL
16231 +
16232 +/*
16233 + * TOS += no (an unsigned number)
16234 + */
16235 +#define CFA_exp_OP_plus_uconst(no)             \
16236 +         .byte DW_OP_plus_uconst NL            \
16237 +         .uleb128 no NL
16238 +
16239 +/*
16240 + * ++TOS = no (a unsigned number)
16241 + */
16242 +#define CFA_exp_OP_constu(no)                  \
16243 +         .byte DW_OP_constu NL                 \
16244 +        .uleb128 no NL
16245 +/*
16246 + * ++TOS = no (a signed number)
16247 + */
16248 +#define CFA_exp_OP_consts(no)                  \
16249 +         .byte DW_OP_consts NL                 \
16250 +        .sleb128 no NL
16251 +/*
16252 + * ++TOS = no (an unsigned byte)
16253 + */
16254 +#define CFA_exp_OP_const1u(no)                 \
16255 +         .byte DW_OP_const1u NL                        \
16256 +        .byte no NL
16257 +
16258 +
16259 +/*
16260 + * ++TOS = no (a address)
16261 + */
16262 +#define CFA_exp_OP_addr(no)                    \
16263 +         .byte DW_OP_addr NL                   \
16264 +        .long no NL
16265 +
16266 +/*
16267 + * Push current frames value for "reg" + offset
16268 + * We take advantage of the opcode assignments to make this a litteral reg
16269 + * rather than use the DW_OP_bregx opcode.
16270 + */
16271 +
16272 +#define CFA_exp_OP_breg(reg,offset)            \
16273 +         .byte DW_OP_breg0+reg NL              \
16274 +         .sleb128 offset NL
16275 +#endif
16276 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/linux/dwarf2.h linux-2.6.18.kgdb/include/linux/dwarf2.h
16277 --- linux-2.6.18/include/linux/dwarf2.h 1970-01-01 03:00:00.000000000 +0300
16278 +++ linux-2.6.18.kgdb/include/linux/dwarf2.h    2008-06-10 16:19:58.000000000 +0400
16279 @@ -0,0 +1,775 @@
16280 +/* Declarations and definitions of codes relating to the DWARF2 symbolic
16281 +   debugging information format.
16282 +   Copyright (C) 1992, 1993, 1995, 1996, 1997, 1999, 2000, 2001, 2002,
16283 +   2003 Free Software Foundation, Inc.
16284 +
16285 +   Written by Gary Funck (gary@intrepid.com) The Ada Joint Program
16286 +   Office (AJPO), Florida State Unviversity and Silicon Graphics Inc.
16287 +   provided support for this effort -- June 21, 1995.
16288 +
16289 +   Derived from the DWARF 1 implementation written by Ron Guilmette
16290 +   (rfg@netcom.com), November 1990.
16291 +
16292 +   This file is part of GCC.
16293 +
16294 +   GCC is free software; you can redistribute it and/or modify it under
16295 +   the terms of the GNU General Public License as published by the Free
16296 +   Software Foundation; either version 2, or (at your option) any later
16297 +   version.
16298 +
16299 +   GCC is distributed in the hope that it will be useful, but WITHOUT
16300 +   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16301 +   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16302 +   License for more details.
16303 +
16304 +   You should have received a copy of the GNU General Public License
16305 +   along with GCC; see the file COPYING.  If not, write to the Free
16306 +   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
16307 +   02111-1307, USA.  */
16308 +
16309 +/* This file is derived from the DWARF specification (a public document)
16310 +   Revision 2.0.0 (July 27, 1993) developed by the UNIX International
16311 +   Programming Languages Special Interest Group (UI/PLSIG) and distributed
16312 +   by UNIX International.  Copies of this specification are available from
16313 +   UNIX International, 20 Waterview Boulevard, Parsippany, NJ, 07054.
16314 +
16315 +   This file also now contains definitions from the DWARF 3 specification.  */
16316 +
16317 +/* This file is shared between GCC and GDB, and should not contain
16318 +   prototypes.  */
16319 +
16320 +#ifndef _ELF_DWARF2_H
16321 +#define _ELF_DWARF2_H
16322 +
16323 +/* Structure found in the .debug_line section.  */
16324 +typedef struct
16325 +{
16326 +  unsigned char li_length          [4];
16327 +  unsigned char li_version         [2];
16328 +  unsigned char li_prologue_length [4];
16329 +  unsigned char li_min_insn_length [1];
16330 +  unsigned char li_default_is_stmt [1];
16331 +  unsigned char li_line_base       [1];
16332 +  unsigned char li_line_range      [1];
16333 +  unsigned char li_opcode_base     [1];
16334 +}
16335 +DWARF2_External_LineInfo;
16336 +
16337 +typedef struct
16338 +{
16339 +  unsigned long  li_length;
16340 +  unsigned short li_version;
16341 +  unsigned int   li_prologue_length;
16342 +  unsigned char  li_min_insn_length;
16343 +  unsigned char  li_default_is_stmt;
16344 +  int            li_line_base;
16345 +  unsigned char  li_line_range;
16346 +  unsigned char  li_opcode_base;
16347 +}
16348 +DWARF2_Internal_LineInfo;
16349 +
16350 +/* Structure found in .debug_pubnames section.  */
16351 +typedef struct
16352 +{
16353 +  unsigned char pn_length  [4];
16354 +  unsigned char pn_version [2];
16355 +  unsigned char pn_offset  [4];
16356 +  unsigned char pn_size    [4];
16357 +}
16358 +DWARF2_External_PubNames;
16359 +
16360 +typedef struct
16361 +{
16362 +  unsigned long  pn_length;
16363 +  unsigned short pn_version;
16364 +  unsigned long  pn_offset;
16365 +  unsigned long  pn_size;
16366 +}
16367 +DWARF2_Internal_PubNames;
16368 +
16369 +/* Structure found in .debug_info section.  */
16370 +typedef struct
16371 +{
16372 +  unsigned char  cu_length        [4];
16373 +  unsigned char  cu_version       [2];
16374 +  unsigned char  cu_abbrev_offset [4];
16375 +  unsigned char  cu_pointer_size  [1];
16376 +}
16377 +DWARF2_External_CompUnit;
16378 +
16379 +typedef struct
16380 +{
16381 +  unsigned long  cu_length;
16382 +  unsigned short cu_version;
16383 +  unsigned long  cu_abbrev_offset;
16384 +  unsigned char  cu_pointer_size;
16385 +}
16386 +DWARF2_Internal_CompUnit;
16387 +
16388 +typedef struct
16389 +{
16390 +  unsigned char  ar_length       [4];
16391 +  unsigned char  ar_version      [2];
16392 +  unsigned char  ar_info_offset  [4];
16393 +  unsigned char  ar_pointer_size [1];
16394 +  unsigned char  ar_segment_size [1];
16395 +}
16396 +DWARF2_External_ARange;
16397 +
16398 +typedef struct
16399 +{
16400 +  unsigned long  ar_length;
16401 +  unsigned short ar_version;
16402 +  unsigned long  ar_info_offset;
16403 +  unsigned char  ar_pointer_size;
16404 +  unsigned char  ar_segment_size;
16405 +}
16406 +DWARF2_Internal_ARange;
16407 +
16408 +
16409 +/* Tag names and codes.  */
16410 +enum dwarf_tag
16411 +  {
16412 +    DW_TAG_padding = 0x00,
16413 +    DW_TAG_array_type = 0x01,
16414 +    DW_TAG_class_type = 0x02,
16415 +    DW_TAG_entry_point = 0x03,
16416 +    DW_TAG_enumeration_type = 0x04,
16417 +    DW_TAG_formal_parameter = 0x05,
16418 +    DW_TAG_imported_declaration = 0x08,
16419 +    DW_TAG_label = 0x0a,
16420 +    DW_TAG_lexical_block = 0x0b,
16421 +    DW_TAG_member = 0x0d,
16422 +    DW_TAG_pointer_type = 0x0f,
16423 +    DW_TAG_reference_type = 0x10,
16424 +    DW_TAG_compile_unit = 0x11,
16425 +    DW_TAG_string_type = 0x12,
16426 +    DW_TAG_structure_type = 0x13,
16427 +    DW_TAG_subroutine_type = 0x15,
16428 +    DW_TAG_typedef = 0x16,
16429 +    DW_TAG_union_type = 0x17,
16430 +    DW_TAG_unspecified_parameters = 0x18,
16431 +    DW_TAG_variant = 0x19,
16432 +    DW_TAG_common_block = 0x1a,
16433 +    DW_TAG_common_inclusion = 0x1b,
16434 +    DW_TAG_inheritance = 0x1c,
16435 +    DW_TAG_inlined_subroutine = 0x1d,
16436 +    DW_TAG_module = 0x1e,
16437 +    DW_TAG_ptr_to_member_type = 0x1f,
16438 +    DW_TAG_set_type = 0x20,
16439 +    DW_TAG_subrange_type = 0x21,
16440 +    DW_TAG_with_stmt = 0x22,
16441 +    DW_TAG_access_declaration = 0x23,
16442 +    DW_TAG_base_type = 0x24,
16443 +    DW_TAG_catch_block = 0x25,
16444 +    DW_TAG_const_type = 0x26,
16445 +    DW_TAG_constant = 0x27,
16446 +    DW_TAG_enumerator = 0x28,
16447 +    DW_TAG_file_type = 0x29,
16448 +    DW_TAG_friend = 0x2a,
16449 +    DW_TAG_namelist = 0x2b,
16450 +    DW_TAG_namelist_item = 0x2c,
16451 +    DW_TAG_packed_type = 0x2d,
16452 +    DW_TAG_subprogram = 0x2e,
16453 +    DW_TAG_template_type_param = 0x2f,
16454 +    DW_TAG_template_value_param = 0x30,
16455 +    DW_TAG_thrown_type = 0x31,
16456 +    DW_TAG_try_block = 0x32,
16457 +    DW_TAG_variant_part = 0x33,
16458 +    DW_TAG_variable = 0x34,
16459 +    DW_TAG_volatile_type = 0x35,
16460 +    /* DWARF 3.  */
16461 +    DW_TAG_dwarf_procedure = 0x36,
16462 +    DW_TAG_restrict_type = 0x37,
16463 +    DW_TAG_interface_type = 0x38,
16464 +    DW_TAG_namespace = 0x39,
16465 +    DW_TAG_imported_module = 0x3a,
16466 +    DW_TAG_unspecified_type = 0x3b,
16467 +    DW_TAG_partial_unit = 0x3c,
16468 +    DW_TAG_imported_unit = 0x3d,
16469 +    /* SGI/MIPS Extensions.  */
16470 +    DW_TAG_MIPS_loop = 0x4081,
16471 +    /* HP extensions.  See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz .  */
16472 +    DW_TAG_HP_array_descriptor = 0x4090,
16473 +    /* GNU extensions.  */
16474 +    DW_TAG_format_label = 0x4101,      /* For FORTRAN 77 and Fortran 90.  */
16475 +    DW_TAG_function_template = 0x4102, /* For C++.  */
16476 +    DW_TAG_class_template = 0x4103,    /* For C++.  */
16477 +    DW_TAG_GNU_BINCL = 0x4104,
16478 +    DW_TAG_GNU_EINCL = 0x4105,
16479 +    /* Extensions for UPC.  See: http://upc.gwu.edu/~upc.  */
16480 +    DW_TAG_upc_shared_type = 0x8765,
16481 +    DW_TAG_upc_strict_type = 0x8766,
16482 +    DW_TAG_upc_relaxed_type = 0x8767,
16483 +    /* PGI (STMicroelectronics) extensions.  No documentation available.  */
16484 +    DW_TAG_PGI_kanji_type      = 0xA000,
16485 +    DW_TAG_PGI_interface_block = 0xA020
16486 +  };
16487 +
16488 +#define DW_TAG_lo_user 0x4080
16489 +#define DW_TAG_hi_user 0xffff
16490 +
16491 +/* Flag that tells whether entry has a child or not.  */
16492 +#define DW_children_no   0
16493 +#define        DW_children_yes  1
16494 +
16495 +/* Form names and codes.  */
16496 +enum dwarf_form
16497 +  {
16498 +    DW_FORM_addr = 0x01,
16499 +    DW_FORM_block2 = 0x03,
16500 +    DW_FORM_block4 = 0x04,
16501 +    DW_FORM_data2 = 0x05,
16502 +    DW_FORM_data4 = 0x06,
16503 +    DW_FORM_data8 = 0x07,
16504 +    DW_FORM_string = 0x08,
16505 +    DW_FORM_block = 0x09,
16506 +    DW_FORM_block1 = 0x0a,
16507 +    DW_FORM_data1 = 0x0b,
16508 +    DW_FORM_flag = 0x0c,
16509 +    DW_FORM_sdata = 0x0d,
16510 +    DW_FORM_strp = 0x0e,
16511 +    DW_FORM_udata = 0x0f,
16512 +    DW_FORM_ref_addr = 0x10,
16513 +    DW_FORM_ref1 = 0x11,
16514 +    DW_FORM_ref2 = 0x12,
16515 +    DW_FORM_ref4 = 0x13,
16516 +    DW_FORM_ref8 = 0x14,
16517 +    DW_FORM_ref_udata = 0x15,
16518 +    DW_FORM_indirect = 0x16
16519 +  };
16520 +
16521 +/* Attribute names and codes.  */
16522 +enum dwarf_attribute
16523 +  {
16524 +    DW_AT_sibling = 0x01,
16525 +    DW_AT_location = 0x02,
16526 +    DW_AT_name = 0x03,
16527 +    DW_AT_ordering = 0x09,
16528 +    DW_AT_subscr_data = 0x0a,
16529 +    DW_AT_byte_size = 0x0b,
16530 +    DW_AT_bit_offset = 0x0c,
16531 +    DW_AT_bit_size = 0x0d,
16532 +    DW_AT_element_list = 0x0f,
16533 +    DW_AT_stmt_list = 0x10,
16534 +    DW_AT_low_pc = 0x11,
16535 +    DW_AT_high_pc = 0x12,
16536 +    DW_AT_language = 0x13,
16537 +    DW_AT_member = 0x14,
16538 +    DW_AT_discr = 0x15,
16539 +    DW_AT_discr_value = 0x16,
16540 +    DW_AT_visibility = 0x17,
16541 +    DW_AT_import = 0x18,
16542 +    DW_AT_string_length = 0x19,
16543 +    DW_AT_common_reference = 0x1a,
16544 +    DW_AT_comp_dir = 0x1b,
16545 +    DW_AT_const_value = 0x1c,
16546 +    DW_AT_containing_type = 0x1d,
16547 +    DW_AT_default_value = 0x1e,
16548 +    DW_AT_inline = 0x20,
16549 +    DW_AT_is_optional = 0x21,
16550 +    DW_AT_lower_bound = 0x22,
16551 +    DW_AT_producer = 0x25,
16552 +    DW_AT_prototyped = 0x27,
16553 +    DW_AT_return_addr = 0x2a,
16554 +    DW_AT_start_scope = 0x2c,
16555 +    DW_AT_stride_size = 0x2e,
16556 +    DW_AT_upper_bound = 0x2f,
16557 +    DW_AT_abstract_origin = 0x31,
16558 +    DW_AT_accessibility = 0x32,
16559 +    DW_AT_address_class = 0x33,
16560 +    DW_AT_artificial = 0x34,
16561 +    DW_AT_base_types = 0x35,
16562 +    DW_AT_calling_convention = 0x36,
16563 +    DW_AT_count = 0x37,
16564 +    DW_AT_data_member_location = 0x38,
16565 +    DW_AT_decl_column = 0x39,
16566 +    DW_AT_decl_file = 0x3a,
16567 +    DW_AT_decl_line = 0x3b,
16568 +    DW_AT_declaration = 0x3c,
16569 +    DW_AT_discr_list = 0x3d,
16570 +    DW_AT_encoding = 0x3e,
16571 +    DW_AT_external = 0x3f,
16572 +    DW_AT_frame_base = 0x40,
16573 +    DW_AT_friend = 0x41,
16574 +    DW_AT_identifier_case = 0x42,
16575 +    DW_AT_macro_info = 0x43,
16576 +    DW_AT_namelist_items = 0x44,
16577 +    DW_AT_priority = 0x45,
16578 +    DW_AT_segment = 0x46,
16579 +    DW_AT_specification = 0x47,
16580 +    DW_AT_static_link = 0x48,
16581 +    DW_AT_type = 0x49,
16582 +    DW_AT_use_location = 0x4a,
16583 +    DW_AT_variable_parameter = 0x4b,
16584 +    DW_AT_virtuality = 0x4c,
16585 +    DW_AT_vtable_elem_location = 0x4d,
16586 +    /* DWARF 3 values.  */
16587 +    DW_AT_allocated     = 0x4e,
16588 +    DW_AT_associated    = 0x4f,
16589 +    DW_AT_data_location = 0x50,
16590 +    DW_AT_stride        = 0x51,
16591 +    DW_AT_entry_pc      = 0x52,
16592 +    DW_AT_use_UTF8      = 0x53,
16593 +    DW_AT_extension     = 0x54,
16594 +    DW_AT_ranges        = 0x55,
16595 +    DW_AT_trampoline    = 0x56,
16596 +    DW_AT_call_column   = 0x57,
16597 +    DW_AT_call_file     = 0x58,
16598 +    DW_AT_call_line     = 0x59,
16599 +    /* SGI/MIPS extensions.  */
16600 +    DW_AT_MIPS_fde = 0x2001,
16601 +    DW_AT_MIPS_loop_begin = 0x2002,
16602 +    DW_AT_MIPS_tail_loop_begin = 0x2003,
16603 +    DW_AT_MIPS_epilog_begin = 0x2004,
16604 +    DW_AT_MIPS_loop_unroll_factor = 0x2005,
16605 +    DW_AT_MIPS_software_pipeline_depth = 0x2006,
16606 +    DW_AT_MIPS_linkage_name = 0x2007,
16607 +    DW_AT_MIPS_stride = 0x2008,
16608 +    DW_AT_MIPS_abstract_name = 0x2009,
16609 +    DW_AT_MIPS_clone_origin = 0x200a,
16610 +    DW_AT_MIPS_has_inlines = 0x200b,
16611 +    /* HP extensions.  */
16612 +    DW_AT_HP_block_index         = 0x2000,
16613 +    DW_AT_HP_unmodifiable        = 0x2001, /* Same as DW_AT_MIPS_fde.  */
16614 +    DW_AT_HP_actuals_stmt_list   = 0x2010,
16615 +    DW_AT_HP_proc_per_section    = 0x2011,
16616 +    DW_AT_HP_raw_data_ptr        = 0x2012,
16617 +    DW_AT_HP_pass_by_reference   = 0x2013,
16618 +    DW_AT_HP_opt_level           = 0x2014,
16619 +    DW_AT_HP_prof_version_id     = 0x2015,
16620 +    DW_AT_HP_opt_flags           = 0x2016,
16621 +    DW_AT_HP_cold_region_low_pc  = 0x2017,
16622 +    DW_AT_HP_cold_region_high_pc = 0x2018,
16623 +    DW_AT_HP_all_variables_modifiable = 0x2019,
16624 +    DW_AT_HP_linkage_name        = 0x201a,
16625 +    DW_AT_HP_prof_flags          = 0x201b,  /* In comp unit of procs_info for -g.  */
16626 +    /* GNU extensions.  */
16627 +    DW_AT_sf_names   = 0x2101,
16628 +    DW_AT_src_info   = 0x2102,
16629 +    DW_AT_mac_info   = 0x2103,
16630 +    DW_AT_src_coords = 0x2104,
16631 +    DW_AT_body_begin = 0x2105,
16632 +    DW_AT_body_end   = 0x2106,
16633 +    DW_AT_GNU_vector = 0x2107,
16634 +    /* VMS extensions.  */
16635 +    DW_AT_VMS_rtnbeg_pd_address = 0x2201,
16636 +    /* UPC extension.  */
16637 +    DW_AT_upc_threads_scaled = 0x3210,
16638 +    /* PGI (STMicroelectronics) extensions.  */
16639 +    DW_AT_PGI_lbase    = 0x3a00,
16640 +    DW_AT_PGI_soffset  = 0x3a01,
16641 +    DW_AT_PGI_lstride  = 0x3a02
16642 +  };
16643 +
16644 +#define DW_AT_lo_user  0x2000  /* Implementation-defined range start.  */
16645 +#define DW_AT_hi_user  0x3ff0  /* Implementation-defined range end.  */
16646 +
16647 +/* Location atom names and codes.  */
16648 +enum dwarf_location_atom
16649 +  {
16650 +    DW_OP_addr = 0x03,
16651 +    DW_OP_deref = 0x06,
16652 +    DW_OP_const1u = 0x08,
16653 +    DW_OP_const1s = 0x09,
16654 +    DW_OP_const2u = 0x0a,
16655 +    DW_OP_const2s = 0x0b,
16656 +    DW_OP_const4u = 0x0c,
16657 +    DW_OP_const4s = 0x0d,
16658 +    DW_OP_const8u = 0x0e,
16659 +    DW_OP_const8s = 0x0f,
16660 +    DW_OP_constu = 0x10,
16661 +    DW_OP_consts = 0x11,
16662 +    DW_OP_dup = 0x12,
16663 +    DW_OP_drop = 0x13,
16664 +    DW_OP_over = 0x14,
16665 +    DW_OP_pick = 0x15,
16666 +    DW_OP_swap = 0x16,
16667 +    DW_OP_rot = 0x17,
16668 +    DW_OP_xderef = 0x18,
16669 +    DW_OP_abs = 0x19,
16670 +    DW_OP_and = 0x1a,
16671 +    DW_OP_div = 0x1b,
16672 +    DW_OP_minus = 0x1c,
16673 +    DW_OP_mod = 0x1d,
16674 +    DW_OP_mul = 0x1e,
16675 +    DW_OP_neg = 0x1f,
16676 +    DW_OP_not = 0x20,
16677 +    DW_OP_or = 0x21,
16678 +    DW_OP_plus = 0x22,
16679 +    DW_OP_plus_uconst = 0x23,
16680 +    DW_OP_shl = 0x24,
16681 +    DW_OP_shr = 0x25,
16682 +    DW_OP_shra = 0x26,
16683 +    DW_OP_xor = 0x27,
16684 +    DW_OP_bra = 0x28,
16685 +    DW_OP_eq = 0x29,
16686 +    DW_OP_ge = 0x2a,
16687 +    DW_OP_gt = 0x2b,
16688 +    DW_OP_le = 0x2c,
16689 +    DW_OP_lt = 0x2d,
16690 +    DW_OP_ne = 0x2e,
16691 +    DW_OP_skip = 0x2f,
16692 +    DW_OP_lit0 = 0x30,
16693 +    DW_OP_lit1 = 0x31,
16694 +    DW_OP_lit2 = 0x32,
16695 +    DW_OP_lit3 = 0x33,
16696 +    DW_OP_lit4 = 0x34,
16697 +    DW_OP_lit5 = 0x35,
16698 +    DW_OP_lit6 = 0x36,
16699 +    DW_OP_lit7 = 0x37,
16700 +    DW_OP_lit8 = 0x38,
16701 +    DW_OP_lit9 = 0x39,
16702 +    DW_OP_lit10 = 0x3a,
16703 +    DW_OP_lit11 = 0x3b,
16704 +    DW_OP_lit12 = 0x3c,
16705 +    DW_OP_lit13 = 0x3d,
16706 +    DW_OP_lit14 = 0x3e,
16707 +    DW_OP_lit15 = 0x3f,
16708 +    DW_OP_lit16 = 0x40,
16709 +    DW_OP_lit17 = 0x41,
16710 +    DW_OP_lit18 = 0x42,
16711 +    DW_OP_lit19 = 0x43,
16712 +    DW_OP_lit20 = 0x44,
16713 +    DW_OP_lit21 = 0x45,
16714 +    DW_OP_lit22 = 0x46,
16715 +    DW_OP_lit23 = 0x47,
16716 +    DW_OP_lit24 = 0x48,
16717 +    DW_OP_lit25 = 0x49,
16718 +    DW_OP_lit26 = 0x4a,
16719 +    DW_OP_lit27 = 0x4b,
16720 +    DW_OP_lit28 = 0x4c,
16721 +    DW_OP_lit29 = 0x4d,
16722 +    DW_OP_lit30 = 0x4e,
16723 +    DW_OP_lit31 = 0x4f,
16724 +    DW_OP_reg0 = 0x50,
16725 +    DW_OP_reg1 = 0x51,
16726 +    DW_OP_reg2 = 0x52,
16727 +    DW_OP_reg3 = 0x53,
16728 +    DW_OP_reg4 = 0x54,
16729 +    DW_OP_reg5 = 0x55,
16730 +    DW_OP_reg6 = 0x56,
16731 +    DW_OP_reg7 = 0x57,
16732 +    DW_OP_reg8 = 0x58,
16733 +    DW_OP_reg9 = 0x59,
16734 +    DW_OP_reg10 = 0x5a,
16735 +    DW_OP_reg11 = 0x5b,
16736 +    DW_OP_reg12 = 0x5c,
16737 +    DW_OP_reg13 = 0x5d,
16738 +    DW_OP_reg14 = 0x5e,
16739 +    DW_OP_reg15 = 0x5f,
16740 +    DW_OP_reg16 = 0x60,
16741 +    DW_OP_reg17 = 0x61,
16742 +    DW_OP_reg18 = 0x62,
16743 +    DW_OP_reg19 = 0x63,
16744 +    DW_OP_reg20 = 0x64,
16745 +    DW_OP_reg21 = 0x65,
16746 +    DW_OP_reg22 = 0x66,
16747 +    DW_OP_reg23 = 0x67,
16748 +    DW_OP_reg24 = 0x68,
16749 +    DW_OP_reg25 = 0x69,
16750 +    DW_OP_reg26 = 0x6a,
16751 +    DW_OP_reg27 = 0x6b,
16752 +    DW_OP_reg28 = 0x6c,
16753 +    DW_OP_reg29 = 0x6d,
16754 +    DW_OP_reg30 = 0x6e,
16755 +    DW_OP_reg31 = 0x6f,
16756 +    DW_OP_breg0 = 0x70,
16757 +    DW_OP_breg1 = 0x71,
16758 +    DW_OP_breg2 = 0x72,
16759 +    DW_OP_breg3 = 0x73,
16760 +    DW_OP_breg4 = 0x74,
16761 +    DW_OP_breg5 = 0x75,
16762 +    DW_OP_breg6 = 0x76,
16763 +    DW_OP_breg7 = 0x77,
16764 +    DW_OP_breg8 = 0x78,
16765 +    DW_OP_breg9 = 0x79,
16766 +    DW_OP_breg10 = 0x7a,
16767 +    DW_OP_breg11 = 0x7b,
16768 +    DW_OP_breg12 = 0x7c,
16769 +    DW_OP_breg13 = 0x7d,
16770 +    DW_OP_breg14 = 0x7e,
16771 +    DW_OP_breg15 = 0x7f,
16772 +    DW_OP_breg16 = 0x80,
16773 +    DW_OP_breg17 = 0x81,
16774 +    DW_OP_breg18 = 0x82,
16775 +    DW_OP_breg19 = 0x83,
16776 +    DW_OP_breg20 = 0x84,
16777 +    DW_OP_breg21 = 0x85,
16778 +    DW_OP_breg22 = 0x86,
16779 +    DW_OP_breg23 = 0x87,
16780 +    DW_OP_breg24 = 0x88,
16781 +    DW_OP_breg25 = 0x89,
16782 +    DW_OP_breg26 = 0x8a,
16783 +    DW_OP_breg27 = 0x8b,
16784 +    DW_OP_breg28 = 0x8c,
16785 +    DW_OP_breg29 = 0x8d,
16786 +    DW_OP_breg30 = 0x8e,
16787 +    DW_OP_breg31 = 0x8f,
16788 +    DW_OP_regx = 0x90,
16789 +    DW_OP_fbreg = 0x91,
16790 +    DW_OP_bregx = 0x92,
16791 +    DW_OP_piece = 0x93,
16792 +    DW_OP_deref_size = 0x94,
16793 +    DW_OP_xderef_size = 0x95,
16794 +    DW_OP_nop = 0x96,
16795 +    /* DWARF 3 extensions.  */
16796 +    DW_OP_push_object_address = 0x97,
16797 +    DW_OP_call2 = 0x98,
16798 +    DW_OP_call4 = 0x99,
16799 +    DW_OP_call_ref = 0x9a,
16800 +    /* GNU extensions.  */
16801 +    DW_OP_GNU_push_tls_address = 0xe0,
16802 +    /* HP extensions.  */
16803 +    DW_OP_HP_unknown     = 0xe0, /* Ouch, the same as GNU_push_tls_address.  */
16804 +    DW_OP_HP_is_value    = 0xe1,
16805 +    DW_OP_HP_fltconst4   = 0xe2,
16806 +    DW_OP_HP_fltconst8   = 0xe3,
16807 +    DW_OP_HP_mod_range   = 0xe4,
16808 +    DW_OP_HP_unmod_range = 0xe5,
16809 +    DW_OP_HP_tls         = 0xe6
16810 +  };
16811 +
16812 +#define DW_OP_lo_user  0xe0    /* Implementation-defined range start.  */
16813 +#define DW_OP_hi_user  0xff    /* Implementation-defined range end.  */
16814 +
16815 +/* Type encodings.  */
16816 +enum dwarf_type
16817 +  {
16818 +    DW_ATE_void = 0x0,
16819 +    DW_ATE_address = 0x1,
16820 +    DW_ATE_boolean = 0x2,
16821 +    DW_ATE_complex_float = 0x3,
16822 +    DW_ATE_float = 0x4,
16823 +    DW_ATE_signed = 0x5,
16824 +    DW_ATE_signed_char = 0x6,
16825 +    DW_ATE_unsigned = 0x7,
16826 +    DW_ATE_unsigned_char = 0x8,
16827 +    /* DWARF 3.  */
16828 +    DW_ATE_imaginary_float = 0x9,
16829 +    /* HP extensions.  */
16830 +    DW_ATE_HP_float80            = 0x80, /* Floating-point (80 bit).  */
16831 +    DW_ATE_HP_complex_float80    = 0x81, /* Complex floating-point (80 bit).  */
16832 +    DW_ATE_HP_float128           = 0x82, /* Floating-point (128 bit).  */
16833 +    DW_ATE_HP_complex_float128   = 0x83, /* Complex floating-point (128 bit).  */
16834 +    DW_ATE_HP_floathpintel       = 0x84, /* Floating-point (82 bit IA64).  */
16835 +    DW_ATE_HP_imaginary_float80  = 0x85,
16836 +    DW_ATE_HP_imaginary_float128 = 0x86
16837 +  };
16838 +
16839 +#define        DW_ATE_lo_user 0x80
16840 +#define        DW_ATE_hi_user 0xff
16841 +
16842 +/* Array ordering names and codes.  */
16843 +enum dwarf_array_dim_ordering
16844 +  {
16845 +    DW_ORD_row_major = 0,
16846 +    DW_ORD_col_major = 1
16847 +  };
16848 +
16849 +/* Access attribute.  */
16850 +enum dwarf_access_attribute
16851 +  {
16852 +    DW_ACCESS_public = 1,
16853 +    DW_ACCESS_protected = 2,
16854 +    DW_ACCESS_private = 3
16855 +  };
16856 +
16857 +/* Visibility.  */
16858 +enum dwarf_visibility_attribute
16859 +  {
16860 +    DW_VIS_local = 1,
16861 +    DW_VIS_exported = 2,
16862 +    DW_VIS_qualified = 3
16863 +  };
16864 +
16865 +/* Virtuality.  */
16866 +enum dwarf_virtuality_attribute
16867 +  {
16868 +    DW_VIRTUALITY_none = 0,
16869 +    DW_VIRTUALITY_virtual = 1,
16870 +    DW_VIRTUALITY_pure_virtual = 2
16871 +  };
16872 +
16873 +/* Case sensitivity.  */
16874 +enum dwarf_id_case
16875 +  {
16876 +    DW_ID_case_sensitive = 0,
16877 +    DW_ID_up_case = 1,
16878 +    DW_ID_down_case = 2,
16879 +    DW_ID_case_insensitive = 3
16880 +  };
16881 +
16882 +/* Calling convention.  */
16883 +enum dwarf_calling_convention
16884 +  {
16885 +    DW_CC_normal = 0x1,
16886 +    DW_CC_program = 0x2,
16887 +    DW_CC_nocall = 0x3
16888 +  };
16889 +
16890 +#define DW_CC_lo_user 0x40
16891 +#define DW_CC_hi_user 0xff
16892 +
16893 +/* Inline attribute.  */
16894 +enum dwarf_inline_attribute
16895 +  {
16896 +    DW_INL_not_inlined = 0,
16897 +    DW_INL_inlined = 1,
16898 +    DW_INL_declared_not_inlined = 2,
16899 +    DW_INL_declared_inlined = 3
16900 +  };
16901 +
16902 +/* Discriminant lists.  */
16903 +enum dwarf_discrim_list
16904 +  {
16905 +    DW_DSC_label = 0,
16906 +    DW_DSC_range = 1
16907 +  };
16908 +
16909 +/* Line number opcodes.  */
16910 +enum dwarf_line_number_ops
16911 +  {
16912 +    DW_LNS_extended_op = 0,
16913 +    DW_LNS_copy = 1,
16914 +    DW_LNS_advance_pc = 2,
16915 +    DW_LNS_advance_line = 3,
16916 +    DW_LNS_set_file = 4,
16917 +    DW_LNS_set_column = 5,
16918 +    DW_LNS_negate_stmt = 6,
16919 +    DW_LNS_set_basic_block = 7,
16920 +    DW_LNS_const_add_pc = 8,
16921 +    DW_LNS_fixed_advance_pc = 9,
16922 +    /* DWARF 3.  */
16923 +    DW_LNS_set_prologue_end = 10,
16924 +    DW_LNS_set_epilogue_begin = 11,
16925 +    DW_LNS_set_isa = 12
16926 +  };
16927 +
16928 +/* Line number extended opcodes.  */
16929 +enum dwarf_line_number_x_ops
16930 +  {
16931 +    DW_LNE_end_sequence = 1,
16932 +    DW_LNE_set_address = 2,
16933 +    DW_LNE_define_file = 3,
16934 +    /* HP extensions.  */
16935 +    DW_LNE_HP_negate_is_UV_update      = 0x11,
16936 +    DW_LNE_HP_push_context             = 0x12,
16937 +    DW_LNE_HP_pop_context              = 0x13,
16938 +    DW_LNE_HP_set_file_line_column     = 0x14,
16939 +    DW_LNE_HP_set_routine_name         = 0x15,
16940 +    DW_LNE_HP_set_sequence             = 0x16,
16941 +    DW_LNE_HP_negate_post_semantics    = 0x17,
16942 +    DW_LNE_HP_negate_function_exit     = 0x18,
16943 +    DW_LNE_HP_negate_front_end_logical = 0x19,
16944 +    DW_LNE_HP_define_proc              = 0x20
16945 +  };
16946 +
16947 +/* Call frame information.  */
16948 +enum dwarf_call_frame_info
16949 +  {
16950 +    DW_CFA_advance_loc = 0x40,
16951 +    DW_CFA_offset = 0x80,
16952 +    DW_CFA_restore = 0xc0,
16953 +    DW_CFA_nop = 0x00,
16954 +    DW_CFA_set_loc = 0x01,
16955 +    DW_CFA_advance_loc1 = 0x02,
16956 +    DW_CFA_advance_loc2 = 0x03,
16957 +    DW_CFA_advance_loc4 = 0x04,
16958 +    DW_CFA_offset_extended = 0x05,
16959 +    DW_CFA_restore_extended = 0x06,
16960 +    DW_CFA_undefined = 0x07,
16961 +    DW_CFA_same_value = 0x08,
16962 +    DW_CFA_register = 0x09,
16963 +    DW_CFA_remember_state = 0x0a,
16964 +    DW_CFA_restore_state = 0x0b,
16965 +    DW_CFA_def_cfa = 0x0c,
16966 +    DW_CFA_def_cfa_register = 0x0d,
16967 +    DW_CFA_def_cfa_offset = 0x0e,
16968 +    /* DWARF 3.  */
16969 +    DW_CFA_def_cfa_expression = 0x0f,
16970 +    DW_CFA_expression = 0x10,
16971 +    DW_CFA_offset_extended_sf = 0x11,
16972 +    DW_CFA_def_cfa_sf = 0x12,
16973 +    DW_CFA_def_cfa_offset_sf = 0x13,
16974 +    /* SGI/MIPS specific.  */
16975 +    DW_CFA_MIPS_advance_loc8 = 0x1d,
16976 +    /* GNU extensions.  */
16977 +    DW_CFA_GNU_window_save = 0x2d,
16978 +    DW_CFA_GNU_args_size = 0x2e,
16979 +    DW_CFA_GNU_negative_offset_extended = 0x2f
16980 +  };
16981 +
16982 +#define DW_CIE_ID        0xffffffff
16983 +#define DW_CIE_VERSION   1
16984 +
16985 +#define DW_CFA_extended   0
16986 +#define DW_CFA_lo_user    0x1c
16987 +#define DW_CFA_hi_user    0x3f
16988 +
16989 +#define DW_CHILDREN_no              0x00
16990 +#define DW_CHILDREN_yes                     0x01
16991 +
16992 +#define DW_ADDR_none           0
16993 +
16994 +/* Source language names and codes.  */
16995 +enum dwarf_source_language
16996 +  {
16997 +    DW_LANG_C89 = 0x0001,
16998 +    DW_LANG_C = 0x0002,
16999 +    DW_LANG_Ada83 = 0x0003,
17000 +    DW_LANG_C_plus_plus = 0x0004,
17001 +    DW_LANG_Cobol74 = 0x0005,
17002 +    DW_LANG_Cobol85 = 0x0006,
17003 +    DW_LANG_Fortran77 = 0x0007,
17004 +    DW_LANG_Fortran90 = 0x0008,
17005 +    DW_LANG_Pascal83 = 0x0009,
17006 +    DW_LANG_Modula2 = 0x000a,
17007 +    DW_LANG_Java = 0x000b,
17008 +    /* DWARF 3.  */
17009 +    DW_LANG_C99 = 0x000c,
17010 +    DW_LANG_Ada95 = 0x000d,
17011 +    DW_LANG_Fortran95 = 0x000e,
17012 +    /* MIPS.  */
17013 +    DW_LANG_Mips_Assembler = 0x8001,
17014 +    /* UPC.  */
17015 +    DW_LANG_Upc = 0x8765
17016 +  };
17017 +
17018 +#define DW_LANG_lo_user 0x8000 /* Implementation-defined range start.  */
17019 +#define DW_LANG_hi_user 0xffff /* Implementation-defined range start.  */
17020 +
17021 +/* Names and codes for macro information.  */
17022 +enum dwarf_macinfo_record_type
17023 +  {
17024 +    DW_MACINFO_define = 1,
17025 +    DW_MACINFO_undef = 2,
17026 +    DW_MACINFO_start_file = 3,
17027 +    DW_MACINFO_end_file = 4,
17028 +    DW_MACINFO_vendor_ext = 255
17029 +  };
17030 +\f
17031 +/* @@@ For use with GNU frame unwind information.  */
17032 +
17033 +#define DW_EH_PE_absptr                0x00
17034 +#define DW_EH_PE_omit          0xff
17035 +
17036 +#define DW_EH_PE_uleb128       0x01
17037 +#define DW_EH_PE_udata2                0x02
17038 +#define DW_EH_PE_udata4                0x03
17039 +#define DW_EH_PE_udata8                0x04
17040 +#define DW_EH_PE_sleb128       0x09
17041 +#define DW_EH_PE_sdata2                0x0A
17042 +#define DW_EH_PE_sdata4                0x0B
17043 +#define DW_EH_PE_sdata8                0x0C
17044 +#define DW_EH_PE_signed                0x08
17045 +
17046 +#define DW_EH_PE_pcrel         0x10
17047 +#define DW_EH_PE_textrel       0x20
17048 +#define DW_EH_PE_datarel       0x30
17049 +#define DW_EH_PE_funcrel       0x40
17050 +#define DW_EH_PE_aligned       0x50
17051 +
17052 +#define DW_EH_PE_indirect      0x80
17053 +
17054 +#endif /* _ELF_DWARF2_H */
17055 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/linux/kgdb.h linux-2.6.18.kgdb/include/linux/kgdb.h
17056 --- linux-2.6.18/include/linux/kgdb.h   1970-01-01 03:00:00.000000000 +0300
17057 +++ linux-2.6.18.kgdb/include/linux/kgdb.h      2008-06-10 16:20:11.000000000 +0400
17058 @@ -0,0 +1,279 @@
17059 +/*
17060 + * include/linux/kgdb.h
17061 + *
17062 + * This provides the hooks and functions that KGDB needs to share between
17063 + * the core, I/O and arch-specific portions.
17064 + *
17065 + * Author: Amit Kale <amitkale@linsyssoft.com> and
17066 + *         Tom Rini <trini@kernel.crashing.org>
17067 + *
17068 + * 2001-2004 (c) Amit S. Kale and 2003-2005 (c) MontaVista Software, Inc.
17069 + * This file is licensed under the terms of the GNU General Public License
17070 + * version 2. This program is licensed "as is" without any warranty of any
17071 + * kind, whether express or implied.
17072 + */
17073 +#ifdef __KERNEL__
17074 +#ifndef _KGDB_H_
17075 +#define _KGDB_H_
17076 +
17077 +#include <asm/atomic.h>
17078 +
17079 +#ifdef CONFIG_KGDB
17080 +#include <asm/kgdb.h>
17081 +#include <linux/serial_8250.h>
17082 +#include <linux/linkage.h>
17083 +#include <linux/init.h>
17084 +
17085 +#ifndef CHECK_EXCEPTION_STACK
17086 +#define CHECK_EXCEPTION_STACK()        1
17087 +#endif
17088 +
17089 +struct tasklet_struct;
17090 +struct pt_regs;
17091 +struct task_struct;
17092 +struct uart_port;
17093 +
17094 +#ifdef CONFIG_KGDB_CONSOLE
17095 +extern struct console kgdbcons;
17096 +#endif
17097 +
17098 +/* To enter the debugger explicitly. */
17099 +extern void breakpoint(void);
17100 +extern int kgdb_connected;
17101 +extern int kgdb_may_fault;
17102 +extern struct tasklet_struct kgdb_tasklet_breakpoint;
17103 +
17104 +extern atomic_t kgdb_setting_breakpoint;
17105 +extern atomic_t cpu_doing_single_step;
17106 +extern atomic_t kgdb_sync_softlockup[NR_CPUS];
17107 +
17108 +extern struct task_struct *kgdb_usethread, *kgdb_contthread;
17109 +
17110 +enum kgdb_bptype {
17111 +       bp_breakpoint = '0',
17112 +       bp_hardware_breakpoint,
17113 +       bp_write_watchpoint,
17114 +       bp_read_watchpoint,
17115 +       bp_access_watchpoint
17116 +};
17117 +
17118 +enum kgdb_bpstate {
17119 +       bp_none = 0,
17120 +       bp_removed,
17121 +       bp_set,
17122 +       bp_active
17123 +};
17124 +
17125 +struct kgdb_bkpt {
17126 +       unsigned long bpt_addr;
17127 +       unsigned char saved_instr[BREAK_INSTR_SIZE];
17128 +       enum kgdb_bptype type;
17129 +       enum kgdb_bpstate state;
17130 +};
17131 +
17132 +/* The maximum number of KGDB I/O modules that can be loaded */
17133 +#define MAX_KGDB_IO_HANDLERS 3
17134 +
17135 +#ifndef MAX_BREAKPOINTS
17136 +#define MAX_BREAKPOINTS                1000
17137 +#endif
17138 +
17139 +#define KGDB_HW_BREAKPOINT     1
17140 +
17141 +/* Required functions. */
17142 +/**
17143 + *     regs_to_gdb_regs - Convert ptrace regs to GDB regs
17144 + *     @gdb_regs: A pointer to hold the registers in the order GDB wants.
17145 + *     @regs: The &struct pt_regs of the current process.
17146 + *
17147 + *     Convert the pt_regs in @regs into the format for registers that
17148 + *     GDB expects, stored in @gdb_regs.
17149 + */
17150 +extern void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs);
17151 +
17152 +/**
17153 + *     sleeping_regs_to_gdb_regs - Convert ptrace regs to GDB regs
17154 + *     @gdb_regs: A pointer to hold the registers in the order GDB wants.
17155 + *     @p: The &struct task_struct of the desired process.
17156 + *
17157 + *     Convert the register values of the sleeping process in @p to
17158 + *     the format that GDB expects.
17159 + *     This function is called when kgdb does not have access to the
17160 + *     &struct pt_regs and therefore it should fill the gdb registers
17161 + *     @gdb_regs with what has been saved in &struct thread_struct
17162 + *     thread field during switch_to.
17163 + */
17164 +extern void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs,
17165 +                                       struct task_struct *p);
17166 +
17167 +/**
17168 + *     gdb_regs_to_regs - Convert GDB regs to ptrace regs.
17169 + *     @gdb_regs: A pointer to hold the registers we've recieved from GDB.
17170 + *     @regs: A pointer to a &struct pt_regs to hold these values in.
17171 + *
17172 + *     Convert the GDB regs in @gdb_regs into the pt_regs, and store them
17173 + *     in @regs.
17174 + */
17175 +extern void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs);
17176 +
17177 +/**
17178 + *     kgdb_arch_handle_exception - Handle architecture specific GDB packets.
17179 + *     @vector: The error vector of the exception that happened.
17180 + *     @signo: The signal number of the exception that happened.
17181 + *     @err_code: The error code of the exception that happened.
17182 + *     @remcom_in_buffer: The buffer of the packet we have read.
17183 + *     @remcom_out_buffer: The buffer, of %BUFMAX to write a packet into.
17184 + *     @regs: The &struct pt_regs of the current process.
17185 + *
17186 + *     This function MUST handle the 'c' and 's' command packets,
17187 + *     as well packets to set / remove a hardware breakpoint, if used.
17188 + *     If there are additional packets which the hardware needs to handle,
17189 + *     they are handled here.  The code should return -1 if it wants to
17190 + *     process more packets, and a %0 or %1 if it wants to exit from the
17191 + *     kgdb hook.
17192 + */
17193 +extern int kgdb_arch_handle_exception(int vector, int signo, int err_code,
17194 +                                     char *remcom_in_buffer,
17195 +                                     char *remcom_out_buffer,
17196 +                                     struct pt_regs *regs);
17197 +
17198 +#ifndef JMP_REGS_ALIGNMENT
17199 +#define JMP_REGS_ALIGNMENT
17200 +#endif
17201 +
17202 +extern unsigned long kgdb_fault_jmp_regs[];
17203 +
17204 +/**
17205 + *     kgdb_fault_setjmp - Store state in case we fault.
17206 + *     @curr_context: An array to store state into.
17207 + *
17208 + *     Certain functions may try and access memory, and in doing so may
17209 + *     cause a fault.  When this happens, we trap it, restore state to
17210 + *     this call, and let ourself know that something bad has happened.
17211 + */
17212 +extern asmlinkage int kgdb_fault_setjmp(unsigned long *curr_context);
17213 +
17214 +/**
17215 + *     kgdb_fault_longjmp - Restore state when we have faulted.
17216 + *     @curr_context: The previously stored state.
17217 + *
17218 + *     When something bad does happen, this function is called to
17219 + *     restore the known good state, and set the return value to 1, so
17220 + *     we know something bad happened.
17221 + */
17222 +extern asmlinkage void kgdb_fault_longjmp(unsigned long *curr_context);
17223 +
17224 +/* Optional functions. */
17225 +extern int kgdb_arch_init(void);
17226 +extern void kgdb_disable_hw_debug(struct pt_regs *regs);
17227 +extern void kgdb_post_master_code(struct pt_regs *regs, int e_vector,
17228 +                                 int err_code);
17229 +extern void kgdb_roundup_cpus(unsigned long flags);
17230 +extern int kgdb_set_hw_break(unsigned long addr);
17231 +extern int kgdb_remove_hw_break(unsigned long addr);
17232 +extern void kgdb_remove_all_hw_break(void);
17233 +extern void kgdb_correct_hw_break(void);
17234 +extern void kgdb_shadowinfo(struct pt_regs *regs, char *buffer,
17235 +                           unsigned threadid);
17236 +extern struct task_struct *kgdb_get_shadow_thread(struct pt_regs *regs,
17237 +                                                 int threadid);
17238 +extern struct pt_regs *kgdb_shadow_regs(struct pt_regs *regs, int threadid);
17239 +extern int kgdb_validate_break_address(unsigned long addr);
17240 +extern int kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr);
17241 +extern int kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle);
17242 +
17243 +/**
17244 + * struct kgdb_arch - Desribe architecture specific values.
17245 + * @gdb_bpt_instr: The instruction to trigger a breakpoint.
17246 + * @flags: Flags for the breakpoint, currently just %KGDB_HW_BREAKPOINT.
17247 + * @shadowth: A value of %1 indicates we shadow information on processes.
17248 + * @set_breakpoint: Allow an architecture to specify how to set a software
17249 + * breakpoint.
17250 + * @remove_breakpoint: Allow an architecture to specify how to remove a
17251 + * software breakpoint.
17252 + * @set_hw_breakpoint: Allow an architecture to specify how to set a hardware
17253 + * breakpoint.
17254 + * @remove_hw_breakpoint: Allow an architecture to specify how to remove a
17255 + * hardware breakpoint.
17256 + *
17257 + * The @shadowth flag is an option to shadow information not retrievable by
17258 + * gdb otherwise.  This is deprecated in favor of a binutils which supports
17259 + * CFI macros.
17260 + */
17261 +struct kgdb_arch {
17262 +       unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
17263 +       unsigned long flags;
17264 +       unsigned shadowth;
17265 +       int (*set_breakpoint) (unsigned long, char *);
17266 +       int (*remove_breakpoint)(unsigned long, char *);
17267 +       int (*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
17268 +       int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
17269 +};
17270 +
17271 +/* Thread reference */
17272 +typedef unsigned char threadref[8];
17273 +
17274 +/**
17275 + * struct kgdb_io - Desribe the interface for an I/O driver to talk with KGDB.
17276 + * @read_char: Pointer to a function that will return one char.
17277 + * @write_char: Pointer to a function that will write one char.
17278 + * @flush: Pointer to a function that will flush any pending writes.
17279 + * @init: Pointer to a function that will initialize the device.
17280 + * @late_init: Pointer to a function that will do any setup that has
17281 + * other dependencies.
17282 + * @pre_exception: Pointer to a function that will do any prep work for
17283 + * the I/O driver.
17284 + * @post_exception: Pointer to a function that will do any cleanup work
17285 + * for the I/O driver.
17286 + *
17287 + * The @init and @late_init function pointers allow for an I/O driver
17288 + * such as a serial driver to fully initialize the port with @init and
17289 + * be called very early, yet safely call request_irq() later in the boot
17290 + * sequence.
17291 + *
17292 + * @init is allowed to return a non-0 return value to indicate failure.
17293 + * If this is called early on, then KGDB will try again when it would call
17294 + * @late_init.  If it has failed later in boot as well, the user will be
17295 + * notified.
17296 + */
17297 +struct kgdb_io {
17298 +       int (*read_char) (void);
17299 +       void (*write_char) (u8);
17300 +       void (*flush) (void);
17301 +       int (*init) (void);
17302 +       void (*late_init) (void);
17303 +       void (*pre_exception) (void);
17304 +       void (*post_exception) (void);
17305 +};
17306 +
17307 +extern struct kgdb_io kgdb_io_ops;
17308 +extern struct kgdb_arch arch_kgdb_ops;
17309 +extern int kgdb_initialized;
17310 +
17311 +extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
17312 +extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
17313 +
17314 +extern void __init kgdb8250_add_port(int i, struct uart_port *serial_req);
17315 +extern void __init kgdb8250_add_platform_port(int i, struct plat_serial8250_port *serial_req);
17316 +
17317 +extern int kgdb_hex2long(char **ptr, long *long_val);
17318 +extern char *kgdb_mem2hex(char *mem, char *buf, int count);
17319 +extern char *kgdb_hex2mem(char *buf, char *mem, int count);
17320 +extern int kgdb_get_mem(char *addr, unsigned char *buf, int count);
17321 +extern int kgdb_set_mem(char *addr, unsigned char *buf, int count);
17322 +
17323 +int kgdb_isremovedbreak(unsigned long addr);
17324 +int kgdb_skipexception(int exception, struct pt_regs *regs);
17325 +
17326 +extern int kgdb_handle_exception(int ex_vector, int signo, int err_code,
17327 +                               struct pt_regs *regs);
17328 +extern void kgdb_nmihook(int cpu, void *regs);
17329 +extern int debugger_step;
17330 +extern atomic_t debugger_active;
17331 +extern struct kgdb_arch *kgdb_ops;
17332 +#else
17333 +/* Stubs for when KGDB is not set. */
17334 +static const atomic_t debugger_active = ATOMIC_INIT(0);
17335 +#endif                         /* CONFIG_KGDB */
17336 +#endif                         /* _KGDB_H_ */
17337 +#endif                         /* __KERNEL__ */
17338 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/linux/module.h linux-2.6.18.kgdb/include/linux/module.h
17339 --- linux-2.6.18/include/linux/module.h 2006-09-20 07:42:06.000000000 +0400
17340 +++ linux-2.6.18.kgdb/include/linux/module.h    2008-06-10 16:20:07.000000000 +0400
17341 @@ -224,8 +224,17 @@ enum module_state
17342         MODULE_STATE_LIVE,
17343         MODULE_STATE_COMING,
17344         MODULE_STATE_GOING,
17345 +       MODULE_STATE_GONE,
17346  };
17347  
17348 +#ifdef CONFIG_KGDB
17349 +#define MAX_SECTNAME 31
17350 +struct mod_section {
17351 +       void *address;
17352 +       char name[MAX_SECTNAME + 1];
17353 +};
17354 +#endif
17355 +
17356  /* Similar stuff for section attributes. */
17357  #define MODULE_SECT_NAME_LEN 32
17358  struct module_sect_attr
17359 @@ -253,6 +262,13 @@ struct module
17360         /* Unique handle for this module */
17361         char name[MODULE_NAME_LEN];
17362  
17363 +#ifdef CONFIG_KGDB
17364 +       /* keep kgdb info at the begining so that gdb doesn't have a chance to
17365 +        * miss out any fields */
17366 +       unsigned long num_sections;
17367 +       struct mod_section *mod_sections;
17368 +#endif
17369 +
17370         /* Sysfs stuff. */
17371         struct module_kobject mkobj;
17372         struct module_param_attrs *param_attrs;
17373 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/linux/netpoll.h linux-2.6.18.kgdb/include/linux/netpoll.h
17374 --- linux-2.6.18/include/linux/netpoll.h        2006-09-20 07:42:06.000000000 +0400
17375 +++ linux-2.6.18.kgdb/include/linux/netpoll.h   2008-06-10 16:19:07.000000000 +0400
17376 @@ -17,7 +17,7 @@ struct netpoll;
17377  struct netpoll {
17378         struct net_device *dev;
17379         char dev_name[16], *name;
17380 -       void (*rx_hook)(struct netpoll *, int, char *, int);
17381 +       void (*rx_hook)(struct netpoll *, int, char *, int, struct sk_buff *);
17382         void (*drop)(struct sk_buff *skb);
17383         u32 local_ip, remote_ip;
17384         u16 local_port, remote_port;
17385 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/include/linux/serial_8250.h linux-2.6.18.kgdb/include/linux/serial_8250.h
17386 --- linux-2.6.18/include/linux/serial_8250.h    2006-09-20 07:42:06.000000000 +0400
17387 +++ linux-2.6.18.kgdb/include/linux/serial_8250.h       2008-06-10 16:19:03.000000000 +0400
17388 @@ -56,6 +56,7 @@ struct uart_port;
17389  
17390  int serial8250_register_port(struct uart_port *);
17391  void serial8250_unregister_port(int line);
17392 +void serial8250_unregister_by_port(struct uart_port *port);
17393  void serial8250_suspend_port(int line);
17394  void serial8250_resume_port(int line);
17395  
17396 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/kernel/Makefile linux-2.6.18.kgdb/kernel/Makefile
17397 --- linux-2.6.18/kernel/Makefile        2006-09-20 07:42:06.000000000 +0400
17398 +++ linux-2.6.18.kgdb/kernel/Makefile   2008-06-10 16:18:58.000000000 +0400
17399 @@ -42,6 +42,7 @@ obj-$(CONFIG_STOP_MACHINE) += stop_machi
17400  obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
17401  obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
17402  obj-$(CONFIG_KPROBES) += kprobes.o
17403 +obj-$(CONFIG_KGDB) += kgdb.o kgdbarchlib.o
17404  obj-$(CONFIG_SYSFS) += ksysfs.o
17405  obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
17406  obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
17407 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/kernel/kgdb.c linux-2.6.18.kgdb/kernel/kgdb.c
17408 --- linux-2.6.18/kernel/kgdb.c  1970-01-01 03:00:00.000000000 +0300
17409 +++ linux-2.6.18.kgdb/kernel/kgdb.c     2008-06-10 16:20:11.000000000 +0400
17410 @@ -0,0 +1,1778 @@
17411 +/*
17412 + * kernel/kgdb.c
17413 + *
17414 + * Maintainer: Tom Rini <trini@kernel.crashing.org>
17415 + *
17416 + * Copyright (C) 2000-2001 VERITAS Software Corporation.
17417 + * Copyright (C) 2002-2004 Timesys Corporation
17418 + * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com>
17419 + * Copyright (C) 2004 Pavel Machek <pavel@suse.cz>
17420 + * Copyright (C) 2004-2005 Tom Rini <trini@kernel.crashing.org>
17421 + * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd.
17422 + * Copyright (C) 2005 Wind River Systems, Inc.
17423 + *
17424 + * Contributors at various stages not listed above:
17425 + *  Jason Wessel ( jason.wessel@windriver.com )
17426 + *  George Anzinger <george@mvista.com>
17427 + *  Anurekh Saxena (anurekh.saxena@timesys.com)
17428 + *  Lake Stevens Instrument Division (Glenn Engel)
17429 + *  Jim Kingdon, Cygnus Support.
17430 + *
17431 + * Original KGDB stub: David Grothe <dave@gcom.com>,
17432 + * Tigran Aivazian <tigran@sco.com>
17433 + *
17434 + * This file is licensed under the terms of the GNU General Public License
17435 + * version 2. This program is licensed "as is" without any warranty of any
17436 + * kind, whether express or implied.
17437 + */
17438 +
17439 +#include <linux/string.h>
17440 +#include <linux/kernel.h>
17441 +#include <linux/interrupt.h>
17442 +#include <linux/sched.h>
17443 +#include <linux/smp.h>
17444 +#include <linux/spinlock.h>
17445 +#include <linux/delay.h>
17446 +#include <linux/mm.h>
17447 +#include <linux/threads.h>
17448 +#include <linux/reboot.h>
17449 +#include <asm/system.h>
17450 +#include <asm/ptrace.h>
17451 +#include <asm/uaccess.h>
17452 +#include <linux/kgdb.h>
17453 +#include <asm/atomic.h>
17454 +#include <linux/notifier.h>
17455 +#include <linux/module.h>
17456 +#include <asm/cacheflush.h>
17457 +#include <linux/init.h>
17458 +#include <linux/sysrq.h>
17459 +#include <linux/console.h>
17460 +#include <linux/sched.h>
17461 +#include <asm/byteorder.h>
17462 +
17463 +extern int pid_max;
17464 +/* How many times to count all of the waiting CPUs */
17465 +#define ROUNDUP_WAIT           640000  /* Arbitrary, increase if needed. */
17466 +#define BUF_THREAD_ID_SIZE     16
17467 +
17468 +/*
17469 + * kgdb_initialized with a value of 1 indicates that kgdb is setup and is
17470 + * all ready to serve breakpoints and other kernel exceptions.  A value of
17471 + * -1 indicates that we have tried to initialize early, and need to try
17472 + * again later.
17473 + */
17474 +int kgdb_initialized;
17475 +/* Is a host GDB connected to us? */
17476 +int kgdb_connected;
17477 +/* Could we be about to try and access a bad memory location? If so we
17478 + * also need to flag this has happend. */
17479 +int kgdb_may_fault;
17480 +/* All the KGDB handlers are installed */
17481 +int kgdb_from_module_registered = 0;
17482 +
17483 +/* We provide a kgdb_io_ops structure that may be overriden. */
17484 +struct kgdb_io __attribute__ ((weak)) kgdb_io_ops;
17485 +
17486 +static struct kgdb_io kgdb_io_ops_prev[MAX_KGDB_IO_HANDLERS];
17487 +static int kgdb_io_handler_cnt = 0;
17488 +
17489 +/* Export the following symbols for use with kernel modules */
17490 +EXPORT_SYMBOL(kgdb_io_ops);
17491 +EXPORT_SYMBOL(kgdb_tasklet_breakpoint);
17492 +EXPORT_SYMBOL(kgdb_connected);
17493 +EXPORT_SYMBOL(kgdb_register_io_module);
17494 +EXPORT_SYMBOL(kgdb_unregister_io_module);
17495 +EXPORT_SYMBOL(debugger_active);
17496 +
17497 +/*
17498 + * Holds information about breakpoints in a kernel. These breakpoints are
17499 + * added and removed by gdb.
17500 + */
17501 +struct kgdb_bkpt kgdb_break[MAX_BREAKPOINTS];
17502 +
17503 +static const char hexchars[] = "0123456789abcdef";
17504 +
17505 +static spinlock_t slavecpulocks[NR_CPUS];
17506 +static atomic_t procindebug[NR_CPUS];
17507 +atomic_t kgdb_setting_breakpoint;
17508 +EXPORT_SYMBOL(kgdb_setting_breakpoint);
17509 +struct task_struct *kgdb_usethread, *kgdb_contthread;
17510 +
17511 +int debugger_step;
17512 +atomic_t debugger_active;
17513 +
17514 +/* Our I/O buffers. */
17515 +static char remcom_in_buffer[BUFMAX];
17516 +static char remcom_out_buffer[BUFMAX];
17517 +/* Storage for the registers, in GDB format. */
17518 +static unsigned long gdb_regs[(NUMREGBYTES + sizeof(unsigned long) - 1) /
17519 +                             sizeof(unsigned long)];
17520 +/* Storage of registers for handling a fault. */
17521 +unsigned long kgdb_fault_jmp_regs[NUMCRITREGBYTES / sizeof(unsigned long)]
17522 + JMP_REGS_ALIGNMENT;
17523 +static int kgdb_notify_reboot(struct notifier_block *this,
17524 +                               unsigned long code ,void *x);
17525 +struct debuggerinfo_struct {
17526 +       void *debuggerinfo;
17527 +       struct task_struct *task;
17528 +} kgdb_info[NR_CPUS];
17529 +
17530 +/* to keep track of the CPU which is doing the single stepping*/
17531 +atomic_t cpu_doing_single_step = ATOMIC_INIT(-1);
17532 +
17533 +atomic_t  kgdb_sync_softlockup[NR_CPUS] = {ATOMIC_INIT(0)};
17534 +
17535 +/* reboot notifier block */
17536 +static struct notifier_block kgdb_reboot_notifier = {
17537 +       .notifier_call  = kgdb_notify_reboot,
17538 +       .next           = NULL,
17539 +       .priority       = INT_MAX,
17540 +};
17541 +
17542 +static int hex(char ch)
17543 +{
17544 +       if ((ch >= 'a') && (ch <= 'f'))
17545 +               return (ch - 'a' + 10);
17546 +       if ((ch >= '0') && (ch <= '9'))
17547 +               return (ch - '0');
17548 +       if ((ch >= 'A') && (ch <= 'F'))
17549 +               return (ch - 'A' + 10);
17550 +       return (-1);
17551 +}
17552 +
17553 +/* scan for the sequence $<data>#<checksum>    */
17554 +static void get_packet(char *buffer)
17555 +{
17556 +       unsigned char checksum;
17557 +       unsigned char xmitcsum;
17558 +       int count;
17559 +       char ch;
17560 +       if (!kgdb_io_ops.read_char)
17561 +               return;
17562 +       do {
17563 +               /* Spin and wait around for the start character, ignore all
17564 +                * other characters */
17565 +               while ((ch = (kgdb_io_ops.read_char())) != '$') ;
17566 +               kgdb_connected = 1;
17567 +               checksum = 0;
17568 +               xmitcsum = -1;
17569 +
17570 +               count = 0;
17571 +
17572 +               /* now, read until a # or end of buffer is found */
17573 +               while (count < (BUFMAX - 1)) {
17574 +                       ch = kgdb_io_ops.read_char();
17575 +                       if (ch == '#')
17576 +                               break;
17577 +                       checksum = checksum + ch;
17578 +                       buffer[count] = ch;
17579 +                       count = count + 1;
17580 +               }
17581 +               buffer[count] = 0;
17582 +
17583 +               if (ch == '#') {
17584 +                       xmitcsum = hex(kgdb_io_ops.read_char()) << 4;
17585 +                       xmitcsum += hex(kgdb_io_ops.read_char());
17586 +
17587 +                       if (checksum != xmitcsum)
17588 +                               /* failed checksum */
17589 +                               kgdb_io_ops.write_char('-');
17590 +                       else
17591 +                               /* successful transfer */
17592 +                               kgdb_io_ops.write_char('+');
17593 +                       if (kgdb_io_ops.flush)
17594 +                               kgdb_io_ops.flush();
17595 +               }
17596 +       } while (checksum != xmitcsum);
17597 +}
17598 +
17599 +/*
17600 + * Send the packet in buffer.
17601 + * Check for gdb connection if asked for.
17602 + */
17603 +static void put_packet(char *buffer)
17604 +{
17605 +       unsigned char checksum;
17606 +       int count;
17607 +       char ch;
17608 +
17609 +       if (!kgdb_io_ops.write_char)
17610 +               return;
17611 +       /* $<packet info>#<checksum>. */
17612 +       while (1) {
17613 +               kgdb_io_ops.write_char('$');
17614 +               checksum = 0;
17615 +               count = 0;
17616 +
17617 +               while ((ch = buffer[count])) {
17618 +                       kgdb_io_ops.write_char(ch);
17619 +                       checksum += ch;
17620 +                       count++;
17621 +               }
17622 +
17623 +               kgdb_io_ops.write_char('#');
17624 +               kgdb_io_ops.write_char(hexchars[checksum >> 4]);
17625 +               kgdb_io_ops.write_char(hexchars[checksum % 16]);
17626 +               if (kgdb_io_ops.flush)
17627 +                       kgdb_io_ops.flush();
17628 +
17629 +               /* Now see what we get in reply. */
17630 +               ch = kgdb_io_ops.read_char();
17631 +
17632 +               if (ch == 3)
17633 +                       ch = kgdb_io_ops.read_char();
17634 +
17635 +               /* If we get an ACK, we are done. */
17636 +               if (ch == '+')
17637 +                       return;
17638 +
17639 +               /* If we get the start of another packet, this means
17640 +                * that GDB is attempting to reconnect.  We will NAK
17641 +                * the packet being sent, and stop trying to send this
17642 +                * packet. */
17643 +               if (ch == '$') {
17644 +                       kgdb_io_ops.write_char('-');
17645 +                       if (kgdb_io_ops.flush)
17646 +                               kgdb_io_ops.flush();
17647 +                       return;
17648 +               }
17649 +       }
17650 +}
17651 +
17652 +/*
17653 + * convert the memory pointed to by mem into hex, placing result in buf
17654 + * return a pointer to the last char put in buf (null). May return an error.
17655 + */
17656 +char *kgdb_mem2hex(char *mem, char *buf, int count)
17657 +{
17658 +       kgdb_may_fault = 1;
17659 +       if ((kgdb_fault_setjmp(kgdb_fault_jmp_regs)) != 0) {
17660 +               kgdb_may_fault = 0;
17661 +               return ERR_PTR(-EINVAL);
17662 +       }
17663 +       /* Accessing some registers in a single load instruction is
17664 +        * required to avoid bad side effects for some I/O registers.
17665 +        */
17666 +       if ((count == 2) && (((long)mem & 1) == 0)) {
17667 +               unsigned short tmp_s = *(unsigned short *)mem;
17668 +               mem += 2;
17669 +#ifdef __BIG_ENDIAN
17670 +               *buf++ = hexchars[(tmp_s >> 12) & 0xf];
17671 +               *buf++ = hexchars[(tmp_s >> 8) & 0xf];
17672 +               *buf++ = hexchars[(tmp_s >> 4) & 0xf];
17673 +               *buf++ = hexchars[tmp_s & 0xf];
17674 +#else
17675 +               *buf++ = hexchars[(tmp_s >> 4) & 0xf];
17676 +               *buf++ = hexchars[tmp_s & 0xf];
17677 +               *buf++ = hexchars[(tmp_s >> 12) & 0xf];
17678 +               *buf++ = hexchars[(tmp_s >> 8) & 0xf];
17679 +#endif
17680 +       } else if ((count == 4) && (((long)mem & 3) == 0)) {
17681 +               unsigned long tmp_l = *(unsigned int *)mem;
17682 +               mem += 4;
17683 +#ifdef __BIG_ENDIAN
17684 +               *buf++ = hexchars[(tmp_l >> 28) & 0xf];
17685 +               *buf++ = hexchars[(tmp_l >> 24) & 0xf];
17686 +               *buf++ = hexchars[(tmp_l >> 20) & 0xf];
17687 +               *buf++ = hexchars[(tmp_l >> 16) & 0xf];
17688 +               *buf++ = hexchars[(tmp_l >> 12) & 0xf];
17689 +               *buf++ = hexchars[(tmp_l >> 8) & 0xf];
17690 +               *buf++ = hexchars[(tmp_l >> 4) & 0xf];
17691 +               *buf++ = hexchars[tmp_l & 0xf];
17692 +#else
17693 +               *buf++ = hexchars[(tmp_l >> 4) & 0xf];
17694 +               *buf++ = hexchars[tmp_l & 0xf];
17695 +               *buf++ = hexchars[(tmp_l >> 12) & 0xf];
17696 +               *buf++ = hexchars[(tmp_l >> 8) & 0xf];
17697 +               *buf++ = hexchars[(tmp_l >> 20) & 0xf];
17698 +               *buf++ = hexchars[(tmp_l >> 16) & 0xf];
17699 +               *buf++ = hexchars[(tmp_l >> 28) & 0xf];
17700 +               *buf++ = hexchars[(tmp_l >> 24) & 0xf];
17701 +#endif
17702 +#ifdef CONFIG_64BIT
17703 +       } else if ((count == 8) && (((long)mem & 7) == 0)) {
17704 +               unsigned long long tmp_ll = *(unsigned long long *)mem;
17705 +               mem += 8;
17706 +#ifdef __BIG_ENDIAN
17707 +               *buf++ = hexchars[(tmp_ll >> 60) & 0xf];
17708 +               *buf++ = hexchars[(tmp_ll >> 56) & 0xf];
17709 +               *buf++ = hexchars[(tmp_ll >> 52) & 0xf];
17710 +               *buf++ = hexchars[(tmp_ll >> 48) & 0xf];
17711 +               *buf++ = hexchars[(tmp_ll >> 44) & 0xf];
17712 +               *buf++ = hexchars[(tmp_ll >> 40) & 0xf];
17713 +               *buf++ = hexchars[(tmp_ll >> 36) & 0xf];
17714 +               *buf++ = hexchars[(tmp_ll >> 32) & 0xf];
17715 +               *buf++ = hexchars[(tmp_ll >> 28) & 0xf];
17716 +               *buf++ = hexchars[(tmp_ll >> 24) & 0xf];
17717 +               *buf++ = hexchars[(tmp_ll >> 20) & 0xf];
17718 +               *buf++ = hexchars[(tmp_ll >> 16) & 0xf];
17719 +               *buf++ = hexchars[(tmp_ll >> 12) & 0xf];
17720 +               *buf++ = hexchars[(tmp_ll >> 8) & 0xf];
17721 +               *buf++ = hexchars[(tmp_ll >> 4) & 0xf];
17722 +               *buf++ = hexchars[tmp_ll & 0xf];
17723 +#else
17724 +               *buf++ = hexchars[(tmp_ll >> 4) & 0xf];
17725 +               *buf++ = hexchars[tmp_ll & 0xf];
17726 +               *buf++ = hexchars[(tmp_ll >> 12) & 0xf];
17727 +               *buf++ = hexchars[(tmp_ll >> 8) & 0xf];
17728 +               *buf++ = hexchars[(tmp_ll >> 20) & 0xf];
17729 +               *buf++ = hexchars[(tmp_ll >> 16) & 0xf];
17730 +               *buf++ = hexchars[(tmp_ll >> 28) & 0xf];
17731 +               *buf++ = hexchars[(tmp_ll >> 24) & 0xf];
17732 +               *buf++ = hexchars[(tmp_ll >> 36) & 0xf];
17733 +               *buf++ = hexchars[(tmp_ll >> 32) & 0xf];
17734 +               *buf++ = hexchars[(tmp_ll >> 44) & 0xf];
17735 +               *buf++ = hexchars[(tmp_ll >> 40) & 0xf];
17736 +               *buf++ = hexchars[(tmp_ll >> 52) & 0xf];
17737 +               *buf++ = hexchars[(tmp_ll >> 48) & 0xf];
17738 +               *buf++ = hexchars[(tmp_ll >> 60) & 0xf];
17739 +               *buf++ = hexchars[(tmp_ll >> 56) & 0xf];
17740 +#endif
17741 +#endif
17742 +       } else {
17743 +               while (count-- > 0) {
17744 +                       unsigned char ch = *mem++;
17745 +                       *buf++ = hexchars[ch >> 4];
17746 +                       *buf++ = hexchars[ch & 0xf];
17747 +               }
17748 +       }
17749 +       kgdb_may_fault = 0;
17750 +       *buf = 0;
17751 +       return (buf);
17752 +}
17753 +
17754 +/*
17755 + * Copy the binary array pointed to by buf into mem.  Fix $, #, and
17756 + * 0x7d escaped with 0x7d.  Return a pointer to the character after
17757 + * the last byte written.
17758 + */
17759 +static char *kgdb_ebin2mem(char *buf, char *mem, int count)
17760 +{
17761 +       kgdb_may_fault = 1;
17762 +       if ((kgdb_fault_setjmp(kgdb_fault_jmp_regs)) != 0) {
17763 +               kgdb_may_fault = 0;
17764 +               return ERR_PTR(-EINVAL);
17765 +       }
17766 +       for (; count > 0; count--, buf++) {
17767 +               if (*buf == 0x7d)
17768 +                       *mem++ = *(++buf) ^ 0x20;
17769 +               else
17770 +                       *mem++ = *buf;
17771 +       }
17772 +       kgdb_may_fault = 0;
17773 +       return mem;
17774 +}
17775 +
17776 +/*
17777 + * convert the hex array pointed to by buf into binary to be placed in mem
17778 + * return a pointer to the character AFTER the last byte written
17779 + * May return an error.
17780 + */
17781 +char *kgdb_hex2mem(char *buf, char *mem, int count)
17782 +{
17783 +       kgdb_may_fault = 1;
17784 +       if ((kgdb_fault_setjmp(kgdb_fault_jmp_regs)) != 0) {
17785 +               kgdb_may_fault = 0;
17786 +               return ERR_PTR(-EINVAL);
17787 +       }
17788 +       if ((count == 2) && (((long)mem & 1) == 0)) {
17789 +               unsigned short tmp_s = 0;
17790 +#ifdef __BIG_ENDIAN
17791 +               tmp_s |= hex(*buf++) << 12;
17792 +               tmp_s |= hex(*buf++) << 8;
17793 +               tmp_s |= hex(*buf++) << 4;
17794 +               tmp_s |= hex(*buf++);
17795 +#else
17796 +               tmp_s |= hex(*buf++) << 4;
17797 +               tmp_s |= hex(*buf++);
17798 +               tmp_s |= hex(*buf++) << 12;
17799 +               tmp_s |= hex(*buf++) << 8;
17800 +#endif
17801 +               *(unsigned short *)mem = tmp_s;
17802 +               mem += 2;
17803 +       } else if ((count == 4) && (((long)mem & 3) == 0)) {
17804 +               unsigned long tmp_l = 0;
17805 +#ifdef __BIG_ENDIAN
17806 +               tmp_l |= hex(*buf++) << 28;
17807 +               tmp_l |= hex(*buf++) << 24;
17808 +               tmp_l |= hex(*buf++) << 20;
17809 +               tmp_l |= hex(*buf++) << 16;
17810 +               tmp_l |= hex(*buf++) << 12;
17811 +               tmp_l |= hex(*buf++) << 8;
17812 +               tmp_l |= hex(*buf++) << 4;
17813 +               tmp_l |= hex(*buf++);
17814 +#else
17815 +               tmp_l |= hex(*buf++) << 4;
17816 +               tmp_l |= hex(*buf++);
17817 +               tmp_l |= hex(*buf++) << 12;
17818 +               tmp_l |= hex(*buf++) << 8;
17819 +               tmp_l |= hex(*buf++) << 20;
17820 +               tmp_l |= hex(*buf++) << 16;
17821 +               tmp_l |= hex(*buf++) << 28;
17822 +               tmp_l |= hex(*buf++) << 24;
17823 +#endif
17824 +               *(unsigned long *)mem = tmp_l;
17825 +               mem += 4;
17826 +       } else {
17827 +               int i;
17828 +               for (i = 0; i < count; i++) {
17829 +                       unsigned char ch = hex(*buf++) << 4;
17830 +                       ch |= hex(*buf++);
17831 +                       *mem++ = ch;
17832 +               }
17833 +       }
17834 +       kgdb_may_fault = 0;
17835 +       return (mem);
17836 +}
17837 +
17838 +/*
17839 + * While we find nice hex chars, build a long_val.
17840 + * Return number of chars processed.
17841 + */
17842 +int kgdb_hex2long(char **ptr, long *long_val)
17843 +{
17844 +       int hex_val, num = 0;
17845 +
17846 +       *long_val = 0;
17847 +
17848 +       while (**ptr) {
17849 +               hex_val = hex(**ptr);
17850 +               if (hex_val >= 0) {
17851 +                       *long_val = (*long_val << 4) | hex_val;
17852 +                       num++;
17853 +               } else
17854 +                       break;
17855 +
17856 +               (*ptr)++;
17857 +       }
17858 +
17859 +       return (num);
17860 +}
17861 +
17862 +/* Write memory due to an 'M' or 'X' packet. */
17863 +static char *write_mem_msg(int binary)
17864 +{
17865 +       char *ptr = &remcom_in_buffer[1];
17866 +       unsigned long addr, length;
17867 +
17868 +       if (kgdb_hex2long(&ptr, &addr) > 0 && *(ptr++) == ',' &&
17869 +           kgdb_hex2long(&ptr, &length) > 0 && *(ptr++) == ':') {
17870 +               if (binary)
17871 +                       ptr = kgdb_ebin2mem(ptr, (char *)addr, length);
17872 +               else
17873 +                       ptr = kgdb_hex2mem(ptr, (char *)addr, length);
17874 +               if (CACHE_FLUSH_IS_SAFE)
17875 +                       flush_icache_range(addr, addr + length + 1);
17876 +               if (IS_ERR(ptr))
17877 +                       return ptr;
17878 +               return NULL;
17879 +       }
17880 +
17881 +       return ERR_PTR(-EINVAL);
17882 +}
17883 +
17884 +static inline char *pack_hex_byte(char *pkt, int byte)
17885 +{
17886 +       *pkt++ = hexchars[(byte >> 4) & 0xf];
17887 +       *pkt++ = hexchars[(byte & 0xf)];
17888 +       return pkt;
17889 +}
17890 +
17891 +static inline void error_packet(char *pkt, int error)
17892 +{
17893 +       error = -error;
17894 +       pkt[0] = 'E';
17895 +       pkt[1] = hexchars[(error / 10)];
17896 +       pkt[2] = hexchars[(error % 10)];
17897 +       pkt[3] = '\0';
17898 +}
17899 +
17900 +static char *pack_threadid(char *pkt, threadref * id)
17901 +{
17902 +       char *limit;
17903 +       unsigned char *altid;
17904 +
17905 +       altid = (unsigned char *)id;
17906 +       limit = pkt + BUF_THREAD_ID_SIZE;
17907 +       while (pkt < limit)
17908 +               pkt = pack_hex_byte(pkt, *altid++);
17909 +
17910 +       return pkt;
17911 +}
17912 +
17913 +void int_to_threadref(threadref * id, int value)
17914 +{
17915 +       unsigned char *scan;
17916 +       int i = 4;
17917 +
17918 +       scan = (unsigned char *)id;
17919 +       while (i--)
17920 +               *scan++ = 0;
17921 +       *scan++ = (value >> 24) & 0xff;
17922 +       *scan++ = (value >> 16) & 0xff;
17923 +       *scan++ = (value >> 8) & 0xff;
17924 +       *scan++ = (value & 0xff);
17925 +}
17926 +
17927 +static struct task_struct *getthread(struct pt_regs *regs, int tid)
17928 +{
17929 +       if (last_pid == 0)
17930 +               return current;
17931 +
17932 +       if (num_online_cpus() &&
17933 +           (tid >= pid_max + num_online_cpus() + kgdb_ops->shadowth))
17934 +               return NULL;
17935 +
17936 +       if (kgdb_ops->shadowth && (tid >= pid_max + num_online_cpus()))
17937 +               return kgdb_get_shadow_thread(regs, tid - pid_max -
17938 +                                             num_online_cpus());
17939 +
17940 +       if (tid >= pid_max)
17941 +               return idle_task(tid - pid_max);
17942 +
17943 +       if (!tid)
17944 +               return NULL;
17945 +
17946 +       return find_task_by_pid(tid);
17947 +}
17948 +
17949 +#ifdef CONFIG_SMP
17950 +static void kgdb_wait(struct pt_regs *regs)
17951 +{
17952 +       unsigned long flags;
17953 +       int processor;
17954 +
17955 +       local_irq_save(flags);
17956 +       processor = smp_processor_id();
17957 +       kgdb_info[processor].debuggerinfo = regs;
17958 +       kgdb_info[processor].task = current;
17959 +       atomic_set(&procindebug[processor], 1);
17960 +       atomic_set(&kgdb_sync_softlockup[smp_processor_id()], 1);
17961 +
17962 +       /* Wait till master processor goes completely into the debugger.
17963 +        * FIXME: this looks racy */
17964 +       while (!atomic_read(&procindebug[atomic_read(&debugger_active) - 1])) {
17965 +               int i = 10;     /* an arbitrary number */
17966 +
17967 +               while (--i)
17968 +                       cpu_relax();
17969 +       }
17970 +
17971 +       /* Wait till master processor is done with debugging */
17972 +       spin_lock_nested(&slavecpulocks[processor], processor);
17973 +
17974 +       /* This has been taken from x86 kgdb implementation and
17975 +        * will be needed by architectures that have SMP support
17976 +        */
17977 +       kgdb_correct_hw_break();
17978 +
17979 +       kgdb_info[processor].debuggerinfo = NULL;
17980 +       kgdb_info[processor].task = NULL;
17981 +
17982 +       /* Signal the master processor that we are done */
17983 +       atomic_set(&procindebug[processor], 0);
17984 +       spin_unlock(&slavecpulocks[processor]);
17985 +       local_irq_restore(flags);
17986 +}
17987 +#endif
17988 +
17989 +int kgdb_get_mem(char *addr, unsigned char *buf, int count)
17990 +{
17991 +       kgdb_may_fault = 1;
17992 +       if ((kgdb_fault_setjmp(kgdb_fault_jmp_regs)) != 0) {
17993 +               kgdb_may_fault = 0;
17994 +               return -EINVAL;
17995 +       }
17996 +       while (count) {
17997 +               if ((unsigned long)addr < TASK_SIZE)
17998 +                       return -EINVAL;
17999 +               *buf++ = *addr++;
18000 +               count--;
18001 +       }
18002 +       kgdb_may_fault = 0;
18003 +       return 0;
18004 +}
18005 +
18006 +int kgdb_set_mem(char *addr, unsigned char *buf, int count)
18007 +{
18008 +       kgdb_may_fault = 1;
18009 +       if ((kgdb_fault_setjmp(kgdb_fault_jmp_regs)) != 0) {
18010 +               kgdb_may_fault = 0;
18011 +               return -EINVAL;
18012 +       }
18013 +       while (count) {
18014 +               if ((unsigned long)addr < TASK_SIZE)
18015 +                       return -EINVAL;
18016 +               *addr++ = *buf++;
18017 +               count--;
18018 +       }
18019 +       kgdb_may_fault = 0;
18020 +       return 0;
18021 +}
18022 +int kgdb_activate_sw_breakpoints(void)
18023 +{
18024 +       int i;
18025 +       int error = 0;
18026 +       unsigned long addr;
18027 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
18028 +               if (kgdb_break[i].state != bp_set)
18029 +                       continue;
18030 +               addr = kgdb_break[i].bpt_addr;
18031 +               if ((error = kgdb_arch_set_breakpoint(addr,
18032 +                                       kgdb_break[i].saved_instr)))
18033 +                       return error;
18034 +
18035 +               if (CACHE_FLUSH_IS_SAFE) {
18036 +                       if (current->mm && addr < TASK_SIZE)
18037 +                               flush_cache_range(current->mm->mmap_cache,
18038 +                                               addr, addr + BREAK_INSTR_SIZE);
18039 +                       else
18040 +                               flush_icache_range(addr, addr +
18041 +                                               BREAK_INSTR_SIZE);
18042 +               }
18043 +
18044 +               kgdb_break[i].state = bp_active;
18045 +        }
18046 +       return 0;
18047 +}
18048 +
18049 +static int kgdb_set_sw_break(unsigned long addr)
18050 +{
18051 +       int i, breakno = -1;
18052 +       int error = 0;
18053 +       if ((error = kgdb_validate_break_address(addr)) < 0)
18054 +               return error;
18055 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
18056 +               if ((kgdb_break[i].state == bp_set) &&
18057 +                       (kgdb_break[i].bpt_addr == addr))
18058 +                       return -EEXIST;
18059 +       }
18060 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
18061 +               if (kgdb_break[i].state == bp_removed &&
18062 +                               kgdb_break[i].bpt_addr == addr) {
18063 +                       breakno = i;
18064 +                       break;
18065 +               }
18066 +       }
18067 +
18068 +       if (breakno == -1) {
18069 +               for (i = 0; i < MAX_BREAKPOINTS; i++) {
18070 +                       if (kgdb_break[i].state == bp_none) {
18071 +                               breakno = i;
18072 +                               break;
18073 +                       }
18074 +               }
18075 +       }
18076 +       if (breakno == -1)
18077 +               return -E2BIG;
18078 +
18079 +       kgdb_break[breakno].state = bp_set;
18080 +       kgdb_break[breakno].type = bp_breakpoint;
18081 +       kgdb_break[breakno].bpt_addr = addr;
18082 +
18083 +       return 0;
18084 +}
18085 +
18086 +int kgdb_deactivate_sw_breakpoints(void)
18087 +{
18088 +       int i;
18089 +       int error = 0;
18090 +       unsigned long addr;
18091 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
18092 +               if (kgdb_break[i].state != bp_active)
18093 +                       continue;
18094 +               addr = kgdb_break[i].bpt_addr;
18095 +               if ((error = kgdb_arch_remove_breakpoint(addr,
18096 +                                       kgdb_break[i].saved_instr)))
18097 +                       return error;
18098 +
18099 +               if (CACHE_FLUSH_IS_SAFE && current->mm &&
18100 +                               addr < TASK_SIZE)
18101 +                       flush_cache_range(current->mm->mmap_cache,
18102 +                                       addr, addr + BREAK_INSTR_SIZE);
18103 +               else if (CACHE_FLUSH_IS_SAFE)
18104 +                       flush_icache_range(addr,
18105 +                                       addr + BREAK_INSTR_SIZE);
18106 +               kgdb_break[i].state = bp_set;
18107 +       }
18108 +       return 0;
18109 +}
18110 +
18111 +static int kgdb_remove_sw_break(unsigned long addr)
18112 +{
18113 +       int i;
18114 +
18115 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
18116 +               if ((kgdb_break[i].state == bp_set) &&
18117 +                       (kgdb_break[i].bpt_addr == addr)) {
18118 +                       kgdb_break[i].state = bp_removed;
18119 +                       return 0;
18120 +               }
18121 +       }
18122 +       return -ENOENT;
18123 +}
18124 +
18125 +int kgdb_isremovedbreak(unsigned long addr)
18126 +{
18127 +       int i;
18128 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
18129 +               if ((kgdb_break[i].state == bp_removed) &&
18130 +                       (kgdb_break[i].bpt_addr == addr)) {
18131 +                       return 1;
18132 +               }
18133 +       }
18134 +       return 0;
18135 +}
18136 +
18137 +int remove_all_break(void)
18138 +{
18139 +       int i;
18140 +       int error;
18141 +       unsigned long addr;
18142 +
18143 +       /* Clear memory breakpoints. */
18144 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
18145 +               if (kgdb_break[i].state != bp_set)
18146 +                       continue;
18147 +               addr = kgdb_break[i].bpt_addr;
18148 +               if ((error = kgdb_arch_remove_breakpoint(addr,
18149 +                                       kgdb_break[i].saved_instr)))
18150 +                       return error;
18151 +               kgdb_break[i].state = bp_removed;
18152 +       }
18153 +
18154 +       /* Clear hardware breakpoints. */
18155 +       kgdb_remove_all_hw_break();
18156 +
18157 +       return 0;
18158 +}
18159 +
18160 +static inline int shadow_pid(int realpid)
18161 +{
18162 +       if (realpid) {
18163 +               return realpid;
18164 +       }
18165 +       return pid_max + smp_processor_id();
18166 +}
18167 +
18168 +static char gdbmsgbuf[BUFMAX + 1];
18169 +static void kgdb_msg_write(const char *s, int len)
18170 +{
18171 +       int i;
18172 +       int wcount;
18173 +       char *bufptr;
18174 +
18175 +       /* 'O'utput */
18176 +       gdbmsgbuf[0] = 'O';
18177 +
18178 +       /* Fill and send buffers... */
18179 +       while (len > 0) {
18180 +               bufptr = gdbmsgbuf + 1;
18181 +
18182 +               /* Calculate how many this time */
18183 +               if ((len << 1) > (BUFMAX - 2))
18184 +                       wcount = (BUFMAX - 2) >> 1;
18185 +               else
18186 +                       wcount = len;
18187 +
18188 +               /* Pack in hex chars */
18189 +               for (i = 0; i < wcount; i++)
18190 +                       bufptr = pack_hex_byte(bufptr, s[i]);
18191 +               *bufptr = '\0';
18192 +
18193 +               /* Move up */
18194 +               s += wcount;
18195 +               len -= wcount;
18196 +
18197 +               /* Write packet */
18198 +               put_packet(gdbmsgbuf);
18199 +       }
18200 +}
18201 +
18202 +/*
18203 + * This function does all command procesing for interfacing to gdb.
18204 + *
18205 + * Locking hierarchy:
18206 + *     interface locks, if any (begin_session)
18207 + *     kgdb lock (debugger_active)
18208 + *
18209 + * Note that since we can be in here prior to our cpumask being filled
18210 + * out, we err on the side of caution and loop over NR_CPUS instead
18211 + * of a for_each_online_cpu.
18212 + *
18213 + */
18214 +int kgdb_handle_exception(int ex_vector, int signo, int err_code,
18215 +                         struct pt_regs *linux_regs)
18216 +{
18217 +       unsigned long length, addr;
18218 +       char *ptr;
18219 +       unsigned long flags;
18220 +       unsigned i;
18221 +       long threadid;
18222 +       threadref thref;
18223 +       struct task_struct *thread = NULL;
18224 +       unsigned procid;
18225 +       int numshadowth = num_online_cpus() + kgdb_ops->shadowth;
18226 +       long kgdb_usethreadid = 0;
18227 +       int error = 0, all_cpus_synced = 0;
18228 +       struct pt_regs *shadowregs;
18229 +       int processor = smp_processor_id();
18230 +       void *local_debuggerinfo;
18231 +
18232 +       /* Panic on recursive debugger calls. */
18233 +       if (atomic_read(&debugger_active) == smp_processor_id() + 1)
18234 +               return 0;
18235 +
18236 +      acquirelock:
18237 +
18238 +       /* Call the I/O drivers pre_exception routine if the I/O
18239 +        * driver defined one
18240 +        */
18241 +       if (kgdb_io_ops.pre_exception)
18242 +               kgdb_io_ops.pre_exception();
18243 +
18244 +       /*
18245 +        * Interrupts will be restored by the 'trap return' code, except when
18246 +        * single stepping.
18247 +        */
18248 +       local_irq_save(flags);
18249 +
18250 +       /* Hold debugger_active */
18251 +       procid = smp_processor_id();
18252 +
18253 +       while (cmpxchg(&atomic_read(&debugger_active), 0, (procid + 1)) != 0) {
18254 +               int i = 25;     /* an arbitrary number */
18255 +
18256 +               while (--i)
18257 +                       cpu_relax();
18258 +
18259 +               if (atomic_read(&cpu_doing_single_step) != -1 &&
18260 +                               atomic_read(&cpu_doing_single_step) != procid)
18261 +                       udelay(1);
18262 +       }
18263 +
18264 +       atomic_set(&kgdb_sync_softlockup[smp_processor_id()], 1);
18265 +
18266 +       /*
18267 +        * Don't enter if the last instance of the exception handler wanted to
18268 +        * come into the debugger again.
18269 +        */
18270 +       if (atomic_read(&cpu_doing_single_step) != -1 &&
18271 +           atomic_read(&cpu_doing_single_step) != procid) {
18272 +               atomic_set(&debugger_active, 0);
18273 +               local_irq_restore(flags);
18274 +               goto acquirelock;
18275 +       }
18276 +
18277 +       /*
18278 +       * Don't enter if we have hit a removed breakpoint.
18279 +       */
18280 +       if (kgdb_skipexception(ex_vector, linux_regs))
18281 +               goto kgdb_restore;
18282 +
18283 +       kgdb_info[processor].debuggerinfo = linux_regs;
18284 +       kgdb_info[processor].task = current;
18285 +
18286 +       kgdb_disable_hw_debug(linux_regs);
18287 +
18288 +       if (!debugger_step || !kgdb_contthread)
18289 +               for (i = 0; i < NR_CPUS; i++)
18290 +                       spin_lock_nested(&slavecpulocks[i], i);
18291 +
18292 +       /* Make sure we get the other CPUs */
18293 +       if (!debugger_step || !kgdb_contthread)
18294 +               kgdb_roundup_cpus(flags);
18295 +
18296 +       /* spin_lock code is good enough as a barrier so we don't
18297 +        * need one here */
18298 +       atomic_set(&procindebug[processor], 1);
18299 +
18300 +       /* Wait a reasonable time for the other CPUs to be notified and
18301 +        * be waiting for us.  Very early on this could be imperfect
18302 +        * as num_online_cpus() could be 0.*/
18303 +       for (i = 0; i < ROUNDUP_WAIT; i++) {
18304 +               int cpu, num = 0;
18305 +               for (cpu = 0; cpu < NR_CPUS; cpu++) {
18306 +                       if (atomic_read(&procindebug[cpu]))
18307 +                               num++;
18308 +               }
18309 +               if (num >= num_online_cpus()) {
18310 +                       all_cpus_synced = 1;
18311 +                       break;
18312 +               }
18313 +       }
18314 +
18315 +       /* Clear the out buffer. */
18316 +       memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer));
18317 +
18318 +       /* Master processor is completely in the debugger */
18319 +       kgdb_post_master_code(linux_regs, ex_vector, err_code);
18320 +       kgdb_deactivate_sw_breakpoints();
18321 +       debugger_step = 0;
18322 +       kgdb_contthread = NULL;
18323 +
18324 +       if (kgdb_connected) {
18325 +               /* If we're still unable to roundup all of the CPUs,
18326 +                * send an 'O' packet informing the user again. */
18327 +               if (!all_cpus_synced)
18328 +                       kgdb_msg_write("Not all CPUs have been synced for "
18329 +                                      "KGDB\n", 39);
18330 +               /* Reply to host that an exception has occurred */
18331 +               ptr = remcom_out_buffer;
18332 +               *ptr++ = 'T';
18333 +               *ptr++ = hexchars[(signo >> 4) % 16];
18334 +               *ptr++ = hexchars[signo % 16];
18335 +               ptr += strlen(strcpy(ptr, "thread:"));
18336 +               int_to_threadref(&thref, shadow_pid(current->pid));
18337 +               ptr = pack_threadid(ptr, &thref);
18338 +               *ptr++ = ';';
18339 +
18340 +               put_packet(remcom_out_buffer);
18341 +       }
18342 +
18343 +       kgdb_usethread = kgdb_info[processor].task;
18344 +       kgdb_usethreadid = shadow_pid(kgdb_info[processor].task->pid);
18345 +
18346 +       while (kgdb_io_ops.read_char) {
18347 +               char *bpt_type;
18348 +               error = 0;
18349 +
18350 +               /* Clear the out buffer. */
18351 +               memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer));
18352 +
18353 +               get_packet(remcom_in_buffer);
18354 +
18355 +               switch (remcom_in_buffer[0]) {
18356 +               case '?':
18357 +                       /* We know that this packet is only sent
18358 +                        * during initial connect.  So to be safe,
18359 +                        * we clear out our breakpoints now incase
18360 +                        * GDB is reconnecting. */
18361 +                       remove_all_break();
18362 +                       /* Also, if we haven't been able to roundup all
18363 +                        * CPUs, send an 'O' packet informing the user
18364 +                        * as much.  Only need to do this once. */
18365 +                       if (!all_cpus_synced)
18366 +                               kgdb_msg_write("Not all CPUs have been "
18367 +                                              "synced for KGDB\n", 39);
18368 +                       remcom_out_buffer[0] = 'S';
18369 +                       remcom_out_buffer[1] = hexchars[signo >> 4];
18370 +                       remcom_out_buffer[2] = hexchars[signo % 16];
18371 +                       break;
18372 +
18373 +               case 'g':       /* return the value of the CPU registers */
18374 +                       thread = kgdb_usethread;
18375 +
18376 +                       if (!thread) {
18377 +                               thread = kgdb_info[processor].task;
18378 +                               local_debuggerinfo =
18379 +                                   kgdb_info[processor].debuggerinfo;
18380 +                       } else {
18381 +                               local_debuggerinfo = NULL;
18382 +                               for (i = 0; i < NR_CPUS; i++) {
18383 +                                       /* Try to find the task on some other
18384 +                                        * or possibly this node if we do not
18385 +                                        * find the matching task then we try
18386 +                                        * to approximate the results.
18387 +                                        */
18388 +                                       if (thread == kgdb_info[i].task)
18389 +                                               local_debuggerinfo =
18390 +                                                   kgdb_info[i].debuggerinfo;
18391 +                               }
18392 +                       }
18393 +
18394 +                       /* All threads that don't have debuggerinfo should be
18395 +                        * in __schedule() sleeping, since all other CPUs
18396 +                        * are in kgdb_wait, and thus have debuggerinfo. */
18397 +                       if (kgdb_ops->shadowth &&
18398 +                           kgdb_usethreadid >= pid_max + num_online_cpus()) {
18399 +                               shadowregs = kgdb_shadow_regs(linux_regs,
18400 +                                                             kgdb_usethreadid -
18401 +                                                             pid_max -
18402 +                                                             num_online_cpus
18403 +                                                             ());
18404 +                               if (!shadowregs) {
18405 +                                       error_packet(remcom_out_buffer,
18406 +                                                    -EINVAL);
18407 +                                       break;
18408 +                               }
18409 +                               regs_to_gdb_regs(gdb_regs, shadowregs);
18410 +                       } else if (local_debuggerinfo)
18411 +                               regs_to_gdb_regs(gdb_regs, local_debuggerinfo);
18412 +                       else {
18413 +                               /* Pull stuff saved during
18414 +                                * switch_to; nothing else is
18415 +                                * accessible (or even particularly relevant).
18416 +                                * This should be enough for a stack trace. */
18417 +                               sleeping_thread_to_gdb_regs(gdb_regs, thread);
18418 +                       }
18419 +                       kgdb_mem2hex((char *)gdb_regs, remcom_out_buffer,
18420 +                                    NUMREGBYTES);
18421 +                       break;
18422 +
18423 +                       /* set the value of the CPU registers - return OK */
18424 +               case 'G':
18425 +                       kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs,
18426 +                                    NUMREGBYTES);
18427 +
18428 +                       if (kgdb_usethread && kgdb_usethread != current)
18429 +                               error_packet(remcom_out_buffer, -EINVAL);
18430 +                       else {
18431 +                               gdb_regs_to_regs(gdb_regs, linux_regs);
18432 +                               strcpy(remcom_out_buffer, "OK");
18433 +                       }
18434 +                       break;
18435 +
18436 +                       /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
18437 +               case 'm':
18438 +                       ptr = &remcom_in_buffer[1];
18439 +                       if (kgdb_hex2long(&ptr, &addr) > 0 && *ptr++ == ',' &&
18440 +                           kgdb_hex2long(&ptr, &length) > 0) {
18441 +                               if (IS_ERR(ptr = kgdb_mem2hex((char *)addr,
18442 +                                                             remcom_out_buffer,
18443 +                                                             length)))
18444 +                                       error_packet(remcom_out_buffer,
18445 +                                                    PTR_ERR(ptr));
18446 +                       } else
18447 +                               error_packet(remcom_out_buffer, -EINVAL);
18448 +                       break;
18449 +
18450 +                       /* MAA..AA,LLLL: Write LLLL bytes at address AA..AA */
18451 +               case 'M':
18452 +                       if (IS_ERR(ptr = write_mem_msg(0)))
18453 +                               error_packet(remcom_out_buffer, PTR_ERR(ptr));
18454 +                       else
18455 +                               strcpy(remcom_out_buffer, "OK");
18456 +                       break;
18457 +                       /* XAA..AA,LLLL: Write LLLL bytes at address AA..AA */
18458 +               case 'X':
18459 +                       if (IS_ERR(ptr = write_mem_msg(1)))
18460 +                               error_packet(remcom_out_buffer, PTR_ERR(ptr));
18461 +                       else
18462 +                               strcpy(remcom_out_buffer, "OK");
18463 +                       break;
18464 +
18465 +                       /* kill or detach. KGDB should treat this like a
18466 +                        * continue.
18467 +                        */
18468 +               case 'D':
18469 +                       if ((error = remove_all_break()) < 0) {
18470 +                               error_packet(remcom_out_buffer, error);
18471 +                       } else {
18472 +                               strcpy(remcom_out_buffer, "OK");
18473 +                               kgdb_connected = 0;
18474 +                       }
18475 +                       put_packet(remcom_out_buffer);
18476 +                       goto default_handle;
18477 +
18478 +               case 'k':
18479 +                       /* Don't care about error from remove_all_break */
18480 +                       remove_all_break();
18481 +                       kgdb_connected = 0;
18482 +                       goto default_handle;
18483 +
18484 +                       /* Reboot */
18485 +               case 'R':
18486 +                       /* For now, only honor R0 */
18487 +                       if (strcmp(remcom_in_buffer, "R0") == 0) {
18488 +                               printk(KERN_CRIT "Executing reboot\n");
18489 +                               strcpy(remcom_out_buffer, "OK");
18490 +                               put_packet(remcom_out_buffer);
18491 +                               emergency_sync();
18492 +                               /* Execution should not return from
18493 +                                * machine_restart()
18494 +                                */
18495 +                               machine_restart(NULL);
18496 +                               kgdb_connected = 0;
18497 +                               goto default_handle;
18498 +                       }
18499 +
18500 +                       /* query */
18501 +               case 'q':
18502 +                       switch (remcom_in_buffer[1]) {
18503 +                       case 's':
18504 +                       case 'f':
18505 +                               if (memcmp(remcom_in_buffer + 2, "ThreadInfo",
18506 +                                          10)) {
18507 +                                       error_packet(remcom_out_buffer,
18508 +                                                    -EINVAL);
18509 +                                       break;
18510 +                               }
18511 +
18512 +                               /*
18513 +                                * If we have not yet completed in
18514 +                                * pidhash_init() there isn't much we
18515 +                                * can give back.
18516 +                                */
18517 +                               if (last_pid == 0) {
18518 +                                       if (remcom_in_buffer[1] == 'f')
18519 +                                               strcpy(remcom_out_buffer,
18520 +                                                      "m0000000000000001");
18521 +                                       break;
18522 +                               }
18523 +
18524 +                               if (remcom_in_buffer[1] == 'f') {
18525 +                                       threadid = 1;
18526 +                               }
18527 +                               remcom_out_buffer[0] = 'm';
18528 +                               ptr = remcom_out_buffer + 1;
18529 +                               for (i = 0; i < 17 && threadid < pid_max +
18530 +                                    numshadowth; threadid++) {
18531 +                                       thread = getthread(linux_regs,
18532 +                                                          threadid);
18533 +                                       if (thread) {
18534 +                                               int_to_threadref(&thref,
18535 +                                                                threadid);
18536 +                                               pack_threadid(ptr, &thref);
18537 +                                               ptr += 16;
18538 +                                               *(ptr++) = ',';
18539 +                                               i++;
18540 +                                       }
18541 +                               }
18542 +                               *(--ptr) = '\0';
18543 +                               break;
18544 +
18545 +                       case 'C':
18546 +                               /* Current thread id */
18547 +                               strcpy(remcom_out_buffer, "QC");
18548 +
18549 +                               threadid = shadow_pid(current->pid);
18550 +
18551 +                               int_to_threadref(&thref, threadid);
18552 +                               pack_threadid(remcom_out_buffer + 2, &thref);
18553 +                               break;
18554 +                       case 'T':
18555 +                               if (memcmp(remcom_in_buffer + 1,
18556 +                                          "ThreadExtraInfo,", 16)) {
18557 +                                       error_packet(remcom_out_buffer,
18558 +                                                    -EINVAL);
18559 +                                       break;
18560 +                               }
18561 +                               threadid = 0;
18562 +                               ptr = remcom_in_buffer + 17;
18563 +                               kgdb_hex2long(&ptr, &threadid);
18564 +                               if (!getthread(linux_regs, threadid)) {
18565 +                                       error_packet(remcom_out_buffer,
18566 +                                                    -EINVAL);
18567 +                                       break;
18568 +                               }
18569 +                               if (threadid < pid_max) {
18570 +                                       kgdb_mem2hex(getthread(linux_regs,
18571 +                                                              threadid)->comm,
18572 +                                                    remcom_out_buffer, 16);
18573 +                               } else if (threadid >= pid_max +
18574 +                                          num_online_cpus()) {
18575 +                                       kgdb_shadowinfo(linux_regs,
18576 +                                                       remcom_out_buffer,
18577 +                                                       threadid - pid_max -
18578 +                                                       num_online_cpus());
18579 +                               } else {
18580 +                                       static char tmpstr[23 +
18581 +                                                          BUF_THREAD_ID_SIZE];
18582 +                                       sprintf(tmpstr, "Shadow task %d"
18583 +                                               " for pid 0",
18584 +                                               (int)(threadid - pid_max));
18585 +                                       kgdb_mem2hex(tmpstr, remcom_out_buffer,
18586 +                                                    strlen(tmpstr));
18587 +                               }
18588 +                               break;
18589 +                       }
18590 +                       break;
18591 +
18592 +                       /* task related */
18593 +               case 'H':
18594 +                       switch (remcom_in_buffer[1]) {
18595 +                       case 'g':
18596 +                               ptr = &remcom_in_buffer[2];
18597 +                               kgdb_hex2long(&ptr, &threadid);
18598 +                               thread = getthread(linux_regs, threadid);
18599 +                               if (!thread && threadid > 0) {
18600 +                                       error_packet(remcom_out_buffer,
18601 +                                                    -EINVAL);
18602 +                                       break;
18603 +                               }
18604 +                               kgdb_usethread = thread;
18605 +                               kgdb_usethreadid = threadid;
18606 +                               strcpy(remcom_out_buffer, "OK");
18607 +                               break;
18608 +
18609 +                       case 'c':
18610 +                               ptr = &remcom_in_buffer[2];
18611 +                               kgdb_hex2long(&ptr, &threadid);
18612 +                               if (!threadid) {
18613 +                                       kgdb_contthread = NULL;
18614 +                               } else {
18615 +                                       thread = getthread(linux_regs,
18616 +                                                          threadid);
18617 +                                       if (!thread && threadid > 0) {
18618 +                                               error_packet(remcom_out_buffer,
18619 +                                                            -EINVAL);
18620 +                                               break;
18621 +                                       }
18622 +                                       kgdb_contthread = thread;
18623 +                               }
18624 +                               strcpy(remcom_out_buffer, "OK");
18625 +                               break;
18626 +                       }
18627 +                       break;
18628 +
18629 +                       /* Query thread status */
18630 +               case 'T':
18631 +                       ptr = &remcom_in_buffer[1];
18632 +                       kgdb_hex2long(&ptr, &threadid);
18633 +                       thread = getthread(linux_regs, threadid);
18634 +                       if (thread)
18635 +                               strcpy(remcom_out_buffer, "OK");
18636 +                       else
18637 +                               error_packet(remcom_out_buffer, -EINVAL);
18638 +                       break;
18639 +               /* Since GDB-5.3, it's been drafted that '0' is a software
18640 +                * breakpoint, '1' is a hardware breakpoint, so let's do
18641 +                * that.
18642 +                */
18643 +               case 'z':
18644 +               case 'Z':
18645 +                       bpt_type = &remcom_in_buffer[1];
18646 +                       ptr = &remcom_in_buffer[2];
18647 +
18648 +                       if (kgdb_ops->set_hw_breakpoint && *bpt_type >= '1') {
18649 +                               /* Unsupported */
18650 +                               if (*bpt_type > '4')
18651 +                                       break;
18652 +                       } else if (*bpt_type != '0' && *bpt_type != '1')
18653 +                               /* Unsupported. */
18654 +                               break;
18655 +                       /* Test if this is a hardware breakpoint, and
18656 +                        * if we support it. */
18657 +                       if (*bpt_type == '1' &&
18658 +                           !kgdb_ops->flags & KGDB_HW_BREAKPOINT)
18659 +                               /* Unsupported. */
18660 +                               break;
18661 +
18662 +                       if (*(ptr++) != ',') {
18663 +                               error_packet(remcom_out_buffer, -EINVAL);
18664 +                               break;
18665 +                       } else if (kgdb_hex2long(&ptr, &addr)) {
18666 +                               if (*(ptr++) != ',' ||
18667 +                                   !kgdb_hex2long(&ptr, &length)) {
18668 +                                       error_packet(remcom_out_buffer,
18669 +                                                    -EINVAL);
18670 +                                       break;
18671 +                               }
18672 +                       } else {
18673 +                               error_packet(remcom_out_buffer, -EINVAL);
18674 +                               break;
18675 +                       }
18676 +
18677 +                       if (remcom_in_buffer[0] == 'Z' && *bpt_type == '0')
18678 +                               error = kgdb_set_sw_break(addr);
18679 +                       else if (remcom_in_buffer[0] == 'Z' && *bpt_type == '1')
18680 +                               error = kgdb_set_hw_break(addr);
18681 +                       else if (remcom_in_buffer[0] == 'z' && *bpt_type == '0')
18682 +                               error = kgdb_remove_sw_break(addr);
18683 +                       else if (remcom_in_buffer[0] == 'z' && *bpt_type == '1')
18684 +                               error = kgdb_remove_hw_break(addr);
18685 +                       else if (remcom_in_buffer[0] == 'Z')
18686 +                               error = kgdb_ops->set_hw_breakpoint(addr,
18687 +                                                                   (int)length,
18688 +                                                                   *bpt_type);
18689 +                       else if (remcom_in_buffer[0] == 'z')
18690 +                               error = kgdb_ops->remove_hw_breakpoint(addr,
18691 +                                                                      (int)
18692 +                                                                      length,
18693 +                                                                      *bpt_type);
18694 +
18695 +                       if (error == 0)
18696 +                               strcpy(remcom_out_buffer, "OK");
18697 +                       else
18698 +                               error_packet(remcom_out_buffer, error);
18699 +
18700 +                       break;
18701 +               case 'c':
18702 +               case 's':
18703 +                       if (kgdb_contthread && kgdb_contthread != current) {
18704 +                               /* Can't switch threads in kgdb */
18705 +                               error_packet(remcom_out_buffer, -EINVAL);
18706 +                               break;
18707 +                       }
18708 +                       kgdb_activate_sw_breakpoints();
18709 +                       /* Followthrough to default processing */
18710 +               default:
18711 +                     default_handle:
18712 +                       error = kgdb_arch_handle_exception(ex_vector, signo,
18713 +                                                          err_code,
18714 +                                                          remcom_in_buffer,
18715 +                                                          remcom_out_buffer,
18716 +                                                          linux_regs);
18717 +
18718 +                       if (error >= 0 || remcom_in_buffer[0] == 'D' ||
18719 +                           remcom_in_buffer[0] == 'k')
18720 +                               goto kgdb_exit;
18721 +
18722 +               }               /* switch */
18723 +
18724 +               /* reply to the request */
18725 +               put_packet(remcom_out_buffer);
18726 +       }
18727 +
18728 +      kgdb_exit:
18729 +       /* Call the I/O driver's post_exception routine if the I/O
18730 +        * driver defined one.
18731 +        */
18732 +       if (kgdb_io_ops.post_exception)
18733 +               kgdb_io_ops.post_exception();
18734 +
18735 +       kgdb_info[processor].debuggerinfo = NULL;
18736 +       kgdb_info[processor].task = NULL;
18737 +       atomic_set(&procindebug[processor], 0);
18738 +
18739 +       if (!debugger_step || !kgdb_contthread) {
18740 +               for (i = 0; i < NR_CPUS; i++)
18741 +                       spin_unlock(&slavecpulocks[i]);
18742 +               /* Wait till all the processors have quit
18743 +                * from the debugger. */
18744 +               for (i = 0; i < NR_CPUS; i++) {
18745 +                       while (atomic_read(&procindebug[i])) {
18746 +                               int j = 10;     /* an arbitrary number */
18747 +
18748 +                               while (--j)
18749 +                                       cpu_relax();
18750 +                       }
18751 +               }
18752 +       }
18753 +
18754 +#ifdef CONFIG_SMP
18755 +       /* This delay has a real purpose.  The problem is that if you
18756 +        * are single-stepping, you are sending an NMI to all the
18757 +        * other processors to stop them.  Interrupts come in, but
18758 +        * don't get handled.  Then you let them go just long enough
18759 +        * to get into their interrupt routines and use up some stack.
18760 +        * You stop them again, and then do the same thing.  After a
18761 +        * while you blow the stack on the other processors.  This
18762 +        * delay gives some time for interrupts to be cleared out on
18763 +        * the other processors.
18764 +        */
18765 +       if (debugger_step)
18766 +               mdelay(2);
18767 +#endif
18768 +kgdb_restore:
18769 +       /* Free debugger_active */
18770 +       atomic_set(&debugger_active, 0);
18771 +       local_irq_restore(flags);
18772 +
18773 +       return error;
18774 +}
18775 +
18776 +/*
18777 + * GDB places a breakpoint at this function to know dynamically
18778 + * loaded objects. It's not defined static so that only one instance with this
18779 + * name exists in the kernel.
18780 + */
18781 +
18782 +int module_event(struct notifier_block *self, unsigned long val, void *data)
18783 +{
18784 +       return 0;
18785 +}
18786 +
18787 +static struct notifier_block kgdb_module_load_nb = {
18788 +       .notifier_call = module_event,
18789 +};
18790 +
18791 +void kgdb_nmihook(int cpu, void *regs)
18792 +{
18793 +#ifdef CONFIG_SMP
18794 +       if (!atomic_read(&procindebug[cpu]) && atomic_read(&debugger_active) != (cpu + 1))
18795 +               kgdb_wait((struct pt_regs *)regs);
18796 +#endif
18797 +}
18798 +
18799 +/*
18800 + * This is called when a panic happens.  All we need to do is
18801 + * breakpoint().
18802 + */
18803 +static int kgdb_panic_notify(struct notifier_block *self, unsigned long cmd,
18804 +                            void *ptr)
18805 +{
18806 +       breakpoint();
18807 +
18808 +       return 0;
18809 +}
18810 +
18811 +static struct notifier_block kgdb_panic_notifier = {
18812 +       .notifier_call = kgdb_panic_notify,
18813 +};
18814 +
18815 +/*
18816 + * Initialization that needs to be done in either of our entry points.
18817 + */
18818 +static void __init kgdb_internal_init(void)
18819 +{
18820 +       int i;
18821 +
18822 +       /* Initialize our spinlocks. */
18823 +       for (i = 0; i < NR_CPUS; i++)
18824 +               spin_lock_init(&slavecpulocks[i]);
18825 +
18826 +       for (i = 0; i < MAX_BREAKPOINTS; i++)
18827 +               kgdb_break[i].state = bp_none;
18828 +
18829 +       /* Initialize the I/O handles */
18830 +       memset(&kgdb_io_ops_prev, 0, sizeof(kgdb_io_ops_prev));
18831 +
18832 +       /* We can't do much if this fails */
18833 +       register_module_notifier(&kgdb_module_load_nb);
18834 +
18835 +       kgdb_initialized = 1;
18836 +}
18837 +
18838 +static void kgdb_register_for_panic(void)
18839 +{
18840 +       /* Register for panics(). */
18841 +       /* The registration is done in the kgdb_register_for_panic
18842 +        * routine because KGDB should not try to handle a panic when
18843 +        * there are no kgdb_io_ops setup. It is assumed that the
18844 +        * kgdb_io_ops are setup at the time this method is called.
18845 +        */
18846 +       if (!kgdb_from_module_registered) {
18847 +               atomic_notifier_chain_register(&panic_notifier_list,
18848 +                                       &kgdb_panic_notifier);
18849 +               kgdb_from_module_registered = 1;
18850 +       }
18851 +}
18852 +
18853 +static void kgdb_unregister_for_panic(void)
18854 +{
18855 +       /* When this routine is called KGDB should unregister from the
18856 +        * panic handler and clean up, making sure it is not handling any
18857 +        * break exceptions at the time.
18858 +        */
18859 +       if (kgdb_from_module_registered) {
18860 +               kgdb_from_module_registered = 0;
18861 +               atomic_notifier_chain_unregister(&panic_notifier_list,
18862 +                                         &kgdb_panic_notifier);
18863 +       }
18864 +}
18865 +
18866 +int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops)
18867 +{
18868 +
18869 +       if (kgdb_connected) {
18870 +               printk(KERN_ERR "kgdb: Cannot load I/O module while KGDB "
18871 +                      "connected.\n");
18872 +               return -EINVAL;
18873 +       }
18874 +
18875 +       /* Save the old values so they can be restored */
18876 +       if (kgdb_io_handler_cnt >= MAX_KGDB_IO_HANDLERS) {
18877 +               printk(KERN_ERR "kgdb: No more I/O handles available.\n");
18878 +               return -EINVAL;
18879 +       }
18880 +
18881 +       /* Check to see if there is an existing driver and if so save its
18882 +        * values.  Also check to make sure the same driver was not trying
18883 +        * to re-register.
18884 +        */
18885 +       if (kgdb_io_ops.read_char != NULL &&
18886 +        kgdb_io_ops.read_char != local_kgdb_io_ops->read_char) {
18887 +               memcpy(&kgdb_io_ops_prev[kgdb_io_handler_cnt],
18888 +                      &kgdb_io_ops, sizeof(struct kgdb_io));
18889 +               kgdb_io_handler_cnt++;
18890 +       }
18891 +
18892 +       /* Initialize the io values for this module */
18893 +       memcpy(&kgdb_io_ops, local_kgdb_io_ops, sizeof(struct kgdb_io));
18894 +
18895 +       /* Make the call to register kgdb if is not initialized */
18896 +       kgdb_register_for_panic();
18897 +
18898 +       return 0;
18899 +}
18900 +
18901 +void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops)
18902 +{
18903 +       int i;
18904 +
18905 +       /* Unregister KGDB if there were no other prior io hooks, else
18906 +        * restore the io hooks.
18907 +        */
18908 +       if (kgdb_io_handler_cnt > 0 && kgdb_io_ops_prev[0].read_char != NULL) {
18909 +               /* First check if the hook that is in use is the one being
18910 +                * removed */
18911 +               if (kgdb_io_ops.read_char == local_kgdb_io_ops->read_char) {
18912 +                       /* Set 'i' to the value of where the list should be
18913 +                        * shifed */
18914 +                       i = kgdb_io_handler_cnt - 1;
18915 +                       memcpy(&kgdb_io_ops, &kgdb_io_ops_prev[i],
18916 +                              sizeof(struct kgdb_io));
18917 +               } else {
18918 +                       /* Simple case to remove an entry for an I/O handler
18919 +                        * that is not in use */
18920 +                       for (i = 0; i < kgdb_io_handler_cnt; i++) {
18921 +                               if (kgdb_io_ops_prev[i].read_char ==
18922 +                                   local_kgdb_io_ops->read_char)
18923 +                                       break;
18924 +                       }
18925 +               }
18926 +
18927 +               /* Shift all the entries in the handler array so it is
18928 +                * ordered from oldest to newest.
18929 +                */
18930 +               kgdb_io_handler_cnt--;
18931 +               for (; i < kgdb_io_handler_cnt; i++) {
18932 +                       memcpy(&kgdb_io_ops_prev[i], &kgdb_io_ops_prev[i + 1],
18933 +                              sizeof(struct kgdb_io));
18934 +               }
18935 +               /* Handle the case if we are on the last element and set it
18936 +                * to NULL; */
18937 +               memset(&kgdb_io_ops_prev[kgdb_io_handler_cnt], 0,
18938 +                               sizeof(struct kgdb_io));
18939 +
18940 +               if (kgdb_connected)
18941 +                       printk(KERN_ERR "kgdb: WARNING: I/O method changed "
18942 +                              "while kgdb was connected state.\n");
18943 +       } else {
18944 +               /* KGDB is no longer able to communicate out, so
18945 +                * unregister our hooks and reset state. */
18946 +               kgdb_unregister_for_panic();
18947 +               if (kgdb_connected) {
18948 +                       printk(KERN_CRIT "kgdb: I/O module was unloaded while "
18949 +                                       "a debugging session was running.  "
18950 +                                       "KGDB will be reset.\n");
18951 +                       if (remove_all_break() < 0)
18952 +                               printk(KERN_CRIT "kgdb: Reset failed.\n");
18953 +                       kgdb_connected = 0;
18954 +               }
18955 +               memset(&kgdb_io_ops, 0, sizeof(struct kgdb_io));
18956 +       }
18957 +}
18958 +
18959 +/*
18960 + * There are times we need to call a tasklet to cause a breakpoint
18961 + * as calling breakpoint() at that point might be fatal.  We have to
18962 + * check that the exception stack is setup, as tasklets may be scheduled
18963 + * prior to this.  When that happens, it is up to the architecture to
18964 + * schedule this when it is safe to run.
18965 + */
18966 +static void kgdb_tasklet_bpt(unsigned long ing)
18967 +{
18968 +       if(CHECK_EXCEPTION_STACK())
18969 +               breakpoint();
18970 +}
18971 +
18972 +DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
18973 +
18974 +/*
18975 + * This function can be called very early, either via early_param() or
18976 + * an explicit breakpoint() early on.
18977 + */
18978 +static void __init kgdb_early_entry(void)
18979 +{
18980 +       /*
18981 +        * Don't try and do anything until the architecture is able to
18982 +        * setup the exception stack.  In this case, it is up to the
18983 +        * architecture to hook in and look at us when they are ready.
18984 +        */
18985 +       if(!CHECK_EXCEPTION_STACK()) {
18986 +               kgdb_initialized = -1;
18987 +               tasklet_schedule(&kgdb_tasklet_breakpoint);
18988 +               return;
18989 +       }
18990 +
18991 +       /* Let the architecture do any setup that it needs to. */
18992 +       kgdb_arch_init();
18993 +
18994 +       /* Now try the I/O. */
18995 +       /* For early entry kgdb_io_ops.init must be defined */
18996 +       if (!kgdb_io_ops.init || kgdb_io_ops.init()) {
18997 +               /* Try again later. */
18998 +               kgdb_initialized = -1;
18999 +               return;
19000 +       }
19001 +
19002 +       /* Finish up. */
19003 +       kgdb_internal_init();
19004 +
19005 +       /* KGDB can assume that if kgdb_io_ops.init was defined that the
19006 +        * panic registion should be performed at this time. This means
19007 +        * kgdb_io_ops.init did not come from a kernel module and was
19008 +        * initialized statically by a built in.
19009 +        */
19010 +       if (kgdb_io_ops.init)
19011 +               kgdb_register_for_panic();
19012 +}
19013 +
19014 +/*
19015 + * This function will always be invoked to make sure that KGDB will grab
19016 + * what it needs to so that if something happens while the system is
19017 + * running, KGDB will get involved.  If kgdb_early_entry() has already
19018 + * been invoked, there is little we need to do.
19019 + */
19020 +static int __init kgdb_late_entry(void)
19021 +{
19022 +       int need_break = 0;
19023 +
19024 +       /* If kgdb_initialized is -1 then we were passed kgdbwait. */
19025 +       if (kgdb_initialized == -1)
19026 +               need_break = 1;
19027 +
19028 +       /*
19029 +        * If we haven't tried to initialize KGDB yet, we need to call
19030 +        * kgdb_arch_init before moving onto the I/O.
19031 +        */
19032 +       if (!kgdb_initialized)
19033 +               kgdb_arch_init();
19034 +
19035 +       if (kgdb_initialized != 1) {
19036 +               if (kgdb_io_ops.init && kgdb_io_ops.init()) {
19037 +                       /* When KGDB allows I/O via modules and the core
19038 +                        * I/O init fails KGDB must default to defering the
19039 +                        * I/O setup, and appropriately print an error about
19040 +                        * it.
19041 +                        */
19042 +                       printk(KERN_ERR "kgdb: Could not setup core I/O "
19043 +                              "for KGDB.\n");
19044 +                       printk(KERN_INFO "kgdb: Defering I/O setup to kernel "
19045 +                              "module.\n");
19046 +                       memset(&kgdb_io_ops, 0, sizeof(struct kgdb_io));
19047 +               }
19048 +
19049 +               kgdb_internal_init();
19050 +
19051 +               /* KGDB can assume that if kgdb_io_ops.init was defined that
19052 +                * panic registion should be performed at this time. This means
19053 +                * kgdb_io_ops.init did not come from a kernel module and was
19054 +                * initialized statically by a built in.
19055 +                */
19056 +               if (kgdb_io_ops.init)
19057 +                       kgdb_register_for_panic();
19058 +       }
19059 +
19060 +       /* Registering to reboot notifier list*/
19061 +       register_reboot_notifier(&kgdb_reboot_notifier);
19062 +
19063 +       /* Now do any late init of the I/O. */
19064 +       if (kgdb_io_ops.late_init)
19065 +               kgdb_io_ops.late_init();
19066 +
19067 +       if (need_break) {
19068 +               printk(KERN_CRIT "kgdb: Waiting for connection from remote"
19069 +                      " gdb...\n");
19070 +               breakpoint();
19071 +       }
19072 +
19073 +       return 0;
19074 +}
19075 +
19076 +late_initcall(kgdb_late_entry);
19077 +
19078 +/*
19079 + * This function will generate a breakpoint exception.  It is used at the
19080 + * beginning of a program to sync up with a debugger and can be used
19081 + * otherwise as a quick means to stop program execution and "break" into
19082 + * the debugger.
19083 + */
19084 +void breakpoint(void)
19085 +{
19086 +       if (kgdb_initialized != 1) {
19087 +               kgdb_early_entry();
19088 +               if (kgdb_initialized == 1)
19089 +                       printk(KERN_CRIT "Waiting for connection from remote "
19090 +                              "gdb...\n");
19091 +               else {
19092 +                       printk(KERN_CRIT "KGDB cannot initialize I/O yet.\n");
19093 +                       return;
19094 +               }
19095 +       }
19096 +
19097 +       atomic_set(&kgdb_setting_breakpoint, 1);
19098 +       wmb();
19099 +       BREAKPOINT();
19100 +       wmb();
19101 +       atomic_set(&kgdb_setting_breakpoint, 0);
19102 +}
19103 +
19104 +EXPORT_SYMBOL(breakpoint);
19105 +
19106 +#ifdef CONFIG_MAGIC_SYSRQ
19107 +static void sysrq_handle_gdb(int key, struct pt_regs *pt_regs,
19108 +                            struct tty_struct *tty)
19109 +{
19110 +       printk("Entering GDB stub\n");
19111 +       breakpoint();
19112 +}
19113 +static struct sysrq_key_op sysrq_gdb_op = {
19114 +       .handler = sysrq_handle_gdb,
19115 +       .help_msg = "Gdb",
19116 +       .action_msg = "GDB",
19117 +};
19118 +
19119 +static int gdb_register_sysrq(void)
19120 +{
19121 +       printk("Registering GDB sysrq handler\n");
19122 +       register_sysrq_key('g', &sysrq_gdb_op);
19123 +       return 0;
19124 +}
19125 +
19126 +module_init(gdb_register_sysrq);
19127 +#endif
19128 +
19129 +static int kgdb_notify_reboot(struct notifier_block *this,
19130 +                            unsigned long code, void *x)
19131 +{
19132 +
19133 +       unsigned long flags;
19134 +
19135 +       /* If we're debugging, or KGDB has not connected, don't try
19136 +        * and print. */
19137 +       if (!kgdb_connected || atomic_read(&debugger_active) != 0)
19138 +               return 0;
19139 +       if ((code == SYS_RESTART) || (code == SYS_HALT) || (code == SYS_POWER_OFF)){
19140 +               local_irq_save(flags);
19141 +               put_packet("X00");
19142 +               local_irq_restore(flags);
19143 +       }
19144 +       return NOTIFY_DONE;
19145 +}
19146 +
19147 +#ifdef CONFIG_KGDB_CONSOLE
19148 +void kgdb_console_write(struct console *co, const char *s, unsigned count)
19149 +{
19150 +       unsigned long flags;
19151 +
19152 +       /* If we're debugging, or KGDB has not connected, don't try
19153 +        * and print. */
19154 +       if (!kgdb_connected || atomic_read(&debugger_active) != 0)
19155 +               return;
19156 +
19157 +       local_irq_save(flags);
19158 +       kgdb_msg_write(s, count);
19159 +       local_irq_restore(flags);
19160 +}
19161 +
19162 +struct console kgdbcons = {
19163 +       .name = "kgdb",
19164 +       .write = kgdb_console_write,
19165 +       .flags = CON_PRINTBUFFER | CON_ENABLED,
19166 +};
19167 +static int __init kgdb_console_init(void)
19168 +{
19169 +       register_console(&kgdbcons);
19170 +       return 0;
19171 +}
19172 +
19173 +console_initcall(kgdb_console_init);
19174 +#endif
19175 +
19176 +static int __init opt_kgdb_enter(char *str)
19177 +{
19178 +       /* We've already done this by an explicit breakpoint() call. */
19179 +       if (kgdb_initialized)
19180 +               return 0;
19181 +
19182 +       /* Call breakpoint() which will take care of init. */
19183 +       breakpoint();
19184 +
19185 +       return 0;
19186 +}
19187 +
19188 +early_param("kgdbwait", opt_kgdb_enter);
19189 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/kernel/kgdbarchlib.c linux-2.6.18.kgdb/kernel/kgdbarchlib.c
19190 --- linux-2.6.18/kernel/kgdbarchlib.c   1970-01-01 03:00:00.000000000 +0300
19191 +++ linux-2.6.18.kgdb/kernel/kgdbarchlib.c      2008-06-10 16:18:58.000000000 +0400
19192 @@ -0,0 +1,198 @@
19193 +#include <linux/kgdb.h>
19194 +
19195 +struct kgdb_arch *kgdb_ops = &arch_kgdb_ops;
19196 +
19197 +/**
19198 + *     kgdb_arch_init - Perform any architecture specific initalization.
19199 + *
19200 + *     RETURN:
19201 + *     The return value is ignored.
19202 + *
19203 + *     This function will handle the initalization of any architecture
19204 + *     specific hooks.
19205 + */
19206 +int __attribute__ ((weak))
19207 +    kgdb_arch_init(void)
19208 +{
19209 +       return 0;
19210 +}
19211 +
19212 +/**
19213 + *     kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.
19214 + *     @regs: Current &struct pt_regs.
19215 + *
19216 + *     This function will be called if the particular architecture must
19217 + *     disable hardware debugging while it is processing gdb packets or
19218 + *     handling exception.
19219 + */
19220 +void __attribute__ ((weak))
19221 +    kgdb_disable_hw_debug(struct pt_regs *regs)
19222 +{
19223 +}
19224 +
19225 +/*
19226 + * Skip an int3 exception when it occurs after a breakpoint has been
19227 + * removed. Backtrack eip by 1 since the int3 would have caused it to
19228 + * increment by 1.
19229 + */
19230 +int __attribute__ ((weak))
19231 +       kgdb_skipexception(int exception, struct pt_regs *regs)
19232 +{
19233 +       return 0;
19234 +}
19235 +
19236 +/**
19237 + *     kgdb_set_hw_break - Set a hardware breakpoint at @addr.
19238 + *     @addr: The address to set a hardware breakpoint at.
19239 + */
19240 +int __attribute__ ((weak))
19241 +    kgdb_set_hw_break(unsigned long addr)
19242 +{
19243 +       return 0;
19244 +}
19245 +
19246 +/**
19247 + *     kgdb_remove_hw_break - Remove a hardware breakpoint at @addr.
19248 + *     @addr: The address to remove a hardware breakpoint from.
19249 + */
19250 +int __attribute__ ((weak))
19251 +    kgdb_remove_hw_break(unsigned long addr)
19252 +{
19253 +       return 0;
19254 +}
19255 +
19256 +/**
19257 + *     kgdb_remove_all_hw_break - Clear all hardware breakpoints.
19258 + */
19259 +void __attribute__ ((weak))
19260 +    kgdb_remove_all_hw_break(void)
19261 +{
19262 +}
19263 +
19264 +/**
19265 + *     kgdb_correct_hw_break - Correct hardware breakpoints.
19266 + *
19267 + *     A hook to allow for changes to the hardware breakpoint, called
19268 + *     after a single step (s) or continue (c) packet, and once we're about
19269 + *     to let the kernel continue running.
19270 + *
19271 + *     This is used to set the hardware breakpoint registers for all the
19272 + *     slave cpus on an SMP configuration. This must be called after any
19273 + *     changes are made to the hardware breakpoints (such as by a single
19274 + *     step (s) or continue (c) packet. This is only required on
19275 + *     architectures that support SMP and every processor has its own set
19276 + *     of breakpoint registers.
19277 + */
19278 +void __attribute__ ((weak))
19279 +    kgdb_correct_hw_break(void)
19280 +{
19281 +}
19282 +
19283 +/**
19284 + *     kgdb_post_master_code - Save error vector/code numbers.
19285 + *     @regs: Original pt_regs.
19286 + *     @e_vector: Original error vector.
19287 + *     @err_code: Original error code.
19288 + *
19289 + *     This is needed on architectures which support SMP and KGDB.
19290 + *     This function is called after all the slave cpus have been put
19291 + *     to a know spin state and the master CPU has control over KGDB.
19292 + */
19293 +
19294 +void __attribute__ ((weak))
19295 +    kgdb_post_master_code(struct pt_regs *regs, int e_vector, int err_code)
19296 +{
19297 +}
19298 +
19299 +/**
19300 + *     kgdb_roundup_cpus - Get other CPUs into a holding pattern
19301 + *     @flags: Current IRQ state
19302 + *
19303 + *     On SMP systems, we need to get the attention of the other CPUs
19304 + *     and get them be in a known state.  This should do what is needed
19305 + *     to get the other CPUs to call kgdb_wait(). Note that on some arches,
19306 + *     the NMI approach is not used for rounding up all the CPUs. For example,
19307 + *     in case of MIPS, smp_call_function() is used to roundup CPUs. In
19308 + *     this case, we have to make sure that interrupts are enabled before
19309 + *     calling smp_call_function(). The argument to this function is
19310 + *     the flags that will be used when restoring the interrupts. There is
19311 + *     local_irq_save() call before kgdb_roundup_cpus().
19312 + */
19313 +void __attribute__ ((weak))
19314 +    kgdb_roundup_cpus(unsigned long flags)
19315 +{
19316 +}
19317 +
19318 +/**
19319 + *     kgdb_shadowinfo - Get shadowed information on @threadid.
19320 + *     @regs: The &struct pt_regs of the current process.
19321 + *     @buffer: A buffer of %BUFMAX size.
19322 + *     @threadid: The thread id of the shadowed process to get information on.
19323 + */
19324 +void __attribute__ ((weak))
19325 +    kgdb_shadowinfo(struct pt_regs *regs, char *buffer, unsigned threadid)
19326 +{
19327 +}
19328 +
19329 +/**
19330 + *     kgdb_get_shadow_thread - Get the shadowed &task_struct of @threadid.
19331 + *     @regs: The &struct pt_regs of the current thread.
19332 + *     @threadid: The thread id of the shadowed process to get information on.
19333 + *
19334 + *     RETURN:
19335 + *     This returns a pointer to the &struct task_struct of the shadowed
19336 + *     thread, @threadid.
19337 + */
19338 +struct task_struct __attribute__ ((weak))
19339 +    * kgdb_get_shadow_thread(struct pt_regs *regs, int threadid)
19340 +{
19341 +       return NULL;
19342 +}
19343 +
19344 +/**
19345 + *     kgdb_shadow_regs - Return the shadowed registers of @threadid.
19346 + *     @regs: The &struct pt_regs of the current thread.
19347 + *     @threadid: The thread id we want the &struct pt_regs for.
19348 + *
19349 + *     RETURN:
19350 + *     The a pointer to the &struct pt_regs of the shadowed thread @threadid.
19351 + */
19352 +struct pt_regs __attribute__ ((weak))
19353 +    * kgdb_shadow_regs(struct pt_regs *regs, int threadid)
19354 +{
19355 +       return NULL;
19356 +}
19357 +
19358 +int __attribute__ ((weak))
19359 +     kgdb_validate_break_address(unsigned long addr)
19360 +{
19361 +       int error = 0;
19362 +       char tmp_variable[BREAK_INSTR_SIZE];
19363 +       error = kgdb_get_mem((char *)addr, tmp_variable, BREAK_INSTR_SIZE);
19364 +       return error;
19365 +}
19366 +
19367 +int __attribute__ ((weak))
19368 +     kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr)
19369 +{
19370 +       int error = 0;
19371 +       if ((error = kgdb_get_mem((char *)addr,
19372 +               saved_instr, BREAK_INSTR_SIZE)) < 0)
19373 +                       return error;
19374 +
19375 +       if ((error = kgdb_set_mem((char *)addr, kgdb_ops->gdb_bpt_instr,
19376 +               BREAK_INSTR_SIZE)) < 0)
19377 +                       return error;
19378 +       return 0;
19379 +}
19380 +
19381 +int __attribute__ ((weak))
19382 +     kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle)
19383 +{
19384 +
19385 +       int error = 0;
19386 +       if ((error =kgdb_set_mem((char *)addr, (char *)bundle,
19387 +               BREAK_INSTR_SIZE)) < 0)
19388 +                       return error;
19389 +       return 0;
19390 +}
19391 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/kernel/module.c linux-2.6.18.kgdb/kernel/module.c
19392 --- linux-2.6.18/kernel/module.c        2006-09-20 07:42:06.000000000 +0400
19393 +++ linux-2.6.18.kgdb/kernel/module.c   2008-06-10 16:20:07.000000000 +0400
19394 @@ -64,6 +64,7 @@ static DEFINE_SPINLOCK(modlist_lock);
19395  /* List of modules, protected by module_mutex AND modlist_lock */
19396  static DEFINE_MUTEX(module_mutex);
19397  static LIST_HEAD(modules);
19398 +static DECLARE_MUTEX(notify_mutex);
19399  
19400  static BLOCKING_NOTIFIER_HEAD(module_notify_list);
19401  
19402 @@ -700,6 +701,12 @@ sys_delete_module(const char __user *nam
19403         if (ret != 0)
19404                 goto out;
19405  
19406 +       down(&notify_mutex);
19407 +       blocking_notifier_call_chain(&module_notify_list, MODULE_STATE_GOING,
19408 +                               mod);
19409 +       up(&notify_mutex);
19410 +
19411 +
19412         /* Never wait if forced. */
19413         if (!forced && module_refcount(mod) != 0)
19414                 wait_for_zero_refcount(mod);
19415 @@ -712,6 +719,11 @@ sys_delete_module(const char __user *nam
19416         }
19417         free_module(mod);
19418  
19419 +       down(&notify_mutex);
19420 +       blocking_notifier_call_chain(&module_notify_list, MODULE_STATE_GONE,
19421 +                       NULL);
19422 +       up(&notify_mutex);
19423 +
19424   out:
19425         mutex_unlock(&module_mutex);
19426         return ret;
19427 @@ -1112,6 +1124,11 @@ static void free_module(struct module *m
19428         /* Arch-specific cleanup. */
19429         module_arch_cleanup(mod);
19430  
19431 +#ifdef CONFIG_KGDB
19432 +       /* kgdb info */
19433 +       vfree(mod->mod_sections);
19434 +#endif
19435 +
19436         /* Module unload stuff */
19437         module_unload_free(mod);
19438  
19439 @@ -1371,6 +1388,31 @@ static void setup_modinfo(struct module 
19440         }
19441  }
19442  
19443 +#ifdef CONFIG_KGDB
19444 +int add_modsects (struct module *mod, Elf_Ehdr *hdr, Elf_Shdr *sechdrs, const
19445 +                char *secstrings)
19446 +{
19447 +        int i;
19448 +
19449 +        mod->num_sections = hdr->e_shnum - 1;
19450 +        mod->mod_sections = vmalloc((hdr->e_shnum - 1)*
19451 +               sizeof (struct mod_section));
19452 +
19453 +        if (mod->mod_sections == NULL) {
19454 +                return -ENOMEM;
19455 +        }
19456 +
19457 +        for (i = 1; i < hdr->e_shnum; i++) {
19458 +                mod->mod_sections[i - 1].address = (void *)sechdrs[i].sh_addr;
19459 +                strncpy(mod->mod_sections[i - 1].name, secstrings +
19460 +                                sechdrs[i].sh_name, MAX_SECTNAME);
19461 +                mod->mod_sections[i - 1].name[MAX_SECTNAME] = '\0';
19462 +       }
19463 +
19464 +       return 0;
19465 +}
19466 +#endif
19467 +
19468  #ifdef CONFIG_KALLSYMS
19469  int is_exported(const char *name, const struct module *mod)
19470  {
19471 @@ -1782,6 +1824,12 @@ static struct module *load_module(void _
19472  
19473         add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
19474  
19475 +#ifdef CONFIG_KGDB
19476 +        if ((err = add_modsects(mod, hdr, sechdrs, secstrings)) < 0) {
19477 +                goto nomodsectinfo;
19478 +        }
19479 +#endif
19480 +
19481         err = module_finalize(hdr, sechdrs, mod);
19482         if (err < 0)
19483                 goto cleanup;
19484 @@ -1842,6 +1890,11 @@ static struct module *load_module(void _
19485   arch_cleanup:
19486         module_arch_cleanup(mod);
19487   cleanup:
19488 +
19489 +#ifdef CONFIG_KGDB
19490 +nomodsectinfo:
19491 +       vfree(mod->mod_sections);
19492 +#endif
19493         module_unload_free(mod);
19494         module_free(mod, mod->module_init);
19495   free_core:
19496 @@ -1913,6 +1966,10 @@ sys_init_module(void __user *umod,
19497                 /* Init routine failed: abort.  Try to protect us from
19498                     buggy refcounters. */
19499                 mod->state = MODULE_STATE_GOING;
19500 +               down(&notify_mutex);
19501 +               blocking_notifier_call_chain(&module_notify_list, MODULE_STATE_GOING,
19502 +                               mod);
19503 +               up(&notify_mutex);
19504                 synchronize_sched();
19505                 if (mod->unsafe)
19506                         printk(KERN_ERR "%s: module is now stuck!\n",
19507 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/kernel/sched.c linux-2.6.18.kgdb/kernel/sched.c
19508 --- linux-2.6.18/kernel/sched.c 2006-09-20 07:42:06.000000000 +0400
19509 +++ linux-2.6.18.kgdb/kernel/sched.c    2008-06-10 16:18:58.000000000 +0400
19510 @@ -52,6 +52,7 @@
19511  #include <linux/acct.h>
19512  #include <linux/kprobes.h>
19513  #include <linux/delayacct.h>
19514 +#include <linux/kgdb.h>
19515  #include <asm/tlb.h>
19516  
19517  #include <asm/unistd.h>
19518 @@ -6790,6 +6791,9 @@ void __might_sleep(char *file, int line)
19519  #ifdef in_atomic
19520         static unsigned long prev_jiffy;        /* ratelimiting */
19521  
19522 +       if (atomic_read(&debugger_active))
19523 +               return;
19524 +
19525         if ((in_atomic() || irqs_disabled()) &&
19526             system_state == SYSTEM_RUNNING && !oops_in_progress) {
19527                 if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
19528 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/kernel/softlockup.c linux-2.6.18.kgdb/kernel/softlockup.c
19529 --- linux-2.6.18/kernel/softlockup.c    2006-09-20 07:42:06.000000000 +0400
19530 +++ linux-2.6.18.kgdb/kernel/softlockup.c       2008-06-10 16:20:11.000000000 +0400
19531 @@ -13,6 +13,7 @@
19532  #include <linux/kthread.h>
19533  #include <linux/notifier.h>
19534  #include <linux/module.h>
19535 +#include <linux/kgdb.h>
19536  
19537  static DEFINE_SPINLOCK(print_lock);
19538  
19539 @@ -37,6 +38,9 @@ static struct notifier_block panic_block
19540  void touch_softlockup_watchdog(void)
19541  {
19542         __raw_get_cpu_var(touch_timestamp) = jiffies;
19543 +#ifdef CONFIG_KGDB
19544 +       atomic_set(&kgdb_sync_softlockup[raw_smp_processor_id()], 0);
19545 +#endif
19546  }
19547  EXPORT_SYMBOL(touch_softlockup_watchdog);
19548  
19549 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/kernel/timer.c linux-2.6.18.kgdb/kernel/timer.c
19550 --- linux-2.6.18/kernel/timer.c 2006-09-20 07:42:06.000000000 +0400
19551 +++ linux-2.6.18.kgdb/kernel/timer.c    2008-06-10 16:20:11.000000000 +0400
19552 @@ -34,6 +34,7 @@
19553  #include <linux/cpu.h>
19554  #include <linux/syscalls.h>
19555  #include <linux/delay.h>
19556 +#include <linux/kgdb.h>
19557  
19558  #include <asm/uaccess.h>
19559  #include <asm/unistd.h>
19560 @@ -1257,7 +1258,11 @@ static void run_timer_softirq(struct sof
19561   */
19562  void run_local_timers(void)
19563  {
19564 +       int this_cpu = smp_processor_id();
19565         raise_softirq(TIMER_SOFTIRQ);
19566 +#ifdef CONFIG_KGDB
19567 +       if(!atomic_read(&kgdb_sync_softlockup[this_cpu]))
19568 +#endif
19569         softlockup_tick();
19570  }
19571  
19572 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/lib/Kconfig.debug linux-2.6.18.kgdb/lib/Kconfig.debug
19573 --- linux-2.6.18/lib/Kconfig.debug      2006-09-20 07:42:06.000000000 +0400
19574 +++ linux-2.6.18.kgdb/lib/Kconfig.debug 2008-06-10 16:19:51.000000000 +0400
19575 @@ -315,7 +315,7 @@ config DEBUG_VM
19576  
19577  config FRAME_POINTER
19578         bool "Compile the kernel with frame pointers"
19579 -       depends on DEBUG_KERNEL && (X86 || CRIS || M68K || M68KNOMMU || FRV || UML || S390)
19580 +       depends on DEBUG_KERNEL && (X86 || CRIS || M68K || M68KNOMMU || FRV || UML || S390 || SUPERH)
19581         default y if DEBUG_INFO && UML
19582         help
19583           If you say Y here the resulting kernel image will be slightly larger
19584 @@ -368,3 +368,158 @@ config RCU_TORTURE_TEST
19585           at boot time (you probably don't).
19586           Say M if you want the RCU torture tests to build as a module.
19587           Say N if you are unsure.
19588 +
19589 +config WANT_EXTRA_DEBUG_INFORMATION
19590 +       bool
19591 +       select DEBUG_INFO
19592 +       select FRAME_POINTER if X86 || SUPERH
19593 +       default n
19594 +
19595 +config KGDB
19596 +       bool "KGDB: kernel debugging with remote gdb"
19597 +       select WANT_EXTRA_DEBUG_INFORMATION
19598 +       depends on DEBUG_KERNEL && (ARM || X86 || MIPS || (SUPERH && !SUPERH64) || IA64 || X86_64 || PPC)
19599 +       help
19600 +         If you say Y here, it will be possible to remotely debug the
19601 +         kernel using gdb. It is strongly suggested that you enable
19602 +         DEBUG_INFO, and if available on your platform, FRAME_POINTER.
19603 +         Documentation of kernel debugger available at
19604 +         http://kgdb.sourceforge.net as well as in DocBook form
19605 +         in Documentation/DocBook/.  If unsure, say N.
19606 +
19607 +config KGDB_CONSOLE
19608 +       bool "KGDB: Console messages through gdb"
19609 +       depends on KGDB
19610 +         help
19611 +           If you say Y here, console messages will appear through gdb.
19612 +           Other consoles such as tty or ttyS will continue to work as usual.
19613 +           Note, that if you use this in conjunction with KGDB_ETH, if the
19614 +           ethernet driver runs into an error condition during use with KGDB
19615 +           it is possible to hit an infinite recusrion, causing the kernel
19616 +           to crash, and typically reboot.  For this reason, it is preferable
19617 +           to use NETCONSOLE in conjunction with KGDB_ETH instead of
19618 +           KGDB_CONSOLE.
19619 +
19620 +choice
19621 +       prompt "Method for KGDB communication"
19622 +       depends on KGDB
19623 +       default KGDB_8250_NOMODULE
19624 +       default KGDB_MPSC if SERIAL_MPSC
19625 +       default KGDB_CPM_UART if (8xx || 8260)
19626 +       default KGDB_SIBYTE if SIBYTE_SB1xxx_SOC
19627 +       help
19628 +         There are a number of different ways in which you can communicate
19629 +         with KGDB.  The most common is via serial, with the 8250 driver
19630 +         (should your hardware have an 8250, or ns1655x style uart).
19631 +         Another option is to use the NETPOLL framework and UDP, should
19632 +         your ethernet card support this.  Other options may exist.
19633 +         You can elect to have one core I/O driver that is built into the
19634 +         kernel for debugging as the kernel is booting, or using only
19635 +         kernel modules.
19636 +
19637 +config KGDB_ONLY_MODULES
19638 +       bool "KGDB: Use only kernel modules for I/O"
19639 +       depends on MODULES
19640 +       help
19641 +         Use only kernel modules to configure KGDB I/O after the
19642 +         kernel is booted.
19643 +
19644 +config KGDB_8250_NOMODULE
19645 +       bool "KGDB: On generic serial port (8250)"
19646 +       select KGDB_8250
19647 +       help
19648 +         Uses generic serial port (8250) to communicate with the host
19649 +         GDB.  This is independent of the normal (SERIAL_8250) driver
19650 +         for this chipset.
19651 +
19652 +config KGDBOE_NOMODULE
19653 +       bool "KGDB: On ethernet - in kernel"
19654 +       select KGDBOE
19655 +       select NETPOLL
19656 +       select NETPOLL_TRAP
19657 +       select NETPOLL_RX
19658 +       help
19659 +         Uses the NETPOLL API to communicate with the host GDB via UDP.
19660 +         In order for this to work, the ethernet interface specified must
19661 +         support the NETPOLL API, and this must be initialized at boot.
19662 +         See the documentation for syntax.
19663 +
19664 +config KGDB_MPSC
19665 +       bool "KGDB on MV64x60 MPSC"
19666 +       depends on SERIAL_MPSC
19667 +       help
19668 +         Uses a Marvell GT64260B or MV64x60 Multi-Purpose Serial
19669 +         Controller (MPSC) channel. Note that the GT64260A is not
19670 +         supported.
19671 +
19672 +config KGDB_CPM_UART
19673 +       bool "KGDB: On CPM UART"
19674 +       depends on PPC && (CPM2 || 8xx)
19675 +       help
19676 +         Uses CPM UART to communicate with the host GDB.
19677 +
19678 +config KGDB_SIBYTE
19679 +       bool "KGDB: On the Broadcom SWARM serial port"
19680 +       depends on MIPS && SIBYTE_SB1xxx_SOC
19681 +endchoice
19682 +
19683 +config KGDBOE
19684 +       tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE
19685 +       depends on m && KGDB
19686 +       select NETPOLL
19687 +       select NETPOLL_TRAP
19688 +       select NETPOLL_RX
19689 +       help
19690 +         Uses the NETPOLL API to communicate with the host GDB via UDP.
19691 +         In order for this to work, the ethernet interface specified must
19692 +         support the NETPOLL API, and this must be initialized at boot.
19693 +         See the documentation for syntax.
19694 +
19695 +config KGDB_8250
19696 +       tristate "KGDB: On generic serial port (8250)" if !KGDB_8250_NOMODULE
19697 +       depends on m && KGDB_ONLY_MODULES
19698 +       help
19699 +         Uses generic serial port (8250) to communicate with the host
19700 +         GDB.  This is independent of the normal (SERIAL_8250) driver
19701 +         for this chipset.
19702 +
19703 +config KGDB_SIMPLE_SERIAL
19704 +       bool "Simple selection of KGDB serial port"
19705 +       depends on KGDB_8250_NOMODULE
19706 +       default y
19707 +       help
19708 +         If you say Y here, you will only have to pick the baud rate
19709 +         and port number that you wish to use for KGDB.  Note that this
19710 +         only works on architectures that register known serial ports
19711 +         early on.  If you say N, you will have to provide, either here
19712 +         or on the command line, the type (I/O or MMIO), IRQ and
19713 +         address to use.  If in doubt, say Y.
19714 +
19715 +config KGDB_BAUDRATE
19716 +       int "Debug serial port baud rate"
19717 +       depends on (KGDB_8250 && KGDB_SIMPLE_SERIAL)
19718 +       default "115200"
19719 +       help
19720 +         gdb and the kernel stub need to agree on the baud rate to be
19721 +         used.  Standard rates from 9600 to 115200 are allowed, and this
19722 +         may be overridden via the commandline.
19723 +
19724 +config KGDB_PORT_NUM
19725 +       int "Serial port number for KGDB"
19726 +       range 0 1 if KGDB_MPSC
19727 +       range 0 3
19728 +       depends on (KGDB_8250 && KGDB_SIMPLE_SERIAL) || KGDB_MPSC
19729 +       default "1"
19730 +       help
19731 +         Pick the port number (0 based) for KGDB to use.
19732 +
19733 +config KGDB_8250_CONF_STRING
19734 +       string "Configuration string for KGDB"
19735 +       depends on KGDB_8250_NOMODULE && !KGDB_SIMPLE_SERIAL
19736 +       default "io,2f8,115200,3" if X86
19737 +       help
19738 +         The format of this string should be <io or
19739 +         mmio>,<address>,<baud rate>,<irq>.  For example, to use the
19740 +         serial port on an i386 box located at 0x2f8 and 115200 baud
19741 +         on IRQ 3 at use:
19742 +         io,2f8,115200,3
19743 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/net/core/netpoll.c linux-2.6.18.kgdb/net/core/netpoll.c
19744 --- linux-2.6.18/net/core/netpoll.c     2006-09-20 07:42:06.000000000 +0400
19745 +++ linux-2.6.18.kgdb/net/core/netpoll.c        2008-06-10 16:19:07.000000000 +0400
19746 @@ -519,7 +519,8 @@ int __netpoll_rx(struct sk_buff *skb)
19747  
19748         np->rx_hook(np, ntohs(uh->source),
19749                     (char *)(uh+1),
19750 -                   ulen - sizeof(struct udphdr));
19751 +                   ulen - sizeof(struct udphdr),
19752 +                   skb);
19753  
19754         kfree_skb(skb);
19755         return 1;
19756 diff -rupN -X ../client-cleanup/dontdiff linux-2.6.18/scripts/dwarfh.awk linux-2.6.18.kgdb/scripts/dwarfh.awk
19757 --- linux-2.6.18/scripts/dwarfh.awk     1970-01-01 03:00:00.000000000 +0300
19758 +++ linux-2.6.18.kgdb/scripts/dwarfh.awk        2008-06-10 16:19:58.000000000 +0400
19759 @@ -0,0 +1,19 @@
19760 +BEGIN {
19761 +       print "#ifndef  _ELF_DWARF_H"
19762 +               print "/* Machine generated from dwarf2.h by scripts/dwarfh.awk */"
19763 +}
19764 +$2 == "=" {
19765 +       gsub(/,/, "", $3)
19766 +       print "#define " $1 "\t " $3
19767 +}
19768 +$1 == "#define" {
19769 +       print $0
19770 +       while( index($0,"\\") == length($0)){
19771 +               getline
19772 +               print $0
19773 +       }
19774 +}
19775 +/.*/ {}
19776 +END {
19777 +       print "#endif"
19778 +}