Whamcloud - gitweb
LU-354 test: Change dev_set_rdonly() check to warning
[fs/lustre-release.git] / lustre / kernel_patches / patches / 2.6-rhel5-kgdb-ga.patch
1 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/Documentation/DocBook/Makefile linux-2.6.18-53.1.14.kgdb/Documentation/DocBook/Makefile
2 --- linux-2.6.18-53.1.14/Documentation/DocBook/Makefile 2008-03-06 05:54:50.000000000 +0300
3 +++ linux-2.6.18-53.1.14.kgdb/Documentation/DocBook/Makefile    2008-06-10 15:37:25.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 utrace.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/Documentation/DocBook/kgdb.tmpl linux-2.6.18-53.1.14.kgdb/Documentation/DocBook/kgdb.tmpl
14 --- linux-2.6.18-53.1.14/Documentation/DocBook/kgdb.tmpl        1970-01-01 03:00:00.000000000 +0300
15 +++ linux-2.6.18-53.1.14.kgdb/Documentation/DocBook/kgdb.tmpl   2008-06-10 15:38:50.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/MAINTAINERS linux-2.6.18-53.1.14.kgdb/MAINTAINERS
268 --- linux-2.6.18-53.1.14/MAINTAINERS    2008-03-06 05:54:49.000000000 +0300
269 +++ linux-2.6.18-53.1.14.kgdb/MAINTAINERS       2008-06-10 15:37:25.000000000 +0400
270 @@ -1715,6 +1715,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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/Makefile linux-2.6.18-53.1.14.kgdb/Makefile
287 --- linux-2.6.18-53.1.14/Makefile       2008-03-06 05:55:00.000000000 +0300
288 +++ linux-2.6.18-53.1.14.kgdb/Makefile  2008-06-10 15:39:01.000000000 +0400
289 @@ -992,6 +992,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 @@ -1422,7 +1423,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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/kernel/Makefile linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/Makefile
311 --- linux-2.6.18-53.1.14/arch/arm/kernel/Makefile       2006-09-20 07:42:06.000000000 +0400
312 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/Makefile  2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/kernel/entry-armv.S linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/entry-armv.S
322 --- linux-2.6.18-53.1.14/arch/arm/kernel/entry-armv.S   2006-09-20 07:42:06.000000000 +0400
323 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/entry-armv.S      2008-06-10 15:39:01.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/kernel/kgdb-jmp.S linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/kgdb-jmp.S
341 --- linux-2.6.18-53.1.14/arch/arm/kernel/kgdb-jmp.S     1970-01-01 03:00:00.000000000 +0300
342 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/kgdb-jmp.S        2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/kernel/kgdb.c linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/kgdb.c
377 --- linux-2.6.18-53.1.14/arch/arm/kernel/kgdb.c 1970-01-01 03:00:00.000000000 +0300
378 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/kgdb.c    2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/kernel/setup.c linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/setup.c
589 --- linux-2.6.18-53.1.14/arch/arm/kernel/setup.c        2006-09-20 07:42:06.000000000 +0400
590 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/setup.c   2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/kernel/traps.c linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/traps.c
604 --- linux-2.6.18-53.1.14/arch/arm/kernel/traps.c        2006-09-20 07:42:06.000000000 +0400
605 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/kernel/traps.c   2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/mach-ixp2000/core.c linux-2.6.18-53.1.14.kgdb/arch/arm/mach-ixp2000/core.c
645 --- linux-2.6.18-53.1.14/arch/arm/mach-ixp2000/core.c   2006-09-20 07:42:06.000000000 +0400
646 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/mach-ixp2000/core.c      2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/mach-ixp2000/ixdp2x01.c linux-2.6.18-53.1.14.kgdb/arch/arm/mach-ixp2000/ixdp2x01.c
666 --- linux-2.6.18-53.1.14/arch/arm/mach-ixp2000/ixdp2x01.c       2006-09-20 07:42:06.000000000 +0400
667 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/mach-ixp2000/ixdp2x01.c  2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/mach-ixp4xx/coyote-setup.c linux-2.6.18-53.1.14.kgdb/arch/arm/mach-ixp4xx/coyote-setup.c
689 --- linux-2.6.18-53.1.14/arch/arm/mach-ixp4xx/coyote-setup.c    2006-09-20 07:42:06.000000000 +0400
690 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/mach-ixp4xx/coyote-setup.c       2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/mach-ixp4xx/ixdp425-setup.c linux-2.6.18-53.1.14.kgdb/arch/arm/mach-ixp4xx/ixdp425-setup.c
703 --- linux-2.6.18-53.1.14/arch/arm/mach-ixp4xx/ixdp425-setup.c   2006-09-20 07:42:06.000000000 +0400
704 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/mach-ixp4xx/ixdp425-setup.c      2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/mach-omap1/serial.c linux-2.6.18-53.1.14.kgdb/arch/arm/mach-omap1/serial.c
746 --- linux-2.6.18-53.1.14/arch/arm/mach-omap1/serial.c   2006-09-20 07:42:06.000000000 +0400
747 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/mach-omap1/serial.c      2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/mach-pxa/Makefile linux-2.6.18-53.1.14.kgdb/arch/arm/mach-pxa/Makefile
767 --- linux-2.6.18-53.1.14/arch/arm/mach-pxa/Makefile     2006-09-20 07:42:06.000000000 +0400
768 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/mach-pxa/Makefile        2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/mach-pxa/kgdb-serial.c linux-2.6.18-53.1.14.kgdb/arch/arm/mach-pxa/kgdb-serial.c
778 --- linux-2.6.18-53.1.14/arch/arm/mach-pxa/kgdb-serial.c        1970-01-01 03:00:00.000000000 +0300
779 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/mach-pxa/kgdb-serial.c   2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/mach-versatile/kgdb_serial.c linux-2.6.18-53.1.14.kgdb/arch/arm/mach-versatile/kgdb_serial.c
880 --- linux-2.6.18-53.1.14/arch/arm/mach-versatile/kgdb_serial.c  1970-01-01 03:00:00.000000000 +0300
881 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/mach-versatile/kgdb_serial.c     2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/arm/mm/extable.c linux-2.6.18-53.1.14.kgdb/arch/arm/mm/extable.c
1005 --- linux-2.6.18-53.1.14/arch/arm/mm/extable.c  2006-09-20 07:42:06.000000000 +0400
1006 +++ linux-2.6.18-53.1.14.kgdb/arch/arm/mm/extable.c     2008-06-10 15:38:56.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/i386/kernel/Makefile linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/Makefile
1029 --- linux-2.6.18-53.1.14/arch/i386/kernel/Makefile      2008-03-06 05:54:14.000000000 +0300
1030 +++ linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/Makefile 2008-06-10 15:38:03.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/i386/kernel/entry.S linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/entry.S
1040 --- linux-2.6.18-53.1.14/arch/i386/kernel/entry.S       2008-03-06 05:55:00.000000000 +0300
1041 +++ linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/entry.S  2008-06-10 15:39:01.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 @@ -659,7 +659,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 @@ -916,7 +916,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 @@ -942,3 +942,108 @@ ENDPROC(kernel_thread_helper)
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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/i386/kernel/head.S linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/head.S
1179 --- linux-2.6.18-53.1.14/arch/i386/kernel/head.S        2008-03-06 05:54:34.000000000 +0300
1180 +++ linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/head.S   2008-06-10 15:39:01.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 @@ -336,6 +337,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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/i386/kernel/kgdb-jmp.S linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/kgdb-jmp.S
1201 --- linux-2.6.18-53.1.14/arch/i386/kernel/kgdb-jmp.S    1970-01-01 03:00:00.000000000 +0300
1202 +++ linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/kgdb-jmp.S       2008-06-10 15:38:03.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/i386/kernel/kgdb.c linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/kgdb.c
1279 --- linux-2.6.18-53.1.14/arch/i386/kernel/kgdb.c        1970-01-01 03:00:00.000000000 +0300
1280 +++ linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/kgdb.c   2008-06-10 15:39:27.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 -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/i386/kernel/setup.c linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/setup.c
1646 --- linux-2.6.18-53.1.14/arch/i386/kernel/setup.c       2008-03-06 05:54:58.000000000 +0300
1647 +++ linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/setup.c  2008-06-10 15:38:03.000000000 +0400
1648 @@ -148,6 +148,7 @@ EXPORT_SYMBOL(ist_info);
1649  struct e820map e820;
1650  
1651  extern void early_cpu_init(void);
1652 +extern void early_trap_init(void);
1653  extern void generic_apic_probe(char *);
1654  extern int root_mountflags;
1655  
1656 @@ -1470,6 +1471,7 @@ void __init setup_arch(char **cmdline_p)
1657         memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
1658         pre_setup_arch_hook();
1659         early_cpu_init();
1660 +       early_trap_init();
1661  
1662         /*
1663          * FIXME: This isn't an official loader_type right
1664 @@ -1526,6 +1528,7 @@ void __init setup_arch(char **cmdline_p)
1665         data_resource.end = virt_to_phys(_edata)-1;
1666  
1667         parse_cmdline_early(cmdline_p);
1668 +       parse_early_param();
1669  
1670  #ifdef CONFIG_EARLY_PRINTK
1671         {
1672 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/i386/kernel/smpboot.c linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/smpboot.c
1673 --- linux-2.6.18-53.1.14/arch/i386/kernel/smpboot.c     2008-03-06 05:54:34.000000000 +0300
1674 +++ linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/smpboot.c        2008-06-10 15:39:01.000000000 +0400
1675 @@ -592,6 +592,9 @@ void __devinit initialize_secondary(void
1676  
1677         asm volatile(
1678                 "movl %0,%%esp\n\t"
1679 +#ifdef CONFIG_KGDB
1680 +               "pushl end_of_stack_stop_unwind_function\n\t"
1681 +#endif
1682                 "jmp *%1"
1683                 :
1684                 :"r" (current->thread.esp),"r" (current->thread.eip));
1685 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/i386/kernel/traps.c linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/traps.c
1686 --- linux-2.6.18-53.1.14/arch/i386/kernel/traps.c       2008-03-06 05:55:00.000000000 +0300
1687 +++ linux-2.6.18-53.1.14.kgdb/arch/i386/kernel/traps.c  2008-06-10 15:38:03.000000000 +0400
1688 @@ -964,6 +964,7 @@ fastcall void __kprobes do_debug(struct 
1689          */
1690  clear_dr7:
1691         set_debugreg(0, 7);
1692 +       notify_die(DIE_DEBUG, "debug2", regs, condition, error_code, SIGTRAP);
1693         return;
1694  
1695  debug_vm86:
1696 @@ -1268,6 +1269,12 @@ static void __init set_task_gate(unsigne
1697         _set_gate(idt_table+n,5,0,0,(gdt_entry<<3));
1698  }
1699  
1700 +/* Some traps need to be set early. */
1701 +void __init early_trap_init(void) {
1702 +       set_intr_gate(1,&debug);
1703 +       set_system_intr_gate(3, &int3); /* int3 can be called from all */
1704 +       set_intr_gate(14,&page_fault);
1705 +}
1706  
1707  void __init trap_init(void)
1708  {
1709 @@ -1284,10 +1291,8 @@ void __init trap_init(void)
1710  #endif
1711  
1712         set_trap_gate(0,&divide_error);
1713 -       set_intr_gate(1,&debug);
1714         set_intr_gate(2,&nmi);
1715 -       set_system_intr_gate(3, &int3); /* int3/4 can be called from all */
1716 -       set_system_gate(4,&overflow);
1717 +       set_system_gate(4,&overflow); /* int4/5 can be called from all */
1718         set_trap_gate(5,&bounds);
1719         set_trap_gate(6,&invalid_op);
1720         set_trap_gate(7,&device_not_available);
1721 @@ -1297,7 +1302,6 @@ void __init trap_init(void)
1722         set_trap_gate(11,&segment_not_present);
1723         set_trap_gate(12,&stack_segment);
1724         set_trap_gate(13,&general_protection);
1725 -       set_intr_gate(14,&page_fault);
1726         set_trap_gate(15,&spurious_interrupt_bug);
1727         set_trap_gate(16,&coprocessor_error);
1728         set_trap_gate(17,&alignment_check);
1729 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/i386/mm/fault.c linux-2.6.18-53.1.14.kgdb/arch/i386/mm/fault.c
1730 --- linux-2.6.18-53.1.14/arch/i386/mm/fault.c   2006-09-20 07:42:06.000000000 +0400
1731 +++ linux-2.6.18-53.1.14.kgdb/arch/i386/mm/fault.c      2008-06-10 15:38:03.000000000 +0400
1732 @@ -539,6 +539,10 @@ no_context:
1733         if (is_prefetch(regs, address, error_code))
1734                 return;
1735  
1736 +       if (notify_die(DIE_PAGE_FAULT_NO_CONTEXT, "no context", regs,
1737 +                               error_code, 14, SIGSEGV) == NOTIFY_STOP)
1738 +               return;
1739 +
1740  /*
1741   * Oops. The kernel tried to access some bad page. We'll have to
1742   * terminate things with extreme prejudice.
1743 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/kernel/Makefile linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/Makefile
1744 --- linux-2.6.18-53.1.14/arch/ia64/kernel/Makefile      2008-03-06 05:54:11.000000000 +0300
1745 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/Makefile 2008-06-10 15:38:32.000000000 +0400
1746 @@ -32,6 +32,7 @@ obj-$(CONFIG_KEXEC)           += machine_kexec.o 
1747  obj-$(CONFIG_IA64_UNCACHED_ALLOCATOR)  += uncached.o
1748  obj-$(CONFIG_AUDIT)            += audit.o
1749  mca_recovery-y                 += mca_drv.o mca_drv_asm.o
1750 +obj-$(CONFIG_KGDB)             += kgdb.o kgdb-jmp.o
1751  
1752  # The gate DSO image is built using a special linker script.
1753  targets += gate.so gate-syms.o
1754 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/kernel/entry.S linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/entry.S
1755 --- linux-2.6.18-53.1.14/arch/ia64/kernel/entry.S       2008-03-06 05:54:43.000000000 +0300
1756 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/entry.S  2008-06-10 15:39:39.000000000 +0400
1757 @@ -959,9 +959,9 @@ GLOBAL_ENTRY(__ia64_leave_kernel)
1758         shr.u r18=r19,16        // get byte size of existing "dirty" partition
1759         ;;
1760         mov r16=ar.bsp          // get existing backing store pointer
1761 -       addl r17=THIS_CPU(ia64_phys_stacked_size_p8),r0
1762 +(pUStk)        addl r17=THIS_CPU(ia64_phys_stacked_size_p8),r0
1763         ;;
1764 -       ld4 r17=[r17]           // r17 = cpu_data->phys_stacked_size_p8
1765 +(pUStk)        ld4 r17=[r17]           // r17 = cpu_data->phys_stacked_size_p8
1766  (pKStk)        br.cond.dpnt skip_rbs_switch
1767  
1768         /*
1769 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/kernel/ivt.S linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/ivt.S
1770 --- linux-2.6.18-53.1.14/arch/ia64/kernel/ivt.S 2006-09-20 07:42:06.000000000 +0400
1771 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/ivt.S    2008-06-10 15:39:39.000000000 +0400
1772 @@ -52,6 +52,14 @@
1773  #include <asm/unistd.h>
1774  #include <asm/errno.h>
1775  
1776 +#ifdef CONFIG_KGDB
1777 +#define KGDB_ENABLE_PSR_DB mov r31=psr;; movl r30=IA64_PSR_DB;;        \
1778 +       or r31=r31,r30;;                                        \
1779 +       mov psr.l=r31;; srlz.i;;
1780 +#else
1781 +#define KGDB_ENABLE_PSR_DB
1782 +#endif
1783 +
1784  #if 1
1785  # define PSR_DEFAULT_BITS      psr.ac
1786  #else
1787 @@ -519,6 +527,7 @@ ENTRY(page_fault)
1788         movl r14=ia64_leave_kernel
1789         ;;
1790         SAVE_REST
1791 +       KGDB_ENABLE_PSR_DB
1792         mov rp=r14
1793         ;;
1794         adds out2=16,r12                        // out2 = pointer to pt_regs
1795 @@ -863,6 +872,7 @@ ENTRY(interrupt)
1796         srlz.i                  // ensure everybody knows psr.ic is back on
1797         ;;
1798         SAVE_REST
1799 +       KGDB_ENABLE_PSR_DB
1800         ;;
1801         MCA_RECOVER_RANGE(interrupt)
1802         alloc r14=ar.pfs,0,0,2,0 // must be first in an insn group
1803 @@ -1110,6 +1120,7 @@ ENTRY(non_syscall)
1804         movl r15=ia64_leave_kernel
1805         ;;
1806         SAVE_REST
1807 +       KGDB_ENABLE_PSR_DB
1808         mov rp=r15
1809         ;;
1810         br.call.sptk.many b6=ia64_bad_break     // avoid WAW on CFM and ignore return addr
1811 @@ -1143,6 +1154,7 @@ ENTRY(dispatch_unaligned_handler)
1812         adds r3=8,r2                            // set up second base pointer
1813         ;;
1814         SAVE_REST
1815 +       KGDB_ENABLE_PSR_DB
1816         movl r14=ia64_leave_kernel
1817         ;;
1818         mov rp=r14
1819 @@ -1185,6 +1197,10 @@ ENTRY(dispatch_to_fault_handler)
1820         adds r3=8,r2                            // set up second base pointer for SAVE_REST
1821         ;;
1822         SAVE_REST
1823 +       cmp.eq p6,p0=29,out0
1824 +(p6)   br.cond.spnt 1f;;                       // debug_vector
1825 +       KGDB_ENABLE_PSR_DB
1826 +1:
1827         movl r14=ia64_leave_kernel
1828         ;;
1829         mov rp=r14
1830 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/kernel/kgdb-jmp.S linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/kgdb-jmp.S
1831 --- linux-2.6.18-53.1.14/arch/ia64/kernel/kgdb-jmp.S    1970-01-01 03:00:00.000000000 +0300
1832 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/kgdb-jmp.S       2008-06-10 15:38:32.000000000 +0400
1833 @@ -0,0 +1,238 @@
1834 +/* setjmp() and longjmp() assembler support for kdb on ia64.
1835 +
1836 +   This code was copied from glibc CVS as of 2001-06-27 and modified where
1837 +   necessary to fit the kernel.
1838 +   Keith Owens <kaos@melbourne.sgi.com> 2001-06-27
1839 + */
1840 +
1841 +/* Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
1842 +   Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
1843 +
1844 +   The GNU C Library is free software; you can redistribute it and/or
1845 +   modify it under the terms of the GNU Library General Public License as
1846 +   published by the Free Software Foundation; either version 2 of the
1847 +   License, or (at your option) any later version.
1848 +
1849 +   The GNU C Library is distributed in the hope that it will be useful,
1850 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
1851 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1852 +   Library General Public License for more details.
1853 +
1854 +   You should have received a copy of the GNU Library General Public
1855 +   License along with the GNU C Library; see the file COPYING.LIB.  If
1856 +   not, write to the Free Software Foundation, Inc.,
1857 +   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1858 +*/
1859 +
1860 +#include <asm/asmmacro.h>
1861 +GLOBAL_ENTRY(kgdb_fault_setjmp)
1862 +       .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(2)
1863 +       alloc loc1=ar.pfs,2,2,2,0
1864 +       mov r16=ar.unat
1865 +       ;;
1866 +       mov r17=ar.fpsr
1867 +       mov r2=in0
1868 +       add r3=8,in0
1869 +       ;;
1870 +.mem.offset 0,0;
1871 +       st8.spill.nta [r2]=sp,16        // r12 (sp)
1872 +.mem.offset 8,0;
1873 +       st8.spill.nta [r3]=gp,16        // r1 (gp)
1874 +       ;;
1875 +       st8.nta [r2]=r16,16             // save caller's unat
1876 +       st8.nta [r3]=r17,16             // save fpsr
1877 +       add r8=0xa0,in0
1878 +       ;;
1879 +.mem.offset 160,0;
1880 +       st8.spill.nta [r2]=r4,16        // r4
1881 +.mem.offset 168,0;
1882 +       st8.spill.nta [r3]=r5,16        // r5
1883 +       add r9=0xb0,in0
1884 +       ;;
1885 +       stf.spill.nta [r8]=f2,32
1886 +       stf.spill.nta [r9]=f3,32
1887 +       mov loc0=rp
1888 +       .body
1889 +       ;;
1890 +       stf.spill.nta [r8]=f4,32
1891 +       stf.spill.nta [r9]=f5,32
1892 +       mov r17=b1
1893 +       ;;
1894 +       stf.spill.nta [r8]=f16,32
1895 +       stf.spill.nta [r9]=f17,32
1896 +       mov r18=b2
1897 +       ;;
1898 +       stf.spill.nta [r8]=f18,32
1899 +       stf.spill.nta [r9]=f19,32
1900 +       mov r19=b3
1901 +       ;;
1902 +       stf.spill.nta [r8]=f20,32
1903 +       stf.spill.nta [r9]=f21,32
1904 +       mov r20=b4
1905 +       ;;
1906 +       stf.spill.nta [r8]=f22,32
1907 +       stf.spill.nta [r9]=f23,32
1908 +       mov r21=b5
1909 +       ;;
1910 +       stf.spill.nta [r8]=f24,32
1911 +       stf.spill.nta [r9]=f25,32
1912 +       mov r22=ar.lc
1913 +       ;;
1914 +       stf.spill.nta [r8]=f26,32
1915 +       stf.spill.nta [r9]=f27,32
1916 +       mov r24=pr
1917 +       ;;
1918 +       stf.spill.nta [r8]=f28,32
1919 +       stf.spill.nta [r9]=f29,32
1920 +       ;;
1921 +       stf.spill.nta [r8]=f30
1922 +       stf.spill.nta [r9]=f31
1923 +
1924 +.mem.offset 0,0;
1925 +       st8.spill.nta [r2]=r6,16        // r6
1926 +.mem.offset 8,0;
1927 +       st8.spill.nta [r3]=r7,16        // r7
1928 +       ;;
1929 +       mov r23=ar.bsp
1930 +       mov r25=ar.unat
1931 +       st8.nta [r2]=loc0,16            // b0
1932 +       st8.nta [r3]=r17,16             // b1
1933 +       ;;
1934 +       st8.nta [r2]=r18,16             // b2
1935 +       st8.nta [r3]=r19,16             // b3
1936 +       ;;
1937 +       st8.nta [r2]=r20,16             // b4
1938 +       st8.nta [r3]=r21,16             // b5
1939 +       ;;
1940 +       st8.nta [r2]=loc1,16            // ar.pfs
1941 +       st8.nta [r3]=r22,16             // ar.lc
1942 +       ;;
1943 +       st8.nta [r2]=r24,16             // pr
1944 +       st8.nta [r3]=r23,16             // ar.bsp
1945 +       ;;
1946 +       st8.nta [r2]=r25                // ar.unat
1947 +       st8.nta [r3]=in0                // &__jmp_buf
1948 +       mov r8=0
1949 +       mov rp=loc0
1950 +       mov ar.pfs=loc1
1951 +       br.ret.sptk.few rp
1952 +END(kdba_setjmp)
1953 +#define        pPos    p6      /* is rotate count positive? */
1954 +#define        pNeg    p7      /* is rotate count negative? */
1955 +GLOBAL_ENTRY(kgdb_fault_longjmp)
1956 +       alloc r8=ar.pfs,2,1,0,0
1957 +       mov r27=ar.rsc
1958 +       add r2=0x98,in0         // r2 <- &jmpbuf.orig_jmp_buf_addr
1959 +       ;;
1960 +       ld8 r8=[r2],-16         // r8 <- orig_jmp_buf_addr
1961 +       mov r10=ar.bsp
1962 +       and r11=~0x3,r27        // clear ar.rsc.mode
1963 +       ;;
1964 +       flushrs                 // flush dirty regs to backing store (must be first in insn grp)
1965 +       ld8 r23=[r2],8          // r23 <- jmpbuf.ar_bsp
1966 +       sub r8=r8,in0           // r8 <- &orig_jmpbuf - &jmpbuf
1967 +       ;;
1968 +       ld8 r25=[r2]            // r25 <- jmpbuf.ar_unat
1969 +       extr.u r8=r8,3,6        // r8 <- (&orig_jmpbuf - &jmpbuf)/8 & 0x3f
1970 +       ;;
1971 +       cmp.lt pNeg,pPos=r8,r0
1972 +       mov r2=in0
1973 +       ;;
1974 +(pPos) mov r16=r8
1975 +(pNeg) add r16=64,r8
1976 +(pPos) sub r17=64,r8
1977 +(pNeg) sub r17=r0,r8
1978 +       ;;
1979 +       mov ar.rsc=r11          // put RSE in enforced lazy mode
1980 +       shr.u r8=r25,r16
1981 +       add r3=8,in0            // r3 <- &jmpbuf.r1
1982 +       shl r9=r25,r17
1983 +       ;;
1984 +       or r25=r8,r9
1985 +       ;;
1986 +       mov r26=ar.rnat
1987 +       mov ar.unat=r25         // setup ar.unat (NaT bits for r1, r4-r7, and r12)
1988 +       ;;
1989 +       ld8.fill.nta sp=[r2],16 // r12 (sp)
1990 +       ld8.fill.nta gp=[r3],16         // r1 (gp)
1991 +       dep r11=-1,r23,3,6      // r11 <- ia64_rse_rnat_addr(jmpbuf.ar_bsp)
1992 +       ;;
1993 +       ld8.nta r16=[r2],16             // caller's unat
1994 +       ld8.nta r17=[r3],16             // fpsr
1995 +       ;;
1996 +       ld8.fill.nta r4=[r2],16 // r4
1997 +       ld8.fill.nta r5=[r3],16         // r5 (gp)
1998 +       cmp.geu p8,p0=r10,r11   // p8 <- (ar.bsp >= jmpbuf.ar_bsp)
1999 +       ;;
2000 +       ld8.fill.nta r6=[r2],16 // r6
2001 +       ld8.fill.nta r7=[r3],16         // r7
2002 +       ;;
2003 +       mov ar.unat=r16                 // restore caller's unat
2004 +       mov ar.fpsr=r17                 // restore fpsr
2005 +       ;;
2006 +       ld8.nta r16=[r2],16             // b0
2007 +       ld8.nta r17=[r3],16             // b1
2008 +       ;;
2009 +(p8)   ld8 r26=[r11]           // r26 <- *ia64_rse_rnat_addr(jmpbuf.ar_bsp)
2010 +       mov ar.bspstore=r23     // restore ar.bspstore
2011 +       ;;
2012 +       ld8.nta r18=[r2],16             // b2
2013 +       ld8.nta r19=[r3],16             // b3
2014 +       ;;
2015 +       ld8.nta r20=[r2],16             // b4
2016 +       ld8.nta r21=[r3],16             // b5
2017 +       ;;
2018 +       ld8.nta r11=[r2],16             // ar.pfs
2019 +       ld8.nta r22=[r3],56             // ar.lc
2020 +       ;;
2021 +       ld8.nta r24=[r2],32             // pr
2022 +       mov b0=r16
2023 +       ;;
2024 +       ldf.fill.nta f2=[r2],32
2025 +       ldf.fill.nta f3=[r3],32
2026 +       mov b1=r17
2027 +       ;;
2028 +       ldf.fill.nta f4=[r2],32
2029 +       ldf.fill.nta f5=[r3],32
2030 +       mov b2=r18
2031 +       ;;
2032 +       ldf.fill.nta f16=[r2],32
2033 +       ldf.fill.nta f17=[r3],32
2034 +       mov b3=r19
2035 +       ;;
2036 +       ldf.fill.nta f18=[r2],32
2037 +       ldf.fill.nta f19=[r3],32
2038 +       mov b4=r20
2039 +       ;;
2040 +       ldf.fill.nta f20=[r2],32
2041 +       ldf.fill.nta f21=[r3],32
2042 +       mov b5=r21
2043 +       ;;
2044 +       ldf.fill.nta f22=[r2],32
2045 +       ldf.fill.nta f23=[r3],32
2046 +       mov ar.lc=r22
2047 +       ;;
2048 +       ldf.fill.nta f24=[r2],32
2049 +       ldf.fill.nta f25=[r3],32
2050 +       cmp.eq p8,p9=0,in1
2051 +       ;;
2052 +       ldf.fill.nta f26=[r2],32
2053 +       ldf.fill.nta f27=[r3],32
2054 +       mov ar.pfs=r11
2055 +       ;;
2056 +       ldf.fill.nta f28=[r2],32
2057 +       ldf.fill.nta f29=[r3],32
2058 +       ;;
2059 +       ldf.fill.nta f30=[r2]
2060 +       ldf.fill.nta f31=[r3]
2061 +(p8)   mov r8=1
2062 +
2063 +       mov ar.rnat=r26         // restore ar.rnat
2064 +       ;;
2065 +       mov ar.rsc=r27          // restore ar.rsc
2066 +(p9)   mov r8=in1
2067 +
2068 +       invala                  // virt. -> phys. regnum mapping may change
2069 +       mov pr=r24,-1
2070 +       br.ret.sptk.few rp
2071 +END(kgdb_fault_longjmp)
2072 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/kernel/kgdb.c linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/kgdb.c
2073 --- linux-2.6.18-53.1.14/arch/ia64/kernel/kgdb.c        1970-01-01 03:00:00.000000000 +0300
2074 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/kgdb.c   2008-06-10 15:38:32.000000000 +0400
2075 @@ -0,0 +1,1131 @@
2076 +/*
2077 + *
2078 + * This program is free software; you can redistribute it and/or modify it
2079 + * under the terms of the GNU General Public License as published by the
2080 + * Free Software Foundation; either version 2, or (at your option) any
2081 + * later version.
2082 + *
2083 + * This program is distributed in the hope that it will be useful, but
2084 + * WITHOUT ANY WARRANTY; without even the implied warranty of
2085 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2086 + * General Public License for more details.
2087 + *
2088 + */
2089 +
2090 +/*
2091 + * Copyright (C) 2000-2001 VERITAS Software Corporation.
2092 + * (c) Copyright 2005 Hewlett-Packard Development Company, L.P.
2093 + *     Bob Picco <bob.picco@hp.com>
2094 + */
2095 +/*
2096 + *  Contributor:     Lake Stevens Instrument Division$
2097 + *  Written by:      Glenn Engel $
2098 + *  Updated by:             Amit Kale<akale@veritas.com>
2099 + *  Modified for 386 by Jim Kingdon, Cygnus Support.
2100 + *  Origianl kgdb, compatibility with 2.1.xx kernel by David Grothe <dave@gcom.com>
2101 + */
2102 +
2103 +#include <linux/string.h>
2104 +#include <linux/kernel.h>
2105 +#include <linux/sched.h>
2106 +#include <linux/smp.h>
2107 +#include <linux/spinlock.h>
2108 +#include <linux/delay.h>
2109 +#include <asm/system.h>
2110 +#include <asm/ptrace.h>                /* for linux pt_regs struct */
2111 +#include <asm/unwind.h>
2112 +#include <asm/rse.h>
2113 +#include <linux/kgdb.h>
2114 +#include <linux/init.h>
2115 +#include <asm/cacheflush.h>
2116 +#include <asm/kdebug.h>
2117 +
2118 +#define NUM_REGS 590
2119 +#define REGISTER_BYTES (NUM_REGS*8+128*8)
2120 +#define REGISTER_BYTE(N) (((N) * 8)                                    \
2121 +       + ((N) <= IA64_FR0_REGNUM ?                                     \
2122 +       0 : 8 * (((N) > IA64_FR127_REGNUM) ? 128 : (N) - IA64_FR0_REGNUM)))
2123 +#define REGISTER_SIZE(N)                                               \
2124 +       (((N) >= IA64_FR0_REGNUM && (N) <= IA64_FR127_REGNUM) ? 16 : 8)
2125 +#define IA64_GR0_REGNUM         0
2126 +#define IA64_FR0_REGNUM         128
2127 +#define IA64_FR127_REGNUM       (IA64_FR0_REGNUM+127)
2128 +#define IA64_PR0_REGNUM         256
2129 +#define IA64_BR0_REGNUM         320
2130 +#define IA64_VFP_REGNUM         328
2131 +#define IA64_PR_REGNUM          330
2132 +#define IA64_IP_REGNUM          331
2133 +#define IA64_PSR_REGNUM         332
2134 +#define IA64_CFM_REGNUM         333
2135 +#define IA64_AR0_REGNUM         334
2136 +#define IA64_NAT0_REGNUM        462
2137 +#define IA64_NAT31_REGNUM       (IA64_NAT0_REGNUM+31)
2138 +#define IA64_NAT32_REGNUM       (IA64_NAT0_REGNUM+32)
2139 +#define IA64_RSC_REGNUM                (IA64_AR0_REGNUM+16)
2140 +#define IA64_BSP_REGNUM                (IA64_AR0_REGNUM+17)
2141 +#define IA64_BSPSTORE_REGNUM   (IA64_AR0_REGNUM+18)
2142 +#define IA64_RNAT_REGNUM       (IA64_AR0_REGNUM+19)
2143 +#define IA64_FCR_REGNUM                (IA64_AR0_REGNUM+21)
2144 +#define IA64_EFLAG_REGNUM      (IA64_AR0_REGNUM+24)
2145 +#define IA64_CSD_REGNUM                (IA64_AR0_REGNUM+25)
2146 +#define IA64_SSD_REGNUM                (IA64_AR0_REGNUM+26)
2147 +#define IA64_CFLG_REGNUM       (IA64_AR0_REGNUM+27)
2148 +#define IA64_FSR_REGNUM                (IA64_AR0_REGNUM+28)
2149 +#define IA64_FIR_REGNUM                (IA64_AR0_REGNUM+29)
2150 +#define IA64_FDR_REGNUM                (IA64_AR0_REGNUM+30)
2151 +#define IA64_CCV_REGNUM                (IA64_AR0_REGNUM+32)
2152 +#define IA64_UNAT_REGNUM       (IA64_AR0_REGNUM+36)
2153 +#define IA64_FPSR_REGNUM       (IA64_AR0_REGNUM+40)
2154 +#define IA64_ITC_REGNUM                (IA64_AR0_REGNUM+44)
2155 +#define IA64_PFS_REGNUM                (IA64_AR0_REGNUM+64)
2156 +#define IA64_LC_REGNUM         (IA64_AR0_REGNUM+65)
2157 +#define IA64_EC_REGNUM         (IA64_AR0_REGNUM+66)
2158 +
2159 +#define        REGISTER_INDEX(N)       (REGISTER_BYTE(N) / sizeof (unsigned long))
2160 +#define BREAK_INSTR_ALIGN      (~0xfULL)
2161 +
2162 +#define        ptoff(V)        ((unsigned int) &((struct pt_regs *)0x0)->V)
2163 +struct reg_to_ptreg_index {
2164 +       unsigned int reg;
2165 +       unsigned int ptregoff;
2166 +};
2167 +
2168 +static struct reg_to_ptreg_index gr_reg_to_ptreg_index[] = {
2169 +       {IA64_GR0_REGNUM + 1, ptoff(r1)},
2170 +       {IA64_GR0_REGNUM + 2, ptoff(r2)},
2171 +       {IA64_GR0_REGNUM + 3, ptoff(r3)},
2172 +       {IA64_GR0_REGNUM + 8, ptoff(r8)},
2173 +       {IA64_GR0_REGNUM + 9, ptoff(r9)},
2174 +       {IA64_GR0_REGNUM + 10, ptoff(r10)},
2175 +       {IA64_GR0_REGNUM + 11, ptoff(r11)},
2176 +       {IA64_GR0_REGNUM + 12, ptoff(r12)},
2177 +       {IA64_GR0_REGNUM + 13, ptoff(r13)},
2178 +       {IA64_GR0_REGNUM + 14, ptoff(r14)},
2179 +       {IA64_GR0_REGNUM + 15, ptoff(r15)},
2180 +       {IA64_GR0_REGNUM + 16, ptoff(r16)},
2181 +       {IA64_GR0_REGNUM + 17, ptoff(r17)},
2182 +       {IA64_GR0_REGNUM + 18, ptoff(r18)},
2183 +       {IA64_GR0_REGNUM + 19, ptoff(r19)},
2184 +       {IA64_GR0_REGNUM + 20, ptoff(r20)},
2185 +       {IA64_GR0_REGNUM + 21, ptoff(r21)},
2186 +       {IA64_GR0_REGNUM + 22, ptoff(r22)},
2187 +       {IA64_GR0_REGNUM + 23, ptoff(r23)},
2188 +       {IA64_GR0_REGNUM + 24, ptoff(r24)},
2189 +       {IA64_GR0_REGNUM + 25, ptoff(r25)},
2190 +       {IA64_GR0_REGNUM + 26, ptoff(r26)},
2191 +       {IA64_GR0_REGNUM + 27, ptoff(r27)},
2192 +       {IA64_GR0_REGNUM + 28, ptoff(r28)},
2193 +       {IA64_GR0_REGNUM + 29, ptoff(r29)},
2194 +       {IA64_GR0_REGNUM + 30, ptoff(r30)},
2195 +       {IA64_GR0_REGNUM + 31, ptoff(r31)},
2196 +};
2197 +
2198 +static struct reg_to_ptreg_index br_reg_to_ptreg_index[] = {
2199 +       {IA64_BR0_REGNUM, ptoff(b0)},
2200 +       {IA64_BR0_REGNUM + 6, ptoff(b6)},
2201 +       {IA64_BR0_REGNUM + 7, ptoff(b7)},
2202 +};
2203 +
2204 +static struct reg_to_ptreg_index ar_reg_to_ptreg_index[] = {
2205 +       {IA64_PFS_REGNUM, ptoff(ar_pfs)},
2206 +       {IA64_UNAT_REGNUM, ptoff(ar_unat)},
2207 +       {IA64_RNAT_REGNUM, ptoff(ar_rnat)},
2208 +       {IA64_BSPSTORE_REGNUM, ptoff(ar_bspstore)},
2209 +       {IA64_RSC_REGNUM, ptoff(ar_rsc)},
2210 +       {IA64_CSD_REGNUM, ptoff(ar_csd)},
2211 +       {IA64_SSD_REGNUM, ptoff(ar_ssd)},
2212 +       {IA64_FPSR_REGNUM, ptoff(ar_fpsr)},
2213 +       {IA64_CCV_REGNUM, ptoff(ar_ccv)},
2214 +};
2215 +
2216 +extern atomic_t cpu_doing_single_step;
2217 +
2218 +static int kgdb_gr_reg(int regnum, struct unw_frame_info *info,
2219 +       unsigned long *reg, int rw)
2220 +{
2221 +       char nat;
2222 +
2223 +       if ((regnum >= IA64_GR0_REGNUM && regnum <= (IA64_GR0_REGNUM + 1)) ||
2224 +               (regnum >= (IA64_GR0_REGNUM + 4) &&
2225 +               regnum <= (IA64_GR0_REGNUM + 7)))
2226 +               return !unw_access_gr(info, regnum - IA64_GR0_REGNUM,
2227 +               reg, &nat, rw);
2228 +       else
2229 +               return 0;
2230 +}
2231 +static int kgdb_gr_ptreg(int regnum, struct pt_regs * ptregs,
2232 +       struct unw_frame_info *info, unsigned long *reg, int rw)
2233 +{
2234 +       int i, result = 1;
2235 +       char nat;
2236 +
2237 +       if (!((regnum >= (IA64_GR0_REGNUM + 2) &&
2238 +               regnum <= (IA64_GR0_REGNUM + 3)) ||
2239 +               (regnum >= (IA64_GR0_REGNUM + 8) &&
2240 +               regnum <= (IA64_GR0_REGNUM + 15)) ||
2241 +               (regnum >= (IA64_GR0_REGNUM + 16) &&
2242 +               regnum <= (IA64_GR0_REGNUM + 31))))
2243 +               return 0;
2244 +       else if (rw && ptregs) {
2245 +               for (i = 0; i < ARRAY_SIZE(gr_reg_to_ptreg_index); i++)
2246 +                       if (gr_reg_to_ptreg_index[i].reg == regnum) {
2247 +                               *((unsigned long *)(((void *)ptregs) +
2248 +                               gr_reg_to_ptreg_index[i].ptregoff)) = *reg;
2249 +                               break;
2250 +                       }
2251 +       } else if (!rw && ptregs) {
2252 +               for (i = 0; i < ARRAY_SIZE(gr_reg_to_ptreg_index); i++)
2253 +                       if (gr_reg_to_ptreg_index[i].reg == regnum) {
2254 +                               *reg = *((unsigned long *)
2255 +                               (((void *)ptregs) +
2256 +                                gr_reg_to_ptreg_index[i].ptregoff));
2257 +                               break;
2258 +                       }
2259 +       } else
2260 +               result = !unw_access_gr(info, regnum - IA64_GR0_REGNUM,
2261 +                                       reg, &nat, rw);
2262 +       return result;
2263 +}
2264 +
2265 +static int kgdb_br_reg(int regnum, struct pt_regs * ptregs,
2266 +       struct unw_frame_info *info, unsigned long *reg, int rw)
2267 +{
2268 +       int i, result = 1;
2269 +
2270 +       if (!(regnum >= IA64_BR0_REGNUM && regnum <= (IA64_BR0_REGNUM + 7)))
2271 +               return 0;
2272 +
2273 +       switch (regnum) {
2274 +       case IA64_BR0_REGNUM:
2275 +       case IA64_BR0_REGNUM + 6:
2276 +       case IA64_BR0_REGNUM + 7:
2277 +               if (rw) {
2278 +                       for (i = 0; i < ARRAY_SIZE(br_reg_to_ptreg_index); i++)
2279 +                               if (br_reg_to_ptreg_index[i].reg == regnum) {
2280 +                                       *((unsigned long *)
2281 +                                       (((void *)ptregs) +
2282 +                                       br_reg_to_ptreg_index[i].ptregoff)) =
2283 +                                       *reg;
2284 +                                       break;
2285 +                               }
2286 +               } else
2287 +                       for (i = 0; i < ARRAY_SIZE(br_reg_to_ptreg_index); i++)
2288 +                               if (br_reg_to_ptreg_index[i].reg == regnum) {
2289 +                                               *reg = *((unsigned long *)
2290 +                                               (((void *)ptregs) +
2291 +                                               br_reg_to_ptreg_index[i].
2292 +                                               ptregoff));
2293 +                                               break;
2294 +                               }
2295 +               break;
2296 +       case IA64_BR0_REGNUM + 1:
2297 +       case IA64_BR0_REGNUM + 2:
2298 +       case IA64_BR0_REGNUM + 3:
2299 +       case IA64_BR0_REGNUM + 4:
2300 +       case IA64_BR0_REGNUM + 5:
2301 +               result = !unw_access_br(info, regnum - IA64_BR0_REGNUM,
2302 +                               reg, rw);
2303 +               break;
2304 +       }
2305 +
2306 +       return result;
2307 +}
2308 +
2309 +static int kgdb_fr_reg(int regnum, char *inbuffer, struct pt_regs * ptregs,
2310 +       struct unw_frame_info *info, unsigned long *reg,
2311 +       struct ia64_fpreg *freg, int rw)
2312 +{
2313 +       int result = 1;
2314 +
2315 +       if (!(regnum >= IA64_FR0_REGNUM && regnum <= (IA64_FR0_REGNUM + 127)))
2316 +               return 0;
2317 +
2318 +       switch (regnum) {
2319 +       case IA64_FR0_REGNUM + 6:
2320 +       case IA64_FR0_REGNUM + 7:
2321 +       case IA64_FR0_REGNUM + 8:
2322 +       case IA64_FR0_REGNUM + 9:
2323 +       case IA64_FR0_REGNUM + 10:
2324 +       case IA64_FR0_REGNUM + 11:
2325 +       case IA64_FR0_REGNUM + 12:
2326 +               if (rw) {
2327 +                       char *ptr = inbuffer;
2328 +
2329 +                       freg->u.bits[0] = *reg;
2330 +                       kgdb_hex2long(&ptr, &freg->u.bits[1]);
2331 +                       *(&ptregs->f6 + (regnum - (IA64_FR0_REGNUM + 6))) =
2332 +                               *freg;
2333 +                       break;
2334 +               } else if (!ptregs)
2335 +                       result = !unw_access_fr(info, regnum - IA64_FR0_REGNUM,
2336 +                               freg, rw);
2337 +               else
2338 +                       *freg =
2339 +                       *(&ptregs->f6 + (regnum - (IA64_FR0_REGNUM + 6)));
2340 +               break;
2341 +       default:
2342 +               if (!rw)
2343 +                       result = !unw_access_fr(info, regnum - IA64_FR0_REGNUM,
2344 +                               freg, rw);
2345 +               else
2346 +                       result = 0;
2347 +               break;
2348 +       }
2349 +
2350 +       return result;
2351 +}
2352 +
2353 +static int kgdb_ar_reg(int regnum, struct pt_regs * ptregs,
2354 +       struct unw_frame_info *info, unsigned long *reg, int rw)
2355 +{
2356 +       int result = 0, i;
2357 +
2358 +       if (!(regnum >= IA64_AR0_REGNUM && regnum <= IA64_EC_REGNUM))
2359 +               return 0;
2360 +
2361 +       if (rw && ptregs) {
2362 +               for (i = 0; i < ARRAY_SIZE(ar_reg_to_ptreg_index); i++)
2363 +                       if (ar_reg_to_ptreg_index[i].reg == regnum) {
2364 +                               *((unsigned long *) (((void *)ptregs) +
2365 +                               ar_reg_to_ptreg_index[i].ptregoff)) =
2366 +                                       *reg;
2367 +                               result = 1;
2368 +                               break;
2369 +                       }
2370 +       } else if (ptregs) {
2371 +               for (i = 0; i < ARRAY_SIZE(ar_reg_to_ptreg_index); i++)
2372 +                       if (ar_reg_to_ptreg_index[i].reg == regnum) {
2373 +                               *reg = *((unsigned long *) (((void *)ptregs) +
2374 +                                       ar_reg_to_ptreg_index[i].ptregoff));
2375 +                                       result = 1;
2376 +                               break;
2377 +                       }
2378 +       }
2379 +
2380 +       if (result)
2381 +               return result;
2382 +
2383 +       result = 1;
2384 +
2385 +       switch (regnum) {
2386 +       case IA64_CSD_REGNUM:
2387 +               result = !unw_access_ar(info, UNW_AR_CSD, reg, rw);
2388 +               break;
2389 +       case IA64_SSD_REGNUM:
2390 +               result = !unw_access_ar(info, UNW_AR_SSD, reg, rw);
2391 +               break;
2392 +       case IA64_UNAT_REGNUM:
2393 +               result = !unw_access_ar(info, UNW_AR_RNAT, reg, rw);
2394 +               break;
2395 +               case IA64_RNAT_REGNUM:
2396 +               result = !unw_access_ar(info, UNW_AR_RNAT, reg, rw);
2397 +               break;
2398 +       case IA64_BSPSTORE_REGNUM:
2399 +               result = !unw_access_ar(info, UNW_AR_RNAT, reg, rw);
2400 +               break;
2401 +       case IA64_PFS_REGNUM:
2402 +               result = !unw_access_ar(info, UNW_AR_RNAT, reg, rw);
2403 +               break;
2404 +       case IA64_LC_REGNUM:
2405 +               result = !unw_access_ar(info, UNW_AR_LC, reg, rw);
2406 +               break;
2407 +       case IA64_EC_REGNUM:
2408 +               result = !unw_access_ar(info, UNW_AR_EC, reg, rw);
2409 +               break;
2410 +       case IA64_FPSR_REGNUM:
2411 +               result = !unw_access_ar(info, UNW_AR_FPSR, reg, rw);
2412 +               break;
2413 +       case IA64_RSC_REGNUM:
2414 +               result = !unw_access_ar(info, UNW_AR_RSC, reg, rw);
2415 +               break;
2416 +       case IA64_CCV_REGNUM:
2417 +               result = !unw_access_ar(info, UNW_AR_CCV, reg, rw);
2418 +               break;
2419 +       default:
2420 +               result = 0;
2421 +       }
2422 +
2423 +       return result;
2424 +}
2425 +
2426 +void kgdb_get_reg(char *outbuffer, int regnum, struct unw_frame_info *info,
2427 +       struct pt_regs *ptregs)
2428 +{
2429 +       unsigned long reg, size = 0, *mem = &reg;
2430 +       struct ia64_fpreg freg;
2431 +
2432 +       if (kgdb_gr_reg(regnum, info, &reg, 0) ||
2433 +               kgdb_gr_ptreg(regnum, ptregs, info, &reg, 0) ||
2434 +               kgdb_br_reg(regnum, ptregs, info, &reg, 0) ||
2435 +               kgdb_ar_reg(regnum, ptregs, info, &reg, 0))
2436 +                       size = sizeof(reg);
2437 +       else if (kgdb_fr_reg(regnum, NULL, ptregs, info, &reg, &freg, 0)) {
2438 +               size = sizeof(freg);
2439 +               mem = (unsigned long *)&freg;
2440 +       } else if (regnum == IA64_IP_REGNUM) {
2441 +               if (!ptregs) {
2442 +                       unw_get_ip(info, &reg);
2443 +                       size = sizeof(reg);
2444 +               } else {
2445 +                       reg = ptregs->cr_iip;
2446 +                       size = sizeof(reg);
2447 +               }
2448 +       } else if (regnum == IA64_CFM_REGNUM) {
2449 +               if (!ptregs)
2450 +                       unw_get_cfm(info, &reg);
2451 +               else
2452 +                       reg = ptregs->cr_ifs;
2453 +               size = sizeof(reg);
2454 +       } else if (regnum == IA64_PSR_REGNUM) {
2455 +               if (!ptregs && kgdb_usethread)
2456 +                       ptregs = (struct pt_regs *)
2457 +                       ((unsigned long)kgdb_usethread +
2458 +                       IA64_STK_OFFSET) - 1;
2459 +               if (ptregs)
2460 +                       reg = ptregs->cr_ipsr;
2461 +               size = sizeof(reg);
2462 +       } else if (regnum == IA64_PR_REGNUM) {
2463 +               if (ptregs)
2464 +                       reg = ptregs->pr;
2465 +               else
2466 +                       unw_access_pr(info, &reg, 0);
2467 +               size = sizeof(reg);
2468 +       } else if (regnum == IA64_BSP_REGNUM) {
2469 +               unw_get_bsp(info, &reg);
2470 +               size = sizeof(reg);
2471 +       }
2472 +
2473 +       if (size) {
2474 +               kgdb_mem2hex((char *) mem, outbuffer, size);
2475 +               outbuffer[size*2] = 0;
2476 +       }
2477 +       else
2478 +               strcpy(outbuffer, "E0");
2479 +
2480 +       return;
2481 +}
2482 +
2483 +void kgdb_put_reg(char *inbuffer, char *outbuffer, int regnum,
2484 +                 struct unw_frame_info *info, struct pt_regs *ptregs)
2485 +{
2486 +       unsigned long reg;
2487 +       struct ia64_fpreg freg;
2488 +       char *ptr = inbuffer;
2489 +
2490 +       kgdb_hex2long(&ptr, &reg);
2491 +       strcpy(outbuffer, "OK");
2492 +
2493 +       if (kgdb_gr_reg(regnum, info, &reg, 1) ||
2494 +               kgdb_gr_ptreg(regnum, ptregs, info, &reg, 1) ||
2495 +               kgdb_br_reg(regnum, ptregs, info, &reg, 1) ||
2496 +               kgdb_fr_reg(regnum, inbuffer, ptregs, info, &reg, &freg, 1) ||
2497 +               kgdb_ar_reg(regnum, ptregs, info, &reg, 1)) ;
2498 +       else if (regnum == IA64_IP_REGNUM)
2499 +               ptregs->cr_iip = reg;
2500 +       else if (regnum == IA64_CFM_REGNUM)
2501 +               ptregs->cr_ifs = reg;
2502 +       else if (regnum == IA64_PSR_REGNUM)
2503 +               ptregs->cr_ipsr = reg;
2504 +       else if (regnum == IA64_PR_REGNUM)
2505 +               ptregs->pr = reg;
2506 +       else
2507 +               strcpy(outbuffer, "E01");
2508 +       return;
2509 +}
2510 +
2511 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
2512 +{
2513 +}
2514 +
2515 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
2516 +{
2517 +}
2518 +
2519 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
2520 +{
2521 +
2522 +}
2523 +
2524 +#define        MAX_HW_BREAKPOINT       (20)
2525 +long hw_break_total_dbr, hw_break_total_ibr;
2526 +#define        HW_BREAKPOINT   (hw_break_total_dbr + hw_break_total_ibr)
2527 +#define        WATCH_INSTRUCTION       0x0
2528 +#define WATCH_WRITE            0x1
2529 +#define        WATCH_READ              0x2
2530 +#define        WATCH_ACCESS            0x3
2531 +
2532 +#define        HWCAP_DBR       ((1 << WATCH_WRITE) | (1 << WATCH_READ))
2533 +#define        HWCAP_IBR       (1 << WATCH_INSTRUCTION)
2534 +struct hw_breakpoint {
2535 +       unsigned enabled;
2536 +       unsigned long capable;
2537 +       unsigned long type;
2538 +       unsigned long mask;
2539 +       unsigned long addr;
2540 +} *breakinfo;
2541 +
2542 +static struct hw_breakpoint hwbreaks[MAX_HW_BREAKPOINT];
2543 +
2544 +enum instruction_type { A, I, M, F, B, L, X, u };
2545 +
2546 +static enum instruction_type bundle_encoding[32][3] = {
2547 +       {M, I, I},              /* 00 */
2548 +       {M, I, I},              /* 01 */
2549 +       {M, I, I},              /* 02 */
2550 +       {M, I, I},              /* 03 */
2551 +       {M, L, X},              /* 04 */
2552 +       {M, L, X},              /* 05 */
2553 +       {u, u, u},              /* 06 */
2554 +       {u, u, u},              /* 07 */
2555 +       {M, M, I},              /* 08 */
2556 +       {M, M, I},              /* 09 */
2557 +       {M, M, I},              /* 0A */
2558 +       {M, M, I},              /* 0B */
2559 +       {M, F, I},              /* 0C */
2560 +       {M, F, I},              /* 0D */
2561 +       {M, M, F},              /* 0E */
2562 +       {M, M, F},              /* 0F */
2563 +       {M, I, B},              /* 10 */
2564 +       {M, I, B},              /* 11 */
2565 +       {M, B, B},              /* 12 */
2566 +       {M, B, B},              /* 13 */
2567 +       {u, u, u},              /* 14 */
2568 +       {u, u, u},              /* 15 */
2569 +       {B, B, B},              /* 16 */
2570 +       {B, B, B},              /* 17 */
2571 +       {M, M, B},              /* 18 */
2572 +       {M, M, B},              /* 19 */
2573 +       {u, u, u},              /* 1A */
2574 +       {u, u, u},              /* 1B */
2575 +       {M, F, B},              /* 1C */
2576 +       {M, F, B},              /* 1D */
2577 +       {u, u, u},              /* 1E */
2578 +       {u, u, u},              /* 1F */
2579 +};
2580 +
2581 +int kgdb_validate_break_address(unsigned long addr)
2582 +{
2583 +       int error;
2584 +       char tmp_variable[BREAK_INSTR_SIZE];
2585 +       error = kgdb_get_mem((char *)(addr & BREAK_INSTR_ALIGN), tmp_variable,
2586 +               BREAK_INSTR_SIZE);
2587 +       return error;
2588 +}
2589 +
2590 +int kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr)
2591 +{
2592 +       extern unsigned long _start[];
2593 +       unsigned long slot = addr & BREAK_INSTR_ALIGN, bundle_addr;
2594 +       unsigned long template;
2595 +       struct bundle {
2596 +               struct {
2597 +                       unsigned long long template:5;
2598 +                       unsigned long long slot0:41;
2599 +                       unsigned long long slot1_p0:64 - 46;
2600 +               } quad0;
2601 +               struct {
2602 +                       unsigned long long slot1_p1:41 - (64 - 46);
2603 +                       unsigned long long slot2:41;
2604 +               } quad1;
2605 +       } bundle;
2606 +       int ret;
2607 +
2608 +       bundle_addr = addr & ~0xFULL;
2609 +
2610 +       if (bundle_addr == (unsigned long)_start)
2611 +               return 0;
2612 +
2613 +       ret = kgdb_get_mem((char *)bundle_addr, (char *)&bundle,
2614 +                          BREAK_INSTR_SIZE);
2615 +       if (ret < 0)
2616 +               return ret;
2617 +
2618 +       if (slot > 2)
2619 +               slot = 0;
2620 +
2621 +       memcpy(saved_instr, &bundle, BREAK_INSTR_SIZE);
2622 +       template = bundle.quad0.template;
2623 +
2624 +       if (slot == 1 && bundle_encoding[template][1] == L)
2625 +               slot = 2;
2626 +
2627 +       switch (slot) {
2628 +       case 0:
2629 +               bundle.quad0.slot0 = BREAKNUM;
2630 +               break;
2631 +       case 1:
2632 +               bundle.quad0.slot1_p0 = BREAKNUM;
2633 +               bundle.quad1.slot1_p1 = (BREAKNUM >> (64 - 46));
2634 +               break;
2635 +       case 2:
2636 +               bundle.quad1.slot2 = BREAKNUM;
2637 +               break;
2638 +       }
2639 +
2640 +       return kgdb_set_mem((char *)bundle_addr, (char *)&bundle,
2641 +                           BREAK_INSTR_SIZE);
2642 +}
2643 +
2644 +int kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle)
2645 +{
2646 +       extern unsigned long _start[];
2647 +
2648 +       addr = addr & BREAK_INSTR_ALIGN;
2649 +       if (addr == (unsigned long)_start)
2650 +               return 0;
2651 +       return kgdb_set_mem((char *)addr, (char *)bundle, BREAK_INSTR_SIZE);
2652 +}
2653 +
2654 +static int hw_breakpoint_init;
2655 +
2656 +void do_init_hw_break(void)
2657 +{
2658 +       s64 status;
2659 +       int i;
2660 +
2661 +       hw_breakpoint_init = 1;
2662 +
2663 +#ifdef CONFIG_IA64_HP_SIM
2664 +       hw_break_total_ibr = 8;
2665 +       hw_break_total_dbr = 8;
2666 +       status = 0;
2667 +#else
2668 +       status = ia64_pal_debug_info(&hw_break_total_ibr, &hw_break_total_dbr);
2669 +#endif
2670 +
2671 +       if (status) {
2672 +               printk(KERN_INFO "do_init_hw_break: pal call failed %d\n",
2673 +                      (int)status);
2674 +               return;
2675 +       }
2676 +
2677 +       if (HW_BREAKPOINT > MAX_HW_BREAKPOINT) {
2678 +               printk(KERN_INFO "do_init_hw_break: %d exceeds max %d\n",
2679 +                      (int)HW_BREAKPOINT, (int)MAX_HW_BREAKPOINT);
2680 +
2681 +               while ((HW_BREAKPOINT > MAX_HW_BREAKPOINT)
2682 +                      && hw_break_total_ibr != 1)
2683 +                       hw_break_total_ibr--;
2684 +               while (HW_BREAKPOINT > MAX_HW_BREAKPOINT)
2685 +                       hw_break_total_dbr--;
2686 +       }
2687 +
2688 +       breakinfo = hwbreaks;
2689 +
2690 +       memset(breakinfo, 0, HW_BREAKPOINT * sizeof(struct hw_breakpoint));
2691 +
2692 +       for (i = 0; i < hw_break_total_dbr; i++)
2693 +               breakinfo[i].capable = HWCAP_DBR;
2694 +
2695 +       for (; i < HW_BREAKPOINT; i++)
2696 +               breakinfo[i].capable = HWCAP_IBR;
2697 +
2698 +       return;
2699 +}
2700 +
2701 +void kgdb_correct_hw_break(void)
2702 +{
2703 +       int breakno;
2704 +
2705 +       if (!breakinfo)
2706 +               return;
2707 +
2708 +       for (breakno = 0; breakno < HW_BREAKPOINT; breakno++) {
2709 +               if (breakinfo[breakno].enabled) {
2710 +                       if (breakinfo[breakno].capable & HWCAP_IBR) {
2711 +                               int ibreakno = breakno - hw_break_total_dbr;
2712 +                               ia64_set_ibr(ibreakno << 1,
2713 +                                            breakinfo[breakno].addr);
2714 +                               ia64_set_ibr((ibreakno << 1) + 1,
2715 +                                            (~breakinfo[breakno].mask &
2716 +                                             ((1UL << 56UL) - 1)) |
2717 +                                             (1UL << 56UL) | (1UL << 63UL));
2718 +                       } else {
2719 +                               ia64_set_dbr(breakno << 1,
2720 +                                            breakinfo[breakno].addr);
2721 +                               ia64_set_dbr((breakno << 1) + 1,
2722 +                                            (~breakinfo[breakno].
2723 +                                             mask & ((1UL << 56UL) - 1)) |
2724 +                                            (1UL << 56UL) |
2725 +                                            (breakinfo[breakno].type << 62UL));
2726 +                       }
2727 +               } else {
2728 +                       if (breakinfo[breakno].capable & HWCAP_IBR)
2729 +                               ia64_set_ibr(((breakno -
2730 +                                              hw_break_total_dbr) << 1) + 1,
2731 +                                            0);
2732 +                       else
2733 +                               ia64_set_dbr((breakno << 1) + 1, 0);
2734 +               }
2735 +       }
2736 +
2737 +       return;
2738 +}
2739 +
2740 +int hardware_breakpoint(unsigned long addr, int length, int type, int action)
2741 +{
2742 +       int breakno, found, watch;
2743 +       unsigned long mask;
2744 +       extern unsigned long _start[];
2745 +
2746 +       if (!hw_breakpoint_init)
2747 +               do_init_hw_break();
2748 +
2749 +       if (!breakinfo)
2750 +               return 0;
2751 +       else if (addr == (unsigned long)_start)
2752 +               return 1;
2753 +
2754 +       if (type == WATCH_ACCESS)
2755 +               mask = HWCAP_DBR;
2756 +       else
2757 +               mask = 1UL << type;
2758 +
2759 +       for (watch = 0, found = 0, breakno = 0; breakno < HW_BREAKPOINT;
2760 +            breakno++) {
2761 +               if (action) {
2762 +                       if (breakinfo[breakno].enabled
2763 +                           || !(breakinfo[breakno].capable & mask))
2764 +                               continue;
2765 +                       breakinfo[breakno].enabled = 1;
2766 +                       breakinfo[breakno].type = type;
2767 +                       breakinfo[breakno].mask = length - 1;
2768 +                       breakinfo[breakno].addr = addr;
2769 +                       watch = breakno;
2770 +               } else if (breakinfo[breakno].enabled &&
2771 +                          ((length < 0 && breakinfo[breakno].addr == addr) ||
2772 +                           ((breakinfo[breakno].capable & mask) &&
2773 +                            (breakinfo[breakno].mask == (length - 1)) &&
2774 +                            (breakinfo[breakno].addr == addr)))) {
2775 +                       breakinfo[breakno].enabled = 0;
2776 +                       breakinfo[breakno].type = 0UL;
2777 +               } else
2778 +                       continue;
2779 +               found++;
2780 +               if (type != WATCH_ACCESS)
2781 +                       break;
2782 +               else if (found == 2)
2783 +                       break;
2784 +               else
2785 +                       mask = HWCAP_IBR;
2786 +       }
2787 +
2788 +       if (type == WATCH_ACCESS && found == 1) {
2789 +               breakinfo[watch].enabled = 0;
2790 +               found = 0;
2791 +       }
2792 +
2793 +       mb();
2794 +       return found;
2795 +}
2796 +
2797 +int kgdb_arch_set_hw_breakpoint(unsigned long addr, int len,
2798 +                               enum kgdb_bptype type)
2799 +{
2800 +       return hardware_breakpoint(addr, len, type - '1', 1);
2801 +}
2802 +
2803 +int kgdb_arch_remove_hw_breakpoint(unsigned long addr, int len,
2804 +                                  enum kgdb_bptype type)
2805 +{
2806 +       return hardware_breakpoint(addr, len, type - '1', 0);
2807 +}
2808 +
2809 +int kgdb_remove_hw_break(unsigned long addr)
2810 +{
2811 +       return hardware_breakpoint(addr, 8, WATCH_INSTRUCTION, 0);
2812 +
2813 +}
2814 +
2815 +void kgdb_remove_all_hw_break(void)
2816 +{
2817 +       int i;
2818 +
2819 +       for (i = 0; i < HW_BREAKPOINT; i++)
2820 +               memset(&breakinfo[i], 0, sizeof(struct hw_breakpoint));
2821 +}
2822 +
2823 +int kgdb_set_hw_break(unsigned long addr)
2824 +{
2825 +       return hardware_breakpoint(addr, 8, WATCH_INSTRUCTION, 1);
2826 +}
2827 +
2828 +void kgdb_disable_hw_debug(struct pt_regs *regs)
2829 +{
2830 +       unsigned long hw_breakpoint_status;
2831 +
2832 +       hw_breakpoint_status = ia64_getreg(_IA64_REG_PSR);
2833 +       if (hw_breakpoint_status & IA64_PSR_DB)
2834 +               ia64_setreg(_IA64_REG_PSR_L,
2835 +                           hw_breakpoint_status ^ IA64_PSR_DB);
2836 +}
2837 +
2838 +volatile static struct smp_unw {
2839 +       struct unw_frame_info *unw;
2840 +       struct task_struct *task;
2841 +} smp_unw[NR_CPUS];
2842 +
2843 +static int inline kgdb_get_blocked_state(struct task_struct *p,
2844 +                                        struct unw_frame_info *unw)
2845 +{
2846 +       unsigned long ip;
2847 +       int count = 0;
2848 +
2849 +       unw_init_from_blocked_task(unw, p);
2850 +       ip = 0UL;
2851 +       do {
2852 +               if (unw_unwind(unw) < 0)
2853 +                       return -1;
2854 +               unw_get_ip(unw, &ip);
2855 +               if (!in_sched_functions(ip))
2856 +                       break;
2857 +       } while (count++ < 16);
2858 +
2859 +       if (!ip)
2860 +               return -1;
2861 +       else
2862 +               return 0;
2863 +}
2864 +
2865 +static void inline kgdb_wait(struct pt_regs *regs)
2866 +{
2867 +       unsigned long hw_breakpoint_status = ia64_getreg(_IA64_REG_PSR);
2868 +       if (hw_breakpoint_status & IA64_PSR_DB)
2869 +               ia64_setreg(_IA64_REG_PSR_L,
2870 +                           hw_breakpoint_status ^ IA64_PSR_DB);
2871 +       kgdb_nmihook(smp_processor_id(), regs);
2872 +       if (hw_breakpoint_status & IA64_PSR_DB)
2873 +               ia64_setreg(_IA64_REG_PSR_L, hw_breakpoint_status);
2874 +
2875 +       return;
2876 +}
2877 +
2878 +static void inline normalize(struct unw_frame_info *running,
2879 +                            struct pt_regs *regs)
2880 +{
2881 +       unsigned long sp;
2882 +
2883 +       do {
2884 +               unw_get_sp(running, &sp);
2885 +               if ((sp + 0x10) >= (unsigned long)regs)
2886 +                       break;
2887 +       } while (unw_unwind(running) >= 0);
2888 +
2889 +       return;
2890 +}
2891 +
2892 +static void kgdb_init_running(struct unw_frame_info *unw, void *data)
2893 +{
2894 +       struct pt_regs *regs;
2895 +
2896 +       regs = data;
2897 +       normalize(unw, regs);
2898 +       smp_unw[smp_processor_id()].unw = unw;
2899 +       kgdb_wait(regs);
2900 +}
2901 +
2902 +void kgdb_wait_ipi(struct pt_regs *regs)
2903 +{
2904 +       struct unw_frame_info unw;
2905 +
2906 +       smp_unw[smp_processor_id()].task = current;
2907 +
2908 +       if (user_mode(regs)) {
2909 +               smp_unw[smp_processor_id()].unw = (struct unw_frame_info *)1;
2910 +               kgdb_wait(regs);
2911 +       } else {
2912 +               if (current->state == TASK_RUNNING)
2913 +                       unw_init_running(kgdb_init_running, regs);
2914 +               else {
2915 +                       if (kgdb_get_blocked_state(current, &unw))
2916 +                               smp_unw[smp_processor_id()].unw =
2917 +                                   (struct unw_frame_info *)1;
2918 +                       else
2919 +                               smp_unw[smp_processor_id()].unw = &unw;
2920 +                       kgdb_wait(regs);
2921 +               }
2922 +       }
2923 +
2924 +       smp_unw[smp_processor_id()].unw = NULL;
2925 +       return;
2926 +}
2927 +
2928 +void kgdb_roundup_cpus(unsigned long flags)
2929 +{
2930 +       if (num_online_cpus() > 1)
2931 +               smp_send_nmi_allbutself();
2932 +}
2933 +
2934 +static volatile int kgdb_hwbreak_sstep[NR_CPUS];
2935 +
2936 +static int kgdb_notify(struct notifier_block *self, unsigned long cmd,
2937 +       void *ptr)
2938 +{
2939 +       struct die_args *args = ptr;
2940 +       struct pt_regs *regs = args->regs;
2941 +       unsigned long err = args->err;
2942 +
2943 +       switch (cmd) {
2944 +       default:
2945 +               return NOTIFY_DONE;
2946 +       case DIE_PAGE_FAULT_NO_CONTEXT:
2947 +               if (atomic_read(&debugger_active) && kgdb_may_fault) {
2948 +                       kgdb_fault_longjmp(kgdb_fault_jmp_regs);
2949 +                       return NOTIFY_STOP;
2950 +               }
2951 +               break;
2952 +       case DIE_BREAK:
2953 +               if (user_mode(regs) || err == 0x80001)
2954 +                       return NOTIFY_DONE;
2955 +               break;
2956 +       case DIE_FAULT:
2957 +               if (user_mode(regs))
2958 +                       return NOTIFY_DONE;
2959 +               else if (err == 36 && kgdb_hwbreak_sstep[smp_processor_id()]) {
2960 +                       kgdb_hwbreak_sstep[smp_processor_id()] = 0;
2961 +                       regs->cr_ipsr &= ~IA64_PSR_SS;
2962 +                       return NOTIFY_STOP;
2963 +               }
2964 +       case DIE_MCA_MONARCH_PROCESS:
2965 +       case DIE_INIT_MONARCH_PROCESS:
2966 +               break;
2967 +       }
2968 +
2969 +       kgdb_handle_exception(args->trapnr, args->signr, args->err, regs);
2970 +       return NOTIFY_STOP;
2971 +}
2972 +
2973 +static struct notifier_block kgdb_notifier = {
2974 +       .notifier_call = kgdb_notify,
2975 +};
2976 +
2977 +int kgdb_arch_init(void)
2978 +{
2979 +       atomic_notifier_chain_register(&ia64die_chain, &kgdb_notifier);
2980 +       return 0;
2981 +}
2982 +
2983 +static void do_kgdb_handle_exception(struct unw_frame_info *, void *data);
2984 +
2985 +struct kgdb_state {
2986 +       int e_vector;
2987 +       int signo;
2988 +       unsigned long err_code;
2989 +       struct pt_regs *regs;
2990 +       struct unw_frame_info *unw;
2991 +       char *inbuf;
2992 +       char *outbuf;
2993 +       int unwind;
2994 +       int ret;
2995 +};
2996 +
2997 +static void inline kgdb_pc(struct pt_regs *regs, unsigned long pc)
2998 +{
2999 +       regs->cr_iip = pc & ~0xf;
3000 +       ia64_psr(regs)->ri = pc & 0x3;
3001 +       return;
3002 +}
3003 +
3004 +int kgdb_arch_handle_exception(int e_vector, int signo,
3005 +                              int err_code, char *remcom_in_buffer,
3006 +                              char *remcom_out_buffer,
3007 +                              struct pt_regs *linux_regs)
3008 +{
3009 +       struct kgdb_state info;
3010 +
3011 +       info.e_vector = e_vector;
3012 +       info.signo = signo;
3013 +       info.err_code = err_code;
3014 +       info.unw = (void *)0;
3015 +       info.inbuf = remcom_in_buffer;
3016 +       info.outbuf = remcom_out_buffer;
3017 +       info.unwind = 0;
3018 +       info.ret = -1;
3019 +
3020 +       if (remcom_in_buffer[0] == 'c' || remcom_in_buffer[0] == 's') {
3021 +               info.regs = linux_regs;
3022 +               do_kgdb_handle_exception(NULL, &info);
3023 +       } else if (kgdb_usethread == current) {
3024 +               info.regs = linux_regs;
3025 +               info.unwind = 1;
3026 +               unw_init_running(do_kgdb_handle_exception, &info);
3027 +       } else if (kgdb_usethread->state != TASK_RUNNING) {
3028 +               struct unw_frame_info unw_info;
3029 +
3030 +               if (kgdb_get_blocked_state(kgdb_usethread, &unw_info)) {
3031 +                       info.ret = 1;
3032 +                       goto bad;
3033 +               }
3034 +               info.regs = NULL;
3035 +               do_kgdb_handle_exception(&unw_info, &info);
3036 +       } else {
3037 +               int i;
3038 +
3039 +               for (i = 0; i < NR_CPUS; i++)
3040 +                       if (smp_unw[i].task == kgdb_usethread && smp_unw[i].unw
3041 +                           && smp_unw[i].unw != (struct unw_frame_info *)1) {
3042 +                               info.regs = NULL;
3043 +                               do_kgdb_handle_exception(smp_unw[i].unw, &info);
3044 +                               break;
3045 +                       } else {
3046 +                               info.ret = 1;
3047 +                               goto bad;
3048 +                       }
3049 +       }
3050 +
3051 +      bad:
3052 +       if (info.ret != -1 && remcom_in_buffer[0] == 'p') {
3053 +               unsigned long bad = 0xbad4badbadbadbadUL;
3054 +
3055 +               printk("kgdb_arch_handle_exception: p packet bad (%s)\n",
3056 +                      remcom_in_buffer);
3057 +               kgdb_mem2hex((char *)&bad, remcom_out_buffer, sizeof(bad));
3058 +               remcom_out_buffer[sizeof(bad) * 2] = 0;
3059 +               info.ret = -1;
3060 +       }
3061 +       return info.ret;
3062 +}
3063 +
3064 +/*
3065 + * This is done because I evidently made an incorrect 'p' encoding
3066 + * when my patch for gdb was committed. It was later corrected. This
3067 + * check supports both my wrong encoding of the register number and
3068 + * the correct encoding. Eventually this should be eliminated and
3069 + * kgdb_hex2long should be demarshalling the regnum.
3070 + */
3071 +static inline int check_packet(unsigned int regnum, char *packet)
3072 +{
3073 +       static int check_done, swap;
3074 +       unsigned long reglong;
3075 +
3076 +       if (likely(check_done)) {
3077 +               if (swap) {
3078 +                       kgdb_hex2long(&packet, &reglong);
3079 +                       regnum = (int) reglong;
3080 +               }
3081 +
3082 +       } else {
3083 +               if (regnum > NUM_REGS) {
3084 +                       kgdb_hex2long(&packet, &reglong);
3085 +                       regnum = (int) reglong;
3086 +                       swap = 1;
3087 +               }
3088 +               check_done = 1;
3089 +       }
3090 +       return regnum;
3091 +}
3092 +
3093 +static void do_kgdb_handle_exception(struct unw_frame_info *unw_info,
3094 +       void *data)
3095 +{
3096 +       long addr;
3097 +       char *ptr;
3098 +       unsigned long newPC;
3099 +       int e_vector, signo;
3100 +       unsigned long err_code;
3101 +       struct pt_regs *linux_regs;
3102 +       struct kgdb_state *info;
3103 +       char *remcom_in_buffer, *remcom_out_buffer;
3104 +
3105 +       info = data;
3106 +       info->unw = unw_info;
3107 +       e_vector = info->e_vector;
3108 +       signo = info->signo;
3109 +       err_code = info->err_code;
3110 +       remcom_in_buffer = info->inbuf;
3111 +       remcom_out_buffer = info->outbuf;
3112 +       linux_regs = info->regs;
3113 +
3114 +       if (info->unwind)
3115 +               normalize(unw_info, linux_regs);
3116 +
3117 +       switch (remcom_in_buffer[0]) {
3118 +       case 'p':
3119 +               {
3120 +                       unsigned int regnum;
3121 +
3122 +                       kgdb_hex2mem(&remcom_in_buffer[1], (char *)&regnum,
3123 +                                    sizeof(regnum));
3124 +                       regnum = check_packet(regnum, &remcom_in_buffer[1]);
3125 +                       if (regnum >= NUM_REGS) {
3126 +                               remcom_out_buffer[0] = 'E';
3127 +                               remcom_out_buffer[1] = 0;
3128 +                       } else
3129 +                               kgdb_get_reg(remcom_out_buffer, regnum,
3130 +                                            unw_info, linux_regs);
3131 +                       break;
3132 +               }
3133 +       case 'P':
3134 +               {
3135 +                       unsigned int regno;
3136 +                       long v;
3137 +                       char *ptr;
3138 +
3139 +                       ptr = &remcom_in_buffer[1];
3140 +                       if ((!kgdb_usethread || kgdb_usethread == current) &&
3141 +                           kgdb_hex2long(&ptr, &v) &&
3142 +                           *ptr++ == '=' && (v >= 0)) {
3143 +                               regno = (unsigned int)v;
3144 +                               regno = (regno >= NUM_REGS ? 0 : regno);
3145 +                               kgdb_put_reg(ptr, remcom_out_buffer, regno,
3146 +                                            unw_info, linux_regs);
3147 +                       } else
3148 +                               strcpy(remcom_out_buffer, "E01");
3149 +                       break;
3150 +               }
3151 +       case 'c':
3152 +       case 's':
3153 +               if (e_vector == TRAP_BRKPT && err_code == KGDBBREAKNUM) {
3154 +                       if (ia64_psr(linux_regs)->ri < 2)
3155 +                               kgdb_pc(linux_regs, linux_regs->cr_iip +
3156 +                                       ia64_psr(linux_regs)->ri + 1);
3157 +                       else
3158 +                               kgdb_pc(linux_regs, linux_regs->cr_iip + 16);
3159 +               }
3160 +
3161 +               /* try to read optional parameter, pc unchanged if no parm */
3162 +               ptr = &remcom_in_buffer[1];
3163 +               if (kgdb_hex2long(&ptr, &addr)) {
3164 +                       linux_regs->cr_iip = addr;
3165 +               }
3166 +               newPC = linux_regs->cr_iip;
3167 +
3168 +               /* clear the trace bit */
3169 +               linux_regs->cr_ipsr &= ~IA64_PSR_SS;
3170 +
3171 +               atomic_set(&cpu_doing_single_step, -1);
3172 +
3173 +               /* set the trace bit if we're stepping or took a hardware break */
3174 +               if (remcom_in_buffer[0] == 's' || e_vector == TRAP_HWBKPT) {
3175 +                       linux_regs->cr_ipsr |= IA64_PSR_SS;
3176 +                       debugger_step = 1;
3177 +                       if (kgdb_contthread)
3178 +                               atomic_set(&cpu_doing_single_step,
3179 +                                          smp_processor_id());
3180 +               }
3181 +
3182 +               kgdb_correct_hw_break();
3183 +
3184 +               /* if not hardware breakpoint, then reenable them */
3185 +               if (e_vector != TRAP_HWBKPT)
3186 +                       linux_regs->cr_ipsr |= IA64_PSR_DB;
3187 +               else {
3188 +                       kgdb_hwbreak_sstep[smp_processor_id()] = 1;
3189 +                       linux_regs->cr_ipsr &= ~IA64_PSR_DB;
3190 +               }
3191 +
3192 +               info->ret = 0;
3193 +               break;
3194 +       default:
3195 +               break;
3196 +       }
3197 +
3198 +       return;
3199 +}
3200 +
3201 +struct kgdb_arch arch_kgdb_ops = {
3202 +       .set_hw_breakpoint = kgdb_arch_set_hw_breakpoint,
3203 +       .remove_hw_breakpoint = kgdb_arch_remove_hw_breakpoint,
3204 +       .gdb_bpt_instr = {0xcc},
3205 +       .flags = KGDB_HW_BREAKPOINT,
3206 +};
3207 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/kernel/process.c linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/process.c
3208 --- linux-2.6.18-53.1.14/arch/ia64/kernel/process.c     2008-03-06 05:55:00.000000000 +0300
3209 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/process.c        2008-06-10 15:39:39.000000000 +0400
3210 @@ -463,6 +463,9 @@ copy_thread (int nr, unsigned long clone
3211          */
3212         child_ptregs->cr_ipsr = ((child_ptregs->cr_ipsr | IA64_PSR_BITS_TO_SET)
3213                                  & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_PP | IA64_PSR_UP));
3214 +#ifdef CONFIG_KGDB
3215 +       child_ptregs->cr_ipsr |= IA64_PSR_DB;
3216 +#endif
3217  
3218         /*
3219          * NOTE: The calling convention considers all floating point
3220 @@ -691,6 +694,9 @@ kernel_thread (int (*fn)(void *), void *
3221         regs.pt.r11 = (unsigned long) arg;      /* 2nd argument */
3222         /* Preserve PSR bits, except for bits 32-34 and 37-45, which we can't read.  */
3223         regs.pt.cr_ipsr = ia64_getreg(_IA64_REG_PSR) | IA64_PSR_BN;
3224 +#ifdef CONFIG_KGDB
3225 +       regs.pt.cr_ipsr |= IA64_PSR_DB;
3226 +#endif
3227         regs.pt.cr_ifs = 1UL << 63;             /* mark as valid, empty frame */
3228         regs.sw.ar_fpsr = regs.pt.ar_fpsr = ia64_getreg(_IA64_REG_AR_FPSR);
3229         regs.sw.ar_bspstore = (unsigned long) current + IA64_RBS_OFFSET;
3230 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/kernel/smp.c linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/smp.c
3231 --- linux-2.6.18-53.1.14/arch/ia64/kernel/smp.c 2008-03-06 05:54:27.000000000 +0300
3232 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/smp.c    2008-06-10 15:38:32.000000000 +0400
3233 @@ -48,6 +48,7 @@
3234  #include <asm/tlbflush.h>
3235  #include <asm/unistd.h>
3236  #include <asm/mca.h>
3237 +#include <linux/kgdb.h>
3238  
3239  /*
3240   * Structure and data for smp_call_function(). This is designed to minimise static memory
3241 @@ -68,6 +69,9 @@ static volatile struct call_data_struct 
3242  #define IPI_CALL_FUNC          0
3243  #define IPI_CPU_STOP           1
3244  #define IPI_KDUMP_CPU_STOP     3
3245 +#ifdef CONFIG_KGDB
3246 +#define        IPI_KGDB_INTERRUPT      2
3247 +#endif
3248  
3249  /* This needs to be cacheline aligned because it is written to by *other* CPUs.  */
3250  static DEFINE_PER_CPU(u64, ipi_operation) ____cacheline_aligned;
3251 @@ -185,6 +189,11 @@ handle_IPI (int irq, void *dev_id, struc
3252                               case IPI_CPU_STOP:
3253                                 stop_this_cpu();
3254                                 break;
3255 +#ifdef CONFIG_KGDB
3256 +                             case IPI_KGDB_INTERRUPT:
3257 +                               kgdb_wait_ipi(regs);
3258 +                               break;
3259 +#endif
3260  #ifdef CONFIG_CRASH_DUMP
3261                               case IPI_KDUMP_CPU_STOP:
3262                                 unw_init_running(kdump_cpu_freeze, NULL);
3263 @@ -359,6 +368,14 @@ smp_call_function_single (int cpuid, voi
3264  }
3265  EXPORT_SYMBOL(smp_call_function_single);
3266  
3267 +#ifdef CONFIG_KGDB
3268 +void
3269 +smp_send_nmi_allbutself(void)
3270 +{
3271 +       send_IPI_allbutself(IPI_KGDB_INTERRUPT);
3272 +}
3273 +#endif
3274 +
3275  /*
3276   * this function sends a 'generic call function' IPI to all other CPUs
3277   * in the system.
3278 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/kernel/traps.c linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/traps.c
3279 --- linux-2.6.18-53.1.14/arch/ia64/kernel/traps.c       2008-03-06 05:54:44.000000000 +0300
3280 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/traps.c  2008-06-10 15:38:32.000000000 +0400
3281 @@ -200,8 +200,12 @@ __kprobes ia64_bad_break (unsigned long 
3282                 break;
3283  
3284               default:
3285 -               if (break_num < 0x40000 || break_num > 0x100000)
3286 +               if (break_num < 0x40000 || break_num > 0x100000) {
3287 +                       if (notify_die(DIE_BREAK, "bad break", regs,
3288 +                               break_num, TRAP_BRKPT, SIGTRAP) == NOTIFY_STOP)
3289 +                               return;
3290                         die_if_kernel("Bad break", regs, break_num);
3291 +               }
3292  
3293                 if (break_num < 0x80000) {
3294                         sig = SIGILL; code = __ILL_BREAK;
3295 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/kernel/unwind.c linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/unwind.c
3296 --- linux-2.6.18-53.1.14/arch/ia64/kernel/unwind.c      2006-09-20 07:42:06.000000000 +0400
3297 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/kernel/unwind.c 2008-06-10 15:39:39.000000000 +0400
3298 @@ -72,10 +72,68 @@
3299  # define STAT(x...)
3300  #endif
3301  
3302 +#ifdef CONFIG_KGDB
3303 +#define        KGDB_EARLY_SIZE 100
3304 +static struct unw_reg_state __initdata kgdb_reg_state[KGDB_EARLY_SIZE];
3305 +static struct unw_labeled_state __initdata kgdb_labeled_state[KGDB_EARLY_SIZE];
3306 +void __initdata *kgdb_reg_state_free, __initdata *kgdb_labeled_state_free;
3307 +
3308 +static void __init
3309 +kgdb_malloc_init(void)
3310 +{
3311 +       int i;
3312 +
3313 +       kgdb_reg_state_free = kgdb_reg_state;
3314 +       for (i = 1; i < KGDB_EARLY_SIZE; i++) {
3315 +               *((unsigned long *) &kgdb_reg_state[i]) = (unsigned long) kgdb_reg_state_free;
3316 +               kgdb_reg_state_free = &kgdb_reg_state[i];
3317 +       }
3318 +
3319 +       kgdb_labeled_state_free = kgdb_labeled_state;
3320 +       for (i = 1; i < KGDB_EARLY_SIZE; i++) {
3321 +               *((unsigned long *) &kgdb_labeled_state[i]) =
3322 +                       (unsigned long) kgdb_labeled_state_free;
3323 +               kgdb_labeled_state_free = &kgdb_labeled_state[i];
3324 +       }
3325 +
3326 +}
3327 +
3328 +static void * __init
3329 +kgdb_malloc(void **mem)
3330 +{
3331 +       void *p;
3332 +
3333 +       p = *mem;
3334 +       *mem = *((void **) p);
3335 +       return p;
3336 +}
3337 +
3338 +static void __init
3339 +kgdb_free(void **mem, void *p)
3340 +{
3341 +       *((void **)p) = *mem;
3342 +       *mem = p;
3343 +}
3344 +
3345 +#define alloc_reg_state()      (!malloc_sizes[0].cs_cachep ?           \
3346 +               kgdb_malloc(&kgdb_reg_state_free) :                     \
3347 +               kmalloc(sizeof(struct unw_reg_state), GFP_ATOMIC))
3348 +#define free_reg_state(usr)    (!malloc_sizes[0].cs_cachep ?           \
3349 +               kgdb_free(&kgdb_reg_state_free, usr) :                  \
3350 +               kfree(usr))
3351 +#define alloc_labeled_state()  (!malloc_sizes[0].cs_cachep ?           \
3352 +               kgdb_malloc(&kgdb_labeled_state_free) :                 \
3353 +               kmalloc(sizeof(struct unw_labeled_state), GFP_ATOMIC))
3354 +#define free_labeled_state(usr)        (!malloc_sizes[0].cs_cachep ?           \
3355 +               kgdb_free(&kgdb_labeled_state_free, usr) :              \
3356 +               kfree(usr))
3357 +
3358 +#else
3359  #define alloc_reg_state()      kmalloc(sizeof(struct unw_reg_state), GFP_ATOMIC)
3360  #define free_reg_state(usr)    kfree(usr)
3361  #define alloc_labeled_state()  kmalloc(sizeof(struct unw_labeled_state), GFP_ATOMIC)
3362  #define free_labeled_state(usr)        kfree(usr)
3363 +#endif
3364  
3365  typedef unsigned long unw_word;
3366  typedef unsigned char unw_hash_index_t;
3367 @@ -238,6 +296,24 @@ static struct {
3368  #endif
3369  };
3370  
3371 +#ifdef CONFIG_KGDB
3372 +/*
3373 + * This makes it safe to call breakpoint() very early
3374 + * in setup_arch providing:
3375 + *     1) breakpoint isn't called between lines in cpu_init
3376 + *        where init_mm.mm_count is incremented and ia64_mmu_init
3377 + *        is called.  Otherwise the test below is invalid.
3378 + *     2) the memory examined doesn't result in tlbmiss.
3379 + */
3380 +static unsigned long inline kgdb_unimpl_va_mask(void)
3381 +{
3382 +       if (atomic_read(&init_mm.mm_count) > 1)
3383 +               return local_cpu_data->unimpl_va_mask;
3384 +       else
3385 +               return 0UL;
3386 +}
3387 +#endif
3388 +
3389  static inline int
3390  read_only (void *addr)
3391  {
3392 @@ -1786,7 +1862,11 @@ run_script (struct unw_script *script, s
3393  
3394                       case UNW_INSN_LOAD:
3395  #ifdef UNW_DEBUG
3396 +#ifdef CONFIG_KGDB
3397 +                       if ((s[val] & (kgdb_unimpl_va_mask() | 0x7)) != 0
3398 +#else
3399                         if ((s[val] & (local_cpu_data->unimpl_va_mask | 0x7)) != 0
3400 +#endif
3401                             || s[val] < TASK_SIZE)
3402                         {
3403                                 UNW_DPRINT(0, "unwind.%s: rejecting bad psp=0x%lx\n",
3404 @@ -1821,7 +1901,11 @@ find_save_locs (struct unw_frame_info *i
3405         struct unw_script *scr;
3406         unsigned long flags = 0;
3407  
3408 +#ifdef CONFIG_KGDB
3409 +       if ((info->ip & (kgdb_unimpl_va_mask() | 0xf)) || info->ip < TASK_SIZE) {
3410 +#else
3411         if ((info->ip & (local_cpu_data->unimpl_va_mask | 0xf)) || info->ip < TASK_SIZE) {
3412 +#endif
3413                 /* don't let obviously bad addresses pollute the cache */
3414                 /* FIXME: should really be level 0 but it occurs too often. KAO */
3415                 UNW_DPRINT(1, "unwind.%s: rejecting bad ip=0x%lx\n", __FUNCTION__, info->ip);
3416 @@ -2249,6 +2333,9 @@ unw_init (void)
3417  
3418         init_unwind_table(&unw.kernel_table, "kernel", KERNEL_START, (unsigned long) __gp,
3419                           __start_unwind, __end_unwind);
3420 +#ifdef CONFIG_KGDB
3421 +       kgdb_malloc_init();
3422 +#endif
3423  }
3424  
3425  /*
3426 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/mm/extable.c linux-2.6.18-53.1.14.kgdb/arch/ia64/mm/extable.c
3427 --- linux-2.6.18-53.1.14/arch/ia64/mm/extable.c 2006-09-20 07:42:06.000000000 +0400
3428 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/mm/extable.c    2008-06-10 15:38:32.000000000 +0400
3429 @@ -6,6 +6,7 @@
3430   */
3431  
3432  #include <linux/sort.h>
3433 +#include <linux/kgdb.h>
3434  
3435  #include <asm/uaccess.h>
3436  #include <asm/module.h>
3437 @@ -73,6 +74,11 @@ search_extable (const struct exception_t
3438                  else
3439                          last = mid - 1;
3440          }
3441 +#ifdef CONFIG_KGDB
3442 +       if (atomic_read(&debugger_active) && kgdb_may_fault)
3443 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
3444 +               /* Not reached. */
3445 +#endif
3446          return NULL;
3447  }
3448  
3449 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ia64/mm/fault.c linux-2.6.18-53.1.14.kgdb/arch/ia64/mm/fault.c
3450 --- linux-2.6.18-53.1.14/arch/ia64/mm/fault.c   2006-09-20 07:42:06.000000000 +0400
3451 +++ linux-2.6.18-53.1.14.kgdb/arch/ia64/mm/fault.c      2008-06-10 15:38:32.000000000 +0400
3452 @@ -266,6 +266,10 @@ ia64_do_page_fault (unsigned long addres
3453          */
3454         bust_spinlocks(1);
3455  
3456 +       if (notify_die(DIE_PAGE_FAULT_NO_CONTEXT, "no context", regs,
3457 +                       isr, 14, SIGSEGV) == NOTIFY_STOP)
3458 +               return;
3459 +
3460         if (address < PAGE_SIZE)
3461                 printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference (address %016lx)\n", address);
3462         else
3463 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/Kconfig.debug linux-2.6.18-53.1.14.kgdb/arch/mips/Kconfig.debug
3464 --- linux-2.6.18-53.1.14/arch/mips/Kconfig.debug        2006-09-20 07:42:06.000000000 +0400
3465 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/Kconfig.debug   2008-06-10 15:38:24.000000000 +0400
3466 @@ -37,25 +37,6 @@ config DEBUG_STACK_USAGE
3467  
3468           This option will slow down process creation somewhat.
3469  
3470 -config KGDB
3471 -       bool "Remote GDB kernel debugging"
3472 -       depends on DEBUG_KERNEL
3473 -       select DEBUG_INFO
3474 -       help
3475 -         If you say Y here, it will be possible to remotely debug the MIPS
3476 -         kernel using gdb. This enlarges your kernel image disk size by
3477 -         several megabytes and requires a machine with more than 16 MB,
3478 -         better 32 MB RAM to avoid excessive linking time. This is only
3479 -         useful for kernel hackers. If unsure, say N.
3480 -
3481 -config GDB_CONSOLE
3482 -       bool "Console output to GDB"
3483 -       depends on KGDB
3484 -       help
3485 -         If you are using GDB for remote debugging over a serial port and
3486 -         would like kernel messages to be formatted into GDB $O packets so
3487 -         that GDB prints them as program output, say 'Y'.
3488 -
3489  config SB1XXX_CORELIS
3490         bool "Corelis Debugger"
3491         depends on SIBYTE_SB1xxx_SOC
3492 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/kernel/Makefile linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/Makefile
3493 --- linux-2.6.18-53.1.14/arch/mips/kernel/Makefile      2006-09-20 07:42:06.000000000 +0400
3494 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/Makefile 2008-06-10 15:38:24.000000000 +0400
3495 @@ -59,7 +59,8 @@ obj-$(CONFIG_MIPS32_COMPAT)   += linux32.o
3496  obj-$(CONFIG_MIPS32_N32)       += binfmt_elfn32.o scall64-n32.o signal_n32.o
3497  obj-$(CONFIG_MIPS32_O32)       += binfmt_elfo32.o scall64-o32.o ptrace32.o
3498  
3499 -obj-$(CONFIG_KGDB)             += gdb-low.o gdb-stub.o
3500 +obj-$(CONFIG_KGDB)             += kgdb_handler.o kgdb.o kgdb-jmp.o     \
3501 +                                       kgdb-setjmp.o
3502  obj-$(CONFIG_PROC_FS)          += proc.o
3503  
3504  obj-$(CONFIG_64BIT)            += cpu-bugs64.o
3505 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/kernel/gdb-low.S linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/gdb-low.S
3506 --- linux-2.6.18-53.1.14/arch/mips/kernel/gdb-low.S     2006-09-20 07:42:06.000000000 +0400
3507 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/gdb-low.S        1970-01-01 03:00:00.000000000 +0300
3508 @@ -1,394 +0,0 @@
3509 -/*
3510 - * gdb-low.S contains the low-level trap handler for the GDB stub.
3511 - *
3512 - * Copyright (C) 1995 Andreas Busse
3513 - */
3514 -#include <linux/sys.h>
3515 -
3516 -#include <asm/asm.h>
3517 -#include <asm/errno.h>
3518 -#include <asm/irqflags.h>
3519 -#include <asm/mipsregs.h>
3520 -#include <asm/regdef.h>
3521 -#include <asm/stackframe.h>
3522 -#include <asm/gdb-stub.h>
3523 -
3524 -#ifdef CONFIG_32BIT
3525 -#define DMFC0  mfc0
3526 -#define DMTC0  mtc0
3527 -#define LDC1   lwc1
3528 -#define SDC1   lwc1
3529 -#endif
3530 -#ifdef CONFIG_64BIT
3531 -#define DMFC0  dmfc0
3532 -#define DMTC0  dmtc0
3533 -#define LDC1   ldc1
3534 -#define SDC1   ldc1
3535 -#endif
3536 -
3537 -/*
3538 - * [jsun] We reserves about 2x GDB_FR_SIZE in stack.  The lower (addressed)
3539 - * part is used to store registers and passed to exception handler.
3540 - * The upper part is reserved for "call func" feature where gdb client
3541 - * saves some of the regs, setups call frame and passes args.
3542 - *
3543 - * A trace shows about 200 bytes are used to store about half of all regs.
3544 - * The rest should be big enough for frame setup and passing args.
3545 - */
3546 -
3547 -/*
3548 - * The low level trap handler
3549 - */
3550 -               .align  5
3551 -               NESTED(trap_low, GDB_FR_SIZE, sp)
3552 -               .set    noat
3553 -               .set    noreorder
3554 -
3555 -               mfc0    k0, CP0_STATUS
3556 -               sll     k0, 3                   /* extract cu0 bit */
3557 -               bltz    k0, 1f
3558 -               move    k1, sp
3559 -
3560 -               /*
3561 -                * Called from user mode, go somewhere else.
3562 -                */
3563 -               mfc0    k0, CP0_CAUSE
3564 -               andi    k0, k0, 0x7c
3565 -#ifdef CONFIG_64BIT
3566 -               dsll    k0, k0, 1
3567 -#endif
3568 -               PTR_L   k1, saved_vectors(k0)
3569 -               jr      k1
3570 -               nop
3571 -1:
3572 -               move    k0, sp
3573 -               PTR_SUBU sp, k1, GDB_FR_SIZE*2  # see comment above
3574 -               LONG_S  k0, GDB_FR_REG29(sp)
3575 -               LONG_S  $2, GDB_FR_REG2(sp)
3576 -
3577 -/*
3578 - * First save the CP0 and special registers
3579 - */
3580 -
3581 -               mfc0    v0, CP0_STATUS
3582 -               LONG_S  v0, GDB_FR_STATUS(sp)
3583 -               mfc0    v0, CP0_CAUSE
3584 -               LONG_S  v0, GDB_FR_CAUSE(sp)
3585 -               DMFC0   v0, CP0_EPC
3586 -               LONG_S  v0, GDB_FR_EPC(sp)
3587 -               DMFC0   v0, CP0_BADVADDR
3588 -               LONG_S  v0, GDB_FR_BADVADDR(sp)
3589 -               mfhi    v0
3590 -               LONG_S  v0, GDB_FR_HI(sp)
3591 -               mflo    v0
3592 -               LONG_S  v0, GDB_FR_LO(sp)
3593 -
3594 -/*
3595 - * Now the integer registers
3596 - */
3597 -
3598 -               LONG_S  zero, GDB_FR_REG0(sp)           /* I know... */
3599 -               LONG_S  $1, GDB_FR_REG1(sp)
3600 -               /* v0 already saved */
3601 -               LONG_S  $3, GDB_FR_REG3(sp)
3602 -               LONG_S  $4, GDB_FR_REG4(sp)
3603 -               LONG_S  $5, GDB_FR_REG5(sp)
3604 -               LONG_S  $6, GDB_FR_REG6(sp)
3605 -               LONG_S  $7, GDB_FR_REG7(sp)
3606 -               LONG_S  $8, GDB_FR_REG8(sp)
3607 -               LONG_S  $9, GDB_FR_REG9(sp)
3608 -               LONG_S  $10, GDB_FR_REG10(sp)
3609 -               LONG_S  $11, GDB_FR_REG11(sp)
3610 -               LONG_S  $12, GDB_FR_REG12(sp)
3611 -               LONG_S  $13, GDB_FR_REG13(sp)
3612 -               LONG_S  $14, GDB_FR_REG14(sp)
3613 -               LONG_S  $15, GDB_FR_REG15(sp)
3614 -               LONG_S  $16, GDB_FR_REG16(sp)
3615 -               LONG_S  $17, GDB_FR_REG17(sp)
3616 -               LONG_S  $18, GDB_FR_REG18(sp)
3617 -               LONG_S  $19, GDB_FR_REG19(sp)
3618 -               LONG_S  $20, GDB_FR_REG20(sp)
3619 -               LONG_S  $21, GDB_FR_REG21(sp)
3620 -               LONG_S  $22, GDB_FR_REG22(sp)
3621 -               LONG_S  $23, GDB_FR_REG23(sp)
3622 -               LONG_S  $24, GDB_FR_REG24(sp)
3623 -               LONG_S  $25, GDB_FR_REG25(sp)
3624 -               LONG_S  $26, GDB_FR_REG26(sp)
3625 -               LONG_S  $27, GDB_FR_REG27(sp)
3626 -               LONG_S  $28, GDB_FR_REG28(sp)
3627 -               /* sp already saved */
3628 -               LONG_S  $30, GDB_FR_REG30(sp)
3629 -               LONG_S  $31, GDB_FR_REG31(sp)
3630 -
3631 -               CLI                             /* disable interrupts */
3632 -               TRACE_IRQS_OFF
3633 -
3634 -/*
3635 - * Followed by the floating point registers
3636 - */
3637 -               mfc0    v0, CP0_STATUS          /* FPU enabled? */
3638 -               srl     v0, v0, 16
3639 -               andi    v0, v0, (ST0_CU1 >> 16)
3640 -
3641 -               beqz    v0,2f                   /* disabled, skip */
3642 -                nop
3643 -
3644 -               SDC1    $0, GDB_FR_FPR0(sp)
3645 -               SDC1    $1, GDB_FR_FPR1(sp)
3646 -               SDC1    $2, GDB_FR_FPR2(sp)
3647 -               SDC1    $3, GDB_FR_FPR3(sp)
3648 -               SDC1    $4, GDB_FR_FPR4(sp)
3649 -               SDC1    $5, GDB_FR_FPR5(sp)
3650 -               SDC1    $6, GDB_FR_FPR6(sp)
3651 -               SDC1    $7, GDB_FR_FPR7(sp)
3652 -               SDC1    $8, GDB_FR_FPR8(sp)
3653 -               SDC1    $9, GDB_FR_FPR9(sp)
3654 -               SDC1    $10, GDB_FR_FPR10(sp)
3655 -               SDC1    $11, GDB_FR_FPR11(sp)
3656 -               SDC1    $12, GDB_FR_FPR12(sp)
3657 -               SDC1    $13, GDB_FR_FPR13(sp)
3658 -               SDC1    $14, GDB_FR_FPR14(sp)
3659 -               SDC1    $15, GDB_FR_FPR15(sp)
3660 -               SDC1    $16, GDB_FR_FPR16(sp)
3661 -               SDC1    $17, GDB_FR_FPR17(sp)
3662 -               SDC1    $18, GDB_FR_FPR18(sp)
3663 -               SDC1    $19, GDB_FR_FPR19(sp)
3664 -               SDC1    $20, GDB_FR_FPR20(sp)
3665 -               SDC1    $21, GDB_FR_FPR21(sp)
3666 -               SDC1    $22, GDB_FR_FPR22(sp)
3667 -               SDC1    $23, GDB_FR_FPR23(sp)
3668 -               SDC1    $24, GDB_FR_FPR24(sp)
3669 -               SDC1    $25, GDB_FR_FPR25(sp)
3670 -               SDC1    $26, GDB_FR_FPR26(sp)
3671 -               SDC1    $27, GDB_FR_FPR27(sp)
3672 -               SDC1    $28, GDB_FR_FPR28(sp)
3673 -               SDC1    $29, GDB_FR_FPR29(sp)
3674 -               SDC1    $30, GDB_FR_FPR30(sp)
3675 -               SDC1    $31, GDB_FR_FPR31(sp)
3676 -
3677 -/*
3678 - * FPU control registers
3679 - */
3680 -
3681 -               cfc1    v0, CP1_STATUS
3682 -               LONG_S  v0, GDB_FR_FSR(sp)
3683 -               cfc1    v0, CP1_REVISION
3684 -               LONG_S  v0, GDB_FR_FIR(sp)
3685 -
3686 -/*
3687 - * Current stack frame ptr
3688 - */
3689 -
3690 -2:
3691 -               LONG_S  sp, GDB_FR_FRP(sp)
3692 -
3693 -/*
3694 - * CP0 registers (R4000/R4400 unused registers skipped)
3695 - */
3696 -
3697 -               mfc0    v0, CP0_INDEX
3698 -               LONG_S  v0, GDB_FR_CP0_INDEX(sp)
3699 -               mfc0    v0, CP0_RANDOM
3700 -               LONG_S  v0, GDB_FR_CP0_RANDOM(sp)
3701 -               DMFC0   v0, CP0_ENTRYLO0
3702 -               LONG_S  v0, GDB_FR_CP0_ENTRYLO0(sp)
3703 -               DMFC0   v0, CP0_ENTRYLO1
3704 -               LONG_S  v0, GDB_FR_CP0_ENTRYLO1(sp)
3705 -               DMFC0   v0, CP0_CONTEXT
3706 -               LONG_S  v0, GDB_FR_CP0_CONTEXT(sp)
3707 -               mfc0    v0, CP0_PAGEMASK
3708 -               LONG_S  v0, GDB_FR_CP0_PAGEMASK(sp)
3709 -               mfc0    v0, CP0_WIRED
3710 -               LONG_S  v0, GDB_FR_CP0_WIRED(sp)
3711 -               DMFC0   v0, CP0_ENTRYHI
3712 -               LONG_S  v0, GDB_FR_CP0_ENTRYHI(sp)
3713 -               mfc0    v0, CP0_PRID
3714 -               LONG_S  v0, GDB_FR_CP0_PRID(sp)
3715 -
3716 -               .set    at
3717 -
3718 -/*
3719 - * Continue with the higher level handler
3720 - */
3721 -
3722 -               move    a0,sp
3723 -
3724 -               jal     handle_exception
3725 -                nop
3726 -
3727 -/*
3728 - * Restore all writable registers, in reverse order
3729 - */
3730 -
3731 -               .set    noat
3732 -
3733 -               LONG_L  v0, GDB_FR_CP0_ENTRYHI(sp)
3734 -               LONG_L  v1, GDB_FR_CP0_WIRED(sp)
3735 -               DMTC0   v0, CP0_ENTRYHI
3736 -               mtc0    v1, CP0_WIRED
3737 -               LONG_L  v0, GDB_FR_CP0_PAGEMASK(sp)
3738 -               LONG_L  v1, GDB_FR_CP0_ENTRYLO1(sp)
3739 -               mtc0    v0, CP0_PAGEMASK
3740 -               DMTC0   v1, CP0_ENTRYLO1
3741 -               LONG_L  v0, GDB_FR_CP0_ENTRYLO0(sp)
3742 -               LONG_L  v1, GDB_FR_CP0_INDEX(sp)
3743 -               DMTC0   v0, CP0_ENTRYLO0
3744 -               LONG_L  v0, GDB_FR_CP0_CONTEXT(sp)
3745 -               mtc0    v1, CP0_INDEX
3746 -               DMTC0   v0, CP0_CONTEXT
3747 -
3748 -
3749 -/*
3750 - * Next, the floating point registers
3751 - */
3752 -               mfc0    v0, CP0_STATUS          /* check if the FPU is enabled */
3753 -               srl     v0, v0, 16
3754 -               andi    v0, v0, (ST0_CU1 >> 16)
3755 -
3756 -               beqz    v0, 3f                  /* disabled, skip */
3757 -                nop
3758 -
3759 -               LDC1    $31, GDB_FR_FPR31(sp)
3760 -               LDC1    $30, GDB_FR_FPR30(sp)
3761 -               LDC1    $29, GDB_FR_FPR29(sp)
3762 -               LDC1    $28, GDB_FR_FPR28(sp)
3763 -               LDC1    $27, GDB_FR_FPR27(sp)
3764 -               LDC1    $26, GDB_FR_FPR26(sp)
3765 -               LDC1    $25, GDB_FR_FPR25(sp)
3766 -               LDC1    $24, GDB_FR_FPR24(sp)
3767 -               LDC1    $23, GDB_FR_FPR23(sp)
3768 -               LDC1    $22, GDB_FR_FPR22(sp)
3769 -               LDC1    $21, GDB_FR_FPR21(sp)
3770 -               LDC1    $20, GDB_FR_FPR20(sp)
3771 -               LDC1    $19, GDB_FR_FPR19(sp)
3772 -               LDC1    $18, GDB_FR_FPR18(sp)
3773 -               LDC1    $17, GDB_FR_FPR17(sp)
3774 -               LDC1    $16, GDB_FR_FPR16(sp)
3775 -               LDC1    $15, GDB_FR_FPR15(sp)
3776 -               LDC1    $14, GDB_FR_FPR14(sp)
3777 -               LDC1    $13, GDB_FR_FPR13(sp)
3778 -               LDC1    $12, GDB_FR_FPR12(sp)
3779 -               LDC1    $11, GDB_FR_FPR11(sp)
3780 -               LDC1    $10, GDB_FR_FPR10(sp)
3781 -               LDC1    $9, GDB_FR_FPR9(sp)
3782 -               LDC1    $8, GDB_FR_FPR8(sp)
3783 -               LDC1    $7, GDB_FR_FPR7(sp)
3784 -               LDC1    $6, GDB_FR_FPR6(sp)
3785 -               LDC1    $5, GDB_FR_FPR5(sp)
3786 -               LDC1    $4, GDB_FR_FPR4(sp)
3787 -               LDC1    $3, GDB_FR_FPR3(sp)
3788 -               LDC1    $2, GDB_FR_FPR2(sp)
3789 -               LDC1    $1, GDB_FR_FPR1(sp)
3790 -               LDC1    $0, GDB_FR_FPR0(sp)
3791 -
3792 -/*
3793 - * Now the CP0 and integer registers
3794 - */
3795 -
3796 -3:
3797 -#ifdef CONFIG_MIPS_MT_SMTC
3798 -               /* Read-modify write of Status must be atomic */
3799 -               mfc0    t2, CP0_TCSTATUS
3800 -               ori     t1, t2, TCSTATUS_IXMT
3801 -               mtc0    t1, CP0_TCSTATUS
3802 -               andi    t2, t2, TCSTATUS_IXMT
3803 -               _ehb
3804 -               DMT     9                               # dmt   t1
3805 -               jal     mips_ihb
3806 -               nop
3807 -#endif /* CONFIG_MIPS_MT_SMTC */
3808 -               mfc0    t0, CP0_STATUS
3809 -               ori     t0, 0x1f
3810 -               xori    t0, 0x1f
3811 -               mtc0    t0, CP0_STATUS
3812 -#ifdef CONFIG_MIPS_MT_SMTC
3813 -               andi    t1, t1, VPECONTROL_TE
3814 -               beqz    t1, 9f
3815 -               nop
3816 -               EMT                                     # emt
3817 -9:
3818 -               mfc0    t1, CP0_TCSTATUS
3819 -               xori    t1, t1, TCSTATUS_IXMT
3820 -               or      t1, t1, t2
3821 -               mtc0    t1, CP0_TCSTATUS
3822 -               _ehb
3823 -#endif /* CONFIG_MIPS_MT_SMTC */
3824 -               LONG_L  v0, GDB_FR_STATUS(sp)
3825 -               LONG_L  v1, GDB_FR_EPC(sp)
3826 -               mtc0    v0, CP0_STATUS
3827 -               DMTC0   v1, CP0_EPC
3828 -               LONG_L  v0, GDB_FR_HI(sp)
3829 -               LONG_L  v1, GDB_FR_LO(sp)
3830 -               mthi    v0
3831 -               mtlo    v1
3832 -               LONG_L  $31, GDB_FR_REG31(sp)
3833 -               LONG_L  $30, GDB_FR_REG30(sp)
3834 -               LONG_L  $28, GDB_FR_REG28(sp)
3835 -               LONG_L  $27, GDB_FR_REG27(sp)
3836 -               LONG_L  $26, GDB_FR_REG26(sp)
3837 -               LONG_L  $25, GDB_FR_REG25(sp)
3838 -               LONG_L  $24, GDB_FR_REG24(sp)
3839 -               LONG_L  $23, GDB_FR_REG23(sp)
3840 -               LONG_L  $22, GDB_FR_REG22(sp)
3841 -               LONG_L  $21, GDB_FR_REG21(sp)
3842 -               LONG_L  $20, GDB_FR_REG20(sp)
3843 -               LONG_L  $19, GDB_FR_REG19(sp)
3844 -               LONG_L  $18, GDB_FR_REG18(sp)
3845 -               LONG_L  $17, GDB_FR_REG17(sp)
3846 -               LONG_L  $16, GDB_FR_REG16(sp)
3847 -               LONG_L  $15, GDB_FR_REG15(sp)
3848 -               LONG_L  $14, GDB_FR_REG14(sp)
3849 -               LONG_L  $13, GDB_FR_REG13(sp)
3850 -               LONG_L  $12, GDB_FR_REG12(sp)
3851 -               LONG_L  $11, GDB_FR_REG11(sp)
3852 -               LONG_L  $10, GDB_FR_REG10(sp)
3853 -               LONG_L  $9, GDB_FR_REG9(sp)
3854 -               LONG_L  $8, GDB_FR_REG8(sp)
3855 -               LONG_L  $7, GDB_FR_REG7(sp)
3856 -               LONG_L  $6, GDB_FR_REG6(sp)
3857 -               LONG_L  $5, GDB_FR_REG5(sp)
3858 -               LONG_L  $4, GDB_FR_REG4(sp)
3859 -               LONG_L  $3, GDB_FR_REG3(sp)
3860 -               LONG_L  $2, GDB_FR_REG2(sp)
3861 -               LONG_L  $1, GDB_FR_REG1(sp)
3862 -#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
3863 -               LONG_L  k0, GDB_FR_EPC(sp)
3864 -               LONG_L  $29, GDB_FR_REG29(sp)           /* Deallocate stack */
3865 -               jr      k0
3866 -               rfe
3867 -#else
3868 -               LONG_L  sp, GDB_FR_REG29(sp)            /* Deallocate stack */
3869 -
3870 -               .set    mips3
3871 -               eret
3872 -               .set    mips0
3873 -#endif
3874 -               .set    at
3875 -               .set    reorder
3876 -               END(trap_low)
3877 -
3878 -LEAF(kgdb_read_byte)
3879 -4:             lb      t0, (a0)
3880 -               sb      t0, (a1)
3881 -               li      v0, 0
3882 -               jr      ra
3883 -               .section __ex_table,"a"
3884 -               PTR     4b, kgdbfault
3885 -               .previous
3886 -               END(kgdb_read_byte)
3887 -
3888 -LEAF(kgdb_write_byte)
3889 -5:             sb      a0, (a1)
3890 -               li      v0, 0
3891 -               jr      ra
3892 -               .section __ex_table,"a"
3893 -               PTR     5b, kgdbfault
3894 -               .previous
3895 -               END(kgdb_write_byte)
3896 -
3897 -               .type   kgdbfault@function
3898 -               .ent    kgdbfault
3899 -
3900 -kgdbfault:     li      v0, -EFAULT
3901 -               jr      ra
3902 -               .end    kgdbfault
3903 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/kernel/gdb-stub.c linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/gdb-stub.c
3904 --- linux-2.6.18-53.1.14/arch/mips/kernel/gdb-stub.c    2006-09-20 07:42:06.000000000 +0400
3905 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/gdb-stub.c       1970-01-01 03:00:00.000000000 +0300
3906 @@ -1,1154 +0,0 @@
3907 -/*
3908 - *  arch/mips/kernel/gdb-stub.c
3909 - *
3910 - *  Originally written by Glenn Engel, Lake Stevens Instrument Division
3911 - *
3912 - *  Contributed by HP Systems
3913 - *
3914 - *  Modified for SPARC by Stu Grossman, Cygnus Support.
3915 - *
3916 - *  Modified for Linux/MIPS (and MIPS in general) by Andreas Busse
3917 - *  Send complaints, suggestions etc. to <andy@waldorf-gmbh.de>
3918 - *
3919 - *  Copyright (C) 1995 Andreas Busse
3920 - *
3921 - *  Copyright (C) 2003 MontaVista Software Inc.
3922 - *  Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
3923 - */
3924 -
3925 -/*
3926 - *  To enable debugger support, two things need to happen.  One, a
3927 - *  call to set_debug_traps() is necessary in order to allow any breakpoints
3928 - *  or error conditions to be properly intercepted and reported to gdb.
3929 - *  Two, a breakpoint needs to be generated to begin communication.  This
3930 - *  is most easily accomplished by a call to breakpoint().  Breakpoint()
3931 - *  simulates a breakpoint by executing a BREAK instruction.
3932 - *
3933 - *
3934 - *    The following gdb commands are supported:
3935 - *
3936 - * command          function                               Return value
3937 - *
3938 - *    g             return the value of the CPU registers  hex data or ENN
3939 - *    G             set the value of the CPU registers     OK or ENN
3940 - *
3941 - *    mAA..AA,LLLL  Read LLLL bytes at address AA..AA      hex data or ENN
3942 - *    MAA..AA,LLLL: Write LLLL bytes at address AA.AA      OK or ENN
3943 - *
3944 - *    c             Resume at current address              SNN   ( signal NN)
3945 - *    cAA..AA       Continue at address AA..AA             SNN
3946 - *
3947 - *    s             Step one instruction                   SNN
3948 - *    sAA..AA       Step one instruction from AA..AA       SNN
3949 - *
3950 - *    k             kill
3951 - *
3952 - *    ?             What was the last sigval ?             SNN   (signal NN)
3953 - *
3954 - *    bBB..BB      Set baud rate to BB..BB                OK or BNN, then sets
3955 - *                                                        baud rate
3956 - *
3957 - * All commands and responses are sent with a packet which includes a
3958 - * checksum.  A packet consists of
3959 - *
3960 - * $<packet info>#<checksum>.
3961 - *
3962 - * where
3963 - * <packet info> :: <characters representing the command or response>
3964 - * <checksum>    :: < two hex digits computed as modulo 256 sum of <packetinfo>>
3965 - *
3966 - * When a packet is received, it is first acknowledged with either '+' or '-'.
3967 - * '+' indicates a successful transfer.  '-' indicates a failed transfer.
3968 - *
3969 - * Example:
3970 - *
3971 - * Host:                  Reply:
3972 - * $m0,10#2a               +$00010203040506070809101112131415#42
3973 - *
3974 - *
3975 - *  ==============
3976 - *  MORE EXAMPLES:
3977 - *  ==============
3978 - *
3979 - *  For reference -- the following are the steps that one
3980 - *  company took (RidgeRun Inc) to get remote gdb debugging
3981 - *  going. In this scenario the host machine was a PC and the
3982 - *  target platform was a Galileo EVB64120A MIPS evaluation
3983 - *  board.
3984 - *
3985 - *  Step 1:
3986 - *  First download gdb-5.0.tar.gz from the internet.
3987 - *  and then build/install the package.
3988 - *
3989 - *  Example:
3990 - *    $ tar zxf gdb-5.0.tar.gz
3991 - *    $ cd gdb-5.0
3992 - *    $ ./configure --target=mips-linux-elf
3993 - *    $ make
3994 - *    $ install
3995 - *    $ which mips-linux-elf-gdb
3996 - *    /usr/local/bin/mips-linux-elf-gdb
3997 - *
3998 - *  Step 2:
3999 - *  Configure linux for remote debugging and build it.
4000 - *
4001 - *  Example:
4002 - *    $ cd ~/linux
4003 - *    $ make menuconfig <go to "Kernel Hacking" and turn on remote debugging>
4004 - *    $ make
4005 - *
4006 - *  Step 3:
4007 - *  Download the kernel to the remote target and start
4008 - *  the kernel running. It will promptly halt and wait
4009 - *  for the host gdb session to connect. It does this
4010 - *  since the "Kernel Hacking" option has defined
4011 - *  CONFIG_KGDB which in turn enables your calls
4012 - *  to:
4013 - *     set_debug_traps();
4014 - *     breakpoint();
4015 - *
4016 - *  Step 4:
4017 - *  Start the gdb session on the host.
4018 - *
4019 - *  Example:
4020 - *    $ mips-linux-elf-gdb vmlinux
4021 - *    (gdb) set remotebaud 115200
4022 - *    (gdb) target remote /dev/ttyS1
4023 - *    ...at this point you are connected to
4024 - *       the remote target and can use gdb
4025 - *       in the normal fasion. Setting
4026 - *       breakpoints, single stepping,
4027 - *       printing variables, etc.
4028 - */
4029 -#include <linux/string.h>
4030 -#include <linux/kernel.h>
4031 -#include <linux/signal.h>
4032 -#include <linux/sched.h>
4033 -#include <linux/mm.h>
4034 -#include <linux/console.h>
4035 -#include <linux/init.h>
4036 -#include <linux/smp.h>
4037 -#include <linux/spinlock.h>
4038 -#include <linux/slab.h>
4039 -#include <linux/reboot.h>
4040 -
4041 -#include <asm/asm.h>
4042 -#include <asm/cacheflush.h>
4043 -#include <asm/mipsregs.h>
4044 -#include <asm/pgtable.h>
4045 -#include <asm/system.h>
4046 -#include <asm/gdb-stub.h>
4047 -#include <asm/inst.h>
4048 -#include <asm/smp.h>
4049 -
4050 -/*
4051 - * external low-level support routines
4052 - */
4053 -
4054 -extern int putDebugChar(char c);    /* write a single character      */
4055 -extern char getDebugChar(void);     /* read and return a single char */
4056 -extern void trap_low(void);
4057 -
4058 -/*
4059 - * breakpoint and test functions
4060 - */
4061 -extern void breakpoint(void);
4062 -extern void breakinst(void);
4063 -extern void async_breakpoint(void);
4064 -extern void async_breakinst(void);
4065 -extern void adel(void);
4066 -
4067 -/*
4068 - * local prototypes
4069 - */
4070 -
4071 -static void getpacket(char *buffer);
4072 -static void putpacket(char *buffer);
4073 -static int computeSignal(int tt);
4074 -static int hex(unsigned char ch);
4075 -static int hexToInt(char **ptr, int *intValue);
4076 -static int hexToLong(char **ptr, long *longValue);
4077 -static unsigned char *mem2hex(char *mem, char *buf, int count, int may_fault);
4078 -void handle_exception(struct gdb_regs *regs);
4079 -
4080 -int kgdb_enabled;
4081 -
4082 -/*
4083 - * spin locks for smp case
4084 - */
4085 -static DEFINE_SPINLOCK(kgdb_lock);
4086 -static raw_spinlock_t kgdb_cpulock[NR_CPUS] = {
4087 -       [0 ... NR_CPUS-1] = __RAW_SPIN_LOCK_UNLOCKED,
4088 -};
4089 -
4090 -/*
4091 - * BUFMAX defines the maximum number of characters in inbound/outbound buffers
4092 - * at least NUMREGBYTES*2 are needed for register packets
4093 - */
4094 -#define BUFMAX 2048
4095 -
4096 -static char input_buffer[BUFMAX];
4097 -static char output_buffer[BUFMAX];
4098 -static int initialized;        /* !0 means we've been initialized */
4099 -static int kgdb_started;
4100 -static const char hexchars[]="0123456789abcdef";
4101 -
4102 -/* Used to prevent crashes in memory access.  Note that they'll crash anyway if
4103 -   we haven't set up fault handlers yet... */
4104 -int kgdb_read_byte(unsigned char *address, unsigned char *dest);
4105 -int kgdb_write_byte(unsigned char val, unsigned char *dest);
4106 -
4107 -/*
4108 - * Convert ch from a hex digit to an int
4109 - */
4110 -static int hex(unsigned char ch)
4111 -{
4112 -       if (ch >= 'a' && ch <= 'f')
4113 -               return ch-'a'+10;
4114 -       if (ch >= '0' && ch <= '9')
4115 -               return ch-'0';
4116 -       if (ch >= 'A' && ch <= 'F')
4117 -               return ch-'A'+10;
4118 -       return -1;
4119 -}
4120 -
4121 -/*
4122 - * scan for the sequence $<data>#<checksum>
4123 - */
4124 -static void getpacket(char *buffer)
4125 -{
4126 -       unsigned char checksum;
4127 -       unsigned char xmitcsum;
4128 -       int i;
4129 -       int count;
4130 -       unsigned char ch;
4131 -
4132 -       do {
4133 -               /*
4134 -                * wait around for the start character,
4135 -                * ignore all other characters
4136 -                */
4137 -               while ((ch = (getDebugChar() & 0x7f)) != '$') ;
4138 -
4139 -               checksum = 0;
4140 -               xmitcsum = -1;
4141 -               count = 0;
4142 -
4143 -               /*
4144 -                * now, read until a # or end of buffer is found
4145 -                */
4146 -               while (count < BUFMAX) {
4147 -                       ch = getDebugChar();
4148 -                       if (ch == '#')
4149 -                               break;
4150 -                       checksum = checksum + ch;
4151 -                       buffer[count] = ch;
4152 -                       count = count + 1;
4153 -               }
4154 -
4155 -               if (count >= BUFMAX)
4156 -                       continue;
4157 -
4158 -               buffer[count] = 0;
4159 -
4160 -               if (ch == '#') {
4161 -                       xmitcsum = hex(getDebugChar() & 0x7f) << 4;
4162 -                       xmitcsum |= hex(getDebugChar() & 0x7f);
4163 -
4164 -                       if (checksum != xmitcsum)
4165 -                               putDebugChar('-');      /* failed checksum */
4166 -                       else {
4167 -                               putDebugChar('+'); /* successful transfer */
4168 -
4169 -                               /*
4170 -                                * if a sequence char is present,
4171 -                                * reply the sequence ID
4172 -                                */
4173 -                               if (buffer[2] == ':') {
4174 -                                       putDebugChar(buffer[0]);
4175 -                                       putDebugChar(buffer[1]);
4176 -
4177 -                                       /*
4178 -                                        * remove sequence chars from buffer
4179 -                                        */
4180 -                                       count = strlen(buffer);
4181 -                                       for (i=3; i <= count; i++)
4182 -                                               buffer[i-3] = buffer[i];
4183 -                               }
4184 -                       }
4185 -               }
4186 -       }
4187 -       while (checksum != xmitcsum);
4188 -}
4189 -
4190 -/*
4191 - * send the packet in buffer.
4192 - */
4193 -static void putpacket(char *buffer)
4194 -{
4195 -       unsigned char checksum;
4196 -       int count;
4197 -       unsigned char ch;
4198 -
4199 -       /*
4200 -        * $<packet info>#<checksum>.
4201 -        */
4202 -
4203 -       do {
4204 -               putDebugChar('$');
4205 -               checksum = 0;
4206 -               count = 0;
4207 -
4208 -               while ((ch = buffer[count]) != 0) {
4209 -                       if (!(putDebugChar(ch)))
4210 -                               return;
4211 -                       checksum += ch;
4212 -                       count += 1;
4213 -               }
4214 -
4215 -               putDebugChar('#');
4216 -               putDebugChar(hexchars[checksum >> 4]);
4217 -               putDebugChar(hexchars[checksum & 0xf]);
4218 -
4219 -       }
4220 -       while ((getDebugChar() & 0x7f) != '+');
4221 -}
4222 -
4223 -
4224 -/*
4225 - * Convert the memory pointed to by mem into hex, placing result in buf.
4226 - * Return a pointer to the last char put in buf (null), in case of mem fault,
4227 - * return 0.
4228 - * may_fault is non-zero if we are reading from arbitrary memory, but is currently
4229 - * not used.
4230 - */
4231 -static unsigned char *mem2hex(char *mem, char *buf, int count, int may_fault)
4232 -{
4233 -       unsigned char ch;
4234 -
4235 -       while (count-- > 0) {
4236 -               if (kgdb_read_byte(mem++, &ch) != 0)
4237 -                       return 0;
4238 -               *buf++ = hexchars[ch >> 4];
4239 -               *buf++ = hexchars[ch & 0xf];
4240 -       }
4241 -
4242 -       *buf = 0;
4243 -
4244 -       return buf;
4245 -}
4246 -
4247 -/*
4248 - * convert the hex array pointed to by buf into binary to be placed in mem
4249 - * return a pointer to the character AFTER the last byte written
4250 - * may_fault is non-zero if we are reading from arbitrary memory, but is currently
4251 - * not used.
4252 - */
4253 -static char *hex2mem(char *buf, char *mem, int count, int binary, int may_fault)
4254 -{
4255 -       int i;
4256 -       unsigned char ch;
4257 -
4258 -       for (i=0; i<count; i++)
4259 -       {
4260 -               if (binary) {
4261 -                       ch = *buf++;
4262 -                       if (ch == 0x7d)
4263 -                               ch = 0x20 ^ *buf++;
4264 -               }
4265 -               else {
4266 -                       ch = hex(*buf++) << 4;
4267 -                       ch |= hex(*buf++);
4268 -               }
4269 -               if (kgdb_write_byte(ch, mem++) != 0)
4270 -                       return 0;
4271 -       }
4272 -
4273 -       return mem;
4274 -}
4275 -
4276 -/*
4277 - * This table contains the mapping between SPARC hardware trap types, and
4278 - * signals, which are primarily what GDB understands.  It also indicates
4279 - * which hardware traps we need to commandeer when initializing the stub.
4280 - */
4281 -static struct hard_trap_info {
4282 -       unsigned char tt;               /* Trap type code for MIPS R3xxx and R4xxx */
4283 -       unsigned char signo;            /* Signal that we map this trap into */
4284 -} hard_trap_info[] = {
4285 -       { 6, SIGBUS },                  /* instruction bus error */
4286 -       { 7, SIGBUS },                  /* data bus error */
4287 -       { 9, SIGTRAP },                 /* break */
4288 -       { 10, SIGILL },                 /* reserved instruction */
4289 -/*     { 11, SIGILL },         */      /* CPU unusable */
4290 -       { 12, SIGFPE },                 /* overflow */
4291 -       { 13, SIGTRAP },                /* trap */
4292 -       { 14, SIGSEGV },                /* virtual instruction cache coherency */
4293 -       { 15, SIGFPE },                 /* floating point exception */
4294 -       { 23, SIGSEGV },                /* watch */
4295 -       { 31, SIGSEGV },                /* virtual data cache coherency */
4296 -       { 0, 0}                         /* Must be last */
4297 -};
4298 -
4299 -/* Save the normal trap handlers for user-mode traps. */
4300 -void *saved_vectors[32];
4301 -
4302 -/*
4303 - * Set up exception handlers for tracing and breakpoints
4304 - */
4305 -void set_debug_traps(void)
4306 -{
4307 -       struct hard_trap_info *ht;
4308 -       unsigned long flags;
4309 -       unsigned char c;
4310 -
4311 -       local_irq_save(flags);
4312 -       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
4313 -               saved_vectors[ht->tt] = set_except_vector(ht->tt, trap_low);
4314 -
4315 -       putDebugChar('+'); /* 'hello world' */
4316 -       /*
4317 -        * In case GDB is started before us, ack any packets
4318 -        * (presumably "$?#xx") sitting there.
4319 -        */
4320 -       while((c = getDebugChar()) != '$');
4321 -       while((c = getDebugChar()) != '#');
4322 -       c = getDebugChar(); /* eat first csum byte */
4323 -       c = getDebugChar(); /* eat second csum byte */
4324 -       putDebugChar('+'); /* ack it */
4325 -
4326 -       initialized = 1;
4327 -       local_irq_restore(flags);
4328 -}
4329 -
4330 -void restore_debug_traps(void)
4331 -{
4332 -       struct hard_trap_info *ht;
4333 -       unsigned long flags;
4334 -
4335 -       local_irq_save(flags);
4336 -       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
4337 -               set_except_vector(ht->tt, saved_vectors[ht->tt]);
4338 -       local_irq_restore(flags);
4339 -}
4340 -
4341 -/*
4342 - * Convert the MIPS hardware trap type code to a Unix signal number.
4343 - */
4344 -static int computeSignal(int tt)
4345 -{
4346 -       struct hard_trap_info *ht;
4347 -
4348 -       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
4349 -               if (ht->tt == tt)
4350 -                       return ht->signo;
4351 -
4352 -       return SIGHUP;          /* default for things we don't know about */
4353 -}
4354 -
4355 -/*
4356 - * While we find nice hex chars, build an int.
4357 - * Return number of chars processed.
4358 - */
4359 -static int hexToInt(char **ptr, int *intValue)
4360 -{
4361 -       int numChars = 0;
4362 -       int hexValue;
4363 -
4364 -       *intValue = 0;
4365 -
4366 -       while (**ptr) {
4367 -               hexValue = hex(**ptr);
4368 -               if (hexValue < 0)
4369 -                       break;
4370 -
4371 -               *intValue = (*intValue << 4) | hexValue;
4372 -               numChars ++;
4373 -
4374 -               (*ptr)++;
4375 -       }
4376 -
4377 -       return (numChars);
4378 -}
4379 -
4380 -static int hexToLong(char **ptr, long *longValue)
4381 -{
4382 -       int numChars = 0;
4383 -       int hexValue;
4384 -
4385 -       *longValue = 0;
4386 -
4387 -       while (**ptr) {
4388 -               hexValue = hex(**ptr);
4389 -               if (hexValue < 0)
4390 -                       break;
4391 -
4392 -               *longValue = (*longValue << 4) | hexValue;
4393 -               numChars ++;
4394 -
4395 -               (*ptr)++;
4396 -       }
4397 -
4398 -       return numChars;
4399 -}
4400 -
4401 -
4402 -#if 0
4403 -/*
4404 - * Print registers (on target console)
4405 - * Used only to debug the stub...
4406 - */
4407 -void show_gdbregs(struct gdb_regs * regs)
4408 -{
4409 -       /*
4410 -        * Saved main processor registers
4411 -        */
4412 -       printk("$0 : %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4413 -              regs->reg0, regs->reg1, regs->reg2, regs->reg3,
4414 -               regs->reg4, regs->reg5, regs->reg6, regs->reg7);
4415 -       printk("$8 : %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4416 -              regs->reg8, regs->reg9, regs->reg10, regs->reg11,
4417 -               regs->reg12, regs->reg13, regs->reg14, regs->reg15);
4418 -       printk("$16: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4419 -              regs->reg16, regs->reg17, regs->reg18, regs->reg19,
4420 -               regs->reg20, regs->reg21, regs->reg22, regs->reg23);
4421 -       printk("$24: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4422 -              regs->reg24, regs->reg25, regs->reg26, regs->reg27,
4423 -              regs->reg28, regs->reg29, regs->reg30, regs->reg31);
4424 -
4425 -       /*
4426 -        * Saved cp0 registers
4427 -        */
4428 -       printk("epc  : %08lx\nStatus: %08lx\nCause : %08lx\n",
4429 -              regs->cp0_epc, regs->cp0_status, regs->cp0_cause);
4430 -}
4431 -#endif /* dead code */
4432 -
4433 -/*
4434 - * We single-step by setting breakpoints. When an exception
4435 - * is handled, we need to restore the instructions hoisted
4436 - * when the breakpoints were set.
4437 - *
4438 - * This is where we save the original instructions.
4439 - */
4440 -static struct gdb_bp_save {
4441 -       unsigned long addr;
4442 -       unsigned int val;
4443 -} step_bp[2];
4444 -
4445 -#define BP 0x0000000d  /* break opcode */
4446 -
4447 -/*
4448 - * Set breakpoint instructions for single stepping.
4449 - */
4450 -static void single_step(struct gdb_regs *regs)
4451 -{
4452 -       union mips_instruction insn;
4453 -       unsigned long targ;
4454 -       int is_branch, is_cond, i;
4455 -
4456 -       targ = regs->cp0_epc;
4457 -       insn.word = *(unsigned int *)targ;
4458 -       is_branch = is_cond = 0;
4459 -
4460 -       switch (insn.i_format.opcode) {
4461 -       /*
4462 -        * jr and jalr are in r_format format.
4463 -        */
4464 -       case spec_op:
4465 -               switch (insn.r_format.func) {
4466 -               case jalr_op:
4467 -               case jr_op:
4468 -                       targ = *(&regs->reg0 + insn.r_format.rs);
4469 -                       is_branch = 1;
4470 -                       break;
4471 -               }
4472 -               break;
4473 -
4474 -       /*
4475 -        * This group contains:
4476 -        * bltz_op, bgez_op, bltzl_op, bgezl_op,
4477 -        * bltzal_op, bgezal_op, bltzall_op, bgezall_op.
4478 -        */
4479 -       case bcond_op:
4480 -               is_branch = is_cond = 1;
4481 -               targ += 4 + (insn.i_format.simmediate << 2);
4482 -               break;
4483 -
4484 -       /*
4485 -        * These are unconditional and in j_format.
4486 -        */
4487 -       case jal_op:
4488 -       case j_op:
4489 -               is_branch = 1;
4490 -               targ += 4;
4491 -               targ >>= 28;
4492 -               targ <<= 28;
4493 -               targ |= (insn.j_format.target << 2);
4494 -               break;
4495 -
4496 -       /*
4497 -        * These are conditional.
4498 -        */
4499 -       case beq_op:
4500 -       case beql_op:
4501 -       case bne_op:
4502 -       case bnel_op:
4503 -       case blez_op:
4504 -       case blezl_op:
4505 -       case bgtz_op:
4506 -       case bgtzl_op:
4507 -       case cop0_op:
4508 -       case cop1_op:
4509 -       case cop2_op:
4510 -       case cop1x_op:
4511 -               is_branch = is_cond = 1;
4512 -               targ += 4 + (insn.i_format.simmediate << 2);
4513 -               break;
4514 -       }
4515 -
4516 -       if (is_branch) {
4517 -               i = 0;
4518 -               if (is_cond && targ != (regs->cp0_epc + 8)) {
4519 -                       step_bp[i].addr = regs->cp0_epc + 8;
4520 -                       step_bp[i++].val = *(unsigned *)(regs->cp0_epc + 8);
4521 -                       *(unsigned *)(regs->cp0_epc + 8) = BP;
4522 -               }
4523 -               step_bp[i].addr = targ;
4524 -               step_bp[i].val  = *(unsigned *)targ;
4525 -               *(unsigned *)targ = BP;
4526 -       } else {
4527 -               step_bp[0].addr = regs->cp0_epc + 4;
4528 -               step_bp[0].val  = *(unsigned *)(regs->cp0_epc + 4);
4529 -               *(unsigned *)(regs->cp0_epc + 4) = BP;
4530 -       }
4531 -}
4532 -
4533 -/*
4534 - *  If asynchronously interrupted by gdb, then we need to set a breakpoint
4535 - *  at the interrupted instruction so that we wind up stopped with a
4536 - *  reasonable stack frame.
4537 - */
4538 -static struct gdb_bp_save async_bp;
4539 -
4540 -/*
4541 - * Swap the interrupted EPC with our asynchronous breakpoint routine.
4542 - * This is safer than stuffing the breakpoint in-place, since no cache
4543 - * flushes (or resulting smp_call_functions) are required.  The
4544 - * assumption is that only one CPU will be handling asynchronous bp's,
4545 - * and only one can be active at a time.
4546 - */
4547 -extern spinlock_t smp_call_lock;
4548 -
4549 -void set_async_breakpoint(unsigned long *epc)
4550 -{
4551 -       /* skip breaking into userland */
4552 -       if ((*epc & 0x80000000) == 0)
4553 -               return;
4554 -
4555 -#ifdef CONFIG_SMP
4556 -       /* avoid deadlock if someone is make IPC */
4557 -       if (spin_is_locked(&smp_call_lock))
4558 -               return;
4559 -#endif
4560 -
4561 -       async_bp.addr = *epc;
4562 -       *epc = (unsigned long)async_breakpoint;
4563 -}
4564 -
4565 -static void kgdb_wait(void *arg)
4566 -{
4567 -       unsigned flags;
4568 -       int cpu = smp_processor_id();
4569 -
4570 -       local_irq_save(flags);
4571 -
4572 -       __raw_spin_lock(&kgdb_cpulock[cpu]);
4573 -       __raw_spin_unlock(&kgdb_cpulock[cpu]);
4574 -
4575 -       local_irq_restore(flags);
4576 -}
4577 -
4578 -/*
4579 - * GDB stub needs to call kgdb_wait on all processor with interrupts
4580 - * disabled, so it uses it's own special variant.
4581 - */
4582 -static int kgdb_smp_call_kgdb_wait(void)
4583 -{
4584 -#ifdef CONFIG_SMP
4585 -       struct call_data_struct data;
4586 -       int i, cpus = num_online_cpus() - 1;
4587 -       int cpu = smp_processor_id();
4588 -
4589 -       /*
4590 -        * Can die spectacularly if this CPU isn't yet marked online
4591 -        */
4592 -       BUG_ON(!cpu_online(cpu));
4593 -
4594 -       if (!cpus)
4595 -               return 0;
4596 -
4597 -       if (spin_is_locked(&smp_call_lock)) {
4598 -               /*
4599 -                * Some other processor is trying to make us do something
4600 -                * but we're not going to respond... give up
4601 -                */
4602 -               return -1;
4603 -               }
4604 -
4605 -       /*
4606 -        * We will continue here, accepting the fact that
4607 -        * the kernel may deadlock if another CPU attempts
4608 -        * to call smp_call_function now...
4609 -        */
4610 -
4611 -       data.func = kgdb_wait;
4612 -       data.info = NULL;
4613 -       atomic_set(&data.started, 0);
4614 -       data.wait = 0;
4615 -
4616 -       spin_lock(&smp_call_lock);
4617 -       call_data = &data;
4618 -       mb();
4619 -
4620 -       /* Send a message to all other CPUs and wait for them to respond */
4621 -       for (i = 0; i < NR_CPUS; i++)
4622 -               if (cpu_online(i) && i != cpu)
4623 -                       core_send_ipi(i, SMP_CALL_FUNCTION);
4624 -
4625 -       /* Wait for response */
4626 -       /* FIXME: lock-up detection, backtrace on lock-up */
4627 -       while (atomic_read(&data.started) != cpus)
4628 -               barrier();
4629 -
4630 -       call_data = NULL;
4631 -       spin_unlock(&smp_call_lock);
4632 -#endif
4633 -
4634 -       return 0;
4635 -}
4636 -
4637 -/*
4638 - * This function does all command processing for interfacing to gdb.  It
4639 - * returns 1 if you should skip the instruction at the trap address, 0
4640 - * otherwise.
4641 - */
4642 -void handle_exception (struct gdb_regs *regs)
4643 -{
4644 -       int trap;                       /* Trap type */
4645 -       int sigval;
4646 -       long addr;
4647 -       int length;
4648 -       char *ptr;
4649 -       unsigned long *stack;
4650 -       int i;
4651 -       int bflag = 0;
4652 -
4653 -       kgdb_started = 1;
4654 -
4655 -       /*
4656 -        * acquire the big kgdb spinlock
4657 -        */
4658 -       if (!spin_trylock(&kgdb_lock)) {
4659 -               /*
4660 -                * some other CPU has the lock, we should go back to
4661 -                * receive the gdb_wait IPC
4662 -                */
4663 -               return;
4664 -       }
4665 -
4666 -       /*
4667 -        * If we're in async_breakpoint(), restore the real EPC from
4668 -        * the breakpoint.
4669 -        */
4670 -       if (regs->cp0_epc == (unsigned long)async_breakinst) {
4671 -               regs->cp0_epc = async_bp.addr;
4672 -               async_bp.addr = 0;
4673 -       }
4674 -
4675 -       /*
4676 -        * acquire the CPU spinlocks
4677 -        */
4678 -       for (i = num_online_cpus()-1; i >= 0; i--)
4679 -               if (__raw_spin_trylock(&kgdb_cpulock[i]) == 0)
4680 -                       panic("kgdb: couldn't get cpulock %d\n", i);
4681 -
4682 -       /*
4683 -        * force other cpus to enter kgdb
4684 -        */
4685 -       kgdb_smp_call_kgdb_wait();
4686 -
4687 -       /*
4688 -        * If we're in breakpoint() increment the PC
4689 -        */
4690 -       trap = (regs->cp0_cause & 0x7c) >> 2;
4691 -       if (trap == 9 && regs->cp0_epc == (unsigned long)breakinst)
4692 -               regs->cp0_epc += 4;
4693 -
4694 -       /*
4695 -        * If we were single_stepping, restore the opcodes hoisted
4696 -        * for the breakpoint[s].
4697 -        */
4698 -       if (step_bp[0].addr) {
4699 -               *(unsigned *)step_bp[0].addr = step_bp[0].val;
4700 -               step_bp[0].addr = 0;
4701 -
4702 -               if (step_bp[1].addr) {
4703 -                       *(unsigned *)step_bp[1].addr = step_bp[1].val;
4704 -                       step_bp[1].addr = 0;
4705 -               }
4706 -       }
4707 -
4708 -       stack = (long *)regs->reg29;                    /* stack ptr */
4709 -       sigval = computeSignal(trap);
4710 -
4711 -       /*
4712 -        * reply to host that an exception has occurred
4713 -        */
4714 -       ptr = output_buffer;
4715 -
4716 -       /*
4717 -        * Send trap type (converted to signal)
4718 -        */
4719 -       *ptr++ = 'T';
4720 -       *ptr++ = hexchars[sigval >> 4];
4721 -       *ptr++ = hexchars[sigval & 0xf];
4722 -
4723 -       /*
4724 -        * Send Error PC
4725 -        */
4726 -       *ptr++ = hexchars[REG_EPC >> 4];
4727 -       *ptr++ = hexchars[REG_EPC & 0xf];
4728 -       *ptr++ = ':';
4729 -       ptr = mem2hex((char *)&regs->cp0_epc, ptr, sizeof(long), 0);
4730 -       *ptr++ = ';';
4731 -
4732 -       /*
4733 -        * Send frame pointer
4734 -        */
4735 -       *ptr++ = hexchars[REG_FP >> 4];
4736 -       *ptr++ = hexchars[REG_FP & 0xf];
4737 -       *ptr++ = ':';
4738 -       ptr = mem2hex((char *)&regs->reg30, ptr, sizeof(long), 0);
4739 -       *ptr++ = ';';
4740 -
4741 -       /*
4742 -        * Send stack pointer
4743 -        */
4744 -       *ptr++ = hexchars[REG_SP >> 4];
4745 -       *ptr++ = hexchars[REG_SP & 0xf];
4746 -       *ptr++ = ':';
4747 -       ptr = mem2hex((char *)&regs->reg29, ptr, sizeof(long), 0);
4748 -       *ptr++ = ';';
4749 -
4750 -       *ptr++ = 0;
4751 -       putpacket(output_buffer);       /* send it off... */
4752 -
4753 -       /*
4754 -        * Wait for input from remote GDB
4755 -        */
4756 -       while (1) {
4757 -               output_buffer[0] = 0;
4758 -               getpacket(input_buffer);
4759 -
4760 -               switch (input_buffer[0])
4761 -               {
4762 -               case '?':
4763 -                       output_buffer[0] = 'S';
4764 -                       output_buffer[1] = hexchars[sigval >> 4];
4765 -                       output_buffer[2] = hexchars[sigval & 0xf];
4766 -                       output_buffer[3] = 0;
4767 -                       break;
4768 -
4769 -               /*
4770 -                * Detach debugger; let CPU run
4771 -                */
4772 -               case 'D':
4773 -                       putpacket(output_buffer);
4774 -                       goto finish_kgdb;
4775 -                       break;
4776 -
4777 -               case 'd':
4778 -                       /* toggle debug flag */
4779 -                       break;
4780 -
4781 -               /*
4782 -                * Return the value of the CPU registers
4783 -                */
4784 -               case 'g':
4785 -                       ptr = output_buffer;
4786 -                       ptr = mem2hex((char *)&regs->reg0, ptr, 32*sizeof(long), 0); /* r0...r31 */
4787 -                       ptr = mem2hex((char *)&regs->cp0_status, ptr, 6*sizeof(long), 0); /* cp0 */
4788 -                       ptr = mem2hex((char *)&regs->fpr0, ptr, 32*sizeof(long), 0); /* f0...31 */
4789 -                       ptr = mem2hex((char *)&regs->cp1_fsr, ptr, 2*sizeof(long), 0); /* cp1 */
4790 -                       ptr = mem2hex((char *)&regs->frame_ptr, ptr, 2*sizeof(long), 0); /* frp */
4791 -                       ptr = mem2hex((char *)&regs->cp0_index, ptr, 16*sizeof(long), 0); /* cp0 */
4792 -                       break;
4793 -
4794 -               /*
4795 -                * set the value of the CPU registers - return OK
4796 -                */
4797 -               case 'G':
4798 -               {
4799 -                       ptr = &input_buffer[1];
4800 -                       hex2mem(ptr, (char *)&regs->reg0, 32*sizeof(long), 0, 0);
4801 -                       ptr += 32*(2*sizeof(long));
4802 -                       hex2mem(ptr, (char *)&regs->cp0_status, 6*sizeof(long), 0, 0);
4803 -                       ptr += 6*(2*sizeof(long));
4804 -                       hex2mem(ptr, (char *)&regs->fpr0, 32*sizeof(long), 0, 0);
4805 -                       ptr += 32*(2*sizeof(long));
4806 -                       hex2mem(ptr, (char *)&regs->cp1_fsr, 2*sizeof(long), 0, 0);
4807 -                       ptr += 2*(2*sizeof(long));
4808 -                       hex2mem(ptr, (char *)&regs->frame_ptr, 2*sizeof(long), 0, 0);
4809 -                       ptr += 2*(2*sizeof(long));
4810 -                       hex2mem(ptr, (char *)&regs->cp0_index, 16*sizeof(long), 0, 0);
4811 -                       strcpy(output_buffer,"OK");
4812 -                }
4813 -               break;
4814 -
4815 -               /*
4816 -                * mAA..AA,LLLL  Read LLLL bytes at address AA..AA
4817 -                */
4818 -               case 'm':
4819 -                       ptr = &input_buffer[1];
4820 -
4821 -                       if (hexToLong(&ptr, &addr)
4822 -                               && *ptr++ == ','
4823 -                               && hexToInt(&ptr, &length)) {
4824 -                               if (mem2hex((char *)addr, output_buffer, length, 1))
4825 -                                       break;
4826 -                               strcpy (output_buffer, "E03");
4827 -                       } else
4828 -                               strcpy(output_buffer,"E01");
4829 -                       break;
4830 -
4831 -               /*
4832 -                * XAA..AA,LLLL: Write LLLL escaped binary bytes at address AA.AA
4833 -                */
4834 -               case 'X':
4835 -                       bflag = 1;
4836 -                       /* fall through */
4837 -
4838 -               /*
4839 -                * MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK
4840 -                */
4841 -               case 'M':
4842 -                       ptr = &input_buffer[1];
4843 -
4844 -                       if (hexToLong(&ptr, &addr)
4845 -                               && *ptr++ == ','
4846 -                               && hexToInt(&ptr, &length)
4847 -                               && *ptr++ == ':') {
4848 -                               if (hex2mem(ptr, (char *)addr, length, bflag, 1))
4849 -                                       strcpy(output_buffer, "OK");
4850 -                               else
4851 -                                       strcpy(output_buffer, "E03");
4852 -                       }
4853 -                       else
4854 -                               strcpy(output_buffer, "E02");
4855 -                       break;
4856 -
4857 -               /*
4858 -                * cAA..AA    Continue at address AA..AA(optional)
4859 -                */
4860 -               case 'c':
4861 -                       /* try to read optional parameter, pc unchanged if no parm */
4862 -
4863 -                       ptr = &input_buffer[1];
4864 -                       if (hexToLong(&ptr, &addr))
4865 -                               regs->cp0_epc = addr;
4866 -
4867 -                       goto exit_kgdb_exception;
4868 -                       break;
4869 -
4870 -               /*
4871 -                * kill the program; let us try to restart the machine
4872 -                * Reset the whole machine.
4873 -                */
4874 -               case 'k':
4875 -               case 'r':
4876 -                       machine_restart("kgdb restarts machine");
4877 -                       break;
4878 -
4879 -               /*
4880 -                * Step to next instruction
4881 -                */
4882 -               case 's':
4883 -                       /*
4884 -                        * There is no single step insn in the MIPS ISA, so we
4885 -                        * use breakpoints and continue, instead.
4886 -                        */
4887 -                       single_step(regs);
4888 -                       goto exit_kgdb_exception;
4889 -                       /* NOTREACHED */
4890 -                       break;
4891 -
4892 -               /*
4893 -                * Set baud rate (bBB)
4894 -                * FIXME: Needs to be written
4895 -                */
4896 -               case 'b':
4897 -               {
4898 -#if 0
4899 -                       int baudrate;
4900 -                       extern void set_timer_3();
4901 -
4902 -                       ptr = &input_buffer[1];
4903 -                       if (!hexToInt(&ptr, &baudrate))
4904 -                       {
4905 -                               strcpy(output_buffer,"B01");
4906 -                               break;
4907 -                       }
4908 -
4909 -                       /* Convert baud rate to uart clock divider */
4910 -
4911 -                       switch (baudrate)
4912 -                       {
4913 -                               case 38400:
4914 -                                       baudrate = 16;
4915 -                                       break;
4916 -                               case 19200:
4917 -                                       baudrate = 33;
4918 -                                       break;
4919 -                               case 9600:
4920 -                                       baudrate = 65;
4921 -                                       break;
4922 -                               default:
4923 -                                       baudrate = 0;
4924 -                                       strcpy(output_buffer,"B02");
4925 -                                       goto x1;
4926 -                       }
4927 -
4928 -                       if (baudrate) {
4929 -                               putpacket("OK");        /* Ack before changing speed */
4930 -                               set_timer_3(baudrate); /* Set it */
4931 -                       }
4932 -#endif
4933 -               }
4934 -               break;
4935 -
4936 -               }                       /* switch */
4937 -
4938 -               /*
4939 -                * reply to the request
4940 -                */
4941 -
4942 -               putpacket(output_buffer);
4943 -
4944 -       } /* while */
4945 -
4946 -       return;
4947 -
4948 -finish_kgdb:
4949 -       restore_debug_traps();
4950 -
4951 -exit_kgdb_exception:
4952 -       /* release locks so other CPUs can go */
4953 -       for (i = num_online_cpus()-1; i >= 0; i--)
4954 -               __raw_spin_unlock(&kgdb_cpulock[i]);
4955 -       spin_unlock(&kgdb_lock);
4956 -
4957 -       __flush_cache_all();
4958 -       return;
4959 -}
4960 -
4961 -/*
4962 - * This function will generate a breakpoint exception.  It is used at the
4963 - * beginning of a program to sync up with a debugger and can be used
4964 - * otherwise as a quick means to stop program execution and "break" into
4965 - * the debugger.
4966 - */
4967 -void breakpoint(void)
4968 -{
4969 -       if (!initialized)
4970 -               return;
4971 -
4972 -       __asm__ __volatile__(
4973 -                       ".globl breakinst\n\t"
4974 -                       ".set\tnoreorder\n\t"
4975 -                       "nop\n"
4976 -                       "breakinst:\tbreak\n\t"
4977 -                       "nop\n\t"
4978 -                       ".set\treorder"
4979 -                       );
4980 -}
4981 -
4982 -/* Nothing but the break; don't pollute any registers */
4983 -void async_breakpoint(void)
4984 -{
4985 -       __asm__ __volatile__(
4986 -                       ".globl async_breakinst\n\t"
4987 -                       ".set\tnoreorder\n\t"
4988 -                       "nop\n"
4989 -                       "async_breakinst:\tbreak\n\t"
4990 -                       "nop\n\t"
4991 -                       ".set\treorder"
4992 -                       );
4993 -}
4994 -
4995 -void adel(void)
4996 -{
4997 -       __asm__ __volatile__(
4998 -                       ".globl\tadel\n\t"
4999 -                       "lui\t$8,0x8000\n\t"
5000 -                       "lw\t$9,1($8)\n\t"
5001 -                       );
5002 -}
5003 -
5004 -/*
5005 - * malloc is needed by gdb client in "call func()", even a private one
5006 - * will make gdb happy
5007 - */
5008 -static void * __attribute_used__ malloc(size_t size)
5009 -{
5010 -       return kmalloc(size, GFP_ATOMIC);
5011 -}
5012 -
5013 -static void __attribute_used__ free (void *where)
5014 -{
5015 -       kfree(where);
5016 -}
5017 -
5018 -#ifdef CONFIG_GDB_CONSOLE
5019 -
5020 -void gdb_putsn(const char *str, int l)
5021 -{
5022 -       char outbuf[18];
5023 -
5024 -       if (!kgdb_started)
5025 -               return;
5026 -
5027 -       outbuf[0]='O';
5028 -
5029 -       while(l) {
5030 -               int i = (l>8)?8:l;
5031 -               mem2hex((char *)str, &outbuf[1], i, 0);
5032 -               outbuf[(i*2)+1]=0;
5033 -               putpacket(outbuf);
5034 -               str += i;
5035 -               l -= i;
5036 -       }
5037 -}
5038 -
5039 -static void gdb_console_write(struct console *con, const char *s, unsigned n)
5040 -{
5041 -       gdb_putsn(s, n);
5042 -}
5043 -
5044 -static struct console gdb_console = {
5045 -       .name   = "gdb",
5046 -       .write  = gdb_console_write,
5047 -       .flags  = CON_PRINTBUFFER,
5048 -       .index  = -1
5049 -};
5050 -
5051 -static int __init register_gdb_console(void)
5052 -{
5053 -       register_console(&gdb_console);
5054 -
5055 -       return 0;
5056 -}
5057 -
5058 -console_initcall(register_gdb_console);
5059 -
5060 -#endif
5061 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/kernel/irq.c linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/irq.c
5062 --- linux-2.6.18-53.1.14/arch/mips/kernel/irq.c 2006-09-20 07:42:06.000000000 +0400
5063 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/irq.c    2008-06-10 15:38:24.000000000 +0400
5064 @@ -25,6 +25,10 @@
5065  #include <asm/atomic.h>
5066  #include <asm/system.h>
5067  #include <asm/uaccess.h>
5068 +#include <asm/kgdb.h>
5069 +
5070 +/* Keep track of if we've done certain initialization already or not. */
5071 +int kgdb_early_setup;
5072  
5073  /*
5074   * 'what should we do if we get a hw irq event on an illegal vector'.
5075 @@ -115,23 +119,13 @@ asmlinkage void spurious_interrupt(struc
5076         atomic_inc(&irq_err_count);
5077  }
5078  
5079 -#ifdef CONFIG_KGDB
5080 -extern void breakpoint(void);
5081 -extern void set_debug_traps(void);
5082 -
5083 -static int kgdb_flag = 1;
5084 -static int __init nokgdb(char *str)
5085 -{
5086 -       kgdb_flag = 0;
5087 -       return 1;
5088 -}
5089 -__setup("nokgdb", nokgdb);
5090 -#endif
5091 -
5092  void __init init_IRQ(void)
5093  {
5094         int i;
5095  
5096 +       if (kgdb_early_setup)
5097 +               return;
5098 +
5099         for (i = 0; i < NR_IRQS; i++) {
5100                 irq_desc[i].status  = IRQ_DISABLED;
5101                 irq_desc[i].action  = NULL;
5102 @@ -144,12 +138,12 @@ void __init init_IRQ(void)
5103         }
5104  
5105         arch_init_irq();
5106 -
5107  #ifdef CONFIG_KGDB
5108 -       if (kgdb_flag) {
5109 -               printk("Wait for gdb client connection ...\n");
5110 -               set_debug_traps();
5111 -               breakpoint();
5112 -       }
5113 +       /*
5114 +        * We have been called before kgdb_arch_init(). Hence,
5115 +        * we dont want the traps to be reinitialized
5116 +        */
5117 +       if (kgdb_early_setup == 0)
5118 +               kgdb_early_setup = 1;
5119  #endif
5120  }
5121 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/kernel/kgdb-jmp.c linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/kgdb-jmp.c
5122 --- linux-2.6.18-53.1.14/arch/mips/kernel/kgdb-jmp.c    1970-01-01 03:00:00.000000000 +0300
5123 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/kgdb-jmp.c       2008-06-10 15:38:24.000000000 +0400
5124 @@ -0,0 +1,116 @@
5125 +/*
5126 + * arch/mips/kernel/kgdb-jmp.c
5127 + *
5128 + * Save and restore system registers so that within a limited frame we
5129 + * may have a fault and "jump back" to a known safe location.
5130 + *
5131 + * Author: Tom Rini <trini@kernel.crashing.org>
5132 + * Author: Manish Lachwani <mlachwani@mvista.com>
5133 + *
5134 + * Cribbed from glibc, which carries the following:
5135 + * Copyright (C) 1996, 1997, 2000, 2002, 2003 Free Software Foundation, Inc.
5136 + * Copyright (C) 2005 by MontaVista Software.
5137 + *
5138 + * This file is licensed under the terms of the GNU General Public License
5139 + * version 2. This program as licensed "as is" without any warranty of
5140 + * any kind, whether express or implied.
5141 + */
5142 +
5143 +#include <linux/kgdb.h>
5144 +#include <asm/interrupt.h>
5145 +
5146 +#ifdef CONFIG_MIPS64
5147 +/*
5148 + * MIPS 64-bit
5149 + */
5150 +
5151 +int kgdb_fault_setjmp_aux(unsigned long *curr_context, int sp, int fp)
5152 +{
5153 +       __asm__ __volatile__ ("sd $gp, %0" : : "m" (curr_context[0]));
5154 +       __asm__ __volatile__ ("sd $16, %0" : : "m" (curr_context[1]));
5155 +       __asm__ __volatile__ ("sd $17, %0" : : "m" (curr_context[2]));
5156 +       __asm__ __volatile__ ("sd $18, %0" : : "m" (curr_context[3]));
5157 +       __asm__ __volatile__ ("sd $19, %0" : : "m" (curr_context[4]));
5158 +       __asm__ __volatile__ ("sd $20, %0" : : "m" (curr_context[5]));
5159 +       __asm__ __volatile__ ("sd $21, %0" : : "m" (curr_context[6]));
5160 +       __asm__ __volatile__ ("sd $22, %0" : : "m" (curr_context[7]));
5161 +       __asm__ __volatile__ ("sd $23, %0" : : "m" (curr_context[8]));
5162 +       __asm__ __volatile__ ("sd $31, %0" : : "m" (curr_context[9]));
5163 +       curr_context[10] = (long *)sp;
5164 +       curr_context[11] = (long *)fp;
5165 +
5166 +       return 0;
5167 +}
5168 +
5169 +void kgdb_fault_longjmp(unsigned long *curr_context)
5170 +{
5171 +       unsigned long sp_val, fp_val;
5172 +
5173 +       __asm__ __volatile__ ("ld $gp, %0" : : "m" (curr_context[0]));
5174 +       __asm__ __volatile__ ("ld $16, %0" : : "m" (curr_context[1]));
5175 +       __asm__ __volatile__ ("ld $17, %0" : : "m" (curr_context[2]));
5176 +       __asm__ __volatile__ ("ld $18, %0" : : "m" (curr_context[3]));
5177 +       __asm__ __volatile__ ("ld $19, %0" : : "m" (curr_context[4]));
5178 +       __asm__ __volatile__ ("ld $20, %0" : : "m" (curr_context[5]));
5179 +       __asm__ __volatile__ ("ld $21, %0" : : "m" (curr_context[6]));
5180 +       __asm__ __volatile__ ("ld $22, %0" : : "m" (curr_context[7]));
5181 +       __asm__ __volatile__ ("ld $23, %0" : : "m" (curr_context[8]));
5182 +       __asm__ __volatile__ ("ld $25, %0" : : "m" (curr_context[9]));
5183 +       sp_val = curr_context[10];
5184 +       fp_val = curr_context[11];
5185 +       __asm__ __volatile__ ("ld $29, %0\n\t"
5186 +                             "ld $30, %1\n\t" : : "m" (sp_val), "m" (fp_val));
5187 +
5188 +       __asm__ __volatile__ ("dli $2, 1");
5189 +       __asm__ __volatile__ ("j $25");
5190 +
5191 +       for (;;);
5192 +}
5193 +#else
5194 +/*
5195 + * MIPS 32-bit
5196 + */
5197 +
5198 +int kgdb_fault_setjmp_aux(unsigned long *curr_context, int sp, int fp)
5199 +{
5200 +       __asm__ __volatile__("sw $gp, %0" : : "m" (curr_context[0]));
5201 +       __asm__ __volatile__("sw $16, %0" : : "m" (curr_context[1]));
5202 +       __asm__ __volatile__("sw $17, %0" : : "m" (curr_context[2]));
5203 +       __asm__ __volatile__("sw $18, %0" : : "m" (curr_context[3]));
5204 +       __asm__ __volatile__("sw $19, %0" : : "m" (curr_context[4]));
5205 +       __asm__ __volatile__("sw $20, %0" : : "m" (curr_context[5]));
5206 +       __asm__ __volatile__("sw $21, %0" : : "m" (curr_context[6]));
5207 +       __asm__ __volatile__("sw $22, %0" : : "m" (curr_context[7]));
5208 +       __asm__ __volatile__("sw $23, %0" : : "m" (curr_context[8]));
5209 +       __asm__ __volatile__("sw $31, %0" : : "m" (curr_context[9]));
5210 +       curr_context[10] = (long *)sp;
5211 +       curr_context[11] = (long *)fp;
5212 +
5213 +       return 0;
5214 +}
5215 +
5216 +void kgdb_fault_longjmp(unsigned long *curr_context)
5217 +{
5218 +       unsigned long sp_val, fp_val;
5219 +
5220 +       __asm__ __volatile__("lw $gp, %0" : : "m" (curr_context[0]));
5221 +       __asm__ __volatile__("lw $16, %0" : : "m" (curr_context[1]));
5222 +       __asm__ __volatile__("lw $17, %0" : : "m" (curr_context[2]));
5223 +       __asm__ __volatile__("lw $18, %0" : : "m" (curr_context[3]));
5224 +       __asm__ __volatile__("lw $19, %0" : : "m" (curr_context[4]));
5225 +       __asm__ __volatile__("lw $20, %0" : : "m" (curr_context[5]));
5226 +       __asm__ __volatile__("lw $21, %0" : : "m" (curr_context[6]));
5227 +       __asm__ __volatile__("lw $22, %0" : : "m" (curr_context[7]));
5228 +       __asm__ __volatile__("lw $23, %0" : : "m" (curr_context[8]));
5229 +       __asm__ __volatile__("lw $25, %0" : : "m" (curr_context[9]));
5230 +       sp_val = curr_context[10];
5231 +       fp_val = curr_context[11];
5232 +       __asm__ __volatile__("lw $29, %0\n\t"
5233 +                             "lw $30, %1\n\t" : : "m" (sp_val), "m" (fp_val));
5234 +
5235 +       __asm__ __volatile__("li $2, 1");
5236 +       __asm__ __volatile__("jr $25");
5237 +
5238 +       for (;;);
5239 +}
5240 +#endif
5241 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/kernel/kgdb-setjmp.S linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/kgdb-setjmp.S
5242 --- linux-2.6.18-53.1.14/arch/mips/kernel/kgdb-setjmp.S 1970-01-01 03:00:00.000000000 +0300
5243 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/kgdb-setjmp.S    2008-06-10 15:38:24.000000000 +0400
5244 @@ -0,0 +1,28 @@
5245 +/*
5246 + * arch/mips/kernel/kgdb-jmp.c
5247 + *
5248 + * Save and restore system registers so that within a limited frame we
5249 + * may have a fault and "jump back" to a known safe location.
5250 + *
5251 + * Copyright (C) 2005 by MontaVista Software.
5252 + * Author: Manish Lachwani (mlachwani@mvista.com)
5253 + *
5254 + * This file is licensed under the terms of the GNU General Public License
5255 + * version 2. This program as licensed "as is" without any warranty of
5256 + * any kind, whether express or implied.
5257 + */
5258 +
5259 +#include <asm/asm.h>
5260 +#include <asm/mipsregs.h>
5261 +#include <asm/regdef.h>
5262 +#include <asm/stackframe.h>
5263 +
5264 +       .ent    kgdb_fault_setjmp,0
5265 +ENTRY (kgdb_fault_setjmp)
5266 +       move    a1, sp
5267 +       move    a2, fp
5268 +#ifdef CONFIG_MIPS64
5269 +       nop
5270 +#endif
5271 +       j       kgdb_fault_setjmp_aux
5272 +       .end    kgdb_fault_setjmp
5273 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/kernel/kgdb.c linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/kgdb.c
5274 --- linux-2.6.18-53.1.14/arch/mips/kernel/kgdb.c        1970-01-01 03:00:00.000000000 +0300
5275 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/kgdb.c   2008-06-10 15:38:24.000000000 +0400
5276 @@ -0,0 +1,297 @@
5277 +/*
5278 + * arch/mips/kernel/kgdb.c
5279 + *
5280 + *  Originally written by Glenn Engel, Lake Stevens Instrument Division
5281 + *
5282 + *  Contributed by HP Systems
5283 + *
5284 + *  Modified for SPARC by Stu Grossman, Cygnus Support.
5285 + *
5286 + *  Modified for Linux/MIPS (and MIPS in general) by Andreas Busse
5287 + *  Send complaints, suggestions etc. to <andy@waldorf-gmbh.de>
5288 + *
5289 + *  Copyright (C) 1995 Andreas Busse
5290 + *
5291 + *  Copyright (C) 2003 MontaVista Software Inc.
5292 + *  Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
5293 + *
5294 + *  Copyright (C) 2004-2005 MontaVista Software Inc.
5295 + *  Author: Manish Lachwani, mlachwani@mvista.com or manish@koffee-break.com
5296 + *
5297 + *  This file is licensed under the terms of the GNU General Public License
5298 + *  version 2. This program is licensed "as is" without any warranty of any
5299 + *  kind, whether express or implied.
5300 + */
5301 +
5302 +#include <linux/string.h>
5303 +#include <linux/kernel.h>
5304 +#include <linux/sched.h>
5305 +#include <linux/smp.h>
5306 +#include <linux/spinlock.h>
5307 +#include <linux/delay.h>
5308 +#include <asm/system.h>
5309 +#include <asm/ptrace.h>                /* for linux pt_regs struct */
5310 +#include <linux/kgdb.h>
5311 +#include <linux/init.h>
5312 +#include <asm/inst.h>
5313 +#include <asm/gdb-stub.h>
5314 +#include <asm/cacheflush.h>
5315 +#include <asm/kdebug.h>
5316 +
5317 +static struct hard_trap_info {
5318 +       unsigned char tt;       /* Trap type code for MIPS R3xxx and R4xxx */
5319 +       unsigned char signo;    /* Signal that we map this trap into */
5320 +} hard_trap_info[] = {
5321 +       { 6, SIGBUS },          /* instruction bus error */
5322 +       { 7, SIGBUS },          /* data bus error */
5323 +       { 9, SIGTRAP },         /* break */
5324 +/*     { 11, SIGILL }, */      /* CPU unusable */
5325 +       { 12, SIGFPE },         /* overflow */
5326 +       { 13, SIGTRAP },        /* trap */
5327 +       { 14, SIGSEGV },        /* virtual instruction cache coherency */
5328 +       { 15, SIGFPE },         /* floating point exception */
5329 +       { 23, SIGSEGV },        /* watch */
5330 +       { 31, SIGSEGV },        /* virtual data cache coherency */
5331 +       { 0, 0}                 /* Must be last */
5332 +};
5333 +
5334 +/* Save the normal trap handlers for user-mode traps. */
5335 +void *saved_vectors[32];
5336 +
5337 +extern void trap_low(void);
5338 +extern void breakinst(void);
5339 +extern void init_IRQ(void);
5340 +
5341 +void kgdb_call_nmi_hook(void *ignored)
5342 +{
5343 +       kgdb_nmihook(smp_processor_id(), (void *)0);
5344 +}
5345 +
5346 +void kgdb_roundup_cpus(unsigned long flags)
5347 +{
5348 +       local_irq_restore(flags);
5349 +       smp_call_function(kgdb_call_nmi_hook, 0, 0, 0);
5350 +       local_irq_save(flags);
5351 +}
5352 +
5353 +static int compute_signal(int tt)
5354 +{
5355 +       struct hard_trap_info *ht;
5356 +
5357 +       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
5358 +               if (ht->tt == tt)
5359 +                       return ht->signo;
5360 +
5361 +       return SIGHUP;          /* default for things we don't know about */
5362 +}
5363 +
5364 +/*
5365 + * Set up exception handlers for tracing and breakpoints
5366 + */
5367 +void handle_exception(struct pt_regs *regs)
5368 +{
5369 +       int trap = (regs->cp0_cause & 0x7c) >> 2;
5370 +
5371 +       if (fixup_exception(regs)) {
5372 +               return;
5373 +       }
5374 +
5375 +       if (atomic_read(&debugger_active))
5376 +               kgdb_nmihook(smp_processor_id(), regs);
5377 +
5378 +       if (atomic_read(&kgdb_setting_breakpoint))
5379 +               if ((trap == 9) && (regs->cp0_epc == (unsigned long)breakinst))
5380 +                       regs->cp0_epc += 4;
5381 +
5382 +       kgdb_handle_exception(0, compute_signal(trap), 0, regs);
5383 +
5384 +       /* In SMP mode, __flush_cache_all does IPI */
5385 +       __flush_cache_all();
5386 +}
5387 +
5388 +void set_debug_traps(void)
5389 +{
5390 +       struct hard_trap_info *ht;
5391 +       unsigned long flags;
5392 +
5393 +       local_irq_save(flags);
5394 +
5395 +       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
5396 +               saved_vectors[ht->tt] = set_except_vector(ht->tt, trap_low);
5397 +
5398 +       local_irq_restore(flags);
5399 +}
5400 +
5401 +#if 0
5402 +/* This should be called before we exit kgdb_handle_exception() I believe.
5403 + * -- Tom
5404 + */
5405 +void restore_debug_traps(void)
5406 +{
5407 +       struct hard_trap_info *ht;
5408 +       unsigned long flags;
5409 +
5410 +       local_irq_save(flags);
5411 +       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
5412 +               set_except_vector(ht->tt, saved_vectors[ht->tt]);
5413 +       local_irq_restore(flags);
5414 +}
5415 +#endif
5416 +
5417 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
5418 +{
5419 +       int reg;
5420 +       gdb_reg_t *ptr = (gdb_reg_t*)gdb_regs;
5421 +
5422 +       for (reg = 0; reg < 32; reg++)
5423 +               *(ptr++) = regs->regs[reg];
5424 +
5425 +       *(ptr++) = regs->cp0_status;
5426 +       *(ptr++) = regs->lo;
5427 +       *(ptr++) = regs->hi;
5428 +       *(ptr++) = regs->cp0_badvaddr;
5429 +       *(ptr++) = regs->cp0_cause;
5430 +       *(ptr++) = regs->cp0_epc;
5431 +
5432 +       return;
5433 +}
5434 +
5435 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
5436 +{
5437 +
5438 +       int reg;
5439 +       const gdb_reg_t *ptr = (gdb_reg_t*)gdb_regs;
5440 +
5441 +       for (reg = 0; reg < 32; reg++)
5442 +               regs->regs[reg] = *(ptr++);
5443 +
5444 +       regs->cp0_status = *(ptr++);
5445 +       regs->lo = *(ptr++);
5446 +       regs->hi = *(ptr++);
5447 +       regs->cp0_badvaddr = *(ptr++);
5448 +       regs->cp0_cause = *(ptr++);
5449 +       regs->cp0_epc = *(ptr++);
5450 +
5451 +       return;
5452 +}
5453 +
5454 +/*
5455 + * Similar to regs_to_gdb_regs() except that process is sleeping and so
5456 + * we may not be able to get all the info.
5457 + */
5458 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
5459 +{
5460 +       int reg;
5461 +       struct thread_info *ti = p->thread_info;
5462 +       unsigned long ksp = (unsigned long)ti + THREAD_SIZE - 32;
5463 +       struct pt_regs *regs = (struct pt_regs *)ksp - 1;
5464 +       gdb_reg_t *ptr = (gdb_reg_t*)gdb_regs;
5465 +
5466 +       for (reg = 0; reg < 16; reg++)
5467 +               *(ptr++) = regs->regs[reg];
5468 +
5469 +       /* S0 - S7 */
5470 +       for (reg = 16; reg < 24; reg++)
5471 +               *(ptr++) = regs->regs[reg];
5472 +
5473 +       for (reg = 24; reg < 28; reg++)
5474 +               *(ptr++) = 0;
5475 +
5476 +       /* GP, SP, FP, RA */
5477 +       for (reg = 28; reg < 32; reg++)
5478 +               *(ptr++) = regs->regs[reg];
5479 +
5480 +       *(ptr++) = regs->cp0_status;
5481 +       *(ptr++) = regs->lo;
5482 +       *(ptr++) = regs->hi;
5483 +       *(ptr++) = regs->cp0_badvaddr;
5484 +       *(ptr++) = regs->cp0_cause;
5485 +       *(ptr++) = regs->cp0_epc;
5486 +
5487 +       return;
5488 +}
5489 +
5490 +/*
5491 + * Calls linux_debug_hook before the kernel dies. If KGDB is enabled,
5492 + * then try to fall into the debugger
5493 + */
5494 +static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd,
5495 +                           void *ptr)
5496 +{
5497 +       struct die_args *args = (struct die_args *)ptr;
5498 +       struct pt_regs *regs = args->regs;
5499 +       int trap = (regs->cp0_cause & 0x7c) >> 2;
5500 +
5501 +       /* See if KGDB is interested. */
5502 +       if (user_mode(regs))
5503 +               /* Userpace events, ignore. */
5504 +               return NOTIFY_DONE;
5505 +
5506 +       kgdb_handle_exception(trap, compute_signal(trap), 0, regs);
5507 +       return NOTIFY_OK;
5508 +}
5509 +
5510 +static struct notifier_block kgdb_notifier = {
5511 +       .notifier_call = kgdb_mips_notify,
5512 +};
5513 +
5514 +/*
5515 + * Handle the 's' and 'c' commands
5516 + */
5517 +int kgdb_arch_handle_exception(int vector, int signo, int err_code,
5518 +                              char *remcom_in_buffer, char *remcom_out_buffer,
5519 +                              struct pt_regs *regs)
5520 +{
5521 +       char *ptr;
5522 +       unsigned long address;
5523 +       int cpu = smp_processor_id();
5524 +
5525 +       switch (remcom_in_buffer[0]) {
5526 +       case 's':
5527 +       case 'c':
5528 +               /* handle the optional parameter */
5529 +               ptr = &remcom_in_buffer[1];
5530 +               if (kgdb_hex2long(&ptr, &address))
5531 +                       regs->cp0_epc = address;
5532 +
5533 +               atomic_set(&cpu_doing_single_step, -1);
5534 +               if (remcom_in_buffer[0] == 's')
5535 +                       if (kgdb_contthread)
5536 +                               atomic_set(&cpu_doing_single_step, cpu);
5537 +
5538 +               return 0;
5539 +       }
5540 +
5541 +       return -1;
5542 +}
5543 +
5544 +struct kgdb_arch arch_kgdb_ops = {
5545 +#ifdef CONFIG_CPU_LITTLE_ENDIAN
5546 +       .gdb_bpt_instr = {0xd},
5547 +#else
5548 +       .gdb_bpt_instr = {0x00, 0x00, 0x00, 0x0d},
5549 +#endif
5550 +};
5551 +
5552 +/*
5553 + * We use kgdb_early_setup so that functions we need to call now don't
5554 + * cause trouble when called again later.
5555 + */
5556 +int kgdb_arch_init(void)
5557 +{
5558 +       /* Board-specifics. */
5559 +       /* Force some calls to happen earlier. */
5560 +       if (kgdb_early_setup == 0) {
5561 +               trap_init();
5562 +               init_IRQ();
5563 +               kgdb_early_setup = 1;
5564 +       }
5565 +
5566 +       /* Set our traps. */
5567 +       /* This needs to be done more finely grained again, paired in
5568 +        * a before/after in kgdb_handle_exception(...) -- Tom */
5569 +       set_debug_traps();
5570 +       notifier_chain_register(&mips_die_chain, &kgdb_notifier);
5571 +
5572 +       return 0;
5573 +}
5574 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/kernel/kgdb_handler.S linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/kgdb_handler.S
5575 --- linux-2.6.18-53.1.14/arch/mips/kernel/kgdb_handler.S        1970-01-01 03:00:00.000000000 +0300
5576 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/kgdb_handler.S   2008-06-10 15:38:24.000000000 +0400
5577 @@ -0,0 +1,57 @@
5578 +/*
5579 + * arch/mips/kernel/kgdb_handler.S
5580 + *
5581 + * Copyright (C) 2004-2005 MontaVista Software Inc.
5582 + * Author: Manish Lachwani, mlachwani@mvista.com or manish@koffee-break.com
5583 + *
5584 + * This file is licensed under the terms of the GNU General Public
5585 + * version 2. This program is licensed "as is" without any warranty of any
5586 + * kind, whether express or implied.
5587 + */
5588 +
5589 +/*
5590 + * Trap Handler for the new KGDB framework. The main KGDB handler is
5591 + * handle_exception that will be called from here
5592 + *
5593 + */
5594 +
5595 +#include <linux/config.h>
5596 +#include <linux/sys.h>
5597 +
5598 +#include <asm/asm.h>
5599 +#include <asm/errno.h>
5600 +#include <asm/mipsregs.h>
5601 +#include <asm/regdef.h>
5602 +#include <asm/stackframe.h>
5603 +
5604 +       .align  5
5605 +       NESTED(trap_low, PT_SIZE, sp)
5606 +               .set    noat
5607 +               .set    noreorder
5608 +
5609 +               /*
5610 +                * Check for privileged instructions in user mode. For
5611 +                * this, check the cu0 bit in the CPU status register.
5612 +                */
5613 +               mfc0    k0, CP0_STATUS
5614 +               sll     k0, 3
5615 +               bltz    k0, 1f
5616 +               move    k1, sp
5617 +
5618 +               /*
5619 +                * GDB userland from within KGDB. If a user mode address
5620 +                * then jump to the saved exception handler
5621 +                */
5622 +               mfc0    k1, CP0_CAUSE
5623 +               andi    k1, k1, 0x7c
5624 +               PTR_L   k0, saved_vectors(k1)
5625 +               jr      k0
5626 +               nop
5627 +1:
5628 +               SAVE_ALL
5629 +               .set    at
5630 +               .set    reorder
5631 +               move    a0, sp
5632 +               jal     handle_exception
5633 +               j       ret_from_exception
5634 +       END(trap_low)
5635 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/kernel/traps.c linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/traps.c
5636 --- linux-2.6.18-53.1.14/arch/mips/kernel/traps.c       2006-09-20 07:42:06.000000000 +0400
5637 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/kernel/traps.c  2008-06-10 15:38:24.000000000 +0400
5638 @@ -10,6 +10,8 @@
5639   * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
5640   * Copyright (C) 2000, 01 MIPS Technologies, Inc.
5641   * Copyright (C) 2002, 2003, 2004, 2005  Maciej W. Rozycki
5642 + *
5643 + * KGDB specific changes - Manish Lachwani (mlachwani@mvista.com)
5644   */
5645  #include <linux/init.h>
5646  #include <linux/mm.h>
5647 @@ -20,6 +22,7 @@
5648  #include <linux/spinlock.h>
5649  #include <linux/kallsyms.h>
5650  #include <linux/bootmem.h>
5651 +#include <linux/kgdb.h>
5652  
5653  #include <asm/bootinfo.h>
5654  #include <asm/branch.h>
5655 @@ -40,6 +43,7 @@
5656  #include <asm/mmu_context.h>
5657  #include <asm/watch.h>
5658  #include <asm/types.h>
5659 +#include <asm/kdebug.h>
5660  
5661  extern asmlinkage void handle_int(void);
5662  extern asmlinkage void handle_tlbm(void);
5663 @@ -78,6 +82,21 @@ void (*board_bind_eic_interrupt)(int irq
5664   */
5665  #define MODULE_RANGE (8*1024*1024)
5666  
5667 +struct notifier_block *mips_die_chain;
5668 +static spinlock_t die_notifier_lock = SPIN_LOCK_UNLOCKED;
5669 +
5670 +int register_die_notifier(struct notifier_block *nb)
5671 +{
5672 +       int err = 0;
5673 +       unsigned long flags;
5674 +
5675 +       spin_lock_irqsave(&die_notifier_lock, flags);
5676 +       err = notifier_chain_register(&mips_die_chain, nb);
5677 +       spin_unlock_irqrestore(&die_notifier_lock, flags);
5678 +
5679 +       return err;
5680 +}
5681 +
5682  /*
5683   * This routine abuses get_user()/put_user() to reference pointers
5684   * with at least a bit of error checking ...
5685 @@ -1387,6 +1406,11 @@ void __init trap_init(void)
5686         extern char except_vec4;
5687         unsigned long i;
5688  
5689 +#if defined(CONFIG_KGDB)
5690 +       if (kgdb_early_setup)
5691 +               return; /* Already done */
5692 +#endif
5693 +
5694         if (cpu_has_veic || cpu_has_vint)
5695                 ebase = (unsigned long) alloc_bootmem_low_pages (0x200 + VECTORSPACING*64);
5696         else
5697 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/mips-boards/generic/Makefile linux-2.6.18-53.1.14.kgdb/arch/mips/mips-boards/generic/Makefile
5698 --- linux-2.6.18-53.1.14/arch/mips/mips-boards/generic/Makefile 2006-09-20 07:42:06.000000000 +0400
5699 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/mips-boards/generic/Makefile    2008-06-10 15:38:24.000000000 +0400
5700 @@ -21,6 +21,5 @@
5701  obj-y                          := reset.o display.o init.o memory.o printf.o \
5702                                    cmdline.o time.o
5703  obj-$(CONFIG_PCI)              += pci.o
5704 -obj-$(CONFIG_KGDB)             += gdb_hook.o
5705  
5706  EXTRA_AFLAGS := $(CFLAGS)
5707 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/mips-boards/generic/init.c linux-2.6.18-53.1.14.kgdb/arch/mips/mips-boards/generic/init.c
5708 --- linux-2.6.18-53.1.14/arch/mips/mips-boards/generic/init.c   2006-09-20 07:42:06.000000000 +0400
5709 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/mips-boards/generic/init.c      2008-06-10 15:38:24.000000000 +0400
5710 @@ -37,15 +37,6 @@
5711  
5712  #include <asm/mips-boards/malta.h>
5713  
5714 -#ifdef CONFIG_KGDB
5715 -extern int rs_kgdb_hook(int, int);
5716 -extern int rs_putDebugChar(char);
5717 -extern char rs_getDebugChar(void);
5718 -extern int saa9730_kgdb_hook(int);
5719 -extern int saa9730_putDebugChar(char);
5720 -extern char saa9730_getDebugChar(void);
5721 -#endif
5722 -
5723  int prom_argc;
5724  int *_prom_argv, *_prom_envp;
5725  
5726 @@ -172,58 +163,6 @@ static void __init console_config(void)
5727  }
5728  #endif
5729  
5730 -#ifdef CONFIG_KGDB
5731 -void __init kgdb_config (void)
5732 -{
5733 -       extern int (*generic_putDebugChar)(char);
5734 -       extern char (*generic_getDebugChar)(void);
5735 -       char *argptr;
5736 -       int line, speed;
5737 -
5738 -       argptr = prom_getcmdline();
5739 -       if ((argptr = strstr(argptr, "kgdb=ttyS")) != NULL) {
5740 -               argptr += strlen("kgdb=ttyS");
5741 -               if (*argptr != '0' && *argptr != '1')
5742 -                       printk("KGDB: Unknown serial line /dev/ttyS%c, "
5743 -                              "falling back to /dev/ttyS1\n", *argptr);
5744 -               line = *argptr == '0' ? 0 : 1;
5745 -               printk("KGDB: Using serial line /dev/ttyS%d for session\n", line);
5746 -
5747 -               speed = 0;
5748 -               if (*++argptr == ',')
5749 -               {
5750 -                       int c;
5751 -                       while ((c = *++argptr) && ('0' <= c && c <= '9'))
5752 -                               speed = speed * 10 + c - '0';
5753 -               }
5754 -#ifdef CONFIG_MIPS_ATLAS
5755 -               if (line == 1) {
5756 -                       speed = saa9730_kgdb_hook(speed);
5757 -                       generic_putDebugChar = saa9730_putDebugChar;
5758 -                       generic_getDebugChar = saa9730_getDebugChar;
5759 -               }
5760 -               else
5761 -#endif
5762 -               {
5763 -                       speed = rs_kgdb_hook(line, speed);
5764 -                       generic_putDebugChar = rs_putDebugChar;
5765 -                       generic_getDebugChar = rs_getDebugChar;
5766 -               }
5767 -
5768 -               prom_printf("KGDB: Using serial line /dev/ttyS%d at %d for session, "
5769 -                           "please connect your debugger\n", line ? 1 : 0, speed);
5770 -
5771 -               {
5772 -                       char *s;
5773 -                       for (s = "Please connect GDB to this port\r\n"; *s; )
5774 -                               generic_putDebugChar (*s++);
5775 -               }
5776 -
5777 -               /* Breakpoint is invoked after interrupts are initialised */
5778 -       }
5779 -}
5780 -#endif
5781 -
5782  void __init mips_nmi_setup (void)
5783  {
5784         void *base;
5785 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/mips-boards/malta/malta_setup.c linux-2.6.18-53.1.14.kgdb/arch/mips/mips-boards/malta/malta_setup.c
5786 --- linux-2.6.18-53.1.14/arch/mips/mips-boards/malta/malta_setup.c      2006-09-20 07:42:06.000000000 +0400
5787 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/mips-boards/malta/malta_setup.c 2008-06-10 15:38:24.000000000 +0400
5788 @@ -46,10 +46,6 @@ extern void mips_reboot_setup(void);
5789  extern void mips_time_init(void);
5790  extern unsigned long mips_rtc_get_time(void);
5791  
5792 -#ifdef CONFIG_KGDB
5793 -extern void kgdb_config(void);
5794 -#endif
5795 -
5796  struct resource standard_io_resources[] = {
5797         { .name = "dma1", .start = 0x00, .end = 0x1f, .flags = IORESOURCE_BUSY },
5798         { .name = "timer", .start = 0x40, .end = 0x5f, .flags = IORESOURCE_BUSY },
5799 @@ -124,10 +120,6 @@ void __init plat_mem_setup(void)
5800          */
5801         enable_dma(4);
5802  
5803 -#ifdef CONFIG_KGDB
5804 -       kgdb_config ();
5805 -#endif
5806 -
5807         if ((mips_revision_corid == MIPS_REVISION_CORID_BONITO64) ||
5808             (mips_revision_corid == MIPS_REVISION_CORID_CORE_20K) ||
5809             (mips_revision_corid == MIPS_REVISION_CORID_CORE_EMUL_BON)) {
5810 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/mm/extable.c linux-2.6.18-53.1.14.kgdb/arch/mips/mm/extable.c
5811 --- linux-2.6.18-53.1.14/arch/mips/mm/extable.c 2006-09-20 07:42:06.000000000 +0400
5812 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/mm/extable.c    2008-06-10 15:38:24.000000000 +0400
5813 @@ -3,6 +3,7 @@
5814   */
5815  #include <linux/module.h>
5816  #include <linux/spinlock.h>
5817 +#include <linux/kgdb.h>
5818  #include <asm/branch.h>
5819  #include <asm/uaccess.h>
5820  
5821 @@ -16,6 +17,12 @@ int fixup_exception(struct pt_regs *regs
5822  
5823                 return 1;
5824         }
5825 +#ifdef CONFIG_KGDB
5826 +       if (atomic_read(&debugger_active) && kgdb_may_fault)
5827 +               /* Restore our previous state. */
5828 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
5829 +               /* Not reached. */
5830 +#endif
5831  
5832         return 0;
5833  }
5834 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/sibyte/cfe/setup.c linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/cfe/setup.c
5835 --- linux-2.6.18-53.1.14/arch/mips/sibyte/cfe/setup.c   2006-09-20 07:42:06.000000000 +0400
5836 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/cfe/setup.c      2008-06-10 15:38:24.000000000 +0400
5837 @@ -58,10 +58,6 @@ int cfe_cons_handle;
5838  extern unsigned long initrd_start, initrd_end;
5839  #endif
5840  
5841 -#ifdef CONFIG_KGDB
5842 -extern int kgdb_port;
5843 -#endif
5844 -
5845  static void ATTRIB_NORET cfe_linux_exit(void *arg)
5846  {
5847         int warm = *(int *)arg;
5848 @@ -242,9 +238,6 @@ void __init prom_init(void)
5849         int argc = fw_arg0;
5850         char **envp = (char **) fw_arg2;
5851         int *prom_vec = (int *) fw_arg3;
5852 -#ifdef CONFIG_KGDB
5853 -       char *arg;
5854 -#endif
5855  
5856         _machine_restart   = cfe_linux_restart;
5857         _machine_halt      = cfe_linux_halt;
5858 @@ -308,13 +301,6 @@ void __init prom_init(void)
5859                 }
5860         }
5861  
5862 -#ifdef CONFIG_KGDB
5863 -       if ((arg = strstr(arcs_cmdline,"kgdb=duart")) != NULL)
5864 -               kgdb_port = (arg[10] == '0') ? 0 : 1;
5865 -       else
5866 -               kgdb_port = 1;
5867 -#endif
5868 -
5869  #ifdef CONFIG_BLK_DEV_INITRD
5870         {
5871                 char *ptr;
5872 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/sibyte/sb1250/Makefile linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/sb1250/Makefile
5873 --- linux-2.6.18-53.1.14/arch/mips/sibyte/sb1250/Makefile       2006-09-20 07:42:06.000000000 +0400
5874 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/sb1250/Makefile  2008-06-10 15:38:24.000000000 +0400
5875 @@ -4,5 +4,6 @@ obj-$(CONFIG_SMP)                       += smp.o
5876  obj-$(CONFIG_SIBYTE_TBPROF)            += bcm1250_tbprof.o
5877  obj-$(CONFIG_SIBYTE_STANDALONE)                += prom.o
5878  obj-$(CONFIG_SIBYTE_BUS_WATCHER)       += bus_watcher.o
5879 +obj-$(CONFIG_KGDB_SIBYTE)              += kgdb_sibyte.o
5880  
5881  EXTRA_AFLAGS := $(CFLAGS)
5882 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/sibyte/sb1250/irq.c linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/sb1250/irq.c
5883 --- linux-2.6.18-53.1.14/arch/mips/sibyte/sb1250/irq.c  2006-09-20 07:42:06.000000000 +0400
5884 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/sb1250/irq.c     2008-06-10 15:38:24.000000000 +0400
5885 @@ -30,6 +30,7 @@
5886  #include <asm/system.h>
5887  #include <asm/ptrace.h>
5888  #include <asm/io.h>
5889 +#include <asm/kgdb.h>
5890  
5891  #include <asm/sibyte/sb1250_regs.h>
5892  #include <asm/sibyte/sb1250_int.h>
5893 @@ -59,16 +60,6 @@ static void sb1250_set_affinity(unsigned
5894  extern unsigned long ldt_eoi_space;
5895  #endif
5896  
5897 -#ifdef CONFIG_KGDB
5898 -static int kgdb_irq;
5899 -
5900 -/* Default to UART1 */
5901 -int kgdb_port = 1;
5902 -#ifdef CONFIG_SIBYTE_SB1250_DUART
5903 -extern char sb1250_duart_present[];
5904 -#endif
5905 -#endif
5906 -
5907  static struct irq_chip sb1250_irq_type = {
5908         .typename = "SB1250-IMR",
5909         .startup = startup_sb1250_irq,
5910 @@ -324,6 +315,11 @@ void __init arch_init_irq(void)
5911         unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
5912                 STATUSF_IP1 | STATUSF_IP0;
5913  
5914 +#ifdef CONFIG_KGDB
5915 +       if (kgdb_early_setup)
5916 +               return;
5917 +#endif
5918 +
5919         /* Default everything to IP2 */
5920         for (i = 0; i < SB1250_NR_IRQS; i++) {  /* was I0 */
5921                 __raw_writeq(IMR_IP2_VAL,
5922 @@ -375,50 +371,6 @@ void __init arch_init_irq(void)
5923         /* Enable necessary IPs, disable the rest */
5924         change_c0_status(ST0_IM, imask);
5925  
5926 -#ifdef CONFIG_KGDB
5927 -       if (kgdb_flag) {
5928 -               kgdb_irq = K_INT_UART_0 + kgdb_port;
5929 -
5930 -#ifdef CONFIG_SIBYTE_SB1250_DUART
5931 -               sb1250_duart_present[kgdb_port] = 0;
5932 -#endif
5933 -               /* Setup uart 1 settings, mapper */
5934 -               __raw_writeq(M_DUART_IMR_BRK,
5935 -                            IOADDR(A_DUART_IMRREG(kgdb_port)));
5936 -
5937 -               sb1250_steal_irq(kgdb_irq);
5938 -               __raw_writeq(IMR_IP6_VAL,
5939 -                            IOADDR(A_IMR_REGISTER(0,
5940 -                                                  R_IMR_INTERRUPT_MAP_BASE) +
5941 -                                   (kgdb_irq << 3)));
5942 -               sb1250_unmask_irq(0, kgdb_irq);
5943 -       }
5944 -#endif
5945 -}
5946 -
5947 -#ifdef CONFIG_KGDB
5948 -
5949 -#include <linux/delay.h>
5950 -
5951 -#define duart_out(reg, val)     csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
5952 -#define duart_in(reg)           csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
5953 -
5954 -static void sb1250_kgdb_interrupt(struct pt_regs *regs)
5955 -{
5956 -       /*
5957 -        * Clear break-change status (allow some time for the remote
5958 -        * host to stop the break, since we would see another
5959 -        * interrupt on the end-of-break too)
5960 -        */
5961 -       kstat_this_cpu.irqs[kgdb_irq]++;
5962 -       mdelay(500);
5963 -       duart_out(R_DUART_CMD, V_DUART_MISC_CMD_RESET_BREAK_INT |
5964 -                               M_DUART_RX_EN | M_DUART_TX_EN);
5965 -       set_async_breakpoint(&regs->cp0_epc);
5966 -}
5967 -
5968 -#endif         /* CONFIG_KGDB */
5969 -
5970  static inline int dclz(unsigned long long x)
5971  {
5972         int lz;
5973 @@ -473,7 +425,7 @@ asmlinkage void plat_irq_dispatch(struct
5974                 sb1250_mailbox_interrupt(regs);
5975  #endif
5976  
5977 -#ifdef CONFIG_KGDB
5978 +#ifdef CONFIG_KGDB_SIBYTE
5979         else if (pending & CAUSEF_IP6)                  /* KGDB (uart 1) */
5980                 sb1250_kgdb_interrupt(regs);
5981  #endif
5982 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/sibyte/sb1250/kgdb_sibyte.c linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/sb1250/kgdb_sibyte.c
5983 --- linux-2.6.18-53.1.14/arch/mips/sibyte/sb1250/kgdb_sibyte.c  1970-01-01 03:00:00.000000000 +0300
5984 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/sb1250/kgdb_sibyte.c     2008-06-10 15:38:24.000000000 +0400
5985 @@ -0,0 +1,164 @@
5986 +/*
5987 + * arch/mips/sibyte/sb1250/kgdb_sibyte.c
5988 + *
5989 + * Author: Manish Lachwani, mlachwani@mvista.com or manish@koffee-break.com
5990 + *
5991 + * 2004 (c) MontaVista Software, Inc. This file is licensed under
5992 + * the terms of the GNU General Public License version 2. This program
5993 + * is licensed "as is" without any warranty of any kind, whether express
5994 + * or implied.
5995 + */
5996 +
5997 +/*
5998 + * Support for KGDB on the Broadcom Sibyte. The SWARM board
5999 + * for example does not have a 8250/16550 compatible serial
6000 + * port. Hence, we need to have a driver for the serial
6001 + * ports to handle KGDB.  This board needs nothing in addition
6002 + * to what is normally provided by the gdb portion of the stub.
6003 + */
6004 +
6005 +#include <linux/delay.h>
6006 +#include <linux/kernel_stat.h>
6007 +#include <linux/init.h>
6008 +#include <linux/kgdb.h>
6009 +
6010 +#include <asm/io.h>
6011 +#include <asm/sibyte/sb1250.h>
6012 +#include <asm/sibyte/sb1250_regs.h>
6013 +#include <asm/sibyte/sb1250_uart.h>
6014 +#include <asm/sibyte/sb1250_int.h>
6015 +#include <asm/addrspace.h>
6016 +
6017 +int kgdb_port = 1;
6018 +static int kgdb_irq;
6019 +
6020 +extern char sb1250_duart_present[];
6021 +extern int sb1250_steal_irq(int irq);
6022 +
6023 +/* Forward declarations. */
6024 +static void kgdbsibyte_init_duart(void);
6025 +static int kgdb_init_io(void);
6026 +
6027 +#define IMR_IP6_VAL    K_INT_MAP_I4
6028 +#define        duart_out(reg, val)     csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
6029 +#define duart_in(reg)          csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
6030 +
6031 +static void kgdb_swarm_write_char(int c)
6032 +{
6033 +       while ((duart_in(R_DUART_STATUS) & M_DUART_TX_RDY) == 0) ;
6034 +       duart_out(R_DUART_TX_HOLD, c);
6035 +}
6036 +
6037 +static int kgdb_swarm_read_char(void)
6038 +{
6039 +       int ret_char;
6040 +       unsigned int status;
6041 +
6042 +       status = duart_in(R_DUART_STATUS);
6043 +       while ((status & M_DUART_RX_RDY) == 0) {
6044 +               status = duart_in(R_DUART_STATUS);
6045 +       }
6046 +
6047 +       /*
6048 +        * Check for framing error
6049 +        */
6050 +       if (status & M_DUART_FRM_ERR) {
6051 +               kgdbsibyte_init_duart();
6052 +               kgdb_swarm_write_char('-');
6053 +               return '-';
6054 +       }
6055 +
6056 +       ret_char = duart_in(R_DUART_RX_HOLD);
6057 +
6058 +       return ret_char;
6059 +}
6060 +
6061 +void sb1250_kgdb_interrupt(struct pt_regs *regs)
6062 +{
6063 +       int kgdb_irq = K_INT_UART_0 + kgdb_port;
6064 +       /*
6065 +        * Clear break-change status (allow some time for the remote
6066 +        * host to stop the break, since we would see another
6067 +        * interrupt on the end-of-break too)
6068 +        */
6069 +       kstat_this_cpu.irqs[kgdb_irq]++;
6070 +       mdelay(500);
6071 +       duart_out(R_DUART_CMD, V_DUART_MISC_CMD_RESET_BREAK_INT |
6072 +                 M_DUART_RX_EN | M_DUART_TX_EN);
6073 +       if (kgdb_io_ops.init != kgdb_init_io) {
6074 +               /* Throw away the data if another I/O routine is
6075 +                * active.
6076 +                */
6077 +               unsigned int status;
6078 +
6079 +               status = duart_in(R_DUART_STATUS);
6080 +               while ((status & M_DUART_RX_RDY) == 0) {
6081 +                       status = duart_in(R_DUART_STATUS);
6082 +               }
6083 +               /*
6084 +                * Check for framing error
6085 +                */
6086 +               if (status & M_DUART_FRM_ERR) {
6087 +                       kgdbsibyte_init_duart();
6088 +               }
6089 +               duart_in(R_DUART_RX_HOLD);
6090 +       } else
6091 +               breakpoint();
6092 +
6093 +}
6094 +
6095 +/*
6096 + * We use port #1 and we set it for 115200 BAUD, 8n1.
6097 + */
6098 +static void kgdbsibyte_init_duart(void)
6099 +{
6100 +       /* Set 8n1. */
6101 +       duart_out(R_DUART_MODE_REG_1,
6102 +                 V_DUART_BITS_PER_CHAR_8 | V_DUART_PARITY_MODE_NONE);
6103 +       duart_out(R_DUART_MODE_REG_2, M_DUART_STOP_BIT_LEN_1);
6104 +       /* Set baud rate of 115200. */
6105 +       duart_out(R_DUART_CLK_SEL, V_DUART_BAUD_RATE(115200));
6106 +       /* Enable rx and tx */
6107 +       duart_out(R_DUART_CMD, M_DUART_RX_EN | M_DUART_TX_EN);
6108 +}
6109 +
6110 +static int kgdb_init_io(void)
6111 +{
6112 +#ifdef CONFIG_SIBYTE_SB1250_DUART
6113 +       sb1250_duart_present[kgdb_port] = 0;
6114 +#endif
6115 +
6116 +       kgdbsibyte_init_duart();
6117 +
6118 +       return 0;
6119 +}
6120 +
6121 +/*
6122 + * Hookup our IRQ line.  We will already have been initialized a
6123 + * this point.
6124 + */
6125 +static void __init kgdbsibyte_hookup_irq(void)
6126 +{
6127 +       /* Steal the IRQ. */
6128 +       kgdb_irq = K_INT_UART_0 + kgdb_port;
6129 +
6130 +       /* Setup uart 1 settings, mapper */
6131 +       __raw_writeq(M_DUART_IMR_BRK, IOADDR(A_DUART_IMRREG(kgdb_port)));
6132 +
6133 +       sb1250_steal_irq(kgdb_irq);
6134 +
6135 +       __raw_writeq(IMR_IP6_VAL,
6136 +                    IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE) +
6137 +                           (kgdb_irq << 3)));
6138 +
6139 +       sb1250_unmask_irq(0, kgdb_irq);
6140 +}
6141 +
6142 +struct kgdb_io kgdb_io_ops = {
6143 +       .read_char = kgdb_swarm_read_char,
6144 +       .write_char = kgdb_swarm_write_char,
6145 +       .init = kgdb_init_io,
6146 +       .late_init = kgdbsibyte_hookup_irq,
6147 +       .pre_exception = NULL,
6148 +       .post_exception = NULL
6149 +};
6150 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/sibyte/swarm/Makefile linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/swarm/Makefile
6151 --- linux-2.6.18-53.1.14/arch/mips/sibyte/swarm/Makefile        2006-09-20 07:42:06.000000000 +0400
6152 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/swarm/Makefile   2008-06-10 15:38:24.000000000 +0400
6153 @@ -1,3 +1 @@
6154  lib-y                          = setup.o rtc_xicor1241.o rtc_m41t81.o
6155 -
6156 -lib-$(CONFIG_KGDB)             += dbg_io.o
6157 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/sibyte/swarm/dbg_io.c linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/swarm/dbg_io.c
6158 --- linux-2.6.18-53.1.14/arch/mips/sibyte/swarm/dbg_io.c        2006-09-20 07:42:06.000000000 +0400
6159 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/sibyte/swarm/dbg_io.c   1970-01-01 03:00:00.000000000 +0300
6160 @@ -1,76 +0,0 @@
6161 -/*
6162 - * kgdb debug routines for SiByte boards.
6163 - *
6164 - * Copyright (C) 2001 MontaVista Software Inc.
6165 - * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
6166 - *
6167 - * This program is free software; you can redistribute  it and/or modify it
6168 - * under  the terms of  the GNU General  Public License as published by the
6169 - * Free Software Foundation;  either version 2 of the  License, or (at your
6170 - * option) any later version.
6171 - *
6172 - */
6173 -
6174 -/* -------------------- BEGINNING OF CONFIG --------------------- */
6175 -
6176 -#include <linux/delay.h>
6177 -#include <asm/io.h>
6178 -#include <asm/sibyte/sb1250.h>
6179 -#include <asm/sibyte/sb1250_regs.h>
6180 -#include <asm/sibyte/sb1250_uart.h>
6181 -#include <asm/sibyte/sb1250_int.h>
6182 -#include <asm/addrspace.h>
6183 -
6184 -/*
6185 - * We use the second serial port for kgdb traffic.
6186 - *     115200, 8, N, 1.
6187 - */
6188 -
6189 -#define        BAUD_RATE               115200
6190 -#define        CLK_DIVISOR             V_DUART_BAUD_RATE(BAUD_RATE)
6191 -#define        DATA_BITS               V_DUART_BITS_PER_CHAR_8         /* or 7    */
6192 -#define        PARITY                  V_DUART_PARITY_MODE_NONE        /* or even */
6193 -#define        STOP_BITS               M_DUART_STOP_BIT_LEN_1          /* or 2    */
6194 -
6195 -static int duart_initialized = 0;      /* 0: need to be init'ed by kgdb */
6196 -
6197 -/* -------------------- END OF CONFIG --------------------- */
6198 -extern int kgdb_port;
6199 -
6200 -#define        duart_out(reg, val)     csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
6201 -#define duart_in(reg)          csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
6202 -
6203 -void putDebugChar(unsigned char c);
6204 -unsigned char getDebugChar(void);
6205 -static void
6206 -duart_init(int clk_divisor, int data, int parity, int stop)
6207 -{
6208 -       duart_out(R_DUART_MODE_REG_1, data | parity);
6209 -       duart_out(R_DUART_MODE_REG_2, stop);
6210 -       duart_out(R_DUART_CLK_SEL, clk_divisor);
6211 -
6212 -       duart_out(R_DUART_CMD, M_DUART_RX_EN | M_DUART_TX_EN);  /* enable rx and tx */
6213 -}
6214 -
6215 -void
6216 -putDebugChar(unsigned char c)
6217 -{
6218 -       if (!duart_initialized) {
6219 -               duart_initialized = 1;
6220 -               duart_init(CLK_DIVISOR, DATA_BITS, PARITY, STOP_BITS);
6221 -       }
6222 -       while ((duart_in(R_DUART_STATUS) & M_DUART_TX_RDY) == 0);
6223 -       duart_out(R_DUART_TX_HOLD, c);
6224 -}
6225 -
6226 -unsigned char
6227 -getDebugChar(void)
6228 -{
6229 -       if (!duart_initialized) {
6230 -               duart_initialized = 1;
6231 -               duart_init(CLK_DIVISOR, DATA_BITS, PARITY, STOP_BITS);
6232 -       }
6233 -       while ((duart_in(R_DUART_STATUS) & M_DUART_RX_RDY) == 0) ;
6234 -       return duart_in(R_DUART_RX_HOLD);
6235 -}
6236 -
6237 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/mips/tx4938/common/Makefile linux-2.6.18-53.1.14.kgdb/arch/mips/tx4938/common/Makefile
6238 --- linux-2.6.18-53.1.14/arch/mips/tx4938/common/Makefile       2006-09-20 07:42:06.000000000 +0400
6239 +++ linux-2.6.18-53.1.14.kgdb/arch/mips/tx4938/common/Makefile  2008-06-10 15:38:24.000000000 +0400
6240 @@ -7,5 +7,5 @@
6241  #
6242  
6243  obj-y  += prom.o setup.o irq.o rtc_rx5c348.o
6244 -obj-$(CONFIG_KGDB) += dbgio.o
6245 +obj-$(CONFIG_KGDB_8250) += dbgio.o
6246  
6247 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/powerpc/Kconfig.debug linux-2.6.18-53.1.14.kgdb/arch/powerpc/Kconfig.debug
6248 --- linux-2.6.18-53.1.14/arch/powerpc/Kconfig.debug     2006-09-20 07:42:06.000000000 +0400
6249 +++ linux-2.6.18-53.1.14.kgdb/arch/powerpc/Kconfig.debug        2008-06-10 15:38:14.000000000 +0400
6250 @@ -18,52 +18,9 @@ config DEBUG_STACK_USAGE
6251  
6252           This option will slow down process creation somewhat.
6253  
6254 -config DEBUGGER
6255 -       bool "Enable debugger hooks"
6256 -       depends on DEBUG_KERNEL
6257 -       help
6258 -         Include in-kernel hooks for kernel debuggers. Unless you are
6259 -         intending to debug the kernel, say N here.
6260 -
6261 -config KGDB
6262 -       bool "Include kgdb kernel debugger"
6263 -       depends on DEBUGGER && (BROKEN || PPC_GEN550 || 4xx)
6264 -       select DEBUG_INFO
6265 -       help
6266 -         Include in-kernel hooks for kgdb, the Linux kernel source level
6267 -         debugger.  See <http://kgdb.sourceforge.net/> for more information.
6268 -         Unless you are intending to debug the kernel, say N here.
6269 -
6270 -choice
6271 -       prompt "Serial Port"
6272 -       depends on KGDB
6273 -       default KGDB_TTYS1
6274 -
6275 -config KGDB_TTYS0
6276 -       bool "ttyS0"
6277 -
6278 -config KGDB_TTYS1
6279 -       bool "ttyS1"
6280 -
6281 -config KGDB_TTYS2
6282 -       bool "ttyS2"
6283 -
6284 -config KGDB_TTYS3
6285 -       bool "ttyS3"
6286 -
6287 -endchoice
6288 -
6289 -config KGDB_CONSOLE
6290 -       bool "Enable serial console thru kgdb port"
6291 -       depends on KGDB && 8xx || CPM2
6292 -       help
6293 -         If you enable this, all serial console messages will be sent
6294 -         over the gdb stub.
6295 -         If unsure, say N.
6296 -
6297  config XMON
6298         bool "Include xmon kernel debugger"
6299 -       depends on DEBUGGER && !PPC_ISERIES
6300 +       depends on DEBUG_KERNEL && !PPC_ISERIES
6301         help
6302           Include in-kernel hooks for the xmon kernel monitor/debugger.
6303           Unless you are intending to debug the kernel, say N here.
6304 @@ -82,6 +39,11 @@ config XMON_DEFAULT
6305           xmon is normally disabled unless booted with 'xmon=on'.
6306           Use 'xmon=off' to disable xmon init during runtime.
6307  
6308 +config DEBUGGER
6309 +       bool
6310 +       depends on KGDB || XMON
6311 +       default y
6312 +
6313  config IRQSTACKS
6314         bool "Use separate kernel stacks when processing interrupts"
6315         depends on PPC64
6316 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/powerpc/kernel/Makefile linux-2.6.18-53.1.14.kgdb/arch/powerpc/kernel/Makefile
6317 --- linux-2.6.18-53.1.14/arch/powerpc/kernel/Makefile   2008-03-06 05:54:47.000000000 +0300
6318 +++ linux-2.6.18-53.1.14.kgdb/arch/powerpc/kernel/Makefile      2008-06-10 15:38:14.000000000 +0400
6319 @@ -59,6 +59,7 @@ obj-$(CONFIG_PPC64)           += misc_64.o dma_64
6320  obj-$(CONFIG_PPC_MULTIPLATFORM)        += prom_init.o
6321  obj-$(CONFIG_MODULES)          += ppc_ksyms.o
6322  obj-$(CONFIG_BOOTX_TEXT)       += btext.o
6323 +obj-$(CONFIG_KGDB)             += kgdb.o
6324  obj-$(CONFIG_SMP)              += smp.o
6325  obj-$(CONFIG_KPROBES)          += kprobes.o
6326  obj-$(CONFIG_PPC_UDBG_16550)   += legacy_serial.o udbg_16550.o
6327 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/powerpc/kernel/kgdb.c linux-2.6.18-53.1.14.kgdb/arch/powerpc/kernel/kgdb.c
6328 --- linux-2.6.18-53.1.14/arch/powerpc/kernel/kgdb.c     1970-01-01 03:00:00.000000000 +0300
6329 +++ linux-2.6.18-53.1.14.kgdb/arch/powerpc/kernel/kgdb.c        2008-06-10 15:38:14.000000000 +0400
6330 @@ -0,0 +1,568 @@
6331 +/*
6332 + * arch/powerpc/kernel/kgdb.c
6333 + *
6334 + * PowerPC backend to the KGDB stub.
6335 + *
6336 + * Maintainer: Tom Rini <trini@kernel.crashing.org>
6337 + *
6338 + * Copied from arch/ppc/kernel/kgdb.c, updated for ppc64
6339 + *
6340 + * Copyright (C) 1996 Paul Mackerras (setjmp/longjmp)
6341 + * 1998 (c) Michael AK Tesch (tesch@cs.wisc.edu)
6342 + * Copyright (C) 2003 Timesys Corporation.
6343 + * Copyright (C) 2004-2006 MontaVista Software, Inc.
6344 + * PPC64 Mods (C) 2005 Frank Rowand (frowand@mvista.com)
6345 + * PPC32 support restored by Vitaly Wool <vwool@ru.mvista.com> and
6346 + * Sergei Shtylyov <sshtylyov@ru.mvista.com>
6347 + *
6348 + * This file is licensed under the terms of the GNU General Public License
6349 + * version 2. This program as licensed "as is" without any warranty of any
6350 + * kind, whether express or implied.
6351 + */
6352 +
6353 +#include <linux/config.h>
6354 +#include <linux/kernel.h>
6355 +#include <linux/init.h>
6356 +#include <linux/kgdb.h>
6357 +#include <linux/smp.h>
6358 +#include <linux/signal.h>
6359 +#include <linux/ptrace.h>
6360 +#include <asm/current.h>
6361 +#include <asm/ptrace.h>
6362 +#include <asm/processor.h>
6363 +#include <asm/machdep.h>
6364 +
6365 +/*
6366 + * This table contains the mapping between PowerPC hardware trap types, and
6367 + * signals, which are primarily what GDB understands.  GDB and the kernel
6368 + * don't always agree on values, so we use constants taken from gdb-6.2.
6369 + */
6370 +static struct hard_trap_info
6371 +{
6372 +       unsigned int tt;                /* Trap type code for powerpc */
6373 +       unsigned char signo;            /* Signal that we map this trap into */
6374 +} hard_trap_info[] = {
6375 +       { 0x0100, 0x02 /* SIGINT */  },         /* system reset */
6376 +       { 0x0200, 0x0b /* SIGSEGV */ },         /* machine check */
6377 +       { 0x0300, 0x0b /* SIGSEGV */ },         /* data access */
6378 +       { 0x0400, 0x0b /* SIGSEGV */ },  /* instruction access */
6379 +       { 0x0500, 0x02 /* SIGINT */  },  /* external interrupt */
6380 +       { 0x0600, 0x0a /* SIGBUS */  },         /* alignment */
6381 +       { 0x0700, 0x05 /* SIGTRAP */ },  /* program check */
6382 +       { 0x0800, 0x08 /* SIGFPE */  },  /* fp unavailable */
6383 +       { 0x0900, 0x0e /* SIGALRM */ },  /* decrementer */
6384 +       { 0x0c00, 0x14 /* SIGCHLD */ },  /* system call */
6385 +#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
6386 +       { 0x2002, 0x05 /* SIGTRAP */ },  /* debug */
6387 +#if defined(CONFIG_FSL_BOOKE)
6388 +       { 0x2010, 0x08 /* SIGFPE */  },  /* spe unavailable */
6389 +       { 0x2020, 0x08 /* SIGFPE */  },  /* spe unavailable */
6390 +       { 0x2030, 0x08 /* SIGFPE */  },  /* spe fp data */
6391 +       { 0x2040, 0x08 /* SIGFPE */  },  /* spe fp data */
6392 +       { 0x2050, 0x08 /* SIGFPE */  },  /* spe fp round */
6393 +       { 0x2060, 0x0e /* SIGILL */  },  /* performace monitor */
6394 +       { 0x2900, 0x08 /* SIGFPE */  },  /* apu unavailable */
6395 +       { 0x3100, 0x0e /* SIGALRM */ },  /* fixed interval timer */
6396 +       { 0x3200, 0x02 /* SIGINT */  },  /* watchdog */
6397 +#else
6398 +       { 0x1000, 0x0e /* SIGALRM */ },  /* programmable interval timer */
6399 +       { 0x1010, 0x0e /* SIGALRM */ },  /* fixed interval timer */
6400 +       { 0x1020, 0x02 /* SIGINT */  },  /* watchdog */
6401 +       { 0x2010, 0x08 /* SIGFPE */  },  /* fp unavailable */
6402 +       { 0x2020, 0x08 /* SIGFPE */  },  /* ap unavailable */
6403 +#endif
6404 +#else
6405 +       { 0x0d00, 0x05 /* SIGTRAP */ },  /* single-step */
6406 +#if defined(CONFIG_8xx)
6407 +       { 0x1000, 0x04 /* SIGILL */  },  /* software emulation */
6408 +#else
6409 +       { 0x0f00, 0x04 /* SIGILL */  },         /* performance monitor */
6410 +       { 0x0f20, 0x08 /* SIGFPE */  },         /* altivec unavailable */
6411 +       { 0x1300, 0x05 /* SIGTRAP */ },         /* instruction address break */
6412 +#if defined(CONFIG_PPC64)
6413 +       { 0x1200, 0x05 /* SIGILL */  },         /* system error */
6414 +       { 0x1500, 0x04 /* SIGILL */  },         /* soft patch */
6415 +       { 0x1600, 0x04 /* SIGILL */  },         /* maintenance */
6416 +       { 0x1700, 0x08 /* SIGFPE */  },  /* altivec assist */
6417 +       { 0x1800, 0x04 /* SIGILL */  },         /* thermal */
6418 +#else
6419 +       { 0x1400, 0x02 /* SIGINT */  },  /* SMI */
6420 +       { 0x1600, 0x08 /* SIGFPE */  },  /* altivec assist */
6421 +       { 0x1700, 0x04 /* SIGILL */  },  /* TAU */
6422 +       { 0x2000, 0x05 /* SIGTRAP */ },  /* run mode */
6423 +#endif
6424 +#endif
6425 +#endif
6426 +       { 0x0000, 0x00 }                        /* Must be last */
6427 +};
6428 +
6429 +extern atomic_t cpu_doing_single_step;
6430 +
6431 +static int computeSignal(unsigned int tt)
6432 +{
6433 +       struct hard_trap_info *ht;
6434 +
6435 +       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
6436 +               if (ht->tt == tt)
6437 +                       return ht->signo;
6438 +
6439 +       return SIGHUP;          /* default for things we don't know about */
6440 +}
6441 +
6442 +static int kgdb_call_nmi_hook(struct pt_regs *regs)
6443 +{
6444 +       kgdb_nmihook(smp_processor_id(), regs);
6445 +       return 0;
6446 +}
6447 +
6448 +#ifdef CONFIG_SMP
6449 +void kgdb_roundup_cpus(unsigned long flags)
6450 +{
6451 +       smp_send_debugger_break(MSG_ALL_BUT_SELF);
6452 +}
6453 +#endif
6454 +
6455 +/* KGDB functions to use existing PowerPC64 hooks. */
6456 +static int kgdb_debugger(struct pt_regs *regs)
6457 +{
6458 +       return kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
6459 +}
6460 +
6461 +static int kgdb_breakpoint(struct pt_regs *regs)
6462 +{
6463 +       if (user_mode(regs))
6464 +               return 0;
6465 +
6466 +       kgdb_handle_exception(0, SIGTRAP, 0, regs);
6467 +
6468 +       if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
6469 +               regs->nip += 4;
6470 +
6471 +       return 1;
6472 +}
6473 +
6474 +static int kgdb_singlestep(struct pt_regs *regs)
6475 +{
6476 +       struct thread_info *thread_info, *exception_thread_info;
6477 +       if (user_mode(regs))
6478 +               return 0;
6479 +       /*
6480 +       * On Book E and perhaps other processsors, singlestep is handled on
6481 +       * the critical exception stack.  This causes current_thread_info()
6482 +       * to fail, since it it locates the thread_info by masking off
6483 +       * the low bits of the current stack pointer.  We work around
6484 +       * this issue by copying the thread_info from the kernel stack
6485 +       * before calling kgdb_handle_exception, and copying it back
6486 +       * afterwards.  On most processors the copy is avoided since
6487 +       * exception_thread_info == thread_info.
6488 +       */
6489 +       thread_info = (struct thread_info *)(regs->gpr[1] & ~(THREAD_SIZE-1));
6490 +       exception_thread_info = current_thread_info();
6491 +
6492 +       if (thread_info != exception_thread_info)
6493 +               memcpy(exception_thread_info, thread_info, sizeof *thread_info);
6494 +
6495 +       kgdb_handle_exception(0, SIGTRAP, 0, regs);
6496 +
6497 +       if (thread_info != exception_thread_info)
6498 +               memcpy(thread_info, exception_thread_info, sizeof *thread_info);
6499 +
6500 +       return 1;
6501 +}
6502 +
6503 +int kgdb_iabr_match(struct pt_regs *regs)
6504 +{
6505 +       if (user_mode(regs))
6506 +               return 0;
6507 +
6508 +       kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
6509 +       return 1;
6510 +}
6511 +
6512 +int kgdb_dabr_match(struct pt_regs *regs)
6513 +{
6514 +       if (user_mode(regs))
6515 +               return 0;
6516 +
6517 +       kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
6518 +       return 1;
6519 +}
6520 +
6521 +#define PACK64(ptr,src) do { *(ptr++) = (src); } while(0)
6522 +
6523 +#define PACK32(ptr,src) do {          \
6524 +       u32 *ptr32;                   \
6525 +       ptr32 = (u32 *)ptr;           \
6526 +       *(ptr32++) = (src);           \
6527 +       ptr = (unsigned long *)ptr32; \
6528 +       } while(0)
6529 +
6530 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
6531 +{
6532 +       unsigned long *ptr = gdb_regs;
6533 +       int reg;
6534 +
6535 +       memset(gdb_regs, 0, NUMREGBYTES);
6536 +
6537 +       for (reg = 0; reg < 32; reg++)
6538 +               PACK64(ptr, regs->gpr[reg]);
6539 +
6540 +#ifdef CONFIG_FSL_BOOKE
6541 +#ifdef CONFIG_SPE
6542 +       for (reg = 0; reg < 32; reg++)
6543 +               PACK64(ptr, current->thread.evr[reg]);
6544 +#else
6545 +       ptr += 32;
6546 +#endif
6547 +#else
6548 +       /* fp registers not used by kernel, leave zero */
6549 +       ptr += 32 * 8 / sizeof(long);
6550 +#endif
6551 +
6552 +       PACK64(ptr, regs->nip);
6553 +       PACK64(ptr, regs->msr);
6554 +       PACK32(ptr, regs->ccr);
6555 +       PACK64(ptr, regs->link);
6556 +       PACK64(ptr, regs->ctr);
6557 +       PACK32(ptr, regs->xer);
6558 +
6559 +#if 0
6560 +       Following are in struct thread_struct, not struct pt_regs,
6561 +       ignoring for now since kernel does not use them.  Would it
6562 +       make sense to get them from the thread that kgdb is set to?
6563 +
6564 +       If this code is enabled, update the definition of NUMREGBYTES to
6565 +       include the vector registers and vector state registers.
6566 +
6567 +       PACK32(ptr, current->thread->fpscr);
6568 +
6569 +       /* vr registers not used by kernel, leave zero */
6570 +       ptr += 32 * 16 / sizeof(long);
6571 +
6572 +#ifdef CONFIG_ALTIVEC
6573 +       PACK32(ptr, current->thread->vscr);
6574 +       PACK32(ptr, current->thread->vrsave);
6575 +#else
6576 +       ptr += 2 * 4 / sizeof(long);
6577 +#endif
6578 +#else
6579 +#ifdef CONFIG_FSL_BOOKE
6580 +#ifdef CONFIG_SPE
6581 +       /* u64 acc */
6582 +       PACK32(ptr, current->thread.acc >> 32);
6583 +       PACK32(ptr, current->thread.acc & 0xffffffff);
6584 +       PACK64(ptr, current->thread.spefscr);
6585 +#else
6586 +       ptr += 2 + 1;
6587 +#endif
6588 +#else
6589 +       /* fpscr not used by kernel, leave zero */
6590 +       PACK32(ptr, 0);
6591 +#endif
6592 +#endif
6593 +
6594 +       BUG_ON((unsigned long)ptr >
6595 +              (unsigned long)(((void *)gdb_regs) + NUMREGBYTES));
6596 +}
6597 +
6598 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
6599 +{
6600 +       struct pt_regs *regs = (struct pt_regs *)(p->thread.ksp +
6601 +                                                 STACK_FRAME_OVERHEAD);
6602 +       unsigned long *ptr = gdb_regs;
6603 +       int reg;
6604 +
6605 +       memset(gdb_regs, 0, NUMREGBYTES);
6606 +
6607 +       /* Regs GPR0-2 */
6608 +       for (reg = 0; reg < 3; reg++)
6609 +               PACK64(ptr, regs->gpr[reg]);
6610 +
6611 +       /* Regs GPR3-13 are caller saved, not in regs->gpr[] */
6612 +       ptr += 11;
6613 +
6614 +       /* Regs GPR14-31 */
6615 +       for (reg = 14; reg < 32; reg++)
6616 +               PACK64(ptr, regs->gpr[reg]);
6617 +
6618 +#ifdef CONFIG_FSL_BOOKE
6619 +#ifdef CONFIG_SPE
6620 +       for (reg = 0; reg < 32; reg++)
6621 +               PACK64(ptr, p->thread.evr[reg]);
6622 +#else
6623 +       ptr += 32;
6624 +#endif
6625 +#else
6626 +       /* fp registers not used by kernel, leave zero */
6627 +       ptr += 32 * 8 / sizeof(long);
6628 +#endif
6629 +       PACK64(ptr, regs->nip);
6630 +       PACK64(ptr, regs->msr);
6631 +       PACK32(ptr, regs->ccr);
6632 +       PACK64(ptr, regs->link);
6633 +       PACK64(ptr, regs->ctr);
6634 +       PACK32(ptr, regs->xer);
6635 +
6636 +#if 0
6637 +       Following are in struct thread_struct, not struct pt_regs,
6638 +       ignoring for now since kernel does not use them.  Would it
6639 +       make sense to get them from the thread that kgdb is set to?
6640 +
6641 +       If this code is enabled, update the definition of NUMREGBYTES to
6642 +       include the vector registers and vector state registers.
6643 +
6644 +       PACK32(ptr, p->thread->fpscr);
6645 +
6646 +       /* vr registers not used by kernel, leave zero */
6647 +       ptr += 32 * 16 / sizeof(long);
6648 +
6649 +#ifdef CONFIG_ALTIVEC
6650 +       PACK32(ptr, p->thread->vscr);
6651 +       PACK32(ptr, p->thread->vrsave);
6652 +#else
6653 +       ptr += 2 * 4 / sizeof(long);
6654 +#endif
6655 +#else
6656 +#ifdef CONFIG_FSL_BOOKE
6657 +#ifdef CONFIG_SPE
6658 +       /* u64 acc */
6659 +       PACK32(ptr, p->thread.acc >> 32);
6660 +       PACK32(ptr, p->thread.acc & 0xffffffff);
6661 +       PACK64(ptr, p->thread.spefscr);
6662 +#else
6663 +       ptr += 2 + 1;
6664 +#endif
6665 +#else
6666 +       /* fpscr not used by kernel, leave zero */
6667 +       PACK32(ptr, 0);
6668 +#endif
6669 +#endif
6670 +
6671 +       BUG_ON((unsigned long)ptr >
6672 +              (unsigned long)(((void *)gdb_regs) + NUMREGBYTES));
6673 +}
6674 +
6675 +#define UNPACK64(dest,ptr) do { dest = *(ptr++); } while(0)
6676 +
6677 +#define UNPACK32(dest,ptr) do {       \
6678 +       u32 *ptr32;                   \
6679 +       ptr32 = (u32 *)ptr;           \
6680 +       dest = *(ptr32++);            \
6681 +       ptr = (unsigned long *)ptr32; \
6682 +       } while(0)
6683 +
6684 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
6685 +{
6686 +       unsigned long *ptr = gdb_regs;
6687 +       int reg;
6688 +
6689 +#ifdef CONFIG_SPE
6690 +       union {
6691 +               u32 v32[2];
6692 +               u64 v64;
6693 +       } acc;
6694 +#endif
6695 +       for (reg = 0; reg < 32; reg++)
6696 +               UNPACK64(regs->gpr[reg], ptr);
6697 +
6698 +#ifdef CONFIG_FSL_BOOKE
6699 +#ifdef CONFIG_SPE
6700 +       for (reg = 0; reg < 32; reg++)
6701 +               UNPACK64(current->thread.evr[reg], ptr);
6702 +#else
6703 +       ptr += 32;
6704 +#endif
6705 +#else
6706 +       /* fp registers not used by kernel, leave zero */
6707 +       ptr += 32 * 8 / sizeof(int);
6708 +#endif
6709 +       UNPACK64(regs->nip, ptr);
6710 +       UNPACK64(regs->msr, ptr);
6711 +       UNPACK32(regs->ccr, ptr);
6712 +       UNPACK64(regs->link, ptr);
6713 +       UNPACK64(regs->ctr, ptr);
6714 +       UNPACK32(regs->xer, ptr);
6715 +
6716 +#if 0
6717 +       Following are in struct thread_struct, not struct pt_regs,
6718 +       ignoring for now since kernel does not use them.  Would it
6719 +       make sense to get them from the thread that kgdb is set to?
6720 +
6721 +       If this code is enabled, update the definition of NUMREGBYTES to
6722 +       include the vector registers and vector state registers.
6723 +
6724 +       /* fpscr, vscr, vrsave not used by kernel, leave unchanged */
6725 +
6726 +       UNPACK32(current->thread->fpscr, ptr);
6727 +
6728 +       /* vr registers not used by kernel, leave zero */
6729 +       ptr += 32 * 16 / sizeof(long);
6730 +
6731 +       #ifdef CONFIG_ALTIVEC
6732 +       UNPACK32(current->thread->vscr, ptr);
6733 +       UNPACK32(current->thread->vrsave, ptr);
6734 +#else
6735 +       ptr += 2 * 4 / sizeof(long);
6736 +#endif
6737 +#else
6738 +#ifdef CONFIG_FSL_BOOKE
6739 +#ifdef CONFIG_SPE
6740 +       /* u64 acc */
6741 +       UNPACK32(acc.v32[0], ptr);
6742 +       UNPACK32(acc.v32[1], ptr);
6743 +       current->thread.acc = acc.v64;
6744 +       UNPACK64(current->thread.spefscr, ptr);
6745 +#else
6746 +       ptr += 2 + 1;
6747 +#endif
6748 +#endif
6749 +#endif
6750 +
6751 +       BUG_ON((unsigned long)ptr >
6752 +              (unsigned long)(((void *)gdb_regs) + NUMREGBYTES));
6753 +}
6754 +
6755 +/*
6756 + * This function does PowerPC specific procesing for interfacing to gdb.
6757 + */
6758 +int kgdb_arch_handle_exception(int vector, int signo, int err_code,
6759 +                              char *remcom_in_buffer, char *remcom_out_buffer,
6760 +                              struct pt_regs *linux_regs)
6761 +{
6762 +       char *ptr = &remcom_in_buffer[1];
6763 +       unsigned long addr;
6764 +
6765 +       switch (remcom_in_buffer[0]) {
6766 +               /*
6767 +                * sAA..AA   Step one instruction from AA..AA
6768 +                * This will return an error to gdb ..
6769 +                */
6770 +       case 's':
6771 +       case 'c':
6772 +               /* handle the optional parameter */
6773 +               if (kgdb_hex2long(&ptr, &addr))
6774 +                       linux_regs->nip = addr;
6775 +
6776 +               atomic_set(&cpu_doing_single_step, -1);
6777 +               /* set the trace bit if we're stepping */
6778 +               if (remcom_in_buffer[0] == 's') {
6779 +#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
6780 +                       mtspr(SPRN_DBCR0,
6781 +                               mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM);
6782 +                       linux_regs->msr |= MSR_DE;
6783 +#else
6784 +                       linux_regs->msr |= MSR_SE;
6785 +#endif
6786 +                       debugger_step = 1;
6787 +                       if (kgdb_contthread)
6788 +                               atomic_set(&cpu_doing_single_step,
6789 +                                          smp_processor_id());
6790 +               }
6791 +               return 0;
6792 +       }
6793 +
6794 +       return -1;
6795 +}
6796 +
6797 +int kgdb_fault_setjmp(unsigned long *curr_context)
6798 +{
6799 +#ifdef CONFIG_PPC32
6800 +       __asm__ __volatile__("mflr 0; stw 0,0(%0);\n\
6801 +                               stw 1,4(%0); stw 2,8(%0);\n\
6802 +                               mfcr 0; stw 0,12(%0);\n\
6803 +                               stmw 13,16(%0)\n" : : "r" (curr_context));
6804 +#else
6805 +       __asm__ __volatile__("mflr 0; std 0,0(%0)\n\
6806 +                             std       1,8(%0)\n\
6807 +                             std       2,16(%0)\n\
6808 +                             mfcr 0; std 0,24(%0)\n\
6809 +                             std       13,32(%0)\n\
6810 +                             std       14,40(%0)\n\
6811 +                             std       15,48(%0)\n\
6812 +                             std       16,56(%0)\n\
6813 +                             std       17,64(%0)\n\
6814 +                             std       18,72(%0)\n\
6815 +                             std       19,80(%0)\n\
6816 +                             std       20,88(%0)\n\
6817 +                             std       21,96(%0)\n\
6818 +                             std       22,104(%0)\n\
6819 +                             std       23,112(%0)\n\
6820 +                             std       24,120(%0)\n\
6821 +                             std       25,128(%0)\n\
6822 +                             std       26,136(%0)\n\
6823 +                             std       27,144(%0)\n\
6824 +                             std       28,152(%0)\n\
6825 +                             std       29,160(%0)\n\
6826 +                             std       30,168(%0)\n\
6827 +                             std       31,176(%0)\n" : : "r" (curr_context));
6828 +#endif
6829 +       return 0;
6830 +}
6831 +
6832 +void kgdb_fault_longjmp(unsigned long *curr_context)
6833 +{
6834 +#ifdef CONFIG_PPC32
6835 +       __asm__ __volatile__("lmw 13,16(%0);\n\
6836 +                             lwz 0,12(%0); mtcrf 0x38,0;\n\
6837 +                             lwz 0,0(%0); lwz 1,4(%0); lwz 2,8(%0);\n\
6838 +                             mtlr 0; mr 3,1\n" : : "r" (curr_context));
6839 +#else
6840 +       __asm__ __volatile__("ld        13,32(%0)\n\
6841 +                             ld        14,40(%0)\n\
6842 +                             ld        15,48(%0)\n\
6843 +                             ld        16,56(%0)\n\
6844 +                             ld        17,64(%0)\n\
6845 +                             ld        18,72(%0)\n\
6846 +                             ld        19,80(%0)\n\
6847 +                             ld        20,88(%0)\n\
6848 +                             ld        21,96(%0)\n\
6849 +                             ld        22,104(%0)\n\
6850 +                             ld        23,112(%0)\n\
6851 +                             ld        24,120(%0)\n\
6852 +                             ld        25,128(%0)\n\
6853 +                             ld        26,136(%0)\n\
6854 +                             ld        27,144(%0)\n\
6855 +                             ld        28,152(%0)\n\
6856 +                             ld        29,160(%0)\n\
6857 +                             ld        30,168(%0)\n\
6858 +                             ld        31,176(%0)\n\
6859 +                             ld        0,24(%0)\n\
6860 +                             mtcrf     0x38,0\n\
6861 +                             ld        0,0(%0)\n\
6862 +                             ld        1,8(%0)\n\
6863 +                             ld        2,16(%0)\n\
6864 +                             mtlr      0\n\
6865 +                             mr        3,1\n" : : "r" (curr_context));
6866 +#endif
6867 +}
6868 +
6869 +/*
6870 + * Global data
6871 + */
6872 +struct kgdb_arch arch_kgdb_ops = {
6873 +       .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
6874 +};
6875 +
6876 +int kgdb_not_implemented(struct pt_regs *regs)
6877 +{
6878 +       return 0;
6879 +}
6880 +
6881 +int kgdb_arch_init(void)
6882 +{
6883 +#ifdef CONFIG_XMON
6884 +#error Both XMON and KGDB selected in .config.  Unselect one of them.
6885 +#endif
6886 +
6887 +       __debugger_ipi = kgdb_call_nmi_hook;
6888 +       __debugger = kgdb_debugger;
6889 +       __debugger_bpt = kgdb_breakpoint;
6890 +       __debugger_sstep = kgdb_singlestep;
6891 +       __debugger_iabr_match = kgdb_iabr_match;
6892 +       __debugger_dabr_match = kgdb_dabr_match;
6893 +       __debugger_fault_handler = kgdb_not_implemented;
6894 +
6895 +       return 0;
6896 +}
6897 +
6898 +arch_initcall(kgdb_arch_init);
6899 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/powerpc/kernel/legacy_serial.c linux-2.6.18-53.1.14.kgdb/arch/powerpc/kernel/legacy_serial.c
6900 --- linux-2.6.18-53.1.14/arch/powerpc/kernel/legacy_serial.c    2008-03-06 05:54:47.000000000 +0300
6901 +++ linux-2.6.18-53.1.14.kgdb/arch/powerpc/kernel/legacy_serial.c       2008-06-10 15:38:14.000000000 +0400
6902 @@ -11,6 +11,9 @@
6903  #include <asm/udbg.h>
6904  #include <asm/pci-bridge.h>
6905  #include <asm/ppc-pci.h>
6906 +#ifdef CONFIG_KGDB_8250
6907 +#include <linux/kgdb.h>
6908 +#endif
6909  
6910  #undef DEBUG
6911  
6912 @@ -485,6 +488,9 @@ static int __init serial_dev_init(void)
6913                         fixup_port_pio(i, np, port);
6914                 if ((port->iotype == UPIO_MEM) || (port->iotype == UPIO_TSI))
6915                         fixup_port_mmio(i, np, port);
6916 +#ifdef CONFIG_KGDB_8250
6917 +               kgdb8250_add_platform_port(i, port);
6918 +#endif
6919         }
6920  
6921         DBG("Registering platform serial ports\n");
6922 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/powerpc/kernel/setup_32.c linux-2.6.18-53.1.14.kgdb/arch/powerpc/kernel/setup_32.c
6923 --- linux-2.6.18-53.1.14/arch/powerpc/kernel/setup_32.c 2008-03-06 05:54:45.000000000 +0300
6924 +++ linux-2.6.18-53.1.14.kgdb/arch/powerpc/kernel/setup_32.c    2008-06-10 15:38:14.000000000 +0400
6925 @@ -45,10 +45,6 @@
6926  
6927  #define DBG(fmt...)
6928  
6929 -#if defined CONFIG_KGDB
6930 -#include <asm/kgdb.h>
6931 -#endif
6932 -
6933  extern void bootx_init(unsigned long r4, unsigned long phys);
6934  
6935  struct ide_machdep_calls ppc_ide_md;
6936 @@ -251,18 +247,6 @@ void __init setup_arch(char **cmdline_p)
6937  
6938         xmon_setup();
6939  
6940 -#if defined(CONFIG_KGDB)
6941 -       if (ppc_md.kgdb_map_scc)
6942 -               ppc_md.kgdb_map_scc();
6943 -       set_debug_traps();
6944 -       if (strstr(cmd_line, "gdb")) {
6945 -               if (ppc_md.progress)
6946 -                       ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
6947 -               printk("kgdb breakpoint activated\n");
6948 -               breakpoint();
6949 -       }
6950 -#endif
6951 -
6952         /*
6953          * Set cache line size based on type of cpu as a default.
6954          * Systems with OF can look in the properties on the cpu node(s)
6955 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/powerpc/mm/fault.c linux-2.6.18-53.1.14.kgdb/arch/powerpc/mm/fault.c
6956 --- linux-2.6.18-53.1.14/arch/powerpc/mm/fault.c        2006-09-20 07:42:06.000000000 +0400
6957 +++ linux-2.6.18-53.1.14.kgdb/arch/powerpc/mm/fault.c   2008-06-10 15:38:14.000000000 +0400
6958 @@ -28,6 +28,7 @@
6959  #include <linux/highmem.h>
6960  #include <linux/module.h>
6961  #include <linux/kprobes.h>
6962 +#include <linux/kgdb.h>
6963  
6964  #include <asm/page.h>
6965  #include <asm/pgtable.h>
6966 @@ -424,6 +425,13 @@ void bad_page_fault(struct pt_regs *regs
6967                 return;
6968         }
6969  
6970 +#ifdef CONFIG_KGDB
6971 +       if (atomic_read(&debugger_active) && kgdb_may_fault)
6972 +               /* Restore our previous state. */
6973 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
6974 +               /* Not reached. */
6975 +#endif
6976 +
6977         /* kernel has accessed a bad area */
6978  
6979         printk(KERN_ALERT "Unable to handle kernel paging request for ");
6980 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/powerpc/platforms/powermac/setup.c linux-2.6.18-53.1.14.kgdb/arch/powerpc/platforms/powermac/setup.c
6981 --- linux-2.6.18-53.1.14/arch/powerpc/platforms/powermac/setup.c        2006-09-20 07:42:06.000000000 +0400
6982 +++ linux-2.6.18-53.1.14.kgdb/arch/powerpc/platforms/powermac/setup.c   2008-06-10 15:38:14.000000000 +0400
6983 @@ -98,8 +98,6 @@ extern struct machdep_calls pmac_md;
6984  int sccdbg;
6985  #endif
6986  
6987 -extern void zs_kgdb_hook(int tty_num);
6988 -
6989  sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
6990  EXPORT_SYMBOL(sys_ctrler);
6991  
6992 @@ -319,10 +317,6 @@ static void __init pmac_setup_arch(void)
6993         l2cr_init();
6994  #endif /* CONFIG_PPC32 */
6995  
6996 -#ifdef CONFIG_KGDB
6997 -       zs_kgdb_hook(0);
6998 -#endif
6999 -
7000         find_via_cuda();
7001         find_via_pmu();
7002         smu_init();
7003 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/Kconfig.debug linux-2.6.18-53.1.14.kgdb/arch/ppc/Kconfig.debug
7004 --- linux-2.6.18-53.1.14/arch/ppc/Kconfig.debug 2006-09-20 07:42:06.000000000 +0400
7005 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/Kconfig.debug    2008-06-10 15:38:14.000000000 +0400
7006 @@ -2,42 +2,6 @@ menu "Kernel hacking"
7007  
7008  source "lib/Kconfig.debug"
7009  
7010 -config KGDB
7011 -       bool "Include kgdb kernel debugger"
7012 -       depends on DEBUG_KERNEL && (BROKEN || PPC_GEN550 || 4xx)
7013 -       select DEBUG_INFO
7014 -       help
7015 -         Include in-kernel hooks for kgdb, the Linux kernel source level
7016 -         debugger.  See <http://kgdb.sourceforge.net/> for more information.
7017 -         Unless you are intending to debug the kernel, say N here.
7018 -
7019 -choice
7020 -       prompt "Serial Port"
7021 -       depends on KGDB
7022 -       default KGDB_TTYS1
7023 -
7024 -config KGDB_TTYS0
7025 -       bool "ttyS0"
7026 -
7027 -config KGDB_TTYS1
7028 -       bool "ttyS1"
7029 -
7030 -config KGDB_TTYS2
7031 -       bool "ttyS2"
7032 -
7033 -config KGDB_TTYS3
7034 -       bool "ttyS3"
7035 -
7036 -endchoice
7037 -
7038 -config KGDB_CONSOLE
7039 -       bool "Enable serial console thru kgdb port"
7040 -       depends on KGDB && 8xx || CPM2
7041 -       help
7042 -         If you enable this, all serial console messages will be sent
7043 -         over the gdb stub.
7044 -         If unsure, say N.
7045 -
7046  config XMON
7047         bool "Include xmon kernel debugger"
7048         depends on DEBUG_KERNEL
7049 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/kernel/kgdb.c linux-2.6.18-53.1.14.kgdb/arch/ppc/kernel/kgdb.c
7050 --- linux-2.6.18-53.1.14/arch/ppc/kernel/kgdb.c 1970-01-01 03:00:00.000000000 +0300
7051 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/kernel/kgdb.c    2008-06-10 15:39:34.000000000 +0400
7052 @@ -0,0 +1,350 @@
7053 +/*
7054 + * arch/ppc/kernel/kgdb.c
7055 + *
7056 + * PowerPC backend to the KGDB stub.
7057 + *
7058 + * Maintainer: Tom Rini <trini@kernel.crashing.org>
7059 + *
7060 + * 1998 (c) Michael AK Tesch (tesch@cs.wisc.edu)
7061 + * Copyright (C) 2003 Timesys Corporation.
7062 + * 2004 (c) MontaVista Software, Inc.
7063 + *
7064 + * This file is licensed under the terms of the GNU General Public License
7065 + * version 2. This program as licensed "as is" without any warranty of any
7066 + * kind, whether express or implied.
7067 + */
7068 +
7069 +#include <linux/config.h>
7070 +#include <linux/kernel.h>
7071 +#include <linux/init.h>
7072 +#include <linux/kgdb.h>
7073 +#include <linux/smp.h>
7074 +#include <linux/signal.h>
7075 +#include <linux/ptrace.h>
7076 +#include <asm/current.h>
7077 +#include <asm/ptrace.h>
7078 +#include <asm/processor.h>
7079 +#include <asm/machdep.h>
7080 +
7081 +/*
7082 + * This table contains the mapping between PowerPC hardware trap types, and
7083 + * signals, which are primarily what GDB understands.  GDB and the kernel
7084 + * don't always agree on values, so we use constants taken from gdb-6.2.
7085 + */
7086 +static struct hard_trap_info
7087 +{
7088 +       unsigned int tt;                /* Trap type code for powerpc */
7089 +       unsigned char signo;            /* Signal that we map this trap into */
7090 +} hard_trap_info[] = {
7091 +#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
7092 +       { 0x0100, 0x02 /* SIGINT */  },         /* critical input interrupt */
7093 +       { 0x0200, 0x0b /* SIGSEGV */ },         /* machine check */
7094 +       { 0x0300, 0x0b /* SIGSEGV */ },         /* data storage */
7095 +       { 0x0400, 0x0a /* SIGBUS */  },         /* instruction storage */
7096 +       { 0x0500, 0x02 /* SIGINT */  },         /* interrupt */
7097 +       { 0x0600, 0x0a /* SIGBUS */  },         /* alignment */
7098 +       { 0x0700, 0x04 /* SIGILL */  },         /* program */
7099 +       { 0x0800, 0x04 /* SIGILL */  },         /* reserved */
7100 +       { 0x0900, 0x04 /* SIGILL */  },         /* reserved */
7101 +       { 0x0a00, 0x04 /* SIGILL */  },         /* reserved */
7102 +       { 0x0b00, 0x04 /* SIGILL */  },         /* reserved */
7103 +       { 0x0c00, 0x14 /* SIGCHLD */ },         /* syscall */
7104 +       { 0x0d00, 0x04 /* SIGILL */  },         /* reserved */
7105 +       { 0x0e00, 0x04 /* SIGILL */  },         /* reserved */
7106 +       { 0x0f00, 0x04 /* SIGILL */  },         /* reserved */
7107 +       { 0x2002, 0x05 /* SIGTRAP */},          /* debug */
7108 +#else
7109 +       { 0x0200, 0x0b /* SIGSEGV */ },         /* machine check */
7110 +       { 0x0300, 0x0b /* SIGSEGV */ },         /* address error (store) */
7111 +       { 0x0400, 0x0a /* SIGBUS */ },          /* instruction bus error */
7112 +       { 0x0500, 0x02 /* SIGINT */ },          /* interrupt */
7113 +       { 0x0600, 0x0a /* SIGBUS */ },          /* alingment */
7114 +       { 0x0700, 0x05 /* SIGTRAP */ },         /* breakpoint trap */
7115 +       { 0x0800, 0x08 /* SIGFPE */},           /* fpu unavail */
7116 +       { 0x0900, 0x0e /* SIGALRM */ },         /* decrementer */
7117 +       { 0x0a00, 0x04 /* SIGILL */ },          /* reserved */
7118 +       { 0x0b00, 0x04 /* SIGILL */ },          /* reserved */
7119 +       { 0x0c00, 0x14 /* SIGCHLD */ },         /* syscall */
7120 +       { 0x0d00, 0x05 /* SIGTRAP */ },         /* single-step/watch */
7121 +       { 0x0e00, 0x08 /* SIGFPE */ },          /* fp assist */
7122 +#endif
7123 +       { 0x0000, 0x000 }                       /* Must be last */
7124 +};
7125 +
7126 +extern atomic_t cpu_doing_single_step;
7127 +
7128 +static int computeSignal(unsigned int tt)
7129 +{
7130 +       struct hard_trap_info *ht;
7131 +
7132 +       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
7133 +               if (ht->tt == tt)
7134 +                       return ht->signo;
7135 +
7136 +       return SIGHUP;          /* default for things we don't know about */
7137 +}
7138 +
7139 +/* KGDB functions to use existing PowerPC hooks. */
7140 +static void kgdb_debugger(struct pt_regs *regs)
7141 +{
7142 +       kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
7143 +}
7144 +
7145 +static int kgdb_breakpoint(struct pt_regs *regs)
7146 +{
7147 +       if (user_mode(regs))
7148 +               return 0;
7149 +
7150 +       kgdb_handle_exception(0, SIGTRAP, 0, regs);
7151 +
7152 +       if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
7153 +               regs->nip += 4;
7154 +
7155 +       return 1;
7156 +}
7157 +
7158 +static int kgdb_singlestep(struct pt_regs *regs)
7159 +{
7160 +       struct thread_info *thread_info, *exception_thread_info;
7161 +
7162 +       if (user_mode(regs))
7163 +               return 0;
7164 +       /*
7165 +       * On Book E and perhaps other processsors, singlestep is handled on
7166 +       * the critical exception stack.  This causes current_thread_info()
7167 +       * to fail, since it it locates the thread_info by masking off
7168 +       * the low bits of the current stack pointer.  We work around
7169 +       * this issue by copying the thread_info from the kernel stack
7170 +       * before calling kgdb_handle_exception, and copying it back
7171 +       * afterwards.  On most processors the copy is avoided since
7172 +       * exception_thread_info == thread_info.
7173 +       */
7174 +       thread_info = (struct thread_info *)(regs->gpr[1] & ~(THREAD_SIZE-1));
7175 +       exception_thread_info = current_thread_info();
7176 +
7177 +       if (thread_info != exception_thread_info)
7178 +               memcpy(exception_thread_info, thread_info, sizeof *thread_info);
7179 +
7180 +       kgdb_handle_exception(0, SIGTRAP, 0, regs);
7181 +
7182 +       if (thread_info != exception_thread_info)
7183 +               memcpy(thread_info, exception_thread_info, sizeof *thread_info);
7184 +
7185 +       return 1;
7186 +}
7187 +
7188 +int kgdb_iabr_match(struct pt_regs *regs)
7189 +{
7190 +       if (user_mode(regs))
7191 +               return 0;
7192 +
7193 +       kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
7194 +       return 1;
7195 +}
7196 +
7197 +int kgdb_dabr_match(struct pt_regs *regs)
7198 +{
7199 +       if (user_mode(regs))
7200 +               return 0;
7201 +
7202 +       kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
7203 +       return 1;
7204 +}
7205 +
7206 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
7207 +{
7208 +       int reg;
7209 +       unsigned long *ptr = gdb_regs;
7210 +
7211 +       memset(gdb_regs, 0, MAXREG * 4);
7212 +
7213 +       for (reg = 0; reg < 32; reg++)
7214 +               *(ptr++) = regs->gpr[reg];
7215 +
7216 +#ifndef CONFIG_E500
7217 +       for (reg = 0; reg < 64; reg++)
7218 +               *(ptr++) = 0;
7219 +#else
7220 +       for (reg = 0; reg < 32; reg++)
7221 +               *(ptr++) = current->thread.evr[reg];
7222 +#endif
7223 +
7224 +       *(ptr++) = regs->nip;
7225 +       *(ptr++) = regs->msr;
7226 +       *(ptr++) = regs->ccr;
7227 +       *(ptr++) = regs->link;
7228 +       *(ptr++) = regs->ctr;
7229 +       *(ptr++) = regs->xer;
7230 +
7231 +#ifdef CONFIG_SPE
7232 +       /* u64 acc */
7233 +       *(ptr++) = (current->thread.acc >> 32);
7234 +       *(ptr++) = (current->thread.acc & 0xffffffff);
7235 +       *(ptr++) = current->thread.spefscr;
7236 +#endif
7237 +}
7238 +
7239 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
7240 +{
7241 +       struct pt_regs *regs = (struct pt_regs *)(p->thread.ksp +
7242 +                                                 STACK_FRAME_OVERHEAD);
7243 +       int reg;
7244 +       unsigned long *ptr = gdb_regs;
7245 +
7246 +       memset(gdb_regs, 0, MAXREG * 4);
7247 +
7248 +       /* Regs GPR0-2 */
7249 +       for (reg = 0; reg < 3; reg++)
7250 +               *(ptr++) = regs->gpr[reg];
7251 +
7252 +       /* Regs GPR3-13 are not saved */
7253 +       for (reg = 3; reg < 14; reg++)
7254 +               *(ptr++) = 0;
7255 +
7256 +       /* Regs GPR14-31 */
7257 +       for (reg = 14; reg < 32; reg++)
7258 +               *(ptr++) = regs->gpr[reg];
7259 +
7260 +#ifndef CONFIG_E500
7261 +       for (reg = 0; reg < 64; reg++)
7262 +               *(ptr++) = 0;
7263 +#else
7264 +       for (reg = 0; reg < 32; reg++)
7265 +               *(ptr++) = current->thread.evr[reg];
7266 +#endif
7267 +
7268 +       *(ptr++) = regs->nip;
7269 +       *(ptr++) = regs->msr;
7270 +       *(ptr++) = regs->ccr;
7271 +       *(ptr++) = regs->link;
7272 +       *(ptr++) = regs->ctr;
7273 +       *(ptr++) = regs->xer;
7274 +
7275 +#ifdef CONFIG_SPE
7276 +       /* u64 acc */
7277 +       *(ptr++) = (current->thread.acc >> 32);
7278 +       *(ptr++) = (current->thread.acc & 0xffffffff);
7279 +       *(ptr++) = current->thread.spefscr;
7280 +#endif
7281 +}
7282 +
7283 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
7284 +{
7285 +       int reg;
7286 +       unsigned long *ptr = gdb_regs;
7287 +#ifdef CONFIG_SPE
7288 +       union {
7289 +               u32 v32[2];
7290 +               u64 v64;
7291 +       } u;
7292 +#endif
7293 +
7294 +       for (reg = 0; reg < 32; reg++)
7295 +               regs->gpr[reg] = *(ptr++);
7296 +
7297 +#ifndef CONFIG_E500
7298 +       for (reg = 0; reg < 64; reg++)
7299 +               ptr++;
7300 +#else
7301 +       for (reg = 0; reg < 32; reg++)
7302 +               current->thread.evr[reg] = *(ptr++);
7303 +#endif
7304 +
7305 +       regs->nip = *(ptr++);
7306 +       regs->msr = *(ptr++);
7307 +       regs->ccr = *(ptr++);
7308 +       regs->link = *(ptr++);
7309 +       regs->ctr = *(ptr++);
7310 +       regs->xer = *(ptr++);
7311 +
7312 +#ifdef CONFIG_SPE
7313 +       /* u64 acc */
7314 +       u.v32[0] = *(ptr++);
7315 +       u.v32[1] = *(ptr++);
7316 +       current->thread.acc = u.v64;
7317 +       current->thread.spefscr = *(ptr++);
7318 +#endif
7319 +}
7320 +
7321 +/*
7322 + * Save/restore state in case a memory access causes a fault.
7323 + */
7324 +int kgdb_fault_setjmp(unsigned long *curr_context)
7325 +{
7326 +       __asm__ __volatile__("mflr 0; stw 0,0(%0);"
7327 +                            "stw 1,4(%0); stw 2,8(%0);"
7328 +                            "mfcr 0; stw 0,12(%0);"
7329 +                            "stmw 13,16(%0)"::"r"(curr_context));
7330 +       return 0;
7331 +}
7332 +
7333 +void kgdb_fault_longjmp(unsigned long *curr_context)
7334 +{
7335 +       __asm__ __volatile__("lmw 13,16(%0);"
7336 +                            "lwz 0,12(%0); mtcrf 0x38,0;"
7337 +                            "lwz 0,0(%0); lwz 1,4(%0); lwz 2,8(%0);"
7338 +                            "mtlr 0; mr 3,1"::"r"(curr_context));
7339 +}
7340 +
7341 +/*
7342 + * This function does PoerPC specific procesing for interfacing to gdb.
7343 + */
7344 +int kgdb_arch_handle_exception(int vector, int signo, int err_code,
7345 +                              char *remcom_in_buffer, char *remcom_out_buffer,
7346 +                              struct pt_regs *linux_regs)
7347 +{
7348 +       char *ptr = &remcom_in_buffer[1];
7349 +       unsigned long addr;
7350 +
7351 +       switch (remcom_in_buffer[0])
7352 +               {
7353 +               /*
7354 +                * sAA..AA   Step one instruction from AA..AA
7355 +                * This will return an error to gdb ..
7356 +                */
7357 +               case 's':
7358 +               case 'c':
7359 +                       /* handle the optional parameter */
7360 +                       if (kgdb_hex2long (&ptr, &addr))
7361 +                               linux_regs->nip = addr;
7362 +
7363 +                       atomic_set(&cpu_doing_single_step, -1);
7364 +                       /* set the trace bit if we're stepping */
7365 +                       if (remcom_in_buffer[0] == 's') {
7366 +#if defined (CONFIG_40x) || defined(CONFIG_BOOKE)
7367 +                               mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) |
7368 +                                               DBCR0_IC | DBCR0_IDM);
7369 +                               linux_regs->msr |= MSR_DE;
7370 +#else
7371 +                               linux_regs->msr |= MSR_SE;
7372 +#endif
7373 +                               debugger_step = 1;
7374 +                               if (kgdb_contthread)
7375 +                                       atomic_set(&cpu_doing_single_step,
7376 +                                                       smp_processor_id());
7377 +                       }
7378 +                       return 0;
7379 +       }
7380 +
7381 +       return -1;
7382 +}
7383 +
7384 +/*
7385 + * Global data
7386 + */
7387 +struct kgdb_arch arch_kgdb_ops = {
7388 +       .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
7389 +};
7390 +
7391 +int kgdb_arch_init(void)
7392 +{
7393 +       debugger = kgdb_debugger;
7394 +       debugger_bpt = kgdb_breakpoint;
7395 +       debugger_sstep = kgdb_singlestep;
7396 +       debugger_iabr_match = kgdb_iabr_match;
7397 +       debugger_dabr_match = kgdb_dabr_match;
7398 +
7399 +       return 0;
7400 +}
7401 +
7402 +arch_initcall(kgdb_arch_init);
7403 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/kernel/ppc-stub.c linux-2.6.18-53.1.14.kgdb/arch/ppc/kernel/ppc-stub.c
7404 --- linux-2.6.18-53.1.14/arch/ppc/kernel/ppc-stub.c     2006-09-20 07:42:06.000000000 +0400
7405 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/kernel/ppc-stub.c        1970-01-01 03:00:00.000000000 +0300
7406 @@ -1,866 +0,0 @@
7407 -/*
7408 - * ppc-stub.c:  KGDB support for the Linux kernel.
7409 - *
7410 - * adapted from arch/sparc/kernel/sparc-stub.c for the PowerPC
7411 - * some stuff borrowed from Paul Mackerras' xmon
7412 - * Copyright (C) 1998 Michael AK Tesch (tesch@cs.wisc.edu)
7413 - *
7414 - * Modifications to run under Linux
7415 - * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
7416 - *
7417 - * This file originally came from the gdb sources, and the
7418 - * copyright notices have been retained below.
7419 - */
7420 -
7421 -/****************************************************************************
7422 -
7423 -               THIS SOFTWARE IS NOT COPYRIGHTED
7424 -
7425 -   HP offers the following for use in the public domain.  HP makes no
7426 -   warranty with regard to the software or its performance and the
7427 -   user accepts the software "AS IS" with all faults.
7428 -
7429 -   HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
7430 -   TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
7431 -   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
7432 -
7433 -****************************************************************************/
7434 -
7435 -/****************************************************************************
7436 - *  Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $
7437 - *
7438 - *  Module name: remcom.c $
7439 - *  Revision: 1.34 $
7440 - *  Date: 91/03/09 12:29:49 $
7441 - *  Contributor:     Lake Stevens Instrument Division$
7442 - *
7443 - *  Description:     low level support for gdb debugger. $
7444 - *
7445 - *  Considerations:  only works on target hardware $
7446 - *
7447 - *  Written by:      Glenn Engel $
7448 - *  ModuleState:     Experimental $
7449 - *
7450 - *  NOTES:           See Below $
7451 - *
7452 - *  Modified for SPARC by Stu Grossman, Cygnus Support.
7453 - *
7454 - *  This code has been extensively tested on the Fujitsu SPARClite demo board.
7455 - *
7456 - *  To enable debugger support, two things need to happen.  One, a
7457 - *  call to set_debug_traps() is necessary in order to allow any breakpoints
7458 - *  or error conditions to be properly intercepted and reported to gdb.
7459 - *  Two, a breakpoint needs to be generated to begin communication.  This
7460 - *  is most easily accomplished by a call to breakpoint().  Breakpoint()
7461 - *  simulates a breakpoint by executing a trap #1.
7462 - *
7463 - *************
7464 - *
7465 - *    The following gdb commands are supported:
7466 - *
7467 - * command          function                     Return value
7468 - *
7469 - *    g             return the value of the CPU registers  hex data or ENN
7470 - *    G             set the value of the CPU registers     OK or ENN
7471 - *    qOffsets      Get section offsets.  Reply is Text=xxx;Data=yyy;Bss=zzz
7472 - *
7473 - *    mAA..AA,LLLL  Read LLLL bytes at address AA..AA      hex data or ENN
7474 - *    MAA..AA,LLLL: Write LLLL bytes at address AA.AA      OK or ENN
7475 - *
7476 - *    c             Resume at current address              SNN   ( signal NN)
7477 - *    cAA..AA       Continue at address AA..AA             SNN
7478 - *
7479 - *    s             Step one instruction                   SNN
7480 - *    sAA..AA       Step one instruction from AA..AA       SNN
7481 - *
7482 - *    k             kill
7483 - *
7484 - *    ?             What was the last sigval ?             SNN   (signal NN)
7485 - *
7486 - *    bBB..BB      Set baud rate to BB..BB                OK or BNN, then sets
7487 - *                                                        baud rate
7488 - *
7489 - * All commands and responses are sent with a packet which includes a
7490 - * checksum.  A packet consists of
7491 - *
7492 - * $<packet info>#<checksum>.
7493 - *
7494 - * where
7495 - * <packet info> :: <characters representing the command or response>
7496 - * <checksum>    :: <two hex digits computed as modulo 256 sum of <packetinfo>>
7497 - *
7498 - * When a packet is received, it is first acknowledged with either '+' or '-'.
7499 - * '+' indicates a successful transfer.  '-' indicates a failed transfer.
7500 - *
7501 - * Example:
7502 - *
7503 - * Host:                  Reply:
7504 - * $m0,10#2a               +$00010203040506070809101112131415#42
7505 - *
7506 - ****************************************************************************/
7507 -
7508 -#include <linux/kernel.h>
7509 -#include <linux/string.h>
7510 -#include <linux/mm.h>
7511 -#include <linux/smp.h>
7512 -#include <linux/smp_lock.h>
7513 -#include <linux/init.h>
7514 -#include <linux/sysrq.h>
7515 -
7516 -#include <asm/cacheflush.h>
7517 -#include <asm/system.h>
7518 -#include <asm/signal.h>
7519 -#include <asm/kgdb.h>
7520 -#include <asm/pgtable.h>
7521 -#include <asm/ptrace.h>
7522 -
7523 -void breakinst(void);
7524 -
7525 -/*
7526 - * BUFMAX defines the maximum number of characters in inbound/outbound buffers
7527 - * at least NUMREGBYTES*2 are needed for register packets
7528 - */
7529 -#define BUFMAX 2048
7530 -static char remcomInBuffer[BUFMAX];
7531 -static char remcomOutBuffer[BUFMAX];
7532 -
7533 -static int initialized;
7534 -static int kgdb_active;
7535 -static int kgdb_started;
7536 -static u_int fault_jmp_buf[100];
7537 -static int kdebug;
7538 -
7539 -
7540 -static const char hexchars[]="0123456789abcdef";
7541 -
7542 -/* Place where we save old trap entries for restoration - sparc*/
7543 -/* struct tt_entry kgdb_savettable[256]; */
7544 -/* typedef void (*trapfunc_t)(void); */
7545 -
7546 -static void kgdb_fault_handler(struct pt_regs *regs);
7547 -static int handle_exception (struct pt_regs *regs);
7548 -
7549 -#if 0
7550 -/* Install an exception handler for kgdb */
7551 -static void exceptionHandler(int tnum, unsigned int *tfunc)
7552 -{
7553 -       /* We are dorking with a live trap table, all irqs off */
7554 -}
7555 -#endif
7556 -
7557 -int
7558 -kgdb_setjmp(long *buf)
7559 -{
7560 -       asm ("mflr 0; stw 0,0(%0);"
7561 -            "stw 1,4(%0); stw 2,8(%0);"
7562 -            "mfcr 0; stw 0,12(%0);"
7563 -            "stmw 13,16(%0)"
7564 -            : : "r" (buf));
7565 -       /* XXX should save fp regs as well */
7566 -       return 0;
7567 -}
7568 -void
7569 -kgdb_longjmp(long *buf, int val)
7570 -{
7571 -       if (val == 0)
7572 -               val = 1;
7573 -       asm ("lmw 13,16(%0);"
7574 -            "lwz 0,12(%0); mtcrf 0x38,0;"
7575 -            "lwz 0,0(%0); lwz 1,4(%0); lwz 2,8(%0);"
7576 -            "mtlr 0; mr 3,%1"
7577 -            : : "r" (buf), "r" (val));
7578 -}
7579 -/* Convert ch from a hex digit to an int */
7580 -static int
7581 -hex(unsigned char ch)
7582 -{
7583 -       if (ch >= 'a' && ch <= 'f')
7584 -               return ch-'a'+10;
7585 -       if (ch >= '0' && ch <= '9')
7586 -               return ch-'0';
7587 -       if (ch >= 'A' && ch <= 'F')
7588 -               return ch-'A'+10;
7589 -       return -1;
7590 -}
7591 -
7592 -/* Convert the memory pointed to by mem into hex, placing result in buf.
7593 - * Return a pointer to the last char put in buf (null), in case of mem fault,
7594 - * return 0.
7595 - */
7596 -static unsigned char *
7597 -mem2hex(const char *mem, char *buf, int count)
7598 -{
7599 -       unsigned char ch;
7600 -       unsigned short tmp_s;
7601 -       unsigned long tmp_l;
7602 -
7603 -       if (kgdb_setjmp((long*)fault_jmp_buf) == 0) {
7604 -               debugger_fault_handler = kgdb_fault_handler;
7605 -
7606 -               /* Accessing 16 bit and 32 bit objects in a single
7607 -               ** load instruction is required to avoid bad side
7608 -               ** effects for some IO registers.
7609 -               */
7610 -
7611 -               if ((count == 2) && (((long)mem & 1) == 0)) {
7612 -                       tmp_s = *(unsigned short *)mem;
7613 -                       mem += 2;
7614 -                       *buf++ = hexchars[(tmp_s >> 12) & 0xf];
7615 -                       *buf++ = hexchars[(tmp_s >> 8) & 0xf];
7616 -                       *buf++ = hexchars[(tmp_s >> 4) & 0xf];
7617 -                       *buf++ = hexchars[tmp_s & 0xf];
7618 -
7619 -               } else if ((count == 4) && (((long)mem & 3) == 0)) {
7620 -                       tmp_l = *(unsigned int *)mem;
7621 -                       mem += 4;
7622 -                       *buf++ = hexchars[(tmp_l >> 28) & 0xf];
7623 -                       *buf++ = hexchars[(tmp_l >> 24) & 0xf];
7624 -                       *buf++ = hexchars[(tmp_l >> 20) & 0xf];
7625 -                       *buf++ = hexchars[(tmp_l >> 16) & 0xf];
7626 -                       *buf++ = hexchars[(tmp_l >> 12) & 0xf];
7627 -                       *buf++ = hexchars[(tmp_l >> 8) & 0xf];
7628 -                       *buf++ = hexchars[(tmp_l >> 4) & 0xf];
7629 -                       *buf++ = hexchars[tmp_l & 0xf];
7630 -
7631 -               } else {
7632 -                       while (count-- > 0) {
7633 -                               ch = *mem++;
7634 -                               *buf++ = hexchars[ch >> 4];
7635 -                               *buf++ = hexchars[ch & 0xf];
7636 -                       }
7637 -               }
7638 -
7639 -       } else {
7640 -               /* error condition */
7641 -       }
7642 -       debugger_fault_handler = NULL;
7643 -       *buf = 0;
7644 -       return buf;
7645 -}
7646 -
7647 -/* convert the hex array pointed to by buf into binary to be placed in mem
7648 - * return a pointer to the character AFTER the last byte written.
7649 -*/
7650 -static char *
7651 -hex2mem(char *buf, char *mem, int count)
7652 -{
7653 -       unsigned char ch;
7654 -       int i;
7655 -       char *orig_mem;
7656 -       unsigned short tmp_s;
7657 -       unsigned long tmp_l;
7658 -
7659 -       orig_mem = mem;
7660 -
7661 -       if (kgdb_setjmp((long*)fault_jmp_buf) == 0) {
7662 -               debugger_fault_handler = kgdb_fault_handler;
7663 -
7664 -               /* Accessing 16 bit and 32 bit objects in a single
7665 -               ** store instruction is required to avoid bad side
7666 -               ** effects for some IO registers.
7667 -               */
7668 -
7669 -               if ((count == 2) && (((long)mem & 1) == 0)) {
7670 -                       tmp_s = hex(*buf++) << 12;
7671 -                       tmp_s |= hex(*buf++) << 8;
7672 -                       tmp_s |= hex(*buf++) << 4;
7673 -                       tmp_s |= hex(*buf++);
7674 -
7675 -                       *(unsigned short *)mem = tmp_s;
7676 -                       mem += 2;
7677 -
7678 -               } else if ((count == 4) && (((long)mem & 3) == 0)) {
7679 -                       tmp_l = hex(*buf++) << 28;
7680 -                       tmp_l |= hex(*buf++) << 24;
7681 -                       tmp_l |= hex(*buf++) << 20;
7682 -                       tmp_l |= hex(*buf++) << 16;
7683 -                       tmp_l |= hex(*buf++) << 12;
7684 -                       tmp_l |= hex(*buf++) << 8;
7685 -                       tmp_l |= hex(*buf++) << 4;
7686 -                       tmp_l |= hex(*buf++);
7687 -
7688 -                       *(unsigned long *)mem = tmp_l;
7689 -                       mem += 4;
7690 -
7691 -               } else {
7692 -                       for (i=0; i<count; i++) {
7693 -                               ch = hex(*buf++) << 4;
7694 -                               ch |= hex(*buf++);
7695 -                               *mem++ = ch;
7696 -                       }
7697 -               }
7698 -
7699 -
7700 -               /*
7701 -               ** Flush the data cache, invalidate the instruction cache.
7702 -               */
7703 -               flush_icache_range((int)orig_mem, (int)orig_mem + count - 1);
7704 -
7705 -       } else {
7706 -               /* error condition */
7707 -       }
7708 -       debugger_fault_handler = NULL;
7709 -       return mem;
7710 -}
7711 -
7712 -/*
7713 - * While we find nice hex chars, build an int.
7714 - * Return number of chars processed.
7715 - */
7716 -static int
7717 -hexToInt(char **ptr, int *intValue)
7718 -{
7719 -       int numChars = 0;
7720 -       int hexValue;
7721 -
7722 -       *intValue = 0;
7723 -
7724 -       if (kgdb_setjmp((long*)fault_jmp_buf) == 0) {
7725 -               debugger_fault_handler = kgdb_fault_handler;
7726 -               while (**ptr) {
7727 -                       hexValue = hex(**ptr);
7728 -                       if (hexValue < 0)
7729 -                               break;
7730 -
7731 -                       *intValue = (*intValue << 4) | hexValue;
7732 -                       numChars ++;
7733 -
7734 -                       (*ptr)++;
7735 -               }
7736 -       } else {
7737 -               /* error condition */
7738 -       }
7739 -       debugger_fault_handler = NULL;
7740 -
7741 -       return (numChars);
7742 -}
7743 -
7744 -/* scan for the sequence $<data>#<checksum> */
7745 -static void
7746 -getpacket(char *buffer)
7747 -{
7748 -       unsigned char checksum;
7749 -       unsigned char xmitcsum;
7750 -       int i;
7751 -       int count;
7752 -       unsigned char ch;
7753 -
7754 -       do {
7755 -               /* wait around for the start character, ignore all other
7756 -                * characters */
7757 -               while ((ch = (getDebugChar() & 0x7f)) != '$') ;
7758 -
7759 -               checksum = 0;
7760 -               xmitcsum = -1;
7761 -
7762 -               count = 0;
7763 -
7764 -               /* now, read until a # or end of buffer is found */
7765 -               while (count < BUFMAX) {
7766 -                       ch = getDebugChar() & 0x7f;
7767 -                       if (ch == '#')
7768 -                               break;
7769 -                       checksum = checksum + ch;
7770 -                       buffer[count] = ch;
7771 -                       count = count + 1;
7772 -               }
7773 -
7774 -               if (count >= BUFMAX)
7775 -                       continue;
7776 -
7777 -               buffer[count] = 0;
7778 -
7779 -               if (ch == '#') {
7780 -                       xmitcsum = hex(getDebugChar() & 0x7f) << 4;
7781 -                       xmitcsum |= hex(getDebugChar() & 0x7f);
7782 -                       if (checksum != xmitcsum)
7783 -                               putDebugChar('-');      /* failed checksum */
7784 -                       else {
7785 -                               putDebugChar('+'); /* successful transfer */
7786 -                               /* if a sequence char is present, reply the ID */
7787 -                               if (buffer[2] == ':') {
7788 -                                       putDebugChar(buffer[0]);
7789 -                                       putDebugChar(buffer[1]);
7790 -                                       /* remove sequence chars from buffer */
7791 -                                       count = strlen(buffer);
7792 -                                       for (i=3; i <= count; i++)
7793 -                                               buffer[i-3] = buffer[i];
7794 -                               }
7795 -                       }
7796 -               }
7797 -       } while (checksum != xmitcsum);
7798 -}
7799 -
7800 -/* send the packet in buffer. */
7801 -static void putpacket(unsigned char *buffer)
7802 -{
7803 -       unsigned char checksum;
7804 -       int count;
7805 -       unsigned char ch, recv;
7806 -
7807 -       /* $<packet info>#<checksum>. */
7808 -       do {
7809 -               putDebugChar('$');
7810 -               checksum = 0;
7811 -               count = 0;
7812 -
7813 -               while ((ch = buffer[count])) {
7814 -                       putDebugChar(ch);
7815 -                       checksum += ch;
7816 -                       count += 1;
7817 -               }
7818 -
7819 -               putDebugChar('#');
7820 -               putDebugChar(hexchars[checksum >> 4]);
7821 -               putDebugChar(hexchars[checksum & 0xf]);
7822 -               recv = getDebugChar();
7823 -       } while ((recv & 0x7f) != '+');
7824 -}
7825 -
7826 -static void kgdb_flush_cache_all(void)
7827 -{
7828 -       flush_instruction_cache();
7829 -}
7830 -
7831 -/* Set up exception handlers for tracing and breakpoints
7832 - * [could be called kgdb_init()]
7833 - */
7834 -void set_debug_traps(void)
7835 -{
7836 -#if 0
7837 -       unsigned char c;
7838 -
7839 -       save_and_cli(flags);
7840 -
7841 -       /* In case GDB is started before us, ack any packets (presumably
7842 -        * "$?#xx") sitting there.
7843 -        *
7844 -        * I've found this code causes more problems than it solves,
7845 -        * so that's why it's commented out.  GDB seems to work fine
7846 -        * now starting either before or after the kernel   -bwb
7847 -        */
7848 -
7849 -       while((c = getDebugChar()) != '$');
7850 -       while((c = getDebugChar()) != '#');
7851 -       c = getDebugChar(); /* eat first csum byte */
7852 -       c = getDebugChar(); /* eat second csum byte */
7853 -       putDebugChar('+'); /* ack it */
7854 -#endif
7855 -       debugger = kgdb;
7856 -       debugger_bpt = kgdb_bpt;
7857 -       debugger_sstep = kgdb_sstep;
7858 -       debugger_iabr_match = kgdb_iabr_match;
7859 -       debugger_dabr_match = kgdb_dabr_match;
7860 -
7861 -       initialized = 1;
7862 -}
7863 -
7864 -static void kgdb_fault_handler(struct pt_regs *regs)
7865 -{
7866 -       kgdb_longjmp((long*)fault_jmp_buf, 1);
7867 -}
7868 -
7869 -int kgdb_bpt(struct pt_regs *regs)
7870 -{
7871 -       return handle_exception(regs);
7872 -}
7873 -
7874 -int kgdb_sstep(struct pt_regs *regs)
7875 -{
7876 -       return handle_exception(regs);
7877 -}
7878 -
7879 -void kgdb(struct pt_regs *regs)
7880 -{
7881 -       handle_exception(regs);
7882 -}
7883 -
7884 -int kgdb_iabr_match(struct pt_regs *regs)
7885 -{
7886 -       printk(KERN_ERR "kgdb doesn't support iabr, what?!?\n");
7887 -       return handle_exception(regs);
7888 -}
7889 -
7890 -int kgdb_dabr_match(struct pt_regs *regs)
7891 -{
7892 -       printk(KERN_ERR "kgdb doesn't support dabr, what?!?\n");
7893 -       return handle_exception(regs);
7894 -}
7895 -
7896 -/* Convert the hardware trap type code to a unix signal number. */
7897 -/*
7898 - * This table contains the mapping between PowerPC hardware trap types, and
7899 - * signals, which are primarily what GDB understands.
7900 - */
7901 -static struct hard_trap_info
7902 -{
7903 -       unsigned int tt;                /* Trap type code for powerpc */
7904 -       unsigned char signo;            /* Signal that we map this trap into */
7905 -} hard_trap_info[] = {
7906 -#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
7907 -       { 0x100, SIGINT  },             /* critical input interrupt */
7908 -       { 0x200, SIGSEGV },             /* machine check */
7909 -       { 0x300, SIGSEGV },             /* data storage */
7910 -       { 0x400, SIGBUS  },             /* instruction storage */
7911 -       { 0x500, SIGINT  },             /* interrupt */
7912 -       { 0x600, SIGBUS  },             /* alignment */
7913 -       { 0x700, SIGILL  },             /* program */
7914 -       { 0x800, SIGILL  },             /* reserved */
7915 -       { 0x900, SIGILL  },             /* reserved */
7916 -       { 0xa00, SIGILL  },             /* reserved */
7917 -       { 0xb00, SIGILL  },             /* reserved */
7918 -       { 0xc00, SIGCHLD },             /* syscall */
7919 -       { 0xd00, SIGILL  },             /* reserved */
7920 -       { 0xe00, SIGILL  },             /* reserved */
7921 -       { 0xf00, SIGILL  },             /* reserved */
7922 -       /*
7923 -       ** 0x1000  PIT
7924 -       ** 0x1010  FIT
7925 -       ** 0x1020  watchdog
7926 -       ** 0x1100  data TLB miss
7927 -       ** 0x1200  instruction TLB miss
7928 -       */
7929 -       { 0x2002, SIGTRAP},             /* debug */
7930 -#else
7931 -       { 0x200, SIGSEGV },             /* machine check */
7932 -       { 0x300, SIGSEGV },             /* address error (store) */
7933 -       { 0x400, SIGBUS },              /* instruction bus error */
7934 -       { 0x500, SIGINT },              /* interrupt */
7935 -       { 0x600, SIGBUS },              /* alingment */
7936 -       { 0x700, SIGTRAP },             /* breakpoint trap */
7937 -       { 0x800, SIGFPE },              /* fpu unavail */
7938 -       { 0x900, SIGALRM },             /* decrementer */
7939 -       { 0xa00, SIGILL },              /* reserved */
7940 -       { 0xb00, SIGILL },              /* reserved */
7941 -       { 0xc00, SIGCHLD },             /* syscall */
7942 -       { 0xd00, SIGTRAP },             /* single-step/watch */
7943 -       { 0xe00, SIGFPE },              /* fp assist */
7944 -#endif
7945 -       { 0, 0}                         /* Must be last */
7946 -
7947 -};
7948 -
7949 -static int computeSignal(unsigned int tt)
7950 -{
7951 -       struct hard_trap_info *ht;
7952 -
7953 -       for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
7954 -               if (ht->tt == tt)
7955 -                       return ht->signo;
7956 -
7957 -       return SIGHUP; /* default for things we don't know about */
7958 -}
7959 -
7960 -#define PC_REGNUM 64
7961 -#define SP_REGNUM 1
7962 -
7963 -/*
7964 - * This function does all command processing for interfacing to gdb.
7965 - */
7966 -static int
7967 -handle_exception (struct pt_regs *regs)
7968 -{
7969 -       int sigval;
7970 -       int addr;
7971 -       int length;
7972 -       char *ptr;
7973 -       unsigned int msr;
7974 -
7975 -       /* We don't handle user-mode breakpoints. */
7976 -       if (user_mode(regs))
7977 -               return 0;
7978 -
7979 -       if (debugger_fault_handler) {
7980 -               debugger_fault_handler(regs);
7981 -               panic("kgdb longjump failed!\n");
7982 -       }
7983 -       if (kgdb_active) {
7984 -               printk(KERN_ERR "interrupt while in kgdb, returning\n");
7985 -               return 0;
7986 -       }
7987 -
7988 -       kgdb_active = 1;
7989 -       kgdb_started = 1;
7990 -
7991 -#ifdef KGDB_DEBUG
7992 -       printk("kgdb: entering handle_exception; trap [0x%x]\n",
7993 -                       (unsigned int)regs->trap);
7994 -#endif
7995 -
7996 -       kgdb_interruptible(0);
7997 -       lock_kernel();
7998 -       msr = mfmsr();
7999 -       mtmsr(msr & ~MSR_EE);   /* disable interrupts */
8000 -
8001 -       if (regs->nip == (unsigned long)breakinst) {
8002 -               /* Skip over breakpoint trap insn */
8003 -               regs->nip += 4;
8004 -       }
8005 -
8006 -       /* reply to host that an exception has occurred */
8007 -       sigval = computeSignal(regs->trap);
8008 -       ptr = remcomOutBuffer;
8009 -
8010 -       *ptr++ = 'T';
8011 -       *ptr++ = hexchars[sigval >> 4];
8012 -       *ptr++ = hexchars[sigval & 0xf];
8013 -       *ptr++ = hexchars[PC_REGNUM >> 4];
8014 -       *ptr++ = hexchars[PC_REGNUM & 0xf];
8015 -       *ptr++ = ':';
8016 -       ptr = mem2hex((char *)&regs->nip, ptr, 4);
8017 -       *ptr++ = ';';
8018 -       *ptr++ = hexchars[SP_REGNUM >> 4];
8019 -       *ptr++ = hexchars[SP_REGNUM & 0xf];
8020 -       *ptr++ = ':';
8021 -       ptr = mem2hex(((char *)regs) + SP_REGNUM*4, ptr, 4);
8022 -       *ptr++ = ';';
8023 -       *ptr++ = 0;
8024 -
8025 -       putpacket(remcomOutBuffer);
8026 -       if (kdebug)
8027 -               printk("remcomOutBuffer: %s\n", remcomOutBuffer);
8028 -
8029 -       /* XXX We may want to add some features dealing with poking the
8030 -        * XXX page tables, ... (look at sparc-stub.c for more info)
8031 -        * XXX also required hacking to the gdb sources directly...
8032 -        */
8033 -
8034 -       while (1) {
8035 -               remcomOutBuffer[0] = 0;
8036 -
8037 -               getpacket(remcomInBuffer);
8038 -               switch (remcomInBuffer[0]) {
8039 -               case '?': /* report most recent signal */
8040 -                       remcomOutBuffer[0] = 'S';
8041 -                       remcomOutBuffer[1] = hexchars[sigval >> 4];
8042 -                       remcomOutBuffer[2] = hexchars[sigval & 0xf];
8043 -                       remcomOutBuffer[3] = 0;
8044 -                       break;
8045 -#if 0
8046 -               case 'q': /* this screws up gdb for some reason...*/
8047 -               {
8048 -                       extern long _start, sdata, __bss_start;
8049 -
8050 -                       ptr = &remcomInBuffer[1];
8051 -                       if (strncmp(ptr, "Offsets", 7) != 0)
8052 -                               break;
8053 -
8054 -                       ptr = remcomOutBuffer;
8055 -                       sprintf(ptr, "Text=%8.8x;Data=%8.8x;Bss=%8.8x",
8056 -                               &_start, &sdata, &__bss_start);
8057 -                       break;
8058 -               }
8059 -#endif
8060 -               case 'd':
8061 -                       /* toggle debug flag */
8062 -                       kdebug ^= 1;
8063 -                       break;
8064 -
8065 -               case 'g':       /* return the value of the CPU registers.
8066 -                                * some of them are non-PowerPC names :(
8067 -                                * they are stored in gdb like:
8068 -                                * struct {
8069 -                                *     u32 gpr[32];
8070 -                                *     f64 fpr[32];
8071 -                                *     u32 pc, ps, cnd, lr; (ps=msr)
8072 -                                *     u32 cnt, xer, mq;
8073 -                                * }
8074 -                                */
8075 -               {
8076 -                       int i;
8077 -                       ptr = remcomOutBuffer;
8078 -                       /* General Purpose Regs */
8079 -                       ptr = mem2hex((char *)regs, ptr, 32 * 4);
8080 -                       /* Floating Point Regs - FIXME */
8081 -                       /*ptr = mem2hex((char *), ptr, 32 * 8);*/
8082 -                       for(i=0; i<(32*8*2); i++) { /* 2chars/byte */
8083 -                               ptr[i] = '0';
8084 -                       }
8085 -                       ptr += 32*8*2;
8086 -                       /* pc, msr, cr, lr, ctr, xer, (mq is unused) */
8087 -                       ptr = mem2hex((char *)&regs->nip, ptr, 4);
8088 -                       ptr = mem2hex((char *)&regs->msr, ptr, 4);
8089 -                       ptr = mem2hex((char *)&regs->ccr, ptr, 4);
8090 -                       ptr = mem2hex((char *)&regs->link, ptr, 4);
8091 -                       ptr = mem2hex((char *)&regs->ctr, ptr, 4);
8092 -                       ptr = mem2hex((char *)&regs->xer, ptr, 4);
8093 -               }
8094 -                       break;
8095 -
8096 -               case 'G': /* set the value of the CPU registers */
8097 -               {
8098 -                       ptr = &remcomInBuffer[1];
8099 -
8100 -                       /*
8101 -                        * If the stack pointer has moved, you should pray.
8102 -                        * (cause only god can help you).
8103 -                        */
8104 -
8105 -                       /* General Purpose Regs */
8106 -                       hex2mem(ptr, (char *)regs, 32 * 4);
8107 -
8108 -                       /* Floating Point Regs - FIXME?? */
8109 -                       /*ptr = hex2mem(ptr, ??, 32 * 8);*/
8110 -                       ptr += 32*8*2;
8111 -
8112 -                       /* pc, msr, cr, lr, ctr, xer, (mq is unused) */
8113 -                       ptr = hex2mem(ptr, (char *)&regs->nip, 4);
8114 -                       ptr = hex2mem(ptr, (char *)&regs->msr, 4);
8115 -                       ptr = hex2mem(ptr, (char *)&regs->ccr, 4);
8116 -                       ptr = hex2mem(ptr, (char *)&regs->link, 4);
8117 -                       ptr = hex2mem(ptr, (char *)&regs->ctr, 4);
8118 -                       ptr = hex2mem(ptr, (char *)&regs->xer, 4);
8119 -
8120 -                       strcpy(remcomOutBuffer,"OK");
8121 -               }
8122 -                       break;
8123 -               case 'H':
8124 -                       /* don't do anything, yet, just acknowledge */
8125 -                       hexToInt(&ptr, &addr);
8126 -                       strcpy(remcomOutBuffer,"OK");
8127 -                       break;
8128 -
8129 -               case 'm':       /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
8130 -                               /* Try to read %x,%x.  */
8131 -
8132 -                       ptr = &remcomInBuffer[1];
8133 -
8134 -                       if (hexToInt(&ptr, &addr) && *ptr++ == ','
8135 -                                       && hexToInt(&ptr, &length)) {
8136 -                               if (mem2hex((char *)addr, remcomOutBuffer,
8137 -                                                       length))
8138 -                                       break;
8139 -                               strcpy(remcomOutBuffer, "E03");
8140 -                       } else
8141 -                               strcpy(remcomOutBuffer, "E01");
8142 -                       break;
8143 -
8144 -               case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
8145 -                       /* Try to read '%x,%x:'.  */
8146 -
8147 -                       ptr = &remcomInBuffer[1];
8148 -
8149 -                       if (hexToInt(&ptr, &addr) && *ptr++ == ','
8150 -                                       && hexToInt(&ptr, &length)
8151 -                                       && *ptr++ == ':') {
8152 -                               if (hex2mem(ptr, (char *)addr, length))
8153 -                                       strcpy(remcomOutBuffer, "OK");
8154 -                               else
8155 -                                       strcpy(remcomOutBuffer, "E03");
8156 -                               flush_icache_range(addr, addr+length);
8157 -                       } else
8158 -                               strcpy(remcomOutBuffer, "E02");
8159 -                       break;
8160 -
8161 -
8162 -               case 'k': /* kill the program, actually just continue */
8163 -               case 'c': /* cAA..AA  Continue; address AA..AA optional */
8164 -                       /* try to read optional parameter, pc unchanged if no parm */
8165 -
8166 -                       ptr = &remcomInBuffer[1];
8167 -                       if (hexToInt(&ptr, &addr))
8168 -                               regs->nip = addr;
8169 -
8170 -/* Need to flush the instruction cache here, as we may have deposited a
8171 - * breakpoint, and the icache probably has no way of knowing that a data ref to
8172 - * some location may have changed something that is in the instruction cache.
8173 - */
8174 -                       kgdb_flush_cache_all();
8175 -                       mtmsr(msr);
8176 -
8177 -                       kgdb_interruptible(1);
8178 -                       unlock_kernel();
8179 -                       kgdb_active = 0;
8180 -                       if (kdebug) {
8181 -                               printk("remcomInBuffer: %s\n", remcomInBuffer);
8182 -                               printk("remcomOutBuffer: %s\n", remcomOutBuffer);
8183 -                       }
8184 -                       return 1;
8185 -
8186 -               case 's':
8187 -                       kgdb_flush_cache_all();
8188 -#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
8189 -                       mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | DBCR0_IC);
8190 -                       regs->msr |= MSR_DE;
8191 -#else
8192 -                       regs->msr |= MSR_SE;
8193 -#endif
8194 -                       unlock_kernel();
8195 -                       kgdb_active = 0;
8196 -                       if (kdebug) {
8197 -                               printk("remcomInBuffer: %s\n", remcomInBuffer);
8198 -                               printk("remcomOutBuffer: %s\n", remcomOutBuffer);
8199 -                       }
8200 -                       return 1;
8201 -
8202 -               case 'r':               /* Reset (if user process..exit ???)*/
8203 -                       panic("kgdb reset.");
8204 -                       break;
8205 -               }                       /* switch */
8206 -               if (remcomOutBuffer[0] && kdebug) {
8207 -                       printk("remcomInBuffer: %s\n", remcomInBuffer);
8208 -                       printk("remcomOutBuffer: %s\n", remcomOutBuffer);
8209 -               }
8210 -               /* reply to the request */
8211 -               putpacket(remcomOutBuffer);
8212 -       } /* while(1) */
8213 -}
8214 -
8215 -/* This function will generate a breakpoint exception.  It is used at the
8216 -   beginning of a program to sync up with a debugger and can be used
8217 -   otherwise as a quick means to stop program execution and "break" into
8218 -   the debugger. */
8219 -
8220 -void
8221 -breakpoint(void)
8222 -{
8223 -       if (!initialized) {
8224 -               printk("breakpoint() called b4 kgdb init\n");
8225 -               return;
8226 -       }
8227 -
8228 -       asm("   .globl breakinst        \n\
8229 -            breakinst: .long 0x7d821008");
8230 -}
8231 -
8232 -#ifdef CONFIG_KGDB_CONSOLE
8233 -/* Output string in GDB O-packet format if GDB has connected. If nothing
8234 -   output, returns 0 (caller must then handle output). */
8235 -int
8236 -kgdb_output_string (const char* s, unsigned int count)
8237 -{
8238 -       char buffer[512];
8239 -
8240 -       if (!kgdb_started)
8241 -               return 0;
8242 -
8243 -       count = (count <= (sizeof(buffer) / 2 - 2))
8244 -               ? count : (sizeof(buffer) / 2 - 2);
8245 -
8246 -       buffer[0] = 'O';
8247 -       mem2hex (s, &buffer[1], count);
8248 -       putpacket(buffer);
8249 -
8250 -       return 1;
8251 -}
8252 -#endif
8253 -
8254 -static void sysrq_handle_gdb(int key, struct pt_regs *pt_regs,
8255 -                            struct tty_struct *tty)
8256 -{
8257 -       printk("Entering GDB stub\n");
8258 -       breakpoint();
8259 -}
8260 -static struct sysrq_key_op sysrq_gdb_op = {
8261 -        .handler        = sysrq_handle_gdb,
8262 -        .help_msg       = "Gdb",
8263 -        .action_msg     = "GDB",
8264 -};
8265 -
8266 -static int gdb_register_sysrq(void)
8267 -{
8268 -       printk("Registering GDB sysrq handler\n");
8269 -       register_sysrq_key('g', &sysrq_gdb_op);
8270 -       return 0;
8271 -}
8272 -module_init(gdb_register_sysrq);
8273 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/kernel/setup.c linux-2.6.18-53.1.14.kgdb/arch/ppc/kernel/setup.c
8274 --- linux-2.6.18-53.1.14/arch/ppc/kernel/setup.c        2008-03-06 05:54:43.000000000 +0300
8275 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/kernel/setup.c   2008-06-10 15:38:14.000000000 +0400
8276 @@ -48,10 +48,6 @@
8277  #include <asm/ppc_sys.h>
8278  #endif
8279  
8280 -#if defined CONFIG_KGDB
8281 -#include <asm/kgdb.h>
8282 -#endif
8283 -
8284  extern void platform_init(unsigned long r3, unsigned long r4,
8285                 unsigned long r5, unsigned long r6, unsigned long r7);
8286  extern void reloc_got2(unsigned long offset);
8287 @@ -506,18 +502,6 @@ void __init setup_arch(char **cmdline_p)
8288  #endif /* CONFIG_XMON */
8289         if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
8290  
8291 -#if defined(CONFIG_KGDB)
8292 -       if (ppc_md.kgdb_map_scc)
8293 -               ppc_md.kgdb_map_scc();
8294 -       set_debug_traps();
8295 -       if (strstr(cmd_line, "gdb")) {
8296 -               if (ppc_md.progress)
8297 -                       ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
8298 -               printk("kgdb breakpoint activated\n");
8299 -               breakpoint();
8300 -       }
8301 -#endif
8302 -
8303         /*
8304          * Set cache line size based on type of cpu as a default.
8305          * Systems with OF can look in the properties on the cpu node(s)
8306 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/mm/fault.c linux-2.6.18-53.1.14.kgdb/arch/ppc/mm/fault.c
8307 --- linux-2.6.18-53.1.14/arch/ppc/mm/fault.c    2006-09-20 07:42:06.000000000 +0400
8308 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/mm/fault.c       2008-06-10 15:38:14.000000000 +0400
8309 @@ -25,6 +25,7 @@
8310  #include <linux/interrupt.h>
8311  #include <linux/highmem.h>
8312  #include <linux/module.h>
8313 +#include <linux/kgdb.h>
8314  
8315  #include <asm/page.h>
8316  #include <asm/pgtable.h>
8317 @@ -329,6 +330,14 @@ bad_page_fault(struct pt_regs *regs, uns
8318                 return;
8319         }
8320  
8321 +#ifdef CONFIG_KGDB
8322 +       if (atomic_read(&debugger_active) && kgdb_may_fault) {
8323 +               /* Restore our previous state. */
8324 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
8325 +               /* Not reached. */
8326 +       }
8327 +#endif
8328 +
8329         /* kernel has accessed a bad area */
8330  #if defined(CONFIG_XMON) || defined(CONFIG_KGDB)
8331         if (debugger_kernel_faults)
8332 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/platforms/4xx/bubinga.c linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/4xx/bubinga.c
8333 --- linux-2.6.18-53.1.14/arch/ppc/platforms/4xx/bubinga.c       2006-09-20 07:42:06.000000000 +0400
8334 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/4xx/bubinga.c  2008-06-10 15:38:14.000000000 +0400
8335 @@ -4,7 +4,7 @@
8336   * Author: SAW (IBM), derived from walnut.c.
8337   *         Maintained by MontaVista Software <source@mvista.com>
8338   *
8339 - * 2003 (c) MontaVista Softare Inc.  This file is licensed under the
8340 + * 2003-2004 (c) MontaVista Softare Inc.  This file is licensed under the
8341   * terms of the GNU General Public License version 2. This program is
8342   * licensed "as is" without any warranty of any kind, whether express
8343   * or implied.
8344 @@ -100,17 +100,26 @@ bubinga_early_serial_map(void)
8345         port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
8346         port.line = 0;
8347  
8348 -       if (early_serial_setup(&port) != 0) {
8349 +#ifdef CONFIG_SERIAL_8250
8350 +       if (early_serial_setup(&port) != 0)
8351                 printk("Early serial init of port 0 failed\n");
8352 -       }
8353 +#endif
8354 +
8355 +#ifdef CONFIG_KGDB_8250
8356 +       kgdb8250_add_port(0, &port);
8357 +#endif
8358  
8359         port.membase = (void*)ACTING_UART1_IO_BASE;
8360         port.irq = ACTING_UART1_INT;
8361         port.line = 1;
8362  
8363 -       if (early_serial_setup(&port) != 0) {
8364 +#ifdef CONFIG_SERIAL_8250
8365 +       if (early_serial_setup(&port) != 0)
8366                 printk("Early serial init of port 1 failed\n");
8367 -       }
8368 +#endif
8369 +#ifdef CONFIG_KGDB_8250
8370 +       kgdb8250_add_port(1, &port);
8371 +#endif
8372  }
8373  
8374  void __init
8375 @@ -255,8 +264,4 @@ platform_init(unsigned long r3, unsigned
8376         ppc_md.nvram_read_val = todc_direct_read_val;
8377         ppc_md.nvram_write_val = todc_direct_write_val;
8378  #endif
8379 -#ifdef CONFIG_KGDB
8380 -       ppc_md.early_serial_map = bubinga_early_serial_map;
8381 -#endif
8382  }
8383 -
8384 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/platforms/4xx/ebony.c linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/4xx/ebony.c
8385 --- linux-2.6.18-53.1.14/arch/ppc/platforms/4xx/ebony.c 2006-09-20 07:42:06.000000000 +0400
8386 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/4xx/ebony.c    2008-06-10 15:38:14.000000000 +0400
8387 @@ -32,6 +32,7 @@
8388  #include <linux/tty.h>
8389  #include <linux/serial.h>
8390  #include <linux/serial_core.h>
8391 +#include <linux/kgdb.h>
8392  
8393  #include <asm/system.h>
8394  #include <asm/pgtable.h>
8395 @@ -226,14 +227,20 @@ ebony_early_serial_map(void)
8396         port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
8397         port.line = 0;
8398  
8399 -       if (early_serial_setup(&port) != 0) {
8400 +#ifdef CONFIG_SERIAL_8250
8401 +       if (early_serial_setup(&port) != 0)
8402                 printk("Early serial init of port 0 failed\n");
8403 -       }
8404 +#endif
8405  
8406 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8407 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8408         /* Configure debug serial access */
8409         gen550_init(0, &port);
8410 +#endif
8411 +#ifdef CONFIG_KGDB_8250
8412 +       kgdb8250_add_port(0, &port);
8413 +#endif
8414  
8415 +#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_8250)
8416         /* Purge TLB entry added in head_44x.S for early serial access */
8417         _tlbie(UART0_IO_BASE);
8418  #endif
8419 @@ -243,14 +250,18 @@ ebony_early_serial_map(void)
8420         port.uartclk = clocks.uart1;
8421         port.line = 1;
8422  
8423 -       if (early_serial_setup(&port) != 0) {
8424 +#ifdef CONFIG_SERIAL_8250
8425 +       if (early_serial_setup(&port) != 1)
8426                 printk("Early serial init of port 1 failed\n");
8427 -       }
8428 +#endif
8429  
8430 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8431 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8432         /* Configure debug serial access */
8433         gen550_init(1, &port);
8434  #endif
8435 +#ifdef CONFIG_KGDB_8250
8436 +       kgdb8250_add_port(1, &port);
8437 +#endif
8438  }
8439  
8440  static void __init
8441 @@ -327,8 +338,4 @@ void __init platform_init(unsigned long 
8442  
8443         ppc_md.nvram_read_val = todc_direct_read_val;
8444         ppc_md.nvram_write_val = todc_direct_write_val;
8445 -#ifdef CONFIG_KGDB
8446 -       ppc_md.early_serial_map = ebony_early_serial_map;
8447 -#endif
8448  }
8449 -
8450 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/platforms/4xx/ocotea.c linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/4xx/ocotea.c
8451 --- linux-2.6.18-53.1.14/arch/ppc/platforms/4xx/ocotea.c        2006-09-20 07:42:06.000000000 +0400
8452 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/4xx/ocotea.c   2008-06-10 15:38:14.000000000 +0400
8453 @@ -30,6 +30,7 @@
8454  #include <linux/tty.h>
8455  #include <linux/serial.h>
8456  #include <linux/serial_core.h>
8457 +#include <linux/kgdb.h>
8458  
8459  #include <asm/system.h>
8460  #include <asm/pgtable.h>
8461 @@ -249,14 +250,20 @@ ocotea_early_serial_map(void)
8462         port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
8463         port.line = 0;
8464  
8465 -       if (early_serial_setup(&port) != 0) {
8466 +#ifdef CONFIG_SERIAL_8250
8467 +       if (early_serial_setup(&port) != 0)
8468                 printk("Early serial init of port 0 failed\n");
8469 -       }
8470 +#endif
8471  
8472 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8473 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8474         /* Configure debug serial access */
8475         gen550_init(0, &port);
8476 +#endif
8477 +#ifdef CONFIG_KGDB_8250
8478 +       kgdb8250_add_port(0, &port);
8479 +#endif
8480  
8481 +#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_8250)
8482         /* Purge TLB entry added in head_44x.S for early serial access */
8483         _tlbie(UART0_IO_BASE);
8484  #endif
8485 @@ -266,14 +273,18 @@ ocotea_early_serial_map(void)
8486         port.uartclk = clocks.uart1;
8487         port.line = 1;
8488  
8489 -       if (early_serial_setup(&port) != 0) {
8490 +#ifdef CONFIG_SERIAL_8250
8491 +       if (early_serial_setup(&port) != 1)
8492                 printk("Early serial init of port 1 failed\n");
8493 -       }
8494 +#endif
8495  
8496 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8497 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8498         /* Configure debug serial access */
8499         gen550_init(1, &port);
8500  #endif
8501 +#ifdef CONFIG_KGDB_8250
8502 +       kgdb8250_add_port(1, &port);
8503 +#endif
8504  }
8505  
8506  static void __init
8507 @@ -343,8 +354,5 @@ void __init platform_init(unsigned long 
8508  
8509         ppc_md.nvram_read_val = todc_direct_read_val;
8510         ppc_md.nvram_write_val = todc_direct_write_val;
8511 -#ifdef CONFIG_KGDB
8512 -       ppc_md.early_serial_map = ocotea_early_serial_map;
8513 -#endif
8514         ppc_md.init = ocotea_init;
8515  }
8516 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/platforms/4xx/xilinx_ml300.c linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/4xx/xilinx_ml300.c
8517 --- linux-2.6.18-53.1.14/arch/ppc/platforms/4xx/xilinx_ml300.c  2006-09-20 07:42:06.000000000 +0400
8518 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/4xx/xilinx_ml300.c     2008-06-10 15:38:14.000000000 +0400
8519 @@ -41,9 +41,6 @@
8520   *      ppc4xx_map_io                          arch/ppc/syslib/ppc4xx_setup.c
8521   *  start_kernel                               init/main.c
8522   *    setup_arch                               arch/ppc/kernel/setup.c
8523 - * #if defined(CONFIG_KGDB)
8524 - *      *ppc_md.kgdb_map_scc() == gen550_kgdb_map_scc
8525 - * #endif
8526   *      *ppc_md.setup_arch == ml300_setup_arch this file
8527   *        ppc4xx_setup_arch                    arch/ppc/syslib/ppc4xx_setup.c
8528   *          ppc4xx_find_bridges                        arch/ppc/syslib/ppc405_pci.c
8529 @@ -117,7 +114,6 @@ ml300_early_serial_init(int num, struct 
8530  void __init
8531  ml300_early_serial_map(void)
8532  {
8533 -#ifdef CONFIG_SERIAL_8250
8534         struct plat_serial8250_port *pdata;
8535         int i = 0;
8536  
8537 @@ -129,7 +125,14 @@ ml300_early_serial_map(void)
8538                 pdata++;
8539                 i++;
8540         }
8541 -#endif /* CONFIG_SERIAL_8250 */
8542 +#ifdef CONFIG_SERIAL_8250
8543 +                if (early_serial_setup(&port) != 0)
8544 +                        printk("Early serial init of port %d failed\n", i);
8545 +#endif
8546 +
8547 +#ifdef CONFIG_KGDB_8250
8548 +       kgdb8250_add_port(i, &port)
8549 +#endif
8550  }
8551  
8552  void __init
8553 @@ -165,9 +168,4 @@ platform_init(unsigned long r3, unsigned
8554  #if defined(XPAR_POWER_0_POWERDOWN_BASEADDR)
8555         ppc_md.power_off = xilinx_power_off;
8556  #endif
8557 -
8558 -#ifdef CONFIG_KGDB
8559 -       ppc_md.early_serial_map = ml300_early_serial_map;
8560 -#endif
8561  }
8562 -
8563 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/platforms/85xx/sbc8560.c linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/85xx/sbc8560.c
8564 --- linux-2.6.18-53.1.14/arch/ppc/platforms/85xx/sbc8560.c      2006-09-20 07:42:06.000000000 +0400
8565 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/85xx/sbc8560.c 2008-06-10 15:38:14.000000000 +0400
8566 @@ -50,7 +50,6 @@
8567  #include <syslib/ppc85xx_common.h>
8568  #include <syslib/ppc85xx_setup.h>
8569  
8570 -#ifdef CONFIG_SERIAL_8250
8571  static void __init
8572  sbc8560_early_serial_map(void)
8573  {
8574 @@ -66,12 +65,16 @@ sbc8560_early_serial_map(void)
8575          uart_req.membase = ioremap(uart_req.mapbase, MPC85xx_UART0_SIZE);
8576         uart_req.type = PORT_16650;
8577  
8578 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8579 -        gen550_init(0, &uart_req);
8580 -#endif
8581
8582 +#ifdef CONFIG_SERIAL_8250
8583          if (early_serial_setup(&uart_req) != 0)
8584                  printk("Early serial init of port 0 failed\n");
8585 +#endif
8586 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8587 +       gen550_init(0, &uart_req);
8588 +#endif
8589 +#ifdef CONFIG_KGDB_8250
8590 +       kgdb8250_add_port(0, &uart_req);
8591 +#endif
8592   
8593          /* Assume early_serial_setup() doesn't modify uart_req */
8594         uart_req.line = 1;
8595 @@ -79,14 +82,17 @@ sbc8560_early_serial_map(void)
8596          uart_req.membase = ioremap(uart_req.mapbase, MPC85xx_UART1_SIZE);
8597         uart_req.irq = MPC85xx_IRQ_EXT10;
8598   
8599 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8600 -        gen550_init(1, &uart_req);
8601 -#endif
8602
8603 +#ifdef CONFIG_SERIAL_8250
8604          if (early_serial_setup(&uart_req) != 0)
8605 -                printk("Early serial init of port 1 failed\n");
8606 -}
8607 +               printk("Early serial init of port 0 failed\n");
8608  #endif
8609 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8610 +       gen550_init(0, &uart_req);
8611 +#endif
8612 +#ifdef CONFIG_KGDB_8250
8613 +       kgdb8250_add_port(0, &uart_req);
8614 +#endif
8615 +}
8616  
8617  /* ************************************************************************
8618   *
8619 @@ -115,9 +121,7 @@ sbc8560_setup_arch(void)
8620         /* setup PCI host bridges */
8621         mpc85xx_setup_hose();
8622  #endif
8623 -#ifdef CONFIG_SERIAL_8250
8624         sbc8560_early_serial_map();
8625 -#endif
8626  #ifdef CONFIG_SERIAL_TEXT_DEBUG
8627         /* Invalidate the entry we stole earlier the serial ports
8628          * should be properly mapped */ 
8629 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/platforms/chestnut.c linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/chestnut.c
8630 --- linux-2.6.18-53.1.14/arch/ppc/platforms/chestnut.c  2006-09-20 07:42:06.000000000 +0400
8631 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/chestnut.c     2008-06-10 15:38:14.000000000 +0400
8632 @@ -492,7 +492,7 @@ chestnut_power_off(void)
8633  static void __init
8634  chestnut_map_io(void)
8635  {
8636 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8637 +#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_8250)
8638         io_block_mapping(CHESTNUT_UART_BASE, CHESTNUT_UART_BASE, 0x100000,
8639                 _PAGE_IO);
8640  #endif
8641 @@ -566,9 +566,6 @@ platform_init(unsigned long r3, unsigned
8642  #if defined(CONFIG_SERIAL_TEXT_DEBUG)
8643         ppc_md.progress = gen550_progress;
8644  #endif
8645 -#if defined(CONFIG_KGDB)
8646 -       ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
8647 -#endif
8648  
8649         if (ppc_md.progress)
8650                  ppc_md.progress("chestnut_init(): exit", 0);
8651 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/platforms/pplus.c linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/pplus.c
8652 --- linux-2.6.18-53.1.14/arch/ppc/platforms/pplus.c     2006-09-20 07:42:06.000000000 +0400
8653 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/pplus.c        2008-06-10 15:38:14.000000000 +0400
8654 @@ -893,9 +893,6 @@ platform_init(unsigned long r3, unsigned
8655  #ifdef CONFIG_SERIAL_TEXT_DEBUG
8656         ppc_md.progress = gen550_progress;
8657  #endif                         /* CONFIG_SERIAL_TEXT_DEBUG */
8658 -#ifdef CONFIG_KGDB
8659 -       ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
8660 -#endif
8661  #ifdef CONFIG_SMP
8662         smp_ops = &pplus_smp_ops;
8663  #endif                         /* CONFIG_SMP */
8664 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/platforms/sandpoint.c linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/sandpoint.c
8665 --- linux-2.6.18-53.1.14/arch/ppc/platforms/sandpoint.c 2006-09-20 07:42:06.000000000 +0400
8666 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/sandpoint.c    2008-06-10 15:38:14.000000000 +0400
8667 @@ -730,9 +730,6 @@ platform_init(unsigned long r3, unsigned
8668         ppc_md.nvram_read_val = todc_mc146818_read_val;
8669         ppc_md.nvram_write_val = todc_mc146818_write_val;
8670  
8671 -#ifdef CONFIG_KGDB
8672 -       ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
8673 -#endif
8674  #ifdef CONFIG_SERIAL_TEXT_DEBUG
8675         ppc_md.progress = gen550_progress;
8676  #endif
8677 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/platforms/spruce.c linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/spruce.c
8678 --- linux-2.6.18-53.1.14/arch/ppc/platforms/spruce.c    2006-09-20 07:42:06.000000000 +0400
8679 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/platforms/spruce.c       2008-06-10 15:38:14.000000000 +0400
8680 @@ -178,26 +178,32 @@ spruce_early_serial_map(void)
8681         serial_req.membase = (u_char *)UART0_IO_BASE;
8682         serial_req.regshift = 0;
8683  
8684 -#if defined(CONFIG_KGDB) || defined(CONFIG_SERIAL_TEXT_DEBUG)
8685 -       gen550_init(0, &serial_req);
8686 -#endif
8687  #ifdef CONFIG_SERIAL_8250
8688         if (early_serial_setup(&serial_req) != 0)
8689                 printk("Early serial init of port 0 failed\n");
8690  #endif
8691 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8692 +       gen550_init(0, &serial_req);
8693 +#endif
8694 +#ifdef CONFIG_KGDB_8250
8695 +       kgdb8250_add_port(0, &port);
8696 +#endif
8697  
8698         /* Assume early_serial_setup() doesn't modify serial_req */
8699         serial_req.line = 1;
8700         serial_req.irq = UART1_INT;
8701         serial_req.membase = (u_char *)UART1_IO_BASE;
8702  
8703 -#if defined(CONFIG_KGDB) || defined(CONFIG_SERIAL_TEXT_DEBUG)
8704 -       gen550_init(1, &serial_req);
8705 -#endif
8706  #ifdef CONFIG_SERIAL_8250
8707         if (early_serial_setup(&serial_req) != 0)
8708                 printk("Early serial init of port 1 failed\n");
8709  #endif
8710 +#ifdef CONFIG_SERIAL_TEXT_DEBUG
8711 +       gen550_init(1, &serial_req);
8712 +#endif
8713 +#ifdef CONFIG_KGDB_8250
8714 +       kgdb8250_add_port(1, &serial_req);
8715 +#endif
8716  }
8717  
8718  TODC_ALLOC();
8719 @@ -316,7 +322,4 @@ platform_init(unsigned long r3, unsigned
8720  #ifdef CONFIG_SERIAL_TEXT_DEBUG
8721         ppc_md.progress = gen550_progress;
8722  #endif /* CONFIG_SERIAL_TEXT_DEBUG */
8723 -#ifdef CONFIG_KGDB
8724 -       ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
8725 -#endif
8726  }
8727 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/syslib/Makefile linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/Makefile
8728 --- linux-2.6.18-53.1.14/arch/ppc/syslib/Makefile       2006-09-20 07:42:06.000000000 +0400
8729 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/Makefile  2008-06-10 15:38:14.000000000 +0400
8730 @@ -76,7 +76,6 @@ obj-$(CONFIG_PCI_8260)                += m82xx_pci.o p
8731  obj-$(CONFIG_8260_PCI9)                += m8260_pci_erratum9.o
8732  obj-$(CONFIG_CPM2)             += cpm2_common.o cpm2_pic.o
8733  ifeq ($(CONFIG_PPC_GEN550),y)
8734 -obj-$(CONFIG_KGDB)             += gen550_kgdb.o gen550_dbg.o
8735  obj-$(CONFIG_SERIAL_TEXT_DEBUG)        += gen550_dbg.o
8736  endif
8737  ifeq ($(CONFIG_SERIAL_MPSC_CONSOLE),y)
8738 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/syslib/gen550.h linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/gen550.h
8739 --- linux-2.6.18-53.1.14/arch/ppc/syslib/gen550.h       2006-09-20 07:42:06.000000000 +0400
8740 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/gen550.h  2008-06-10 15:38:14.000000000 +0400
8741 @@ -11,4 +11,3 @@
8742  
8743  extern void gen550_progress(char *, unsigned short);
8744  extern void gen550_init(int, struct uart_port *);
8745 -extern void gen550_kgdb_map_scc(void);
8746 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/syslib/ibm44x_common.c linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/ibm44x_common.c
8747 --- linux-2.6.18-53.1.14/arch/ppc/syslib/ibm44x_common.c        2006-09-20 07:42:06.000000000 +0400
8748 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/ibm44x_common.c   2008-06-10 15:38:14.000000000 +0400
8749 @@ -192,9 +192,6 @@ void __init ibm44x_platform_init(unsigne
8750  #ifdef CONFIG_SERIAL_TEXT_DEBUG
8751         ppc_md.progress = gen550_progress;
8752  #endif /* CONFIG_SERIAL_TEXT_DEBUG */
8753 -#ifdef CONFIG_KGDB
8754 -       ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
8755 -#endif
8756  
8757         /*
8758          * The Abatron BDI JTAG debugger does not tolerate others
8759 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/syslib/mv64x60.c linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/mv64x60.c
8760 --- linux-2.6.18-53.1.14/arch/ppc/syslib/mv64x60.c      2006-09-20 07:42:06.000000000 +0400
8761 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/mv64x60.c 2008-06-10 15:38:14.000000000 +0400
8762 @@ -241,6 +241,12 @@ static struct resource mv64x60_mpsc0_res
8763                 .end    = MV64x60_IRQ_SDMA_0,
8764                 .flags  = IORESOURCE_IRQ,
8765         },
8766 +       [4] = {
8767 +               .name   = "mpsc 0 irq",
8768 +               .start  = MV64x60_IRQ_MPSC_0,
8769 +               .end    = MV64x60_IRQ_MPSC_0,
8770 +               .flags  = IORESOURCE_IRQ,
8771 +       },
8772  };
8773  
8774  static struct platform_device mpsc0_device = {
8775 @@ -298,6 +304,12 @@ static struct resource mv64x60_mpsc1_res
8776                 .end    = MV64360_IRQ_SDMA_1,
8777                 .flags  = IORESOURCE_IRQ,
8778         },
8779 +       [4] = {
8780 +               .name   = "mpsc 1 irq",
8781 +               .start  = MV64360_IRQ_MPSC_1,
8782 +               .end    = MV64360_IRQ_MPSC_1,
8783 +               .flags  = IORESOURCE_IRQ,
8784 +       },
8785  };
8786  
8787  static struct platform_device mpsc1_device = {
8788 @@ -1426,12 +1438,46 @@ mv64x60_pd_fixup(struct mv64x60_handle *
8789  static int __init
8790  mv64x60_add_pds(void)
8791  {
8792 -       return platform_add_devices(mv64x60_pd_devs,
8793 -               ARRAY_SIZE(mv64x60_pd_devs));
8794 +       int i, ret = 0;
8795 +
8796 +       for (i = 0; i < ARRAY_SIZE(mv64x60_pd_devs); i++) {
8797 +               if (mv64x60_pd_devs[i]) {
8798 +                       ret = platform_device_register(mv64x60_pd_devs[i]);
8799 +               }
8800 +               if (ret) {
8801 +                       while (--i >= 0)
8802 +                               platform_device_unregister(mv64x60_pd_devs[i]);
8803 +                       break;
8804 +               }
8805 +       }
8806 +       return ret;
8807  }
8808  arch_initcall(mv64x60_add_pds);
8809  
8810  /*
8811 + * mv64x60_early_get_pdev_data()
8812 + *
8813 + * Get the data associated with a platform device by name and number.
8814 + */
8815 +struct platform_device * __init
8816 +mv64x60_early_get_pdev_data(const char *name, int id, int remove)
8817 +{
8818 +       int i;
8819 +       struct platform_device *pdev;
8820 +
8821 +       for (i = 0; i <ARRAY_SIZE(mv64x60_pd_devs); i++) {
8822 +               if ((pdev = mv64x60_pd_devs[i]) &&
8823 +                       pdev->id == id &&
8824 +                       !strcmp(pdev->name, name)) {
8825 +                       if (remove)
8826 +                               mv64x60_pd_devs[i] = NULL;
8827 +                       return pdev;
8828 +               }
8829 +       }
8830 +       return NULL;
8831 +}
8832 +
8833 +/*
8834   *****************************************************************************
8835   *
8836   *     GT64260-Specific Routines
8837 @@ -1764,6 +1810,11 @@ gt64260a_chip_specific_init(struct mv64x
8838                 r->start = MV64x60_IRQ_SDMA_0;
8839                 r->end = MV64x60_IRQ_SDMA_0;
8840         }
8841 +       if ((r = platform_get_resource(&mpsc1_device, IORESOURCE_IRQ, 1))
8842 +                       != NULL) {
8843 +               r->start = GT64260_IRQ_MPSC_1;
8844 +               r->end = GT64260_IRQ_MPSC_1;
8845 +       }
8846  #endif
8847  }
8848  
8849 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/syslib/mv64x60_dbg.c linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/mv64x60_dbg.c
8850 --- linux-2.6.18-53.1.14/arch/ppc/syslib/mv64x60_dbg.c  2006-09-20 07:42:06.000000000 +0400
8851 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/mv64x60_dbg.c     2008-06-10 15:38:14.000000000 +0400
8852 @@ -34,7 +34,7 @@ static struct mv64x60_handle  mv64x60_dbg
8853  void
8854  mv64x60_progress_init(u32 base)
8855  {
8856 -       mv64x60_dbg_bh.v_base = base;
8857 +       mv64x60_dbg_bh.v_base = (void*)base;
8858         return;
8859  }
8860  
8861 @@ -69,53 +69,3 @@ mv64x60_mpsc_progress(char *s, unsigned 
8862         return;
8863  }
8864  #endif /* CONFIG_SERIAL_TEXT_DEBUG */
8865 -
8866 -
8867 -#if defined(CONFIG_KGDB)
8868 -
8869 -#if defined(CONFIG_KGDB_TTYS0)
8870 -#define KGDB_PORT 0
8871 -#elif defined(CONFIG_KGDB_TTYS1)
8872 -#define KGDB_PORT 1
8873 -#else
8874 -#error "Invalid kgdb_tty port"
8875 -#endif
8876 -
8877 -void
8878 -putDebugChar(unsigned char c)
8879 -{
8880 -       mv64x60_polled_putc(KGDB_PORT, (char)c);
8881 -}
8882 -
8883 -int
8884 -getDebugChar(void)
8885 -{
8886 -       unsigned char   c;
8887 -
8888 -       while (!mv64x60_polled_getc(KGDB_PORT, &c));
8889 -       return (int)c;
8890 -}
8891 -
8892 -void
8893 -putDebugString(char* str)
8894 -{
8895 -       while (*str != '\0') {
8896 -               putDebugChar(*str);
8897 -               str++;
8898 -       }
8899 -       putDebugChar('\r');
8900 -       return;
8901 -}
8902 -
8903 -void
8904 -kgdb_interruptible(int enable)
8905 -{
8906 -}
8907 -
8908 -void
8909 -kgdb_map_scc(void)
8910 -{
8911 -       if (ppc_md.early_serial_map)
8912 -               ppc_md.early_serial_map();
8913 -}
8914 -#endif /* CONFIG_KGDB */
8915 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/ppc/syslib/ppc85xx_setup.c linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/ppc85xx_setup.c
8916 --- linux-2.6.18-53.1.14/arch/ppc/syslib/ppc85xx_setup.c        2006-09-20 07:42:06.000000000 +0400
8917 +++ linux-2.6.18-53.1.14.kgdb/arch/ppc/syslib/ppc85xx_setup.c   2008-06-10 15:38:14.000000000 +0400
8918 @@ -69,7 +69,6 @@ mpc85xx_calibrate_decr(void)
8919         mtspr(SPRN_TCR, TCR_DIE);
8920  }
8921  
8922 -#ifdef CONFIG_SERIAL_8250
8923  void __init
8924  mpc85xx_early_serial_map(void)
8925  {
8926 @@ -85,7 +84,7 @@ mpc85xx_early_serial_map(void)
8927         pdata[0].mapbase += binfo->bi_immr_base;
8928         pdata[0].membase = ioremap(pdata[0].mapbase, MPC85xx_UART0_SIZE);
8929  
8930 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8931 +#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_8250)
8932         memset(&serial_req, 0, sizeof (serial_req));
8933         serial_req.iotype = UPIO_MEM;
8934         serial_req.mapbase = pdata[0].mapbase;
8935 @@ -93,18 +92,24 @@ mpc85xx_early_serial_map(void)
8936         serial_req.regshift = 0;
8937  
8938         gen550_init(0, &serial_req);
8939 +#ifdef CONFIG_KGDB_8250
8940 +       kgdb8250_add_port(0, &serial_req);
8941 +#endif
8942  #endif
8943  
8944         pdata[1].uartclk = binfo->bi_busfreq;
8945         pdata[1].mapbase += binfo->bi_immr_base;
8946         pdata[1].membase = ioremap(pdata[1].mapbase, MPC85xx_UART0_SIZE);
8947  
8948 -#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
8949 +#if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB_8250)
8950         /* Assume gen550_init() doesn't modify serial_req */
8951         serial_req.mapbase = pdata[1].mapbase;
8952         serial_req.membase = pdata[1].membase;
8953  
8954         gen550_init(1, &serial_req);
8955 +#ifdef CONFIG_KGDB_8250
8956 +       kgdb8250_add_port(1, &serial_req);
8957 +#endif
8958  #endif
8959  }
8960  #endif
8961 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/Kconfig.debug linux-2.6.18-53.1.14.kgdb/arch/sh/Kconfig.debug
8962 --- linux-2.6.18-53.1.14/arch/sh/Kconfig.debug  2006-09-20 07:42:06.000000000 +0400
8963 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/Kconfig.debug     2008-06-10 15:38:50.000000000 +0400
8964 @@ -29,96 +29,4 @@ config EARLY_PRINTK
8965           This option is only useful porting the kernel to a new machine,
8966           when the kernel may crash or hang before the serial console is
8967           initialised. If unsure, say N.
8968 -
8969 -config KGDB
8970 -       bool "Include KGDB kernel debugger"
8971 -       help
8972 -         Include in-kernel hooks for kgdb, the Linux kernel source level
8973 -         debugger.  See <http://kgdb.sourceforge.net/> for more information.
8974 -         Unless you are intending to debug the kernel, say N here.
8975 -
8976 -menu "KGDB configuration options"
8977 -       depends on KGDB
8978 -
8979 -config MORE_COMPILE_OPTIONS
8980 -       bool "Add any additional compile options"
8981 -       help
8982 -         If you want to add additional CFLAGS to the kernel build, enable this
8983 -         option and then enter what you would like to add in the next question.
8984 -         Note however that -g is already appended with the selection of KGDB.
8985 -
8986 -config COMPILE_OPTIONS
8987 -       string "Additional compile arguments"
8988 -       depends on MORE_COMPILE_OPTIONS
8989 -
8990 -config KGDB_NMI
8991 -       bool "Enter KGDB on NMI"
8992 -       default n
8993 -
8994 -config KGDB_THREAD
8995 -       bool "Include KGDB thread support"
8996 -       default y
8997 -
8998 -config SH_KGDB_CONSOLE
8999 -       bool "Console messages through GDB"
9000 -       default n
9001 -
9002 -config KGDB_SYSRQ
9003 -       bool "Allow SysRq 'G' to enter KGDB"
9004 -       default y
9005 -
9006 -config KGDB_KERNEL_ASSERTS
9007 -       bool "Include KGDB kernel assertions"
9008 -       default n
9009 -
9010 -comment "Serial port setup"
9011 -
9012 -config KGDB_DEFPORT
9013 -       int "Port number (ttySCn)"
9014 -       default "1"
9015 -
9016 -config KGDB_DEFBAUD
9017 -       int "Baud rate"
9018 -       default "115200"
9019 -
9020 -choice
9021 -       prompt "Parity"
9022 -       depends on KGDB
9023 -       default KGDB_DEFPARITY_N
9024 -
9025 -config KGDB_DEFPARITY_N
9026 -       bool "None"
9027 -
9028 -config KGDB_DEFPARITY_E
9029 -       bool "Even"
9030 -
9031 -config KGDB_DEFPARITY_O
9032 -       bool "Odd"
9033 -
9034 -endchoice
9035 -
9036 -choice
9037 -       prompt "Data bits"
9038 -       depends on KGDB
9039 -       default KGDB_DEFBITS_8
9040 -
9041 -config KGDB_DEFBITS_8
9042 -       bool "8"
9043 -
9044 -config KGDB_DEFBITS_7
9045 -       bool "7"
9046 -
9047 -endchoice
9048 -
9049 -endmenu
9050 -
9051 -config FRAME_POINTER
9052 -       bool "Compile the kernel with frame pointers"
9053 -       default y if KGDB
9054 -       help
9055 -         If you say Y here the resulting kernel image will be slightly larger
9056 -         and slower, but it will give very useful debugging information.
9057 -         If you don't debug the kernel, you can say N, but we may not be able
9058 -         to solve problems without frame pointers.
9059 -
9060  endmenu
9061 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/Makefile linux-2.6.18-53.1.14.kgdb/arch/sh/Makefile
9062 --- linux-2.6.18-53.1.14/arch/sh/Makefile       2006-09-20 07:42:06.000000000 +0400
9063 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/Makefile  2008-06-10 15:38:50.000000000 +0400
9064 @@ -43,7 +43,6 @@ cflags-$(CONFIG_CPU_SH4)              += -m4 \
9065  cflags-$(CONFIG_CPU_SH4A)              += $(call cc-option,-m4a-nofpu,)
9066  
9067  cflags-$(CONFIG_SH_DSP)                        += -Wa,-dsp
9068 -cflags-$(CONFIG_SH_KGDB)               += -g
9069  
9070  cflags-$(CONFIG_MORE_COMPILE_OPTIONS)  += \
9071         $(shell echo $(CONFIG_COMPILE_OPTIONS) | sed -e 's/"//g')
9072 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/boards/se/7751/setup.c linux-2.6.18-53.1.14.kgdb/arch/sh/boards/se/7751/setup.c
9073 --- linux-2.6.18-53.1.14/arch/sh/boards/se/7751/setup.c 2006-09-20 07:42:06.000000000 +0400
9074 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/boards/se/7751/setup.c    2008-06-10 15:38:50.000000000 +0400
9075 @@ -17,10 +17,6 @@
9076  #include <asm/io.h>
9077  #include <asm/se7751/se7751.h>
9078  
9079 -#ifdef CONFIG_SH_KGDB
9080 -#include <asm/kgdb.h>
9081 -#endif
9082 -
9083  /*
9084   * Configure the Super I/O chip
9085   */
9086 @@ -82,12 +78,6 @@ const char *get_system_type(void)
9087         return "7751 SolutionEngine";
9088  }
9089  
9090 -#ifdef CONFIG_SH_KGDB
9091 -static int kgdb_uart_setup(void);
9092 -static struct kgdb_sermap kgdb_uart_sermap = 
9093 -{ "ttyS", 0, kgdb_uart_setup, NULL };
9094 -#endif
9095
9096  /*
9097   * Initialize the board
9098   */
9099 @@ -95,133 +85,4 @@ void __init platform_setup(void)
9100  {
9101         /* Call init_smsc() replacement to set up SuperIO. */
9102         /* XXX: RTC setting comes here */
9103 -#ifdef CONFIG_SH_KGDB
9104 -       kgdb_register_sermap(&kgdb_uart_sermap);
9105 -#endif
9106 -}
9107 -
9108 -/*********************************************************************
9109 - * Currently a hack (e.g. does not interact well w/serial.c, lots of *
9110 - * hardcoded stuff) but may be useful if SCI/F needs debugging.      *
9111 - * Mostly copied from x86 code (see files asm-i386/kgdb_local.h and  *
9112 - * arch/i386/lib/kgdb_serial.c).                                     *
9113 - *********************************************************************/
9114 -
9115 -#ifdef CONFIG_SH_KGDB
9116 -#include <linux/types.h>
9117 -#include <linux/serial.h>
9118 -#include <linux/serialP.h>
9119 -#include <linux/serial_reg.h>
9120 -
9121 -#define COM1_PORT 0x3f8  /* Base I/O address */
9122 -#define COM1_IRQ  4      /* IRQ not used yet */
9123 -#define COM2_PORT 0x2f8  /* Base I/O address */
9124 -#define COM2_IRQ  3      /* IRQ not used yet */
9125 -
9126 -#define SB_CLOCK 1843200 /* Serial baud clock */
9127 -#define SB_BASE (SB_CLOCK/16)
9128 -#define SB_MCR UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS
9129 -
9130 -struct uart_port {
9131 -       int base;
9132 -};
9133 -#define UART_NPORTS 2
9134 -struct uart_port uart_ports[] = {
9135 -       { COM1_PORT },
9136 -       { COM2_PORT },
9137 -};
9138 -struct uart_port *kgdb_uart_port;
9139 -
9140 -#define UART_IN(reg)   inb_p(kgdb_uart_port->base + reg)
9141 -#define UART_OUT(reg,v)        outb_p((v), kgdb_uart_port->base + reg)
9142 -
9143 -/* Basic read/write functions for the UART */
9144 -#define UART_LSR_RXCERR    (UART_LSR_BI | UART_LSR_FE | UART_LSR_PE)
9145 -static int kgdb_uart_getchar(void)
9146 -{
9147 -       int lsr;
9148 -       int c = -1;
9149 -
9150 -       while (c == -1) {
9151 -               lsr = UART_IN(UART_LSR);
9152 -               if (lsr & UART_LSR_DR) 
9153 -                       c = UART_IN(UART_RX);
9154 -               if ((lsr & UART_LSR_RXCERR))
9155 -                       c = -1;
9156 -       }
9157 -       return c;
9158 -}
9159 -
9160 -static void kgdb_uart_putchar(int c)
9161 -{
9162 -       while ((UART_IN(UART_LSR) & UART_LSR_THRE) == 0)
9163 -               ;
9164 -       UART_OUT(UART_TX, c);
9165 -}
9166 -
9167 -/*
9168 - * Initialize UART to configured/requested values.
9169 - * (But we don't interrupts yet, or interact w/serial.c)
9170 - */
9171 -static int kgdb_uart_setup(void)
9172 -{
9173 -       int port;
9174 -       int lcr = 0;
9175 -       int bdiv = 0;
9176 -
9177 -       if (kgdb_portnum >= UART_NPORTS) {
9178 -               KGDB_PRINTK("uart port %d invalid.\n", kgdb_portnum);
9179 -               return -1;
9180 -       }
9181 -
9182 -       kgdb_uart_port = &uart_ports[kgdb_portnum];
9183 -
9184 -       /* Init sequence from gdb_hook_interrupt */
9185 -       UART_IN(UART_RX);
9186 -       UART_OUT(UART_IER, 0);
9187 -
9188 -       UART_IN(UART_RX);       /* Serial driver comments say */
9189 -       UART_IN(UART_IIR);      /* this clears interrupt regs */
9190 -       UART_IN(UART_MSR);
9191 -
9192 -       /* Figure basic LCR values */
9193 -       switch (kgdb_bits) {
9194 -       case '7':
9195 -               lcr |= UART_LCR_WLEN7;
9196 -               break;
9197 -       default: case '8': 
9198 -               lcr |= UART_LCR_WLEN8;
9199 -               break;
9200 -       }
9201 -       switch (kgdb_parity) {
9202 -       case 'O':
9203 -               lcr |= UART_LCR_PARITY;
9204 -               break;
9205 -       case 'E':
9206 -               lcr |= (UART_LCR_PARITY | UART_LCR_EPAR);
9207 -               break;
9208 -       default: break;
9209 -       }
9210 -
9211 -       /* Figure the baud rate divisor */
9212 -       bdiv = (SB_BASE/kgdb_baud);
9213 -       
9214 -       /* Set the baud rate and LCR values */
9215 -       UART_OUT(UART_LCR, (lcr | UART_LCR_DLAB));
9216 -       UART_OUT(UART_DLL, (bdiv & 0xff));
9217 -       UART_OUT(UART_DLM, ((bdiv >> 8) & 0xff));
9218 -       UART_OUT(UART_LCR, lcr);
9219 -
9220 -       /* Set the MCR */
9221 -       UART_OUT(UART_MCR, SB_MCR);
9222 -
9223 -       /* Turn off FIFOs for now */
9224 -       UART_OUT(UART_FCR, 0);
9225 -
9226 -       /* Setup complete: initialize function pointers */
9227 -       kgdb_getchar = kgdb_uart_getchar;
9228 -       kgdb_putchar = kgdb_uart_putchar;
9229 -
9230 -       return 0;
9231  }
9232 -#endif /* CONFIG_SH_KGDB */
9233 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/Makefile linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/Makefile
9234 --- linux-2.6.18-53.1.14/arch/sh/kernel/Makefile        2006-09-20 07:42:06.000000000 +0400
9235 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/Makefile   2008-06-10 15:38:50.000000000 +0400
9236 @@ -13,7 +13,7 @@ obj-y                         += cpu/ timers/
9237  obj-$(CONFIG_SMP)              += smp.o
9238  obj-$(CONFIG_CF_ENABLER)       += cf-enabler.o
9239  obj-$(CONFIG_SH_STANDARD_BIOS) += sh_bios.o
9240 -obj-$(CONFIG_SH_KGDB)          += kgdb_stub.o kgdb_jmp.o
9241 +obj-$(CONFIG_KGDB)             += kgdb.o kgdb-jmp.o
9242  obj-$(CONFIG_SH_CPU_FREQ)      += cpufreq.o
9243  obj-$(CONFIG_MODULES)          += module.o
9244  obj-$(CONFIG_EARLY_PRINTK)     += early_printk.o
9245 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/cpu/sh3/ex.S linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/cpu/sh3/ex.S
9246 --- linux-2.6.18-53.1.14/arch/sh/kernel/cpu/sh3/ex.S    2006-09-20 07:42:06.000000000 +0400
9247 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/cpu/sh3/ex.S       2008-06-10 15:38:50.000000000 +0400
9248 @@ -42,7 +42,7 @@ ENTRY(exception_handling_table)
9249         .long   exception_error ! reserved_instruction (filled by trap_init) /* 180 */
9250         .long   exception_error ! illegal_slot_instruction (filled by trap_init) /*1A0*/
9251  ENTRY(nmi_slot)
9252 -#if defined (CONFIG_KGDB_NMI)
9253 +#if defined (CONFIG_KGDB)
9254         .long   debug_enter     /* 1C0 */       ! Allow trap to debugger
9255  #else
9256         .long   exception_none  /* 1C0 */       ! Not implemented yet
9257 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/cpu/sh4/ex.S linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/cpu/sh4/ex.S
9258 --- linux-2.6.18-53.1.14/arch/sh/kernel/cpu/sh4/ex.S    2006-09-20 07:42:06.000000000 +0400
9259 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/cpu/sh4/ex.S       2008-06-10 15:38:50.000000000 +0400
9260 @@ -46,7 +46,7 @@ ENTRY(exception_handling_table)
9261         .long   exception_error ! reserved_instruction (filled by trap_init) /* 180 */
9262         .long   exception_error ! illegal_slot_instruction (filled by trap_init) /*1A0*/
9263  ENTRY(nmi_slot)
9264 -#if defined (CONFIG_KGDB_NMI)
9265 +#if defined (CONFIG_KGDB)
9266         .long   debug_enter     /* 1C0 */       ! Allow trap to debugger
9267  #else
9268         .long   exception_none  /* 1C0 */       ! Not implemented yet
9269 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/entry.S linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/entry.S
9270 --- linux-2.6.18-53.1.14/arch/sh/kernel/entry.S 2006-09-20 07:42:06.000000000 +0400
9271 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/entry.S    2008-06-10 15:38:50.000000000 +0400
9272 @@ -75,7 +75,7 @@
9273  ENOSYS = 38
9274  EINVAL = 22
9275  
9276 -#if defined(CONFIG_KGDB_NMI)
9277 +#if defined(CONFIG_KGDB)
9278  NMI_VEC = 0x1c0                        ! Must catch early for debounce
9279  #endif
9280  
9281 @@ -227,31 +227,33 @@ call_dae:
9282  2:     .long   do_address_error
9283  #endif /* CONFIG_MMU */
9284  
9285 -#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
9286 +#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_KGDB)
9287  ! Handle kernel debug if either kgdb (SW) or gdb-stub (FW) is present.
9288  ! If both are configured, handle the debug traps (breakpoints) in SW,
9289  ! but still allow BIOS traps to FW.
9290  
9291         .align  2
9292  debug_kernel:
9293 -#if defined(CONFIG_SH_STANDARD_BIOS) && defined(CONFIG_SH_KGDB)
9294 +#if defined(CONFIG_SH_STANDARD_BIOS) && defined(CONFIG_KGDB)
9295         /* Force BIOS call to FW (debug_trap put TRA in r8) */
9296         mov     r8,r0
9297         shlr2   r0
9298         cmp/eq  #0x3f,r0
9299         bt      debug_kernel_fw
9300 -#endif /* CONFIG_SH_STANDARD_BIOS && CONFIG_SH_KGDB */
9301 +#endif /* CONFIG_SH_STANDARD_BIOS && CONFIG_KGDB */
9302  
9303 +       .align 2
9304 +       .globl debug_enter
9305  debug_enter:           
9306 -#if defined(CONFIG_SH_KGDB)
9307 +#if defined(CONFIG_KGDB)
9308         /* Jump to kgdb, pass stacked regs as arg */
9309  debug_kernel_sw:
9310         mov.l   3f, r0
9311         jmp     @r0
9312          mov    r15, r4
9313         .align  2
9314 -3:     .long   kgdb_handle_exception
9315 -#endif /* CONFIG_SH_KGDB */
9316 +3:     .long   kgdb_exception_handler
9317 +#endif /* CONFIG_KGDB */
9318  
9319  #if defined(CONFIG_SH_STANDARD_BIOS)
9320         /* Unwind the stack and jmp to the debug entry */
9321 @@ -293,12 +295,12 @@ debug_kernel_fw:
9322  2:     .long   gdb_vbr_vector
9323  #endif /* CONFIG_SH_STANDARD_BIOS */
9324  
9325 -#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
9326 +#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_KGDB */
9327  
9328  
9329         .align  2
9330  debug_trap:    
9331 -#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
9332 +#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_KGDB)
9333         mov     #OFF_SR, r0
9334         mov.l   @(r0,r15), r0           ! get status register
9335         shll    r0
9336 @@ -642,7 +644,7 @@ skip_restore:
9337  6:     or      k0, k2                  ! Set the IMASK-bits
9338         ldc     k2, ssr
9339         !
9340 -#if defined(CONFIG_KGDB_NMI)
9341 +#if defined(CONFIG_KGDB)
9342         ! Clear in_nmi
9343         mov.l   4f, k0
9344         mov     #0, k1
9345 @@ -694,7 +696,7 @@ tlb_miss:
9346  interrupt:
9347         mov.l   2f, k2
9348         mov.l   3f, k3
9349 -#if defined(CONFIG_KGDB_NMI)
9350 +#if defined(CONFIG_KGDB)
9351         ! Debounce (filter nested NMI)
9352         mov.l   @k2, k0
9353         mov.l   5f, k1
9354 @@ -709,7 +711,7 @@ interrupt:
9355  5:     .long   NMI_VEC
9356  6:     .long   in_nmi
9357  0:
9358 -#endif /* defined(CONFIG_KGDB_NMI) */
9359 +#endif /* defined(CONFIG_KGDB) */
9360         bra     handle_exception
9361          mov.l  @k2, k2
9362  
9363 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/kgdb-jmp.S linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/kgdb-jmp.S
9364 --- linux-2.6.18-53.1.14/arch/sh/kernel/kgdb-jmp.S      1970-01-01 03:00:00.000000000 +0300
9365 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/kgdb-jmp.S 2008-06-10 15:38:50.000000000 +0400
9366 @@ -0,0 +1,32 @@
9367 +#include <linux/linkage.h>
9368 +
9369 +ENTRY(kgdb_fault_setjmp)
9370 +       add     #(9*4), r4
9371 +       sts.l   pr, @-r4
9372 +       mov.l   r15, @-r4
9373 +       mov.l   r14, @-r4
9374 +       mov.l   r13, @-r4
9375 +       mov.l   r12, @-r4
9376 +       mov.l   r11, @-r4
9377 +       mov.l   r10, @-r4
9378 +       mov.l   r9, @-r4
9379 +       mov.l   r8, @-r4
9380 +       rts
9381 +        mov    #0, r0
9382 +
9383 +ENTRY(kgdb_fault_longjmp)
9384 +       mov.l   @r4+, r8
9385 +       mov.l   @r4+, r9
9386 +       mov.l   @r4+, r10
9387 +       mov.l   @r4+, r11
9388 +       mov.l   @r4+, r12
9389 +       mov.l   @r4+, r13
9390 +       mov.l   @r4+, r14
9391 +       mov.l   @r4+, r15
9392 +       lds.l   @r4+, pr
9393 +       mov     r5, r0
9394 +       tst     r0, r0
9395 +       bf      1f
9396 +       mov     #1, r0
9397 +1:     rts
9398 +        nop
9399 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/kgdb.c linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/kgdb.c
9400 --- linux-2.6.18-53.1.14/arch/sh/kernel/kgdb.c  1970-01-01 03:00:00.000000000 +0300
9401 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/kgdb.c     2008-06-10 15:38:50.000000000 +0400
9402 @@ -0,0 +1,363 @@
9403 +/*
9404 + * arch/sh/kernel/kgdb.c
9405 + *
9406 + * Contains SH-specific low-level support for KGDB.
9407 + *
9408 + * Containes extracts from code by Glenn Engel, Jim Kingdon,
9409 + * David Grothe <dave@gcom.com>, Tigran Aivazian <tigran@sco.com>,
9410 + * Amit S. Kale <akale@veritas.com>,  William Gatliff <bgat@open-widgets.com>,
9411 + * Ben Lee, Steve Chamberlain and Benoit Miller <fulg@iname.com>,
9412 + * Henry Bell <henry.bell@st.com> and Jeremy Siegel <jsiegel@mvista.com>
9413 + *
9414 + * Maintainer: Tom Rini <trini@kernel.crashing.org>
9415 + *
9416 + * 2004 (c) MontaVista Software, Inc. This file is licensed under
9417 + * the terms of the GNU General Public License version 2. This program
9418 + * is licensed "as is" without any warranty of any kind, whether express
9419 + * or implied.
9420 + */
9421 +
9422 +#include <linux/string.h>
9423 +#include <linux/kernel.h>
9424 +#include <linux/sched.h>
9425 +#include <linux/smp.h>
9426 +#include <linux/spinlock.h>
9427 +#include <linux/delay.h>
9428 +#include <linux/linkage.h>
9429 +#include <linux/init.h>
9430 +#include <linux/kgdb.h>
9431 +
9432 +#include <asm/system.h>
9433 +#include <asm/current.h>
9434 +#include <asm/signal.h>
9435 +#include <asm/pgtable.h>
9436 +#include <asm/ptrace.h>
9437 +
9438 +extern void per_cpu_trap_init(void);
9439 +extern atomic_t cpu_doing_single_step;
9440 +
9441 +/* Function pointers for linkage */
9442 +static struct kgdb_regs trap_registers;
9443 +
9444 +/* Globals. */
9445 +char in_nmi;                   /* Set during NMI to prevent reentry */
9446 +
9447 +/* TRA differs sh3/4 */
9448 +#if defined(CONFIG_CPU_SH3)
9449 +#define TRA 0xffffffd0
9450 +#elif defined(CONFIG_CPU_SH4)
9451 +#define TRA 0xff000020
9452 +#endif
9453 +
9454 +/* Macros for single step instruction identification */
9455 +#define OPCODE_BT(op)         (((op) & 0xff00) == 0x8900)
9456 +#define OPCODE_BF(op)         (((op) & 0xff00) == 0x8b00)
9457 +#define OPCODE_BTF_DISP(op)   (((op) & 0x80) ? (((op) | 0xffffff80) << 1) : \
9458 +                             (((op) & 0x7f ) << 1))
9459 +#define OPCODE_BFS(op)        (((op) & 0xff00) == 0x8f00)
9460 +#define OPCODE_BTS(op)        (((op) & 0xff00) == 0x8d00)
9461 +#define OPCODE_BRA(op)        (((op) & 0xf000) == 0xa000)
9462 +#define OPCODE_BRA_DISP(op)   (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \
9463 +                             (((op) & 0x7ff) << 1))
9464 +#define OPCODE_BRAF(op)       (((op) & 0xf0ff) == 0x0023)
9465 +#define OPCODE_BRAF_REG(op)   (((op) & 0x0f00) >> 8)
9466 +#define OPCODE_BSR(op)        (((op) & 0xf000) == 0xb000)
9467 +#define OPCODE_BSR_DISP(op)   (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \
9468 +                             (((op) & 0x7ff) << 1))
9469 +#define OPCODE_BSRF(op)       (((op) & 0xf0ff) == 0x0003)
9470 +#define OPCODE_BSRF_REG(op)   (((op) >> 8) & 0xf)
9471 +#define OPCODE_JMP(op)        (((op) & 0xf0ff) == 0x402b)
9472 +#define OPCODE_JMP_REG(op)    (((op) >> 8) & 0xf)
9473 +#define OPCODE_JSR(op)        (((op) & 0xf0ff) == 0x400b)
9474 +#define OPCODE_JSR_REG(op)    (((op) >> 8) & 0xf)
9475 +#define OPCODE_RTS(op)        ((op) == 0xb)
9476 +#define OPCODE_RTE(op)        ((op) == 0x2b)
9477 +
9478 +#define SR_T_BIT_MASK           0x1
9479 +#define STEP_OPCODE             0xc320
9480 +#define BIOS_CALL_TRAP          0x3f
9481 +
9482 +/* Exception codes as per SH-4 core manual */
9483 +#define ADDRESS_ERROR_LOAD_VEC   7
9484 +#define ADDRESS_ERROR_STORE_VEC  8
9485 +#define TRAP_VEC                 11
9486 +#define INVALID_INSN_VEC         12
9487 +#define INVALID_SLOT_VEC         13
9488 +#define NMI_VEC                  14
9489 +#define SERIAL_BREAK_VEC         58
9490 +
9491 +/* Misc static */
9492 +static int stepped_address;
9493 +static short stepped_opcode;
9494 +
9495 +/* Translate SH-3/4 exception numbers to unix-like signal values */
9496 +static int compute_signal(const int excep_code)
9497 +{
9498 +       switch (excep_code) {
9499 +       case INVALID_INSN_VEC:
9500 +       case INVALID_SLOT_VEC:
9501 +               return SIGILL;
9502 +       case ADDRESS_ERROR_LOAD_VEC:
9503 +       case ADDRESS_ERROR_STORE_VEC:
9504 +               return SIGSEGV;
9505 +       case SERIAL_BREAK_VEC:
9506 +       case NMI_VEC:
9507 +               return SIGINT;
9508 +       default:
9509 +               /* Act like it was a break/trap. */
9510 +               return SIGTRAP;
9511 +       }
9512 +}
9513 +
9514 +/*
9515 + * Translate the registers of the system into the format that GDB wants.  Since
9516 + * we use a local structure to store things, instead of getting them out
9517 + * of pt_regs, we can just do a memcpy.
9518 + */
9519 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *ign)
9520 +{
9521 +       memcpy(gdb_regs, &trap_registers, sizeof(trap_registers));
9522 +}
9523 +
9524 +/*
9525 + * On SH we save: r1 (prev->thread.sp) r2 (prev->thread.pc) r4 (prev) r5 (next)
9526 + * r6 (next->thread.sp) r7 (next->thread.pc)
9527 + */
9528 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
9529 +{
9530 +       int count;
9531 +
9532 +       for (count = 0; count < 16; count++)
9533 +               *(gdb_regs++) = 0;
9534 +       *(gdb_regs++) = p->thread.pc;
9535 +       *(gdb_regs++) = 0;
9536 +       *(gdb_regs++) = 0;
9537 +       *(gdb_regs++) = 0;
9538 +       *(gdb_regs++) = 0;
9539 +       *(gdb_regs++) = 0;
9540 +       *(gdb_regs++) = 0;
9541 +}
9542 +
9543 +/*
9544 + * Translate the registers values that GDB has given us back into the
9545 + * format of the system.  See the comment above about memcpy.
9546 + */
9547 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *ign)
9548 +{
9549 +       memcpy(&trap_registers, gdb_regs, sizeof(trap_registers));
9550 +}
9551 +
9552 +/* Calculate the new address for after a step */
9553 +static short *get_step_address(void)
9554 +{
9555 +       short op = *(short *)trap_registers.pc;
9556 +       long addr;
9557 +
9558 +       /* BT */
9559 +       if (OPCODE_BT(op)) {
9560 +               if (trap_registers.sr & SR_T_BIT_MASK)
9561 +                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
9562 +               else
9563 +                       addr = trap_registers.pc + 2;
9564 +       }
9565 +
9566 +       /* BTS */
9567 +       else if (OPCODE_BTS(op)) {
9568 +               if (trap_registers.sr & SR_T_BIT_MASK)
9569 +                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
9570 +               else
9571 +                       addr = trap_registers.pc + 4;   /* Not in delay slot */
9572 +       }
9573 +
9574 +       /* BF */
9575 +       else if (OPCODE_BF(op)) {
9576 +               if (!(trap_registers.sr & SR_T_BIT_MASK))
9577 +                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
9578 +               else
9579 +                       addr = trap_registers.pc + 2;
9580 +       }
9581 +
9582 +       /* BFS */
9583 +       else if (OPCODE_BFS(op)) {
9584 +               if (!(trap_registers.sr & SR_T_BIT_MASK))
9585 +                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
9586 +               else
9587 +                       addr = trap_registers.pc + 4;   /* Not in delay slot */
9588 +       }
9589 +
9590 +       /* BRA */
9591 +       else if (OPCODE_BRA(op))
9592 +               addr = trap_registers.pc + 4 + OPCODE_BRA_DISP(op);
9593 +
9594 +       /* BRAF */
9595 +       else if (OPCODE_BRAF(op))
9596 +               addr = trap_registers.pc + 4
9597 +                   + trap_registers.regs[OPCODE_BRAF_REG(op)];
9598 +
9599 +       /* BSR */
9600 +       else if (OPCODE_BSR(op))
9601 +               addr = trap_registers.pc + 4 + OPCODE_BSR_DISP(op);
9602 +
9603 +       /* BSRF */
9604 +       else if (OPCODE_BSRF(op))
9605 +               addr = trap_registers.pc + 4
9606 +                   + trap_registers.regs[OPCODE_BSRF_REG(op)];
9607 +
9608 +       /* JMP */
9609 +       else if (OPCODE_JMP(op))
9610 +               addr = trap_registers.regs[OPCODE_JMP_REG(op)];
9611 +
9612 +       /* JSR */
9613 +       else if (OPCODE_JSR(op))
9614 +               addr = trap_registers.regs[OPCODE_JSR_REG(op)];
9615 +
9616 +       /* RTS */
9617 +       else if (OPCODE_RTS(op))
9618 +               addr = trap_registers.pr;
9619 +
9620 +       /* RTE */
9621 +       else if (OPCODE_RTE(op))
9622 +               addr = trap_registers.regs[15];
9623 +
9624 +       /* Other */
9625 +       else
9626 +               addr = trap_registers.pc + 2;
9627 +
9628 +       kgdb_flush_icache_range(addr, addr + 2);
9629 +       return (short *)addr;
9630 +}
9631 +
9632 +/* The command loop, read and act on requests */
9633 +int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
9634 +                              char *remcom_in_buffer, char *remcom_out_buffer,
9635 +                              struct pt_regs *ign)
9636 +{
9637 +       unsigned long addr;
9638 +       char *ptr = &remcom_in_buffer[1];
9639 +
9640 +       /* Examine first char of buffer to see what we need to do */
9641 +       switch (remcom_in_buffer[0]) {
9642 +       case 'c':               /* Continue at address AA..AA (optional) */
9643 +       case 's':               /* Step one instruction from AA..AA */
9644 +               /* Try to read optional parameter, PC unchanged if none */
9645 +               if (kgdb_hex2long(&ptr, &addr))
9646 +                       trap_registers.pc = addr;
9647 +
9648 +               atomic_set(&cpu_doing_single_step, -1);
9649 +               if (remcom_in_buffer[0] == 's') {
9650 +                       /* Replace the instruction immediately after the
9651 +                        * current instruction (i.e. next in the expected
9652 +                        * flow of control) with a trap instruction, so that
9653 +                        * returning will cause only a single instruction to
9654 +                        * be executed. Note that this model is slightly
9655 +                        * broken for instructions with delay slots
9656 +                        * (e.g. B[TF]S, BSR, BRA etc), where both the branch
9657 +                        * and the instruction in the delay slot will be
9658 +                        * executed.
9659 +                        */
9660 +                       /* Determine where the target instruction will send
9661 +                        * us to */
9662 +                       unsigned short *next_addr = get_step_address();
9663 +                       stepped_address = (int)next_addr;
9664 +
9665 +                       /* Replace it */
9666 +                       stepped_opcode = *(short *)next_addr;
9667 +                       *next_addr = STEP_OPCODE;
9668 +
9669 +                       /* Flush and return */
9670 +                       kgdb_flush_icache_range((long)next_addr,
9671 +                                               (long)next_addr + 2);
9672 +                       if (kgdb_contthread)
9673 +                               atomic_set(&cpu_doing_single_step,
9674 +                                          smp_processor_id());
9675 +               }
9676 +               return 0;
9677 +       }
9678 +       return -1;
9679 +}
9680 +
9681 +/*
9682 + * When an exception has occured, we are called.  We need to set things
9683 + * up so that we can call kgdb_handle_exception to handle requests from
9684 + * the remote GDB.
9685 + */
9686 +void kgdb_exception_handler(struct pt_regs *regs)
9687 +{
9688 +       int excep_code, vbr_val;
9689 +       int count;
9690 +
9691 +       /* Copy kernel regs (from stack) */
9692 +       for (count = 0; count < 16; count++)
9693 +               trap_registers.regs[count] = regs->regs[count];
9694 +       trap_registers.pc = regs->pc;
9695 +       trap_registers.pr = regs->pr;
9696 +       trap_registers.sr = regs->sr;
9697 +       trap_registers.gbr = regs->gbr;
9698 +       trap_registers.mach = regs->mach;
9699 +       trap_registers.macl = regs->macl;
9700 +
9701 +       __asm__ __volatile__("stc vbr, %0":"=r"(vbr_val));
9702 +       trap_registers.vbr = vbr_val;
9703 +
9704 +       /* Get the execption code. */
9705 +       __asm__ __volatile__("stc r2_bank, %0":"=r"(excep_code));
9706 +
9707 +       excep_code >>= 5;
9708 +
9709 +       /* If we got an NMI, and KGDB is not yet initialized, call
9710 +        * breakpoint() to try and initialize everything for us. */
9711 +       if (excep_code == NMI_VEC && !kgdb_initialized) {
9712 +               breakpoint();
9713 +               return;
9714 +       }
9715 +
9716 +       /* TRAP_VEC exception indicates a software trap inserted in place of
9717 +        * code by GDB so back up PC by one instruction, as this instruction
9718 +        * will later be replaced by its original one.  Do NOT do this for
9719 +        * trap 0xff, since that indicates a compiled-in breakpoint which
9720 +        * will not be replaced (and we would retake the trap forever) */
9721 +       if (excep_code == TRAP_VEC &&
9722 +           (*(volatile unsigned long *)TRA != (0xff << 2)))
9723 +               trap_registers.pc -= 2;
9724 +
9725 +       /* If we have been single-stepping, put back the old instruction.
9726 +        * We use stepped_address in case we have stopped more than one
9727 +        * instruction away. */
9728 +       if (stepped_opcode != 0) {
9729 +               *(short *)stepped_address = stepped_opcode;
9730 +               kgdb_flush_icache_range(stepped_address, stepped_address + 2);
9731 +       }
9732 +       stepped_opcode = 0;
9733 +
9734 +       /* Call the stub to do the processing.  Note that not everything we
9735 +        * need to send back and forth lives in pt_regs. */
9736 +       kgdb_handle_exception(excep_code, compute_signal(excep_code), 0, regs);
9737 +
9738 +       /* Copy back the (maybe modified) registers */
9739 +       for (count = 0; count < 16; count++)
9740 +               regs->regs[count] = trap_registers.regs[count];
9741 +       regs->pc = trap_registers.pc;
9742 +       regs->pr = trap_registers.pr;
9743 +       regs->sr = trap_registers.sr;
9744 +       regs->gbr = trap_registers.gbr;
9745 +       regs->mach = trap_registers.mach;
9746 +       regs->macl = trap_registers.macl;
9747 +
9748 +       vbr_val = trap_registers.vbr;
9749 +       __asm__ __volatile__("ldc %0, vbr": :"r"(vbr_val));
9750 +}
9751 +
9752 +int __init kgdb_arch_init(void)
9753 +{
9754 +       per_cpu_trap_init();
9755 +
9756 +       return 0;
9757 +}
9758 +
9759 +struct kgdb_arch arch_kgdb_ops = {
9760 +#ifdef CONFIG_CPU_LITTLE_ENDIAN
9761 +       .gdb_bpt_instr = {0xff, 0xc3},
9762 +#else
9763 +       .gdb_bpt_instr = {0xc3, 0xff},
9764 +#endif
9765 +};
9766 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/kgdb_jmp.S linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/kgdb_jmp.S
9767 --- linux-2.6.18-53.1.14/arch/sh/kernel/kgdb_jmp.S      2006-09-20 07:42:06.000000000 +0400
9768 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/kgdb_jmp.S 1970-01-01 03:00:00.000000000 +0300
9769 @@ -1,33 +0,0 @@
9770 -#include <linux/linkage.h>
9771 -
9772 -ENTRY(setjmp)
9773 -       add     #(9*4), r4
9774 -       sts.l   pr, @-r4
9775 -       mov.l   r15, @-r4
9776 -       mov.l   r14, @-r4
9777 -       mov.l   r13, @-r4
9778 -       mov.l   r12, @-r4
9779 -       mov.l   r11, @-r4
9780 -       mov.l   r10, @-r4
9781 -       mov.l   r9, @-r4
9782 -       mov.l   r8, @-r4
9783 -       rts
9784 -        mov    #0, r0
9785 -
9786 -ENTRY(longjmp)
9787 -       mov.l   @r4+, r8
9788 -       mov.l   @r4+, r9
9789 -       mov.l   @r4+, r10
9790 -       mov.l   @r4+, r11
9791 -       mov.l   @r4+, r12
9792 -       mov.l   @r4+, r13
9793 -       mov.l   @r4+, r14
9794 -       mov.l   @r4+, r15
9795 -       lds.l   @r4+, pr
9796 -       mov     r5, r0
9797 -       tst     r0, r0
9798 -       bf      1f
9799 -       mov     #1, r0  ! in case val==0
9800 -1:     rts
9801 -        nop
9802 -
9803 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/kgdb_stub.c linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/kgdb_stub.c
9804 --- linux-2.6.18-53.1.14/arch/sh/kernel/kgdb_stub.c     2006-09-20 07:42:06.000000000 +0400
9805 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/kgdb_stub.c        1970-01-01 03:00:00.000000000 +0300
9806 @@ -1,1491 +0,0 @@
9807 -/*
9808 - * May be copied or modified under the terms of the GNU General Public
9809 - * License.  See linux/COPYING for more information.
9810 - *
9811 - * Containes extracts from code by Glenn Engel, Jim Kingdon,
9812 - * David Grothe <dave@gcom.com>, Tigran Aivazian <tigran@sco.com>,
9813 - * Amit S. Kale <akale@veritas.com>,  William Gatliff <bgat@open-widgets.com>,
9814 - * Ben Lee, Steve Chamberlain and Benoit Miller <fulg@iname.com>.
9815 - * 
9816 - * This version by Henry Bell <henry.bell@st.com>
9817 - * Minor modifications by Jeremy Siegel <jsiegel@mvista.com>
9818 - * 
9819 - * Contains low-level support for remote debug using GDB. 
9820 - *
9821 - * To enable debugger support, two things need to happen. A call to
9822 - * set_debug_traps() is necessary in order to allow any breakpoints
9823 - * or error conditions to be properly intercepted and reported to gdb.
9824 - * A breakpoint also needs to be generated to begin communication.  This
9825 - * is most easily accomplished by a call to breakpoint() which does
9826 - * a trapa if the initialisation phase has been successfully completed.
9827 - *
9828 - * In this case, set_debug_traps() is not used to "take over" exceptions;
9829 - * other kernel code is modified instead to enter the kgdb functions here
9830 - * when appropriate (see entry.S for breakpoint traps and NMI interrupts,
9831 - * see traps.c for kernel error exceptions).
9832 - *
9833 - * The following gdb commands are supported:
9834 - *
9835 - *    Command       Function                               Return value
9836 - *
9837 - *    g             return the value of the CPU registers  hex data or ENN
9838 - *    G             set the value of the CPU registers     OK or ENN
9839 - *
9840 - *    mAA..AA,LLLL  Read LLLL bytes at address AA..AA      hex data or ENN
9841 - *    MAA..AA,LLLL: Write LLLL bytes at address AA.AA      OK or ENN
9842 - *    XAA..AA,LLLL: Same, but data is binary (not hex)     OK or ENN
9843 - *
9844 - *    c             Resume at current address              SNN   ( signal NN)
9845 - *    cAA..AA       Continue at address AA..AA             SNN
9846 - *    CNN;          Resume at current address with signal  SNN
9847 - *    CNN;AA..AA    Resume at address AA..AA with signal   SNN
9848 - *
9849 - *    s             Step one instruction                   SNN
9850 - *    sAA..AA       Step one instruction from AA..AA       SNN
9851 - *    SNN;          Step one instruction with signal       SNN
9852 - *    SNNAA..AA     Step one instruction from AA..AA w/NN  SNN
9853 - *
9854 - *    k             kill (Detach GDB)
9855 - *
9856 - *    d             Toggle debug flag
9857 - *    D             Detach GDB 
9858 - *
9859 - *    Hct           Set thread t for operations,           OK or ENN
9860 - *                  c = 'c' (step, cont), c = 'g' (other
9861 - *                  operations)
9862 - *
9863 - *    qC            Query current thread ID                QCpid
9864 - *    qfThreadInfo  Get list of current threads (first)    m<id>
9865 - *    qsThreadInfo   "    "  "     "      "   (subsequent)
9866 - *    qOffsets      Get section offsets                  Text=x;Data=y;Bss=z
9867 - * 
9868 - *    TXX           Find if thread XX is alive             OK or ENN
9869 - *    ?             What was the last sigval ?             SNN   (signal NN)
9870 - *    O             Output to GDB console
9871 - *
9872 - * Remote communication protocol.
9873 - *
9874 - *    A debug packet whose contents are <data> is encapsulated for
9875 - *    transmission in the form:
9876 - *
9877 - *       $ <data> # CSUM1 CSUM2
9878 - *
9879 - *       <data> must be ASCII alphanumeric and cannot include characters
9880 - *       '$' or '#'.  If <data> starts with two characters followed by
9881 - *       ':', then the existing stubs interpret this as a sequence number.
9882 - *
9883 - *       CSUM1 and CSUM2 are ascii hex representation of an 8-bit 
9884 - *       checksum of <data>, the most significant nibble is sent first.
9885 - *       the hex digits 0-9,a-f are used.
9886 - *
9887 - *    Receiver responds with:
9888 - *
9889 - *       +       - if CSUM is correct and ready for next packet
9890 - *       -       - if CSUM is incorrect
9891 - *
9892 - * Responses can be run-length encoded to save space.  A '*' means that
9893 - * the next character is an ASCII encoding giving a repeat count which
9894 - * stands for that many repititions of the character preceding the '*'.
9895 - * The encoding is n+29, yielding a printable character where n >=3 
9896 - * (which is where RLE starts to win).  Don't use an n > 126. 
9897 - *
9898 - * So "0* " means the same as "0000".
9899 - */
9900 -
9901 -#include <linux/string.h>
9902 -#include <linux/kernel.h>
9903 -#include <linux/sched.h>
9904 -#include <linux/smp.h>
9905 -#include <linux/spinlock.h>
9906 -#include <linux/delay.h>
9907 -#include <linux/linkage.h>
9908 -#include <linux/init.h>
9909 -
9910 -#include <asm/system.h>
9911 -#include <asm/current.h>
9912 -#include <asm/signal.h>
9913 -#include <asm/pgtable.h>
9914 -#include <asm/ptrace.h>
9915 -#include <asm/kgdb.h>
9916 -
9917 -#ifdef CONFIG_SH_KGDB_CONSOLE
9918 -#include <linux/console.h>
9919 -#endif
9920 -
9921 -/* Function pointers for linkage */
9922 -kgdb_debug_hook_t *kgdb_debug_hook;
9923 -kgdb_bus_error_hook_t *kgdb_bus_err_hook;
9924 -
9925 -int (*kgdb_getchar)(void);
9926 -void (*kgdb_putchar)(int);
9927 -
9928 -static void put_debug_char(int c)
9929 -{
9930 -       if (!kgdb_putchar)
9931 -               return;
9932 -       (*kgdb_putchar)(c);
9933 -}
9934 -static int get_debug_char(void)
9935 -{
9936 -       if (!kgdb_getchar)
9937 -               return -1;
9938 -       return (*kgdb_getchar)();
9939 -}
9940 -
9941 -/* Num chars in in/out bound buffers, register packets need NUMREGBYTES * 2 */
9942 -#define BUFMAX 1024
9943 -#define NUMREGBYTES (MAXREG*4)
9944 -#define OUTBUFMAX (NUMREGBYTES*2+512)
9945 -
9946 -enum regs {
9947 -       R0 = 0, R1,  R2,  R3,   R4,   R5,  R6, R7,
9948 -       R8, R9, R10, R11, R12,  R13,  R14, R15,
9949 -       PC, PR, GBR, VBR, MACH, MACL, SR,
9950 -       /*  */
9951 -       MAXREG
9952 -};
9953 -
9954 -static unsigned int registers[MAXREG];
9955 -struct kgdb_regs trap_registers;
9956 -
9957 -char kgdb_in_gdb_mode;
9958 -char in_nmi;                   /* Set during NMI to prevent reentry */
9959 -int kgdb_nofault;              /* Boolean to ignore bus errs (i.e. in GDB) */
9960 -int kgdb_enabled = 1;          /* Default to enabled, cmdline can disable */
9961 -int kgdb_halt;
9962 -
9963 -/* Exposed for user access */
9964 -struct task_struct *kgdb_current;
9965 -unsigned int kgdb_g_imask;
9966 -int kgdb_trapa_val;
9967 -int kgdb_excode;
9968 -
9969 -/* Default values for SCI (can override via kernel args in setup.c) */
9970 -#ifndef CONFIG_KGDB_DEFPORT
9971 -#define CONFIG_KGDB_DEFPORT 1
9972 -#endif
9973 -
9974 -#ifndef CONFIG_KGDB_DEFBAUD
9975 -#define CONFIG_KGDB_DEFBAUD 115200
9976 -#endif
9977 -
9978 -#if defined(CONFIG_KGDB_DEFPARITY_E)
9979 -#define CONFIG_KGDB_DEFPARITY 'E'
9980 -#elif defined(CONFIG_KGDB_DEFPARITY_O)
9981 -#define CONFIG_KGDB_DEFPARITY 'O'
9982 -#else /* CONFIG_KGDB_DEFPARITY_N */
9983 -#define CONFIG_KGDB_DEFPARITY 'N'
9984 -#endif
9985 -
9986 -#ifdef CONFIG_KGDB_DEFBITS_7
9987 -#define CONFIG_KGDB_DEFBITS '7'
9988 -#else /* CONFIG_KGDB_DEFBITS_8 */
9989 -#define CONFIG_KGDB_DEFBITS '8'
9990 -#endif
9991 -
9992 -/* SCI/UART settings, used in kgdb_console_setup() */
9993 -int  kgdb_portnum = CONFIG_KGDB_DEFPORT;
9994 -int  kgdb_baud = CONFIG_KGDB_DEFBAUD;
9995 -char kgdb_parity = CONFIG_KGDB_DEFPARITY;
9996 -char kgdb_bits = CONFIG_KGDB_DEFBITS;
9997 -
9998 -/* Jump buffer for setjmp/longjmp */
9999 -static jmp_buf rem_com_env;
10000 -
10001 -/* TRA differs sh3/4 */
10002 -#if defined(CONFIG_CPU_SH3)
10003 -#define TRA 0xffffffd0
10004 -#elif defined(CONFIG_CPU_SH4)
10005 -#define TRA 0xff000020
10006 -#endif
10007 -
10008 -/* Macros for single step instruction identification */
10009 -#define OPCODE_BT(op)         (((op) & 0xff00) == 0x8900)
10010 -#define OPCODE_BF(op)         (((op) & 0xff00) == 0x8b00)
10011 -#define OPCODE_BTF_DISP(op)   (((op) & 0x80) ? (((op) | 0xffffff80) << 1) : \
10012 -                             (((op) & 0x7f ) << 1))
10013 -#define OPCODE_BFS(op)        (((op) & 0xff00) == 0x8f00)
10014 -#define OPCODE_BTS(op)        (((op) & 0xff00) == 0x8d00)
10015 -#define OPCODE_BRA(op)        (((op) & 0xf000) == 0xa000)
10016 -#define OPCODE_BRA_DISP(op)   (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \
10017 -                             (((op) & 0x7ff) << 1))
10018 -#define OPCODE_BRAF(op)       (((op) & 0xf0ff) == 0x0023)
10019 -#define OPCODE_BRAF_REG(op)   (((op) & 0x0f00) >> 8)
10020 -#define OPCODE_BSR(op)        (((op) & 0xf000) == 0xb000)
10021 -#define OPCODE_BSR_DISP(op)   (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \
10022 -                             (((op) & 0x7ff) << 1))
10023 -#define OPCODE_BSRF(op)       (((op) & 0xf0ff) == 0x0003)
10024 -#define OPCODE_BSRF_REG(op)   (((op) >> 8) & 0xf)
10025 -#define OPCODE_JMP(op)        (((op) & 0xf0ff) == 0x402b)
10026 -#define OPCODE_JMP_REG(op)    (((op) >> 8) & 0xf)
10027 -#define OPCODE_JSR(op)        (((op) & 0xf0ff) == 0x400b)
10028 -#define OPCODE_JSR_REG(op)    (((op) >> 8) & 0xf)
10029 -#define OPCODE_RTS(op)        ((op) == 0xb)
10030 -#define OPCODE_RTE(op)        ((op) == 0x2b)
10031 -
10032 -#define SR_T_BIT_MASK           0x1
10033 -#define STEP_OPCODE             0xc320
10034 -#define BIOS_CALL_TRAP          0x3f
10035 -
10036 -/* Exception codes as per SH-4 core manual */
10037 -#define ADDRESS_ERROR_LOAD_VEC   7
10038 -#define ADDRESS_ERROR_STORE_VEC  8
10039 -#define TRAP_VEC                 11
10040 -#define INVALID_INSN_VEC         12
10041 -#define INVALID_SLOT_VEC         13
10042 -#define NMI_VEC                  14
10043 -#define USER_BREAK_VEC           15
10044 -#define SERIAL_BREAK_VEC         58
10045 -
10046 -/* Misc static */
10047 -static int stepped_address;
10048 -static short stepped_opcode;
10049 -static const char hexchars[] = "0123456789abcdef";
10050 -static char in_buffer[BUFMAX];
10051 -static char out_buffer[OUTBUFMAX];
10052 -
10053 -static void kgdb_to_gdb(const char *s);
10054 -
10055 -#ifdef CONFIG_KGDB_THREAD
10056 -static struct task_struct *trapped_thread;
10057 -static struct task_struct *current_thread;
10058 -typedef unsigned char threadref[8];
10059 -#define BUF_THREAD_ID_SIZE 16
10060 -#endif
10061 -
10062 -/* Return addr as a real volatile address */
10063 -static inline unsigned int ctrl_inl(const unsigned long addr)
10064 -{
10065 -       return *(volatile unsigned long *) addr;
10066 -}
10067 -
10068 -/* Correctly set *addr using volatile */
10069 -static inline void ctrl_outl(const unsigned int b, unsigned long addr)
10070 -{
10071 -       *(volatile unsigned long *) addr = b;
10072 -}
10073 -
10074 -/* Get high hex bits */
10075 -static char highhex(const int x)
10076 -{
10077 -       return hexchars[(x >> 4) & 0xf];
10078 -}
10079 -
10080 -/* Get low hex bits */
10081 -static char lowhex(const int x)
10082 -{
10083 -       return hexchars[x & 0xf];
10084 -}
10085 -
10086 -/* Convert ch to hex */
10087 -static int hex(const char ch)
10088 -{
10089 -       if ((ch >= 'a') && (ch <= 'f'))
10090 -               return (ch - 'a' + 10);
10091 -       if ((ch >= '0') && (ch <= '9'))
10092 -               return (ch - '0');
10093 -       if ((ch >= 'A') && (ch <= 'F'))
10094 -               return (ch - 'A' + 10);
10095 -       return (-1);
10096 -}
10097 -
10098 -/* Convert the memory pointed to by mem into hex, placing result in buf.
10099 -   Returns a pointer to the last char put in buf (null) */
10100 -static char *mem_to_hex(const char *mem, char *buf, const int count)
10101 -{
10102 -       int i;
10103 -       int ch;
10104 -       unsigned short s_val;
10105 -       unsigned long l_val;
10106 -
10107 -       /* Check for 16 or 32 */
10108 -       if (count == 2 && ((long) mem & 1) == 0) {
10109 -               s_val = *(unsigned short *) mem;
10110 -               mem = (char *) &s_val;
10111 -       } else if (count == 4 && ((long) mem & 3) == 0) {
10112 -               l_val = *(unsigned long *) mem;
10113 -               mem = (char *) &l_val;
10114 -       }
10115 -       for (i = 0; i < count; i++) {
10116 -               ch = *mem++;
10117 -               *buf++ = highhex(ch);
10118 -               *buf++ = lowhex(ch);
10119 -       }
10120 -       *buf = 0;
10121 -       return (buf);
10122 -}
10123 -
10124 -/* Convert the hex array pointed to by buf into binary, to be placed in mem.
10125 -   Return a pointer to the character after the last byte written */
10126 -static char *hex_to_mem(const char *buf, char *mem, const int count)
10127 -{
10128 -       int i;
10129 -       unsigned char ch;
10130 -
10131 -       for (i = 0; i < count; i++) {
10132 -               ch = hex(*buf++) << 4;
10133 -               ch = ch + hex(*buf++);
10134 -               *mem++ = ch;
10135 -       }
10136 -       return (mem);
10137 -}
10138 -
10139 -/* While finding valid hex chars, convert to an integer, then return it */
10140 -static int hex_to_int(char **ptr, int *int_value)
10141 -{
10142 -       int num_chars = 0;
10143 -       int hex_value;
10144 -
10145 -       *int_value = 0;
10146 -
10147 -       while (**ptr) {
10148 -               hex_value = hex(**ptr);
10149 -               if (hex_value >= 0) {
10150 -                       *int_value = (*int_value << 4) | hex_value;
10151 -                       num_chars++;
10152 -               } else
10153 -                       break;
10154 -               (*ptr)++;
10155 -       }
10156 -       return num_chars;
10157 -}
10158 -
10159 -/*  Copy the binary array pointed to by buf into mem.  Fix $, #,
10160 -    and 0x7d escaped with 0x7d.  Return a pointer to the character 
10161 -    after the last byte written. */
10162 -static char *ebin_to_mem(const char *buf, char *mem, int count)
10163 -{
10164 -       for (; count > 0; count--, buf++) {
10165 -               if (*buf == 0x7d)
10166 -                       *mem++ = *(++buf) ^ 0x20;
10167 -               else
10168 -                       *mem++ = *buf;
10169 -       }
10170 -       return mem;
10171 -}
10172 -
10173 -/* Pack a hex byte */
10174 -static char *pack_hex_byte(char *pkt, int byte)
10175 -{
10176 -       *pkt++ = hexchars[(byte >> 4) & 0xf];
10177 -       *pkt++ = hexchars[(byte & 0xf)];
10178 -       return pkt;
10179 -}
10180 -
10181 -#ifdef CONFIG_KGDB_THREAD
10182 -
10183 -/* Pack a thread ID */
10184 -static char *pack_threadid(char *pkt, threadref * id)
10185 -{
10186 -       char *limit;
10187 -       unsigned char *altid;
10188 -
10189 -       altid = (unsigned char *) id;
10190 -
10191 -       limit = pkt + BUF_THREAD_ID_SIZE;
10192 -       while (pkt < limit)
10193 -               pkt = pack_hex_byte(pkt, *altid++);
10194 -       return pkt;
10195 -}
10196 -
10197 -/* Convert an integer into our threadref */
10198 -static void int_to_threadref(threadref * id, const int value)
10199 -{
10200 -       unsigned char *scan = (unsigned char *) id;
10201 -       int i = 4;
10202 -
10203 -       while (i--)
10204 -               *scan++ = 0;
10205 -
10206 -       *scan++ = (value >> 24) & 0xff;
10207 -       *scan++ = (value >> 16) & 0xff;
10208 -       *scan++ = (value >> 8) & 0xff;
10209 -       *scan++ = (value & 0xff);
10210 -}
10211 -
10212 -/* Return a task structure ptr for a particular pid */
10213 -static struct task_struct *get_thread(int pid)
10214 -{
10215 -       struct task_struct *thread;
10216 -
10217 -       /* Use PID_MAX w/gdb for pid 0 */
10218 -       if (pid == PID_MAX) pid = 0;
10219 -
10220 -       /* First check via PID */
10221 -       thread = find_task_by_pid(pid);
10222 -
10223 -       if (thread)
10224 -               return thread;
10225 -
10226 -       /* Start at the start */
10227 -       thread = init_tasks[0];
10228 -
10229 -       /* Walk along the linked list of tasks */
10230 -       do {
10231 -               if (thread->pid == pid)
10232 -                       return thread;
10233 -               thread = thread->next_task;
10234 -       } while (thread != init_tasks[0]);
10235 -
10236 -       return NULL;
10237 -}
10238 -
10239 -#endif /* CONFIG_KGDB_THREAD */
10240 -
10241 -/* Scan for the start char '$', read the packet and check the checksum */
10242 -static void get_packet(char *buffer, int buflen)
10243 -{
10244 -       unsigned char checksum;
10245 -       unsigned char xmitcsum;
10246 -       int i;
10247 -       int count;
10248 -       char ch;
10249 -
10250 -       do {
10251 -               /* Ignore everything until the start character */
10252 -               while ((ch = get_debug_char()) != '$');
10253 -
10254 -               checksum = 0;
10255 -               xmitcsum = -1;
10256 -               count = 0;
10257 -
10258 -               /* Now, read until a # or end of buffer is found */
10259 -               while (count < (buflen - 1)) {
10260 -                       ch = get_debug_char();
10261 -
10262 -                       if (ch == '#')
10263 -                               break;
10264 -
10265 -                       checksum = checksum + ch;
10266 -                       buffer[count] = ch;
10267 -                       count = count + 1;
10268 -               }
10269 -
10270 -               buffer[count] = 0;
10271 -
10272 -               /* Continue to read checksum following # */
10273 -               if (ch == '#') {
10274 -                       xmitcsum = hex(get_debug_char()) << 4;
10275 -                       xmitcsum += hex(get_debug_char());
10276 -
10277 -                       /* Checksum */
10278 -                       if (checksum != xmitcsum)
10279 -                               put_debug_char('-');    /* Failed checksum */
10280 -                       else {
10281 -                               /* Ack successful transfer */
10282 -                               put_debug_char('+');
10283 -
10284 -                               /* If a sequence char is present, reply 
10285 -                                  the sequence ID */
10286 -                               if (buffer[2] == ':') {
10287 -                                       put_debug_char(buffer[0]);
10288 -                                       put_debug_char(buffer[1]);
10289 -
10290 -                                       /* Remove sequence chars from buffer */
10291 -                                       count = strlen(buffer);
10292 -                                       for (i = 3; i <= count; i++)
10293 -                                               buffer[i - 3] = buffer[i];
10294 -                               }
10295 -                       }
10296 -               }
10297 -       }
10298 -       while (checksum != xmitcsum);   /* Keep trying while we fail */
10299 -}
10300 -
10301 -/* Send the packet in the buffer with run-length encoding */
10302 -static void put_packet(char *buffer)
10303 -{
10304 -       int checksum;
10305 -       char *src;
10306 -       int runlen;
10307 -       int encode;
10308 -
10309 -       do {
10310 -               src = buffer;
10311 -               put_debug_char('$');
10312 -               checksum = 0;
10313 -
10314 -               /* Continue while we still have chars left */
10315 -               while (*src) {
10316 -                       /* Check for runs up to 99 chars long */
10317 -                       for (runlen = 1; runlen < 99; runlen++) {
10318 -                               if (src[0] != src[runlen])
10319 -                                       break;
10320 -                       }
10321 -
10322 -                       if (runlen > 3) {
10323 -                               /* Got a useful amount, send encoding */
10324 -                               encode = runlen + ' ' - 4;
10325 -                               put_debug_char(*src);   checksum += *src;
10326 -                               put_debug_char('*');    checksum += '*';
10327 -                               put_debug_char(encode); checksum += encode;
10328 -                               src += runlen;
10329 -                       } else {
10330 -                               /* Otherwise just send the current char */
10331 -                               put_debug_char(*src);   checksum += *src;
10332 -                               src += 1;
10333 -                       }
10334 -               }
10335 -
10336 -               /* '#' Separator, put high and low components of checksum */
10337 -               put_debug_char('#');
10338 -               put_debug_char(highhex(checksum));
10339 -               put_debug_char(lowhex(checksum));
10340 -       }
10341 -       while ((get_debug_char()) != '+');      /* While no ack */
10342 -}
10343 -
10344 -/* A bus error has occurred - perform a longjmp to return execution and
10345 -   allow handling of the error */
10346 -static void kgdb_handle_bus_error(void)
10347 -{
10348 -       longjmp(rem_com_env, 1);
10349 -}
10350 -
10351 -/* Translate SH-3/4 exception numbers to unix-like signal values */
10352 -static int compute_signal(const int excep_code)
10353 -{
10354 -       int sigval;
10355 -
10356 -       switch (excep_code) {
10357 -
10358 -       case INVALID_INSN_VEC:
10359 -       case INVALID_SLOT_VEC:
10360 -               sigval = SIGILL;
10361 -               break;
10362 -       case ADDRESS_ERROR_LOAD_VEC:
10363 -       case ADDRESS_ERROR_STORE_VEC:
10364 -               sigval = SIGSEGV;
10365 -               break;
10366 -
10367 -       case SERIAL_BREAK_VEC:
10368 -       case NMI_VEC:
10369 -               sigval = SIGINT;
10370 -               break;
10371 -
10372 -       case USER_BREAK_VEC:
10373 -       case TRAP_VEC:
10374 -               sigval = SIGTRAP;
10375 -               break;
10376 -
10377 -       default:
10378 -               sigval = SIGBUS;        /* "software generated" */
10379 -               break;
10380 -       }
10381 -
10382 -       return (sigval);
10383 -}
10384 -
10385 -/* Make a local copy of the registers passed into the handler (bletch) */
10386 -static void kgdb_regs_to_gdb_regs(const struct kgdb_regs *regs,
10387 -                                 int *gdb_regs)
10388 -{
10389 -       gdb_regs[R0] = regs->regs[R0];
10390 -       gdb_regs[R1] = regs->regs[R1];
10391 -       gdb_regs[R2] = regs->regs[R2];
10392 -       gdb_regs[R3] = regs->regs[R3];
10393 -       gdb_regs[R4] = regs->regs[R4];
10394 -       gdb_regs[R5] = regs->regs[R5];
10395 -       gdb_regs[R6] = regs->regs[R6];
10396 -       gdb_regs[R7] = regs->regs[R7];
10397 -       gdb_regs[R8] = regs->regs[R8];
10398 -       gdb_regs[R9] = regs->regs[R9];
10399 -       gdb_regs[R10] = regs->regs[R10];
10400 -       gdb_regs[R11] = regs->regs[R11];
10401 -       gdb_regs[R12] = regs->regs[R12];
10402 -       gdb_regs[R13] = regs->regs[R13];
10403 -       gdb_regs[R14] = regs->regs[R14];
10404 -       gdb_regs[R15] = regs->regs[R15];
10405 -       gdb_regs[PC] = regs->pc;
10406 -       gdb_regs[PR] = regs->pr;
10407 -       gdb_regs[GBR] = regs->gbr;
10408 -       gdb_regs[MACH] = regs->mach;
10409 -       gdb_regs[MACL] = regs->macl;
10410 -       gdb_regs[SR] = regs->sr;
10411 -       gdb_regs[VBR] = regs->vbr;
10412 -}
10413 -
10414 -/* Copy local gdb registers back to kgdb regs, for later copy to kernel */
10415 -static void gdb_regs_to_kgdb_regs(const int *gdb_regs,
10416 -                                 struct kgdb_regs *regs)
10417 -{
10418 -       regs->regs[R0] = gdb_regs[R0];
10419 -       regs->regs[R1] = gdb_regs[R1];
10420 -       regs->regs[R2] = gdb_regs[R2];
10421 -       regs->regs[R3] = gdb_regs[R3];
10422 -       regs->regs[R4] = gdb_regs[R4];
10423 -       regs->regs[R5] = gdb_regs[R5];
10424 -       regs->regs[R6] = gdb_regs[R6];
10425 -       regs->regs[R7] = gdb_regs[R7];
10426 -       regs->regs[R8] = gdb_regs[R8];
10427 -       regs->regs[R9] = gdb_regs[R9];
10428 -       regs->regs[R10] = gdb_regs[R10];
10429 -       regs->regs[R11] = gdb_regs[R11];
10430 -       regs->regs[R12] = gdb_regs[R12];
10431 -       regs->regs[R13] = gdb_regs[R13];
10432 -       regs->regs[R14] = gdb_regs[R14];
10433 -       regs->regs[R15] = gdb_regs[R15];
10434 -       regs->pc = gdb_regs[PC];
10435 -       regs->pr = gdb_regs[PR];
10436 -       regs->gbr = gdb_regs[GBR];
10437 -       regs->mach = gdb_regs[MACH];
10438 -       regs->macl = gdb_regs[MACL];
10439 -       regs->sr = gdb_regs[SR];
10440 -       regs->vbr = gdb_regs[VBR];
10441 -}
10442 -
10443 -#ifdef CONFIG_KGDB_THREAD
10444 -/* Make a local copy of registers from the specified thread */
10445 -asmlinkage void ret_from_fork(void);
10446 -static void thread_regs_to_gdb_regs(const struct task_struct *thread,
10447 -                                   int *gdb_regs)
10448 -{
10449 -       int regno;
10450 -       int *tregs;
10451 -
10452 -       /* Initialize to zero */
10453 -       for (regno = 0; regno < MAXREG; regno++)
10454 -               gdb_regs[regno] = 0;
10455 -
10456 -       /* Just making sure... */
10457 -       if (thread == NULL)
10458 -               return;
10459 -
10460 -       /* A new fork has pt_regs on the stack from a fork() call */
10461 -       if (thread->thread.pc == (unsigned long)ret_from_fork) {
10462 -
10463 -               int vbr_val;
10464 -               struct pt_regs *kregs;
10465 -               kregs = (struct pt_regs*)thread->thread.sp;
10466 -
10467 -               gdb_regs[R0] = kregs->regs[R0];
10468 -               gdb_regs[R1] = kregs->regs[R1];
10469 -               gdb_regs[R2] = kregs->regs[R2];
10470 -               gdb_regs[R3] = kregs->regs[R3];
10471 -               gdb_regs[R4] = kregs->regs[R4];
10472 -               gdb_regs[R5] = kregs->regs[R5];
10473 -               gdb_regs[R6] = kregs->regs[R6];
10474 -               gdb_regs[R7] = kregs->regs[R7];
10475 -               gdb_regs[R8] = kregs->regs[R8];
10476 -               gdb_regs[R9] = kregs->regs[R9];
10477 -               gdb_regs[R10] = kregs->regs[R10];
10478 -               gdb_regs[R11] = kregs->regs[R11];
10479 -               gdb_regs[R12] = kregs->regs[R12];
10480 -               gdb_regs[R13] = kregs->regs[R13];
10481 -               gdb_regs[R14] = kregs->regs[R14];
10482 -               gdb_regs[R15] = kregs->regs[R15];
10483 -               gdb_regs[PC] = kregs->pc;
10484 -               gdb_regs[PR] = kregs->pr;
10485 -               gdb_regs[GBR] = kregs->gbr;
10486 -               gdb_regs[MACH] = kregs->mach;
10487 -               gdb_regs[MACL] = kregs->macl;
10488 -               gdb_regs[SR] = kregs->sr;
10489 -
10490 -               asm("stc vbr, %0":"=r"(vbr_val));
10491 -               gdb_regs[VBR] = vbr_val;
10492 -               return;
10493 -       }
10494 -
10495 -       /* Otherwise, we have only some registers from switch_to() */
10496 -       tregs = (int *)thread->thread.sp;
10497 -       gdb_regs[R15] = (int)tregs;
10498 -       gdb_regs[R14] = *tregs++;
10499 -       gdb_regs[R13] = *tregs++;
10500 -       gdb_regs[R12] = *tregs++;
10501 -       gdb_regs[R11] = *tregs++;
10502 -       gdb_regs[R10] = *tregs++;
10503 -       gdb_regs[R9] = *tregs++;
10504 -       gdb_regs[R8] = *tregs++;
10505 -       gdb_regs[PR] = *tregs++;
10506 -       gdb_regs[GBR] = *tregs++;
10507 -       gdb_regs[PC] = thread->thread.pc;
10508 -}
10509 -#endif /* CONFIG_KGDB_THREAD */
10510 -
10511 -/* Calculate the new address for after a step */
10512 -static short *get_step_address(void)
10513 -{
10514 -       short op = *(short *) trap_registers.pc;
10515 -       long addr;
10516 -
10517 -       /* BT */
10518 -       if (OPCODE_BT(op)) {
10519 -               if (trap_registers.sr & SR_T_BIT_MASK)
10520 -                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
10521 -               else
10522 -                       addr = trap_registers.pc + 2;
10523 -       }
10524 -
10525 -       /* BTS */
10526 -       else if (OPCODE_BTS(op)) {
10527 -               if (trap_registers.sr & SR_T_BIT_MASK)
10528 -                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
10529 -               else
10530 -                       addr = trap_registers.pc + 4;   /* Not in delay slot */
10531 -       }
10532 -
10533 -       /* BF */
10534 -       else if (OPCODE_BF(op)) {
10535 -               if (!(trap_registers.sr & SR_T_BIT_MASK))
10536 -                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
10537 -               else
10538 -                       addr = trap_registers.pc + 2;
10539 -       }
10540 -
10541 -       /* BFS */
10542 -       else if (OPCODE_BFS(op)) {
10543 -               if (!(trap_registers.sr & SR_T_BIT_MASK))
10544 -                       addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op);
10545 -               else
10546 -                       addr = trap_registers.pc + 4;   /* Not in delay slot */
10547 -       }
10548 -
10549 -       /* BRA */
10550 -       else if (OPCODE_BRA(op))
10551 -               addr = trap_registers.pc + 4 + OPCODE_BRA_DISP(op);
10552 -
10553 -       /* BRAF */
10554 -       else if (OPCODE_BRAF(op))
10555 -               addr = trap_registers.pc + 4
10556 -                   + trap_registers.regs[OPCODE_BRAF_REG(op)];
10557 -
10558 -       /* BSR */
10559 -       else if (OPCODE_BSR(op))
10560 -               addr = trap_registers.pc + 4 + OPCODE_BSR_DISP(op);
10561 -
10562 -       /* BSRF */
10563 -       else if (OPCODE_BSRF(op))
10564 -               addr = trap_registers.pc + 4
10565 -                   + trap_registers.regs[OPCODE_BSRF_REG(op)];
10566 -
10567 -       /* JMP */
10568 -       else if (OPCODE_JMP(op))
10569 -               addr = trap_registers.regs[OPCODE_JMP_REG(op)];
10570 -
10571 -       /* JSR */
10572 -       else if (OPCODE_JSR(op))
10573 -               addr = trap_registers.regs[OPCODE_JSR_REG(op)];
10574 -
10575 -       /* RTS */
10576 -       else if (OPCODE_RTS(op))
10577 -               addr = trap_registers.pr;
10578 -
10579 -       /* RTE */
10580 -       else if (OPCODE_RTE(op))
10581 -               addr = trap_registers.regs[15];
10582 -
10583 -       /* Other */
10584 -       else
10585 -               addr = trap_registers.pc + 2;
10586 -
10587 -       kgdb_flush_icache_range(addr, addr + 2);
10588 -       return (short *) addr;
10589 -}
10590 -
10591 -/* Set up a single-step.  Replace the instruction immediately after the 
10592 -   current instruction (i.e. next in the expected flow of control) with a
10593 -   trap instruction, so that returning will cause only a single instruction
10594 -   to be executed. Note that this model is slightly broken for instructions
10595 -   with delay slots (e.g. B[TF]S, BSR, BRA etc), where both the branch
10596 -   and the instruction in the delay slot will be executed. */
10597 -static void do_single_step(void)
10598 -{
10599 -       unsigned short *addr = 0;
10600 -
10601 -       /* Determine where the target instruction will send us to */
10602 -       addr = get_step_address();
10603 -       stepped_address = (int)addr;
10604 -
10605 -       /* Replace it */
10606 -       stepped_opcode = *(short *)addr;
10607 -       *addr = STEP_OPCODE;
10608 -
10609 -       /* Flush and return */
10610 -       kgdb_flush_icache_range((long) addr, (long) addr + 2);
10611 -       return;
10612 -}
10613 -
10614 -/* Undo a single step */
10615 -static void undo_single_step(void)
10616 -{
10617 -       /* If we have stepped, put back the old instruction */
10618 -       /* Use stepped_address in case we stopped elsewhere */
10619 -       if (stepped_opcode != 0) {
10620 -               *(short*)stepped_address = stepped_opcode;
10621 -               kgdb_flush_icache_range(stepped_address, stepped_address + 2);
10622 -       }
10623 -       stepped_opcode = 0;
10624 -}
10625 -
10626 -/* Send a signal message */
10627 -static void send_signal_msg(const int signum)
10628 -{
10629 -#ifndef CONFIG_KGDB_THREAD
10630 -       out_buffer[0] = 'S';
10631 -       out_buffer[1] = highhex(signum);
10632 -       out_buffer[2] = lowhex(signum);
10633 -       out_buffer[3] = 0;
10634 -       put_packet(out_buffer);
10635 -#else /* CONFIG_KGDB_THREAD */
10636 -       int threadid;
10637 -       threadref thref;
10638 -       char *out = out_buffer;
10639 -       const char *tstring = "thread";
10640 -
10641 -       *out++ = 'T';
10642 -       *out++ = highhex(signum);
10643 -       *out++ = lowhex(signum);
10644 -
10645 -       while (*tstring) {
10646 -               *out++ = *tstring++;
10647 -       }
10648 -       *out++ = ':';
10649 -
10650 -       threadid = trapped_thread->pid;
10651 -       if (threadid == 0) threadid = PID_MAX;
10652 -       int_to_threadref(&thref, threadid);
10653 -       pack_threadid(out, &thref);
10654 -       out += BUF_THREAD_ID_SIZE;
10655 -       *out++ = ';';
10656 -
10657 -       *out = 0;
10658 -       put_packet(out_buffer);
10659 -#endif /* CONFIG_KGDB_THREAD */
10660 -}
10661 -
10662 -/* Reply that all was well */
10663 -static void send_ok_msg(void)
10664 -{
10665 -       strcpy(out_buffer, "OK");
10666 -       put_packet(out_buffer);
10667 -}
10668 -
10669 -/* Reply that an error occurred */
10670 -static void send_err_msg(void)
10671 -{
10672 -       strcpy(out_buffer, "E01");
10673 -       put_packet(out_buffer);
10674 -}
10675 -
10676 -/* Empty message indicates unrecognised command */
10677 -static void send_empty_msg(void)
10678 -{
10679 -       put_packet("");
10680 -}
10681 -
10682 -/* Read memory due to 'm' message */
10683 -static void read_mem_msg(void)
10684 -{
10685 -       char *ptr;
10686 -       int addr;
10687 -       int length;
10688 -
10689 -       /* Jmp, disable bus error handler */
10690 -       if (setjmp(rem_com_env) == 0) {
10691 -
10692 -               kgdb_nofault = 1;
10693 -
10694 -               /* Walk through, have m<addr>,<length> */
10695 -               ptr = &in_buffer[1];
10696 -               if (hex_to_int(&ptr, &addr) && (*ptr++ == ','))
10697 -                       if (hex_to_int(&ptr, &length)) {
10698 -                               ptr = 0;
10699 -                               if (length * 2 > OUTBUFMAX)
10700 -                                       length = OUTBUFMAX / 2;
10701 -                               mem_to_hex((char *) addr, out_buffer, length);
10702 -                       }
10703 -               if (ptr)
10704 -                       send_err_msg();
10705 -               else
10706 -                       put_packet(out_buffer);
10707 -       } else
10708 -               send_err_msg();
10709 -
10710 -       /* Restore bus error handler */
10711 -       kgdb_nofault = 0;
10712 -}
10713 -
10714 -/* Write memory due to 'M' or 'X' message */
10715 -static void write_mem_msg(int binary)
10716 -{
10717 -       char *ptr;
10718 -       int addr;
10719 -       int length;
10720 -
10721 -       if (setjmp(rem_com_env) == 0) {
10722 -
10723 -               kgdb_nofault = 1;
10724 -
10725 -               /* Walk through, have M<addr>,<length>:<data> */
10726 -               ptr = &in_buffer[1];
10727 -               if (hex_to_int(&ptr, &addr) && (*ptr++ == ','))
10728 -                       if (hex_to_int(&ptr, &length) && (*ptr++ == ':')) {
10729 -                               if (binary)
10730 -                                       ebin_to_mem(ptr, (char*)addr, length);
10731 -                               else
10732 -                                       hex_to_mem(ptr, (char*)addr, length);
10733 -                               kgdb_flush_icache_range(addr, addr + length);
10734 -                               ptr = 0;
10735 -                               send_ok_msg();
10736 -                       }
10737 -               if (ptr)
10738 -                       send_err_msg();
10739 -       } else
10740 -               send_err_msg();
10741 -
10742 -       /* Restore bus error handler */
10743 -       kgdb_nofault = 0;
10744 -}
10745 -
10746 -/* Continue message  */
10747 -static void continue_msg(void)
10748 -{
10749 -       /* Try to read optional parameter, PC unchanged if none */
10750 -       char *ptr = &in_buffer[1];
10751 -       int addr;
10752 -
10753 -       if (hex_to_int(&ptr, &addr))
10754 -               trap_registers.pc = addr;
10755 -}
10756 -
10757 -/* Continue message with signal */
10758 -static void continue_with_sig_msg(void)
10759 -{
10760 -       int signal;
10761 -       char *ptr = &in_buffer[1];
10762 -       int addr;
10763 -
10764 -       /* Report limitation */
10765 -       kgdb_to_gdb("Cannot force signal in kgdb, continuing anyway.\n");
10766 -
10767 -       /* Signal */
10768 -       hex_to_int(&ptr, &signal);
10769 -       if (*ptr == ';')
10770 -               ptr++;
10771 -
10772 -       /* Optional address */
10773 -       if (hex_to_int(&ptr, &addr))
10774 -               trap_registers.pc = addr;
10775 -}
10776 -
10777 -/* Step message */
10778 -static void step_msg(void)
10779 -{
10780 -       continue_msg();
10781 -       do_single_step();
10782 -}
10783 -
10784 -/* Step message with signal */
10785 -static void step_with_sig_msg(void)
10786 -{
10787 -       continue_with_sig_msg();
10788 -       do_single_step();
10789 -}
10790 -
10791 -/* Send register contents */
10792 -static void send_regs_msg(void)
10793 -{
10794 -#ifdef CONFIG_KGDB_THREAD
10795 -       if (!current_thread)
10796 -               kgdb_regs_to_gdb_regs(&trap_registers, registers);
10797 -       else
10798 -               thread_regs_to_gdb_regs(current_thread, registers);
10799 -#else
10800 -       kgdb_regs_to_gdb_regs(&trap_registers, registers);
10801 -#endif
10802 -
10803 -       mem_to_hex((char *) registers, out_buffer, NUMREGBYTES);
10804 -       put_packet(out_buffer);
10805 -}
10806 -
10807 -/* Set register contents - currently can't set other thread's registers */
10808 -static void set_regs_msg(void)
10809 -{
10810 -#ifdef CONFIG_KGDB_THREAD
10811 -       if (!current_thread) {
10812 -#endif
10813 -               kgdb_regs_to_gdb_regs(&trap_registers, registers);
10814 -               hex_to_mem(&in_buffer[1], (char *) registers, NUMREGBYTES);
10815 -               gdb_regs_to_kgdb_regs(registers, &trap_registers);
10816 -               send_ok_msg();
10817 -#ifdef CONFIG_KGDB_THREAD
10818 -       } else
10819 -               send_err_msg();
10820 -#endif
10821 -}
10822 -
10823 -
10824 -#ifdef CONFIG_KGDB_THREAD
10825 -
10826 -/* Set the status for a thread */
10827 -void set_thread_msg(void)
10828 -{
10829 -       int threadid;
10830 -       struct task_struct *thread = NULL;
10831 -       char *ptr;
10832 -
10833 -       switch (in_buffer[1]) {
10834 -
10835 -               /* To select which thread for gG etc messages, i.e. supported */
10836 -       case 'g':
10837 -
10838 -               ptr = &in_buffer[2];
10839 -               hex_to_int(&ptr, &threadid);
10840 -               thread = get_thread(threadid);
10841 -
10842 -               /* If we haven't found it */
10843 -               if (!thread) {
10844 -                       send_err_msg();
10845 -                       break;
10846 -               }
10847 -
10848 -               /* Set current_thread (or not) */
10849 -               if (thread == trapped_thread)
10850 -                       current_thread = NULL;
10851 -               else
10852 -                       current_thread = thread;
10853 -               send_ok_msg();
10854 -               break;
10855 -
10856 -       /* To select which thread for cCsS messages, i.e. unsupported */
10857 -       case 'c':
10858 -               send_ok_msg();
10859 -               break;
10860 -
10861 -       default:
10862 -               send_empty_msg();
10863 -               break;
10864 -       }
10865 -}
10866 -
10867 -/* Is a thread alive? */
10868 -static void thread_status_msg(void)
10869 -{
10870 -       char *ptr;
10871 -       int threadid;
10872 -       struct task_struct *thread = NULL;
10873 -
10874 -       ptr = &in_buffer[1];
10875 -       hex_to_int(&ptr, &threadid);
10876 -       thread = get_thread(threadid);
10877 -       if (thread)
10878 -               send_ok_msg();
10879 -       else
10880 -               send_err_msg();
10881 -}
10882 -/* Send the current thread ID */
10883 -static void thread_id_msg(void)
10884 -{
10885 -       int threadid;
10886 -       threadref thref;
10887 -
10888 -       out_buffer[0] = 'Q';
10889 -       out_buffer[1] = 'C';
10890 -
10891 -       if (current_thread)
10892 -               threadid = current_thread->pid;
10893 -       else if (trapped_thread)
10894 -               threadid = trapped_thread->pid;
10895 -       else /* Impossible, but just in case! */
10896 -       {
10897 -               send_err_msg();
10898 -               return;
10899 -       }
10900 -
10901 -       /* Translate pid 0 to PID_MAX for gdb */
10902 -       if (threadid == 0) threadid = PID_MAX;
10903 -
10904 -       int_to_threadref(&thref, threadid);
10905 -       pack_threadid(out_buffer + 2, &thref);
10906 -       out_buffer[2 + BUF_THREAD_ID_SIZE] = '\0';
10907 -       put_packet(out_buffer);
10908 -}
10909 -
10910 -/* Send thread info */
10911 -static void thread_info_msg(void)
10912 -{
10913 -       struct task_struct *thread = NULL;
10914 -       int threadid;
10915 -       char *pos;
10916 -       threadref thref;
10917 -
10918 -       /* Start with 'm' */
10919 -       out_buffer[0] = 'm';
10920 -       pos = &out_buffer[1];
10921 -
10922 -       /* For all possible thread IDs - this will overrun if > 44 threads! */
10923 -       /* Start at 1 and include PID_MAX (since GDB won't use pid 0...) */
10924 -       for (threadid = 1; threadid <= PID_MAX; threadid++) {
10925 -
10926 -               read_lock(&tasklist_lock);
10927 -               thread = get_thread(threadid);
10928 -               read_unlock(&tasklist_lock);
10929 -
10930 -               /* If it's a valid thread */
10931 -               if (thread) {
10932 -                       int_to_threadref(&thref, threadid);
10933 -                       pack_threadid(pos, &thref);
10934 -                       pos += BUF_THREAD_ID_SIZE;
10935 -                       *pos++ = ',';
10936 -               }
10937 -       }
10938 -       *--pos = 0;             /* Lose final comma */
10939 -       put_packet(out_buffer);
10940 -
10941 -}
10942 -
10943 -/* Return printable info for gdb's 'info threads' command */
10944 -static void thread_extra_info_msg(void)
10945 -{
10946 -       int threadid;
10947 -       struct task_struct *thread = NULL;
10948 -       char buffer[20], *ptr;
10949 -       int i;
10950 -
10951 -       /* Extract thread ID */
10952 -       ptr = &in_buffer[17];
10953 -       hex_to_int(&ptr, &threadid);
10954 -       thread = get_thread(threadid);
10955 -
10956 -       /* If we don't recognise it, say so */
10957 -       if (thread == NULL)
10958 -               strcpy(buffer, "(unknown)");
10959 -       else
10960 -               strcpy(buffer, thread->comm);
10961 -
10962 -       /* Construct packet */
10963 -       for (i = 0, ptr = out_buffer; buffer[i]; i++)
10964 -               ptr = pack_hex_byte(ptr, buffer[i]);
10965 -
10966 -       if (thread->thread.pc == (unsigned long)ret_from_fork) {
10967 -               strcpy(buffer, "<new fork>");
10968 -               for (i = 0; buffer[i]; i++)
10969 -                       ptr = pack_hex_byte(ptr, buffer[i]);
10970 -       }
10971 -
10972 -       *ptr = '\0';
10973 -       put_packet(out_buffer);
10974 -}
10975 -
10976 -/* Handle all qFooBarBaz messages - have to use an if statement as
10977 -   opposed to a switch because q messages can have > 1 char id. */
10978 -static void query_msg(void)
10979 -{
10980 -       const char *q_start = &in_buffer[1];
10981 -
10982 -       /* qC = return current thread ID */
10983 -       if (strncmp(q_start, "C", 1) == 0)
10984 -               thread_id_msg();
10985 -
10986 -       /* qfThreadInfo = query all threads (first) */
10987 -       else if (strncmp(q_start, "fThreadInfo", 11) == 0)
10988 -               thread_info_msg();
10989 -
10990 -       /* qsThreadInfo = query all threads (subsequent). We know we have sent
10991 -          them all after the qfThreadInfo message, so there are no to send */
10992 -       else if (strncmp(q_start, "sThreadInfo", 11) == 0)
10993 -               put_packet("l");        /* el = last */
10994 -
10995 -       /* qThreadExtraInfo = supply printable information per thread */
10996 -       else if (strncmp(q_start, "ThreadExtraInfo", 15) == 0)
10997 -               thread_extra_info_msg();
10998 -
10999 -       /* Unsupported - empty message as per spec */
11000 -       else
11001 -               send_empty_msg();
11002 -}
11003 -#endif /* CONFIG_KGDB_THREAD */
11004 -
11005 -/*
11006 - * Bring up the ports..
11007 - */
11008 -static int kgdb_serial_setup(void)
11009 -{
11010 -       extern int kgdb_console_setup(struct console *co, char *options);
11011 -       struct console dummy;
11012 -
11013 -       kgdb_console_setup(&dummy, 0);
11014 -
11015 -       return 0;
11016 -}
11017 -
11018 -/* The command loop, read and act on requests */
11019 -static void kgdb_command_loop(const int excep_code, const int trapa_value)
11020 -{
11021 -       int sigval;
11022 -
11023 -       if (excep_code == NMI_VEC) {
11024 -#ifndef CONFIG_KGDB_NMI
11025 -               KGDB_PRINTK("Ignoring unexpected NMI?\n");
11026 -               return;
11027 -#else /* CONFIG_KGDB_NMI */
11028 -               if (!kgdb_enabled) {
11029 -                       kgdb_enabled = 1;
11030 -                       kgdb_init();
11031 -               }
11032 -#endif /* CONFIG_KGDB_NMI */
11033 -       }
11034 -
11035 -       /* Ignore if we're disabled */
11036 -       if (!kgdb_enabled)
11037 -               return;
11038 -
11039 -#ifdef CONFIG_KGDB_THREAD
11040 -       /* Until GDB specifies a thread */
11041 -       current_thread = NULL;
11042 -       trapped_thread = current;
11043 -#endif
11044 -
11045 -       /* Enter GDB mode (e.g. after detach) */
11046 -       if (!kgdb_in_gdb_mode) {
11047 -               /* Do serial setup, notify user, issue preemptive ack */
11048 -               kgdb_serial_setup();
11049 -               KGDB_PRINTK("Waiting for GDB (on %s%d at %d baud)\n",
11050 -                           (kgdb_porttype ? kgdb_porttype->name : ""),
11051 -                           kgdb_portnum, kgdb_baud);
11052 -               kgdb_in_gdb_mode = 1;
11053 -               put_debug_char('+');
11054 -       }
11055 -
11056 -       /* Reply to host that an exception has occurred */
11057 -       sigval = compute_signal(excep_code);
11058 -       send_signal_msg(sigval);
11059 -
11060 -       /* TRAP_VEC exception indicates a software trap inserted in place of
11061 -          code by GDB so back up PC by one instruction, as this instruction
11062 -          will later be replaced by its original one.  Do NOT do this for
11063 -          trap 0xff, since that indicates a compiled-in breakpoint which
11064 -          will not be replaced (and we would retake the trap forever) */
11065 -       if ((excep_code == TRAP_VEC) && (trapa_value != (0xff << 2))) {
11066 -               trap_registers.pc -= 2;
11067 -       }
11068 -
11069 -       /* Undo any stepping we may have done */
11070 -       undo_single_step();
11071 -
11072 -       while (1) {
11073 -
11074 -               out_buffer[0] = 0;
11075 -               get_packet(in_buffer, BUFMAX);
11076 -
11077 -               /* Examine first char of buffer to see what we need to do */
11078 -               switch (in_buffer[0]) {
11079 -
11080 -               case '?':       /* Send which signal we've received */
11081 -                       send_signal_msg(sigval);
11082 -                       break;
11083 -
11084 -               case 'g':       /* Return the values of the CPU registers */
11085 -                       send_regs_msg();
11086 -                       break;
11087 -
11088 -               case 'G':       /* Set the value of the CPU registers */
11089 -                       set_regs_msg();
11090 -                       break;
11091 -
11092 -               case 'm':       /* Read LLLL bytes address AA..AA */
11093 -                       read_mem_msg();
11094 -                       break;
11095 -
11096 -               case 'M':       /* Write LLLL bytes address AA..AA, ret OK */
11097 -                       write_mem_msg(0);       /* 0 = data in hex */
11098 -                       break;
11099 -
11100 -               case 'X':       /* Write LLLL bytes esc bin address AA..AA */
11101 -                       if (kgdb_bits == '8')
11102 -                               write_mem_msg(1); /* 1 = data in binary */
11103 -                       else
11104 -                               send_empty_msg();
11105 -                       break;
11106 -
11107 -               case 'C':       /* Continue, signum included, we ignore it */
11108 -                       continue_with_sig_msg();
11109 -                       return;
11110 -
11111 -               case 'c':       /* Continue at address AA..AA (optional) */
11112 -                       continue_msg();
11113 -                       return;
11114 -
11115 -               case 'S':       /* Step, signum included, we ignore it */
11116 -                       step_with_sig_msg();
11117 -                       return;
11118 -
11119 -               case 's':       /* Step one instruction from AA..AA */
11120 -                       step_msg();
11121 -                       return;
11122 -
11123 -#ifdef CONFIG_KGDB_THREAD
11124 -
11125 -               case 'H':       /* Task related */
11126 -                       set_thread_msg();
11127 -                       break;
11128 -
11129 -               case 'T':       /* Query thread status */
11130 -                       thread_status_msg();
11131 -                       break;
11132 -
11133 -               case 'q':       /* Handle query - currently thread-related */
11134 -                       query_msg();
11135 -                       break;
11136 -#endif
11137 -
11138 -               case 'k':       /* 'Kill the program' with a kernel ? */
11139 -                       break;
11140 -
11141 -               case 'D':       /* Detach from program, send reply OK */
11142 -                       kgdb_in_gdb_mode = 0;
11143 -                       send_ok_msg();
11144 -                       get_debug_char();
11145 -                       return;
11146 -
11147 -               default:
11148 -                       send_empty_msg();
11149 -                       break;
11150 -               }
11151 -       }
11152 -}
11153 -
11154 -/* There has been an exception, most likely a breakpoint. */
11155 -void kgdb_handle_exception(struct pt_regs *regs)
11156 -{
11157 -       int excep_code, vbr_val;
11158 -       int count;
11159 -       int trapa_value = ctrl_inl(TRA);
11160 -
11161 -       /* Copy kernel regs (from stack) */
11162 -       for (count = 0; count < 16; count++)
11163 -               trap_registers.regs[count] = regs->regs[count];
11164 -       trap_registers.pc = regs->pc;
11165 -       trap_registers.pr = regs->pr;
11166 -       trap_registers.sr = regs->sr;
11167 -       trap_registers.gbr = regs->gbr;
11168 -       trap_registers.mach = regs->mach;
11169 -       trap_registers.macl = regs->macl;
11170 -
11171 -       asm("stc vbr, %0":"=r"(vbr_val));
11172 -       trap_registers.vbr = vbr_val;
11173 -
11174 -       /* Get excode for command loop call, user access */
11175 -       asm("stc r2_bank, %0":"=r"(excep_code));
11176 -       kgdb_excode = excep_code;
11177 -
11178 -       /* Other interesting environment items for reference */
11179 -       asm("stc r6_bank, %0":"=r"(kgdb_g_imask));
11180 -       kgdb_current = current;
11181 -       kgdb_trapa_val = trapa_value;
11182 -
11183 -       /* Act on the exception */
11184 -       kgdb_command_loop(excep_code >> 5, trapa_value);
11185 -
11186 -       kgdb_current = NULL;
11187 -
11188 -       /* Copy back the (maybe modified) registers */
11189 -       for (count = 0; count < 16; count++)
11190 -               regs->regs[count] = trap_registers.regs[count];
11191 -       regs->pc = trap_registers.pc;
11192 -       regs->pr = trap_registers.pr;
11193 -       regs->sr = trap_registers.sr;
11194 -       regs->gbr = trap_registers.gbr;
11195 -       regs->mach = trap_registers.mach;
11196 -       regs->macl = trap_registers.macl;
11197 -
11198 -       vbr_val = trap_registers.vbr;
11199 -       asm("ldc %0, vbr": :"r"(vbr_val));
11200 -
11201 -       return;
11202 -}
11203 -
11204 -/* Trigger a breakpoint by function */
11205 -void breakpoint(void)
11206 -{
11207 -       if (!kgdb_enabled) {
11208 -               kgdb_enabled = 1;
11209 -               kgdb_init();
11210 -       }
11211 -       BREAKPOINT();
11212 -}
11213 -
11214 -/* Initialise the KGDB data structures and serial configuration */
11215 -int kgdb_init(void)
11216 -{
11217 -       if (!kgdb_enabled)
11218 -               return 1;
11219 -
11220 -       in_nmi = 0;
11221 -       kgdb_nofault = 0;
11222 -       stepped_opcode = 0;
11223 -       kgdb_in_gdb_mode = 0;
11224 -
11225 -       if (kgdb_serial_setup() != 0) {
11226 -               KGDB_PRINTK("serial setup error\n");
11227 -               return -1;
11228 -       }
11229 -
11230 -       /* Init ptr to exception handler */
11231 -       kgdb_debug_hook = kgdb_handle_exception;
11232 -       kgdb_bus_err_hook = kgdb_handle_bus_error;
11233 -
11234 -       /* Enter kgdb now if requested, or just report init done */
11235 -       if (kgdb_halt) {
11236 -               kgdb_in_gdb_mode = 1;
11237 -               put_debug_char('+');
11238 -               breakpoint();
11239 -       }
11240 -       else
11241 -       {
11242 -               KGDB_PRINTK("stub is initialized.\n");
11243 -       }
11244 -
11245 -       return 0;
11246 -}
11247 -
11248 -/* Make function available for "user messages"; console will use it too. */
11249 -
11250 -char gdbmsgbuf[BUFMAX];
11251 -#define MAXOUT ((BUFMAX-2)/2)
11252 -
11253 -static void kgdb_msg_write(const char *s, unsigned count)
11254 -{
11255 -       int i;
11256 -       int wcount;
11257 -       char *bufptr;
11258 -
11259 -       /* 'O'utput */
11260 -       gdbmsgbuf[0] = 'O';
11261 -
11262 -       /* Fill and send buffers... */
11263 -       while (count > 0) {
11264 -               bufptr = gdbmsgbuf + 1;
11265 -
11266 -               /* Calculate how many this time */
11267 -               wcount = (count > MAXOUT) ? MAXOUT : count;
11268 -               
11269 -               /* Pack in hex chars */
11270 -               for (i = 0; i < wcount; i++)
11271 -                       bufptr = pack_hex_byte(bufptr, s[i]);
11272 -               *bufptr = '\0';
11273 -
11274 -               /* Move up */
11275 -               s += wcount;
11276 -               count -= wcount;
11277 -
11278 -               /* Write packet */
11279 -               put_packet(gdbmsgbuf);
11280 -       }
11281 -}
11282 -
11283 -static void kgdb_to_gdb(const char *s)
11284 -{
11285 -       kgdb_msg_write(s, strlen(s));
11286 -}
11287 -
11288 -#ifdef CONFIG_SH_KGDB_CONSOLE
11289 -void kgdb_console_write(struct console *co, const char *s, unsigned count)
11290 -{
11291 -       /* Bail if we're not talking to GDB */
11292 -       if (!kgdb_in_gdb_mode)
11293 -               return;
11294 -
11295 -       kgdb_msg_write(s, count);
11296 -}
11297 -#endif
11298 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/setup.c linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/setup.c
11299 --- linux-2.6.18-53.1.14/arch/sh/kernel/setup.c 2006-09-20 07:42:06.000000000 +0400
11300 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/setup.c    2008-06-10 15:38:50.000000000 +0400
11301 @@ -28,10 +28,6 @@
11302  #include <asm/setup.h>
11303  #include <asm/clock.h>
11304  
11305 -#ifdef CONFIG_SH_KGDB
11306 -#include <asm/kgdb.h>
11307 -static int kgdb_parse_options(char *options);
11308 -#endif
11309  extern void * __rd_start, * __rd_end;
11310  /*
11311   * Machine setup..
11312 @@ -528,93 +524,3 @@ struct seq_operations cpuinfo_op = {
11313         .show   = show_cpuinfo,
11314  };
11315  #endif /* CONFIG_PROC_FS */
11316 -
11317 -#ifdef CONFIG_SH_KGDB
11318 -/*
11319 - * Parse command-line kgdb options.  By default KGDB is enabled,
11320 - * entered on error (or other action) using default serial info.
11321 - * The command-line option can include a serial port specification
11322 - * and an action to override default or configured behavior.
11323 - */
11324 -struct kgdb_sermap kgdb_sci_sermap =
11325 -{ "ttySC", 5, kgdb_sci_setup, NULL };
11326 -
11327 -struct kgdb_sermap *kgdb_serlist = &kgdb_sci_sermap;
11328 -struct kgdb_sermap *kgdb_porttype = &kgdb_sci_sermap;
11329 -
11330 -void kgdb_register_sermap(struct kgdb_sermap *map)
11331 -{
11332 -       struct kgdb_sermap *last;
11333 -
11334 -       for (last = kgdb_serlist; last->next; last = last->next)
11335 -               ;
11336 -       last->next = map;
11337 -       if (!map->namelen) {
11338 -               map->namelen = strlen(map->name);
11339 -       }
11340 -}
11341 -
11342 -static int __init kgdb_parse_options(char *options)
11343 -{
11344 -       char c;
11345 -       int baud;
11346 -
11347 -       /* Check for port spec (or use default) */
11348 -
11349 -       /* Determine port type and instance */
11350 -       if (!memcmp(options, "tty", 3)) {
11351 -               struct kgdb_sermap *map = kgdb_serlist;
11352 -
11353 -               while (map && memcmp(options, map->name, map->namelen))
11354 -                       map = map->next;
11355 -
11356 -               if (!map) {
11357 -                       KGDB_PRINTK("unknown port spec in %s\n", options);
11358 -                       return -1;
11359 -               }
11360 -
11361 -               kgdb_porttype = map;
11362 -               kgdb_serial_setup = map->setup_fn;
11363 -               kgdb_portnum = options[map->namelen] - '0';
11364 -               options += map->namelen + 1;
11365 -
11366 -               options = (*options == ',') ? options+1 : options;
11367 -
11368 -               /* Read optional parameters (baud/parity/bits) */
11369 -               baud = simple_strtoul(options, &options, 10);
11370 -               if (baud != 0) {
11371 -                       kgdb_baud = baud;
11372 -
11373 -                       c = toupper(*options);
11374 -                       if (c == 'E' || c == 'O' || c == 'N') {
11375 -                               kgdb_parity = c;
11376 -                               options++;
11377 -                       }
11378 -
11379 -                       c = *options;
11380 -                       if (c == '7' || c == '8') {
11381 -                               kgdb_bits = c;
11382 -                               options++;
11383 -                       }
11384 -                       options = (*options == ',') ? options+1 : options;
11385 -               }
11386 -       }
11387 -
11388 -       /* Check for action specification */
11389 -       if (!memcmp(options, "halt", 4)) {
11390 -               kgdb_halt = 1;
11391 -               options += 4;
11392 -       } else if (!memcmp(options, "disabled", 8)) {
11393 -               kgdb_enabled = 0;
11394 -               options += 8;
11395 -       }
11396 -
11397 -       if (*options) {
11398 -                KGDB_PRINTK("ignored unknown options: %s\n", options);
11399 -               return 0;
11400 -       }
11401 -       return 1;
11402 -}
11403 -__setup("kgdb=", kgdb_parse_options);
11404 -#endif /* CONFIG_SH_KGDB */
11405 -
11406 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/time.c linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/time.c
11407 --- linux-2.6.18-53.1.14/arch/sh/kernel/time.c  2006-09-20 07:42:06.000000000 +0400
11408 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/time.c     2008-06-10 15:38:50.000000000 +0400
11409 @@ -184,12 +184,4 @@ void __init time_init(void)
11410          */
11411         sys_timer = get_sys_timer();
11412         printk(KERN_INFO "Using %s for system timer\n", sys_timer->name);
11413 -
11414 -#if defined(CONFIG_SH_KGDB)
11415 -       /*
11416 -        * Set up kgdb as requested. We do it here because the serial
11417 -        * init uses the timer vars we just set up for figuring baud.
11418 -        */
11419 -       kgdb_init();
11420 -#endif
11421  }
11422 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/kernel/traps.c linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/traps.c
11423 --- linux-2.6.18-53.1.14/arch/sh/kernel/traps.c 2006-09-20 07:42:06.000000000 +0400
11424 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/kernel/traps.c    2008-06-10 15:38:50.000000000 +0400
11425 @@ -26,6 +26,7 @@
11426  #include <linux/spinlock.h>
11427  #include <linux/module.h>
11428  #include <linux/kallsyms.h>
11429 +#include <linux/kgdb.h>
11430  
11431  #include <asm/system.h>
11432  #include <asm/uaccess.h>
11433 @@ -34,17 +35,8 @@
11434  #include <asm/processor.h>
11435  #include <asm/sections.h>
11436  
11437 -#ifdef CONFIG_SH_KGDB
11438 -#include <asm/kgdb.h>
11439 -#define CHK_REMOTE_DEBUG(regs)                                               \
11440 -{                                                                            \
11441 -  if ((kgdb_debug_hook != (kgdb_debug_hook_t *) NULL) && (!user_mode(regs))) \
11442 -  {                                                                          \
11443 -    (*kgdb_debug_hook)(regs);                                                \
11444 -  }                                                                          \
11445 -}
11446 -#else
11447 -#define CHK_REMOTE_DEBUG(regs)
11448 +#ifndef CONFIG_KGDB
11449 +#define kgdb_handle_exception(t, s, e, r)
11450  #endif
11451  
11452  #define DO_ERROR(trapnr, signr, str, name, tsk)                                \
11453 @@ -65,7 +57,7 @@ asmlinkage void do_##name(unsigned long 
11454         local_irq_enable();                                             \
11455         tsk->thread.error_code = error_code;                            \
11456         tsk->thread.trap_no = trapnr;                                   \
11457 -        CHK_REMOTE_DEBUG(&regs);                                       \
11458 +       kgdb_handle_exception(trapnr, signr, error_code, &regs);        \
11459         force_sig(signr, tsk);                                          \
11460         die_if_no_fixup(str,&regs,error_code);                          \
11461  }
11462 @@ -92,10 +84,12 @@ void die(const char * str, struct pt_reg
11463  {
11464         static int die_counter;
11465  
11466 +#ifdef CONFIG_KGDB
11467 +       kgdb_handle_exception(1, SIGTRAP, err, regs);
11468 +#endif
11469         console_verbose();
11470         spin_lock_irq(&die_lock);
11471         printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
11472 -       CHK_REMOTE_DEBUG(regs);
11473         show_regs(regs);
11474         spin_unlock_irq(&die_lock);
11475         do_exit(SIGSEGV);
11476 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/mm/extable.c linux-2.6.18-53.1.14.kgdb/arch/sh/mm/extable.c
11477 --- linux-2.6.18-53.1.14/arch/sh/mm/extable.c   2006-09-20 07:42:06.000000000 +0400
11478 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/mm/extable.c      2008-06-10 15:38:50.000000000 +0400
11479 @@ -5,6 +5,7 @@
11480   */
11481  
11482  #include <linux/module.h>
11483 +#include <linux/kgdb.h>
11484  #include <asm/uaccess.h>
11485  
11486  int fixup_exception(struct pt_regs *regs)
11487 @@ -16,6 +17,12 @@ int fixup_exception(struct pt_regs *regs
11488                 regs->pc = fixup->fixup;
11489                 return 1;
11490         }
11491 +#ifdef CONFIG_KGDB
11492 +       if (atomic_read(&debugger_active) && kgdb_may_fault)
11493 +               /* Restore our previous state. */
11494 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
11495 +               /* Never reached. */
11496 +#endif
11497  
11498         return 0;
11499  }
11500 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/mm/fault-nommu.c linux-2.6.18-53.1.14.kgdb/arch/sh/mm/fault-nommu.c
11501 --- linux-2.6.18-53.1.14/arch/sh/mm/fault-nommu.c       2006-09-20 07:42:06.000000000 +0400
11502 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/mm/fault-nommu.c  2008-06-10 15:38:50.000000000 +0400
11503 @@ -29,10 +29,6 @@
11504  #include <asm/mmu_context.h>
11505  #include <asm/cacheflush.h>
11506  
11507 -#if defined(CONFIG_SH_KGDB)
11508 -#include <asm/kgdb.h>
11509 -#endif
11510 -
11511  extern void die(const char *,struct pt_regs *,long);
11512  
11513  /*
11514 @@ -43,11 +39,6 @@ extern void die(const char *,struct pt_r
11515  asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long writeaccess,
11516                               unsigned long address)
11517  {
11518 -#if defined(CONFIG_SH_KGDB)
11519 -       if (kgdb_nofault && kgdb_bus_err_hook)
11520 -               kgdb_bus_err_hook();
11521 -#endif
11522 -
11523         /*
11524          * Oops. The kernel tried to access some bad page. We'll have to
11525          * terminate things with extreme prejudice.
11526 @@ -69,11 +60,6 @@ asmlinkage void do_page_fault(struct pt_
11527  asmlinkage int __do_page_fault(struct pt_regs *regs, unsigned long writeaccess,
11528                                unsigned long address)
11529  {
11530 -#if defined(CONFIG_SH_KGDB)
11531 -       if (kgdb_nofault && kgdb_bus_err_hook)
11532 -               kgdb_bus_err_hook();
11533 -#endif
11534 -
11535         if (address >= TASK_SIZE)
11536                 return 1;
11537  
11538 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/sh/mm/fault.c linux-2.6.18-53.1.14.kgdb/arch/sh/mm/fault.c
11539 --- linux-2.6.18-53.1.14/arch/sh/mm/fault.c     2006-09-20 07:42:06.000000000 +0400
11540 +++ linux-2.6.18-53.1.14.kgdb/arch/sh/mm/fault.c        2008-06-10 15:38:50.000000000 +0400
11541 @@ -28,7 +28,6 @@
11542  #include <asm/pgalloc.h>
11543  #include <asm/mmu_context.h>
11544  #include <asm/cacheflush.h>
11545 -#include <asm/kgdb.h>
11546  
11547  extern void die(const char *,struct pt_regs *,long);
11548  
11549 @@ -45,11 +44,6 @@ asmlinkage void do_page_fault(struct pt_
11550         struct vm_area_struct * vma;
11551         unsigned long page;
11552  
11553 -#ifdef CONFIG_SH_KGDB
11554 -       if (kgdb_nofault && kgdb_bus_err_hook)
11555 -               kgdb_bus_err_hook();
11556 -#endif
11557 -
11558         tsk = current;
11559         mm = tsk->mm;
11560  
11561 @@ -153,6 +147,7 @@ no_context:
11562         }
11563         die("Oops", regs, writeaccess);
11564         do_exit(SIGKILL);
11565 +       dump_stack();
11566  
11567  /*
11568   * We ran out of memory, or some other thing happened to us that made
11569 @@ -202,11 +197,6 @@ asmlinkage int __do_page_fault(struct pt
11570         spinlock_t *ptl;
11571         int ret = 1;
11572  
11573 -#ifdef CONFIG_SH_KGDB
11574 -       if (kgdb_nofault && kgdb_bus_err_hook)
11575 -               kgdb_bus_err_hook();
11576 -#endif
11577 -
11578  #ifdef CONFIG_SH_STORE_QUEUES
11579         addrmax = P4SEG_STORE_QUE + 0x04000000;
11580  #endif
11581 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/x86_64/Kconfig.debug linux-2.6.18-53.1.14.kgdb/arch/x86_64/Kconfig.debug
11582 --- linux-2.6.18-53.1.14/arch/x86_64/Kconfig.debug      2006-09-20 07:42:06.000000000 +0400
11583 +++ linux-2.6.18-53.1.14.kgdb/arch/x86_64/Kconfig.debug 2008-06-10 15:38:44.000000000 +0400
11584 @@ -55,7 +55,4 @@ config DEBUG_STACK_USAGE
11585  
11586           This option will slow down process creation somewhat.
11587  
11588 -#config X86_REMOTE_DEBUG
11589 -#       bool "kgdb debugging stub"
11590 -
11591  endmenu
11592 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/x86_64/kernel/Makefile linux-2.6.18-53.1.14.kgdb/arch/x86_64/kernel/Makefile
11593 --- linux-2.6.18-53.1.14/arch/x86_64/kernel/Makefile    2008-03-06 05:54:48.000000000 +0300
11594 +++ linux-2.6.18-53.1.14.kgdb/arch/x86_64/kernel/Makefile       2008-06-10 15:38:44.000000000 +0400
11595 @@ -35,6 +35,7 @@ obj-$(CONFIG_IOMMU)           += pci-gart.o apert
11596  obj-$(CONFIG_CALGARY_IOMMU)    += pci-calgary.o tce.o
11597  obj-$(CONFIG_SWIOTLB)          += pci-swiotlb.o
11598  obj-$(CONFIG_KPROBES)          += kprobes.o
11599 +obj-$(CONFIG_KGDB)             += kgdb.o kgdb-jmp.o
11600  obj-$(CONFIG_X86_PM_TIMER)     += pmtimer.o
11601  obj-$(CONFIG_X86_VSMP)         += vsmp.o
11602  obj-$(CONFIG_K8_NB)            += k8.o
11603 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/x86_64/kernel/entry.S linux-2.6.18-53.1.14.kgdb/arch/x86_64/kernel/entry.S
11604 --- linux-2.6.18-53.1.14/arch/x86_64/kernel/entry.S     2008-03-06 05:54:50.000000000 +0300
11605 +++ linux-2.6.18-53.1.14.kgdb/arch/x86_64/kernel/entry.S        2008-06-10 15:39:01.000000000 +0400
11606 @@ -42,6 +42,7 @@
11607  #include <asm/hw_irq.h>
11608  #include <asm/page.h>
11609  #include <asm/irqflags.h>
11610 +#include <asm/kgdb.h>
11611  
11612         .code64
11613  
11614 @@ -887,6 +888,7 @@ error_exit:         
11615         RESTORE_ARGS 0,8,0                                              
11616         jmp iret_label
11617         CFI_ENDPROC
11618 +       CFI_END_FRAME(kernel_thread)
11619  
11620  error_kernelspace:
11621         incl %ebx
11622 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/x86_64/kernel/kgdb-jmp.S linux-2.6.18-53.1.14.kgdb/arch/x86_64/kernel/kgdb-jmp.S
11623 --- linux-2.6.18-53.1.14/arch/x86_64/kernel/kgdb-jmp.S  1970-01-01 03:00:00.000000000 +0300
11624 +++ linux-2.6.18-53.1.14.kgdb/arch/x86_64/kernel/kgdb-jmp.S     2008-06-10 15:38:44.000000000 +0400
11625 @@ -0,0 +1,65 @@
11626 +/*
11627 + * arch/x86_64/kernel/kgdb-jmp.S
11628 + *
11629 + * Save and restore system registers so that within a limited frame we
11630 + * may have a fault and "jump back" to a known safe location.
11631 + *
11632 + * Author: Tom Rini <trini@kernel.crashing.org>
11633 + *
11634 + * Cribbed from glibc, which carries the following:
11635 + * Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
11636 + * Copyright (C) 2005 by MontaVista Software.
11637 + *
11638 + * This file is licensed under the terms of the GNU General Public License
11639 + * version 2. This program as licensed "as is" without any warranty of
11640 + * any kind, whether express or implied.
11641 + */
11642 +
11643 +#include <linux/linkage.h>
11644 +
11645 +#define JB_RBX         0
11646 +#define JB_RBP         1
11647 +#define JB_R12         2
11648 +#define JB_R13         3
11649 +#define JB_R14         4
11650 +#define JB_R15         5
11651 +#define JB_RSP         6
11652 +#define JB_PC          7
11653 +
11654 +       .code64
11655 +
11656 +/* This must be called prior to kgdb_fault_longjmp and
11657 + * kgdb_fault_longjmp must not be called outside of the context of the
11658 + * last call to kgdb_fault_setjmp.
11659 + */
11660 +ENTRY(kgdb_fault_setjmp)
11661 +       /* Save registers. */
11662 +       movq %rbx, (JB_RBX*8)(%rdi)
11663 +       movq %rbp, (JB_RBP*8)(%rdi)
11664 +       movq %r12, (JB_R12*8)(%rdi)
11665 +       movq %r13, (JB_R13*8)(%rdi)
11666 +       movq %r14, (JB_R14*8)(%rdi)
11667 +       movq %r15, (JB_R15*8)(%rdi)
11668 +       leaq 8(%rsp), %rdx      /* Save SP as it will be after we return. */
11669 +       movq %rdx, (JB_RSP*8)(%rdi)
11670 +       movq (%rsp), %rax       /* Save PC we are returning to now. */
11671 +       movq %rax, (JB_PC*8)(%rdi)
11672 +       /* Set return value for setjmp. */
11673 +       mov $0,%eax
11674 +       movq (JB_PC*8)(%rdi),%rdx
11675 +       movq (JB_RSP*8)(%rdi),%rsp
11676 +       jmpq *%rdx
11677 +
11678 +ENTRY(kgdb_fault_longjmp)
11679 +       /* Restore registers. */
11680 +       movq (JB_RBX*8)(%rdi),%rbx
11681 +       movq (JB_RBP*8)(%rdi),%rbp
11682 +       movq (JB_R12*8)(%rdi),%r12
11683 +       movq (JB_R13*8)(%rdi),%r13
11684 +       movq (JB_R14*8)(%rdi),%r14
11685 +       movq (JB_R15*8)(%rdi),%r15
11686 +       /* Set return value for setjmp. */
11687 +       movq (JB_PC*8)(%rdi),%rdx
11688 +       movq (JB_RSP*8)(%rdi),%rsp
11689 +       mov $1,%eax
11690 +       jmpq *%rdx
11691 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/x86_64/kernel/kgdb.c linux-2.6.18-53.1.14.kgdb/arch/x86_64/kernel/kgdb.c
11692 --- linux-2.6.18-53.1.14/arch/x86_64/kernel/kgdb.c      1970-01-01 03:00:00.000000000 +0300
11693 +++ linux-2.6.18-53.1.14.kgdb/arch/x86_64/kernel/kgdb.c 2008-06-10 15:38:44.000000000 +0400
11694 @@ -0,0 +1,474 @@
11695 +/*
11696 + *
11697 + * This program is free software; you can redistribute it and/or modify it
11698 + * under the terms of the GNU General Public License as published by the
11699 + * Free Software Foundation; either version 2, or (at your option) any
11700 + * later version.
11701 + *
11702 + * This program is distributed in the hope that it will be useful, but
11703 + * WITHOUT ANY WARRANTY; without even the implied warranty of
11704 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11705 + * General Public License for more details.
11706 + *
11707 + */
11708 +
11709 +/*
11710 + * Copyright (C) 2004 Amit S. Kale <amitkale@linsyssoft.com>
11711 + * Copyright (C) 2000-2001 VERITAS Software Corporation.
11712 + * Copyright (C) 2002 Andi Kleen, SuSE Labs
11713 + * Copyright (C) 2004 LinSysSoft Technologies Pvt. Ltd.
11714 + */
11715 +/****************************************************************************
11716 + *  Contributor:     Lake Stevens Instrument Division$
11717 + *  Written by:      Glenn Engel $
11718 + *  Updated by:             Amit Kale<akale@veritas.com>
11719 + *  Modified for 386 by Jim Kingdon, Cygnus Support.
11720 + *  Origianl kgdb, compatibility with 2.1.xx kernel by
11721 + *  David Grothe <dave@gcom.com>
11722 + *  Integrated into 2.2.5 kernel by Tigran Aivazian <tigran@sco.com>
11723 + *  X86_64 changes from Andi Kleen's patch merged by Jim Houston
11724 + */
11725 +
11726 +#include <linux/string.h>
11727 +#include <linux/kernel.h>
11728 +#include <linux/sched.h>
11729 +#include <linux/smp.h>
11730 +#include <linux/spinlock.h>
11731 +#include <linux/delay.h>
11732 +#include <asm/system.h>
11733 +#include <asm/ptrace.h>                /* for linux pt_regs struct */
11734 +#include <linux/kgdb.h>
11735 +#include <linux/init.h>
11736 +#include <asm/apicdef.h>
11737 +#include <asm/mach_apic.h>
11738 +#include <asm/kdebug.h>
11739 +#include <asm/debugreg.h>
11740 +
11741 +/* Put the error code here just in case the user cares.  */
11742 +int gdb_x86_64errcode;
11743 +/* Likewise, the vector number here (since GDB only gets the signal
11744 +   number through the usual means, and that's not very specific).  */
11745 +int gdb_x86_64vector = -1;
11746 +
11747 +extern atomic_t cpu_doing_single_step;
11748 +
11749 +void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
11750 +{
11751 +       gdb_regs[_RAX] = regs->rax;
11752 +       gdb_regs[_RBX] = regs->rbx;
11753 +       gdb_regs[_RCX] = regs->rcx;
11754 +       gdb_regs[_RDX] = regs->rdx;
11755 +       gdb_regs[_RSI] = regs->rsi;
11756 +       gdb_regs[_RDI] = regs->rdi;
11757 +       gdb_regs[_RBP] = regs->rbp;
11758 +       gdb_regs[_PS] = regs->eflags;
11759 +       gdb_regs[_PC] = regs->rip;
11760 +       gdb_regs[_R8] = regs->r8;
11761 +       gdb_regs[_R9] = regs->r9;
11762 +       gdb_regs[_R10] = regs->r10;
11763 +       gdb_regs[_R11] = regs->r11;
11764 +       gdb_regs[_R12] = regs->r12;
11765 +       gdb_regs[_R13] = regs->r13;
11766 +       gdb_regs[_R14] = regs->r14;
11767 +       gdb_regs[_R15] = regs->r15;
11768 +       gdb_regs[_RSP] = regs->rsp;
11769 +}
11770 +
11771 +extern void thread_return(void);
11772 +void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
11773 +{
11774 +       gdb_regs[_RAX] = 0;
11775 +       gdb_regs[_RBX] = 0;
11776 +       gdb_regs[_RCX] = 0;
11777 +       gdb_regs[_RDX] = 0;
11778 +       gdb_regs[_RSI] = 0;
11779 +       gdb_regs[_RDI] = 0;
11780 +       gdb_regs[_RBP] = *(unsigned long *)p->thread.rsp;
11781 +       gdb_regs[_PS] = *(unsigned long *)(p->thread.rsp + 8);
11782 +       gdb_regs[_PC] = (unsigned long)&thread_return;
11783 +       gdb_regs[_R8] = 0;
11784 +       gdb_regs[_R9] = 0;
11785 +       gdb_regs[_R10] = 0;
11786 +       gdb_regs[_R11] = 0;
11787 +       gdb_regs[_R12] = 0;
11788 +       gdb_regs[_R13] = 0;
11789 +       gdb_regs[_R14] = 0;
11790 +       gdb_regs[_R15] = 0;
11791 +       gdb_regs[_RSP] = p->thread.rsp;
11792 +}
11793 +
11794 +void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)
11795 +{
11796 +       regs->rax = gdb_regs[_RAX];
11797 +       regs->rbx = gdb_regs[_RBX];
11798 +       regs->rcx = gdb_regs[_RCX];
11799 +       regs->rdx = gdb_regs[_RDX];
11800 +       regs->rsi = gdb_regs[_RSI];
11801 +       regs->rdi = gdb_regs[_RDI];
11802 +       regs->rbp = gdb_regs[_RBP];
11803 +       regs->eflags = gdb_regs[_PS];
11804 +       regs->rip = gdb_regs[_PC];
11805 +       regs->r8 = gdb_regs[_R8];
11806 +       regs->r9 = gdb_regs[_R9];
11807 +       regs->r10 = gdb_regs[_R10];
11808 +       regs->r11 = gdb_regs[_R11];
11809 +       regs->r12 = gdb_regs[_R12];
11810 +       regs->r13 = gdb_regs[_R13];
11811 +       regs->r14 = gdb_regs[_R14];
11812 +       regs->r15 = gdb_regs[_R15];
11813 +#if 0                          /* can't change these */
11814 +       regs->rsp = gdb_regs[_RSP];
11815 +       regs->ss = gdb_regs[_SS];
11816 +       regs->fs = gdb_regs[_FS];
11817 +       regs->gs = gdb_regs[_GS];
11818 +#endif
11819 +
11820 +}                              /* gdb_regs_to_regs */
11821 +
11822 +struct hw_breakpoint {
11823 +       unsigned enabled;
11824 +       unsigned type;
11825 +       unsigned len;
11826 +       unsigned long addr;
11827 +} breakinfo[4] = { {
11828 +enabled:0}, {
11829 +enabled:0}, {
11830 +enabled:0}, {
11831 +enabled:0}};
11832 +
11833 +void kgdb_correct_hw_break(void)
11834 +{
11835 +       int breakno;
11836 +       int correctit;
11837 +       int breakbit;
11838 +       unsigned long dr7;
11839 +
11840 +       asm volatile ("movq %%db7, %0\n":"=r" (dr7):);
11841 +       do {
11842 +               unsigned long addr0, addr1, addr2, addr3;
11843 +               asm volatile ("movq %%db0, %0\n"
11844 +                             "movq %%db1, %1\n"
11845 +                             "movq %%db2, %2\n"
11846 +                             "movq %%db3, %3\n":"=r" (addr0), "=r"(addr1),
11847 +                             "=r"(addr2), "=r"(addr3):);
11848 +       } while (0);
11849 +       correctit = 0;
11850 +       for (breakno = 0; breakno < 3; breakno++) {
11851 +               breakbit = 2 << (breakno << 1);
11852 +               if (!(dr7 & breakbit) && breakinfo[breakno].enabled) {
11853 +                       correctit = 1;
11854 +                       dr7 |= breakbit;
11855 +                       dr7 &= ~(0xf0000 << (breakno << 2));
11856 +                       dr7 |= (((breakinfo[breakno].len << 2) |
11857 +                                breakinfo[breakno].type) << 16) <<
11858 +                           (breakno << 2);
11859 +                       switch (breakno) {
11860 +                       case 0:
11861 +                               asm volatile ("movq %0, %%dr0\n"::"r"
11862 +                                             (breakinfo[breakno].addr));
11863 +                               break;
11864 +
11865 +                       case 1:
11866 +                               asm volatile ("movq %0, %%dr1\n"::"r"
11867 +                                             (breakinfo[breakno].addr));
11868 +                               break;
11869 +
11870 +                       case 2:
11871 +                               asm volatile ("movq %0, %%dr2\n"::"r"
11872 +                                             (breakinfo[breakno].addr));
11873 +                               break;
11874 +
11875 +                       case 3:
11876 +                               asm volatile ("movq %0, %%dr3\n"::"r"
11877 +                                             (breakinfo[breakno].addr));
11878 +                               break;
11879 +                       }
11880 +               } else if ((dr7 & breakbit) && !breakinfo[breakno].enabled) {
11881 +                       correctit = 1;
11882 +                       dr7 &= ~breakbit;
11883 +                       dr7 &= ~(0xf0000 << (breakno << 2));
11884 +               }
11885 +       }
11886 +       if (correctit) {
11887 +               asm volatile ("movq %0, %%db7\n"::"r" (dr7));
11888 +       }
11889 +}
11890 +
11891 +int kgdb_remove_hw_break(unsigned long addr)
11892 +{
11893 +       int i, idx = -1;
11894 +       for (i = 0; i < 4; i++) {
11895 +               if (breakinfo[i].addr == addr && breakinfo[i].enabled) {
11896 +                       idx = i;
11897 +                       break;
11898 +               }
11899 +       }
11900 +       if (idx == -1)
11901 +               return -1;
11902 +
11903 +       breakinfo[idx].enabled = 0;
11904 +       return 0;
11905 +}
11906 +
11907 +int kgdb_set_hw_break(unsigned long addr)
11908 +{
11909 +       int i, idx = -1;
11910 +       for (i = 0; i < 4; i++) {
11911 +               if (!breakinfo[i].enabled) {
11912 +                       idx = i;
11913 +                       break;
11914 +               }
11915 +       }
11916 +       if (idx == -1)
11917 +               return -1;
11918 +
11919 +       breakinfo[idx].enabled = 1;
11920 +       breakinfo[idx].type = 1;
11921 +       breakinfo[idx].len = 1;
11922 +       breakinfo[idx].addr = addr;
11923 +       return 0;
11924 +}
11925 +
11926 +int remove_hw_break(unsigned breakno)
11927 +{
11928 +       if (!breakinfo[breakno].enabled) {
11929 +               return -1;
11930 +       }
11931 +       breakinfo[breakno].enabled = 0;
11932 +       return 0;
11933 +}
11934 +
11935 +int set_hw_break(unsigned breakno, unsigned type, unsigned len, unsigned addr)
11936 +{
11937 +       if (breakinfo[breakno].enabled) {
11938 +               return -1;
11939 +       }
11940 +       breakinfo[breakno].enabled = 1;
11941 +       breakinfo[breakno].type = type;
11942 +       breakinfo[breakno].len = len;
11943 +       breakinfo[breakno].addr = addr;
11944 +       return 0;
11945 +}
11946 +
11947 +void kgdb_disable_hw_debug(struct pt_regs *regs)
11948 +{
11949 +       /* Disable hardware debugging while we are in kgdb */
11950 +       asm volatile ("movq %0,%%db7": /* no output */ :"r" (0UL));
11951 +}
11952 +
11953 +void kgdb_post_master_code(struct pt_regs *regs, int e_vector, int err_code)
11954 +{
11955 +       /* Master processor is completely in the debugger */
11956 +       gdb_x86_64vector = e_vector;
11957 +       gdb_x86_64errcode = err_code;
11958 +}
11959 +
11960 +void kgdb_roundup_cpus(unsigned long flags)
11961 +{
11962 +       send_IPI_allbutself(APIC_DM_NMI);
11963 +}
11964 +
11965 +int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
11966 +                              char *remcomInBuffer, char *remcomOutBuffer,
11967 +                              struct pt_regs *linux_regs)
11968 +{
11969 +       unsigned long addr, length;
11970 +       unsigned long breakno, breaktype;
11971 +       char *ptr;
11972 +       int newPC;
11973 +       unsigned long dr6;
11974 +
11975 +       switch (remcomInBuffer[0]) {
11976 +       case 'c':
11977 +       case 's':
11978 +               /* try to read optional parameter, pc unchanged if no parm */
11979 +               ptr = &remcomInBuffer[1];
11980 +               if (kgdb_hex2long(&ptr, &addr))
11981 +                       linux_regs->rip = addr;
11982 +               newPC = linux_regs->rip;
11983 +
11984 +               /* clear the trace bit */
11985 +               linux_regs->eflags &= ~TF_MASK;
11986 +
11987 +               atomic_set(&cpu_doing_single_step, -1);
11988 +               /* set the trace bit if we're stepping */
11989 +               if (remcomInBuffer[0] == 's') {
11990 +                       linux_regs->eflags |= TF_MASK;
11991 +                       debugger_step = 1;
11992 +                       if (kgdb_contthread)
11993 +                               atomic_set(&cpu_doing_single_step,
11994 +                                          smp_processor_id());
11995 +
11996 +               }
11997 +
11998 +               asm volatile ("movq %%db6, %0\n":"=r" (dr6));
11999 +               if (!(dr6 & 0x4000)) {
12000 +                       for (breakno = 0; breakno < 4; ++breakno) {
12001 +                               if (dr6 & (1 << breakno)) {
12002 +                                       if (breakinfo[breakno].type == 0) {
12003 +                                               /* Set restore flag */
12004 +                                               linux_regs->eflags |=
12005 +                                                   X86_EFLAGS_RF;
12006 +                                               break;
12007 +                                       }
12008 +                               }
12009 +                       }
12010 +               }
12011 +               kgdb_correct_hw_break();
12012 +               asm volatile ("movq %0, %%db6\n"::"r" (0UL));
12013 +
12014 +               return (0);
12015 +
12016 +       case 'Y':
12017 +               ptr = &remcomInBuffer[1];
12018 +               kgdb_hex2long(&ptr, &breakno);
12019 +               ptr++;
12020 +               kgdb_hex2long(&ptr, &breaktype);
12021 +               ptr++;
12022 +               kgdb_hex2long(&ptr, &length);
12023 +               ptr++;
12024 +               kgdb_hex2long(&ptr, &addr);
12025 +               if (set_hw_break(breakno & 0x3, breaktype & 0x3,
12026 +                                length & 0x3, addr) == 0)
12027 +                       strcpy(remcomOutBuffer, "OK");
12028 +               else
12029 +                       strcpy(remcomOutBuffer, "ERROR");
12030 +               break;
12031 +
12032 +               /* Remove hardware breakpoint */
12033 +       case 'y':
12034 +               ptr = &remcomInBuffer[1];
12035 +               kgdb_hex2long(&ptr, &breakno);
12036 +               if (remove_hw_break(breakno & 0x3) == 0)
12037 +                       strcpy(remcomOutBuffer, "OK");
12038 +               else
12039 +                       strcpy(remcomOutBuffer, "ERROR");
12040 +               break;
12041 +
12042 +       }                       /* switch */
12043 +       return -1;
12044 +}
12045 +
12046 +static struct pt_regs *in_interrupt_stack(unsigned long rsp, int cpu)
12047 +{
12048 +       struct pt_regs *regs;
12049 +       unsigned long end = (unsigned long)cpu_pda(cpu)->irqstackptr;
12050 +       if (rsp <= end && rsp >= end - IRQSTACKSIZE + 8) {
12051 +               regs = *(((struct pt_regs **)end) - 1);
12052 +               return regs;
12053 +       }
12054 +       return NULL;
12055 +}
12056 +
12057 +static struct pt_regs *in_exception_stack(unsigned long rsp, int cpu)
12058 +{
12059 +       int i;
12060 +       struct tss_struct *init_tss = &__get_cpu_var(init_tss);
12061 +       for (i = 0; i < N_EXCEPTION_STACKS; i++)
12062 +               if (rsp >= init_tss[cpu].ist[i] &&
12063 +                   rsp <= init_tss[cpu].ist[i] + EXCEPTION_STKSZ) {
12064 +                       struct pt_regs *r =
12065 +                           (void *)init_tss[cpu].ist[i] + EXCEPTION_STKSZ;
12066 +                       return r - 1;
12067 +               }
12068 +       return NULL;
12069 +}
12070 +
12071 +void kgdb_shadowinfo(struct pt_regs *regs, char *buffer, unsigned threadid)
12072 +{
12073 +       static char intr_desc[] = "Stack at interrupt entrypoint";
12074 +       static char exc_desc[] = "Stack at exception entrypoint";
12075 +       struct pt_regs *stregs;
12076 +       int cpu = hard_smp_processor_id();
12077 +
12078 +       if ((stregs = in_interrupt_stack(regs->rsp, cpu)))
12079 +               kgdb_mem2hex(intr_desc, buffer, strlen(intr_desc));
12080 +       else if ((stregs = in_exception_stack(regs->rsp, cpu)))
12081 +               kgdb_mem2hex(exc_desc, buffer, strlen(exc_desc));
12082 +}
12083 +
12084 +struct task_struct *kgdb_get_shadow_thread(struct pt_regs *regs, int threadid)
12085 +{
12086 +       struct pt_regs *stregs;
12087 +       int cpu = hard_smp_processor_id();
12088 +
12089 +       if ((stregs = in_interrupt_stack(regs->rsp, cpu)))
12090 +               return current;
12091 +       else if ((stregs = in_exception_stack(regs->rsp, cpu)))
12092 +               return current;
12093 +
12094 +       return NULL;
12095 +}
12096 +
12097 +struct pt_regs *kgdb_shadow_regs(struct pt_regs *regs, int threadid)
12098 +{
12099 +       struct pt_regs *stregs;
12100 +       int cpu = hard_smp_processor_id();
12101 +
12102 +       if ((stregs = in_interrupt_stack(regs->rsp, cpu)))
12103 +               return stregs;
12104 +       else if ((stregs = in_exception_stack(regs->rsp, cpu)))
12105 +               return stregs;
12106 +
12107 +       return NULL;
12108 +}
12109 +
12110 +/* Register KGDB with the die_chain so that we hook into all of the right
12111 + * spots. */
12112 +static int kgdb_notify(struct notifier_block *self, unsigned long cmd,
12113 +                      void *ptr)
12114 +{
12115 +       struct die_args *args = ptr;
12116 +       struct pt_regs *regs = args->regs;
12117 +
12118 +       if (cmd == DIE_PAGE_FAULT_NO_CONTEXT && atomic_read(&debugger_active)
12119 +                       && kgdb_may_fault) {
12120 +               kgdb_fault_longjmp(kgdb_fault_jmp_regs);
12121 +               return NOTIFY_STOP;
12122 +       /* CPU roundup? */
12123 +       } else if (atomic_read(&debugger_active) && cmd == DIE_NMI_IPI) {
12124 +               kgdb_nmihook(smp_processor_id(), regs);
12125 +               return NOTIFY_STOP;
12126 +               /* See if KGDB is interested. */
12127 +       } else if (cmd == DIE_PAGE_FAULT || user_mode(regs) ||
12128 +                  cmd == DIE_NMI_IPI || (cmd == DIE_DEBUG &&
12129 +                                         atomic_read(&debugger_active)))
12130 +               /* Userpace events, normal watchdog event, or spurious
12131 +                * debug exception.  Ignore. */
12132 +               return NOTIFY_DONE;
12133 +
12134 +       kgdb_handle_exception(args->trapnr, args->signr, args->err, regs);
12135 +
12136 +       return NOTIFY_STOP;
12137 +}
12138 +
12139 +static struct notifier_block kgdb_notifier = {
12140 +       .notifier_call = kgdb_notify,
12141 +       .priority = 0x7fffffff, /* we need to notified first */
12142 +};
12143 +
12144 +int kgdb_arch_init(void)
12145 +{
12146 +       atomic_notifier_chain_register(&die_chain, &kgdb_notifier);
12147 +       return 0;
12148 +}
12149 +/*
12150 + * Skip an int3 exception when it occurs after a breakpoint has been
12151 + * removed. Backtrack eip by 1 since the int3 would have caused it to
12152 + * increment by 1.
12153 + */
12154 +
12155 +int kgdb_skipexception(int exception, struct pt_regs *regs)
12156 +{
12157 +       if (exception == 3 && kgdb_isremovedbreak(regs->rip - 1)) {
12158 +               regs->rip -= 1;
12159 +               return 1;
12160 +       }
12161 +       return 0;
12162 +}
12163 +
12164 +struct kgdb_arch arch_kgdb_ops = {
12165 +       .gdb_bpt_instr = {0xcc},
12166 +       .flags = KGDB_HW_BREAKPOINT,
12167 +       .shadowth = 1,
12168 +};
12169 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/arch/x86_64/mm/fault.c linux-2.6.18-53.1.14.kgdb/arch/x86_64/mm/fault.c
12170 --- linux-2.6.18-53.1.14/arch/x86_64/mm/fault.c 2008-03-06 05:54:27.000000000 +0300
12171 +++ linux-2.6.18-53.1.14.kgdb/arch/x86_64/mm/fault.c    2008-06-10 15:38:41.000000000 +0400
12172 @@ -557,6 +557,10 @@ no_context:
12173         if (is_errata93(regs, address))
12174                 return; 
12175  
12176 +       if (notify_die(DIE_PAGE_FAULT_NO_CONTEXT, "no context", regs,
12177 +                               error_code, 14, SIGSEGV) == NOTIFY_STOP)
12178 +               return;
12179 +
12180  /*
12181   * Oops. The kernel tried to access some bad page. We'll have to
12182   * terminate things with extreme prejudice.
12183 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/char/keyboard.c linux-2.6.18-53.1.14.kgdb/drivers/char/keyboard.c
12184 --- linux-2.6.18-53.1.14/drivers/char/keyboard.c        2008-03-06 05:54:23.000000000 +0300
12185 +++ linux-2.6.18-53.1.14.kgdb/drivers/char/keyboard.c   2008-06-10 15:39:11.000000000 +0400
12186 @@ -1174,6 +1174,7 @@ static void kbd_keycode(unsigned int key
12187                 sysrq_down = 0;
12188         if (sysrq_down && down && !rep) {
12189                 handle_sysrq(kbd_sysrq_xlate[keycode], regs, tty);
12190 +               sysrq_down = 0;         /* In case we miss the 'up' event. */
12191                 return;
12192         }
12193  #endif
12194 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/net/Makefile linux-2.6.18-53.1.14.kgdb/drivers/net/Makefile
12195 --- linux-2.6.18-53.1.14/drivers/net/Makefile   2008-03-06 05:54:59.000000000 +0300
12196 +++ linux-2.6.18-53.1.14.kgdb/drivers/net/Makefile      2008-06-10 15:37:55.000000000 +0400
12197 @@ -221,6 +221,7 @@ obj-$(CONFIG_ETRAX_ETHERNET) += cris/
12198  obj-$(CONFIG_ENP2611_MSF_NET) += ixp2000/
12199  
12200  obj-$(CONFIG_NETCONSOLE) += netconsole.o
12201 +obj-$(CONFIG_KGDBOE) += kgdboe.o
12202  
12203  obj-$(CONFIG_FS_ENET) += fs_enet/
12204  
12205 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/net/kgdboe.c linux-2.6.18-53.1.14.kgdb/drivers/net/kgdboe.c
12206 --- linux-2.6.18-53.1.14/drivers/net/kgdboe.c   1970-01-01 03:00:00.000000000 +0300
12207 +++ linux-2.6.18-53.1.14.kgdb/drivers/net/kgdboe.c      2008-06-10 15:37:55.000000000 +0400
12208 @@ -0,0 +1,294 @@
12209 +/*
12210 + * drivers/net/kgdboe.c
12211 + *
12212 + * A network interface for GDB.
12213 + * Based upon 'gdbserial' by David Grothe <dave@gcom.com>
12214 + * and Scott Foehner <sfoehner@engr.sgi.com>
12215 + *
12216 + * Maintainers: Amit S. Kale <amitkale@linsyssoft.com> and
12217 + *             Tom Rini <trini@kernel.crashing.org>
12218 + *
12219 + * 2004 (c) Amit S. Kale <amitkale@linsyssoft.com>
12220 + * 2004-2005 (c) MontaVista Software, Inc.
12221 + * 2005 (c) Wind River Systems, Inc.
12222 + *
12223 + * Contributors at various stages not listed above:
12224 + * San Mehat <nettwerk@biodome.org>, Robert Walsh <rjwalsh@durables.org>,
12225 + * wangdi <wangdi@clusterfs.com>, Matt Mackall <mpm@selenic.com>,
12226 + * Pavel Machek <pavel@suse.cz>, Jason Wessel <jason.wessel@windriver.com>
12227 + *
12228 + * This file is licensed under the terms of the GNU General Public License
12229 + * version 2. This program is licensed "as is" without any warranty of any
12230 + * kind, whether express or implied.
12231 + */
12232 +
12233 +#include <linux/kernel.h>
12234 +#include <linux/interrupt.h>
12235 +#include <linux/string.h>
12236 +#include <linux/kgdb.h>
12237 +#include <linux/netpoll.h>
12238 +#include <linux/init.h>
12239 +
12240 +#include <asm/atomic.h>
12241 +
12242 +#define IN_BUF_SIZE 512                /* power of 2, please */
12243 +#define NOT_CONFIGURED_STRING "not_configured"
12244 +#define OUT_BUF_SIZE 30                /* We don't want to send too big of a packet. */
12245 +#define MAX_KGDBOE_CONFIG_STR 256
12246 +
12247 +static char in_buf[IN_BUF_SIZE], out_buf[OUT_BUF_SIZE];
12248 +static int in_head, in_tail, out_count;
12249 +static atomic_t in_count;
12250 +/* 0 = unconfigured, 1 = netpoll options parsed, 2 = fully configured. */
12251 +static int configured;
12252 +static struct kgdb_io local_kgdb_io_ops;
12253 +static int use_dynamic_mac;
12254 +
12255 +MODULE_DESCRIPTION("KGDB driver for network interfaces");
12256 +MODULE_LICENSE("GPL");
12257 +static char config[MAX_KGDBOE_CONFIG_STR] = NOT_CONFIGURED_STRING;
12258 +static struct kparam_string kps = {
12259 +       .string = config,
12260 +       .maxlen = MAX_KGDBOE_CONFIG_STR,
12261 +};
12262 +
12263 +static void rx_hook(struct netpoll *np, int port, char *msg, int len,
12264 +                   struct sk_buff *skb)
12265 +{
12266 +       int i;
12267 +
12268 +       np->remote_port = port;
12269 +
12270 +       /* Copy the MAC address if we need to. */
12271 +       if (use_dynamic_mac) {
12272 +               memcpy(np->remote_mac, eth_hdr(skb)->h_source,
12273 +                               sizeof(np->remote_mac));
12274 +               use_dynamic_mac = 0;
12275 +       }
12276 +
12277 +       /*
12278 +        * This could be GDB trying to attach.  But it could also be GDB
12279 +        * finishing up a session, with kgdb_connected=0 but GDB sending
12280 +        * an ACK for the final packet.  To make sure we don't try and
12281 +        * make a breakpoint when GDB is leaving, make sure that if
12282 +        * !kgdb_connected the only len == 1 packet we allow is ^C.
12283 +        */
12284 +       if (!kgdb_connected && (len != 1 || msg[0] == 3) &&
12285 +           !atomic_read(&kgdb_setting_breakpoint)) {
12286 +               tasklet_schedule(&kgdb_tasklet_breakpoint);
12287 +       }
12288 +
12289 +       for (i = 0; i < len; i++) {
12290 +               if (msg[i] == 3)
12291 +                       tasklet_schedule(&kgdb_tasklet_breakpoint);
12292 +
12293 +               if (atomic_read(&in_count) >= IN_BUF_SIZE) {
12294 +                       /* buffer overflow, clear it */
12295 +                       in_head = in_tail = 0;
12296 +                       atomic_set(&in_count, 0);
12297 +                       break;
12298 +               }
12299 +               in_buf[in_head++] = msg[i];
12300 +               in_head &= (IN_BUF_SIZE - 1);
12301 +               atomic_inc(&in_count);
12302 +       }
12303 +}
12304 +
12305 +static struct netpoll np = {
12306 +       .dev_name = "eth0",
12307 +       .name = "kgdboe",
12308 +       .rx_hook = rx_hook,
12309 +       .local_port = 6443,
12310 +       .remote_port = 6442,
12311 +       .remote_mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
12312 +};
12313 +
12314 +static void eth_pre_exception_handler(void)
12315 +{
12316 +       /* Increment the module count when the debugger is active */
12317 +       if (!kgdb_connected)
12318 +               try_module_get(THIS_MODULE);
12319 +       netpoll_set_trap(1);
12320 +}
12321 +
12322 +static void eth_post_exception_handler(void)
12323 +{
12324 +       /* decrement the module count when the debugger detaches */
12325 +       if (!kgdb_connected)
12326 +               module_put(THIS_MODULE);
12327 +       netpoll_set_trap(0);
12328 +}
12329 +
12330 +static int eth_get_char(void)
12331 +{
12332 +       int chr;
12333 +
12334 +       while (atomic_read(&in_count) == 0)
12335 +               netpoll_poll(&np);
12336 +
12337 +       chr = in_buf[in_tail++];
12338 +       in_tail &= (IN_BUF_SIZE - 1);
12339 +       atomic_dec(&in_count);
12340 +       return chr;
12341 +}
12342 +
12343 +static void eth_flush_buf(void)
12344 +{
12345 +       if (out_count && np.dev) {
12346 +               netpoll_send_udp(&np, out_buf, out_count);
12347 +               memset(out_buf, 0, sizeof(out_buf));
12348 +               out_count = 0;
12349 +       }
12350 +}
12351 +
12352 +static void eth_put_char(u8 chr)
12353 +{
12354 +       out_buf[out_count++] = chr;
12355 +       if (out_count == OUT_BUF_SIZE)
12356 +               eth_flush_buf();
12357 +}
12358 +
12359 +static int option_setup(char *opt)
12360 +{
12361 +       char opt_scratch[MAX_KGDBOE_CONFIG_STR];
12362 +
12363 +       /* If we're being given a new configuration, copy it in. */
12364 +       if (opt != config)
12365 +               strcpy(config, opt);
12366 +       /* But work on a copy as netpoll_parse_options will eat it. */
12367 +       strcpy(opt_scratch, opt);
12368 +       configured = !netpoll_parse_options(&np, opt_scratch);
12369 +
12370 +       use_dynamic_mac = 1;
12371 +
12372 +       return 0;
12373 +}
12374 +__setup("kgdboe=", option_setup);
12375 +
12376 +/* With our config string set by some means, configure kgdboe. */
12377 +static int configure_kgdboe(void)
12378 +{
12379 +       /* Try out the string. */
12380 +       option_setup(config);
12381 +
12382 +       if (!configured) {
12383 +               printk(KERN_ERR "kgdboe: configuration incorrect - kgdboe not "
12384 +                      "loaded.\n");
12385 +               printk(KERN_ERR "  Usage: kgdboe=[src-port]@[src-ip]/[dev],"
12386 +                               "[tgt-port]@<tgt-ip>/<tgt-macaddr>\n");
12387 +               return -EINVAL;
12388 +       }
12389 +
12390 +       /* Bring it up. */
12391 +       if (netpoll_setup(&np)) {
12392 +               printk(KERN_ERR "kgdboe: netpoll_setup failed kgdboe failed\n");
12393 +               return -EINVAL;
12394 +       }
12395 +
12396 +       if (kgdb_register_io_module(&local_kgdb_io_ops)) {
12397 +               netpoll_cleanup(&np);
12398 +               return -EINVAL;
12399 +       }
12400 +
12401 +       configured = 2;
12402 +
12403 +       return 0;
12404 +}
12405 +
12406 +static int init_kgdboe(void)
12407 +{
12408 +       int ret;
12409 +
12410 +       /* Already done? */
12411 +       if (configured == 2)
12412 +               return 0;
12413 +
12414 +       /* OK, go ahead and do it. */
12415 +       ret = configure_kgdboe();
12416 +
12417 +       if (configured == 2)
12418 +               printk(KERN_INFO "kgdboe: debugging over ethernet enabled\n");
12419 +
12420 +       return ret;
12421 +}
12422 +
12423 +static void cleanup_kgdboe(void)
12424 +{
12425 +       netpoll_cleanup(&np);
12426 +       configured = 0;
12427 +       kgdb_unregister_io_module(&local_kgdb_io_ops);
12428 +}
12429 +
12430 +static int param_set_kgdboe_var(const char *kmessage, struct kernel_param *kp)
12431 +{
12432 +       char kmessage_save[MAX_KGDBOE_CONFIG_STR];
12433 +       int msg_len = strlen(kmessage);
12434 +
12435 +       if (msg_len + 1 > MAX_KGDBOE_CONFIG_STR) {
12436 +               printk(KERN_ERR "%s: string doesn't fit in %u chars.\n",
12437 +                      kp->name, MAX_KGDBOE_CONFIG_STR - 1);
12438 +               return -ENOSPC;
12439 +       }
12440 +
12441 +       if (kgdb_connected) {
12442 +               printk(KERN_ERR "kgdboe: Cannot reconfigure while KGDB is "
12443 +                               "connected.\n");
12444 +               return 0;
12445 +       }
12446 +
12447 +       /* Start the reconfiguration process by saving the old string */
12448 +       strncpy(kmessage_save, config, sizeof(kmessage_save));
12449 +
12450 +
12451 +       /* Copy in the new param and strip out invalid characters so we
12452 +        * can optionally specify the MAC.
12453 +        */
12454 +       strncpy(config, kmessage, sizeof(config));
12455 +       msg_len--;
12456 +       while (msg_len > 0 &&
12457 +                       (config[msg_len] < ',' || config[msg_len] > 'f')) {
12458 +               config[msg_len] = '\0';
12459 +               msg_len--;
12460 +       }
12461 +
12462 +       /* Check to see if we are unconfiguring the io module and that it
12463 +        * was in a fully configured state, as this is the only time that
12464 +        * netpoll_cleanup should get called
12465 +        */
12466 +       if (configured == 2 && strcmp(config, NOT_CONFIGURED_STRING) == 0) {
12467 +               printk(KERN_INFO "kgdboe: reverting to unconfigured state\n");
12468 +               cleanup_kgdboe();
12469 +               return 0;
12470 +       } else
12471 +               /* Go and configure with the new params. */
12472 +               configure_kgdboe();
12473 +
12474 +       if (configured == 2)
12475 +               return 0;
12476 +
12477 +       /* If the new string was invalid, revert to the previous state, which
12478 +        * is at a minimum not_configured. */
12479 +       strncpy(config, kmessage_save, sizeof(config));
12480 +       if (strcmp(kmessage_save, NOT_CONFIGURED_STRING) != 0) {
12481 +               printk(KERN_INFO "kgdboe: reverting to prior configuration\n");
12482 +               /* revert back to the original config */
12483 +               strncpy(config, kmessage_save, sizeof(config));
12484 +               configure_kgdboe();
12485 +       }
12486 +       return 0;
12487 +}
12488 +
12489 +static struct kgdb_io local_kgdb_io_ops = {
12490 +       .read_char = eth_get_char,
12491 +       .write_char = eth_put_char,
12492 +       .init = init_kgdboe,
12493 +       .flush = eth_flush_buf,
12494 +       .pre_exception = eth_pre_exception_handler,
12495 +       .post_exception = eth_post_exception_handler
12496 +};
12497 +
12498 +module_init(init_kgdboe);
12499 +module_exit(cleanup_kgdboe);
12500 +module_param_call(kgdboe, param_set_kgdboe_var, param_get_string, &kps, 0644);
12501 +MODULE_PARM_DESC(kgdboe, " kgdboe=[src-port]@[src-ip]/[dev],"
12502 +                "[tgt-port]@<tgt-ip>/<tgt-macaddr>\n");
12503 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/8250.c linux-2.6.18-53.1.14.kgdb/drivers/serial/8250.c
12504 --- linux-2.6.18-53.1.14/drivers/serial/8250.c  2008-03-06 05:54:43.000000000 +0300
12505 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/8250.c     2008-06-10 15:37:43.000000000 +0400
12506 @@ -2656,6 +2656,25 @@ void serial8250_unregister_port(int line
12507  }
12508  EXPORT_SYMBOL(serial8250_unregister_port);
12509  
12510 +/**
12511 + *     serial8250_unregister_by_port - remove a 16x50 serial port
12512 + *     at runtime.
12513 + *     @port: A &struct uart_port that describes the port to remove.
12514 + *
12515 + *     Remove one serial port.  This may not be called from interrupt
12516 + *     context.  We hand the port back to the our control.
12517 + */
12518 +void serial8250_unregister_by_port(struct uart_port *port)
12519 +{
12520 +       struct uart_8250_port *uart;
12521 +
12522 +       uart = serial8250_find_match_or_unused(port);
12523 +
12524 +       if (uart)
12525 +               serial8250_unregister_port(uart->port.line);
12526 +}
12527 +EXPORT_SYMBOL(serial8250_unregister_by_port);
12528 +
12529  static int __init serial8250_init(void)
12530  {
12531         int ret, i;
12532 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/8250_kgdb.c linux-2.6.18-53.1.14.kgdb/drivers/serial/8250_kgdb.c
12533 --- linux-2.6.18-53.1.14/drivers/serial/8250_kgdb.c     1970-01-01 03:00:00.000000000 +0300
12534 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/8250_kgdb.c        2008-06-10 15:37:43.000000000 +0400
12535 @@ -0,0 +1,516 @@
12536 +/*
12537 + * 8250 interface for kgdb.
12538 + *
12539 + * This is a merging of many different drivers, and all of the people have
12540 + * had an impact in some form or another:
12541 + *
12542 + * 2004-2005 (c) MontaVista Software, Inc.
12543 + * 2005-2006 (c) Wind River Systems, Inc.
12544 + *
12545 + * Amit Kale <amitkale@emsyssoft.com>, David Grothe <dave@gcom.com>,
12546 + * Scott Foehner <sfoehner@engr.sgi.com>, George Anzinger <george@mvista.com>,
12547 + * Robert Walsh <rjwalsh@durables.org>, wangdi <wangdi@clusterfs.com>,
12548 + * San Mehat, Tom Rini <trini@mvista.com>,
12549 + * Jason Wessel <jason.wessel@windriver.com>
12550 + */
12551 +
12552 +#include <linux/config.h>
12553 +#include <linux/kernel.h>
12554 +#include <linux/init.h>
12555 +#include <linux/kgdb.h>
12556 +#include <linux/interrupt.h>
12557 +#include <linux/tty.h>
12558 +#include <linux/serial.h>
12559 +#include <linux/serial_reg.h>
12560 +#include <linux/serialP.h>
12561 +#include <linux/ioport.h>
12562 +
12563 +#include <asm/io.h>
12564 +#include <asm/serial.h>                /* For BASE_BAUD and SERIAL_PORT_DFNS */
12565 +
12566 +#include "8250.h"
12567 +
12568 +#define GDB_BUF_SIZE   512     /* power of 2, please */
12569 +
12570 +MODULE_DESCRIPTION("KGDB driver for the 8250");
12571 +MODULE_LICENSE("GPL");
12572 +/* These will conflict with early_param otherwise. */
12573 +#ifdef CONFIG_KGDB_8250_MODULE
12574 +static char config[256];
12575 +module_param_string(kgdb8250, config, 256, 0);
12576 +MODULE_PARM_DESC(kgdb8250,
12577 +                " kgdb8250=<io or mmio>,<address>,<baud rate>,<irq>\n");
12578 +static struct kgdb_io local_kgdb_io_ops;
12579 +#endif                         /* CONFIG_KGDB_8250_MODULE */
12580 +
12581 +/* Speed of the UART. */
12582 +static int kgdb8250_baud;
12583 +
12584 +/* Flag for if we need to call request_mem_region */
12585 +static int kgdb8250_needs_request_mem_region;
12586 +
12587 +static char kgdb8250_buf[GDB_BUF_SIZE];
12588 +static atomic_t kgdb8250_buf_in_cnt;
12589 +static int kgdb8250_buf_out_inx;
12590 +
12591 +/* Old-style serial definitions, if existant, and a counter. */
12592 +#ifdef CONFIG_KGDB_SIMPLE_SERIAL
12593 +static int __initdata should_copy_rs_table = 1;
12594 +static struct serial_state old_rs_table[] __initdata = {
12595 +#ifdef SERIAL_PORT_DFNS
12596 +       SERIAL_PORT_DFNS
12597 +#endif
12598 +};
12599 +#endif
12600 +
12601 +/* Our internal table of UARTS. */
12602 +#define UART_NR        CONFIG_SERIAL_8250_NR_UARTS
12603 +static struct uart_port kgdb8250_ports[UART_NR];
12604 +
12605 +static struct uart_port *current_port;
12606 +
12607 +/* Base of the UART. */
12608 +static void *kgdb8250_addr;
12609 +
12610 +/* Forward declarations. */
12611 +static int kgdb8250_uart_init(void);
12612 +static int __init kgdb_init_io(void);
12613 +static int __init kgdb8250_opt(char *str);
12614 +
12615 +/* These are much shorter calls to ioread8/iowrite8 that take into
12616 + * account our shifts, etc. */
12617 +static inline unsigned int kgdb_ioread(u8 mask)
12618 +{
12619 +       return ioread8(kgdb8250_addr + (mask << current_port->regshift));
12620 +}
12621 +
12622 +static inline void kgdb_iowrite(u8 val, u8 mask)
12623 +{
12624 +       iowrite8(val, kgdb8250_addr + (mask << current_port->regshift));
12625 +}
12626 +
12627 +/*
12628 + * Wait until the interface can accept a char, then write it.
12629 + */
12630 +static void kgdb_put_debug_char(u8 chr)
12631 +{
12632 +       while (!(kgdb_ioread(UART_LSR) & UART_LSR_THRE)) ;
12633 +
12634 +       kgdb_iowrite(chr, UART_TX);
12635 +}
12636 +
12637 +/*
12638 + * Get a byte from the hardware data buffer and return it
12639 + */
12640 +static int read_data_bfr(void)
12641 +{
12642 +       char it = kgdb_ioread(UART_LSR);
12643 +
12644 +       if (it & UART_LSR_DR)
12645 +               return kgdb_ioread(UART_RX);
12646 +
12647 +       /*
12648 +        * If we have a framing error assume somebody messed with
12649 +        * our uart.  Reprogram it and send '-' both ways...
12650 +        */
12651 +       if (it & 0xc) {
12652 +               kgdb8250_uart_init();
12653 +               kgdb_put_debug_char('-');
12654 +               return '-';
12655 +       }
12656 +
12657 +       return -1;
12658 +}
12659 +
12660 +/*
12661 + * Get a char if available, return -1 if nothing available.
12662 + * Empty the receive buffer first, then look at the interface hardware.
12663 + */
12664 +static int kgdb_get_debug_char(void)
12665 +{
12666 +       int retchr;
12667 +
12668 +       /* intr routine has q'd chars */
12669 +       if (atomic_read(&kgdb8250_buf_in_cnt) != 0) {
12670 +               retchr = kgdb8250_buf[kgdb8250_buf_out_inx++];
12671 +               kgdb8250_buf_out_inx &= (GDB_BUF_SIZE - 1);
12672 +               atomic_dec(&kgdb8250_buf_in_cnt);
12673 +               return retchr;
12674 +       }
12675 +
12676 +       do {
12677 +               retchr = read_data_bfr();
12678 +       } while (retchr < 0);
12679 +
12680 +       return retchr;
12681 +}
12682 +
12683 +/*
12684 + * This is the receiver interrupt routine for the GDB stub.
12685 + * All that we need to do is verify that the interrupt happened on the
12686 + * line we're in charge of.  If this is true, schedule a breakpoint and
12687 + * return.
12688 + */
12689 +static irqreturn_t
12690 +kgdb8250_interrupt(int irq, void *dev_id, struct pt_regs *regs)
12691 +{
12692 +       if (kgdb_ioread(UART_IIR) & UART_IIR_RDI) {
12693 +               /* Throw away the data if another I/O routine is active. */
12694 +               if (kgdb_io_ops.read_char != kgdb_get_debug_char &&
12695 +                               (kgdb_ioread(UART_LSR) & UART_LSR_DR))
12696 +                       kgdb_ioread(UART_RX);
12697 +               else
12698 +                       breakpoint();
12699 +       }
12700 +
12701 +       return IRQ_HANDLED;
12702 +}
12703 +
12704 +/*
12705 + *  Initializes the UART.
12706 + *  Returns:
12707 + *     0 on success, 1 on failure.
12708 + */
12709 +static int
12710 +kgdb8250_uart_init (void)
12711 +{
12712 +       unsigned int ier, base_baud = current_port->uartclk ?
12713 +               current_port->uartclk / 16 : BASE_BAUD;
12714 +
12715 +       /* test uart existance */
12716 +       if(kgdb_ioread(UART_LSR) == 0xff)
12717 +               return -1;
12718 +
12719 +       /* disable interrupts */
12720 +       kgdb_iowrite(0, UART_IER);
12721 +
12722 +#if defined(CONFIG_ARCH_OMAP1510)
12723 +       /* Workaround to enable 115200 baud on OMAP1510 internal ports */
12724 +       if (cpu_is_omap1510() && is_omap_port((void *)kgdb8250_addr)) {
12725 +               if (kgdb8250_baud == 115200) {
12726 +                       base_baud = 1;
12727 +                       kgdb8250_baud = 1;
12728 +                       kgdb_iowrite(1, UART_OMAP_OSC_12M_SEL);
12729 +               } else
12730 +                       kgdb_iowrite(0, UART_OMAP_OSC_12M_SEL);
12731 +       }
12732 +#endif
12733 +       /* set DLAB */
12734 +       kgdb_iowrite(UART_LCR_DLAB, UART_LCR);
12735 +
12736 +       /* set baud */
12737 +       kgdb_iowrite((base_baud / kgdb8250_baud) & 0xff, UART_DLL);
12738 +       kgdb_iowrite((base_baud / kgdb8250_baud) >> 8, UART_DLM);
12739 +
12740 +       /* reset DLAB, set LCR */
12741 +       kgdb_iowrite(UART_LCR_WLEN8, UART_LCR);
12742 +
12743 +       /* set DTR and RTS */
12744 +       kgdb_iowrite(UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS, UART_MCR);
12745 +
12746 +       /* setup fifo */
12747 +       kgdb_iowrite(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR
12748 +               | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_8,
12749 +               UART_FCR);
12750 +
12751 +       /* clear pending interrupts */
12752 +       kgdb_ioread(UART_IIR);
12753 +       kgdb_ioread(UART_RX);
12754 +       kgdb_ioread(UART_LSR);
12755 +       kgdb_ioread(UART_MSR);
12756 +
12757 +       /* turn on RX interrupt only */
12758 +       kgdb_iowrite(UART_IER_RDI, UART_IER);
12759 +
12760 +       /*
12761 +        * Borrowed from the main 8250 driver.
12762 +        * Try writing and reading the UART_IER_UUE bit (b6).
12763 +        * If it works, this is probably one of the Xscale platform's
12764 +        * internal UARTs.
12765 +        * We're going to explicitly set the UUE bit to 0 before
12766 +        * trying to write and read a 1 just to make sure it's not
12767 +        * already a 1 and maybe locked there before we even start start.
12768 +        */
12769 +       ier = kgdb_ioread(UART_IER);
12770 +       kgdb_iowrite(ier & ~UART_IER_UUE, UART_IER);
12771 +       if (!(kgdb_ioread(UART_IER) & UART_IER_UUE)) {
12772 +               /*
12773 +                * OK it's in a known zero state, try writing and reading
12774 +                * without disturbing the current state of the other bits.
12775 +                */
12776 +               kgdb_iowrite(ier | UART_IER_UUE, UART_IER);
12777 +               if (kgdb_ioread(UART_IER) & UART_IER_UUE)
12778 +                       /*
12779 +                        * It's an Xscale.
12780 +                        */
12781 +                       ier |= UART_IER_UUE | UART_IER_RTOIE;
12782 +       }
12783 +       kgdb_iowrite(ier, UART_IER);
12784 +       return 0;
12785 +}
12786 +
12787 +/*
12788 + * Copy the old serial_state table to our uart_port table if we haven't
12789 + * had values specifically configured in.  We need to make sure this only
12790 + * happens once.
12791 + */
12792 +static void __init kgdb8250_copy_rs_table(void)
12793 +{
12794 +#ifdef CONFIG_KGDB_SIMPLE_SERIAL
12795 +       int i;
12796 +
12797 +       if (!should_copy_rs_table)
12798 +               return;
12799 +
12800 +       for (i = 0; i < ARRAY_SIZE(old_rs_table); i++) {
12801 +               kgdb8250_ports[i].iobase = old_rs_table[i].port;
12802 +               kgdb8250_ports[i].irq = irq_canonicalize(old_rs_table[i].irq);
12803 +               kgdb8250_ports[i].uartclk = old_rs_table[i].baud_base * 16;
12804 +               kgdb8250_ports[i].membase = old_rs_table[i].iomem_base;
12805 +               kgdb8250_ports[i].iotype = old_rs_table[i].io_type;
12806 +               kgdb8250_ports[i].regshift = old_rs_table[i].iomem_reg_shift;
12807 +               kgdb8250_ports[i].line = i;
12808 +       }
12809 +
12810 +       should_copy_rs_table = 0;
12811 +#endif
12812 +}
12813 +
12814 +/*
12815 + * Hookup our IRQ line now that it is safe to do so, after we grab any
12816 + * memory regions we might need to.  If we haven't been initialized yet,
12817 + * go ahead and copy the old_rs_table in.
12818 + */
12819 +static void __init kgdb8250_late_init(void)
12820 +{
12821 +       /* Try and copy the old_rs_table. */
12822 +       kgdb8250_copy_rs_table();
12823 +
12824 +#if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
12825 +       /* Take the port away from the main driver. */
12826 +       serial8250_unregister_by_port(current_port);
12827 +
12828 +       /* Now reinit the port as the above has disabled things. */
12829 +       kgdb8250_uart_init();
12830 +#endif
12831 +       /* We may need to call request_mem_region() first. */
12832 +       if (kgdb8250_needs_request_mem_region)
12833 +               request_mem_region(current_port->mapbase,
12834 +                                  8 << current_port->regshift, "kgdb");
12835 +       if (request_irq(current_port->irq, kgdb8250_interrupt, SA_SHIRQ,
12836 +                       "GDB-stub", current_port) < 0)
12837 +               printk(KERN_ERR "KGDB failed to request the serial IRQ (%d)\n",
12838 +                      current_port->irq);
12839 +}
12840 +
12841 +static __init int kgdb_init_io(void)
12842 +{
12843 +       /* Give us the basic table of uarts. */
12844 +       kgdb8250_copy_rs_table();
12845 +
12846 +       /* We're either a module and parse a config string, or we have a
12847 +        * semi-static config. */
12848 +#ifdef CONFIG_KGDB_8250_MODULE
12849 +       if (strlen(config)) {
12850 +               if (kgdb8250_opt(config))
12851 +                       return -EINVAL;
12852 +       } else {
12853 +               printk(KERN_ERR "kgdb8250: argument error, usage: "
12854 +                      "kgdb8250=<io or mmio>,<address>,<baud rate>,<irq>\n");
12855 +               return -EINVAL;
12856 +       }
12857 +#elif defined(CONFIG_KGDB_SIMPLE_SERIAL)
12858 +       kgdb8250_baud = CONFIG_KGDB_BAUDRATE;
12859 +
12860 +       /* Setup our pointer to the serial port now. */
12861 +       current_port = &kgdb8250_ports[CONFIG_KGDB_PORT_NUM];
12862 +#else
12863 +       if (kgdb8250_opt(CONFIG_KGDB_8250_CONF_STRING))
12864 +               return -EINVAL;
12865 +#endif
12866 +
12867 +
12868 +       /* Internal driver setup. */
12869 +       switch (current_port->iotype) {
12870 +       case UPIO_MEM:
12871 +               if (current_port->mapbase)
12872 +                       kgdb8250_needs_request_mem_region = 1;
12873 +               if (current_port->flags & UPF_IOREMAP) {
12874 +                       current_port->membase = ioremap(current_port->mapbase,
12875 +                                               8 << current_port->regshift);
12876 +                       if (!current_port->membase)
12877 +                               return -EIO;    /* Failed. */
12878 +               }
12879 +               kgdb8250_addr = current_port->membase;
12880 +               break;
12881 +       case UPIO_PORT:
12882 +       default:
12883 +               kgdb8250_addr = ioport_map(current_port->iobase,
12884 +                                          8 << current_port->regshift);
12885 +               if (!kgdb8250_addr)
12886 +                       return -EIO;    /* Failed. */
12887 +       }
12888 +
12889 +       if (kgdb8250_uart_init() == -1) {
12890 +               printk(KERN_ERR "kgdb8250: init failed\n");
12891 +               return -EIO;
12892 +       }
12893 +#ifdef CONFIG_KGDB_8250_MODULE
12894 +       /* Attach the kgdb irq. When this is built into the kernel, it
12895 +        * is called as a part of late_init sequence.
12896 +        */
12897 +       kgdb8250_late_init();
12898 +       if (kgdb_register_io_module(&local_kgdb_io_ops))
12899 +               return -EINVAL;
12900 +
12901 +       printk(KERN_INFO "kgdb8250: debugging enabled\n");
12902 +#endif                         /* CONFIG_KGD_8250_MODULE */
12903 +
12904 +       return 0;
12905 +}
12906 +
12907 +#ifdef CONFIG_KGDB_8250_MODULE
12908 +/* If it is a module the kgdb_io_ops should be a static which
12909 + * is passed to the KGDB I/O initialization
12910 + */
12911 +static struct kgdb_io local_kgdb_io_ops = {
12912 +#else                          /* ! CONFIG_KGDB_8250_MODULE */
12913 +struct kgdb_io kgdb_io_ops = {
12914 +#endif                         /* ! CONFIG_KGD_8250_MODULE */
12915 +       .read_char = kgdb_get_debug_char,
12916 +       .write_char = kgdb_put_debug_char,
12917 +       .init = kgdb_init_io,
12918 +       .late_init = kgdb8250_late_init,
12919 +};
12920 +
12921 +/**
12922 + *     kgdb8250_add_port - Define a serial port for use with KGDB
12923 + *     @i: The index of the port being added
12924 + *     @serial_req: The &struct uart_port describing the port
12925 + *
12926 + *     On platforms where we must register the serial device
12927 + *     dynamically, this is the best option if a platform also normally
12928 + *     calls early_serial_setup().
12929 + */
12930 +void __init kgdb8250_add_port(int i, struct uart_port *serial_req)
12931 +{
12932 +       /* Make sure we've got the built-in data before we override. */
12933 +       kgdb8250_copy_rs_table();
12934 +
12935 +       /* Copy the whole thing over. */
12936 +       if (current_port != &kgdb8250_ports[i])
12937 +                memcpy(&kgdb8250_ports[i], serial_req, sizeof(struct uart_port));
12938 +}
12939 +
12940 +/**
12941 + *     kgdb8250_add_platform_port - Define a serial port for use with KGDB
12942 + *     @i: The index of the port being added
12943 + *     @p: The &struct plat_serial8250_port describing the port
12944 + *
12945 + *     On platforms where we must register the serial device
12946 + *     dynamically, this is the best option if a platform normally
12947 + *     handles uart setup with an array of &struct plat_serial8250_port.
12948 + */
12949 +void __init kgdb8250_add_platform_port(int i, struct plat_serial8250_port *p)
12950 +{
12951 +       /* Make sure we've got the built-in data before we override. */
12952 +       kgdb8250_copy_rs_table();
12953 +
12954 +       kgdb8250_ports[i].iobase = p->iobase;
12955 +       kgdb8250_ports[i].membase = p->membase;
12956 +       kgdb8250_ports[i].irq = p->irq;
12957 +       kgdb8250_ports[i].uartclk = p->uartclk;
12958 +       kgdb8250_ports[i].regshift = p->regshift;
12959 +       kgdb8250_ports[i].iotype = p->iotype;
12960 +       kgdb8250_ports[i].flags = p->flags;
12961 +       kgdb8250_ports[i].mapbase = p->mapbase;
12962 +}
12963 +
12964 +/*
12965 + * Syntax for this cmdline option is:
12966 + * kgdb8250=<io or mmio>,<address>,<baud rate>,<irq>"
12967 + */
12968 +static int __init kgdb8250_opt(char *str)
12969 +{
12970 +       /* We'll fill out and use the first slot. */
12971 +       current_port = &kgdb8250_ports[0];
12972 +
12973 +       if (!strncmp(str, "io", 2)) {
12974 +               current_port->iotype = UPIO_PORT;
12975 +               str += 2;
12976 +       } else if (!strncmp(str, "mmap", 4)) {
12977 +               current_port->iotype = UPIO_MEM;
12978 +               current_port->flags |= UPF_IOREMAP;
12979 +               str += 4;
12980 +       } else if (!strncmp(str, "mmio", 4)) {
12981 +               current_port->iotype = UPIO_MEM;
12982 +               current_port->flags &= ~UPF_IOREMAP;
12983 +               str += 4;
12984 +       } else
12985 +               goto errout;
12986 +
12987 +       if (*str != ',')
12988 +               goto errout;
12989 +       str++;
12990 +
12991 +       if (current_port->iotype == UPIO_PORT)
12992 +               current_port->iobase = simple_strtoul(str, &str, 16);
12993 +       else {
12994 +               if (current_port->flags & UPF_IOREMAP)
12995 +                       current_port->mapbase =
12996 +                               (unsigned long) simple_strtoul(str, &str, 16);
12997 +               else
12998 +                       current_port->membase =
12999 +                               (void *) simple_strtoul(str, &str, 16);
13000 +       }
13001 +
13002 +       if (*str != ',')
13003 +               goto errout;
13004 +       str++;
13005 +
13006 +       kgdb8250_baud = simple_strtoul(str, &str, 10);
13007 +       if (!kgdb8250_baud)
13008 +               goto errout;
13009 +
13010 +       if (*str != ',')
13011 +               goto errout;
13012 +       str++;
13013 +
13014 +       current_port->irq = simple_strtoul(str, &str, 10);
13015 +
13016 +#ifdef CONFIG_KGDB_SIMPLE_SERIAL
13017 +       should_copy_rs_table = 0;
13018 +#endif
13019 +
13020 +       return 0;
13021 +
13022 +      errout:
13023 +       printk(KERN_ERR "Invalid syntax for option kgdb8250=\n");
13024 +       return 1;
13025 +}
13026 +
13027 +#ifdef CONFIG_KGDB_8250_MODULE
13028 +static void cleanup_kgdb8250(void)
13029 +{
13030 +       kgdb_unregister_io_module(&local_kgdb_io_ops);
13031 +
13032 +       /* Clean up the irq and memory */
13033 +       free_irq(current_port->irq, current_port);
13034 +
13035 +       if (kgdb8250_needs_request_mem_region)
13036 +               release_mem_region(current_port->mapbase,
13037 +                                  8 << current_port->regshift);
13038 +       /* Hook up the serial port back to what it was previously
13039 +        * hooked up to.
13040 +        */
13041 +#if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
13042 +       /* Give the port back to the 8250 driver. */
13043 +       serial8250_register_port(current_port);
13044 +#endif
13045 +}
13046 +
13047 +module_init(kgdb_init_io);
13048 +module_exit(cleanup_kgdb8250);
13049 +#else                          /* ! CONFIG_KGDB_8250_MODULE */
13050 +early_param("kgdb8250", kgdb8250_opt);
13051 +#endif                         /* ! CONFIG_KGDB_8250_MODULE */
13052 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/Kconfig linux-2.6.18-53.1.14.kgdb/drivers/serial/Kconfig
13053 --- linux-2.6.18-53.1.14/drivers/serial/Kconfig 2008-03-06 05:54:47.000000000 +0300
13054 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/Kconfig    2008-06-10 15:37:43.000000000 +0400
13055 @@ -107,7 +107,7 @@ config SERIAL_8250_CS
13056  
13057  config SERIAL_8250_NR_UARTS
13058         int "Maximum number of 8250/16550 serial ports"
13059 -       depends on SERIAL_8250
13060 +       depends on SERIAL_8250 || KGDB_8250
13061         default "4"
13062         help
13063           Set this to the number of serial ports you want the driver
13064 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/Makefile linux-2.6.18-53.1.14.kgdb/drivers/serial/Makefile
13065 --- linux-2.6.18-53.1.14/drivers/serial/Makefile        2008-03-06 05:54:47.000000000 +0300
13066 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/Makefile   2008-06-10 15:38:14.000000000 +0400
13067 @@ -47,6 +47,7 @@ obj-$(CONFIG_SERIAL_IMX) += imx.o
13068  obj-$(CONFIG_SERIAL_MPC52xx) += mpc52xx_uart.o
13069  obj-$(CONFIG_SERIAL_ICOM) += icom.o
13070  obj-$(CONFIG_SERIAL_M32R_SIO) += m32r_sio.o
13071 +obj-$(CONFIG_KGDB_MPSC) += mpsc_kgdb.o
13072  obj-$(CONFIG_SERIAL_MPSC) += mpsc.o
13073  obj-$(CONFIG_ETRAX_SERIAL) += crisv10.o
13074  obj-$(CONFIG_SERIAL_JSM) += jsm/
13075 @@ -57,3 +58,4 @@ obj-$(CONFIG_SERIAL_SGI_IOC3) += ioc3_se
13076  obj-$(CONFIG_SERIAL_AT91) += at91_serial.o
13077  obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
13078  obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o
13079 +obj-$(CONFIG_KGDB_8250) += 8250_kgdb.o
13080 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/amba-pl011.c linux-2.6.18-53.1.14.kgdb/drivers/serial/amba-pl011.c
13081 --- linux-2.6.18-53.1.14/drivers/serial/amba-pl011.c    2006-09-20 07:42:06.000000000 +0400
13082 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/amba-pl011.c       2008-06-10 15:38:56.000000000 +0400
13083 @@ -340,7 +340,7 @@ static int pl011_startup(struct uart_por
13084         /*
13085          * Allocate the IRQ
13086          */
13087 -       retval = request_irq(uap->port.irq, pl011_int, 0, "uart-pl011", uap);
13088 +       retval = request_irq(uap->port.irq, pl011_int, SA_SHIRQ, "uart-pl011", uap);
13089         if (retval)
13090                 goto clk_dis;
13091  
13092 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/cpm_uart/Makefile linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/Makefile
13093 --- linux-2.6.18-53.1.14/drivers/serial/cpm_uart/Makefile       2006-09-20 07:42:06.000000000 +0400
13094 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/Makefile  2008-06-10 15:38:14.000000000 +0400
13095 @@ -7,5 +7,6 @@ obj-$(CONFIG_SERIAL_CPM) += cpm_uart.o
13096  # Select the correct platform objects.
13097  cpm_uart-objs-$(CONFIG_CPM2)   += cpm_uart_cpm2.o
13098  cpm_uart-objs-$(CONFIG_8xx)    += cpm_uart_cpm1.o
13099 +cpm_uart-objs-$(CONFIG_KGDB_CPM_UART)  += cpm_uart_kgdb.o
13100  
13101  cpm_uart-objs  := cpm_uart_core.o $(cpm_uart-objs-y)
13102 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/cpm_uart/cpm_uart.h linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/cpm_uart.h
13103 --- linux-2.6.18-53.1.14/drivers/serial/cpm_uart/cpm_uart.h     2008-03-06 05:54:12.000000000 +0300
13104 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/cpm_uart.h        2008-06-10 15:38:14.000000000 +0400
13105 @@ -50,6 +50,39 @@
13106  
13107  #define SCC_WAIT_CLOSING 100
13108  
13109 +#ifdef CONFIG_KGDB_CPM_UART
13110 +
13111 +/* Speed of the debug UART. */
13112 +#if defined(CONFIG_KGDB_9600BAUD)
13113 +#define KGDB_BAUD B9600
13114 +#elif defined(CONFIG_KGDB_19200BAUD)
13115 +#define KGDB_BAUD B19200
13116 +#elif defined(CONFIG_KGDB_38400BAUD)
13117 +#define KGDB_BAUD B38400
13118 +#elif defined(CONFIG_KGDB_57600BAUD)
13119 +#define KGDB_BAUD B57600
13120 +#else
13121 +#define KGDB_BAUD B115200      /* Start with this if not given */
13122 +#endif
13123 +
13124 +#ifdef CONFIG_KGDB_CPM_UART_SCC1
13125 +#define KGDB_PINFO_INDEX       UART_SCC1
13126 +#elif CONFIG_KGDB_CPM_UART_SCC2
13127 +#define KGDB_PINFO_INDEX       UART_SCC2
13128 +#elif CONFIG_KGDB_CPM_UART_SCC3
13129 +#define KGDB_PINFO_INDEX       UART_SCC3
13130 +#elif CONFIG_KGDB_CPM_UART_SCC4
13131 +#define KGDB_PINFO_INDEX       UART_SCC4
13132 +#elif CONFIG_KGDB_CPM_UART_SMC1
13133 +#define KGDB_PINFO_INDEX       UART_SMC1
13134 +#elif CONFIG_KGDB_CPM_UART_SMC2
13135 +#define KGDB_PINFO_INDEX       UART_SMC2
13136 +#else
13137 +#error The S(M)CC for kgdb console is undefined
13138 +#endif
13139 +
13140 +#endif /* CONFIG_KGDB_CPM_UART */
13141 +
13142  struct uart_cpm_port {
13143         struct uart_port        port;
13144         u16                     rx_nrfifos;
13145 @@ -86,6 +119,9 @@ extern int cpm_uart_port_map[UART_NR];
13146  extern int cpm_uart_nr;
13147  extern struct uart_cpm_port cpm_uart_ports[UART_NR];
13148  
13149 +void cpm_uart_early_write(int index, const char *s, u_int count);
13150 +int cpm_uart_early_setup(int index,int early);
13151 +
13152  /* these are located in their respective files */
13153  void cpm_line_cr_cmd(int line, int cmd);
13154  int cpm_uart_init_portdesc(void);
13155 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/cpm_uart/cpm_uart_core.c linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/cpm_uart_core.c
13156 --- linux-2.6.18-53.1.14/drivers/serial/cpm_uart/cpm_uart_core.c        2006-09-20 07:42:06.000000000 +0400
13157 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/cpm_uart_core.c   2008-06-10 15:38:14.000000000 +0400
13158 @@ -1070,22 +1070,17 @@ int cpm_uart_drv_get_platform_data(struc
13159         return 0;
13160  }
13161  
13162 -#ifdef CONFIG_SERIAL_CPM_CONSOLE
13163 -/*
13164 - *     Print a string to the serial port trying not to disturb
13165 - *     any possible real use of the port...
13166 - *
13167 - *     Note that this is called with interrupts already disabled
13168 - */
13169 -static void cpm_uart_console_write(struct console *co, const char *s,
13170 +void cpm_uart_early_write(int index, const char *s,
13171                                    u_int count)
13172  {
13173 -       struct uart_cpm_port *pinfo =
13174 -           &cpm_uart_ports[cpm_uart_port_map[co->index]];
13175 +       struct uart_cpm_port *pinfo;
13176         unsigned int i;
13177         volatile cbd_t *bdp, *bdbase;
13178         volatile unsigned char *cp;
13179  
13180 +       BUG_ON(index>UART_NR);
13181 +       pinfo = &cpm_uart_ports[index];
13182 +
13183         /* Get the address of the host memory buffer.
13184          */
13185         bdp = pinfo->tx_cur;
13186 @@ -1149,16 +1144,11 @@ static void cpm_uart_console_write(struc
13187         pinfo->tx_cur = (volatile cbd_t *) bdp;
13188  }
13189  
13190 -
13191 -static int __init cpm_uart_console_setup(struct console *co, char *options)
13192 +int cpm_uart_early_setup(int index, int early)
13193  {
13194 +       int ret;
13195         struct uart_port *port;
13196         struct uart_cpm_port *pinfo;
13197 -       int baud = 38400;
13198 -       int bits = 8;
13199 -       int parity = 'n';
13200 -       int flow = 'n';
13201 -       int ret;
13202  
13203         struct fs_uart_platform_info *pdata;
13204         struct platform_device* pdev = early_uart_get_pdev(co->index);
13205 @@ -1169,8 +1159,9 @@ static int __init cpm_uart_console_setup
13206                 cpm_uart_init_portdesc();
13207         }
13208  
13209 +       BUG_ON(index>UART_NR);
13210         port =
13211 -           (struct uart_port *)&cpm_uart_ports[cpm_uart_port_map[co->index]];
13212 +               (struct uart_port *)&cpm_uart_ports[index];
13213         pinfo = (struct uart_cpm_port *)port;
13214         if (!pdev) {
13215                 if (pinfo->set_lineif)
13216 @@ -1184,19 +1175,6 @@ static int __init cpm_uart_console_setup
13217                 cpm_uart_drv_get_platform_data(pdev, 1);
13218         }
13219  
13220 -       pinfo->flags |= FLAG_CONSOLE;
13221 -
13222 -       if (options) {
13223 -               uart_parse_options(options, &baud, &parity, &bits, &flow);
13224 -       } else {
13225 -               bd_t *bd = (bd_t *) __res;
13226 -
13227 -               if (bd->bi_baudrate)
13228 -                       baud = bd->bi_baudrate;
13229 -               else
13230 -                       baud = 9600;
13231 -       }
13232 -
13233         if (IS_SMC(pinfo)) {
13234                 pinfo->smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
13235                 pinfo->smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
13236 @@ -1204,8 +1182,7 @@ static int __init cpm_uart_console_setup
13237                 pinfo->sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
13238                 pinfo->sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
13239         }
13240 -
13241 -       ret = cpm_uart_allocbuf(pinfo, 1);
13242 +       ret = cpm_uart_allocbuf(pinfo, early);
13243  
13244         if (ret)
13245                 return ret;
13246 @@ -1217,6 +1194,56 @@ static int __init cpm_uart_console_setup
13247         else
13248                 cpm_uart_init_scc(pinfo);
13249  
13250 +       return 0;
13251 +}
13252 +
13253 +#ifdef CONFIG_SERIAL_CPM_CONSOLE
13254 +/*
13255 + *     Print a string to the serial port trying not to disturb
13256 + *     any possible real use of the port...
13257 + *
13258 + *     Note that this is called with interrupts already disabled
13259 + */
13260 +
13261 +static void cpm_uart_console_write(struct console *co, const char *s,
13262 +                                  u_int count)
13263 +{
13264 +       cpm_uart_early_write(cpm_uart_port_map[co->index],s,count);
13265 +}
13266 +
13267 +/*
13268 + * Setup console. Be careful is called early !
13269 + */
13270 +static int __init cpm_uart_console_setup(struct console *co, char *options)
13271 +{
13272 +       struct uart_port *port;
13273 +       struct uart_cpm_port *pinfo;
13274 +       int baud = 115200;
13275 +       int bits = 8;
13276 +       int parity = 'n';
13277 +       int flow = 'n';
13278 +       int ret;
13279 +
13280 +       port =
13281 +           (struct uart_port *)&cpm_uart_ports[cpm_uart_port_map[co->index]];
13282 +       pinfo = (struct uart_cpm_port *)port;
13283 +
13284 +       pinfo->flags |= FLAG_CONSOLE;
13285 +
13286 +       if (options) {
13287 +               uart_parse_options(options, &baud, &parity, &bits, &flow);
13288 +       } else {
13289 +               bd_t *bd = (bd_t *) __res;
13290 +
13291 +               if (bd->bi_baudrate)
13292 +                       baud = bd->bi_baudrate;
13293 +               else
13294 +                       baud = 9600;
13295 +       }
13296 +
13297 +       ret = cpm_uart_early_setup(cpm_uart_port_map[co->index], 1);
13298 +       if(ret)
13299 +               return ret;
13300         uart_set_options(port, co, baud, parity, bits, flow);
13301  
13302         return 0;
13303 @@ -1364,6 +1391,12 @@ static int cpm_uart_init(void) {
13304  
13305                 for (i = 0; i < cpm_uart_nr; i++) {
13306                         int con = cpm_uart_port_map[i];
13307 +
13308 +#ifdef CONFIG_KGDB_CPM_UART
13309 +               /* We are not interested in ports yet utilized by kgdb */
13310 +               if(con == KGDB_PINFO_INDEX)
13311 +                       continue;
13312 +#endif
13313                         cpm_uart_ports[con].port.line = i;
13314                         cpm_uart_ports[con].port.flags = UPF_BOOT_AUTOCONF;
13315                         uart_add_one_port(&cpm_reg, &cpm_uart_ports[con].port);
13316 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/cpm_uart/cpm_uart_cpm1.c linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/cpm_uart_cpm1.c
13317 --- linux-2.6.18-53.1.14/drivers/serial/cpm_uart/cpm_uart_cpm1.c        2006-09-20 07:42:06.000000000 +0400
13318 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/cpm_uart_cpm1.c   2008-06-10 15:38:14.000000000 +0400
13319 @@ -52,6 +52,7 @@ void cpm_line_cr_cmd(int line, int cmd)
13320  {
13321         ushort val;
13322         volatile cpm8xx_t *cp = cpmp;
13323 +       unsigned *bcsr_io;
13324  
13325         switch (line) {
13326         case UART_SMC1:
13327 @@ -94,12 +95,35 @@ void scc1_lineif(struct uart_cpm_port *p
13328  {
13329         /* XXX SCC1: insert port configuration here */
13330         pinfo->brg = 1;
13331 +
13332 +#if defined (CONFIG_MPC885ADS) || defined (CONFIG_MPC86XADS)
13333 +       bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
13334 +
13335 +       if (bcsr_io == NULL) {
13336 +               printk(KERN_CRIT "Could not remap BCSR\n");
13337 +               return;
13338 +       }
13339 +       out_be32(bcsr_io, in_be32(bcsr_io) & ~BCSR1_RS232EN_1);
13340 +       iounmap(bcsr_io);
13341 +#endif
13342  }
13343  
13344  void scc2_lineif(struct uart_cpm_port *pinfo)
13345  {
13346         /* XXX SCC2: insert port configuration here */
13347         pinfo->brg = 2;
13348 +       unsigned *bcsr_io;
13349 +
13350 +#if defined (CONFIG_MPC885ADS) || defined (CONFIG_MPC86XADS)
13351 +       bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
13352 +
13353 +       if (bcsr_io == NULL) {
13354 +               printk(KERN_CRIT "Could not remap BCSR\n");
13355 +               return;
13356 +       }
13357 +        out_be32(bcsr_io, in_be32(bcsr_io) & ~BCSR1_RS232EN_2);
13358 +       iounmap(bcsr_io);
13359 +#endif
13360  }
13361  
13362  void scc3_lineif(struct uart_cpm_port *pinfo)
13363 @@ -188,6 +212,10 @@ int cpm_uart_init_portdesc(void)
13364  {
13365         pr_debug("CPM uart[-]:init portdesc\n");
13366  
13367 +       /* Check if we have called this yet. This may happen if early kgdb
13368 +       breakpoint is on */
13369 +       if(cpm_uart_nr)
13370 +               return 0;
13371         cpm_uart_nr = 0;
13372  #ifdef CONFIG_SERIAL_CPM_SMC1
13373         cpm_uart_ports[UART_SMC1].smcp = &cpmp->cp_smc[0];
13374 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/cpm_uart/cpm_uart_cpm2.c linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/cpm_uart_cpm2.c
13375 --- linux-2.6.18-53.1.14/drivers/serial/cpm_uart/cpm_uart_cpm2.c        2006-09-20 07:42:06.000000000 +0400
13376 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/cpm_uart_cpm2.c   2008-06-10 15:38:14.000000000 +0400
13377 @@ -256,6 +256,10 @@ int cpm_uart_init_portdesc(void)
13378  {
13379         pr_debug("CPM uart[-]:init portdesc\n");
13380  
13381 +       /* Check if we have called this yet. This may happen if early kgdb
13382 +       breakpoint is on */
13383 +       if(cpm_uart_nr)
13384 +               return 0;
13385         cpm_uart_nr = 0;
13386  #ifdef CONFIG_SERIAL_CPM_SMC1
13387         cpm_uart_ports[UART_SMC1].smcp = (smc_t *) & cpm2_immr->im_smc[0];
13388 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/cpm_uart/cpm_uart_kgdb.c linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/cpm_uart_kgdb.c
13389 --- linux-2.6.18-53.1.14/drivers/serial/cpm_uart/cpm_uart_kgdb.c        1970-01-01 03:00:00.000000000 +0300
13390 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/cpm_uart/cpm_uart_kgdb.c   2008-06-10 15:38:14.000000000 +0400
13391 @@ -0,0 +1,195 @@
13392 +/*
13393 + * drivers/serial/cpm_uart/cpm_uart_kgdb.c
13394 + *
13395 + * CPM UART interface for kgdb.
13396 + *
13397 + * Author: Vitaly Bordug <vbordug@ru.mvista.com>
13398 + *
13399 + * Used some bits from drivers/serial/kgdb_8250.c as a template
13400 + *
13401 + * 2005 (c) MontaVista Software, Inc. This file is licensed under
13402 + * the terms of the GNU General Public License version 2. This program
13403 + * is licensed "as is" without any warranty of any kind, whether express
13404 + * or implied.
13405 + */
13406 +
13407 +#include <linux/kgdb.h>
13408 +#include <linux/config.h>
13409 +#include <linux/kernel.h>
13410 +#include <linux/init.h>
13411 +#include <linux/interrupt.h>
13412 +#include <linux/tty.h>
13413 +#include <linux/serial.h>
13414 +#include <linux/serial_core.h>
13415 +#include <linux/serial_reg.h>
13416 +
13417 +#include <asm/io.h>
13418 +#include <asm/serial.h>                /* For BASE_BAUD and SERIAL_PORT_DFNS */
13419 +
13420 +#include "cpm_uart.h"
13421 +
13422 +#define GDB_BUF_SIZE   512     /* power of 2, please */
13423 +
13424 +
13425 +static char kgdb_buf[GDB_BUF_SIZE], *kgdbp;
13426 +static int kgdb_chars;
13427 +
13428 +/* Forward declarations. */
13429 +
13430 +/*
13431 + * Receive character from the serial port.  This only works well
13432 + * before the port is initialize for real use.
13433 + */
13434 +static int kgdb_wait_key(char *obuf)
13435 +{
13436 +       struct uart_cpm_port *pinfo;
13437 +
13438 +       u_char                          c, *cp;
13439 +       volatile        cbd_t           *bdp;
13440 +       int                             i;
13441 +
13442 +       pinfo = &cpm_uart_ports[KGDB_PINFO_INDEX];
13443 +
13444 +       /* Get the address of the host memory buffer.
13445 +        */
13446 +       bdp = pinfo->rx_cur;
13447 +       while (bdp->cbd_sc & BD_SC_EMPTY);
13448 +
13449 +       /* If the buffer address is in the CPM DPRAM, don't
13450 +        * convert it.
13451 +        */
13452 +       cp = cpm2cpu_addr(bdp->cbd_bufaddr);
13453 +
13454 +       if (obuf) {
13455 +               i = c = bdp->cbd_datlen;
13456 +               while (i-- > 0)
13457 +               {
13458 +                       *obuf++ = *cp++;
13459 +               }
13460 +       } else {
13461 +               c = *cp;
13462 +       }
13463 +       bdp->cbd_sc |= BD_SC_EMPTY;
13464 +
13465 +       if (bdp->cbd_sc & BD_SC_WRAP) {
13466 +               bdp = pinfo->rx_bd_base;
13467 +       } else {
13468 +               bdp++;
13469 +       }
13470 +       pinfo->rx_cur = (cbd_t *)bdp;
13471 +
13472 +       return((int)c);
13473 +}
13474 +
13475 +
13476 +/*
13477 + * Wait until the interface can accept a char, then write it.
13478 + */
13479 +static void
13480 +kgdb_put_debug_char(int chr)
13481 +{
13482 +       static char ch[2];
13483 +       ch[0]=(char)chr;
13484 +       cpm_uart_early_write(KGDB_PINFO_INDEX, ch, 1);
13485 +}
13486 +
13487 +
13488 +/*
13489 + * Get a char if available, return -1 if nothing available.
13490 + * Empty the receive buffer first, then look at the interface hardware.
13491 + */
13492 +static int
13493 +kgdb_get_debug_char(void)
13494 +{
13495 +       if (kgdb_chars<=0) {
13496 +               kgdb_chars = kgdb_wait_key(kgdb_buf);
13497 +               kgdbp = kgdb_buf;
13498 +       }
13499 +       kgdb_chars--;
13500 +
13501 +       return (*kgdbp++);
13502 +}
13503 +
13504 +static void termios_set_options(int index,
13505 +                int baud, int parity, int bits, int flow)
13506 +{
13507 +       struct termios termios;
13508 +       struct uart_port *port;
13509 +       struct uart_cpm_port *pinfo;
13510 +
13511 +       BUG_ON(index>UART_NR);
13512 +
13513 +       port =
13514 +           (struct uart_port *)&cpm_uart_ports[index];
13515 +       pinfo = (struct uart_cpm_port *)port;
13516 +
13517 +       /*
13518 +        * Ensure that the serial console lock is initialised
13519 +        * early.
13520 +        */
13521 +       spin_lock_init(&port->lock);
13522 +
13523 +       memset(&termios, 0, sizeof(struct termios));
13524 +
13525 +       termios.c_cflag = CREAD | HUPCL | CLOCAL;
13526 +
13527 +       termios.c_cflag |= baud;
13528 +
13529 +       if (bits == 7)
13530 +               termios.c_cflag |= CS7;
13531 +       else
13532 +               termios.c_cflag |= CS8;
13533 +
13534 +       switch (parity) {
13535 +       case 'o': case 'O':
13536 +               termios.c_cflag |= PARODD;
13537 +               /*fall through*/
13538 +       case 'e': case 'E':
13539 +               termios.c_cflag |= PARENB;
13540 +               break;
13541 +       }
13542 +
13543 +       if (flow == 'r')
13544 +               termios.c_cflag |= CRTSCTS;
13545 +
13546 +       port->ops->set_termios(port, &termios, NULL);
13547 +}
13548 +
13549 +/*
13550 + *  Returns:
13551 + *     0 on success, 1 on failure.
13552 + */
13553 +static int kgdb_init(void)
13554 +{
13555 +       struct uart_port *port;
13556 +       struct uart_cpm_port *pinfo;
13557 +
13558 +       int use_bootmem = 0; /* use dma by default */
13559 +
13560 +       if(!cpm_uart_nr)
13561 +       {
13562 +               use_bootmem = 1;
13563 +               cpm_uart_init_portdesc();
13564 +       }
13565 +       port = (struct uart_port *)&cpm_uart_ports[KGDB_PINFO_INDEX];
13566 +       pinfo = (struct uart_cpm_port *)port;
13567 +
13568 +       if (cpm_uart_early_setup(KGDB_PINFO_INDEX, use_bootmem))
13569 +               return 1;
13570 +
13571 +       termios_set_options(KGDB_PINFO_INDEX, KGDB_BAUD,'n',8,'n');
13572 +        if (IS_SMC(pinfo))
13573 +                pinfo->smcp->smc_smcm |= SMCM_TX;
13574 +        else
13575 +                pinfo->sccp->scc_sccm |= UART_SCCM_TX;
13576 +
13577 +       return 0;
13578 +}
13579 +
13580 +
13581 +struct kgdb_io kgdb_io_ops = {
13582 +       .read_char = kgdb_get_debug_char,
13583 +       .write_char = kgdb_put_debug_char,
13584 +       .init = kgdb_init,
13585 +};
13586 +
13587 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/mpsc.c linux-2.6.18-53.1.14.kgdb/drivers/serial/mpsc.c
13588 --- linux-2.6.18-53.1.14/drivers/serial/mpsc.c  2006-09-20 07:42:06.000000000 +0400
13589 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/mpsc.c     2008-06-10 15:38:14.000000000 +0400
13590 @@ -242,6 +242,11 @@ struct mpsc_port_info *mpsc_device_remov
13591  #define        MPSC_RCRR                       0x0004
13592  #define        MPSC_TCRR                       0x0008
13593  
13594 +/* MPSC Interrupt registers (offset from MV64x60_SDMA_INTR_OFFSET) */
13595 +#define MPSC_INTR_CAUSE                        0x0004
13596 +#define MPSC_INTR_MASK                 0x0084
13597 +#define MPSC_INTR_CAUSE_RCC            (1<<6)
13598 +
13599  /* Serial DMA Controller Interface Registers */
13600  #define        SDMA_SDC                        0x0000
13601  #define        SDMA_SDCM                       0x0008
13602 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/mpsc_kgdb.c linux-2.6.18-53.1.14.kgdb/drivers/serial/mpsc_kgdb.c
13603 --- linux-2.6.18-53.1.14/drivers/serial/mpsc_kgdb.c     1970-01-01 03:00:00.000000000 +0300
13604 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/mpsc_kgdb.c        2008-06-10 15:38:14.000000000 +0400
13605 @@ -0,0 +1,299 @@
13606 +/*
13607 + * drivers/serial/mpsc_kgdb.c
13608 + *
13609 + * KGDB driver for the Marvell MultiProtocol Serial Controller (MPCS)
13610 + *
13611 + * Based on the polled boot loader driver by Ajit Prem (ajit.prem@motorola.com)
13612 + *
13613 + * Author: Randy Vinson <rvinson@mvista.com>
13614 + *
13615 + * 2005 (c) MontaVista Software, Inc.
13616 + * This program is free software; you can redistribute  it and/or modify it
13617 + * under  the terms of  the GNU General  Public License as published by the
13618 + * Free Software Foundation;  either version 2 of the  License, or (at your
13619 + * option) any later version.
13620 + */
13621 +
13622 +#include <linux/config.h>
13623 +#include <linux/kgdb.h>
13624 +#include <linux/mv643xx.h>
13625 +#include <linux/device.h>
13626 +#include <asm/mv64x60.h>
13627 +#include <asm/serial.h>
13628 +#include <asm/io.h>
13629 +#include <asm/delay.h>
13630 +
13631 +#include "mpsc.h"
13632 +
13633 +/* Speed of the UART. */
13634 +static int kgdbmpsc_baud = CONFIG_KGDB_BAUDRATE;
13635 +
13636 +/* Index of the UART, matches ttyMX naming. */
13637 +static int kgdbmpsc_ttyMM = CONFIG_KGDB_PORT_NUM;
13638 +
13639 +#define MPSC_INTR_REG_SELECT(x)        ((x) + (8 * kgdbmpsc_ttyMM))
13640 +
13641 +static int kgdbmpsc_init(void);
13642 +
13643 +static struct platform_device mpsc_dev, shared_dev;
13644 +
13645 +static void __iomem *mpsc_base;
13646 +static void __iomem *brg_base;
13647 +static void __iomem *routing_base;
13648 +static void __iomem *sdma_base;
13649 +
13650 +static unsigned int mpsc_irq;
13651 +
13652 +static void kgdb_write_debug_char(int c)
13653 +{
13654 +       u32 data;
13655 +
13656 +       data = readl(mpsc_base + MPSC_MPCR);
13657 +       writeb(c, mpsc_base + MPSC_CHR_1);
13658 +       mb();
13659 +       data = readl(mpsc_base + MPSC_CHR_2);
13660 +       data |= MPSC_CHR_2_TTCS;
13661 +       writel(data, mpsc_base + MPSC_CHR_2);
13662 +       mb();
13663 +
13664 +       while (readl(mpsc_base + MPSC_CHR_2) & MPSC_CHR_2_TTCS) ;
13665 +}
13666 +
13667 +static int kgdb_get_debug_char(void)
13668 +{
13669 +       unsigned char c;
13670 +
13671 +       while (!(readl(sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_CAUSE)) &
13672 +                MPSC_INTR_CAUSE_RCC)) ;
13673 +
13674 +       c = readb(mpsc_base + MPSC_CHR_10 + (1 << 1));
13675 +       mb();
13676 +       writeb(c, mpsc_base + MPSC_CHR_10 + (1 << 1));
13677 +       mb();
13678 +       writel(~MPSC_INTR_CAUSE_RCC, sdma_base +
13679 +              MPSC_INTR_REG_SELECT(MPSC_INTR_CAUSE));
13680 +       return (c);
13681 +}
13682 +
13683 +/*
13684 + * This is the receiver interrupt routine for the GDB stub.
13685 + * All that we need to do is verify that the interrupt happened on the
13686 + * line we're in charge of.  If this is true, schedule a breakpoint and
13687 + * return.
13688 + */
13689 +static irqreturn_t
13690 +kgdbmpsc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
13691 +{
13692 +       if (irq != mpsc_irq)
13693 +               return IRQ_NONE;
13694 +       /*
13695 +        * If  there is some other CPU in KGDB then this is a
13696 +        * spurious interrupt. so return without even checking a byte
13697 +        */
13698 +       if (atomic_read(&debugger_active))
13699 +               return IRQ_NONE;
13700 +
13701 +       if (readl(sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_CAUSE)) &
13702 +           MPSC_INTR_CAUSE_RCC)
13703 +               breakpoint();
13704 +
13705 +       return IRQ_HANDLED;
13706 +}
13707 +
13708 +static int __init kgdbmpsc_init(void)
13709 +{
13710 +       struct mpsc_pdata *pdata;
13711 +       u32 cdv;
13712 +
13713 +       if (!brg_base || !mpsc_base || !routing_base || !sdma_base)
13714 +               return -1;
13715 +
13716 +       /* Set MPSC Routing to enable both ports */
13717 +       writel(0x0, routing_base + MPSC_MRR);
13718 +
13719 +       /* MPSC 0/1 Rx & Tx get clocks BRG0/1 */
13720 +       writel(0x00000100, routing_base + MPSC_RCRR);
13721 +       writel(0x00000100, routing_base + MPSC_TCRR);
13722 +
13723 +       /* Disable all MPSC interrupts and clear any pending interrupts */
13724 +       writel(0, sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_MASK));
13725 +       writel(0, sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_CAUSE));
13726 +
13727 +       pdata = (struct mpsc_pdata *)mpsc_dev.dev.platform_data;
13728 +
13729 +       /* cdv = (clock/(2*16*baud rate)) for 16X mode. */
13730 +       cdv = ((pdata->brg_clk_freq / (32 * kgdbmpsc_baud)) - 1);
13731 +       writel((pdata->brg_clk_src << 18) | (1 << 16) | cdv,
13732 +              brg_base + BRG_BCR);
13733 +
13734 +       /* Put MPSC into UART mode, no null modem, 16x clock mode */
13735 +       writel(0x000004c4, mpsc_base + MPSC_MMCRL);
13736 +       writel(0x04400400, mpsc_base + MPSC_MMCRH);
13737 +
13738 +       writel(0, mpsc_base + MPSC_CHR_1);
13739 +       writel(0, mpsc_base + MPSC_CHR_9);
13740 +       writel(0, mpsc_base + MPSC_CHR_10);
13741 +       writel(4, mpsc_base + MPSC_CHR_3);
13742 +       writel(0x20000000, mpsc_base + MPSC_CHR_4);
13743 +       writel(0x9000, mpsc_base + MPSC_CHR_5);
13744 +       writel(0, mpsc_base + MPSC_CHR_6);
13745 +       writel(0, mpsc_base + MPSC_CHR_7);
13746 +       writel(0, mpsc_base + MPSC_CHR_8);
13747 +
13748 +       /* 8 data bits, 1 stop bit */
13749 +       writel((3 << 12), mpsc_base + MPSC_MPCR);
13750 +
13751 +       /* Enter "hunt" mode */
13752 +       writel((1 << 31), mpsc_base + MPSC_CHR_2);
13753 +
13754 +       udelay(100);
13755 +       return 0;
13756 +}
13757 +
13758 +static void __iomem *__init
13759 +kgdbmpsc_map_resource(struct platform_device *pd, int type, int num)
13760 +{
13761 +       void __iomem *base = NULL;
13762 +       struct resource *r;
13763 +
13764 +       if ((r = platform_get_resource(pd, IORESOURCE_MEM, num)))
13765 +               base = ioremap(r->start, r->end - r->start + 1);
13766 +       return base;
13767 +}
13768 +
13769 +static void __iomem *__init
13770 +kgdbmpsc_unmap_resource(struct platform_device *pd, int type, int num,
13771 +                       void __iomem * base)
13772 +{
13773 +       if (base)
13774 +               iounmap(base);
13775 +       return NULL;
13776 +}
13777 +
13778 +static void __init
13779 +kgdbmpsc_reserve_resource(struct platform_device *pd, int type, int num)
13780 +{
13781 +       struct resource *r;
13782 +
13783 +       if ((r = platform_get_resource(pd, IORESOURCE_MEM, num)))
13784 +               request_mem_region(r->start, r->end - r->start + 1, "kgdb");
13785 +}
13786 +
13787 +static int __init kgdbmpsc_local_init(void)
13788 +{
13789 +       if (!mpsc_dev.num_resources || !shared_dev.num_resources)
13790 +               return 1;       /* failure */
13791 +
13792 +       mpsc_base = kgdbmpsc_map_resource(&mpsc_dev, IORESOURCE_MEM,
13793 +                                         MPSC_BASE_ORDER);
13794 +       brg_base = kgdbmpsc_map_resource(&mpsc_dev, IORESOURCE_MEM,
13795 +                                        MPSC_BRG_BASE_ORDER);
13796 +
13797 +       /* get the platform data for the shared registers and get them mapped */
13798 +       routing_base = kgdbmpsc_map_resource(&shared_dev,
13799 +                                            IORESOURCE_MEM,
13800 +                                            MPSC_ROUTING_BASE_ORDER);
13801 +       sdma_base =
13802 +           kgdbmpsc_map_resource(&shared_dev, IORESOURCE_MEM,
13803 +                                 MPSC_SDMA_INTR_BASE_ORDER);
13804 +
13805 +       mpsc_irq = platform_get_irq(&mpsc_dev, 1);
13806 +
13807 +       if (mpsc_base && brg_base && routing_base && sdma_base)
13808 +               return 0;       /* success */
13809 +
13810 +       return 1;               /* failure */
13811 +}
13812 +
13813 +static void __init kgdbmpsc_local_exit(void)
13814 +{
13815 +       if (sdma_base)
13816 +               sdma_base = kgdbmpsc_unmap_resource(&shared_dev, IORESOURCE_MEM,
13817 +                                                   MPSC_SDMA_INTR_BASE_ORDER,
13818 +                                                   sdma_base);
13819 +       if (routing_base)
13820 +               routing_base = kgdbmpsc_unmap_resource(&shared_dev,
13821 +                                                      IORESOURCE_MEM,
13822 +                                                      MPSC_ROUTING_BASE_ORDER,
13823 +                                                      routing_base);
13824 +       if (brg_base)
13825 +               brg_base = kgdbmpsc_unmap_resource(&mpsc_dev, IORESOURCE_MEM,
13826 +                                                  MPSC_BRG_BASE_ORDER,
13827 +                                                  brg_base);
13828 +       if (mpsc_base)
13829 +               mpsc_base = kgdbmpsc_unmap_resource(&mpsc_dev, IORESOURCE_MEM,
13830 +                                                   MPSC_BASE_ORDER, mpsc_base);
13831 +}
13832 +
13833 +static void __init kgdbmpsc_update_pdata(struct platform_device *pdev)
13834 +{
13835 +
13836 +       snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s%u", pdev->name, pdev->id);
13837 +}
13838 +
13839 +static int __init kgdbmpsc_pdev_init(void)
13840 +{
13841 +       struct platform_device *pdev;
13842 +
13843 +       /* get the platform data for the specified port. */
13844 +       pdev = mv64x60_early_get_pdev_data(MPSC_CTLR_NAME, kgdbmpsc_ttyMM, 1);
13845 +       if (pdev) {
13846 +               memcpy(&mpsc_dev, pdev, sizeof(struct platform_device));
13847 +               if (platform_notify) {
13848 +                       kgdbmpsc_update_pdata(&mpsc_dev);
13849 +                       platform_notify(&mpsc_dev.dev);
13850 +               }
13851 +
13852 +               /* get the platform data for the shared registers. */
13853 +               pdev = mv64x60_early_get_pdev_data(MPSC_SHARED_NAME, 0, 0);
13854 +               if (pdev) {
13855 +                       memcpy(&shared_dev, pdev,
13856 +                              sizeof(struct platform_device));
13857 +                       if (platform_notify) {
13858 +                               kgdbmpsc_update_pdata(&shared_dev);
13859 +                               platform_notify(&shared_dev.dev);
13860 +                       }
13861 +               }
13862 +       }
13863 +       return 0;
13864 +}
13865 +
13866 +postcore_initcall(kgdbmpsc_pdev_init);
13867 +
13868 +static int __init kgdbmpsc_init_io(void)
13869 +{
13870 +
13871 +       kgdbmpsc_pdev_init();
13872 +
13873 +       if (kgdbmpsc_local_init()) {
13874 +               kgdbmpsc_local_exit();
13875 +               return -1;
13876 +       }
13877 +
13878 +       if (kgdbmpsc_init() == -1)
13879 +               return -1;
13880 +       return 0;
13881 +}
13882 +
13883 +static void __init kgdbmpsc_hookup_irq(void)
13884 +{
13885 +       unsigned int msk;
13886 +       if (!request_irq(mpsc_irq, kgdbmpsc_interrupt, 0, "kgdb mpsc", NULL)) {
13887 +               /* Enable interrupt */
13888 +               msk = readl(sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_MASK));
13889 +               msk |= MPSC_INTR_CAUSE_RCC;
13890 +               writel(msk, sdma_base + MPSC_INTR_REG_SELECT(MPSC_INTR_MASK));
13891 +
13892 +               kgdbmpsc_reserve_resource(&mpsc_dev, IORESOURCE_MEM,
13893 +                                         MPSC_BASE_ORDER);
13894 +               kgdbmpsc_reserve_resource(&mpsc_dev, IORESOURCE_MEM,
13895 +                                         MPSC_BRG_BASE_ORDER);
13896 +       }
13897 +}
13898 +
13899 +struct kgdb_io kgdb_io_ops = {
13900 +       .read_char = kgdb_get_debug_char,
13901 +       .write_char = kgdb_write_debug_char,
13902 +       .init = kgdbmpsc_init_io,
13903 +       .late_init = kgdbmpsc_hookup_irq,
13904 +};
13905 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/pxa.c linux-2.6.18-53.1.14.kgdb/drivers/serial/pxa.c
13906 --- linux-2.6.18-53.1.14/drivers/serial/pxa.c   2006-09-20 07:42:06.000000000 +0400
13907 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/pxa.c      2008-06-10 15:38:56.000000000 +0400
13908 @@ -42,6 +42,9 @@
13909  #include <linux/tty.h>
13910  #include <linux/tty_flip.h>
13911  #include <linux/serial_core.h>
13912 +#ifdef CONFIG_KGDB_CONSOLE
13913 +#include <linux/kgdb.h>
13914 +#endif
13915  
13916  #include <asm/io.h>
13917  #include <asm/hardware.h>
13918 @@ -692,6 +695,8 @@ serial_pxa_console_init(void)
13919  console_initcall(serial_pxa_console_init);
13920  
13921  #define PXA_CONSOLE    &serial_pxa_console
13922 +#elif defined(CONFIG_KGDB_CONSOLE)
13923 +#define PXA_CONSOLE    &kgdbcons
13924  #else
13925  #define PXA_CONSOLE    NULL
13926  #endif
13927 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/serial_core.c linux-2.6.18-53.1.14.kgdb/drivers/serial/serial_core.c
13928 --- linux-2.6.18-53.1.14/drivers/serial/serial_core.c   2008-03-06 05:54:07.000000000 +0300
13929 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/serial_core.c      2008-06-10 15:37:43.000000000 +0400
13930 @@ -33,6 +33,7 @@
13931  #include <linux/serial.h> /* for serial_state and serial_icounter_struct */
13932  #include <linux/delay.h>
13933  #include <linux/mutex.h>
13934 +#include <linux/kgdb.h>
13935  
13936  #include <asm/irq.h>
13937  #include <asm/uaccess.h>
13938 @@ -65,6 +66,12 @@ static struct lock_class_key port_lock_k
13939  #define uart_console(port)     (0)
13940  #endif
13941  
13942 +#ifdef CONFIG_KGDB_CONSOLE
13943 +#define uart_kgdb(port)                (port->cons && !strcmp(port->cons->name, "kgdb"))
13944 +#else
13945 +#define uart_kgdb(port)                (0)
13946 +#endif
13947 +
13948  static void uart_change_speed(struct uart_state *state, struct termios *old_termios);
13949  static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
13950  static void uart_change_pm(struct uart_state *state, int pm_state);
13951 @@ -1673,6 +1680,9 @@ static int uart_line_info(char *buf, str
13952                         port->iotype == UPIO_MEM ? port->mapbase :
13953                                                 (unsigned long) port->iobase,
13954                         port->irq);
13955 +       if (port->iotype == UPIO_MEM)
13956 +               ret += sprintf(buf+ret, " membase 0x%08lX",
13957 +                                          (unsigned long) port->membase);
13958  
13959         if (port->type == PORT_UNKNOWN) {
13960                 strcat(buf, "\n");
13961 @@ -2043,7 +2053,8 @@ uart_report_port(struct uart_driver *drv
13962         case UPIO_AU:
13963         case UPIO_TSI:
13964                 snprintf(address, sizeof(address),
13965 -                        "MMIO 0x%lx", port->mapbase);
13966 +                       "MMIO map 0x%lx mem 0x%lx", port->mapbase,
13967 +                       (unsigned long) port->membase);
13968                 break;
13969         default:
13970                 strlcpy(address, "*unknown*", sizeof(address));
13971 @@ -2095,9 +2106,9 @@ uart_configure_port(struct uart_driver *
13972  
13973                 /*
13974                  * Power down all ports by default, except the
13975 -                * console if we have one.
13976 +                * console (real or kgdb) if we have one.
13977                  */
13978 -               if (!uart_console(port))
13979 +               if (!uart_console(port) && !uart_kgdb(port))
13980                         uart_change_pm(state, 3);
13981         }
13982  }
13983 @@ -2289,6 +2300,12 @@ int uart_add_one_port(struct uart_driver
13984          */
13985         port->flags &= ~UPF_DEAD;
13986  
13987 +#if defined(CONFIG_KGDB_8250)
13988 +       /* Add any 8250-like ports we find later. */
13989 +       if (port->type <= PORT_MAX_8250)
13990 +               kgdb8250_add_port(port->line, port);
13991 +#endif
13992 +
13993   out:
13994         mutex_unlock(&state->mutex);
13995         mutex_unlock(&port_mutex);
13996 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/serial_txx9.c linux-2.6.18-53.1.14.kgdb/drivers/serial/serial_txx9.c
13997 --- linux-2.6.18-53.1.14/drivers/serial/serial_txx9.c   2006-09-20 07:42:06.000000000 +0400
13998 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/serial_txx9.c      2008-06-10 15:38:24.000000000 +0400
13999 @@ -1164,6 +1164,96 @@ static struct pci_driver serial_txx9_pci
14000  MODULE_DEVICE_TABLE(pci, serial_txx9_pci_tbl);
14001  #endif /* ENABLE_SERIAL_TXX9_PCI */
14002  
14003 +/******************************************************************************/
14004 +/* BEG: KDBG Routines                                                         */
14005 +/******************************************************************************/
14006 +
14007 +#ifdef CONFIG_KGDB
14008 +int kgdb_init_count = 0;
14009 +
14010 +void txx9_sio_kgdb_hook(unsigned int port, unsigned int baud_rate)
14011 +{
14012 +       static struct resource kgdb_resource;
14013 +       int ret;
14014 +       struct uart_txx9_port *up = &serial_txx9_ports[port];
14015 +
14016 +       /* prevent initialization by driver */
14017 +       kgdb_resource.name = "serial_txx9(debug)";
14018 +       kgdb_resource.start = (unsigned long)up->port.membase;
14019 +       kgdb_resource.end = (unsigned long)(up->port.membase + 36 - 1);
14020 +       kgdb_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
14021 +
14022 +       ret = request_resource(&iomem_resource, &kgdb_resource);
14023 +       if(ret == -EBUSY)
14024 +               printk(" serial_txx9(debug): request_resource failed\n");
14025 +
14026 +       return;
14027 +}
14028 +void
14029 +txx9_sio_kdbg_init( unsigned int port_number )
14030 +{
14031 +       if (port_number == 1) {
14032 +               txx9_sio_kgdb_hook(port_number, 38400);
14033 +       } else {
14034 +               printk("Bad Port Number [%u] != [1]\n",port_number);
14035 +       }
14036 +       return;
14037 +}
14038 +
14039 +u8
14040 +txx9_sio_kdbg_rd( void )
14041 +{
14042 +       unsigned int status,ch;
14043 +       struct uart_txx9_port *up = &serial_txx9_ports[1];
14044 +
14045 +       if (kgdb_init_count == 0) {
14046 +               txx9_sio_kdbg_init(1);
14047 +               kgdb_init_count = 1;
14048 +       }
14049 +
14050 +       while (1) {
14051 +               status = sio_in(up, TXX9_SIDISR);
14052 +               if ( status & 0x1f ) {
14053 +                       ch = sio_in(up, TXX9_SIRFIFO );
14054 +                       break;
14055 +               }
14056 +       }
14057 +
14058 +       return (ch);
14059 +}
14060 +
14061 +int
14062 +txx9_sio_kdbg_wr( u8 ch )
14063 +{
14064 +       unsigned int status;
14065 +       struct uart_txx9_port *up = &serial_txx9_ports[1];
14066 +
14067 +       if (kgdb_init_count == 0) {
14068 +               txx9_sio_kdbg_init(1);
14069 +               kgdb_init_count = 1;
14070 +       }
14071 +
14072 +       while (1) {
14073 +               status = sio_in(up, TXX9_SICISR);
14074 +               if (status & TXX9_SICISR_TRDY) {
14075 +                       if ( ch == '\n' ) {
14076 +                               txx9_sio_kdbg_wr( '\r' );
14077 +                       }
14078 +                       sio_out(up, TXX9_SITFIFO, (u32)ch );
14079 +
14080 +                       break;
14081 +               }
14082 +       }
14083 +
14084 +       return (1);
14085 +}
14086 +#endif /* CONFIG_KGDB */
14087 +
14088 +
14089 +/******************************************************************************/
14090 +/* END: KDBG Routines                                                         */
14091 +/******************************************************************************/
14092 +
14093  static int __init serial_txx9_init(void)
14094  {
14095         int ret;
14096 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/drivers/serial/sh-sci.c linux-2.6.18-53.1.14.kgdb/drivers/serial/sh-sci.c
14097 --- linux-2.6.18-53.1.14/drivers/serial/sh-sci.c        2006-09-20 07:42:06.000000000 +0400
14098 +++ linux-2.6.18-53.1.14.kgdb/drivers/serial/sh-sci.c   2008-06-10 15:38:50.000000000 +0400
14099 @@ -42,6 +42,7 @@
14100  #include <linux/console.h>
14101  #include <linux/bitops.h>
14102  #include <linux/generic_serial.h>
14103 +#include <linux/kgdb.h>
14104  
14105  #ifdef CONFIG_CPU_FREQ
14106  #include <linux/notifier.h>
14107 @@ -67,14 +68,16 @@
14108  
14109  #include "sh-sci.h"
14110  
14111 -#ifdef CONFIG_SH_KGDB
14112 -#include <asm/kgdb.h>
14113 -
14114 -static int kgdb_get_char(struct sci_port *port);
14115 -static void kgdb_put_char(struct sci_port *port, char c);
14116 -static void kgdb_handle_error(struct sci_port *port);
14117 -static struct sci_port *kgdb_sci_port;
14118 -#endif /* CONFIG_SH_KGDB */
14119 +#ifdef CONFIG_KGDB_SH_SCI
14120 +/* Speed of the UART. */
14121 +static int kgdbsci_baud = CONFIG_KGDB_BAUDRATE
14122 +
14123 +/* Index of the UART, matches ttySCX naming. */
14124 +static int kgdbsci_ttySC = CONFIG_KGDB_PORT_NUM;
14125 +
14126 +/* Make life easier on us. */
14127 +#define KGDBPORT       sci_ports[kgdbsci_ttySC]
14128 +#endif /* CONFIG_KGDB_SH_SCI */
14129  
14130  #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
14131  static struct sci_port *serial_console_port = 0;
14132 @@ -87,20 +90,17 @@ static void sci_start_rx(struct uart_por
14133  static void sci_stop_rx(struct uart_port *port);
14134  static int sci_request_irq(struct sci_port *port);
14135  static void sci_free_irq(struct sci_port *port);
14136 +static void sci_set_termios(struct uart_port *port, struct termios *termios,
14137 +                       struct termios *old);
14138 +static int kgdbsci_init(void);
14139  
14140  static struct sci_port sci_ports[];
14141  static struct uart_driver sci_uart_driver;
14142  
14143  #define SCI_NPORTS sci_uart_driver.nr
14144  
14145 -#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
14146 -
14147 -static void handle_error(struct uart_port *port)
14148 -{                              /* Clear error flags */
14149 -       sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
14150 -}
14151 -
14152 -static int get_char(struct uart_port *port)
14153 +#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_KGDB_SH_SCI)
14154 +static int get_char_for_gdb(struct uart_port *port)
14155  {
14156         unsigned long flags;
14157         unsigned short status;
14158 @@ -110,7 +110,8 @@ static int get_char(struct uart_port *po
14159          do {
14160                 status = sci_in(port, SCxSR);
14161                 if (status & SCxSR_ERRORS(port)) {
14162 -                       handle_error(port);
14163 +                       /* Clear error flags. */
14164 +                       sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
14165                         continue;
14166                 }
14167         } while (!(status & SCxSR_RDxF(port)));
14168 @@ -121,21 +122,7 @@ static int get_char(struct uart_port *po
14169  
14170         return c;
14171  }
14172 -
14173 -/* Taken from sh-stub.c of GDB 4.18 */
14174 -static const char hexchars[] = "0123456789abcdef";
14175 -
14176 -static __inline__ char highhex(int  x)
14177 -{
14178 -       return hexchars[(x >> 4) & 0xf];
14179 -}
14180 -
14181 -static __inline__ char lowhex(int  x)
14182 -{
14183 -       return hexchars[x & 0xf];
14184 -}
14185 -
14186 -#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
14187 +#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_KGDB_SH_SCI */
14188  
14189  /*
14190   * Send the packet in buffer.  The host gets one chance to read it.
14191 @@ -167,21 +154,14 @@ static void put_string(struct sci_port *
14192         const unsigned char *p = buffer;
14193         int i;
14194  
14195 -#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
14196 +#ifdef CONFIG_SH_STANDARD_BIOS
14197         int checksum;
14198 -       int usegdb=0;
14199 +        const char hexchars[] = "0123456789abcdef";
14200  
14201 -#ifdef CONFIG_SH_STANDARD_BIOS
14202         /* This call only does a trap the first time it is
14203          * called, and so is safe to do here unconditionally
14204          */
14205 -       usegdb |= sh_bios_in_gdb_mode();
14206 -#endif
14207 -#ifdef CONFIG_SH_KGDB
14208 -       usegdb |= (kgdb_in_gdb_mode && (port == kgdb_sci_port));
14209 -#endif
14210 -
14211 -       if (usegdb) {
14212 +       if (sh_bios_in_gdb_mode()) {
14213             /*  $<packet info>#<checksum>. */
14214             do {
14215                 unsigned char c;
14216 @@ -193,18 +173,18 @@ static void put_string(struct sci_port *
14217                         int h, l;
14218  
14219                         c = *p++;
14220 -                       h = highhex(c);
14221 -                       l = lowhex(c);
14222 +                       h = hexchars[c >> 4];
14223 +                       l = hexchars[c % 16];
14224                         put_char(port, h);
14225                         put_char(port, l);
14226                         checksum += h + l;
14227                 }
14228                 put_char(port, '#');
14229 -               put_char(port, highhex(checksum));
14230 -               put_char(port, lowhex(checksum));
14231 +               put_char(port, hexchars[checksum >> 4]);
14232 +               put_char(port, hexchars[checksum % 16]);
14233             } while  (get_char(port) != '+');
14234         } else
14235 -#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
14236 +#endif /* CONFIG_SH_STANDARD_BIOS */
14237         for (i=0; i<count; i++) {
14238                 if (*p == 10)
14239                         put_char(port, '\r');
14240 @@ -214,90 +194,163 @@ static void put_string(struct sci_port *
14241  #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
14242  
14243  
14244 -#ifdef CONFIG_SH_KGDB
14245 -
14246 -/* Is the SCI ready, ie is there a char waiting? */
14247 -static int kgdb_is_char_ready(struct sci_port *port)
14248 +#ifdef CONFIG_KGDB_SH_SCI
14249 +static int kgdbsci_read_char(void)
14250  {
14251 -        unsigned short status = sci_in(port, SCxSR);
14252 -
14253 -        if (status & (SCxSR_ERRORS(port) | SCxSR_BRK(port)))
14254 -                kgdb_handle_error(port);
14255 -
14256 -        return (status & SCxSR_RDxF(port));
14257 +       return get_char_for_gdb(&KGDBPORT.port);
14258  }
14259  
14260 -/* Write a char */
14261 -static void kgdb_put_char(struct sci_port *port, char c)
14262 +/* Called from kgdbstub.c to put a character, just a wrapper */
14263 +static void kgdbsci_write_char(int c)
14264  {
14265          unsigned short status;
14266  
14267          do
14268 -                status = sci_in(port, SCxSR);
14269 -        while (!(status & SCxSR_TDxE(port)));
14270 +               status = sci_in(&KGDBPORT.port, SCxSR);
14271 +       while (!(status & SCxSR_TDxE(&KGDBPORT.port)));
14272  
14273 -        sci_out(port, SCxTDR, c);
14274 -        sci_in(port, SCxSR);    /* Dummy read */
14275 -        sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
14276 +       sci_out(&KGDBPORT.port, SCxTDR, c);
14277 +       sci_in(&KGDBPORT.port, SCxSR);  /* Dummy read */
14278 +       sci_out(&KGDBPORT.port, SCxSR, SCxSR_TDxE_CLEAR(&KGDBPORT.port));
14279  }
14280  
14281 -/* Get a char if there is one, else ret -1 */
14282 -static int kgdb_get_char(struct sci_port *port)
14283 +#ifndef CONFIG_SERIAL_SH_SCI_CONSOLE
14284 +/* If we don't have console, we never hookup IRQs.  But we need to
14285 + * hookup one so that we can interrupt the system.
14286 + */
14287 +static irqreturn_t kgdbsci_rx_interrupt(int irq, void *ptr,
14288 +               struct pt_regs *regs)
14289  {
14290 -        int c;
14291 +       struct uart_port *port = ptr;
14292  
14293 -        if (kgdb_is_char_ready(port) == 0)
14294 -                c = -1;
14295 -        else {
14296 -                c = sci_in(port, SCxRDR);
14297 -                sci_in(port, SCxSR);    /* Dummy read */
14298 +       if (!(sci_in(port, SCxSR) & SCxSR_RDxF(port)))
14299 +               return IRQ_NONE;
14300 +
14301 +       if (kgdb_io_ops.init != kgdbsci_init) {
14302 +               /* Throw away the data if another I/O routine is active */
14303 +               get_char_for_gdb(&KGDBPORT.port);
14304 +       } else
14305 +               /* We've got an interrupt, so go ahead and call breakpoint() */
14306 +               breakpoint();
14307 +
14308 +       sci_in(port, SCxSR); /* dummy read */
14309                  sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
14310 -        }
14311  
14312 -        return c;
14313 +       return IRQ_HANDLED;
14314  }
14315  
14316 -/* Called from kgdbstub.c to get a character, i.e. is blocking */
14317 -static int kgdb_sci_getchar(void)
14318 +static irqreturn_t kgdbsci_mpxed_interrupt(int irq, void *ptr,
14319 +               struct pt_regs *regs)
14320  {
14321 -        volatile int c;
14322 -
14323 -        /* Keep trying to read a character, this could be neater */
14324 -        while ((c = kgdb_get_char(kgdb_sci_port)) < 0);
14325 +        unsigned short ssr_status, scr_status;
14326 +        struct uart_port *port = ptr;
14327  
14328 -        return c;
14329 -}
14330 +        ssr_status = sci_in(port,SCxSR);
14331 +        scr_status = sci_in(port,SCSCR);
14332  
14333 -/* Called from kgdbstub.c to put a character, just a wrapper */
14334 -static void kgdb_sci_putchar(int c)
14335 -{
14336 +       /* Rx Interrupt */
14337 +        if ((ssr_status&0x0002) && (scr_status&0x0040))
14338 +               kgdbsci_rx_interrupt(irq, ptr, regs);
14339  
14340 -        kgdb_put_char(kgdb_sci_port, c);
14341 +       return IRQ_HANDLED;
14342  }
14343  
14344 -/* Clear any errors on the SCI */
14345 -static void kgdb_handle_error(struct sci_port *port)
14346 +static void __init kgdbsci_lateinit(void)
14347  {
14348 -        sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));  /* Clear error flags */
14349 +       if (KGDBPORT.irqs[0] == KGDBPORT.irqs[1]) {
14350 +               if (!KGDBPORT.irqs[0]) {
14351 +                       printk(KERN_ERR "kgdbsci: Cannot allocate irq.\n");
14352 +                       return;
14353 +               }
14354 +               if (request_irq(KGDBPORT.irqs[0], kgdbsci_mpxed_interrupt,
14355 +                                       SA_INTERRUPT, "kgdbsci",
14356 +                                       &KGDBPORT.port)) {
14357 +                       printk(KERN_ERR "kgdbsci: Cannot allocate irq.\n");
14358 +                       return;
14359 +               }
14360 +       } else {
14361 +               if (KGDBPORT.irqs[1])
14362 +                       request_irq(KGDBPORT.irqs[1],
14363 +                                       kgdbsci_rx_interrupt, SA_INTERRUPT,
14364 +                                       "kgdbsci", &KGDBPORT.port);
14365 +       }
14366  }
14367 +#endif
14368  
14369 -/* Breakpoint if there's a break sent on the serial port */
14370 -static void kgdb_break_interrupt(int irq, void *ptr, struct pt_regs *regs)
14371 +/*
14372 + * We use the normal init routine to setup the port, so we can't be
14373 + * in here too early.
14374 + */
14375 +static int kgdbsci_init(void)
14376  {
14377 -        struct sci_port *port = ptr;
14378 -        unsigned short status = sci_in(port, SCxSR);
14379 -
14380 -        if (status & SCxSR_BRK(port)) {
14381 +       struct termios termios;
14382  
14383 -                /* Break into the debugger if a break is detected */
14384 -                BREAKPOINT();
14385 +       memset(&termios, 0, sizeof(struct termios));
14386  
14387 -                /* Clear */
14388 -                sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port));
14389 +       termios.c_cflag = CREAD | HUPCL | CLOCAL | CS8;
14390 +       switch (kgdbsci_baud) {
14391 +       case 9600:
14392 +               termios.c_cflag |= B9600;
14393 +               break;
14394 +       case 19200:
14395 +               termios.c_cflag |= B19200;
14396 +               break;
14397 +       case 38400:
14398 +               termios.c_cflag |= B38400;
14399 +               break;
14400 +       case 57600:
14401 +               termios.c_cflag |= B57600;
14402 +               break;
14403 +       case 115200:
14404 +               termios.c_cflag |= B115200;
14405 +               break;
14406          }
14407 +       sci_set_termios(&KGDBPORT.port, &termios, NULL);
14408 +
14409 +       return 0;
14410  }
14411  
14412 -#endif /* CONFIG_SH_KGDB */
14413 +struct kgdb_io kgdb_io_ops = {
14414 +       .read_char = kgdbsci_read_char,
14415 +       .write_char = kgdbsci_write_char,
14416 +       .init = kgdbsci_init,
14417 +#ifndef CONFIG_SERIAL_SH_SCI_CONSOLE
14418 +       .late_init = kgdbsci_lateinit,
14419 +#else /* ! CONFIG_SERIAL_SH_SCI_CONSOLE */
14420 +       .late_init = NULL,
14421 +#endif /* ! CONFIG_SERIAL_SH_SCI_CONSOLE */
14422 +       .pre_exception = NULL,
14423 +       .post_exception = NULL
14424 +};
14425 +
14426 +/*
14427 + * Syntax for this cmdline option is "kgdbsci=ttyno,baudrate".
14428 + */
14429 +static int __init
14430 +kgdbsci_opt(char *str)
14431 +{
14432 +       /* We might have anywhere from 1 to 3 ports. */
14433 +       if (*str < '0' || *str > SCI_NPORTS + '0')
14434 +                goto errout;
14435 +       kgdbsci_ttySC = *str - '0';
14436 +       str++;
14437 +       if (*str != ',')
14438 +                goto errout;
14439 +       str++;
14440 +       kgdbsci_baud = simple_strtoul(str, &str, 10);
14441 +       if (kgdbsci_baud != 9600 && kgdbsci_baud != 19200 &&
14442 +           kgdbsci_baud != 38400 && kgdbsci_baud != 57600 &&
14443 +           kgdbsci_baud != 115200)
14444 +                goto errout;
14445 +
14446 +       return 0;
14447 +
14448 +errout:
14449 +       printk(KERN_ERR "Invalid syntax for option kgdbsci=\n");
14450 +       return 1;
14451 +}
14452 +__setup("kgdbsci", kgdbsci_opt);
14453 +#endif /* CONFIG_KGDB_SH_SCI */
14454  
14455  #if defined(__H8300S__)
14456  enum { sci_disable, sci_enable };
14457 @@ -555,6 +608,16 @@ static inline void sci_receive_chars(str
14458                                         continue;
14459                                 }
14460  
14461 +#ifdef CONFIG_KGDB_SH_SCI
14462 +                               /* We assume that a ^C on the port KGDB
14463 +                                * is using means that KGDB wants to
14464 +                                * interrupt the running system.
14465 +                                */
14466 +                               if (port->line == KGDBPORT.port.line &&
14467 +                                               c == 3)
14468 +                                       breakpoint();
14469 +#endif
14470 +
14471                                 /* Store data and status */
14472                                 if (status&SCxSR_FER(port)) {
14473                                         flag = TTY_FRAME;
14474 @@ -1618,6 +1681,7 @@ static int __init sci_console_init(void)
14475  console_initcall(sci_console_init);
14476  #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
14477  
14478 +#if 0
14479  #ifdef CONFIG_SH_KGDB
14480  /*
14481   * FIXME: Most of this can go away.. at the moment, we rely on
14482 @@ -1663,30 +1727,9 @@ int __init kgdb_console_setup(struct con
14483         return uart_set_options(port, co, baud, parity, bits, flow);
14484  }
14485  #endif /* CONFIG_SH_KGDB */
14486 +#endif /* 0 */
14487  
14488 -#ifdef CONFIG_SH_KGDB_CONSOLE
14489 -static struct console kgdb_console = {
14490 -        .name          = "ttySC",
14491 -        .write         = kgdb_console_write,
14492 -        .setup         = kgdb_console_setup,
14493 -        .flags         = CON_PRINTBUFFER | CON_ENABLED,
14494 -        .index         = -1,
14495 -       .data           = &sci_uart_driver,
14496 -};
14497 -
14498 -/* Register the KGDB console so we get messages (d'oh!) */
14499 -static int __init kgdb_console_init(void)
14500 -{
14501 -       register_console(&kgdb_console);
14502 -       return 0;
14503 -}
14504 -
14505 -console_initcall(kgdb_console_init);
14506 -#endif /* CONFIG_SH_KGDB_CONSOLE */
14507 -
14508 -#if defined(CONFIG_SH_KGDB_CONSOLE)
14509 -#define SCI_CONSOLE    &kgdb_console
14510 -#elif defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
14511 +#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
14512  #define SCI_CONSOLE    &serial_console
14513  #else
14514  #define SCI_CONSOLE    0
14515 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-arm/kgdb.h linux-2.6.18-53.1.14.kgdb/include/asm-arm/kgdb.h
14516 --- linux-2.6.18-53.1.14/include/asm-arm/kgdb.h 1970-01-01 03:00:00.000000000 +0300
14517 +++ linux-2.6.18-53.1.14.kgdb/include/asm-arm/kgdb.h    2008-06-10 15:39:01.000000000 +0400
14518 @@ -0,0 +1,92 @@
14519 +/*
14520 + * include/asm-arm/kgdb.h
14521 + *
14522 + * ARM KGDB support
14523 + *
14524 + * Author: Deepak Saxena <dsaxena@mvista.com>
14525 + *
14526 + * Copyright (C) 2002 MontaVista Software Inc.
14527 + *
14528 + */
14529 +
14530 +#ifndef __ASM_KGDB_H__
14531 +#define __ASM_KGDB_H__
14532 +
14533 +#include <linux/config.h>
14534 +#include <asm/ptrace.h>
14535 +#include <asm-generic/kgdb.h>
14536 +
14537 +
14538 +/*
14539 + * GDB assumes that we're a user process being debugged, so
14540 + * it will send us an SWI command to write into memory as the
14541 + * debug trap. When an SWI occurs, the next instruction addr is
14542 + * placed into R14_svc before jumping to the vector trap.
14543 + * This doesn't work for kernel debugging as we are already in SVC
14544 + * we would loose the kernel's LR, which is a bad thing. This
14545 + * is  bad thing.
14546 + *
14547 + * By doing this as an undefined instruction trap, we force a mode
14548 + * switch from SVC to UND mode, allowing us to save full kernel state.
14549 + *
14550 + * We also define a KGDB_COMPILED_BREAK which can be used to compile
14551 + * in breakpoints. This is important for things like sysrq-G and for
14552 + * the initial breakpoint from trap_init().
14553 + *
14554 + * Note to ARM HW designers: Add real trap support like SH && PPC to
14555 + * make our lives much much simpler. :)
14556 + */
14557 +#define        BREAK_INSTR_SIZE                4
14558 +#define GDB_BREAKINST                   0xef9f0001
14559 +#define KGDB_BREAKINST                  0xe7ffdefe
14560 +#define KGDB_COMPILED_BREAK             0xe7ffdeff
14561 +#define CACHE_FLUSH_IS_SAFE            1
14562 +
14563 +#ifndef        __ASSEMBLY__
14564 +
14565 +#define        BREAKPOINT()                    asm(".word      0xe7ffdeff")
14566 +
14567 +
14568 +extern void kgdb_handle_bus_error(void);
14569 +extern int kgdb_fault_expected;
14570 +#endif /* !__ASSEMBLY__ */
14571 +
14572 +/*
14573 + * From Amit S. Kale:
14574 + *
14575 + * In the register packet, words 0-15 are R0 to R10, FP, IP, SP, LR, PC. But
14576 + * Register 16 isn't cpsr. GDB passes CPSR in word 25. There are 9 words in
14577 + * between which are unused. Passing only 26 words to gdb is sufficient.
14578 + * GDB can figure out that floating point registers are not passed.
14579 + * GDB_MAX_REGS should be 26.
14580 + */
14581 +#define        GDB_MAX_REGS            (26)
14582 +
14583 +#define        KGDB_MAX_NO_CPUS        1
14584 +#define        BUFMAX                  400
14585 +#define        NUMREGBYTES             (GDB_MAX_REGS << 2)
14586 +#define        NUMCRITREGBYTES         (32 << 2)
14587 +
14588 +#define        _R0             0
14589 +#define        _R1             1
14590 +#define        _R2             2
14591 +#define        _R3             3
14592 +#define        _R4             4
14593 +#define        _R5             5
14594 +#define        _R6             6
14595 +#define        _R7             7
14596 +#define        _R8             8
14597 +#define        _R9             9
14598 +#define        _R10            10
14599 +#define        _FP             11
14600 +#define        _IP             12
14601 +#define        _SP             13
14602 +#define        _LR             14
14603 +#define        _PC             15
14604 +#define        _CPSR           (GDB_MAX_REGS - 1)
14605 +
14606 +/* So that we can denote the end of a frame for tracing, in the simple
14607 + * case. */
14608 +#define CFI_END_FRAME(func)    __CFI_END_FRAME(_PC,_SP,func)
14609 +
14610 +#endif /* __ASM_KGDB_H__ */
14611 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-arm/system.h linux-2.6.18-53.1.14.kgdb/include/asm-arm/system.h
14612 --- linux-2.6.18-53.1.14/include/asm-arm/system.h       2006-09-20 07:42:06.000000000 +0400
14613 +++ linux-2.6.18-53.1.14.kgdb/include/asm-arm/system.h  2008-06-10 15:38:56.000000000 +0400
14614 @@ -444,6 +444,47 @@ static inline unsigned long __xchg(unsig
14615  extern void disable_hlt(void);
14616  extern void enable_hlt(void);
14617  
14618 +#define        __HAVE_ARCH_CMPXCHG     1
14619 +
14620 +#include <asm/types.h>
14621 +
14622 +static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
14623 +                                       unsigned long new)
14624 +{
14625 +       u32 retval;
14626 +       unsigned long flags;
14627 +
14628 +       local_irq_save(flags);
14629 +       retval = *m;
14630 +       if (retval == old)
14631 +               *m = new;
14632 +       local_irq_restore(flags);       /* implies memory barrier  */
14633 +
14634 +       return retval;
14635 +}
14636 +
14637 +/* This function doesn't exist, so you'll get a linker error
14638 +   if something tries to do an invalid cmpxchg().  */
14639 +extern void __cmpxchg_called_with_bad_pointer(void);
14640 +
14641 +static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
14642 +       unsigned long new, int size)
14643 +{
14644 +       switch (size) {
14645 +       case 4:
14646 +               return __cmpxchg_u32(ptr, old, new);
14647 +       }
14648 +       __cmpxchg_called_with_bad_pointer();
14649 +       return old;
14650 +}
14651 +
14652 +#define cmpxchg(ptr,o,n)                                                \
14653 +  ({                                                                    \
14654 +     __typeof__(*(ptr)) _o_ = (o);                                      \
14655 +     __typeof__(*(ptr)) _n_ = (n);                                      \
14656 +     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,          \
14657 +                                   (unsigned long)_n_, sizeof(*(ptr))); \
14658 +  })
14659  #endif /* __ASSEMBLY__ */
14660  
14661  #define arch_align_stack(x) (x)
14662 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-generic/kgdb.h linux-2.6.18-53.1.14.kgdb/include/asm-generic/kgdb.h
14663 --- linux-2.6.18-53.1.14/include/asm-generic/kgdb.h     1970-01-01 03:00:00.000000000 +0300
14664 +++ linux-2.6.18-53.1.14.kgdb/include/asm-generic/kgdb.h        2008-06-10 15:39:01.000000000 +0400
14665 @@ -0,0 +1,34 @@
14666 +/*
14667 + * include/asm-generic/kgdb.h
14668 + *
14669 + * This provides the assembly level information so that KGDB can provide
14670 + * a GDB that has been patched with enough information to know to stop
14671 + * trying to unwind the function.
14672 + *
14673 + * Author: Tom Rini <trini@kernel.crashing.org>
14674 + *
14675 + * 2005 (c) MontaVista Software, Inc. This file is licensed under the terms
14676 + * of the GNU General Public License version 2. This program is licensed
14677 + * "as is" without any warranty of any kind, whether express or implied.
14678 + */
14679 +
14680 +#ifndef __ASM_GENERIC_KGDB_H__
14681 +#define __ASM_GENERIC_KGDB_H__
14682 +
14683 +#include <linux/dwarf2-lang.h>
14684 +#ifdef __ASSEMBLY__
14685 +#ifdef CONFIG_KGDB
14686 +/* This MUST be put at the end of a given assembly function */
14687 +#define __CFI_END_FRAME(pc,sp,func)                    \
14688 +CAT3(.Lend_,func,:)                                    \
14689 +       CFI_preamble(func,pc,0x1,-DATA_ALIGN_FACTOR)    \
14690 +       CFA_define_reference(sp, 0)                     \
14691 +       CFA_undefine_reg(pc)                            \
14692 +       CFI_postamble()                                 \
14693 +       FDE_preamble(func,func,CAT3(.Lend,_,func))      \
14694 +       FDE_postamble()
14695 +#else
14696 +#define __CFI_END_FRAME(pc,sp,fn)
14697 +#endif                         /* CONFIG_KGDB */
14698 +#endif                         /* __ASSEMBLY__ */
14699 +#endif                         /* __ASM_GENERIC_KGDB_H__ */
14700 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-i386/kdebug.h linux-2.6.18-53.1.14.kgdb/include/asm-i386/kdebug.h
14701 --- linux-2.6.18-53.1.14/include/asm-i386/kdebug.h      2006-09-20 07:42:06.000000000 +0400
14702 +++ linux-2.6.18-53.1.14.kgdb/include/asm-i386/kdebug.h 2008-06-10 15:38:03.000000000 +0400
14703 @@ -39,6 +39,7 @@ enum die_val {
14704         DIE_CALL,
14705         DIE_NMI_IPI,
14706         DIE_PAGE_FAULT,
14707 +       DIE_PAGE_FAULT_NO_CONTEXT,
14708  };
14709  
14710  static inline int notify_die(enum die_val val, const char *str,
14711 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-i386/kgdb.h linux-2.6.18-53.1.14.kgdb/include/asm-i386/kgdb.h
14712 --- linux-2.6.18-53.1.14/include/asm-i386/kgdb.h        1970-01-01 03:00:00.000000000 +0300
14713 +++ linux-2.6.18-53.1.14.kgdb/include/asm-i386/kgdb.h   2008-06-10 15:39:01.000000000 +0400
14714 @@ -0,0 +1,58 @@
14715 +#ifdef __KERNEL__
14716 +#ifndef _ASM_KGDB_H_
14717 +#define _ASM_KGDB_H_
14718 +
14719 +/*
14720 + * Copyright (C) 2001-2004 Amit S. Kale
14721 + */
14722 +
14723 +#include <asm-generic/kgdb.h>
14724 +
14725 +/*
14726 + *  Note that this register image is in a different order than
14727 + *  the register image that Linux produces at interrupt time.
14728 + *
14729 + *  Linux's register image is defined by struct pt_regs in ptrace.h.
14730 + *  Just why GDB uses a different order is a historical mystery.
14731 + */
14732 +#define _EAX   0
14733 +#define _ECX   1
14734 +#define _EDX   2
14735 +#define _EBX   3
14736 +#define _ESP   4
14737 +#define _EBP   5
14738 +#define _ESI   6
14739 +#define _EDI   7
14740 +#define _PC    8
14741 +#define _EIP   8
14742 +#define _PS    9
14743 +#define _EFLAGS        9
14744 +#define _CS    10
14745 +#define _SS    11
14746 +#define _DS    12
14747 +#define _ES    13
14748 +#define _FS    14
14749 +#define _GS    15
14750 +
14751 +/* So that we can denote the end of a frame for tracing, in the simple
14752 + * case. */
14753 +#define CFI_END_FRAME(func)    __CFI_END_FRAME(_EIP,_ESP,func)
14754 +
14755 +#ifndef __ASSEMBLY__
14756 +/************************************************************************/
14757 +/* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/
14758 +/* at least NUMREGBYTES*2 are needed for register packets */
14759 +/* Longer buffer is needed to list all threads */
14760 +#define BUFMAX                 1024
14761 +
14762 +/* Number of bytes of registers.  */
14763 +#define NUMREGBYTES            64
14764 +/* Number of bytes of registers we need to save for a setjmp/longjmp. */
14765 +#define NUMCRITREGBYTES                24
14766 +
14767 +#define BREAKPOINT()           asm("   int $3");
14768 +#define BREAK_INSTR_SIZE       1
14769 +#define CACHE_FLUSH_IS_SAFE    1
14770 +#endif                         /* !__ASSEMBLY__ */
14771 +#endif                         /* _ASM_KGDB_H_ */
14772 +#endif                         /* __KERNEL__ */
14773 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-ia64/kdebug.h linux-2.6.18-53.1.14.kgdb/include/asm-ia64/kdebug.h
14774 --- linux-2.6.18-53.1.14/include/asm-ia64/kdebug.h      2006-09-20 07:42:06.000000000 +0400
14775 +++ linux-2.6.18-53.1.14.kgdb/include/asm-ia64/kdebug.h 2008-06-10 15:38:32.000000000 +0400
14776 @@ -72,6 +72,7 @@ enum die_val {
14777         DIE_KDEBUG_LEAVE,
14778         DIE_KDUMP_ENTER,
14779         DIE_KDUMP_LEAVE,
14780 +       DIE_PAGE_FAULT_NO_CONTEXT,
14781  };
14782  
14783  static inline int notify_die(enum die_val val, char *str, struct pt_regs *regs,
14784 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-ia64/kgdb.h linux-2.6.18-53.1.14.kgdb/include/asm-ia64/kgdb.h
14785 --- linux-2.6.18-53.1.14/include/asm-ia64/kgdb.h        1970-01-01 03:00:00.000000000 +0300
14786 +++ linux-2.6.18-53.1.14.kgdb/include/asm-ia64/kgdb.h   2008-06-10 15:38:32.000000000 +0400
14787 @@ -0,0 +1,36 @@
14788 +#ifdef __KERNEL__
14789 +#ifndef _ASM_KGDB_H_
14790 +#define _ASM_KGDB_H_
14791 +
14792 +/*
14793 + * Copyright (C) 2001-2004 Amit S. Kale
14794 + */
14795 +
14796 +#include <linux/threads.h>
14797 +
14798 +/************************************************************************/
14799 +/* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/
14800 +/* at least NUMREGBYTES*2 are needed for register packets */
14801 +/* Longer buffer is needed to list all threads */
14802 +#define BUFMAX                 1024
14803 +
14804 +/* Number of bytes of registers.  We set this to 0 so that certain GDB
14805 + * packets will fail, forcing the use of others, which are more friendly
14806 + * on ia64. */
14807 +#define NUMREGBYTES            0
14808 +
14809 +#define NUMCRITREGBYTES                (70*8)
14810 +#define JMP_REGS_ALIGNMENT     __attribute__ ((aligned (16)))
14811 +
14812 +#define BREAKNUM               0x00003333300LL
14813 +#define KGDBBREAKNUM           0x6665UL
14814 +#define BREAKPOINT()           asm volatile ("break.m 0x6665")
14815 +#define BREAK_INSTR_SIZE       16
14816 +#define CACHE_FLUSH_IS_SAFE    1
14817 +
14818 +struct pt_regs;
14819 +extern volatile int kgdb_hwbreak_sstep[NR_CPUS];
14820 +extern void smp_send_nmi_allbutself(void);
14821 +extern void kgdb_wait_ipi(struct pt_regs *);
14822 +#endif                         /* _ASM_KGDB_H_ */
14823 +#endif                         /* __KERNEL__ */
14824 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-mips/kdebug.h linux-2.6.18-53.1.14.kgdb/include/asm-mips/kdebug.h
14825 --- linux-2.6.18-53.1.14/include/asm-mips/kdebug.h      1970-01-01 03:00:00.000000000 +0300
14826 +++ linux-2.6.18-53.1.14.kgdb/include/asm-mips/kdebug.h 2008-06-10 15:38:24.000000000 +0400
14827 @@ -0,0 +1,47 @@
14828 +/*
14829 + *
14830 + * Copyright (C) 2004  MontaVista Software Inc.
14831 + * Author: Manish Lachwani, mlachwani@mvista.com or manish@koffee-break.com
14832 + *
14833 + * This program is free software; you can redistribute  it and/or modify it
14834 + * under  the terms of  the GNU General  Public License as published by the
14835 + * Free Software Foundation;  either version 2 of the  License, or (at your
14836 + * option) any later version.
14837 + *
14838 + */
14839 +#ifndef _MIPS_KDEBUG_H
14840 +#define _MIPS_KDEBUG_H
14841 +
14842 +#include <linux/notifier.h>
14843 +
14844 +struct pt_regs;
14845 +
14846 +struct die_args {
14847 +       struct pt_regs *regs;
14848 +       const char *str;
14849 +       long err;
14850 +};
14851 +
14852 +int register_die_notifier(struct notifier_block *nb);
14853 +extern struct notifier_block *mips_die_chain;
14854 +
14855 +enum die_val {
14856 +       DIE_OOPS = 1,
14857 +       DIE_PANIC,
14858 +       DIE_DIE,
14859 +       DIE_KERNELDEBUG,
14860 +       DIE_TRAP,
14861 +       DIE_PAGE_FAULT,
14862 +};
14863 +
14864 +/*
14865 + * trap number can be computed from regs and signr can be computed using
14866 + * compute_signal()
14867 + */
14868 +static inline int notify_die(enum die_val val,char *str,struct pt_regs *regs,long err)
14869 +{
14870 +       struct die_args args = { .regs=regs, .str=str, .err=err };
14871 +       return notifier_call_chain(&mips_die_chain, val, &args);
14872 +}
14873 +
14874 +#endif /* _MIPS_KDEBUG_H */
14875 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-mips/kgdb.h linux-2.6.18-53.1.14.kgdb/include/asm-mips/kgdb.h
14876 --- linux-2.6.18-53.1.14/include/asm-mips/kgdb.h        1970-01-01 03:00:00.000000000 +0300
14877 +++ linux-2.6.18-53.1.14.kgdb/include/asm-mips/kgdb.h   2008-06-10 15:39:01.000000000 +0400
14878 @@ -0,0 +1,34 @@
14879 +#ifdef __KERNEL__
14880 +#ifndef _ASM_KGDB_H_
14881 +#define _ASM_KGDB_H_
14882 +
14883 +#ifndef __ASSEMBLY__
14884 +#if (_MIPS_ISA == _MIPS_ISA_MIPS1) || (_MIPS_ISA == _MIPS_ISA_MIPS2)
14885 +typedef u32 gdb_reg_t;
14886 +#elif (_MIPS_ISA == _MIPS_ISA_MIPS3) || (_MIPS_ISA == _MIPS_ISA_MIPS4)
14887 +typedef u64 gdb_reg_t;
14888 +#else
14889 +#error need to do
14890 +#endif /* _MIPS_ISA */
14891 +
14892 +#include <asm-generic/kgdb.h>
14893 +
14894 +#ifndef __ASSEMBLY__
14895 +#define BUFMAX                 2048
14896 +#define NUMREGBYTES            (90*sizeof(gdb_reg_t))
14897 +#define NUMCRITREGBYTES                (12*sizeof(gdb_reg_t))
14898 +#define BREAK_INSTR_SIZE       4
14899 +#define BREAKPOINT()           __asm__ __volatile__(           \
14900 +                                       ".globl breakinst\n\t"  \
14901 +                                       ".set\tnoreorder\n\t"   \
14902 +                                       "nop\n"                 \
14903 +                                       "breakinst:\tbreak\n\t" \
14904 +                                       "nop\n\t"               \
14905 +                                       ".set\treorder")
14906 +#define CACHE_FLUSH_IS_SAFE    0
14907 +
14908 +extern int kgdb_early_setup;
14909 +
14910 +#endif                         /* !__ASSEMBLY__ */
14911 +#endif                         /* _ASM_KGDB_H_ */
14912 +#endif                         /* __KERNEL__ */
14913 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-powerpc/kgdb.h linux-2.6.18-53.1.14.kgdb/include/asm-powerpc/kgdb.h
14914 --- linux-2.6.18-53.1.14/include/asm-powerpc/kgdb.h     1970-01-01 03:00:00.000000000 +0300
14915 +++ linux-2.6.18-53.1.14.kgdb/include/asm-powerpc/kgdb.h        2008-06-10 15:39:01.000000000 +0400
14916 @@ -0,0 +1,74 @@
14917 +/*
14918 + * include/asm-powerpc/kgdb.h
14919 + *
14920 + * The PowerPC (32/64) specific defines / externs for KGDB.  Based on
14921 + * the previous 32bit and 64bit specific files, which had the following
14922 + * copyrights:
14923 + *
14924 + * PPC64 Mods (C) 2005 Frank Rowand (frowand@mvista.com)
14925 + * PPC Mods (C) 2004 Tom Rini (trini@mvista.com)
14926 + * PPC Mods (C) 2003 John Whitney (john.whitney@timesys.com)
14927 + * PPC Mods (C) 1998 Michael Tesch (tesch@cs.wisc.edu)
14928 + *
14929 + *
14930 + * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
14931 + * Author: Tom Rini <trini@kernel.crashing.org>
14932 + *
14933 + * 2006 (c) MontaVista Software, Inc. This file is licensed under
14934 + * the terms of the GNU General Public License version 2. This program
14935 + * is licensed "as is" without any warranty of any kind, whether express
14936 + * or implied.
14937 + */
14938 +#ifdef __KERNEL__
14939 +#ifndef __POWERPC_KGDB_H__
14940 +#define __POWERPC_KGDB_H__
14941 +
14942 +#include <asm-generic/kgdb.h>
14943 +#ifndef __ASSEMBLY__
14944 +
14945 +#define BREAK_INSTR_SIZE       4
14946 +#define BUFMAX                 ((NUMREGBYTES * 2) + 512)
14947 +#define OUTBUFMAX              ((NUMREGBYTES * 2) + 512)
14948 +#define BREAKPOINT()           asm(".long 0x7d821008"); /* twge r2, r2 */
14949 +#define CACHE_FLUSH_IS_SAFE    1
14950 +
14951 +/* The number bytes of registers we have to save depends on a few
14952 + * things.  For 64bit we default to not including vector registers and
14953 + * vector state registers. */
14954 +#ifdef CONFIG_PPC64
14955 +/*
14956 + * 64 bit (8 byte) registers:
14957 + *   32 gpr, 32 fpr, nip, msr, link, ctr
14958 + * 32 bit (4 byte) registers:
14959 + *   ccr, xer, fpscr
14960 + */
14961 +#define NUMREGBYTES            ((68 * 8) + (3 * 4))
14962 +#if 0
14963 +/* The following adds in vector registers and vector state registers. */
14964 +/* 128 bit (16 byte) registers:
14965 + *   32 vr
14966 + * 64 bit (8 byte) registers:
14967 + *   32 gpr, 32 fpr, nip, msr, link, ctr
14968 + * 32 bit (4 byte) registers:
14969 + *   ccr, xer, fpscr, vscr, vrsave
14970 + */
14971 +#define NUMREGBYTES            ((128 * 16) + (68 * 8) + (5 * 4))
14972 +#endif
14973 +#define NUMCRITREGBYTES                184
14974 +#else /* CONFIG_PPC32 */
14975 +/* On non-E500 family PPC32 we determine the size by picking the last
14976 + * register we need, but on E500 we skip sections so we list what we
14977 + * need to store, and add it up. */
14978 +#ifndef CONFIG_E500
14979 +#define MAXREG                 (PT_FPSCR+1)
14980 +#else
14981 +/* 32 GPRs (8 bytes), nip, msr, ccr, link, ctr, xer, acc (8 bytes), spefscr*/
14982 +#define MAXREG                 ((32*2)+6+2+1)
14983 +#endif
14984 +#define NUMREGBYTES            (MAXREG * sizeof(int))
14985 +/* CR/LR, R1, R2, R13-R31 inclusive. */
14986 +#define NUMCRITREGBYTES                (23 * sizeof(int))
14987 +#endif /* 32/64 */
14988 +#endif /* !(__ASSEMBLY__) */
14989 +#endif /* !__POWERPC_KGDB_H__ */
14990 +#endif /* __KERNEL__ */
14991 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-ppc/kgdb.h linux-2.6.18-53.1.14.kgdb/include/asm-ppc/kgdb.h
14992 --- linux-2.6.18-53.1.14/include/asm-ppc/kgdb.h 2006-09-20 07:42:06.000000000 +0400
14993 +++ linux-2.6.18-53.1.14.kgdb/include/asm-ppc/kgdb.h    2008-06-10 15:38:14.000000000 +0400
14994 @@ -1,57 +1,18 @@
14995 -/*
14996 - * kgdb.h: Defines and declarations for serial line source level
14997 - *         remote debugging of the Linux kernel using gdb.
14998 - *
14999 - * PPC Mods (C) 1998 Michael Tesch (tesch@cs.wisc.edu)
15000 - *
15001 - * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
15002 - */
15003  #ifdef __KERNEL__
15004 -#ifndef _PPC_KGDB_H
15005 -#define _PPC_KGDB_H
15006 -
15007 +#ifndef __PPC_KGDB_H__
15008 +#define __PPC_KGDB_H__
15009 +#include <asm-powerpc/kgdb.h>
15010  #ifndef __ASSEMBLY__
15011 -
15012 -/* Things specific to the gen550 backend. */
15013 -struct uart_port;
15014 -
15015 -extern void gen550_progress(char *, unsigned short);
15016 -extern void gen550_kgdb_map_scc(void);
15017 -extern void gen550_init(int, struct uart_port *);
15018 -
15019 -/* Things specific to the pmac backend. */
15020 -extern void zs_kgdb_hook(int tty_num);
15021 -
15022 -/* To init the kgdb engine. (called by serial hook)*/
15023 -extern void set_debug_traps(void);
15024 -
15025 -/* To enter the debugger explicitly. */
15026 -extern void breakpoint(void);
15027 -
15028 -/* For taking exceptions
15029 + /* For taking exceptions
15030   * these are defined in traps.c
15031   */
15032 -extern int (*debugger)(struct pt_regs *regs);
15033 +struct pt_regs;
15034 +extern void (*debugger)(struct pt_regs *regs);
15035  extern int (*debugger_bpt)(struct pt_regs *regs);
15036  extern int (*debugger_sstep)(struct pt_regs *regs);
15037  extern int (*debugger_iabr_match)(struct pt_regs *regs);
15038  extern int (*debugger_dabr_match)(struct pt_regs *regs);
15039  extern void (*debugger_fault_handler)(struct pt_regs *regs);
15040 -
15041 -/* What we bring to the party */
15042 -int kgdb_bpt(struct pt_regs *regs);
15043 -int kgdb_sstep(struct pt_regs *regs);
15044 -void kgdb(struct pt_regs *regs);
15045 -int kgdb_iabr_match(struct pt_regs *regs);
15046 -int kgdb_dabr_match(struct pt_regs *regs);
15047 -
15048 -/*
15049 - * external low-level support routines (ie macserial.c)
15050 - */
15051 -extern void kgdb_interruptible(int); /* control interrupts from serial */
15052 -extern void putDebugChar(char);   /* write a single character      */
15053 -extern char getDebugChar(void);   /* read and return a single char */
15054 -
15055 -#endif /* !(__ASSEMBLY__) */
15056 -#endif /* !(_PPC_KGDB_H) */
15057 +#endif /* !__ASSEMBLY__ */
15058 +#endif /* __PPC_KGDB_H__ */
15059  #endif /* __KERNEL__ */
15060 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-ppc/machdep.h linux-2.6.18-53.1.14.kgdb/include/asm-ppc/machdep.h
15061 --- linux-2.6.18-53.1.14/include/asm-ppc/machdep.h      2006-09-20 07:42:06.000000000 +0400
15062 +++ linux-2.6.18-53.1.14.kgdb/include/asm-ppc/machdep.h 2008-06-10 15:38:14.000000000 +0400
15063 @@ -72,9 +72,7 @@ struct machdep_calls {
15064         unsigned long   (*find_end_of_memory)(void);
15065         void            (*setup_io_mappings)(void);
15066  
15067 -       void            (*early_serial_map)(void);
15068         void            (*progress)(char *, unsigned short);
15069 -       void            (*kgdb_map_scc)(void);
15070  
15071         unsigned char   (*nvram_read_val)(int addr);
15072         void            (*nvram_write_val)(int addr, unsigned char val);
15073 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-ppc/mv64x60.h linux-2.6.18-53.1.14.kgdb/include/asm-ppc/mv64x60.h
15074 --- linux-2.6.18-53.1.14/include/asm-ppc/mv64x60.h      2006-09-20 07:42:06.000000000 +0400
15075 +++ linux-2.6.18-53.1.14.kgdb/include/asm-ppc/mv64x60.h 2008-06-10 15:38:14.000000000 +0400
15076 @@ -348,6 +348,8 @@ u32 mv64x60_calc_mem_size(struct mv64x60
15077  
15078  void mv64x60_progress_init(u32 base);
15079  void mv64x60_mpsc_progress(char *s, unsigned short hex);
15080 +struct platform_device * mv64x60_early_get_pdev_data(const char *name,
15081 +               int id, int remove);
15082  
15083  extern struct mv64x60_32bit_window
15084         gt64260_32bit_windows[MV64x60_32BIT_WIN_COUNT];
15085 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-ppc/mv64x60_defs.h linux-2.6.18-53.1.14.kgdb/include/asm-ppc/mv64x60_defs.h
15086 --- linux-2.6.18-53.1.14/include/asm-ppc/mv64x60_defs.h 2006-09-20 07:42:06.000000000 +0400
15087 +++ linux-2.6.18-53.1.14.kgdb/include/asm-ppc/mv64x60_defs.h    2008-06-10 15:38:14.000000000 +0400
15088 @@ -57,7 +57,8 @@
15089  #define        MV64x60_IRQ_I2C                         37
15090  #define        MV64x60_IRQ_BRG                         39
15091  #define        MV64x60_IRQ_MPSC_0                      40
15092 -#define        MV64x60_IRQ_MPSC_1                      42
15093 +#define        MV64360_IRQ_MPSC_1                      41
15094 +#define        GT64260_IRQ_MPSC_1                      42
15095  #define        MV64x60_IRQ_COMM                        43
15096  #define        MV64x60_IRQ_P0_GPP_0_7                  56
15097  #define        MV64x60_IRQ_P0_GPP_8_15                 57
15098 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-sh/kgdb.h linux-2.6.18-53.1.14.kgdb/include/asm-sh/kgdb.h
15099 --- linux-2.6.18-53.1.14/include/asm-sh/kgdb.h  2006-09-20 07:42:06.000000000 +0400
15100 +++ linux-2.6.18-53.1.14.kgdb/include/asm-sh/kgdb.h     2008-06-10 15:39:01.000000000 +0400
15101 @@ -2,94 +2,40 @@
15102   * May be copied or modified under the terms of the GNU General Public
15103   * License.  See linux/COPYING for more information.
15104   *
15105 - * Based on original code by Glenn Engel, Jim Kingdon,
15106 - * David Grothe <dave@gcom.com>, Tigran Aivazian, <tigran@sco.com> and
15107 - * Amit S. Kale <akale@veritas.com>
15108 + * Based on a file that was modified or based on files by: Glenn Engel,
15109 + * Jim Kingdon, David Grothe <dave@gcom.com>, Tigran Aivazian <tigran@sco.com>,
15110 + * Amit S. Kale <akale@veritas.com>, sh-stub.c from Ben Lee and
15111 + * Steve Chamberlain, Henry Bell <henry.bell@st.com>
15112   * 
15113 - * Super-H port based on sh-stub.c (Ben Lee and Steve Chamberlain) by
15114 - * Henry Bell <henry.bell@st.com>
15115 - * 
15116 - * Header file for low-level support for remote debug using GDB. 
15117 + * Maintainer: Tom Rini <trini@kernel.crashing.org>
15118   *
15119   */
15120  
15121  #ifndef __KGDB_H
15122  #define __KGDB_H
15123  
15124 -#include <asm/ptrace.h>
15125 -
15126 -struct console;
15127 +#include <asm-generic/kgdb.h>
15128 +/* Based on sh-gdb.c from gdb-6.1, Glenn
15129 +     Engel at HP  Ben Lee and Steve Chamberlain */
15130 +#define NUMREGBYTES    112     /* 92 */
15131 +#define NUMCRITREGBYTES        (9 << 2)
15132 +#define BUFMAX         400
15133  
15134 -/* Same as pt_regs but has vbr in place of syscall_nr */
15135 +#ifndef __ASSEMBLY__
15136  struct kgdb_regs {
15137          unsigned long regs[16];
15138          unsigned long pc;
15139          unsigned long pr;
15140 -        unsigned long sr;
15141          unsigned long gbr;
15142 +        unsigned long vbr;
15143          unsigned long mach;
15144          unsigned long macl;
15145 -        unsigned long vbr;
15146 -};
15147 -
15148 -/* State info */
15149 -extern char kgdb_in_gdb_mode;
15150 -extern int kgdb_done_init;
15151 -extern int kgdb_enabled;
15152 -extern int kgdb_nofault;       /* Ignore bus errors (in gdb mem access) */
15153 -extern int kgdb_halt;          /* Execute initial breakpoint at startup */
15154 -extern char in_nmi;            /* Debounce flag to prevent NMI reentry*/
15155 -
15156 -/* SCI */
15157 -extern int kgdb_portnum;
15158 -extern int kgdb_baud;
15159 -extern char kgdb_parity;
15160 -extern char kgdb_bits;
15161 -extern int kgdb_console_setup(struct console *, char *);
15162 -
15163 -/* Init and interface stuff */
15164 -extern int kgdb_init(void);
15165 -extern int (*kgdb_serial_setup)(void);
15166 -extern int (*kgdb_getchar)(void);
15167 -extern void (*kgdb_putchar)(int);
15168 -
15169 -struct kgdb_sermap {
15170 -       char *name;
15171 -       int namelen;
15172 -       int (*setup_fn)(struct console *, char *);
15173 -       struct kgdb_sermap *next;
15174 +        unsigned long sr;
15175  };
15176 -extern void kgdb_register_sermap(struct kgdb_sermap *map);
15177 -extern struct kgdb_sermap *kgdb_porttype;
15178  
15179 -/* Trap functions */
15180 -typedef void (kgdb_debug_hook_t)(struct pt_regs *regs); 
15181 -typedef void (kgdb_bus_error_hook_t)(void);
15182 -extern kgdb_debug_hook_t  *kgdb_debug_hook;
15183 -extern kgdb_bus_error_hook_t *kgdb_bus_err_hook;
15184 -
15185 -extern void breakpoint(void);
15186 -
15187 -/* Console */
15188 -struct console;
15189 -void kgdb_console_write(struct console *co, const char *s, unsigned count);
15190 -void kgdb_console_init(void);
15191 -
15192 -/* Prototypes for jmp fns */
15193 -#define _JBLEN 9
15194 -typedef        int jmp_buf[_JBLEN];
15195 -extern void    longjmp(jmp_buf __jmpb, int __retval);
15196 -extern int     setjmp(jmp_buf __jmpb);
15197 -
15198 -/* Variadic macro to print our own message to the console */
15199 -#define KGDB_PRINTK(...) printk("KGDB: " __VA_ARGS__)
15200 -
15201 -/* Forced breakpoint */
15202 -#define BREAKPOINT() do {                                     \
15203 -  if (kgdb_enabled) {                                         \
15204 -    asm volatile("trapa   #0xff");                            \
15205 -  }                                                           \
15206 -} while (0)
15207 +#define BREAKPOINT()           asm("trapa #0xff");
15208 +#define BREAK_INSTR_SIZE       2
15209 +#define CACHE_FLUSH_IS_SAFE    1
15210  
15211  /* KGDB should be able to flush all kernel text space */
15212  #if defined(CONFIG_CPU_SH4)
15213 @@ -102,30 +48,5 @@ extern int     setjmp(jmp_buf __jmpb);
15214  #else
15215  #define kgdb_flush_icache_range(start, end)    do { } while (0)
15216  #endif
15217 -
15218 -/* Kernel assert macros */
15219 -#ifdef CONFIG_KGDB_KERNEL_ASSERTS
15220 -
15221 -/* Predefined conditions */
15222 -#define KA_VALID_ERRNO(errno) ((errno) > 0 && (errno) <= EMEDIUMTYPE)
15223 -#define KA_VALID_PTR_ERR(ptr) KA_VALID_ERRNO(-PTR_ERR(ptr))
15224 -#define KA_VALID_KPTR(ptr)  (!(ptr) || \
15225 -              ((void *)(ptr) >= (void *)PAGE_OFFSET &&  \
15226 -               (void *)(ptr) < ERR_PTR(-EMEDIUMTYPE)))
15227 -#define KA_VALID_PTRORERR(errptr) \
15228 -               (KA_VALID_KPTR(errptr) || KA_VALID_PTR_ERR(errptr))
15229 -#define KA_HELD_GKL()  (current->lock_depth >= 0)
15230 -
15231 -/* The actual assert */
15232 -#define KGDB_ASSERT(condition, message) do {                   \
15233 -       if (!(condition) && (kgdb_enabled)) {                   \
15234 -               KGDB_PRINTK("Assertion failed at %s:%d: %s\n",  \
15235 -                                  __FILE__, __LINE__, message);\
15236 -               BREAKPOINT();                                   \
15237 -       }                                                       \
15238 -} while (0)
15239 -#else
15240 -#define KGDB_ASSERT(condition, message)
15241 -#endif
15242 -
15243 +#endif                         /* !__ASSEMBLY__ */
15244  #endif
15245 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-sh/system.h linux-2.6.18-53.1.14.kgdb/include/asm-sh/system.h
15246 --- linux-2.6.18-53.1.14/include/asm-sh/system.h        2006-09-20 07:42:06.000000000 +0400
15247 +++ linux-2.6.18-53.1.14.kgdb/include/asm-sh/system.h   2008-06-10 15:38:50.000000000 +0400
15248 @@ -6,6 +6,7 @@
15249   * Copyright (C) 2002 Paul Mundt
15250   */
15251  
15252 +#include <asm/types.h>
15253  
15254  /*
15255   *     switch_to() should switch tasks to task nr n, first
15256 @@ -260,6 +261,45 @@ static __inline__ unsigned long __xchg(u
15257         return x;
15258  }
15259  
15260 +static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
15261 +       unsigned long new)
15262 +{
15263 +       __u32 retval;
15264 +       unsigned long flags;
15265 +
15266 +       local_irq_save(flags);
15267 +       retval = *m;
15268 +       if (retval == old)
15269 +               *m = new;
15270 +       local_irq_restore(flags);       /* implies memory barrier  */
15271 +       return retval;
15272 +}
15273 +
15274 +/* This function doesn't exist, so you'll get a linker error
15275 + * if something tries to do an invalid cmpxchg(). */
15276 +extern void __cmpxchg_called_with_bad_pointer(void);
15277 +
15278 +#define __HAVE_ARCH_CMPXCHG    1
15279 +
15280 +static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
15281 +               unsigned long new, int size)
15282 +{
15283 +       switch (size) {
15284 +       case 4:
15285 +               return __cmpxchg_u32(ptr, old, new);
15286 +       }
15287 +       __cmpxchg_called_with_bad_pointer();
15288 +       return old;
15289 +}
15290 +
15291 +#define cmpxchg(ptr,o,n)                                                \
15292 +  ({                                                                    \
15293 +     __typeof__(*(ptr)) _o_ = (o);                                      \
15294 +     __typeof__(*(ptr)) _n_ = (n);                                      \
15295 +     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,          \
15296 +                                   (unsigned long)_n_, sizeof(*(ptr))); \
15297 +  })
15298 +
15299  /* XXX
15300   * disable hlt during certain critical i/o operations
15301   */
15302 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-x86_64/kdebug.h linux-2.6.18-53.1.14.kgdb/include/asm-x86_64/kdebug.h
15303 --- linux-2.6.18-53.1.14/include/asm-x86_64/kdebug.h    2006-09-20 07:42:06.000000000 +0400
15304 +++ linux-2.6.18-53.1.14.kgdb/include/asm-x86_64/kdebug.h       2008-06-10 15:38:41.000000000 +0400
15305 @@ -34,6 +34,7 @@ enum die_val {
15306         DIE_CALL,
15307         DIE_NMI_IPI,
15308         DIE_PAGE_FAULT,
15309 +       DIE_PAGE_FAULT_NO_CONTEXT,
15310  };
15311  
15312  static inline int notify_die(enum die_val val, const char *str,
15313 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-x86_64/kgdb.h linux-2.6.18-53.1.14.kgdb/include/asm-x86_64/kgdb.h
15314 --- linux-2.6.18-53.1.14/include/asm-x86_64/kgdb.h      1970-01-01 03:00:00.000000000 +0300
15315 +++ linux-2.6.18-53.1.14.kgdb/include/asm-x86_64/kgdb.h 2008-06-10 15:39:01.000000000 +0400
15316 @@ -0,0 +1,54 @@
15317 +#ifdef __KERNEL__
15318 +#ifndef _ASM_KGDB_H_
15319 +#define _ASM_KGDB_H_
15320 +
15321 +/*
15322 + * Copyright (C) 2001-2004 Amit S. Kale
15323 + */
15324 +
15325 +#include <asm-generic/kgdb.h>
15326 +
15327 +/*
15328 + *  Note that this register image is in a different order than
15329 + *  the register image that Linux produces at interrupt time.
15330 + *
15331 + *  Linux's register image is defined by struct pt_regs in ptrace.h.
15332 + *  Just why GDB uses a different order is a historical mystery.
15333 + */
15334 +#define _RAX   0
15335 +#define _RDX   1
15336 +#define _RCX   2
15337 +#define _RBX   3
15338 +#define _RSI   4
15339 +#define _RDI   5
15340 +#define _RBP   6
15341 +#define _RSP   7
15342 +#define _R8    8
15343 +#define _R9    9
15344 +#define _R10   10
15345 +#define _R11   11
15346 +#define _R12   12
15347 +#define _R13   13
15348 +#define _R14   14
15349 +#define _R15   15
15350 +#define _PC    16
15351 +#define _PS    17
15352 +
15353 +/* Number of bytes of registers.  */
15354 +#define NUMREGBYTES            ((_PS+1)*8)
15355 +#define NUMCRITREGBYTES                (8 * 8)         /* 8 registers. */
15356 +
15357 +/* Help GDB to know when to stop backtracing. */
15358 +#define CFI_END_FRAME(func)    __CFI_END_FRAME(_PC,_RSP,func)
15359 +#ifndef __ASSEMBLY__
15360 +/* BUFMAX defines the maximum number of characters in inbound/outbound
15361 + * buffers at least NUMREGBYTES*2 are needed for register packets, and
15362 + * a longer buffer is needed to list all threads. */
15363 +#define BUFMAX                 1024
15364 +#define BREAKPOINT()           asm("   int $3");
15365 +#define CHECK_EXCEPTION_STACK() ((&__get_cpu_var(init_tss))[0].ist[0])
15366 +#define BREAK_INSTR_SIZE       1
15367 +#define CACHE_FLUSH_IS_SAFE    1
15368 +#endif                         /* !__ASSEMBLY__ */
15369 +#endif                         /* _ASM_KGDB_H_ */
15370 +#endif                         /* __KERNEL__ */
15371 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/asm-x86_64/system.h linux-2.6.18-53.1.14.kgdb/include/asm-x86_64/system.h
15372 --- linux-2.6.18-53.1.14/include/asm-x86_64/system.h    2008-03-06 05:54:38.000000000 +0300
15373 +++ linux-2.6.18-53.1.14.kgdb/include/asm-x86_64/system.h       2008-06-10 15:38:44.000000000 +0400
15374 @@ -22,7 +22,9 @@
15375  
15376  /* Save restore flags to clear handle leaking NT */
15377  #define switch_to(prev,next,last) \
15378 -       asm volatile(SAVE_CONTEXT                                                   \
15379 +       asm volatile(".globl __switch_to_begin\n\t"                                 \
15380 +                    "__switch_to_begin:\n\t"                                     \
15381 +                    SAVE_CONTEXT                                                 \
15382                      "movq %%rsp,%P[threadrsp](%[prev])\n\t" /* save RSP */       \
15383                      "movq %P[threadrsp](%[next]),%%rsp\n\t" /* restore RSP */    \
15384                      "call __switch_to\n\t"                                       \
15385 @@ -34,6 +36,8 @@
15386                      "movq %%rax,%%rdi\n\t"                                       \
15387                      "jc   ret_from_fork\n\t"                                     \
15388                      RESTORE_CONTEXT                                                \
15389 +                    ".globl __switch_to_end\n\t"                                 \
15390 +                    "__switch_to_end:\n\t"                                       \
15391                      : "=a" (last)                                                \
15392                      : [next] "S" (next), [prev] "D" (prev),                      \
15393                        [threadrsp] "i" (offsetof(struct task_struct, thread.rsp)), \
15394 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/linux/dwarf2-lang.h linux-2.6.18-53.1.14.kgdb/include/linux/dwarf2-lang.h
15395 --- linux-2.6.18-53.1.14/include/linux/dwarf2-lang.h    1970-01-01 03:00:00.000000000 +0300
15396 +++ linux-2.6.18-53.1.14.kgdb/include/linux/dwarf2-lang.h       2008-06-10 15:39:01.000000000 +0400
15397 @@ -0,0 +1,300 @@
15398 +#ifndef DWARF2_LANG
15399 +#define DWARF2_LANG
15400 +
15401 +/*
15402 + * This is free software; you can redistribute it and/or modify it under
15403 + * the terms of the GNU General Public License as published by the Free
15404 + * Software Foundation; either version 2, or (at your option) any later
15405 + * version.
15406 + */
15407 +/*
15408 + * This file defines macros that allow generation of DWARF debug records
15409 + * for asm files.  This file is platform independent.  Register numbers
15410 + * (which are about the only thing that is platform dependent) are to be
15411 + * supplied by a platform defined file.
15412 + */
15413 +/*
15414 + * We need this to work for both asm and C.  In asm we are using the
15415 + * old comment trick to concatenate while C uses the new ANSI thing.
15416 + * Here we have concat macro...  The multi level thing is to allow and
15417 + * macros used in the names to be resolved prior to the cat (at which
15418 + * time they are no longer the same string).
15419 + */
15420 +#define CAT3(a,b,c) _CAT3(a,b,c)
15421 +#define _CAT3(a,b,c) __CAT3(a,b,c)
15422 +#ifndef __STDC__
15423 +#define __CAT3(a,b,c) a/**/b/**/c
15424 +#else
15425 +#define __CAT3(a,b,c) a##b##c
15426 +#endif
15427 +#ifdef __ASSEMBLY__
15428 +#define IFC(a)
15429 +#define IFN_C(a) a
15430 +#define NL ;
15431 +#define QUOTE_THIS(a) a
15432 +#define DWARF_preamble .section .debug_frame,"",%progbits;
15433 +#else
15434 +#define IFC(a) a
15435 +#define IFN_C(a)
15436 +#define NL \n\t
15437 +#define QUOTE_THIS(a) _QUOTE_THIS(a)
15438 +#define _QUOTE_THIS(a) #a
15439 +/* Don't let CPP see the " and , \042=" \054=, */
15440 +#define DWARF_preamble .section .debug_frame \054\042\042\054%progbits
15441 +#endif
15442 +
15443 +#ifdef CONFIG_64BIT
15444 +#define DATA_ALIGN_FACTOR      8
15445 +#define ADDR_LOC               .quad
15446 +#else
15447 +#define DATA_ALIGN_FACTOR      4
15448 +#define ADDR_LOC               .long
15449 +#endif
15450 +
15451 +#include <linux/dwarf2-defs.h>
15452 +/*
15453 + * This macro starts a debug frame section.  The debug_frame describes
15454 + * where to find the registers that the enclosing function saved on
15455 + * entry.
15456 + *
15457 + * ORD is use by the label generator and should be the same as what is
15458 + * passed to CFI_postamble.
15459 + *
15460 + * pc, pc register gdb ordinal.
15461 + *
15462 + * code_align this is the factor used to define locations or regions
15463 + * where the given definitions apply.  If you use labels to define these
15464 + * this should be 1.
15465 + *
15466 + * data_align this is the factor used to define register offsets.  If
15467 + * you use struct offset, this should be the size of the register in
15468 + * bytes or the negative of that.  This is how it is used: you will
15469 + * define a register as the reference register, say the stack pointer,
15470 + * then you will say where a register is located relative to this
15471 + * reference registers value, say 40 for register 3 (the gdb register
15472 + * number).  The <40> will be multiplied by <data_align> to define the
15473 + * byte offset of the given register (3, in this example).  So if your
15474 + * <40> is the byte offset and the reference register points at the
15475 + * begining, you would want 1 for the data_offset.  If <40> was the 40th
15476 + * 4-byte element in that structure you would want 4.  And if your
15477 + * reference register points at the end of the structure you would want
15478 + * a negative data_align value(and you would have to do other math as
15479 + * well).
15480 + */
15481 +
15482 +#define CFI_preamble(ORD, pc, code_align, data_align)  \
15483 +         DWARF_preamble        NL                              \
15484 +       .align DATA_ALIGN_FACTOR NL                     \
15485 +        .globl CAT3(frame,_,ORD) NL                    \
15486 +CAT3(frame,_,ORD): NL                                  \
15487 +       .long 7f-6f NL                                  \
15488 +6:                                                     \
15489 +       .long   DW_CIE_ID NL                            \
15490 +       .byte   DW_CIE_VERSION NL                       \
15491 +       .byte 0  NL                                     \
15492 +       .uleb128 code_align NL                          \
15493 +       .sleb128 data_align NL                          \
15494 +       .byte pc NL
15495 +
15496 +/*
15497 + * After the above macro and prior to the CFI_postamble, you need to
15498 + * define the initial state.  This starts with defining the reference
15499 + * register and, usually the pc.  Here are some helper macros:
15500 + */
15501 +
15502 +#define CFA_define_reference(reg, offset)      \
15503 +       .byte DW_CFA_def_cfa NL                 \
15504 +       .uleb128 reg NL                         \
15505 +       .uleb128 (offset) NL
15506 +
15507 +#define CFA_define_offset(reg, offset)         \
15508 +       .byte (DW_CFA_offset + reg) NL          \
15509 +       .uleb128 (offset) NL
15510 +
15511 +#define CFA_restore(reg)                       \
15512 +        .byte (DW_CFA_restore + reg) NL
15513 +
15514 +#define CFI_postamble()                                \
15515 +       .align DATA_ALIGN_FACTOR NL                             \
15516 +7: NL                                          \
15517 +.previous NL
15518 +
15519 +/*
15520 + * So now your code pushs stuff on the stack, you need a new location
15521 + * and the rules for what to do.  This starts a running description of
15522 + * the call frame.  You need to describe what changes with respect to
15523 + * the call registers as the location of the pc moves through the code.
15524 + * The following builds an FDE (fram descriptor entry?).  Like the
15525 + * above, it has a preamble and a postamble.  It also is tied to the CFI
15526 + * above.
15527 + * The preamble macro is tied to the CFI thru the first parameter.  The
15528 + * second is the code start address and then the code end address+1.
15529 + */
15530 +#define FDE_preamble(ORD, initial_address, end_address)        \
15531 +        DWARF_preamble NL                              \
15532 +       .align DATA_ALIGN_FACTOR NL                                     \
15533 +       .long 9f-8f NL                                  \
15534 +8:                                                     \
15535 +       .long CAT3(frame,_,ORD) NL                      \
15536 +       ADDR_LOC initial_address NL                     \
15537 +       ADDR_LOC (end_address - initial_address) NL
15538 +
15539 +#define FDE_postamble()                                \
15540 +       .align DATA_ALIGN_FACTOR NL                             \
15541 +9:      NL                                     \
15542 +.previous NL
15543 +
15544 +/*
15545 + * That done, you can now add registers, subtract registers, move the
15546 + * reference and even change the reference.  You can also define a new
15547 + * area of code the info applies to.  For discontinuous bits you should
15548 + * start a new FDE.  You may have as many as you like.
15549 + */
15550 +
15551 +/*
15552 + * To advance the stack address by <bytes> (0x3f max)
15553 + */
15554 +
15555 +#define CFA_advance_loc(bytes)                 \
15556 +       .byte DW_CFA_advance_loc+bytes NL
15557 +
15558 +/*
15559 + * This one is good for 0xff or 255
15560 + */
15561 +#define CFA_advance_loc1(bytes)                        \
15562 +       .byte DW_CFA_advance_loc1 NL            \
15563 +        .byte bytes NL
15564 +
15565 +#define CFA_undefine_reg(reg)                  \
15566 +        .byte DW_CFA_undefined NL              \
15567 +       .uleb128 reg NL
15568 +/*
15569 + * With the above you can define all the register locations.  But
15570 + * suppose the reference register moves... Takes the new offset NOT an
15571 + * increment.  This is how esp is tracked if it is not saved.
15572 + */
15573 +
15574 +#define CFA_define_cfa_offset(offset)          \
15575 +       .byte DW_CFA_def_cfa_offset NL          \
15576 +       .uleb128 (offset) NL
15577 +/*
15578 + * Or suppose you want to use a different reference register...
15579 + */
15580 +#define CFA_define_cfa_register(reg)           \
15581 +       .byte DW_CFA_def_cfa_register NL        \
15582 +       .uleb128 reg NL
15583 +
15584 +/*
15585 + * If you want to mess with the stack pointer, here is the expression.
15586 + * The stack starts empty.
15587 + */
15588 +#define CFA_def_cfa_expression                         \
15589 +        .byte DW_CFA_def_cfa_expression        NL      \
15590 +       .uleb128 20f-10f NL                     \
15591 +10:     NL
15592 +/*
15593 + * This expression is to be used for other regs.  The stack starts with the
15594 + * stack address.
15595 + */
15596 +
15597 +#define CFA_expression(reg)                    \
15598 +        .byte DW_CFA_expression         NL             \
15599 +        .uleb128 reg NL                                \
15600 +       .uleb128 20f-10f NL                     \
15601 +10:     NL
15602 +/*
15603 + * Here we do the expression stuff.  You should code the above followed
15604 + *  by expression OPs followed by CFA_expression_end.
15605 + */
15606 +
15607 +
15608 +#define CFA_expression_end                     \
15609 +20:     NL
15610 +
15611 +#define CFA_exp_OP_const4s(a)                  \
15612 +        .byte DW_OP_const4s NL                 \
15613 +        .long a NL
15614 +
15615 +#define  CFA_exp_OP_swap  .byte DW_OP_swap NL
15616 +#define  CFA_exp_OP_dup  .byte DW_OP_dup NL
15617 +#define  CFA_exp_OP_drop  .byte DW_OP_drop NL
15618 +/*
15619 + * All these work on the top two elements on the stack, replacing them
15620 + * with the result.  Top comes first where it matters.  True is 1, false 0.
15621 + */
15622 +#define  CFA_exp_OP_deref .byte DW_OP_deref NL
15623 +#define  CFA_exp_OP_and   .byte DW_OP_and NL
15624 +#define  CFA_exp_OP_div   .byte DW_OP_div NL
15625 +#define  CFA_exp_OP_minus .byte DW_OP_minus NL
15626 +#define  CFA_exp_OP_mod   .byte DW_OP_mod NL
15627 +#define  CFA_exp_OP_neg   .byte DW_OP_neg NL
15628 +#define  CFA_exp_OP_plus  .byte DW_OP_plus NL
15629 +#define  CFA_exp_OP_not   .byte DW_OP_not NL
15630 +#define  CFA_exp_OP_or    .byte DW_OP_or NL
15631 +#define  CFA_exp_OP_xor   .byte DW_OP_xor NL
15632 +#define  CFA_exp_OP_le    .byte DW_OP_le NL
15633 +#define  CFA_exp_OP_ge    .byte DW_OP_ge NL
15634 +#define  CFA_exp_OP_eq    .byte DW_OP_eq NL
15635 +#define  CFA_exp_OP_lt    .byte DW_OP_lt NL
15636 +#define  CFA_exp_OP_gt    .byte DW_OP_gt NL
15637 +#define  CFA_exp_OP_ne    .byte DW_OP_ne NL
15638 +/*
15639 + * These take a parameter as noted
15640 + */
15641 +/*
15642 + * Unconditional skip to loc. loc is a label (loc:)
15643 + */
15644 +#define CFA_exp_OP_skip(loc)                   \
15645 +         .byte DW_OP_skip  NL                  \
15646 +        .hword  loc-.-2 NL
15647 +/*
15648 + * Conditional skip to loc (TOS != 0, TOS--) (loc is a label)
15649 + */
15650 +#define CFA_exp_OP_bra(loc)                    \
15651 +         .byte DW_OP_bra NL                    \
15652 +        .hword loc-.-2 NL
15653 +
15654 +/*
15655 + * TOS += no (an unsigned number)
15656 + */
15657 +#define CFA_exp_OP_plus_uconst(no)             \
15658 +         .byte DW_OP_plus_uconst NL            \
15659 +         .uleb128 no NL
15660 +
15661 +/*
15662 + * ++TOS = no (a unsigned number)
15663 + */
15664 +#define CFA_exp_OP_constu(no)                  \
15665 +         .byte DW_OP_constu NL                 \
15666 +        .uleb128 no NL
15667 +/*
15668 + * ++TOS = no (a signed number)
15669 + */
15670 +#define CFA_exp_OP_consts(no)                  \
15671 +         .byte DW_OP_consts NL                 \
15672 +        .sleb128 no NL
15673 +/*
15674 + * ++TOS = no (an unsigned byte)
15675 + */
15676 +#define CFA_exp_OP_const1u(no)                 \
15677 +         .byte DW_OP_const1u NL                        \
15678 +        .byte no NL
15679 +
15680 +
15681 +/*
15682 + * ++TOS = no (a address)
15683 + */
15684 +#define CFA_exp_OP_addr(no)                    \
15685 +         .byte DW_OP_addr NL                   \
15686 +        .long no NL
15687 +
15688 +/*
15689 + * Push current frames value for "reg" + offset
15690 + * We take advantage of the opcode assignments to make this a litteral reg
15691 + * rather than use the DW_OP_bregx opcode.
15692 + */
15693 +
15694 +#define CFA_exp_OP_breg(reg,offset)            \
15695 +         .byte DW_OP_breg0+reg NL              \
15696 +         .sleb128 offset NL
15697 +#endif
15698 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/linux/dwarf2.h linux-2.6.18-53.1.14.kgdb/include/linux/dwarf2.h
15699 --- linux-2.6.18-53.1.14/include/linux/dwarf2.h 1970-01-01 03:00:00.000000000 +0300
15700 +++ linux-2.6.18-53.1.14.kgdb/include/linux/dwarf2.h    2008-06-10 15:39:01.000000000 +0400
15701 @@ -0,0 +1,775 @@
15702 +/* Declarations and definitions of codes relating to the DWARF2 symbolic
15703 +   debugging information format.
15704 +   Copyright (C) 1992, 1993, 1995, 1996, 1997, 1999, 2000, 2001, 2002,
15705 +   2003 Free Software Foundation, Inc.
15706 +
15707 +   Written by Gary Funck (gary@intrepid.com) The Ada Joint Program
15708 +   Office (AJPO), Florida State Unviversity and Silicon Graphics Inc.
15709 +   provided support for this effort -- June 21, 1995.
15710 +
15711 +   Derived from the DWARF 1 implementation written by Ron Guilmette
15712 +   (rfg@netcom.com), November 1990.
15713 +
15714 +   This file is part of GCC.
15715 +
15716 +   GCC is free software; you can redistribute it and/or modify it under
15717 +   the terms of the GNU General Public License as published by the Free
15718 +   Software Foundation; either version 2, or (at your option) any later
15719 +   version.
15720 +
15721 +   GCC is distributed in the hope that it will be useful, but WITHOUT
15722 +   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15723 +   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15724 +   License for more details.
15725 +
15726 +   You should have received a copy of the GNU General Public License
15727 +   along with GCC; see the file COPYING.  If not, write to the Free
15728 +   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
15729 +   02111-1307, USA.  */
15730 +
15731 +/* This file is derived from the DWARF specification (a public document)
15732 +   Revision 2.0.0 (July 27, 1993) developed by the UNIX International
15733 +   Programming Languages Special Interest Group (UI/PLSIG) and distributed
15734 +   by UNIX International.  Copies of this specification are available from
15735 +   UNIX International, 20 Waterview Boulevard, Parsippany, NJ, 07054.
15736 +
15737 +   This file also now contains definitions from the DWARF 3 specification.  */
15738 +
15739 +/* This file is shared between GCC and GDB, and should not contain
15740 +   prototypes.  */
15741 +
15742 +#ifndef _ELF_DWARF2_H
15743 +#define _ELF_DWARF2_H
15744 +
15745 +/* Structure found in the .debug_line section.  */
15746 +typedef struct
15747 +{
15748 +  unsigned char li_length          [4];
15749 +  unsigned char li_version         [2];
15750 +  unsigned char li_prologue_length [4];
15751 +  unsigned char li_min_insn_length [1];
15752 +  unsigned char li_default_is_stmt [1];
15753 +  unsigned char li_line_base       [1];
15754 +  unsigned char li_line_range      [1];
15755 +  unsigned char li_opcode_base     [1];
15756 +}
15757 +DWARF2_External_LineInfo;
15758 +
15759 +typedef struct
15760 +{
15761 +  unsigned long  li_length;
15762 +  unsigned short li_version;
15763 +  unsigned int   li_prologue_length;
15764 +  unsigned char  li_min_insn_length;
15765 +  unsigned char  li_default_is_stmt;
15766 +  int            li_line_base;
15767 +  unsigned char  li_line_range;
15768 +  unsigned char  li_opcode_base;
15769 +}
15770 +DWARF2_Internal_LineInfo;
15771 +
15772 +/* Structure found in .debug_pubnames section.  */
15773 +typedef struct
15774 +{
15775 +  unsigned char pn_length  [4];
15776 +  unsigned char pn_version [2];
15777 +  unsigned char pn_offset  [4];
15778 +  unsigned char pn_size    [4];
15779 +}
15780 +DWARF2_External_PubNames;
15781 +
15782 +typedef struct
15783 +{
15784 +  unsigned long  pn_length;
15785 +  unsigned short pn_version;
15786 +  unsigned long  pn_offset;
15787 +  unsigned long  pn_size;
15788 +}
15789 +DWARF2_Internal_PubNames;
15790 +
15791 +/* Structure found in .debug_info section.  */
15792 +typedef struct
15793 +{
15794 +  unsigned char  cu_length        [4];
15795 +  unsigned char  cu_version       [2];
15796 +  unsigned char  cu_abbrev_offset [4];
15797 +  unsigned char  cu_pointer_size  [1];
15798 +}
15799 +DWARF2_External_CompUnit;
15800 +
15801 +typedef struct
15802 +{
15803 +  unsigned long  cu_length;
15804 +  unsigned short cu_version;
15805 +  unsigned long  cu_abbrev_offset;
15806 +  unsigned char  cu_pointer_size;
15807 +}
15808 +DWARF2_Internal_CompUnit;
15809 +
15810 +typedef struct
15811 +{
15812 +  unsigned char  ar_length       [4];
15813 +  unsigned char  ar_version      [2];
15814 +  unsigned char  ar_info_offset  [4];
15815 +  unsigned char  ar_pointer_size [1];
15816 +  unsigned char  ar_segment_size [1];
15817 +}
15818 +DWARF2_External_ARange;
15819 +
15820 +typedef struct
15821 +{
15822 +  unsigned long  ar_length;
15823 +  unsigned short ar_version;
15824 +  unsigned long  ar_info_offset;
15825 +  unsigned char  ar_pointer_size;
15826 +  unsigned char  ar_segment_size;
15827 +}
15828 +DWARF2_Internal_ARange;
15829 +
15830 +
15831 +/* Tag names and codes.  */
15832 +enum dwarf_tag
15833 +  {
15834 +    DW_TAG_padding = 0x00,
15835 +    DW_TAG_array_type = 0x01,
15836 +    DW_TAG_class_type = 0x02,
15837 +    DW_TAG_entry_point = 0x03,
15838 +    DW_TAG_enumeration_type = 0x04,
15839 +    DW_TAG_formal_parameter = 0x05,
15840 +    DW_TAG_imported_declaration = 0x08,
15841 +    DW_TAG_label = 0x0a,
15842 +    DW_TAG_lexical_block = 0x0b,
15843 +    DW_TAG_member = 0x0d,
15844 +    DW_TAG_pointer_type = 0x0f,
15845 +    DW_TAG_reference_type = 0x10,
15846 +    DW_TAG_compile_unit = 0x11,
15847 +    DW_TAG_string_type = 0x12,
15848 +    DW_TAG_structure_type = 0x13,
15849 +    DW_TAG_subroutine_type = 0x15,
15850 +    DW_TAG_typedef = 0x16,
15851 +    DW_TAG_union_type = 0x17,
15852 +    DW_TAG_unspecified_parameters = 0x18,
15853 +    DW_TAG_variant = 0x19,
15854 +    DW_TAG_common_block = 0x1a,
15855 +    DW_TAG_common_inclusion = 0x1b,
15856 +    DW_TAG_inheritance = 0x1c,
15857 +    DW_TAG_inlined_subroutine = 0x1d,
15858 +    DW_TAG_module = 0x1e,
15859 +    DW_TAG_ptr_to_member_type = 0x1f,
15860 +    DW_TAG_set_type = 0x20,
15861 +    DW_TAG_subrange_type = 0x21,
15862 +    DW_TAG_with_stmt = 0x22,
15863 +    DW_TAG_access_declaration = 0x23,
15864 +    DW_TAG_base_type = 0x24,
15865 +    DW_TAG_catch_block = 0x25,
15866 +    DW_TAG_const_type = 0x26,
15867 +    DW_TAG_constant = 0x27,
15868 +    DW_TAG_enumerator = 0x28,
15869 +    DW_TAG_file_type = 0x29,
15870 +    DW_TAG_friend = 0x2a,
15871 +    DW_TAG_namelist = 0x2b,
15872 +    DW_TAG_namelist_item = 0x2c,
15873 +    DW_TAG_packed_type = 0x2d,
15874 +    DW_TAG_subprogram = 0x2e,
15875 +    DW_TAG_template_type_param = 0x2f,
15876 +    DW_TAG_template_value_param = 0x30,
15877 +    DW_TAG_thrown_type = 0x31,
15878 +    DW_TAG_try_block = 0x32,
15879 +    DW_TAG_variant_part = 0x33,
15880 +    DW_TAG_variable = 0x34,
15881 +    DW_TAG_volatile_type = 0x35,
15882 +    /* DWARF 3.  */
15883 +    DW_TAG_dwarf_procedure = 0x36,
15884 +    DW_TAG_restrict_type = 0x37,
15885 +    DW_TAG_interface_type = 0x38,
15886 +    DW_TAG_namespace = 0x39,
15887 +    DW_TAG_imported_module = 0x3a,
15888 +    DW_TAG_unspecified_type = 0x3b,
15889 +    DW_TAG_partial_unit = 0x3c,
15890 +    DW_TAG_imported_unit = 0x3d,
15891 +    /* SGI/MIPS Extensions.  */
15892 +    DW_TAG_MIPS_loop = 0x4081,
15893 +    /* HP extensions.  See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz .  */
15894 +    DW_TAG_HP_array_descriptor = 0x4090,
15895 +    /* GNU extensions.  */
15896 +    DW_TAG_format_label = 0x4101,      /* For FORTRAN 77 and Fortran 90.  */
15897 +    DW_TAG_function_template = 0x4102, /* For C++.  */
15898 +    DW_TAG_class_template = 0x4103,    /* For C++.  */
15899 +    DW_TAG_GNU_BINCL = 0x4104,
15900 +    DW_TAG_GNU_EINCL = 0x4105,
15901 +    /* Extensions for UPC.  See: http://upc.gwu.edu/~upc.  */
15902 +    DW_TAG_upc_shared_type = 0x8765,
15903 +    DW_TAG_upc_strict_type = 0x8766,
15904 +    DW_TAG_upc_relaxed_type = 0x8767,
15905 +    /* PGI (STMicroelectronics) extensions.  No documentation available.  */
15906 +    DW_TAG_PGI_kanji_type      = 0xA000,
15907 +    DW_TAG_PGI_interface_block = 0xA020
15908 +  };
15909 +
15910 +#define DW_TAG_lo_user 0x4080
15911 +#define DW_TAG_hi_user 0xffff
15912 +
15913 +/* Flag that tells whether entry has a child or not.  */
15914 +#define DW_children_no   0
15915 +#define        DW_children_yes  1
15916 +
15917 +/* Form names and codes.  */
15918 +enum dwarf_form
15919 +  {
15920 +    DW_FORM_addr = 0x01,
15921 +    DW_FORM_block2 = 0x03,
15922 +    DW_FORM_block4 = 0x04,
15923 +    DW_FORM_data2 = 0x05,
15924 +    DW_FORM_data4 = 0x06,
15925 +    DW_FORM_data8 = 0x07,
15926 +    DW_FORM_string = 0x08,
15927 +    DW_FORM_block = 0x09,
15928 +    DW_FORM_block1 = 0x0a,
15929 +    DW_FORM_data1 = 0x0b,
15930 +    DW_FORM_flag = 0x0c,
15931 +    DW_FORM_sdata = 0x0d,
15932 +    DW_FORM_strp = 0x0e,
15933 +    DW_FORM_udata = 0x0f,
15934 +    DW_FORM_ref_addr = 0x10,
15935 +    DW_FORM_ref1 = 0x11,
15936 +    DW_FORM_ref2 = 0x12,
15937 +    DW_FORM_ref4 = 0x13,
15938 +    DW_FORM_ref8 = 0x14,
15939 +    DW_FORM_ref_udata = 0x15,
15940 +    DW_FORM_indirect = 0x16
15941 +  };
15942 +
15943 +/* Attribute names and codes.  */
15944 +enum dwarf_attribute
15945 +  {
15946 +    DW_AT_sibling = 0x01,
15947 +    DW_AT_location = 0x02,
15948 +    DW_AT_name = 0x03,
15949 +    DW_AT_ordering = 0x09,
15950 +    DW_AT_subscr_data = 0x0a,
15951 +    DW_AT_byte_size = 0x0b,
15952 +    DW_AT_bit_offset = 0x0c,
15953 +    DW_AT_bit_size = 0x0d,
15954 +    DW_AT_element_list = 0x0f,
15955 +    DW_AT_stmt_list = 0x10,
15956 +    DW_AT_low_pc = 0x11,
15957 +    DW_AT_high_pc = 0x12,
15958 +    DW_AT_language = 0x13,
15959 +    DW_AT_member = 0x14,
15960 +    DW_AT_discr = 0x15,
15961 +    DW_AT_discr_value = 0x16,
15962 +    DW_AT_visibility = 0x17,
15963 +    DW_AT_import = 0x18,
15964 +    DW_AT_string_length = 0x19,
15965 +    DW_AT_common_reference = 0x1a,
15966 +    DW_AT_comp_dir = 0x1b,
15967 +    DW_AT_const_value = 0x1c,
15968 +    DW_AT_containing_type = 0x1d,
15969 +    DW_AT_default_value = 0x1e,
15970 +    DW_AT_inline = 0x20,
15971 +    DW_AT_is_optional = 0x21,
15972 +    DW_AT_lower_bound = 0x22,
15973 +    DW_AT_producer = 0x25,
15974 +    DW_AT_prototyped = 0x27,
15975 +    DW_AT_return_addr = 0x2a,
15976 +    DW_AT_start_scope = 0x2c,
15977 +    DW_AT_stride_size = 0x2e,
15978 +    DW_AT_upper_bound = 0x2f,
15979 +    DW_AT_abstract_origin = 0x31,
15980 +    DW_AT_accessibility = 0x32,
15981 +    DW_AT_address_class = 0x33,
15982 +    DW_AT_artificial = 0x34,
15983 +    DW_AT_base_types = 0x35,
15984 +    DW_AT_calling_convention = 0x36,
15985 +    DW_AT_count = 0x37,
15986 +    DW_AT_data_member_location = 0x38,
15987 +    DW_AT_decl_column = 0x39,
15988 +    DW_AT_decl_file = 0x3a,
15989 +    DW_AT_decl_line = 0x3b,
15990 +    DW_AT_declaration = 0x3c,
15991 +    DW_AT_discr_list = 0x3d,
15992 +    DW_AT_encoding = 0x3e,
15993 +    DW_AT_external = 0x3f,
15994 +    DW_AT_frame_base = 0x40,
15995 +    DW_AT_friend = 0x41,
15996 +    DW_AT_identifier_case = 0x42,
15997 +    DW_AT_macro_info = 0x43,
15998 +    DW_AT_namelist_items = 0x44,
15999 +    DW_AT_priority = 0x45,
16000 +    DW_AT_segment = 0x46,
16001 +    DW_AT_specification = 0x47,
16002 +    DW_AT_static_link = 0x48,
16003 +    DW_AT_type = 0x49,
16004 +    DW_AT_use_location = 0x4a,
16005 +    DW_AT_variable_parameter = 0x4b,
16006 +    DW_AT_virtuality = 0x4c,
16007 +    DW_AT_vtable_elem_location = 0x4d,
16008 +    /* DWARF 3 values.  */
16009 +    DW_AT_allocated     = 0x4e,
16010 +    DW_AT_associated    = 0x4f,
16011 +    DW_AT_data_location = 0x50,
16012 +    DW_AT_stride        = 0x51,
16013 +    DW_AT_entry_pc      = 0x52,
16014 +    DW_AT_use_UTF8      = 0x53,
16015 +    DW_AT_extension     = 0x54,
16016 +    DW_AT_ranges        = 0x55,
16017 +    DW_AT_trampoline    = 0x56,
16018 +    DW_AT_call_column   = 0x57,
16019 +    DW_AT_call_file     = 0x58,
16020 +    DW_AT_call_line     = 0x59,
16021 +    /* SGI/MIPS extensions.  */
16022 +    DW_AT_MIPS_fde = 0x2001,
16023 +    DW_AT_MIPS_loop_begin = 0x2002,
16024 +    DW_AT_MIPS_tail_loop_begin = 0x2003,
16025 +    DW_AT_MIPS_epilog_begin = 0x2004,
16026 +    DW_AT_MIPS_loop_unroll_factor = 0x2005,
16027 +    DW_AT_MIPS_software_pipeline_depth = 0x2006,
16028 +    DW_AT_MIPS_linkage_name = 0x2007,
16029 +    DW_AT_MIPS_stride = 0x2008,
16030 +    DW_AT_MIPS_abstract_name = 0x2009,
16031 +    DW_AT_MIPS_clone_origin = 0x200a,
16032 +    DW_AT_MIPS_has_inlines = 0x200b,
16033 +    /* HP extensions.  */
16034 +    DW_AT_HP_block_index         = 0x2000,
16035 +    DW_AT_HP_unmodifiable        = 0x2001, /* Same as DW_AT_MIPS_fde.  */
16036 +    DW_AT_HP_actuals_stmt_list   = 0x2010,
16037 +    DW_AT_HP_proc_per_section    = 0x2011,
16038 +    DW_AT_HP_raw_data_ptr        = 0x2012,
16039 +    DW_AT_HP_pass_by_reference   = 0x2013,
16040 +    DW_AT_HP_opt_level           = 0x2014,
16041 +    DW_AT_HP_prof_version_id     = 0x2015,
16042 +    DW_AT_HP_opt_flags           = 0x2016,
16043 +    DW_AT_HP_cold_region_low_pc  = 0x2017,
16044 +    DW_AT_HP_cold_region_high_pc = 0x2018,
16045 +    DW_AT_HP_all_variables_modifiable = 0x2019,
16046 +    DW_AT_HP_linkage_name        = 0x201a,
16047 +    DW_AT_HP_prof_flags          = 0x201b,  /* In comp unit of procs_info for -g.  */
16048 +    /* GNU extensions.  */
16049 +    DW_AT_sf_names   = 0x2101,
16050 +    DW_AT_src_info   = 0x2102,
16051 +    DW_AT_mac_info   = 0x2103,
16052 +    DW_AT_src_coords = 0x2104,
16053 +    DW_AT_body_begin = 0x2105,
16054 +    DW_AT_body_end   = 0x2106,
16055 +    DW_AT_GNU_vector = 0x2107,
16056 +    /* VMS extensions.  */
16057 +    DW_AT_VMS_rtnbeg_pd_address = 0x2201,
16058 +    /* UPC extension.  */
16059 +    DW_AT_upc_threads_scaled = 0x3210,
16060 +    /* PGI (STMicroelectronics) extensions.  */
16061 +    DW_AT_PGI_lbase    = 0x3a00,
16062 +    DW_AT_PGI_soffset  = 0x3a01,
16063 +    DW_AT_PGI_lstride  = 0x3a02
16064 +  };
16065 +
16066 +#define DW_AT_lo_user  0x2000  /* Implementation-defined range start.  */
16067 +#define DW_AT_hi_user  0x3ff0  /* Implementation-defined range end.  */
16068 +
16069 +/* Location atom names and codes.  */
16070 +enum dwarf_location_atom
16071 +  {
16072 +    DW_OP_addr = 0x03,
16073 +    DW_OP_deref = 0x06,
16074 +    DW_OP_const1u = 0x08,
16075 +    DW_OP_const1s = 0x09,
16076 +    DW_OP_const2u = 0x0a,
16077 +    DW_OP_const2s = 0x0b,
16078 +    DW_OP_const4u = 0x0c,
16079 +    DW_OP_const4s = 0x0d,
16080 +    DW_OP_const8u = 0x0e,
16081 +    DW_OP_const8s = 0x0f,
16082 +    DW_OP_constu = 0x10,
16083 +    DW_OP_consts = 0x11,
16084 +    DW_OP_dup = 0x12,
16085 +    DW_OP_drop = 0x13,
16086 +    DW_OP_over = 0x14,
16087 +    DW_OP_pick = 0x15,
16088 +    DW_OP_swap = 0x16,
16089 +    DW_OP_rot = 0x17,
16090 +    DW_OP_xderef = 0x18,
16091 +    DW_OP_abs = 0x19,
16092 +    DW_OP_and = 0x1a,
16093 +    DW_OP_div = 0x1b,
16094 +    DW_OP_minus = 0x1c,
16095 +    DW_OP_mod = 0x1d,
16096 +    DW_OP_mul = 0x1e,
16097 +    DW_OP_neg = 0x1f,
16098 +    DW_OP_not = 0x20,
16099 +    DW_OP_or = 0x21,
16100 +    DW_OP_plus = 0x22,
16101 +    DW_OP_plus_uconst = 0x23,
16102 +    DW_OP_shl = 0x24,
16103 +    DW_OP_shr = 0x25,
16104 +    DW_OP_shra = 0x26,
16105 +    DW_OP_xor = 0x27,
16106 +    DW_OP_bra = 0x28,
16107 +    DW_OP_eq = 0x29,
16108 +    DW_OP_ge = 0x2a,
16109 +    DW_OP_gt = 0x2b,
16110 +    DW_OP_le = 0x2c,
16111 +    DW_OP_lt = 0x2d,
16112 +    DW_OP_ne = 0x2e,
16113 +    DW_OP_skip = 0x2f,
16114 +    DW_OP_lit0 = 0x30,
16115 +    DW_OP_lit1 = 0x31,
16116 +    DW_OP_lit2 = 0x32,
16117 +    DW_OP_lit3 = 0x33,
16118 +    DW_OP_lit4 = 0x34,
16119 +    DW_OP_lit5 = 0x35,
16120 +    DW_OP_lit6 = 0x36,
16121 +    DW_OP_lit7 = 0x37,
16122 +    DW_OP_lit8 = 0x38,
16123 +    DW_OP_lit9 = 0x39,
16124 +    DW_OP_lit10 = 0x3a,
16125 +    DW_OP_lit11 = 0x3b,
16126 +    DW_OP_lit12 = 0x3c,
16127 +    DW_OP_lit13 = 0x3d,
16128 +    DW_OP_lit14 = 0x3e,
16129 +    DW_OP_lit15 = 0x3f,
16130 +    DW_OP_lit16 = 0x40,
16131 +    DW_OP_lit17 = 0x41,
16132 +    DW_OP_lit18 = 0x42,
16133 +    DW_OP_lit19 = 0x43,
16134 +    DW_OP_lit20 = 0x44,
16135 +    DW_OP_lit21 = 0x45,
16136 +    DW_OP_lit22 = 0x46,
16137 +    DW_OP_lit23 = 0x47,
16138 +    DW_OP_lit24 = 0x48,
16139 +    DW_OP_lit25 = 0x49,
16140 +    DW_OP_lit26 = 0x4a,
16141 +    DW_OP_lit27 = 0x4b,
16142 +    DW_OP_lit28 = 0x4c,
16143 +    DW_OP_lit29 = 0x4d,
16144 +    DW_OP_lit30 = 0x4e,
16145 +    DW_OP_lit31 = 0x4f,
16146 +    DW_OP_reg0 = 0x50,
16147 +    DW_OP_reg1 = 0x51,
16148 +    DW_OP_reg2 = 0x52,
16149 +    DW_OP_reg3 = 0x53,
16150 +    DW_OP_reg4 = 0x54,
16151 +    DW_OP_reg5 = 0x55,
16152 +    DW_OP_reg6 = 0x56,
16153 +    DW_OP_reg7 = 0x57,
16154 +    DW_OP_reg8 = 0x58,
16155 +    DW_OP_reg9 = 0x59,
16156 +    DW_OP_reg10 = 0x5a,
16157 +    DW_OP_reg11 = 0x5b,
16158 +    DW_OP_reg12 = 0x5c,
16159 +    DW_OP_reg13 = 0x5d,
16160 +    DW_OP_reg14 = 0x5e,
16161 +    DW_OP_reg15 = 0x5f,
16162 +    DW_OP_reg16 = 0x60,
16163 +    DW_OP_reg17 = 0x61,
16164 +    DW_OP_reg18 = 0x62,
16165 +    DW_OP_reg19 = 0x63,
16166 +    DW_OP_reg20 = 0x64,
16167 +    DW_OP_reg21 = 0x65,
16168 +    DW_OP_reg22 = 0x66,
16169 +    DW_OP_reg23 = 0x67,
16170 +    DW_OP_reg24 = 0x68,
16171 +    DW_OP_reg25 = 0x69,
16172 +    DW_OP_reg26 = 0x6a,
16173 +    DW_OP_reg27 = 0x6b,
16174 +    DW_OP_reg28 = 0x6c,
16175 +    DW_OP_reg29 = 0x6d,
16176 +    DW_OP_reg30 = 0x6e,
16177 +    DW_OP_reg31 = 0x6f,
16178 +    DW_OP_breg0 = 0x70,
16179 +    DW_OP_breg1 = 0x71,
16180 +    DW_OP_breg2 = 0x72,
16181 +    DW_OP_breg3 = 0x73,
16182 +    DW_OP_breg4 = 0x74,
16183 +    DW_OP_breg5 = 0x75,
16184 +    DW_OP_breg6 = 0x76,
16185 +    DW_OP_breg7 = 0x77,
16186 +    DW_OP_breg8 = 0x78,
16187 +    DW_OP_breg9 = 0x79,
16188 +    DW_OP_breg10 = 0x7a,
16189 +    DW_OP_breg11 = 0x7b,
16190 +    DW_OP_breg12 = 0x7c,
16191 +    DW_OP_breg13 = 0x7d,
16192 +    DW_OP_breg14 = 0x7e,
16193 +    DW_OP_breg15 = 0x7f,
16194 +    DW_OP_breg16 = 0x80,
16195 +    DW_OP_breg17 = 0x81,
16196 +    DW_OP_breg18 = 0x82,
16197 +    DW_OP_breg19 = 0x83,
16198 +    DW_OP_breg20 = 0x84,
16199 +    DW_OP_breg21 = 0x85,
16200 +    DW_OP_breg22 = 0x86,
16201 +    DW_OP_breg23 = 0x87,
16202 +    DW_OP_breg24 = 0x88,
16203 +    DW_OP_breg25 = 0x89,
16204 +    DW_OP_breg26 = 0x8a,
16205 +    DW_OP_breg27 = 0x8b,
16206 +    DW_OP_breg28 = 0x8c,
16207 +    DW_OP_breg29 = 0x8d,
16208 +    DW_OP_breg30 = 0x8e,
16209 +    DW_OP_breg31 = 0x8f,
16210 +    DW_OP_regx = 0x90,
16211 +    DW_OP_fbreg = 0x91,
16212 +    DW_OP_bregx = 0x92,
16213 +    DW_OP_piece = 0x93,
16214 +    DW_OP_deref_size = 0x94,
16215 +    DW_OP_xderef_size = 0x95,
16216 +    DW_OP_nop = 0x96,
16217 +    /* DWARF 3 extensions.  */
16218 +    DW_OP_push_object_address = 0x97,
16219 +    DW_OP_call2 = 0x98,
16220 +    DW_OP_call4 = 0x99,
16221 +    DW_OP_call_ref = 0x9a,
16222 +    /* GNU extensions.  */
16223 +    DW_OP_GNU_push_tls_address = 0xe0,
16224 +    /* HP extensions.  */
16225 +    DW_OP_HP_unknown     = 0xe0, /* Ouch, the same as GNU_push_tls_address.  */
16226 +    DW_OP_HP_is_value    = 0xe1,
16227 +    DW_OP_HP_fltconst4   = 0xe2,
16228 +    DW_OP_HP_fltconst8   = 0xe3,
16229 +    DW_OP_HP_mod_range   = 0xe4,
16230 +    DW_OP_HP_unmod_range = 0xe5,
16231 +    DW_OP_HP_tls         = 0xe6
16232 +  };
16233 +
16234 +#define DW_OP_lo_user  0xe0    /* Implementation-defined range start.  */
16235 +#define DW_OP_hi_user  0xff    /* Implementation-defined range end.  */
16236 +
16237 +/* Type encodings.  */
16238 +enum dwarf_type
16239 +  {
16240 +    DW_ATE_void = 0x0,
16241 +    DW_ATE_address = 0x1,
16242 +    DW_ATE_boolean = 0x2,
16243 +    DW_ATE_complex_float = 0x3,
16244 +    DW_ATE_float = 0x4,
16245 +    DW_ATE_signed = 0x5,
16246 +    DW_ATE_signed_char = 0x6,
16247 +    DW_ATE_unsigned = 0x7,
16248 +    DW_ATE_unsigned_char = 0x8,
16249 +    /* DWARF 3.  */
16250 +    DW_ATE_imaginary_float = 0x9,
16251 +    /* HP extensions.  */
16252 +    DW_ATE_HP_float80            = 0x80, /* Floating-point (80 bit).  */
16253 +    DW_ATE_HP_complex_float80    = 0x81, /* Complex floating-point (80 bit).  */
16254 +    DW_ATE_HP_float128           = 0x82, /* Floating-point (128 bit).  */
16255 +    DW_ATE_HP_complex_float128   = 0x83, /* Complex floating-point (128 bit).  */
16256 +    DW_ATE_HP_floathpintel       = 0x84, /* Floating-point (82 bit IA64).  */
16257 +    DW_ATE_HP_imaginary_float80  = 0x85,
16258 +    DW_ATE_HP_imaginary_float128 = 0x86
16259 +  };
16260 +
16261 +#define        DW_ATE_lo_user 0x80
16262 +#define        DW_ATE_hi_user 0xff
16263 +
16264 +/* Array ordering names and codes.  */
16265 +enum dwarf_array_dim_ordering
16266 +  {
16267 +    DW_ORD_row_major = 0,
16268 +    DW_ORD_col_major = 1
16269 +  };
16270 +
16271 +/* Access attribute.  */
16272 +enum dwarf_access_attribute
16273 +  {
16274 +    DW_ACCESS_public = 1,
16275 +    DW_ACCESS_protected = 2,
16276 +    DW_ACCESS_private = 3
16277 +  };
16278 +
16279 +/* Visibility.  */
16280 +enum dwarf_visibility_attribute
16281 +  {
16282 +    DW_VIS_local = 1,
16283 +    DW_VIS_exported = 2,
16284 +    DW_VIS_qualified = 3
16285 +  };
16286 +
16287 +/* Virtuality.  */
16288 +enum dwarf_virtuality_attribute
16289 +  {
16290 +    DW_VIRTUALITY_none = 0,
16291 +    DW_VIRTUALITY_virtual = 1,
16292 +    DW_VIRTUALITY_pure_virtual = 2
16293 +  };
16294 +
16295 +/* Case sensitivity.  */
16296 +enum dwarf_id_case
16297 +  {
16298 +    DW_ID_case_sensitive = 0,
16299 +    DW_ID_up_case = 1,
16300 +    DW_ID_down_case = 2,
16301 +    DW_ID_case_insensitive = 3
16302 +  };
16303 +
16304 +/* Calling convention.  */
16305 +enum dwarf_calling_convention
16306 +  {
16307 +    DW_CC_normal = 0x1,
16308 +    DW_CC_program = 0x2,
16309 +    DW_CC_nocall = 0x3
16310 +  };
16311 +
16312 +#define DW_CC_lo_user 0x40
16313 +#define DW_CC_hi_user 0xff
16314 +
16315 +/* Inline attribute.  */
16316 +enum dwarf_inline_attribute
16317 +  {
16318 +    DW_INL_not_inlined = 0,
16319 +    DW_INL_inlined = 1,
16320 +    DW_INL_declared_not_inlined = 2,
16321 +    DW_INL_declared_inlined = 3
16322 +  };
16323 +
16324 +/* Discriminant lists.  */
16325 +enum dwarf_discrim_list
16326 +  {
16327 +    DW_DSC_label = 0,
16328 +    DW_DSC_range = 1
16329 +  };
16330 +
16331 +/* Line number opcodes.  */
16332 +enum dwarf_line_number_ops
16333 +  {
16334 +    DW_LNS_extended_op = 0,
16335 +    DW_LNS_copy = 1,
16336 +    DW_LNS_advance_pc = 2,
16337 +    DW_LNS_advance_line = 3,
16338 +    DW_LNS_set_file = 4,
16339 +    DW_LNS_set_column = 5,
16340 +    DW_LNS_negate_stmt = 6,
16341 +    DW_LNS_set_basic_block = 7,
16342 +    DW_LNS_const_add_pc = 8,
16343 +    DW_LNS_fixed_advance_pc = 9,
16344 +    /* DWARF 3.  */
16345 +    DW_LNS_set_prologue_end = 10,
16346 +    DW_LNS_set_epilogue_begin = 11,
16347 +    DW_LNS_set_isa = 12
16348 +  };
16349 +
16350 +/* Line number extended opcodes.  */
16351 +enum dwarf_line_number_x_ops
16352 +  {
16353 +    DW_LNE_end_sequence = 1,
16354 +    DW_LNE_set_address = 2,
16355 +    DW_LNE_define_file = 3,
16356 +    /* HP extensions.  */
16357 +    DW_LNE_HP_negate_is_UV_update      = 0x11,
16358 +    DW_LNE_HP_push_context             = 0x12,
16359 +    DW_LNE_HP_pop_context              = 0x13,
16360 +    DW_LNE_HP_set_file_line_column     = 0x14,
16361 +    DW_LNE_HP_set_routine_name         = 0x15,
16362 +    DW_LNE_HP_set_sequence             = 0x16,
16363 +    DW_LNE_HP_negate_post_semantics    = 0x17,
16364 +    DW_LNE_HP_negate_function_exit     = 0x18,
16365 +    DW_LNE_HP_negate_front_end_logical = 0x19,
16366 +    DW_LNE_HP_define_proc              = 0x20
16367 +  };
16368 +
16369 +/* Call frame information.  */
16370 +enum dwarf_call_frame_info
16371 +  {
16372 +    DW_CFA_advance_loc = 0x40,
16373 +    DW_CFA_offset = 0x80,
16374 +    DW_CFA_restore = 0xc0,
16375 +    DW_CFA_nop = 0x00,
16376 +    DW_CFA_set_loc = 0x01,
16377 +    DW_CFA_advance_loc1 = 0x02,
16378 +    DW_CFA_advance_loc2 = 0x03,
16379 +    DW_CFA_advance_loc4 = 0x04,
16380 +    DW_CFA_offset_extended = 0x05,
16381 +    DW_CFA_restore_extended = 0x06,
16382 +    DW_CFA_undefined = 0x07,
16383 +    DW_CFA_same_value = 0x08,
16384 +    DW_CFA_register = 0x09,
16385 +    DW_CFA_remember_state = 0x0a,
16386 +    DW_CFA_restore_state = 0x0b,
16387 +    DW_CFA_def_cfa = 0x0c,
16388 +    DW_CFA_def_cfa_register = 0x0d,
16389 +    DW_CFA_def_cfa_offset = 0x0e,
16390 +    /* DWARF 3.  */
16391 +    DW_CFA_def_cfa_expression = 0x0f,
16392 +    DW_CFA_expression = 0x10,
16393 +    DW_CFA_offset_extended_sf = 0x11,
16394 +    DW_CFA_def_cfa_sf = 0x12,
16395 +    DW_CFA_def_cfa_offset_sf = 0x13,
16396 +    /* SGI/MIPS specific.  */
16397 +    DW_CFA_MIPS_advance_loc8 = 0x1d,
16398 +    /* GNU extensions.  */
16399 +    DW_CFA_GNU_window_save = 0x2d,
16400 +    DW_CFA_GNU_args_size = 0x2e,
16401 +    DW_CFA_GNU_negative_offset_extended = 0x2f
16402 +  };
16403 +
16404 +#define DW_CIE_ID        0xffffffff
16405 +#define DW_CIE_VERSION   1
16406 +
16407 +#define DW_CFA_extended   0
16408 +#define DW_CFA_lo_user    0x1c
16409 +#define DW_CFA_hi_user    0x3f
16410 +
16411 +#define DW_CHILDREN_no              0x00
16412 +#define DW_CHILDREN_yes                     0x01
16413 +
16414 +#define DW_ADDR_none           0
16415 +
16416 +/* Source language names and codes.  */
16417 +enum dwarf_source_language
16418 +  {
16419 +    DW_LANG_C89 = 0x0001,
16420 +    DW_LANG_C = 0x0002,
16421 +    DW_LANG_Ada83 = 0x0003,
16422 +    DW_LANG_C_plus_plus = 0x0004,
16423 +    DW_LANG_Cobol74 = 0x0005,
16424 +    DW_LANG_Cobol85 = 0x0006,
16425 +    DW_LANG_Fortran77 = 0x0007,
16426 +    DW_LANG_Fortran90 = 0x0008,
16427 +    DW_LANG_Pascal83 = 0x0009,
16428 +    DW_LANG_Modula2 = 0x000a,
16429 +    DW_LANG_Java = 0x000b,
16430 +    /* DWARF 3.  */
16431 +    DW_LANG_C99 = 0x000c,
16432 +    DW_LANG_Ada95 = 0x000d,
16433 +    DW_LANG_Fortran95 = 0x000e,
16434 +    /* MIPS.  */
16435 +    DW_LANG_Mips_Assembler = 0x8001,
16436 +    /* UPC.  */
16437 +    DW_LANG_Upc = 0x8765
16438 +  };
16439 +
16440 +#define DW_LANG_lo_user 0x8000 /* Implementation-defined range start.  */
16441 +#define DW_LANG_hi_user 0xffff /* Implementation-defined range start.  */
16442 +
16443 +/* Names and codes for macro information.  */
16444 +enum dwarf_macinfo_record_type
16445 +  {
16446 +    DW_MACINFO_define = 1,
16447 +    DW_MACINFO_undef = 2,
16448 +    DW_MACINFO_start_file = 3,
16449 +    DW_MACINFO_end_file = 4,
16450 +    DW_MACINFO_vendor_ext = 255
16451 +  };
16452 +\f
16453 +/* @@@ For use with GNU frame unwind information.  */
16454 +
16455 +#define DW_EH_PE_absptr                0x00
16456 +#define DW_EH_PE_omit          0xff
16457 +
16458 +#define DW_EH_PE_uleb128       0x01
16459 +#define DW_EH_PE_udata2                0x02
16460 +#define DW_EH_PE_udata4                0x03
16461 +#define DW_EH_PE_udata8                0x04
16462 +#define DW_EH_PE_sleb128       0x09
16463 +#define DW_EH_PE_sdata2                0x0A
16464 +#define DW_EH_PE_sdata4                0x0B
16465 +#define DW_EH_PE_sdata8                0x0C
16466 +#define DW_EH_PE_signed                0x08
16467 +
16468 +#define DW_EH_PE_pcrel         0x10
16469 +#define DW_EH_PE_textrel       0x20
16470 +#define DW_EH_PE_datarel       0x30
16471 +#define DW_EH_PE_funcrel       0x40
16472 +#define DW_EH_PE_aligned       0x50
16473 +
16474 +#define DW_EH_PE_indirect      0x80
16475 +
16476 +#endif /* _ELF_DWARF2_H */
16477 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/linux/kgdb.h linux-2.6.18-53.1.14.kgdb/include/linux/kgdb.h
16478 --- linux-2.6.18-53.1.14/include/linux/kgdb.h   1970-01-01 03:00:00.000000000 +0300
16479 +++ linux-2.6.18-53.1.14.kgdb/include/linux/kgdb.h      2008-06-10 15:39:21.000000000 +0400
16480 @@ -0,0 +1,279 @@
16481 +/*
16482 + * include/linux/kgdb.h
16483 + *
16484 + * This provides the hooks and functions that KGDB needs to share between
16485 + * the core, I/O and arch-specific portions.
16486 + *
16487 + * Author: Amit Kale <amitkale@linsyssoft.com> and
16488 + *         Tom Rini <trini@kernel.crashing.org>
16489 + *
16490 + * 2001-2004 (c) Amit S. Kale and 2003-2005 (c) MontaVista Software, Inc.
16491 + * This file is licensed under the terms of the GNU General Public License
16492 + * version 2. This program is licensed "as is" without any warranty of any
16493 + * kind, whether express or implied.
16494 + */
16495 +#ifdef __KERNEL__
16496 +#ifndef _KGDB_H_
16497 +#define _KGDB_H_
16498 +
16499 +#include <asm/atomic.h>
16500 +
16501 +#ifdef CONFIG_KGDB
16502 +#include <asm/kgdb.h>
16503 +#include <linux/serial_8250.h>
16504 +#include <linux/linkage.h>
16505 +#include <linux/init.h>
16506 +
16507 +#ifndef CHECK_EXCEPTION_STACK
16508 +#define CHECK_EXCEPTION_STACK()        1
16509 +#endif
16510 +
16511 +struct tasklet_struct;
16512 +struct pt_regs;
16513 +struct task_struct;
16514 +struct uart_port;
16515 +
16516 +#ifdef CONFIG_KGDB_CONSOLE
16517 +extern struct console kgdbcons;
16518 +#endif
16519 +
16520 +/* To enter the debugger explicitly. */
16521 +extern void breakpoint(void);
16522 +extern int kgdb_connected;
16523 +extern int kgdb_may_fault;
16524 +extern struct tasklet_struct kgdb_tasklet_breakpoint;
16525 +
16526 +extern atomic_t kgdb_setting_breakpoint;
16527 +extern atomic_t cpu_doing_single_step;
16528 +extern atomic_t kgdb_sync_softlockup[NR_CPUS];
16529 +
16530 +extern struct task_struct *kgdb_usethread, *kgdb_contthread;
16531 +
16532 +enum kgdb_bptype {
16533 +       bp_breakpoint = '0',
16534 +       bp_hardware_breakpoint,
16535 +       bp_write_watchpoint,
16536 +       bp_read_watchpoint,
16537 +       bp_access_watchpoint
16538 +};
16539 +
16540 +enum kgdb_bpstate {
16541 +       bp_none = 0,
16542 +       bp_removed,
16543 +       bp_set,
16544 +       bp_active
16545 +};
16546 +
16547 +struct kgdb_bkpt {
16548 +       unsigned long bpt_addr;
16549 +       unsigned char saved_instr[BREAK_INSTR_SIZE];
16550 +       enum kgdb_bptype type;
16551 +       enum kgdb_bpstate state;
16552 +};
16553 +
16554 +/* The maximum number of KGDB I/O modules that can be loaded */
16555 +#define MAX_KGDB_IO_HANDLERS 3
16556 +
16557 +#ifndef MAX_BREAKPOINTS
16558 +#define MAX_BREAKPOINTS                1000
16559 +#endif
16560 +
16561 +#define KGDB_HW_BREAKPOINT     1
16562 +
16563 +/* Required functions. */
16564 +/**
16565 + *     regs_to_gdb_regs - Convert ptrace regs to GDB regs
16566 + *     @gdb_regs: A pointer to hold the registers in the order GDB wants.
16567 + *     @regs: The &struct pt_regs of the current process.
16568 + *
16569 + *     Convert the pt_regs in @regs into the format for registers that
16570 + *     GDB expects, stored in @gdb_regs.
16571 + */
16572 +extern void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs);
16573 +
16574 +/**
16575 + *     sleeping_regs_to_gdb_regs - Convert ptrace regs to GDB regs
16576 + *     @gdb_regs: A pointer to hold the registers in the order GDB wants.
16577 + *     @p: The &struct task_struct of the desired process.
16578 + *
16579 + *     Convert the register values of the sleeping process in @p to
16580 + *     the format that GDB expects.
16581 + *     This function is called when kgdb does not have access to the
16582 + *     &struct pt_regs and therefore it should fill the gdb registers
16583 + *     @gdb_regs with what has been saved in &struct thread_struct
16584 + *     thread field during switch_to.
16585 + */
16586 +extern void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs,
16587 +                                       struct task_struct *p);
16588 +
16589 +/**
16590 + *     gdb_regs_to_regs - Convert GDB regs to ptrace regs.
16591 + *     @gdb_regs: A pointer to hold the registers we've recieved from GDB.
16592 + *     @regs: A pointer to a &struct pt_regs to hold these values in.
16593 + *
16594 + *     Convert the GDB regs in @gdb_regs into the pt_regs, and store them
16595 + *     in @regs.
16596 + */
16597 +extern void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs);
16598 +
16599 +/**
16600 + *     kgdb_arch_handle_exception - Handle architecture specific GDB packets.
16601 + *     @vector: The error vector of the exception that happened.
16602 + *     @signo: The signal number of the exception that happened.
16603 + *     @err_code: The error code of the exception that happened.
16604 + *     @remcom_in_buffer: The buffer of the packet we have read.
16605 + *     @remcom_out_buffer: The buffer, of %BUFMAX to write a packet into.
16606 + *     @regs: The &struct pt_regs of the current process.
16607 + *
16608 + *     This function MUST handle the 'c' and 's' command packets,
16609 + *     as well packets to set / remove a hardware breakpoint, if used.
16610 + *     If there are additional packets which the hardware needs to handle,
16611 + *     they are handled here.  The code should return -1 if it wants to
16612 + *     process more packets, and a %0 or %1 if it wants to exit from the
16613 + *     kgdb hook.
16614 + */
16615 +extern int kgdb_arch_handle_exception(int vector, int signo, int err_code,
16616 +                                     char *remcom_in_buffer,
16617 +                                     char *remcom_out_buffer,
16618 +                                     struct pt_regs *regs);
16619 +
16620 +#ifndef JMP_REGS_ALIGNMENT
16621 +#define JMP_REGS_ALIGNMENT
16622 +#endif
16623 +
16624 +extern unsigned long kgdb_fault_jmp_regs[];
16625 +
16626 +/**
16627 + *     kgdb_fault_setjmp - Store state in case we fault.
16628 + *     @curr_context: An array to store state into.
16629 + *
16630 + *     Certain functions may try and access memory, and in doing so may
16631 + *     cause a fault.  When this happens, we trap it, restore state to
16632 + *     this call, and let ourself know that something bad has happened.
16633 + */
16634 +extern asmlinkage int kgdb_fault_setjmp(unsigned long *curr_context);
16635 +
16636 +/**
16637 + *     kgdb_fault_longjmp - Restore state when we have faulted.
16638 + *     @curr_context: The previously stored state.
16639 + *
16640 + *     When something bad does happen, this function is called to
16641 + *     restore the known good state, and set the return value to 1, so
16642 + *     we know something bad happened.
16643 + */
16644 +extern asmlinkage void kgdb_fault_longjmp(unsigned long *curr_context);
16645 +
16646 +/* Optional functions. */
16647 +extern int kgdb_arch_init(void);
16648 +extern void kgdb_disable_hw_debug(struct pt_regs *regs);
16649 +extern void kgdb_post_master_code(struct pt_regs *regs, int e_vector,
16650 +                                 int err_code);
16651 +extern void kgdb_roundup_cpus(unsigned long flags);
16652 +extern int kgdb_set_hw_break(unsigned long addr);
16653 +extern int kgdb_remove_hw_break(unsigned long addr);
16654 +extern void kgdb_remove_all_hw_break(void);
16655 +extern void kgdb_correct_hw_break(void);
16656 +extern void kgdb_shadowinfo(struct pt_regs *regs, char *buffer,
16657 +                           unsigned threadid);
16658 +extern struct task_struct *kgdb_get_shadow_thread(struct pt_regs *regs,
16659 +                                                 int threadid);
16660 +extern struct pt_regs *kgdb_shadow_regs(struct pt_regs *regs, int threadid);
16661 +extern int kgdb_validate_break_address(unsigned long addr);
16662 +extern int kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr);
16663 +extern int kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle);
16664 +
16665 +/**
16666 + * struct kgdb_arch - Desribe architecture specific values.
16667 + * @gdb_bpt_instr: The instruction to trigger a breakpoint.
16668 + * @flags: Flags for the breakpoint, currently just %KGDB_HW_BREAKPOINT.
16669 + * @shadowth: A value of %1 indicates we shadow information on processes.
16670 + * @set_breakpoint: Allow an architecture to specify how to set a software
16671 + * breakpoint.
16672 + * @remove_breakpoint: Allow an architecture to specify how to remove a
16673 + * software breakpoint.
16674 + * @set_hw_breakpoint: Allow an architecture to specify how to set a hardware
16675 + * breakpoint.
16676 + * @remove_hw_breakpoint: Allow an architecture to specify how to remove a
16677 + * hardware breakpoint.
16678 + *
16679 + * The @shadowth flag is an option to shadow information not retrievable by
16680 + * gdb otherwise.  This is deprecated in favor of a binutils which supports
16681 + * CFI macros.
16682 + */
16683 +struct kgdb_arch {
16684 +       unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
16685 +       unsigned long flags;
16686 +       unsigned shadowth;
16687 +       int (*set_breakpoint) (unsigned long, char *);
16688 +       int (*remove_breakpoint)(unsigned long, char *);
16689 +       int (*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
16690 +       int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
16691 +};
16692 +
16693 +/* Thread reference */
16694 +typedef unsigned char threadref[8];
16695 +
16696 +/**
16697 + * struct kgdb_io - Desribe the interface for an I/O driver to talk with KGDB.
16698 + * @read_char: Pointer to a function that will return one char.
16699 + * @write_char: Pointer to a function that will write one char.
16700 + * @flush: Pointer to a function that will flush any pending writes.
16701 + * @init: Pointer to a function that will initialize the device.
16702 + * @late_init: Pointer to a function that will do any setup that has
16703 + * other dependencies.
16704 + * @pre_exception: Pointer to a function that will do any prep work for
16705 + * the I/O driver.
16706 + * @post_exception: Pointer to a function that will do any cleanup work
16707 + * for the I/O driver.
16708 + *
16709 + * The @init and @late_init function pointers allow for an I/O driver
16710 + * such as a serial driver to fully initialize the port with @init and
16711 + * be called very early, yet safely call request_irq() later in the boot
16712 + * sequence.
16713 + *
16714 + * @init is allowed to return a non-0 return value to indicate failure.
16715 + * If this is called early on, then KGDB will try again when it would call
16716 + * @late_init.  If it has failed later in boot as well, the user will be
16717 + * notified.
16718 + */
16719 +struct kgdb_io {
16720 +       int (*read_char) (void);
16721 +       void (*write_char) (u8);
16722 +       void (*flush) (void);
16723 +       int (*init) (void);
16724 +       void (*late_init) (void);
16725 +       void (*pre_exception) (void);
16726 +       void (*post_exception) (void);
16727 +};
16728 +
16729 +extern struct kgdb_io kgdb_io_ops;
16730 +extern struct kgdb_arch arch_kgdb_ops;
16731 +extern int kgdb_initialized;
16732 +
16733 +extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
16734 +extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
16735 +
16736 +extern void __init kgdb8250_add_port(int i, struct uart_port *serial_req);
16737 +extern void __init kgdb8250_add_platform_port(int i, struct plat_serial8250_port *serial_req);
16738 +
16739 +extern int kgdb_hex2long(char **ptr, long *long_val);
16740 +extern char *kgdb_mem2hex(char *mem, char *buf, int count);
16741 +extern char *kgdb_hex2mem(char *buf, char *mem, int count);
16742 +extern int kgdb_get_mem(char *addr, unsigned char *buf, int count);
16743 +extern int kgdb_set_mem(char *addr, unsigned char *buf, int count);
16744 +
16745 +int kgdb_isremovedbreak(unsigned long addr);
16746 +int kgdb_skipexception(int exception, struct pt_regs *regs);
16747 +
16748 +extern int kgdb_handle_exception(int ex_vector, int signo, int err_code,
16749 +                               struct pt_regs *regs);
16750 +extern void kgdb_nmihook(int cpu, void *regs);
16751 +extern int debugger_step;
16752 +extern atomic_t debugger_active;
16753 +extern struct kgdb_arch *kgdb_ops;
16754 +#else
16755 +/* Stubs for when KGDB is not set. */
16756 +static const atomic_t debugger_active = ATOMIC_INIT(0);
16757 +#endif                         /* CONFIG_KGDB */
16758 +#endif                         /* _KGDB_H_ */
16759 +#endif                         /* __KERNEL__ */
16760 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/linux/module.h linux-2.6.18-53.1.14.kgdb/include/linux/module.h
16761 --- linux-2.6.18-53.1.14/include/linux/module.h 2008-03-06 05:54:41.000000000 +0300
16762 +++ linux-2.6.18-53.1.14.kgdb/include/linux/module.h    2008-06-10 15:39:15.000000000 +0400
16763 @@ -229,8 +229,17 @@ enum module_state
16764         MODULE_STATE_LIVE,
16765         MODULE_STATE_COMING,
16766         MODULE_STATE_GOING,
16767 +       MODULE_STATE_GONE,
16768  };
16769  
16770 +#ifdef CONFIG_KGDB
16771 +#define MAX_SECTNAME 31
16772 +struct mod_section {
16773 +       void *address;
16774 +       char name[MAX_SECTNAME + 1];
16775 +};
16776 +#endif
16777 +
16778  /* Similar stuff for section attributes. */
16779  #define MODULE_SECT_NAME_LEN 32
16780  struct module_sect_attr
16781 @@ -258,6 +267,13 @@ struct module
16782         /* Unique handle for this module */
16783         char name[MODULE_NAME_LEN];
16784  
16785 +#ifdef CONFIG_KGDB
16786 +       /* keep kgdb info at the begining so that gdb doesn't have a chance to
16787 +        * miss out any fields */
16788 +       unsigned long num_sections;
16789 +       struct mod_section *mod_sections;
16790 +#endif
16791 +
16792         /* Sysfs stuff. */
16793         struct module_kobject mkobj;
16794         struct module_param_attrs *param_attrs;
16795 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/linux/netpoll.h linux-2.6.18-53.1.14.kgdb/include/linux/netpoll.h
16796 --- linux-2.6.18-53.1.14/include/linux/netpoll.h        2006-09-20 07:42:06.000000000 +0400
16797 +++ linux-2.6.18-53.1.14.kgdb/include/linux/netpoll.h   2008-06-10 15:37:49.000000000 +0400
16798 @@ -17,7 +17,7 @@ struct netpoll;
16799  struct netpoll {
16800         struct net_device *dev;
16801         char dev_name[16], *name;
16802 -       void (*rx_hook)(struct netpoll *, int, char *, int);
16803 +       void (*rx_hook)(struct netpoll *, int, char *, int, struct sk_buff *);
16804         void (*drop)(struct sk_buff *skb);
16805         u32 local_ip, remote_ip;
16806         u16 local_port, remote_port;
16807 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/include/linux/serial_8250.h linux-2.6.18-53.1.14.kgdb/include/linux/serial_8250.h
16808 --- linux-2.6.18-53.1.14/include/linux/serial_8250.h    2006-09-20 07:42:06.000000000 +0400
16809 +++ linux-2.6.18-53.1.14.kgdb/include/linux/serial_8250.h       2008-06-10 15:37:43.000000000 +0400
16810 @@ -56,6 +56,7 @@ struct uart_port;
16811  
16812  int serial8250_register_port(struct uart_port *);
16813  void serial8250_unregister_port(int line);
16814 +void serial8250_unregister_by_port(struct uart_port *port);
16815  void serial8250_suspend_port(int line);
16816  void serial8250_resume_port(int line);
16817  
16818 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/kernel/Makefile linux-2.6.18-53.1.14.kgdb/kernel/Makefile
16819 --- linux-2.6.18-53.1.14/kernel/Makefile        2008-03-06 05:54:50.000000000 +0300
16820 +++ linux-2.6.18-53.1.14.kgdb/kernel/Makefile   2008-06-10 15:37:25.000000000 +0400
16821 @@ -42,6 +42,7 @@ obj-$(CONFIG_STOP_MACHINE) += stop_machi
16822  obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
16823  obj-$(CONFIG_AUDITSYSCALL) += auditsc.o audit_tree.o
16824  obj-$(CONFIG_KPROBES) += kprobes.o
16825 +obj-$(CONFIG_KGDB) += kgdb.o kgdbarchlib.o
16826  obj-$(CONFIG_SYSFS) += ksysfs.o
16827  obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
16828  obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
16829 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/kernel/kgdb.c linux-2.6.18-53.1.14.kgdb/kernel/kgdb.c
16830 --- linux-2.6.18-53.1.14/kernel/kgdb.c  1970-01-01 03:00:00.000000000 +0300
16831 +++ linux-2.6.18-53.1.14.kgdb/kernel/kgdb.c     2008-06-10 15:39:21.000000000 +0400
16832 @@ -0,0 +1,1778 @@
16833 +/*
16834 + * kernel/kgdb.c
16835 + *
16836 + * Maintainer: Tom Rini <trini@kernel.crashing.org>
16837 + *
16838 + * Copyright (C) 2000-2001 VERITAS Software Corporation.
16839 + * Copyright (C) 2002-2004 Timesys Corporation
16840 + * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com>
16841 + * Copyright (C) 2004 Pavel Machek <pavel@suse.cz>
16842 + * Copyright (C) 2004-2005 Tom Rini <trini@kernel.crashing.org>
16843 + * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd.
16844 + * Copyright (C) 2005 Wind River Systems, Inc.
16845 + *
16846 + * Contributors at various stages not listed above:
16847 + *  Jason Wessel ( jason.wessel@windriver.com )
16848 + *  George Anzinger <george@mvista.com>
16849 + *  Anurekh Saxena (anurekh.saxena@timesys.com)
16850 + *  Lake Stevens Instrument Division (Glenn Engel)
16851 + *  Jim Kingdon, Cygnus Support.
16852 + *
16853 + * Original KGDB stub: David Grothe <dave@gcom.com>,
16854 + * Tigran Aivazian <tigran@sco.com>
16855 + *
16856 + * This file is licensed under the terms of the GNU General Public License
16857 + * version 2. This program is licensed "as is" without any warranty of any
16858 + * kind, whether express or implied.
16859 + */
16860 +
16861 +#include <linux/string.h>
16862 +#include <linux/kernel.h>
16863 +#include <linux/interrupt.h>
16864 +#include <linux/sched.h>
16865 +#include <linux/smp.h>
16866 +#include <linux/spinlock.h>
16867 +#include <linux/delay.h>
16868 +#include <linux/mm.h>
16869 +#include <linux/threads.h>
16870 +#include <linux/reboot.h>
16871 +#include <asm/system.h>
16872 +#include <asm/ptrace.h>
16873 +#include <asm/uaccess.h>
16874 +#include <linux/kgdb.h>
16875 +#include <asm/atomic.h>
16876 +#include <linux/notifier.h>
16877 +#include <linux/module.h>
16878 +#include <asm/cacheflush.h>
16879 +#include <linux/init.h>
16880 +#include <linux/sysrq.h>
16881 +#include <linux/console.h>
16882 +#include <linux/sched.h>
16883 +#include <asm/byteorder.h>
16884 +
16885 +extern int pid_max;
16886 +/* How many times to count all of the waiting CPUs */
16887 +#define ROUNDUP_WAIT           640000  /* Arbitrary, increase if needed. */
16888 +#define BUF_THREAD_ID_SIZE     16
16889 +
16890 +/*
16891 + * kgdb_initialized with a value of 1 indicates that kgdb is setup and is
16892 + * all ready to serve breakpoints and other kernel exceptions.  A value of
16893 + * -1 indicates that we have tried to initialize early, and need to try
16894 + * again later.
16895 + */
16896 +int kgdb_initialized;
16897 +/* Is a host GDB connected to us? */
16898 +int kgdb_connected;
16899 +/* Could we be about to try and access a bad memory location? If so we
16900 + * also need to flag this has happend. */
16901 +int kgdb_may_fault;
16902 +/* All the KGDB handlers are installed */
16903 +int kgdb_from_module_registered = 0;
16904 +
16905 +/* We provide a kgdb_io_ops structure that may be overriden. */
16906 +struct kgdb_io __attribute__ ((weak)) kgdb_io_ops;
16907 +
16908 +static struct kgdb_io kgdb_io_ops_prev[MAX_KGDB_IO_HANDLERS];
16909 +static int kgdb_io_handler_cnt = 0;
16910 +
16911 +/* Export the following symbols for use with kernel modules */
16912 +EXPORT_SYMBOL(kgdb_io_ops);
16913 +EXPORT_SYMBOL(kgdb_tasklet_breakpoint);
16914 +EXPORT_SYMBOL(kgdb_connected);
16915 +EXPORT_SYMBOL(kgdb_register_io_module);
16916 +EXPORT_SYMBOL(kgdb_unregister_io_module);
16917 +EXPORT_SYMBOL(debugger_active);
16918 +
16919 +/*
16920 + * Holds information about breakpoints in a kernel. These breakpoints are
16921 + * added and removed by gdb.
16922 + */
16923 +struct kgdb_bkpt kgdb_break[MAX_BREAKPOINTS];
16924 +
16925 +static const char hexchars[] = "0123456789abcdef";
16926 +
16927 +static spinlock_t slavecpulocks[NR_CPUS];
16928 +static atomic_t procindebug[NR_CPUS];
16929 +atomic_t kgdb_setting_breakpoint;
16930 +EXPORT_SYMBOL(kgdb_setting_breakpoint);
16931 +struct task_struct *kgdb_usethread, *kgdb_contthread;
16932 +
16933 +int debugger_step;
16934 +atomic_t debugger_active;
16935 +
16936 +/* Our I/O buffers. */
16937 +static char remcom_in_buffer[BUFMAX];
16938 +static char remcom_out_buffer[BUFMAX];
16939 +/* Storage for the registers, in GDB format. */
16940 +static unsigned long gdb_regs[(NUMREGBYTES + sizeof(unsigned long) - 1) /
16941 +                             sizeof(unsigned long)];
16942 +/* Storage of registers for handling a fault. */
16943 +unsigned long kgdb_fault_jmp_regs[NUMCRITREGBYTES / sizeof(unsigned long)]
16944 + JMP_REGS_ALIGNMENT;
16945 +static int kgdb_notify_reboot(struct notifier_block *this,
16946 +                               unsigned long code ,void *x);
16947 +struct debuggerinfo_struct {
16948 +       void *debuggerinfo;
16949 +       struct task_struct *task;
16950 +} kgdb_info[NR_CPUS];
16951 +
16952 +/* to keep track of the CPU which is doing the single stepping*/
16953 +atomic_t cpu_doing_single_step = ATOMIC_INIT(-1);
16954 +
16955 +atomic_t  kgdb_sync_softlockup[NR_CPUS] = {ATOMIC_INIT(0)};
16956 +
16957 +/* reboot notifier block */
16958 +static struct notifier_block kgdb_reboot_notifier = {
16959 +       .notifier_call  = kgdb_notify_reboot,
16960 +       .next           = NULL,
16961 +       .priority       = INT_MAX,
16962 +};
16963 +
16964 +static int hex(char ch)
16965 +{
16966 +       if ((ch >= 'a') && (ch <= 'f'))
16967 +               return (ch - 'a' + 10);
16968 +       if ((ch >= '0') && (ch <= '9'))
16969 +               return (ch - '0');
16970 +       if ((ch >= 'A') && (ch <= 'F'))
16971 +               return (ch - 'A' + 10);
16972 +       return (-1);
16973 +}
16974 +
16975 +/* scan for the sequence $<data>#<checksum>    */
16976 +static void get_packet(char *buffer)
16977 +{
16978 +       unsigned char checksum;
16979 +       unsigned char xmitcsum;
16980 +       int count;
16981 +       char ch;
16982 +       if (!kgdb_io_ops.read_char)
16983 +               return;
16984 +       do {
16985 +               /* Spin and wait around for the start character, ignore all
16986 +                * other characters */
16987 +               while ((ch = (kgdb_io_ops.read_char())) != '$') ;
16988 +               kgdb_connected = 1;
16989 +               checksum = 0;
16990 +               xmitcsum = -1;
16991 +
16992 +               count = 0;
16993 +
16994 +               /* now, read until a # or end of buffer is found */
16995 +               while (count < (BUFMAX - 1)) {
16996 +                       ch = kgdb_io_ops.read_char();
16997 +                       if (ch == '#')
16998 +                               break;
16999 +                       checksum = checksum + ch;
17000 +                       buffer[count] = ch;
17001 +                       count = count + 1;
17002 +               }
17003 +               buffer[count] = 0;
17004 +
17005 +               if (ch == '#') {
17006 +                       xmitcsum = hex(kgdb_io_ops.read_char()) << 4;
17007 +                       xmitcsum += hex(kgdb_io_ops.read_char());
17008 +
17009 +                       if (checksum != xmitcsum)
17010 +                               /* failed checksum */
17011 +                               kgdb_io_ops.write_char('-');
17012 +                       else
17013 +                               /* successful transfer */
17014 +                               kgdb_io_ops.write_char('+');
17015 +                       if (kgdb_io_ops.flush)
17016 +                               kgdb_io_ops.flush();
17017 +               }
17018 +       } while (checksum != xmitcsum);
17019 +}
17020 +
17021 +/*
17022 + * Send the packet in buffer.
17023 + * Check for gdb connection if asked for.
17024 + */
17025 +static void put_packet(char *buffer)
17026 +{
17027 +       unsigned char checksum;
17028 +       int count;
17029 +       char ch;
17030 +
17031 +       if (!kgdb_io_ops.write_char)
17032 +               return;
17033 +       /* $<packet info>#<checksum>. */
17034 +       while (1) {
17035 +               kgdb_io_ops.write_char('$');
17036 +               checksum = 0;
17037 +               count = 0;
17038 +
17039 +               while ((ch = buffer[count])) {
17040 +                       kgdb_io_ops.write_char(ch);
17041 +                       checksum += ch;
17042 +                       count++;
17043 +               }
17044 +
17045 +               kgdb_io_ops.write_char('#');
17046 +               kgdb_io_ops.write_char(hexchars[checksum >> 4]);
17047 +               kgdb_io_ops.write_char(hexchars[checksum % 16]);
17048 +               if (kgdb_io_ops.flush)
17049 +                       kgdb_io_ops.flush();
17050 +
17051 +               /* Now see what we get in reply. */
17052 +               ch = kgdb_io_ops.read_char();
17053 +
17054 +               if (ch == 3)
17055 +                       ch = kgdb_io_ops.read_char();
17056 +
17057 +               /* If we get an ACK, we are done. */
17058 +               if (ch == '+')
17059 +                       return;
17060 +
17061 +               /* If we get the start of another packet, this means
17062 +                * that GDB is attempting to reconnect.  We will NAK
17063 +                * the packet being sent, and stop trying to send this
17064 +                * packet. */
17065 +               if (ch == '$') {
17066 +                       kgdb_io_ops.write_char('-');
17067 +                       if (kgdb_io_ops.flush)
17068 +                               kgdb_io_ops.flush();
17069 +                       return;
17070 +               }
17071 +       }
17072 +}
17073 +
17074 +/*
17075 + * convert the memory pointed to by mem into hex, placing result in buf
17076 + * return a pointer to the last char put in buf (null). May return an error.
17077 + */
17078 +char *kgdb_mem2hex(char *mem, char *buf, int count)
17079 +{
17080 +       kgdb_may_fault = 1;
17081 +       if ((kgdb_fault_setjmp(kgdb_fault_jmp_regs)) != 0) {
17082 +               kgdb_may_fault = 0;
17083 +               return ERR_PTR(-EINVAL);
17084 +       }
17085 +       /* Accessing some registers in a single load instruction is
17086 +        * required to avoid bad side effects for some I/O registers.
17087 +        */
17088 +       if ((count == 2) && (((long)mem & 1) == 0)) {
17089 +               unsigned short tmp_s = *(unsigned short *)mem;
17090 +               mem += 2;
17091 +#ifdef __BIG_ENDIAN
17092 +               *buf++ = hexchars[(tmp_s >> 12) & 0xf];
17093 +               *buf++ = hexchars[(tmp_s >> 8) & 0xf];
17094 +               *buf++ = hexchars[(tmp_s >> 4) & 0xf];
17095 +               *buf++ = hexchars[tmp_s & 0xf];
17096 +#else
17097 +               *buf++ = hexchars[(tmp_s >> 4) & 0xf];
17098 +               *buf++ = hexchars[tmp_s & 0xf];
17099 +               *buf++ = hexchars[(tmp_s >> 12) & 0xf];
17100 +               *buf++ = hexchars[(tmp_s >> 8) & 0xf];
17101 +#endif
17102 +       } else if ((count == 4) && (((long)mem & 3) == 0)) {
17103 +               unsigned long tmp_l = *(unsigned int *)mem;
17104 +               mem += 4;
17105 +#ifdef __BIG_ENDIAN
17106 +               *buf++ = hexchars[(tmp_l >> 28) & 0xf];
17107 +               *buf++ = hexchars[(tmp_l >> 24) & 0xf];
17108 +               *buf++ = hexchars[(tmp_l >> 20) & 0xf];
17109 +               *buf++ = hexchars[(tmp_l >> 16) & 0xf];
17110 +               *buf++ = hexchars[(tmp_l >> 12) & 0xf];
17111 +               *buf++ = hexchars[(tmp_l >> 8) & 0xf];
17112 +               *buf++ = hexchars[(tmp_l >> 4) & 0xf];
17113 +               *buf++ = hexchars[tmp_l & 0xf];
17114 +#else
17115 +               *buf++ = hexchars[(tmp_l >> 4) & 0xf];
17116 +               *buf++ = hexchars[tmp_l & 0xf];
17117 +               *buf++ = hexchars[(tmp_l >> 12) & 0xf];
17118 +               *buf++ = hexchars[(tmp_l >> 8) & 0xf];
17119 +               *buf++ = hexchars[(tmp_l >> 20) & 0xf];
17120 +               *buf++ = hexchars[(tmp_l >> 16) & 0xf];
17121 +               *buf++ = hexchars[(tmp_l >> 28) & 0xf];
17122 +               *buf++ = hexchars[(tmp_l >> 24) & 0xf];
17123 +#endif
17124 +#ifdef CONFIG_64BIT
17125 +       } else if ((count == 8) && (((long)mem & 7) == 0)) {
17126 +               unsigned long long tmp_ll = *(unsigned long long *)mem;
17127 +               mem += 8;
17128 +#ifdef __BIG_ENDIAN
17129 +               *buf++ = hexchars[(tmp_ll >> 60) & 0xf];
17130 +               *buf++ = hexchars[(tmp_ll >> 56) & 0xf];
17131 +               *buf++ = hexchars[(tmp_ll >> 52) & 0xf];
17132 +               *buf++ = hexchars[(tmp_ll >> 48) & 0xf];
17133 +               *buf++ = hexchars[(tmp_ll >> 44) & 0xf];
17134 +               *buf++ = hexchars[(tmp_ll >> 40) & 0xf];
17135 +               *buf++ = hexchars[(tmp_ll >> 36) & 0xf];
17136 +               *buf++ = hexchars[(tmp_ll >> 32) & 0xf];
17137 +               *buf++ = hexchars[(tmp_ll >> 28) & 0xf];
17138 +               *buf++ = hexchars[(tmp_ll >> 24) & 0xf];
17139 +               *buf++ = hexchars[(tmp_ll >> 20) & 0xf];
17140 +               *buf++ = hexchars[(tmp_ll >> 16) & 0xf];
17141 +               *buf++ = hexchars[(tmp_ll >> 12) & 0xf];
17142 +               *buf++ = hexchars[(tmp_ll >> 8) & 0xf];
17143 +               *buf++ = hexchars[(tmp_ll >> 4) & 0xf];
17144 +               *buf++ = hexchars[tmp_ll & 0xf];
17145 +#else
17146 +               *buf++ = hexchars[(tmp_ll >> 4) & 0xf];
17147 +               *buf++ = hexchars[tmp_ll & 0xf];
17148 +               *buf++ = hexchars[(tmp_ll >> 12) & 0xf];
17149 +               *buf++ = hexchars[(tmp_ll >> 8) & 0xf];
17150 +               *buf++ = hexchars[(tmp_ll >> 20) & 0xf];
17151 +               *buf++ = hexchars[(tmp_ll >> 16) & 0xf];
17152 +               *buf++ = hexchars[(tmp_ll >> 28) & 0xf];
17153 +               *buf++ = hexchars[(tmp_ll >> 24) & 0xf];
17154 +               *buf++ = hexchars[(tmp_ll >> 36) & 0xf];
17155 +               *buf++ = hexchars[(tmp_ll >> 32) & 0xf];
17156 +               *buf++ = hexchars[(tmp_ll >> 44) & 0xf];
17157 +               *buf++ = hexchars[(tmp_ll >> 40) & 0xf];
17158 +               *buf++ = hexchars[(tmp_ll >> 52) & 0xf];
17159 +               *buf++ = hexchars[(tmp_ll >> 48) & 0xf];
17160 +               *buf++ = hexchars[(tmp_ll >> 60) & 0xf];
17161 +               *buf++ = hexchars[(tmp_ll >> 56) & 0xf];
17162 +#endif
17163 +#endif
17164 +       } else {
17165 +               while (count-- > 0) {
17166 +                       unsigned char ch = *mem++;
17167 +                       *buf++ = hexchars[ch >> 4];
17168 +                       *buf++ = hexchars[ch & 0xf];
17169 +               }
17170 +       }
17171 +       kgdb_may_fault = 0;
17172 +       *buf = 0;
17173 +       return (buf);
17174 +}
17175 +
17176 +/*
17177 + * Copy the binary array pointed to by buf into mem.  Fix $, #, and
17178 + * 0x7d escaped with 0x7d.  Return a pointer to the character after
17179 + * the last byte written.
17180 + */
17181 +static char *kgdb_ebin2mem(char *buf, char *mem, int count)
17182 +{
17183 +       kgdb_may_fault = 1;
17184 +       if ((kgdb_fault_setjmp(kgdb_fault_jmp_regs)) != 0) {
17185 +               kgdb_may_fault = 0;
17186 +               return ERR_PTR(-EINVAL);
17187 +       }
17188 +       for (; count > 0; count--, buf++) {
17189 +               if (*buf == 0x7d)
17190 +                       *mem++ = *(++buf) ^ 0x20;
17191 +               else
17192 +                       *mem++ = *buf;
17193 +       }
17194 +       kgdb_may_fault = 0;
17195 +       return mem;
17196 +}
17197 +
17198 +/*
17199 + * convert the hex array pointed to by buf into binary to be placed in mem
17200 + * return a pointer to the character AFTER the last byte written
17201 + * May return an error.
17202 + */
17203 +char *kgdb_hex2mem(char *buf, char *mem, int count)
17204 +{
17205 +       kgdb_may_fault = 1;
17206 +       if ((kgdb_fault_setjmp(kgdb_fault_jmp_regs)) != 0) {
17207 +               kgdb_may_fault = 0;
17208 +               return ERR_PTR(-EINVAL);
17209 +       }
17210 +       if ((count == 2) && (((long)mem & 1) == 0)) {
17211 +               unsigned short tmp_s = 0;
17212 +#ifdef __BIG_ENDIAN
17213 +               tmp_s |= hex(*buf++) << 12;
17214 +               tmp_s |= hex(*buf++) << 8;
17215 +               tmp_s |= hex(*buf++) << 4;
17216 +               tmp_s |= hex(*buf++);
17217 +#else
17218 +               tmp_s |= hex(*buf++) << 4;
17219 +               tmp_s |= hex(*buf++);
17220 +               tmp_s |= hex(*buf++) << 12;
17221 +               tmp_s |= hex(*buf++) << 8;
17222 +#endif
17223 +               *(unsigned short *)mem = tmp_s;
17224 +               mem += 2;
17225 +       } else if ((count == 4) && (((long)mem & 3) == 0)) {
17226 +               unsigned long tmp_l = 0;
17227 +#ifdef __BIG_ENDIAN
17228 +               tmp_l |= hex(*buf++) << 28;
17229 +               tmp_l |= hex(*buf++) << 24;
17230 +               tmp_l |= hex(*buf++) << 20;
17231 +               tmp_l |= hex(*buf++) << 16;
17232 +               tmp_l |= hex(*buf++) << 12;
17233 +               tmp_l |= hex(*buf++) << 8;
17234 +               tmp_l |= hex(*buf++) << 4;
17235 +               tmp_l |= hex(*buf++);
17236 +#else
17237 +               tmp_l |= hex(*buf++) << 4;
17238 +               tmp_l |= hex(*buf++);
17239 +               tmp_l |= hex(*buf++) << 12;
17240 +               tmp_l |= hex(*buf++) << 8;
17241 +               tmp_l |= hex(*buf++) << 20;
17242 +               tmp_l |= hex(*buf++) << 16;
17243 +               tmp_l |= hex(*buf++) << 28;
17244 +               tmp_l |= hex(*buf++) << 24;
17245 +#endif
17246 +               *(unsigned long *)mem = tmp_l;
17247 +               mem += 4;
17248 +       } else {
17249 +               int i;
17250 +               for (i = 0; i < count; i++) {
17251 +                       unsigned char ch = hex(*buf++) << 4;
17252 +                       ch |= hex(*buf++);
17253 +                       *mem++ = ch;
17254 +               }
17255 +       }
17256 +       kgdb_may_fault = 0;
17257 +       return (mem);
17258 +}
17259 +
17260 +/*
17261 + * While we find nice hex chars, build a long_val.
17262 + * Return number of chars processed.
17263 + */
17264 +int kgdb_hex2long(char **ptr, long *long_val)
17265 +{
17266 +       int hex_val, num = 0;
17267 +
17268 +       *long_val = 0;
17269 +
17270 +       while (**ptr) {
17271 +               hex_val = hex(**ptr);
17272 +               if (hex_val >= 0) {
17273 +                       *long_val = (*long_val << 4) | hex_val;
17274 +                       num++;
17275 +               } else
17276 +                       break;
17277 +
17278 +               (*ptr)++;
17279 +       }
17280 +
17281 +       return (num);
17282 +}
17283 +
17284 +/* Write memory due to an 'M' or 'X' packet. */
17285 +static char *write_mem_msg(int binary)
17286 +{
17287 +       char *ptr = &remcom_in_buffer[1];
17288 +       unsigned long addr, length;
17289 +
17290 +       if (kgdb_hex2long(&ptr, &addr) > 0 && *(ptr++) == ',' &&
17291 +           kgdb_hex2long(&ptr, &length) > 0 && *(ptr++) == ':') {
17292 +               if (binary)
17293 +                       ptr = kgdb_ebin2mem(ptr, (char *)addr, length);
17294 +               else
17295 +                       ptr = kgdb_hex2mem(ptr, (char *)addr, length);
17296 +               if (CACHE_FLUSH_IS_SAFE)
17297 +                       flush_icache_range(addr, addr + length + 1);
17298 +               if (IS_ERR(ptr))
17299 +                       return ptr;
17300 +               return NULL;
17301 +       }
17302 +
17303 +       return ERR_PTR(-EINVAL);
17304 +}
17305 +
17306 +static inline char *pack_hex_byte(char *pkt, int byte)
17307 +{
17308 +       *pkt++ = hexchars[(byte >> 4) & 0xf];
17309 +       *pkt++ = hexchars[(byte & 0xf)];
17310 +       return pkt;
17311 +}
17312 +
17313 +static inline void error_packet(char *pkt, int error)
17314 +{
17315 +       error = -error;
17316 +       pkt[0] = 'E';
17317 +       pkt[1] = hexchars[(error / 10)];
17318 +       pkt[2] = hexchars[(error % 10)];
17319 +       pkt[3] = '\0';
17320 +}
17321 +
17322 +static char *pack_threadid(char *pkt, threadref * id)
17323 +{
17324 +       char *limit;
17325 +       unsigned char *altid;
17326 +
17327 +       altid = (unsigned char *)id;
17328 +       limit = pkt + BUF_THREAD_ID_SIZE;
17329 +       while (pkt < limit)
17330 +               pkt = pack_hex_byte(pkt, *altid++);
17331 +
17332 +       return pkt;
17333 +}
17334 +
17335 +void int_to_threadref(threadref * id, int value)
17336 +{
17337 +       unsigned char *scan;
17338 +       int i = 4;
17339 +
17340 +       scan = (unsigned char *)id;
17341 +       while (i--)
17342 +               *scan++ = 0;
17343 +       *scan++ = (value >> 24) & 0xff;
17344 +       *scan++ = (value >> 16) & 0xff;
17345 +       *scan++ = (value >> 8) & 0xff;
17346 +       *scan++ = (value & 0xff);
17347 +}
17348 +
17349 +static struct task_struct *getthread(struct pt_regs *regs, int tid)
17350 +{
17351 +       if (last_pid == 0)
17352 +               return current;
17353 +
17354 +       if (num_online_cpus() &&
17355 +           (tid >= pid_max + num_online_cpus() + kgdb_ops->shadowth))
17356 +               return NULL;
17357 +
17358 +       if (kgdb_ops->shadowth && (tid >= pid_max + num_online_cpus()))
17359 +               return kgdb_get_shadow_thread(regs, tid - pid_max -
17360 +                                             num_online_cpus());
17361 +
17362 +       if (tid >= pid_max)
17363 +               return idle_task(tid - pid_max);
17364 +
17365 +       if (!tid)
17366 +               return NULL;
17367 +
17368 +       return find_task_by_pid(tid);
17369 +}
17370 +
17371 +#ifdef CONFIG_SMP
17372 +static void kgdb_wait(struct pt_regs *regs)
17373 +{
17374 +       unsigned long flags;
17375 +       int processor;
17376 +
17377 +       local_irq_save(flags);
17378 +       processor = smp_processor_id();
17379 +       kgdb_info[processor].debuggerinfo = regs;
17380 +       kgdb_info[processor].task = current;
17381 +       atomic_set(&procindebug[processor], 1);
17382 +       atomic_set(&kgdb_sync_softlockup[smp_processor_id()], 1);
17383 +
17384 +       /* Wait till master processor goes completely into the debugger.
17385 +        * FIXME: this looks racy */
17386 +       while (!atomic_read(&procindebug[atomic_read(&debugger_active) - 1])) {
17387 +               int i = 10;     /* an arbitrary number */
17388 +
17389 +               while (--i)
17390 +                       cpu_relax();
17391 +       }
17392 +
17393 +       /* Wait till master processor is done with debugging */
17394 +       spin_lock(&slavecpulocks[processor]);
17395 +
17396 +       /* This has been taken from x86 kgdb implementation and
17397 +        * will be needed by architectures that have SMP support
17398 +        */
17399 +       kgdb_correct_hw_break();
17400 +
17401 +       kgdb_info[processor].debuggerinfo = NULL;
17402 +       kgdb_info[processor].task = NULL;
17403 +
17404 +       /* Signal the master processor that we are done */
17405 +       atomic_set(&procindebug[processor], 0);
17406 +       spin_unlock(&slavecpulocks[processor]);
17407 +       local_irq_restore(flags);
17408 +}
17409 +#endif
17410 +
17411 +int kgdb_get_mem(char *addr, unsigned char *buf, int count)
17412 +{
17413 +       kgdb_may_fault = 1;
17414 +       if ((kgdb_fault_setjmp(kgdb_fault_jmp_regs)) != 0) {
17415 +               kgdb_may_fault = 0;
17416 +               return -EINVAL;
17417 +       }
17418 +       while (count) {
17419 +               if ((unsigned long)addr < TASK_SIZE)
17420 +                       return -EINVAL;
17421 +               *buf++ = *addr++;
17422 +               count--;
17423 +       }
17424 +       kgdb_may_fault = 0;
17425 +       return 0;
17426 +}
17427 +
17428 +int kgdb_set_mem(char *addr, unsigned char *buf, int count)
17429 +{
17430 +       kgdb_may_fault = 1;
17431 +       if ((kgdb_fault_setjmp(kgdb_fault_jmp_regs)) != 0) {
17432 +               kgdb_may_fault = 0;
17433 +               return -EINVAL;
17434 +       }
17435 +       while (count) {
17436 +               if ((unsigned long)addr < TASK_SIZE)
17437 +                       return -EINVAL;
17438 +               *addr++ = *buf++;
17439 +               count--;
17440 +       }
17441 +       kgdb_may_fault = 0;
17442 +       return 0;
17443 +}
17444 +int kgdb_activate_sw_breakpoints(void)
17445 +{
17446 +       int i;
17447 +       int error = 0;
17448 +       unsigned long addr;
17449 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
17450 +               if (kgdb_break[i].state != bp_set)
17451 +                       continue;
17452 +               addr = kgdb_break[i].bpt_addr;
17453 +               if ((error = kgdb_arch_set_breakpoint(addr,
17454 +                                       kgdb_break[i].saved_instr)))
17455 +                       return error;
17456 +
17457 +               if (CACHE_FLUSH_IS_SAFE) {
17458 +                       if (current->mm && addr < TASK_SIZE)
17459 +                               flush_cache_range(current->mm->mmap_cache,
17460 +                                               addr, addr + BREAK_INSTR_SIZE);
17461 +                       else
17462 +                               flush_icache_range(addr, addr +
17463 +                                               BREAK_INSTR_SIZE);
17464 +               }
17465 +
17466 +               kgdb_break[i].state = bp_active;
17467 +        }
17468 +       return 0;
17469 +}
17470 +
17471 +static int kgdb_set_sw_break(unsigned long addr)
17472 +{
17473 +       int i, breakno = -1;
17474 +       int error = 0;
17475 +       if ((error = kgdb_validate_break_address(addr)) < 0)
17476 +               return error;
17477 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
17478 +               if ((kgdb_break[i].state == bp_set) &&
17479 +                       (kgdb_break[i].bpt_addr == addr))
17480 +                       return -EEXIST;
17481 +       }
17482 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
17483 +               if (kgdb_break[i].state == bp_removed &&
17484 +                               kgdb_break[i].bpt_addr == addr) {
17485 +                       breakno = i;
17486 +                       break;
17487 +               }
17488 +       }
17489 +
17490 +       if (breakno == -1) {
17491 +               for (i = 0; i < MAX_BREAKPOINTS; i++) {
17492 +                       if (kgdb_break[i].state == bp_none) {
17493 +                               breakno = i;
17494 +                               break;
17495 +                       }
17496 +               }
17497 +       }
17498 +       if (breakno == -1)
17499 +               return -E2BIG;
17500 +
17501 +       kgdb_break[breakno].state = bp_set;
17502 +       kgdb_break[breakno].type = bp_breakpoint;
17503 +       kgdb_break[breakno].bpt_addr = addr;
17504 +
17505 +       return 0;
17506 +}
17507 +
17508 +int kgdb_deactivate_sw_breakpoints(void)
17509 +{
17510 +       int i;
17511 +       int error = 0;
17512 +       unsigned long addr;
17513 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
17514 +               if (kgdb_break[i].state != bp_active)
17515 +                       continue;
17516 +               addr = kgdb_break[i].bpt_addr;
17517 +               if ((error = kgdb_arch_remove_breakpoint(addr,
17518 +                                       kgdb_break[i].saved_instr)))
17519 +                       return error;
17520 +
17521 +               if (CACHE_FLUSH_IS_SAFE && current->mm &&
17522 +                               addr < TASK_SIZE)
17523 +                       flush_cache_range(current->mm->mmap_cache,
17524 +                                       addr, addr + BREAK_INSTR_SIZE);
17525 +               else if (CACHE_FLUSH_IS_SAFE)
17526 +                       flush_icache_range(addr,
17527 +                                       addr + BREAK_INSTR_SIZE);
17528 +               kgdb_break[i].state = bp_set;
17529 +       }
17530 +       return 0;
17531 +}
17532 +
17533 +static int kgdb_remove_sw_break(unsigned long addr)
17534 +{
17535 +       int i;
17536 +
17537 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
17538 +               if ((kgdb_break[i].state == bp_set) &&
17539 +                       (kgdb_break[i].bpt_addr == addr)) {
17540 +                       kgdb_break[i].state = bp_removed;
17541 +                       return 0;
17542 +               }
17543 +       }
17544 +       return -ENOENT;
17545 +}
17546 +
17547 +int kgdb_isremovedbreak(unsigned long addr)
17548 +{
17549 +       int i;
17550 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
17551 +               if ((kgdb_break[i].state == bp_removed) &&
17552 +                       (kgdb_break[i].bpt_addr == addr)) {
17553 +                       return 1;
17554 +               }
17555 +       }
17556 +       return 0;
17557 +}
17558 +
17559 +int remove_all_break(void)
17560 +{
17561 +       int i;
17562 +       int error;
17563 +       unsigned long addr;
17564 +
17565 +       /* Clear memory breakpoints. */
17566 +       for (i = 0; i < MAX_BREAKPOINTS; i++) {
17567 +               if (kgdb_break[i].state != bp_set)
17568 +                       continue;
17569 +               addr = kgdb_break[i].bpt_addr;
17570 +               if ((error = kgdb_arch_remove_breakpoint(addr,
17571 +                                       kgdb_break[i].saved_instr)))
17572 +                       return error;
17573 +               kgdb_break[i].state = bp_removed;
17574 +       }
17575 +
17576 +       /* Clear hardware breakpoints. */
17577 +       kgdb_remove_all_hw_break();
17578 +
17579 +       return 0;
17580 +}
17581 +
17582 +static inline int shadow_pid(int realpid)
17583 +{
17584 +       if (realpid) {
17585 +               return realpid;
17586 +       }
17587 +       return pid_max + smp_processor_id();
17588 +}
17589 +
17590 +static char gdbmsgbuf[BUFMAX + 1];
17591 +static void kgdb_msg_write(const char *s, int len)
17592 +{
17593 +       int i;
17594 +       int wcount;
17595 +       char *bufptr;
17596 +
17597 +       /* 'O'utput */
17598 +       gdbmsgbuf[0] = 'O';
17599 +
17600 +       /* Fill and send buffers... */
17601 +       while (len > 0) {
17602 +               bufptr = gdbmsgbuf + 1;
17603 +
17604 +               /* Calculate how many this time */
17605 +               if ((len << 1) > (BUFMAX - 2))
17606 +                       wcount = (BUFMAX - 2) >> 1;
17607 +               else
17608 +                       wcount = len;
17609 +
17610 +               /* Pack in hex chars */
17611 +               for (i = 0; i < wcount; i++)
17612 +                       bufptr = pack_hex_byte(bufptr, s[i]);
17613 +               *bufptr = '\0';
17614 +
17615 +               /* Move up */
17616 +               s += wcount;
17617 +               len -= wcount;
17618 +
17619 +               /* Write packet */
17620 +               put_packet(gdbmsgbuf);
17621 +       }
17622 +}
17623 +
17624 +/*
17625 + * This function does all command procesing for interfacing to gdb.
17626 + *
17627 + * Locking hierarchy:
17628 + *     interface locks, if any (begin_session)
17629 + *     kgdb lock (debugger_active)
17630 + *
17631 + * Note that since we can be in here prior to our cpumask being filled
17632 + * out, we err on the side of caution and loop over NR_CPUS instead
17633 + * of a for_each_online_cpu.
17634 + *
17635 + */
17636 +int kgdb_handle_exception(int ex_vector, int signo, int err_code,
17637 +                         struct pt_regs *linux_regs)
17638 +{
17639 +       unsigned long length, addr;
17640 +       char *ptr;
17641 +       unsigned long flags;
17642 +       unsigned i;
17643 +       long threadid;
17644 +       threadref thref;
17645 +       struct task_struct *thread = NULL;
17646 +       unsigned procid;
17647 +       int numshadowth = num_online_cpus() + kgdb_ops->shadowth;
17648 +       long kgdb_usethreadid = 0;
17649 +       int error = 0, all_cpus_synced = 0;
17650 +       struct pt_regs *shadowregs;
17651 +       int processor = smp_processor_id();
17652 +       void *local_debuggerinfo;
17653 +
17654 +       /* Panic on recursive debugger calls. */
17655 +       if (atomic_read(&debugger_active) == smp_processor_id() + 1)
17656 +               return 0;
17657 +
17658 +      acquirelock:
17659 +
17660 +       /* Call the I/O drivers pre_exception routine if the I/O
17661 +        * driver defined one
17662 +        */
17663 +       if (kgdb_io_ops.pre_exception)
17664 +               kgdb_io_ops.pre_exception();
17665 +
17666 +       /*
17667 +        * Interrupts will be restored by the 'trap return' code, except when
17668 +        * single stepping.
17669 +        */
17670 +       local_irq_save(flags);
17671 +
17672 +       /* Hold debugger_active */
17673 +       procid = smp_processor_id();
17674 +
17675 +       while (cmpxchg(&atomic_read(&debugger_active), 0, (procid + 1)) != 0) {
17676 +               int i = 25;     /* an arbitrary number */
17677 +
17678 +               while (--i)
17679 +                       cpu_relax();
17680 +
17681 +               if (atomic_read(&cpu_doing_single_step) != -1 &&
17682 +                               atomic_read(&cpu_doing_single_step) != procid)
17683 +                       udelay(1);
17684 +       }
17685 +
17686 +       atomic_set(&kgdb_sync_softlockup[smp_processor_id()], 1);
17687 +
17688 +       /*
17689 +        * Don't enter if the last instance of the exception handler wanted to
17690 +        * come into the debugger again.
17691 +        */
17692 +       if (atomic_read(&cpu_doing_single_step) != -1 &&
17693 +           atomic_read(&cpu_doing_single_step) != procid) {
17694 +               atomic_set(&debugger_active, 0);
17695 +               local_irq_restore(flags);
17696 +               goto acquirelock;
17697 +       }
17698 +
17699 +       /*
17700 +       * Don't enter if we have hit a removed breakpoint.
17701 +       */
17702 +       if (kgdb_skipexception(ex_vector, linux_regs))
17703 +               goto kgdb_restore;
17704 +
17705 +       kgdb_info[processor].debuggerinfo = linux_regs;
17706 +       kgdb_info[processor].task = current;
17707 +
17708 +       kgdb_disable_hw_debug(linux_regs);
17709 +
17710 +       if (!debugger_step || !kgdb_contthread)
17711 +               for (i = 0; i < NR_CPUS; i++)
17712 +                       spin_lock(&slavecpulocks[i]);
17713 +
17714 +       /* Make sure we get the other CPUs */
17715 +       if (!debugger_step || !kgdb_contthread)
17716 +               kgdb_roundup_cpus(flags);
17717 +
17718 +       /* spin_lock code is good enough as a barrier so we don't
17719 +        * need one here */
17720 +       atomic_set(&procindebug[processor], 1);
17721 +
17722 +       /* Wait a reasonable time for the other CPUs to be notified and
17723 +        * be waiting for us.  Very early on this could be imperfect
17724 +        * as num_online_cpus() could be 0.*/
17725 +       for (i = 0; i < ROUNDUP_WAIT; i++) {
17726 +               int cpu, num = 0;
17727 +               for (cpu = 0; cpu < NR_CPUS; cpu++) {
17728 +                       if (atomic_read(&procindebug[cpu]))
17729 +                               num++;
17730 +               }
17731 +               if (num >= num_online_cpus()) {
17732 +                       all_cpus_synced = 1;
17733 +                       break;
17734 +               }
17735 +       }
17736 +
17737 +       /* Clear the out buffer. */
17738 +       memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer));
17739 +
17740 +       /* Master processor is completely in the debugger */
17741 +       kgdb_post_master_code(linux_regs, ex_vector, err_code);
17742 +       kgdb_deactivate_sw_breakpoints();
17743 +       debugger_step = 0;
17744 +       kgdb_contthread = NULL;
17745 +
17746 +       if (kgdb_connected) {
17747 +               /* If we're still unable to roundup all of the CPUs,
17748 +                * send an 'O' packet informing the user again. */
17749 +               if (!all_cpus_synced)
17750 +                       kgdb_msg_write("Not all CPUs have been synced for "
17751 +                                      "KGDB\n", 39);
17752 +               /* Reply to host that an exception has occurred */
17753 +               ptr = remcom_out_buffer;
17754 +               *ptr++ = 'T';
17755 +               *ptr++ = hexchars[(signo >> 4) % 16];
17756 +               *ptr++ = hexchars[signo % 16];
17757 +               ptr += strlen(strcpy(ptr, "thread:"));
17758 +               int_to_threadref(&thref, shadow_pid(current->pid));
17759 +               ptr = pack_threadid(ptr, &thref);
17760 +               *ptr++ = ';';
17761 +
17762 +               put_packet(remcom_out_buffer);
17763 +       }
17764 +
17765 +       kgdb_usethread = kgdb_info[processor].task;
17766 +       kgdb_usethreadid = shadow_pid(kgdb_info[processor].task->pid);
17767 +
17768 +       while (kgdb_io_ops.read_char) {
17769 +               char *bpt_type;
17770 +               error = 0;
17771 +
17772 +               /* Clear the out buffer. */
17773 +               memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer));
17774 +
17775 +               get_packet(remcom_in_buffer);
17776 +
17777 +               switch (remcom_in_buffer[0]) {
17778 +               case '?':
17779 +                       /* We know that this packet is only sent
17780 +                        * during initial connect.  So to be safe,
17781 +                        * we clear out our breakpoints now incase
17782 +                        * GDB is reconnecting. */
17783 +                       remove_all_break();
17784 +                       /* Also, if we haven't been able to roundup all
17785 +                        * CPUs, send an 'O' packet informing the user
17786 +                        * as much.  Only need to do this once. */
17787 +                       if (!all_cpus_synced)
17788 +                               kgdb_msg_write("Not all CPUs have been "
17789 +                                              "synced for KGDB\n", 39);
17790 +                       remcom_out_buffer[0] = 'S';
17791 +                       remcom_out_buffer[1] = hexchars[signo >> 4];
17792 +                       remcom_out_buffer[2] = hexchars[signo % 16];
17793 +                       break;
17794 +
17795 +               case 'g':       /* return the value of the CPU registers */
17796 +                       thread = kgdb_usethread;
17797 +
17798 +                       if (!thread) {
17799 +                               thread = kgdb_info[processor].task;
17800 +                               local_debuggerinfo =
17801 +                                   kgdb_info[processor].debuggerinfo;
17802 +                       } else {
17803 +                               local_debuggerinfo = NULL;
17804 +                               for (i = 0; i < NR_CPUS; i++) {
17805 +                                       /* Try to find the task on some other
17806 +                                        * or possibly this node if we do not
17807 +                                        * find the matching task then we try
17808 +                                        * to approximate the results.
17809 +                                        */
17810 +                                       if (thread == kgdb_info[i].task)
17811 +                                               local_debuggerinfo =
17812 +                                                   kgdb_info[i].debuggerinfo;
17813 +                               }
17814 +                       }
17815 +
17816 +                       /* All threads that don't have debuggerinfo should be
17817 +                        * in __schedule() sleeping, since all other CPUs
17818 +                        * are in kgdb_wait, and thus have debuggerinfo. */
17819 +                       if (kgdb_ops->shadowth &&
17820 +                           kgdb_usethreadid >= pid_max + num_online_cpus()) {
17821 +                               shadowregs = kgdb_shadow_regs(linux_regs,
17822 +                                                             kgdb_usethreadid -
17823 +                                                             pid_max -
17824 +                                                             num_online_cpus
17825 +                                                             ());
17826 +                               if (!shadowregs) {
17827 +                                       error_packet(remcom_out_buffer,
17828 +                                                    -EINVAL);
17829 +                                       break;
17830 +                               }
17831 +                               regs_to_gdb_regs(gdb_regs, shadowregs);
17832 +                       } else if (local_debuggerinfo)
17833 +                               regs_to_gdb_regs(gdb_regs, local_debuggerinfo);
17834 +                       else {
17835 +                               /* Pull stuff saved during
17836 +                                * switch_to; nothing else is
17837 +                                * accessible (or even particularly relevant).
17838 +                                * This should be enough for a stack trace. */
17839 +                               sleeping_thread_to_gdb_regs(gdb_regs, thread);
17840 +                       }
17841 +                       kgdb_mem2hex((char *)gdb_regs, remcom_out_buffer,
17842 +                                    NUMREGBYTES);
17843 +                       break;
17844 +
17845 +                       /* set the value of the CPU registers - return OK */
17846 +               case 'G':
17847 +                       kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs,
17848 +                                    NUMREGBYTES);
17849 +
17850 +                       if (kgdb_usethread && kgdb_usethread != current)
17851 +                               error_packet(remcom_out_buffer, -EINVAL);
17852 +                       else {
17853 +                               gdb_regs_to_regs(gdb_regs, linux_regs);
17854 +                               strcpy(remcom_out_buffer, "OK");
17855 +                       }
17856 +                       break;
17857 +
17858 +                       /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
17859 +               case 'm':
17860 +                       ptr = &remcom_in_buffer[1];
17861 +                       if (kgdb_hex2long(&ptr, &addr) > 0 && *ptr++ == ',' &&
17862 +                           kgdb_hex2long(&ptr, &length) > 0) {
17863 +                               if (IS_ERR(ptr = kgdb_mem2hex((char *)addr,
17864 +                                                             remcom_out_buffer,
17865 +                                                             length)))
17866 +                                       error_packet(remcom_out_buffer,
17867 +                                                    PTR_ERR(ptr));
17868 +                       } else
17869 +                               error_packet(remcom_out_buffer, -EINVAL);
17870 +                       break;
17871 +
17872 +                       /* MAA..AA,LLLL: Write LLLL bytes at address AA..AA */
17873 +               case 'M':
17874 +                       if (IS_ERR(ptr = write_mem_msg(0)))
17875 +                               error_packet(remcom_out_buffer, PTR_ERR(ptr));
17876 +                       else
17877 +                               strcpy(remcom_out_buffer, "OK");
17878 +                       break;
17879 +                       /* XAA..AA,LLLL: Write LLLL bytes at address AA..AA */
17880 +               case 'X':
17881 +                       if (IS_ERR(ptr = write_mem_msg(1)))
17882 +                               error_packet(remcom_out_buffer, PTR_ERR(ptr));
17883 +                       else
17884 +                               strcpy(remcom_out_buffer, "OK");
17885 +                       break;
17886 +
17887 +                       /* kill or detach. KGDB should treat this like a
17888 +                        * continue.
17889 +                        */
17890 +               case 'D':
17891 +                       if ((error = remove_all_break()) < 0) {
17892 +                               error_packet(remcom_out_buffer, error);
17893 +                       } else {
17894 +                               strcpy(remcom_out_buffer, "OK");
17895 +                               kgdb_connected = 0;
17896 +                       }
17897 +                       put_packet(remcom_out_buffer);
17898 +                       goto default_handle;
17899 +
17900 +               case 'k':
17901 +                       /* Don't care about error from remove_all_break */
17902 +                       remove_all_break();
17903 +                       kgdb_connected = 0;
17904 +                       goto default_handle;
17905 +
17906 +                       /* Reboot */
17907 +               case 'R':
17908 +                       /* For now, only honor R0 */
17909 +                       if (strcmp(remcom_in_buffer, "R0") == 0) {
17910 +                               printk(KERN_CRIT "Executing reboot\n");
17911 +                               strcpy(remcom_out_buffer, "OK");
17912 +                               put_packet(remcom_out_buffer);
17913 +                               emergency_sync();
17914 +                               /* Execution should not return from
17915 +                                * machine_restart()
17916 +                                */
17917 +                               machine_restart(NULL);
17918 +                               kgdb_connected = 0;
17919 +                               goto default_handle;
17920 +                       }
17921 +
17922 +                       /* query */
17923 +               case 'q':
17924 +                       switch (remcom_in_buffer[1]) {
17925 +                       case 's':
17926 +                       case 'f':
17927 +                               if (memcmp(remcom_in_buffer + 2, "ThreadInfo",
17928 +                                          10)) {
17929 +                                       error_packet(remcom_out_buffer,
17930 +                                                    -EINVAL);
17931 +                                       break;
17932 +                               }
17933 +
17934 +                               /*
17935 +                                * If we have not yet completed in
17936 +                                * pidhash_init() there isn't much we
17937 +                                * can give back.
17938 +                                */
17939 +                               if (last_pid == 0) {
17940 +                                       if (remcom_in_buffer[1] == 'f')
17941 +                                               strcpy(remcom_out_buffer,
17942 +                                                      "m0000000000000001");
17943 +                                       break;
17944 +                               }
17945 +
17946 +                               if (remcom_in_buffer[1] == 'f') {
17947 +                                       threadid = 1;
17948 +                               }
17949 +                               remcom_out_buffer[0] = 'm';
17950 +                               ptr = remcom_out_buffer + 1;
17951 +                               for (i = 0; i < 17 && threadid < pid_max +
17952 +                                    numshadowth; threadid++) {
17953 +                                       thread = getthread(linux_regs,
17954 +                                                          threadid);
17955 +                                       if (thread) {
17956 +                                               int_to_threadref(&thref,
17957 +                                                                threadid);
17958 +                                               pack_threadid(ptr, &thref);
17959 +                                               ptr += 16;
17960 +                                               *(ptr++) = ',';
17961 +                                               i++;
17962 +                                       }
17963 +                               }
17964 +                               *(--ptr) = '\0';
17965 +                               break;
17966 +
17967 +                       case 'C':
17968 +                               /* Current thread id */
17969 +                               strcpy(remcom_out_buffer, "QC");
17970 +
17971 +                               threadid = shadow_pid(current->pid);
17972 +
17973 +                               int_to_threadref(&thref, threadid);
17974 +                               pack_threadid(remcom_out_buffer + 2, &thref);
17975 +                               break;
17976 +                       case 'T':
17977 +                               if (memcmp(remcom_in_buffer + 1,
17978 +                                          "ThreadExtraInfo,", 16)) {
17979 +                                       error_packet(remcom_out_buffer,
17980 +                                                    -EINVAL);
17981 +                                       break;
17982 +                               }
17983 +                               threadid = 0;
17984 +                               ptr = remcom_in_buffer + 17;
17985 +                               kgdb_hex2long(&ptr, &threadid);
17986 +                               if (!getthread(linux_regs, threadid)) {
17987 +                                       error_packet(remcom_out_buffer,
17988 +                                                    -EINVAL);
17989 +                                       break;
17990 +                               }
17991 +                               if (threadid < pid_max) {
17992 +                                       kgdb_mem2hex(getthread(linux_regs,
17993 +                                                              threadid)->comm,
17994 +                                                    remcom_out_buffer, 16);
17995 +                               } else if (threadid >= pid_max +
17996 +                                          num_online_cpus()) {
17997 +                                       kgdb_shadowinfo(linux_regs,
17998 +                                                       remcom_out_buffer,
17999 +                                                       threadid - pid_max -
18000 +                                                       num_online_cpus());
18001 +                               } else {
18002 +                                       static char tmpstr[23 +
18003 +                                                          BUF_THREAD_ID_SIZE];
18004 +                                       sprintf(tmpstr, "Shadow task %d"
18005 +                                               " for pid 0",
18006 +                                               (int)(threadid - pid_max));
18007 +                                       kgdb_mem2hex(tmpstr, remcom_out_buffer,
18008 +                                                    strlen(tmpstr));
18009 +                               }
18010 +                               break;
18011 +                       }
18012 +                       break;
18013 +
18014 +                       /* task related */
18015 +               case 'H':
18016 +                       switch (remcom_in_buffer[1]) {
18017 +                       case 'g':
18018 +                               ptr = &remcom_in_buffer[2];
18019 +                               kgdb_hex2long(&ptr, &threadid);
18020 +                               thread = getthread(linux_regs, threadid);
18021 +                               if (!thread && threadid > 0) {
18022 +                                       error_packet(remcom_out_buffer,
18023 +                                                    -EINVAL);
18024 +                                       break;
18025 +                               }
18026 +                               kgdb_usethread = thread;
18027 +                               kgdb_usethreadid = threadid;
18028 +                               strcpy(remcom_out_buffer, "OK");
18029 +                               break;
18030 +
18031 +                       case 'c':
18032 +                               ptr = &remcom_in_buffer[2];
18033 +                               kgdb_hex2long(&ptr, &threadid);
18034 +                               if (!threadid) {
18035 +                                       kgdb_contthread = NULL;
18036 +                               } else {
18037 +                                       thread = getthread(linux_regs,
18038 +                                                          threadid);
18039 +                                       if (!thread && threadid > 0) {
18040 +                                               error_packet(remcom_out_buffer,
18041 +                                                            -EINVAL);
18042 +                                               break;
18043 +                                       }
18044 +                                       kgdb_contthread = thread;
18045 +                               }
18046 +                               strcpy(remcom_out_buffer, "OK");
18047 +                               break;
18048 +                       }
18049 +                       break;
18050 +
18051 +                       /* Query thread status */
18052 +               case 'T':
18053 +                       ptr = &remcom_in_buffer[1];
18054 +                       kgdb_hex2long(&ptr, &threadid);
18055 +                       thread = getthread(linux_regs, threadid);
18056 +                       if (thread)
18057 +                               strcpy(remcom_out_buffer, "OK");
18058 +                       else
18059 +                               error_packet(remcom_out_buffer, -EINVAL);
18060 +                       break;
18061 +               /* Since GDB-5.3, it's been drafted that '0' is a software
18062 +                * breakpoint, '1' is a hardware breakpoint, so let's do
18063 +                * that.
18064 +                */
18065 +               case 'z':
18066 +               case 'Z':
18067 +                       bpt_type = &remcom_in_buffer[1];
18068 +                       ptr = &remcom_in_buffer[2];
18069 +
18070 +                       if (kgdb_ops->set_hw_breakpoint && *bpt_type >= '1') {
18071 +                               /* Unsupported */
18072 +                               if (*bpt_type > '4')
18073 +                                       break;
18074 +                       } else if (*bpt_type != '0' && *bpt_type != '1')
18075 +                               /* Unsupported. */
18076 +                               break;
18077 +                       /* Test if this is a hardware breakpoint, and
18078 +                        * if we support it. */
18079 +                       if (*bpt_type == '1' &&
18080 +                           !kgdb_ops->flags & KGDB_HW_BREAKPOINT)
18081 +                               /* Unsupported. */
18082 +                               break;
18083 +
18084 +                       if (*(ptr++) != ',') {
18085 +                               error_packet(remcom_out_buffer, -EINVAL);
18086 +                               break;
18087 +                       } else if (kgdb_hex2long(&ptr, &addr)) {
18088 +                               if (*(ptr++) != ',' ||
18089 +                                   !kgdb_hex2long(&ptr, &length)) {
18090 +                                       error_packet(remcom_out_buffer,
18091 +                                                    -EINVAL);
18092 +                                       break;
18093 +                               }
18094 +                       } else {
18095 +                               error_packet(remcom_out_buffer, -EINVAL);
18096 +                               break;
18097 +                       }
18098 +
18099 +                       if (remcom_in_buffer[0] == 'Z' && *bpt_type == '0')
18100 +                               error = kgdb_set_sw_break(addr);
18101 +                       else if (remcom_in_buffer[0] == 'Z' && *bpt_type == '1')
18102 +                               error = kgdb_set_hw_break(addr);
18103 +                       else if (remcom_in_buffer[0] == 'z' && *bpt_type == '0')
18104 +                               error = kgdb_remove_sw_break(addr);
18105 +                       else if (remcom_in_buffer[0] == 'z' && *bpt_type == '1')
18106 +                               error = kgdb_remove_hw_break(addr);
18107 +                       else if (remcom_in_buffer[0] == 'Z')
18108 +                               error = kgdb_ops->set_hw_breakpoint(addr,
18109 +                                                                   (int)length,
18110 +                                                                   *bpt_type);
18111 +                       else if (remcom_in_buffer[0] == 'z')
18112 +                               error = kgdb_ops->remove_hw_breakpoint(addr,
18113 +                                                                      (int)
18114 +                                                                      length,
18115 +                                                                      *bpt_type);
18116 +
18117 +                       if (error == 0)
18118 +                               strcpy(remcom_out_buffer, "OK");
18119 +                       else
18120 +                               error_packet(remcom_out_buffer, error);
18121 +
18122 +                       break;
18123 +               case 'c':
18124 +               case 's':
18125 +                       if (kgdb_contthread && kgdb_contthread != current) {
18126 +                               /* Can't switch threads in kgdb */
18127 +                               error_packet(remcom_out_buffer, -EINVAL);
18128 +                               break;
18129 +                       }
18130 +                       kgdb_activate_sw_breakpoints();
18131 +                       /* Followthrough to default processing */
18132 +               default:
18133 +                     default_handle:
18134 +                       error = kgdb_arch_handle_exception(ex_vector, signo,
18135 +                                                          err_code,
18136 +                                                          remcom_in_buffer,
18137 +                                                          remcom_out_buffer,
18138 +                                                          linux_regs);
18139 +
18140 +                       if (error >= 0 || remcom_in_buffer[0] == 'D' ||
18141 +                           remcom_in_buffer[0] == 'k')
18142 +                               goto kgdb_exit;
18143 +
18144 +               }               /* switch */
18145 +
18146 +               /* reply to the request */
18147 +               put_packet(remcom_out_buffer);
18148 +       }
18149 +
18150 +      kgdb_exit:
18151 +       /* Call the I/O driver's post_exception routine if the I/O
18152 +        * driver defined one.
18153 +        */
18154 +       if (kgdb_io_ops.post_exception)
18155 +               kgdb_io_ops.post_exception();
18156 +
18157 +       kgdb_info[processor].debuggerinfo = NULL;
18158 +       kgdb_info[processor].task = NULL;
18159 +       atomic_set(&procindebug[processor], 0);
18160 +
18161 +       if (!debugger_step || !kgdb_contthread) {
18162 +               for (i = 0; i < NR_CPUS; i++)
18163 +                       spin_unlock(&slavecpulocks[i]);
18164 +               /* Wait till all the processors have quit
18165 +                * from the debugger. */
18166 +               for (i = 0; i < NR_CPUS; i++) {
18167 +                       while (atomic_read(&procindebug[i])) {
18168 +                               int j = 10;     /* an arbitrary number */
18169 +
18170 +                               while (--j)
18171 +                                       cpu_relax();
18172 +                       }
18173 +               }
18174 +       }
18175 +
18176 +#ifdef CONFIG_SMP
18177 +       /* This delay has a real purpose.  The problem is that if you
18178 +        * are single-stepping, you are sending an NMI to all the
18179 +        * other processors to stop them.  Interrupts come in, but
18180 +        * don't get handled.  Then you let them go just long enough
18181 +        * to get into their interrupt routines and use up some stack.
18182 +        * You stop them again, and then do the same thing.  After a
18183 +        * while you blow the stack on the other processors.  This
18184 +        * delay gives some time for interrupts to be cleared out on
18185 +        * the other processors.
18186 +        */
18187 +       if (debugger_step)
18188 +               mdelay(2);
18189 +#endif
18190 +kgdb_restore:
18191 +       /* Free debugger_active */
18192 +       atomic_set(&debugger_active, 0);
18193 +       local_irq_restore(flags);
18194 +
18195 +       return error;
18196 +}
18197 +
18198 +/*
18199 + * GDB places a breakpoint at this function to know dynamically
18200 + * loaded objects. It's not defined static so that only one instance with this
18201 + * name exists in the kernel.
18202 + */
18203 +
18204 +int module_event(struct notifier_block *self, unsigned long val, void *data)
18205 +{
18206 +       return 0;
18207 +}
18208 +
18209 +static struct notifier_block kgdb_module_load_nb = {
18210 +       .notifier_call = module_event,
18211 +};
18212 +
18213 +void kgdb_nmihook(int cpu, void *regs)
18214 +{
18215 +#ifdef CONFIG_SMP
18216 +       if (!atomic_read(&procindebug[cpu]) && atomic_read(&debugger_active) != (cpu + 1))
18217 +               kgdb_wait((struct pt_regs *)regs);
18218 +#endif
18219 +}
18220 +
18221 +/*
18222 + * This is called when a panic happens.  All we need to do is
18223 + * breakpoint().
18224 + */
18225 +static int kgdb_panic_notify(struct notifier_block *self, unsigned long cmd,
18226 +                            void *ptr)
18227 +{
18228 +       breakpoint();
18229 +
18230 +       return 0;
18231 +}
18232 +
18233 +static struct notifier_block kgdb_panic_notifier = {
18234 +       .notifier_call = kgdb_panic_notify,
18235 +};
18236 +
18237 +/*
18238 + * Initialization that needs to be done in either of our entry points.
18239 + */
18240 +static void __init kgdb_internal_init(void)
18241 +{
18242 +       int i;
18243 +
18244 +       /* Initialize our spinlocks. */
18245 +       for (i = 0; i < NR_CPUS; i++)
18246 +               spin_lock_init(&slavecpulocks[i]);
18247 +
18248 +       for (i = 0; i < MAX_BREAKPOINTS; i++)
18249 +               kgdb_break[i].state = bp_none;
18250 +
18251 +       /* Initialize the I/O handles */
18252 +       memset(&kgdb_io_ops_prev, 0, sizeof(kgdb_io_ops_prev));
18253 +
18254 +       /* We can't do much if this fails */
18255 +       register_module_notifier(&kgdb_module_load_nb);
18256 +
18257 +       kgdb_initialized = 1;
18258 +}
18259 +
18260 +static void kgdb_register_for_panic(void)
18261 +{
18262 +       /* Register for panics(). */
18263 +       /* The registration is done in the kgdb_register_for_panic
18264 +        * routine because KGDB should not try to handle a panic when
18265 +        * there are no kgdb_io_ops setup. It is assumed that the
18266 +        * kgdb_io_ops are setup at the time this method is called.
18267 +        */
18268 +       if (!kgdb_from_module_registered) {
18269 +               atomic_notifier_chain_register(&panic_notifier_list,
18270 +                                       &kgdb_panic_notifier);
18271 +               kgdb_from_module_registered = 1;
18272 +       }
18273 +}
18274 +
18275 +static void kgdb_unregister_for_panic(void)
18276 +{
18277 +       /* When this routine is called KGDB should unregister from the
18278 +        * panic handler and clean up, making sure it is not handling any
18279 +        * break exceptions at the time.
18280 +        */
18281 +       if (kgdb_from_module_registered) {
18282 +               kgdb_from_module_registered = 0;
18283 +               atomic_notifier_chain_unregister(&panic_notifier_list,
18284 +                                         &kgdb_panic_notifier);
18285 +       }
18286 +}
18287 +
18288 +int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops)
18289 +{
18290 +
18291 +       if (kgdb_connected) {
18292 +               printk(KERN_ERR "kgdb: Cannot load I/O module while KGDB "
18293 +                      "connected.\n");
18294 +               return -EINVAL;
18295 +       }
18296 +
18297 +       /* Save the old values so they can be restored */
18298 +       if (kgdb_io_handler_cnt >= MAX_KGDB_IO_HANDLERS) {
18299 +               printk(KERN_ERR "kgdb: No more I/O handles available.\n");
18300 +               return -EINVAL;
18301 +       }
18302 +
18303 +       /* Check to see if there is an existing driver and if so save its
18304 +        * values.  Also check to make sure the same driver was not trying
18305 +        * to re-register.
18306 +        */
18307 +       if (kgdb_io_ops.read_char != NULL &&
18308 +        kgdb_io_ops.read_char != local_kgdb_io_ops->read_char) {
18309 +               memcpy(&kgdb_io_ops_prev[kgdb_io_handler_cnt],
18310 +                      &kgdb_io_ops, sizeof(struct kgdb_io));
18311 +               kgdb_io_handler_cnt++;
18312 +       }
18313 +
18314 +       /* Initialize the io values for this module */
18315 +       memcpy(&kgdb_io_ops, local_kgdb_io_ops, sizeof(struct kgdb_io));
18316 +
18317 +       /* Make the call to register kgdb if is not initialized */
18318 +       kgdb_register_for_panic();
18319 +
18320 +       return 0;
18321 +}
18322 +
18323 +void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops)
18324 +{
18325 +       int i;
18326 +
18327 +       /* Unregister KGDB if there were no other prior io hooks, else
18328 +        * restore the io hooks.
18329 +        */
18330 +       if (kgdb_io_handler_cnt > 0 && kgdb_io_ops_prev[0].read_char != NULL) {
18331 +               /* First check if the hook that is in use is the one being
18332 +                * removed */
18333 +               if (kgdb_io_ops.read_char == local_kgdb_io_ops->read_char) {
18334 +                       /* Set 'i' to the value of where the list should be
18335 +                        * shifed */
18336 +                       i = kgdb_io_handler_cnt - 1;
18337 +                       memcpy(&kgdb_io_ops, &kgdb_io_ops_prev[i],
18338 +                              sizeof(struct kgdb_io));
18339 +               } else {
18340 +                       /* Simple case to remove an entry for an I/O handler
18341 +                        * that is not in use */
18342 +                       for (i = 0; i < kgdb_io_handler_cnt; i++) {
18343 +                               if (kgdb_io_ops_prev[i].read_char ==
18344 +                                   local_kgdb_io_ops->read_char)
18345 +                                       break;
18346 +                       }
18347 +               }
18348 +
18349 +               /* Shift all the entries in the handler array so it is
18350 +                * ordered from oldest to newest.
18351 +                */
18352 +               kgdb_io_handler_cnt--;
18353 +               for (; i < kgdb_io_handler_cnt; i++) {
18354 +                       memcpy(&kgdb_io_ops_prev[i], &kgdb_io_ops_prev[i + 1],
18355 +                              sizeof(struct kgdb_io));
18356 +               }
18357 +               /* Handle the case if we are on the last element and set it
18358 +                * to NULL; */
18359 +               memset(&kgdb_io_ops_prev[kgdb_io_handler_cnt], 0,
18360 +                               sizeof(struct kgdb_io));
18361 +
18362 +               if (kgdb_connected)
18363 +                       printk(KERN_ERR "kgdb: WARNING: I/O method changed "
18364 +                              "while kgdb was connected state.\n");
18365 +       } else {
18366 +               /* KGDB is no longer able to communicate out, so
18367 +                * unregister our hooks and reset state. */
18368 +               kgdb_unregister_for_panic();
18369 +               if (kgdb_connected) {
18370 +                       printk(KERN_CRIT "kgdb: I/O module was unloaded while "
18371 +                                       "a debugging session was running.  "
18372 +                                       "KGDB will be reset.\n");
18373 +                       if (remove_all_break() < 0)
18374 +                               printk(KERN_CRIT "kgdb: Reset failed.\n");
18375 +                       kgdb_connected = 0;
18376 +               }
18377 +               memset(&kgdb_io_ops, 0, sizeof(struct kgdb_io));
18378 +       }
18379 +}
18380 +
18381 +/*
18382 + * There are times we need to call a tasklet to cause a breakpoint
18383 + * as calling breakpoint() at that point might be fatal.  We have to
18384 + * check that the exception stack is setup, as tasklets may be scheduled
18385 + * prior to this.  When that happens, it is up to the architecture to
18386 + * schedule this when it is safe to run.
18387 + */
18388 +static void kgdb_tasklet_bpt(unsigned long ing)
18389 +{
18390 +       if(CHECK_EXCEPTION_STACK())
18391 +               breakpoint();
18392 +}
18393 +
18394 +DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
18395 +
18396 +/*
18397 + * This function can be called very early, either via early_param() or
18398 + * an explicit breakpoint() early on.
18399 + */
18400 +static void __init kgdb_early_entry(void)
18401 +{
18402 +       /*
18403 +        * Don't try and do anything until the architecture is able to
18404 +        * setup the exception stack.  In this case, it is up to the
18405 +        * architecture to hook in and look at us when they are ready.
18406 +        */
18407 +       if(!CHECK_EXCEPTION_STACK()) {
18408 +               kgdb_initialized = -1;
18409 +               tasklet_schedule(&kgdb_tasklet_breakpoint);
18410 +               return;
18411 +       }
18412 +
18413 +       /* Let the architecture do any setup that it needs to. */
18414 +       kgdb_arch_init();
18415 +
18416 +       /* Now try the I/O. */
18417 +       /* For early entry kgdb_io_ops.init must be defined */
18418 +       if (!kgdb_io_ops.init || kgdb_io_ops.init()) {
18419 +               /* Try again later. */
18420 +               kgdb_initialized = -1;
18421 +               return;
18422 +       }
18423 +
18424 +       /* Finish up. */
18425 +       kgdb_internal_init();
18426 +
18427 +       /* KGDB can assume that if kgdb_io_ops.init was defined that the
18428 +        * panic registion should be performed at this time. This means
18429 +        * kgdb_io_ops.init did not come from a kernel module and was
18430 +        * initialized statically by a built in.
18431 +        */
18432 +       if (kgdb_io_ops.init)
18433 +               kgdb_register_for_panic();
18434 +}
18435 +
18436 +/*
18437 + * This function will always be invoked to make sure that KGDB will grab
18438 + * what it needs to so that if something happens while the system is
18439 + * running, KGDB will get involved.  If kgdb_early_entry() has already
18440 + * been invoked, there is little we need to do.
18441 + */
18442 +static int __init kgdb_late_entry(void)
18443 +{
18444 +       int need_break = 0;
18445 +
18446 +       /* If kgdb_initialized is -1 then we were passed kgdbwait. */
18447 +       if (kgdb_initialized == -1)
18448 +               need_break = 1;
18449 +
18450 +       /*
18451 +        * If we haven't tried to initialize KGDB yet, we need to call
18452 +        * kgdb_arch_init before moving onto the I/O.
18453 +        */
18454 +       if (!kgdb_initialized)
18455 +               kgdb_arch_init();
18456 +
18457 +       if (kgdb_initialized != 1) {
18458 +               if (kgdb_io_ops.init && kgdb_io_ops.init()) {
18459 +                       /* When KGDB allows I/O via modules and the core
18460 +                        * I/O init fails KGDB must default to defering the
18461 +                        * I/O setup, and appropriately print an error about
18462 +                        * it.
18463 +                        */
18464 +                       printk(KERN_ERR "kgdb: Could not setup core I/O "
18465 +                              "for KGDB.\n");
18466 +                       printk(KERN_INFO "kgdb: Defering I/O setup to kernel "
18467 +                              "module.\n");
18468 +                       memset(&kgdb_io_ops, 0, sizeof(struct kgdb_io));
18469 +               }
18470 +
18471 +               kgdb_internal_init();
18472 +
18473 +               /* KGDB can assume that if kgdb_io_ops.init was defined that
18474 +                * panic registion should be performed at this time. This means
18475 +                * kgdb_io_ops.init did not come from a kernel module and was
18476 +                * initialized statically by a built in.
18477 +                */
18478 +               if (kgdb_io_ops.init)
18479 +                       kgdb_register_for_panic();
18480 +       }
18481 +
18482 +       /* Registering to reboot notifier list*/
18483 +       register_reboot_notifier(&kgdb_reboot_notifier);
18484 +
18485 +       /* Now do any late init of the I/O. */
18486 +       if (kgdb_io_ops.late_init)
18487 +               kgdb_io_ops.late_init();
18488 +
18489 +       if (need_break) {
18490 +               printk(KERN_CRIT "kgdb: Waiting for connection from remote"
18491 +                      " gdb...\n");
18492 +               breakpoint();
18493 +       }
18494 +
18495 +       return 0;
18496 +}
18497 +
18498 +late_initcall(kgdb_late_entry);
18499 +
18500 +/*
18501 + * This function will generate a breakpoint exception.  It is used at the
18502 + * beginning of a program to sync up with a debugger and can be used
18503 + * otherwise as a quick means to stop program execution and "break" into
18504 + * the debugger.
18505 + */
18506 +void breakpoint(void)
18507 +{
18508 +       if (kgdb_initialized != 1) {
18509 +               kgdb_early_entry();
18510 +               if (kgdb_initialized == 1)
18511 +                       printk(KERN_CRIT "Waiting for connection from remote "
18512 +                              "gdb...\n");
18513 +               else {
18514 +                       printk(KERN_CRIT "KGDB cannot initialize I/O yet.\n");
18515 +                       return;
18516 +               }
18517 +       }
18518 +
18519 +       atomic_set(&kgdb_setting_breakpoint, 1);
18520 +       wmb();
18521 +       BREAKPOINT();
18522 +       wmb();
18523 +       atomic_set(&kgdb_setting_breakpoint, 0);
18524 +}
18525 +
18526 +EXPORT_SYMBOL(breakpoint);
18527 +
18528 +#ifdef CONFIG_MAGIC_SYSRQ
18529 +static void sysrq_handle_gdb(int key, struct pt_regs *pt_regs,
18530 +                            struct tty_struct *tty)
18531 +{
18532 +       printk("Entering GDB stub\n");
18533 +       breakpoint();
18534 +}
18535 +static struct sysrq_key_op sysrq_gdb_op = {
18536 +       .handler = sysrq_handle_gdb,
18537 +       .help_msg = "Gdb",
18538 +       .action_msg = "GDB",
18539 +};
18540 +
18541 +static int gdb_register_sysrq(void)
18542 +{
18543 +       printk("Registering GDB sysrq handler\n");
18544 +       register_sysrq_key('g', &sysrq_gdb_op);
18545 +       return 0;
18546 +}
18547 +
18548 +module_init(gdb_register_sysrq);
18549 +#endif
18550 +
18551 +static int kgdb_notify_reboot(struct notifier_block *this,
18552 +                            unsigned long code, void *x)
18553 +{
18554 +
18555 +       unsigned long flags;
18556 +
18557 +       /* If we're debugging, or KGDB has not connected, don't try
18558 +        * and print. */
18559 +       if (!kgdb_connected || atomic_read(&debugger_active) != 0)
18560 +               return 0;
18561 +       if ((code == SYS_RESTART) || (code == SYS_HALT) || (code == SYS_POWER_OFF)){
18562 +               local_irq_save(flags);
18563 +               put_packet("X00");
18564 +               local_irq_restore(flags);
18565 +       }
18566 +       return NOTIFY_DONE;
18567 +}
18568 +
18569 +#ifdef CONFIG_KGDB_CONSOLE
18570 +void kgdb_console_write(struct console *co, const char *s, unsigned count)
18571 +{
18572 +       unsigned long flags;
18573 +
18574 +       /* If we're debugging, or KGDB has not connected, don't try
18575 +        * and print. */
18576 +       if (!kgdb_connected || atomic_read(&debugger_active) != 0)
18577 +               return;
18578 +
18579 +       local_irq_save(flags);
18580 +       kgdb_msg_write(s, count);
18581 +       local_irq_restore(flags);
18582 +}
18583 +
18584 +struct console kgdbcons = {
18585 +       .name = "kgdb",
18586 +       .write = kgdb_console_write,
18587 +       .flags = CON_PRINTBUFFER | CON_ENABLED,
18588 +};
18589 +static int __init kgdb_console_init(void)
18590 +{
18591 +       register_console(&kgdbcons);
18592 +       return 0;
18593 +}
18594 +
18595 +console_initcall(kgdb_console_init);
18596 +#endif
18597 +
18598 +static int __init opt_kgdb_enter(char *str)
18599 +{
18600 +       /* We've already done this by an explicit breakpoint() call. */
18601 +       if (kgdb_initialized)
18602 +               return 0;
18603 +
18604 +       /* Call breakpoint() which will take care of init. */
18605 +       breakpoint();
18606 +
18607 +       return 0;
18608 +}
18609 +
18610 +early_param("kgdbwait", opt_kgdb_enter);
18611 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/kernel/kgdbarchlib.c linux-2.6.18-53.1.14.kgdb/kernel/kgdbarchlib.c
18612 --- linux-2.6.18-53.1.14/kernel/kgdbarchlib.c   1970-01-01 03:00:00.000000000 +0300
18613 +++ linux-2.6.18-53.1.14.kgdb/kernel/kgdbarchlib.c      2008-06-10 15:37:25.000000000 +0400
18614 @@ -0,0 +1,198 @@
18615 +#include <linux/kgdb.h>
18616 +
18617 +struct kgdb_arch *kgdb_ops = &arch_kgdb_ops;
18618 +
18619 +/**
18620 + *     kgdb_arch_init - Perform any architecture specific initalization.
18621 + *
18622 + *     RETURN:
18623 + *     The return value is ignored.
18624 + *
18625 + *     This function will handle the initalization of any architecture
18626 + *     specific hooks.
18627 + */
18628 +int __attribute__ ((weak))
18629 +    kgdb_arch_init(void)
18630 +{
18631 +       return 0;
18632 +}
18633 +
18634 +/**
18635 + *     kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.
18636 + *     @regs: Current &struct pt_regs.
18637 + *
18638 + *     This function will be called if the particular architecture must
18639 + *     disable hardware debugging while it is processing gdb packets or
18640 + *     handling exception.
18641 + */
18642 +void __attribute__ ((weak))
18643 +    kgdb_disable_hw_debug(struct pt_regs *regs)
18644 +{
18645 +}
18646 +
18647 +/*
18648 + * Skip an int3 exception when it occurs after a breakpoint has been
18649 + * removed. Backtrack eip by 1 since the int3 would have caused it to
18650 + * increment by 1.
18651 + */
18652 +int __attribute__ ((weak))
18653 +       kgdb_skipexception(int exception, struct pt_regs *regs)
18654 +{
18655 +       return 0;
18656 +}
18657 +
18658 +/**
18659 + *     kgdb_set_hw_break - Set a hardware breakpoint at @addr.
18660 + *     @addr: The address to set a hardware breakpoint at.
18661 + */
18662 +int __attribute__ ((weak))
18663 +    kgdb_set_hw_break(unsigned long addr)
18664 +{
18665 +       return 0;
18666 +}
18667 +
18668 +/**
18669 + *     kgdb_remove_hw_break - Remove a hardware breakpoint at @addr.
18670 + *     @addr: The address to remove a hardware breakpoint from.
18671 + */
18672 +int __attribute__ ((weak))
18673 +    kgdb_remove_hw_break(unsigned long addr)
18674 +{
18675 +       return 0;
18676 +}
18677 +
18678 +/**
18679 + *     kgdb_remove_all_hw_break - Clear all hardware breakpoints.
18680 + */
18681 +void __attribute__ ((weak))
18682 +    kgdb_remove_all_hw_break(void)
18683 +{
18684 +}
18685 +
18686 +/**
18687 + *     kgdb_correct_hw_break - Correct hardware breakpoints.
18688 + *
18689 + *     A hook to allow for changes to the hardware breakpoint, called
18690 + *     after a single step (s) or continue (c) packet, and once we're about
18691 + *     to let the kernel continue running.
18692 + *
18693 + *     This is used to set the hardware breakpoint registers for all the
18694 + *     slave cpus on an SMP configuration. This must be called after any
18695 + *     changes are made to the hardware breakpoints (such as by a single
18696 + *     step (s) or continue (c) packet. This is only required on
18697 + *     architectures that support SMP and every processor has its own set
18698 + *     of breakpoint registers.
18699 + */
18700 +void __attribute__ ((weak))
18701 +    kgdb_correct_hw_break(void)
18702 +{
18703 +}
18704 +
18705 +/**
18706 + *     kgdb_post_master_code - Save error vector/code numbers.
18707 + *     @regs: Original pt_regs.
18708 + *     @e_vector: Original error vector.
18709 + *     @err_code: Original error code.
18710 + *
18711 + *     This is needed on architectures which support SMP and KGDB.
18712 + *     This function is called after all the slave cpus have been put
18713 + *     to a know spin state and the master CPU has control over KGDB.
18714 + */
18715 +
18716 +void __attribute__ ((weak))
18717 +    kgdb_post_master_code(struct pt_regs *regs, int e_vector, int err_code)
18718 +{
18719 +}
18720 +
18721 +/**
18722 + *     kgdb_roundup_cpus - Get other CPUs into a holding pattern
18723 + *     @flags: Current IRQ state
18724 + *
18725 + *     On SMP systems, we need to get the attention of the other CPUs
18726 + *     and get them be in a known state.  This should do what is needed
18727 + *     to get the other CPUs to call kgdb_wait(). Note that on some arches,
18728 + *     the NMI approach is not used for rounding up all the CPUs. For example,
18729 + *     in case of MIPS, smp_call_function() is used to roundup CPUs. In
18730 + *     this case, we have to make sure that interrupts are enabled before
18731 + *     calling smp_call_function(). The argument to this function is
18732 + *     the flags that will be used when restoring the interrupts. There is
18733 + *     local_irq_save() call before kgdb_roundup_cpus().
18734 + */
18735 +void __attribute__ ((weak))
18736 +    kgdb_roundup_cpus(unsigned long flags)
18737 +{
18738 +}
18739 +
18740 +/**
18741 + *     kgdb_shadowinfo - Get shadowed information on @threadid.
18742 + *     @regs: The &struct pt_regs of the current process.
18743 + *     @buffer: A buffer of %BUFMAX size.
18744 + *     @threadid: The thread id of the shadowed process to get information on.
18745 + */
18746 +void __attribute__ ((weak))
18747 +    kgdb_shadowinfo(struct pt_regs *regs, char *buffer, unsigned threadid)
18748 +{
18749 +}
18750 +
18751 +/**
18752 + *     kgdb_get_shadow_thread - Get the shadowed &task_struct of @threadid.
18753 + *     @regs: The &struct pt_regs of the current thread.
18754 + *     @threadid: The thread id of the shadowed process to get information on.
18755 + *
18756 + *     RETURN:
18757 + *     This returns a pointer to the &struct task_struct of the shadowed
18758 + *     thread, @threadid.
18759 + */
18760 +struct task_struct __attribute__ ((weak))
18761 +    * kgdb_get_shadow_thread(struct pt_regs *regs, int threadid)
18762 +{
18763 +       return NULL;
18764 +}
18765 +
18766 +/**
18767 + *     kgdb_shadow_regs - Return the shadowed registers of @threadid.
18768 + *     @regs: The &struct pt_regs of the current thread.
18769 + *     @threadid: The thread id we want the &struct pt_regs for.
18770 + *
18771 + *     RETURN:
18772 + *     The a pointer to the &struct pt_regs of the shadowed thread @threadid.
18773 + */
18774 +struct pt_regs __attribute__ ((weak))
18775 +    * kgdb_shadow_regs(struct pt_regs *regs, int threadid)
18776 +{
18777 +       return NULL;
18778 +}
18779 +
18780 +int __attribute__ ((weak))
18781 +     kgdb_validate_break_address(unsigned long addr)
18782 +{
18783 +       int error = 0;
18784 +       char tmp_variable[BREAK_INSTR_SIZE];
18785 +       error = kgdb_get_mem((char *)addr, tmp_variable, BREAK_INSTR_SIZE);
18786 +       return error;
18787 +}
18788 +
18789 +int __attribute__ ((weak))
18790 +     kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr)
18791 +{
18792 +       int error = 0;
18793 +       if ((error = kgdb_get_mem((char *)addr,
18794 +               saved_instr, BREAK_INSTR_SIZE)) < 0)
18795 +                       return error;
18796 +
18797 +       if ((error = kgdb_set_mem((char *)addr, kgdb_ops->gdb_bpt_instr,
18798 +               BREAK_INSTR_SIZE)) < 0)
18799 +                       return error;
18800 +       return 0;
18801 +}
18802 +
18803 +int __attribute__ ((weak))
18804 +     kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle)
18805 +{
18806 +
18807 +       int error = 0;
18808 +       if ((error =kgdb_set_mem((char *)addr, (char *)bundle,
18809 +               BREAK_INSTR_SIZE)) < 0)
18810 +                       return error;
18811 +       return 0;
18812 +}
18813 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/kernel/module.c linux-2.6.18-53.1.14.kgdb/kernel/module.c
18814 --- linux-2.6.18-53.1.14/kernel/module.c        2008-03-06 05:54:13.000000000 +0300
18815 +++ linux-2.6.18-53.1.14.kgdb/kernel/module.c   2008-06-10 15:39:15.000000000 +0400
18816 @@ -65,6 +65,7 @@ static DEFINE_SPINLOCK(modlist_lock);
18817  /* List of modules, protected by module_mutex AND modlist_lock */
18818  static DEFINE_MUTEX(module_mutex);
18819  static LIST_HEAD(modules);
18820 +static DECLARE_MUTEX(notify_mutex);
18821  
18822  static BLOCKING_NOTIFIER_HEAD(module_notify_list);
18823  
18824 @@ -701,6 +702,12 @@ sys_delete_module(const char __user *nam
18825         if (ret != 0)
18826                 goto out;
18827  
18828 +       down(&notify_mutex);
18829 +       blocking_notifier_call_chain(&module_notify_list, MODULE_STATE_GOING,
18830 +                               mod);
18831 +       up(&notify_mutex);
18832 +
18833 +
18834         /* Never wait if forced. */
18835         if (!forced && module_refcount(mod) != 0)
18836                 wait_for_zero_refcount(mod);
18837 @@ -713,6 +720,11 @@ sys_delete_module(const char __user *nam
18838         }
18839         free_module(mod);
18840  
18841 +       down(&notify_mutex);
18842 +       blocking_notifier_call_chain(&module_notify_list, MODULE_STATE_GONE,
18843 +                       NULL);
18844 +       up(&notify_mutex);
18845 +
18846   out:
18847         mutex_unlock(&module_mutex);
18848         return ret;
18849 @@ -1119,6 +1131,11 @@ static void free_module(struct module *m
18850         /* Arch-specific cleanup. */
18851         module_arch_cleanup(mod);
18852  
18853 +#ifdef CONFIG_KGDB
18854 +       /* kgdb info */
18855 +       vfree(mod->mod_sections);
18856 +#endif
18857 +
18858         /* Module unload stuff */
18859         module_unload_free(mod);
18860  
18861 @@ -1378,6 +1395,31 @@ static void setup_modinfo(struct module 
18862         }
18863  }
18864  
18865 +#ifdef CONFIG_KGDB
18866 +int add_modsects (struct module *mod, Elf_Ehdr *hdr, Elf_Shdr *sechdrs, const
18867 +                char *secstrings)
18868 +{
18869 +        int i;
18870 +
18871 +        mod->num_sections = hdr->e_shnum - 1;
18872 +        mod->mod_sections = vmalloc((hdr->e_shnum - 1)*
18873 +               sizeof (struct mod_section));
18874 +
18875 +        if (mod->mod_sections == NULL) {
18876 +                return -ENOMEM;
18877 +        }
18878 +
18879 +        for (i = 1; i < hdr->e_shnum; i++) {
18880 +                mod->mod_sections[i - 1].address = (void *)sechdrs[i].sh_addr;
18881 +                strncpy(mod->mod_sections[i - 1].name, secstrings +
18882 +                                sechdrs[i].sh_name, MAX_SECTNAME);
18883 +                mod->mod_sections[i - 1].name[MAX_SECTNAME] = '\0';
18884 +       }
18885 +
18886 +       return 0;
18887 +}
18888 +#endif
18889 +
18890  #ifdef CONFIG_KALLSYMS
18891  int is_exported(const char *name, const struct module *mod)
18892  {
18893 @@ -1796,6 +1838,12 @@ static struct module *load_module(void _
18894  
18895         add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
18896  
18897 +#ifdef CONFIG_KGDB
18898 +        if ((err = add_modsects(mod, hdr, sechdrs, secstrings)) < 0) {
18899 +                goto nomodsectinfo;
18900 +        }
18901 +#endif
18902 +
18903         err = module_finalize(hdr, sechdrs, mod);
18904         if (err < 0)
18905                 goto cleanup;
18906 @@ -1856,6 +1904,11 @@ static struct module *load_module(void _
18907   arch_cleanup:
18908         module_arch_cleanup(mod);
18909   cleanup:
18910 +
18911 +#ifdef CONFIG_KGDB
18912 +nomodsectinfo:
18913 +       vfree(mod->mod_sections);
18914 +#endif
18915         module_unload_free(mod);
18916         module_free(mod, mod->module_init);
18917   free_core:
18918 @@ -1927,6 +1980,10 @@ sys_init_module(void __user *umod,
18919                 /* Init routine failed: abort.  Try to protect us from
18920                     buggy refcounters. */
18921                 mod->state = MODULE_STATE_GOING;
18922 +               down(&notify_mutex);
18923 +               blocking_notifier_call_chain(&module_notify_list, MODULE_STATE_GOING,
18924 +                               mod);
18925 +               up(&notify_mutex);
18926                 synchronize_sched();
18927                 if (mod->unsafe)
18928                         printk(KERN_ERR "%s: module is now stuck!\n",
18929 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/kernel/sched.c linux-2.6.18-53.1.14.kgdb/kernel/sched.c
18930 --- linux-2.6.18-53.1.14/kernel/sched.c 2008-03-06 05:54:44.000000000 +0300
18931 +++ linux-2.6.18-53.1.14.kgdb/kernel/sched.c    2008-06-10 15:37:25.000000000 +0400
18932 @@ -52,6 +52,7 @@
18933  #include <linux/acct.h>
18934  #include <linux/kprobes.h>
18935  #include <linux/delayacct.h>
18936 +#include <linux/kgdb.h>
18937  #include <asm/tlb.h>
18938  
18939  #include <asm/unistd.h>
18940 @@ -6835,6 +6836,9 @@ void __might_sleep(char *file, int line)
18941  #ifdef in_atomic
18942         static unsigned long prev_jiffy;        /* ratelimiting */
18943  
18944 +       if (atomic_read(&debugger_active))
18945 +               return;
18946 +
18947         if ((in_atomic() || irqs_disabled()) &&
18948             system_state == SYSTEM_RUNNING && !oops_in_progress) {
18949                 if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
18950 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/kernel/softlockup.c linux-2.6.18-53.1.14.kgdb/kernel/softlockup.c
18951 --- linux-2.6.18-53.1.14/kernel/softlockup.c    2008-03-06 05:54:44.000000000 +0300
18952 +++ linux-2.6.18-53.1.14.kgdb/kernel/softlockup.c       2008-06-10 15:39:21.000000000 +0400
18953 @@ -13,6 +13,7 @@
18954  #include <linux/kthread.h>
18955  #include <linux/notifier.h>
18956  #include <linux/module.h>
18957 +#include <linux/kgdb.h>
18958  
18959  static DEFINE_SPINLOCK(print_lock);
18960  
18961 @@ -37,6 +38,9 @@ static struct notifier_block panic_block
18962  void touch_softlockup_watchdog(void)
18963  {
18964         __raw_get_cpu_var(touch_timestamp) = jiffies;
18965 +#ifdef CONFIG_KGDB
18966 +       atomic_set(&kgdb_sync_softlockup[raw_smp_processor_id()], 0);
18967 +#endif
18968  }
18969  EXPORT_SYMBOL(touch_softlockup_watchdog);
18970  
18971 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/kernel/timer.c linux-2.6.18-53.1.14.kgdb/kernel/timer.c
18972 --- linux-2.6.18-53.1.14/kernel/timer.c 2008-03-06 05:54:50.000000000 +0300
18973 +++ linux-2.6.18-53.1.14.kgdb/kernel/timer.c    2008-06-10 15:39:21.000000000 +0400
18974 @@ -34,6 +34,7 @@
18975  #include <linux/cpu.h>
18976  #include <linux/syscalls.h>
18977  #include <linux/delay.h>
18978 +#include <linux/kgdb.h>
18979  
18980  #include <asm/uaccess.h>
18981  #include <asm/unistd.h>
18982 @@ -1385,7 +1386,11 @@ static void run_timer_softirq(struct sof
18983   */
18984  void run_local_timers(void)
18985  {
18986 +       int this_cpu = smp_processor_id();
18987         raise_softirq(TIMER_SOFTIRQ);
18988 +#ifdef CONFIG_KGDB
18989 +       if(!atomic_read(&kgdb_sync_softlockup[this_cpu]))
18990 +#endif
18991         softlockup_tick();
18992  }
18993  
18994 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/lib/Kconfig.debug linux-2.6.18-53.1.14.kgdb/lib/Kconfig.debug
18995 --- linux-2.6.18-53.1.14/lib/Kconfig.debug      2008-03-06 05:54:32.000000000 +0300
18996 +++ linux-2.6.18-53.1.14.kgdb/lib/Kconfig.debug 2008-06-10 15:38:56.000000000 +0400
18997 @@ -324,7 +324,7 @@ config DEBUG_LIST
18998  
18999  config FRAME_POINTER
19000         bool "Compile the kernel with frame pointers"
19001 -       depends on DEBUG_KERNEL && (X86 || CRIS || M68K || M68KNOMMU || FRV || UML || S390)
19002 +       depends on DEBUG_KERNEL && (X86 || CRIS || M68K || M68KNOMMU || FRV || UML || S390 || SUPERH)
19003         default y if DEBUG_INFO && UML
19004         help
19005           If you say Y here the resulting kernel image will be slightly larger
19006 @@ -377,3 +377,158 @@ config RCU_TORTURE_TEST
19007           at boot time (you probably don't).
19008           Say M if you want the RCU torture tests to build as a module.
19009           Say N if you are unsure.
19010 +
19011 +config WANT_EXTRA_DEBUG_INFORMATION
19012 +       bool
19013 +       select DEBUG_INFO
19014 +       select FRAME_POINTER if X86 || SUPERH
19015 +       default n
19016 +
19017 +config KGDB
19018 +       bool "KGDB: kernel debugging with remote gdb"
19019 +       select WANT_EXTRA_DEBUG_INFORMATION
19020 +       depends on DEBUG_KERNEL && (ARM || X86 || MIPS || (SUPERH && !SUPERH64) || IA64 || X86_64 || PPC)
19021 +       help
19022 +         If you say Y here, it will be possible to remotely debug the
19023 +         kernel using gdb. It is strongly suggested that you enable
19024 +         DEBUG_INFO, and if available on your platform, FRAME_POINTER.
19025 +         Documentation of kernel debugger available at
19026 +         http://kgdb.sourceforge.net as well as in DocBook form
19027 +         in Documentation/DocBook/.  If unsure, say N.
19028 +
19029 +config KGDB_CONSOLE
19030 +       bool "KGDB: Console messages through gdb"
19031 +       depends on KGDB
19032 +         help
19033 +           If you say Y here, console messages will appear through gdb.
19034 +           Other consoles such as tty or ttyS will continue to work as usual.
19035 +           Note, that if you use this in conjunction with KGDB_ETH, if the
19036 +           ethernet driver runs into an error condition during use with KGDB
19037 +           it is possible to hit an infinite recusrion, causing the kernel
19038 +           to crash, and typically reboot.  For this reason, it is preferable
19039 +           to use NETCONSOLE in conjunction with KGDB_ETH instead of
19040 +           KGDB_CONSOLE.
19041 +
19042 +choice
19043 +       prompt "Method for KGDB communication"
19044 +       depends on KGDB
19045 +       default KGDB_8250_NOMODULE
19046 +       default KGDB_MPSC if SERIAL_MPSC
19047 +       default KGDB_CPM_UART if (8xx || 8260)
19048 +       default KGDB_SIBYTE if SIBYTE_SB1xxx_SOC
19049 +       help
19050 +         There are a number of different ways in which you can communicate
19051 +         with KGDB.  The most common is via serial, with the 8250 driver
19052 +         (should your hardware have an 8250, or ns1655x style uart).
19053 +         Another option is to use the NETPOLL framework and UDP, should
19054 +         your ethernet card support this.  Other options may exist.
19055 +         You can elect to have one core I/O driver that is built into the
19056 +         kernel for debugging as the kernel is booting, or using only
19057 +         kernel modules.
19058 +
19059 +config KGDB_ONLY_MODULES
19060 +       bool "KGDB: Use only kernel modules for I/O"
19061 +       depends on MODULES
19062 +       help
19063 +         Use only kernel modules to configure KGDB I/O after the
19064 +         kernel is booted.
19065 +
19066 +config KGDB_8250_NOMODULE
19067 +       bool "KGDB: On generic serial port (8250)"
19068 +       select KGDB_8250
19069 +       help
19070 +         Uses generic serial port (8250) to communicate with the host
19071 +         GDB.  This is independent of the normal (SERIAL_8250) driver
19072 +         for this chipset.
19073 +
19074 +config KGDBOE_NOMODULE
19075 +       bool "KGDB: On ethernet - in kernel"
19076 +       select KGDBOE
19077 +       select NETPOLL
19078 +       select NETPOLL_TRAP
19079 +       select NETPOLL_RX
19080 +       help
19081 +         Uses the NETPOLL API to communicate with the host GDB via UDP.
19082 +         In order for this to work, the ethernet interface specified must
19083 +         support the NETPOLL API, and this must be initialized at boot.
19084 +         See the documentation for syntax.
19085 +
19086 +config KGDB_MPSC
19087 +       bool "KGDB on MV64x60 MPSC"
19088 +       depends on SERIAL_MPSC
19089 +       help
19090 +         Uses a Marvell GT64260B or MV64x60 Multi-Purpose Serial
19091 +         Controller (MPSC) channel. Note that the GT64260A is not
19092 +         supported.
19093 +
19094 +config KGDB_CPM_UART
19095 +       bool "KGDB: On CPM UART"
19096 +       depends on PPC && (CPM2 || 8xx)
19097 +       help
19098 +         Uses CPM UART to communicate with the host GDB.
19099 +
19100 +config KGDB_SIBYTE
19101 +       bool "KGDB: On the Broadcom SWARM serial port"
19102 +       depends on MIPS && SIBYTE_SB1xxx_SOC
19103 +endchoice
19104 +
19105 +config KGDBOE
19106 +       tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE
19107 +       depends on m && KGDB
19108 +       select NETPOLL
19109 +       select NETPOLL_TRAP
19110 +       select NETPOLL_RX
19111 +       help
19112 +         Uses the NETPOLL API to communicate with the host GDB via UDP.
19113 +         In order for this to work, the ethernet interface specified must
19114 +         support the NETPOLL API, and this must be initialized at boot.
19115 +         See the documentation for syntax.
19116 +
19117 +config KGDB_8250
19118 +       tristate "KGDB: On generic serial port (8250)" if !KGDB_8250_NOMODULE
19119 +       depends on m && KGDB_ONLY_MODULES
19120 +       help
19121 +         Uses generic serial port (8250) to communicate with the host
19122 +         GDB.  This is independent of the normal (SERIAL_8250) driver
19123 +         for this chipset.
19124 +
19125 +config KGDB_SIMPLE_SERIAL
19126 +       bool "Simple selection of KGDB serial port"
19127 +       depends on KGDB_8250_NOMODULE
19128 +       default y
19129 +       help
19130 +         If you say Y here, you will only have to pick the baud rate
19131 +         and port number that you wish to use for KGDB.  Note that this
19132 +         only works on architectures that register known serial ports
19133 +         early on.  If you say N, you will have to provide, either here
19134 +         or on the command line, the type (I/O or MMIO), IRQ and
19135 +         address to use.  If in doubt, say Y.
19136 +
19137 +config KGDB_BAUDRATE
19138 +       int "Debug serial port baud rate"
19139 +       depends on (KGDB_8250 && KGDB_SIMPLE_SERIAL)
19140 +       default "115200"
19141 +       help
19142 +         gdb and the kernel stub need to agree on the baud rate to be
19143 +         used.  Standard rates from 9600 to 115200 are allowed, and this
19144 +         may be overridden via the commandline.
19145 +
19146 +config KGDB_PORT_NUM
19147 +       int "Serial port number for KGDB"
19148 +       range 0 1 if KGDB_MPSC
19149 +       range 0 3
19150 +       depends on (KGDB_8250 && KGDB_SIMPLE_SERIAL) || KGDB_MPSC
19151 +       default "1"
19152 +       help
19153 +         Pick the port number (0 based) for KGDB to use.
19154 +
19155 +config KGDB_8250_CONF_STRING
19156 +       string "Configuration string for KGDB"
19157 +       depends on KGDB_8250_NOMODULE && !KGDB_SIMPLE_SERIAL
19158 +       default "io,2f8,115200,3" if X86
19159 +       help
19160 +         The format of this string should be <io or
19161 +         mmio>,<address>,<baud rate>,<irq>.  For example, to use the
19162 +         serial port on an i386 box located at 0x2f8 and 115200 baud
19163 +         on IRQ 3 at use:
19164 +         io,2f8,115200,3
19165 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/net/core/netpoll.c linux-2.6.18-53.1.14.kgdb/net/core/netpoll.c
19166 --- linux-2.6.18-53.1.14/net/core/netpoll.c     2008-03-06 05:54:27.000000000 +0300
19167 +++ linux-2.6.18-53.1.14.kgdb/net/core/netpoll.c        2008-06-10 15:37:49.000000000 +0400
19168 @@ -525,7 +525,8 @@ int __netpoll_rx(struct sk_buff *skb)
19169  
19170         np->rx_hook(np, ntohs(uh->source),
19171                     (char *)(uh+1),
19172 -                   ulen - sizeof(struct udphdr));
19173 +                   ulen - sizeof(struct udphdr),
19174 +                   skb);
19175  
19176         kfree_skb(skb);
19177         return 1;
19178 diff -rupbBN -X ../client-cleanup/dontdiff linux-2.6.18-53.1.14/scripts/dwarfh.awk linux-2.6.18-53.1.14.kgdb/scripts/dwarfh.awk
19179 --- linux-2.6.18-53.1.14/scripts/dwarfh.awk     1970-01-01 03:00:00.000000000 +0300
19180 +++ linux-2.6.18-53.1.14.kgdb/scripts/dwarfh.awk        2008-06-10 15:39:01.000000000 +0400
19181 @@ -0,0 +1,19 @@
19182 +BEGIN {
19183 +       print "#ifndef  _ELF_DWARF_H"
19184 +               print "/* Machine generated from dwarf2.h by scripts/dwarfh.awk */"
19185 +}
19186 +$2 == "=" {
19187 +       gsub(/,/, "", $3)
19188 +       print "#define " $1 "\t " $3
19189 +}
19190 +$1 == "#define" {
19191 +       print $0
19192 +       while( index($0,"\\") == length($0)){
19193 +               getline
19194 +               print $0
19195 +       }
19196 +}
19197 +/.*/ {}
19198 +END {
19199 +       print "#endif"
19200 +}